1 diff -Nur linux-2.6.16/Documentation/networking/bcm43xx-d80211-HOWTO.txt linux-2.6.16-bcm43xx/Documentation/networking/bcm43xx-d80211-HOWTO.txt
2 --- linux-2.6.16/Documentation/networking/bcm43xx-d80211-HOWTO.txt 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.16-bcm43xx/Documentation/networking/bcm43xx-d80211-HOWTO.txt 2006-03-28 22:16:14.000000000 +0200
6 +**** HOWTO get bcm43xx-dscape running ****
9 +This is a port of the bcm43xx driver for the devicescape ieee802.11
10 +stack. The devicescape ieee802.11 stack is an advanced out-of-mainline
11 +802.11 protocol module.
12 +I will call the "devicescape ieee802.11 stack" simply "dscape" in the
16 +*** Setting up the bcm43xx driver with dscape is currently non-trivial,
17 +*** as several modifications to the kernel and the userland
18 +*** wpa_supplicant tool are required. We are working on it...
21 +1) You need to patch the kernel with the ieee80211-devicescape stack
22 + and the bcm43xx-dscape port.
23 + Both are available in one cummulative at:
24 + ftp://ftp.bu3sch.de/bcm43xx-snapshots/all-in-one/bcm43xx-dscape/
25 + Read the instructions on http://bcm43xx.berlios.de/ for how to apply
28 + Patch the kernel, compile and install it.
29 + When configuring, enable
30 + "Networking/Generic IEEE 802.11 Networking Stack (dscape)"
32 + "Device Drivers/Network device support/Wireless LAN (non-hamradio)/Broadcom BCM43xx wireless support (DeviceScape stack)"
35 +2) Set up a wpa_supplicant config file in /etc/wpa_supplicant.conf
36 + Here is an example for an AES WPA encrypted network:
38 + # WPA AES encryption
39 + ctrl_interface=/var/run/wpa_supplicant
41 + ssid="ACCESSPOINT_SSID"
50 +3) Take a bottle of your favourite beer, open it and take a swallow.
52 +4) Now it's time to bring the driver up.
53 + Do modprobe bcm43xx-d80211 to load the driver.
54 + There is an ugly bash script to bring the driver up after insmod.
55 + It is found in the "scripts" subdirectory of the patched kernel
56 + tree and is called "bcm43xx-d80211-sta_up.sh".
57 + Call scripts/bcm43xx-d80211-sta_up.sh --help to get some usage information.
58 + It may suffice to call scripts/bcm43xx-d80211-sta_up.sh without any parameters. See
59 + the help. Default parameters, which are used when called without parameters,
60 + are explained there.
62 +5) If you want to access the internet, make sure your default route
63 + is correctly set up with your gateway's IP:
64 + route add default gw 192.168.xxx.xxx
66 +6) Take another swallow from your bottle of beer and test if it works:
69 +7) If it works, drink the rest of your beer. Otherwise read this HOWTO again,
70 + and again and again. Complain to bcm43xx-dev@lists.berlios.de, if it still
72 diff -Nur linux-2.6.16/Documentation/networking/bcm43xx-d80211.txt linux-2.6.16-bcm43xx/Documentation/networking/bcm43xx-d80211.txt
73 --- linux-2.6.16/Documentation/networking/bcm43xx-d80211.txt 1970-01-01 01:00:00.000000000 +0100
74 +++ linux-2.6.16-bcm43xx/Documentation/networking/bcm43xx-d80211.txt 2006-03-28 22:16:14.000000000 +0200
77 + BCM43xx Linux Driver Project
78 + ============================
83 +The goal of this project is to develop a linux driver for Broadcom
84 +BCM43xx chips, based on the specification at
85 +http://bcm-specs.sipsolutions.net/
87 +The project page is http://bcm43xx.berlios.de/
89 +This is a port of the bcm43xx driver for the devicescape ieee802.11
95 +1) Linux Kernel 2.6.16 or later
96 + http://www.kernel.org/
98 + See Documentation/networking/bcm43xx-d80211-HOWTO.txt for further
103 + Please try bcm43xx-fwcutter. It can extract the firmware from various
104 + binary driver files and supports driver files from Windows, MacOS and
105 + Linux. You can get bcm43xx-fwcutter from http://bcm43xx.berlios.de/.
106 + Also, bcm43xx-fwcutter comes with a README file for further instructions.
107 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
108 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c 1970-01-01 01:00:00.000000000 +0100
109 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.c 2006-03-28 22:16:14.000000000 +0200
113 + Broadcom BCM43xx wireless driver
115 + debugfs driver debugging code
117 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
119 + This program is free software; you can redistribute it and/or modify
120 + it under the terms of the GNU General Public License as published by
121 + the Free Software Foundation; either version 2 of the License, or
122 + (at your option) any later version.
124 + This program is distributed in the hope that it will be useful,
125 + but WITHOUT ANY WARRANTY; without even the implied warranty of
126 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
127 + GNU General Public License for more details.
129 + You should have received a copy of the GNU General Public License
130 + along with this program; see the file COPYING. If not, write to
131 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
132 + Boston, MA 02110-1301, USA.
138 +#include <linux/fs.h>
139 +#include <linux/debugfs.h>
140 +#include <linux/slab.h>
141 +#include <linux/netdevice.h>
142 +#include <linux/pci.h>
145 +#include "bcm43xx.h"
146 +#include "bcm43xx_main.h"
147 +#include "bcm43xx_debugfs.h"
148 +#include "bcm43xx_dma.h"
149 +#include "bcm43xx_pio.h"
150 +#include "bcm43xx_xmit.h"
152 +#define REALLY_BIG_BUFFER_SIZE (1024*256)
154 +static struct bcm43xx_debugfs fs;
155 +static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
156 +static DECLARE_MUTEX(big_buffer_sem);
159 +static ssize_t write_file_dummy(struct file *file, const char __user *buf,
160 + size_t count, loff_t *ppos)
165 +static int open_file_generic(struct inode *inode, struct file *file)
167 + file->private_data = inode->u.generic_ip;
171 +#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
173 +static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
174 + size_t count, loff_t *ppos)
176 + const size_t len = REALLY_BIG_BUFFER_SIZE;
178 + struct bcm43xx_private *bcm = file->private_data;
179 + char *buf = really_big_buffer;
182 + struct net_device *net_dev;
183 + struct pci_dev *pci_dev;
184 + unsigned long flags;
188 + down(&big_buffer_sem);
190 + bcm43xx_lock_mmio(bcm, flags);
191 + if (!bcm->initialized) {
192 + fappend("Board not initialized.\n");
195 + net_dev = bcm->net_dev;
196 + pci_dev = bcm->pci_dev;
198 + /* This is where the information is written to the "devinfo" file */
199 + fappend("*** %s devinfo ***\n", net_dev->name);
200 + fappend("vendor: 0x%04x device: 0x%04x\n",
201 + pci_dev->vendor, pci_dev->device);
202 + fappend("subsystem_vendor: 0x%04x subsystem_device: 0x%04x\n",
203 + pci_dev->subsystem_vendor, pci_dev->subsystem_device);
204 + fappend("IRQ: %d\n", bcm->irq);
205 + fappend("mmio_addr: 0x%p mmio_len: %u\n", bcm->mmio_addr, bcm->mmio_len);
206 + fappend("chip_id: 0x%04x chip_rev: 0x%02x\n", bcm->chip_id, bcm->chip_rev);
207 + if ((bcm->core_80211[0].rev >= 3) && (bcm43xx_read32(bcm, 0x0158) & (1 << 16)))
208 + fappend("Radio disabled by hardware!\n");
209 + if ((bcm->core_80211[0].rev < 3) && !(bcm43xx_read16(bcm, 0x049A) & (1 << 4)))
210 + fappend("Radio disabled by hardware!\n");
211 + fappend("board_vendor: 0x%04x board_type: 0x%04x\n", bcm->board_vendor,
214 + fappend("\nCores:\n");
215 +#define fappend_core(name, info) fappend("core \"" name "\" %s, %s, id: 0x%04x, " \
216 + "rev: 0x%02x, index: 0x%02x\n", \
218 + ? "available" : "nonavailable", \
220 + ? "enabled" : "disabled", \
221 + (info).id, (info).rev, (info).index)
222 + fappend_core("CHIPCOMMON", bcm->core_chipcommon);
223 + fappend_core("PCI", bcm->core_pci);
224 + fappend_core("first 80211", bcm->core_80211[0]);
225 + fappend_core("second 80211", bcm->core_80211[1]);
227 + tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
229 + for (i = 0; i < BCM43xx_NR_LEDS; i++)
230 + fappend("%d ", !!(tmp16 & (1 << i)));
234 + bcm43xx_unlock_mmio(bcm, flags);
235 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
236 + up(&big_buffer_sem);
240 +static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
241 + size_t count, loff_t *ppos)
243 + const size_t len = REALLY_BIG_BUFFER_SIZE;
245 + char *buf = really_big_buffer;
249 + down(&big_buffer_sem);
251 + /* This is where the information is written to the "driver" file */
252 + fappend(KBUILD_MODNAME " driver\n");
253 + fappend("Compiled at: %s %s\n", __DATE__, __TIME__);
255 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
256 + up(&big_buffer_sem);
260 +static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
261 + size_t count, loff_t *ppos)
263 + const size_t len = REALLY_BIG_BUFFER_SIZE;
265 + struct bcm43xx_private *bcm = file->private_data;
266 + char *buf = really_big_buffer;
269 + unsigned long flags;
271 + down(&big_buffer_sem);
272 + bcm43xx_lock_mmio(bcm, flags);
273 + if (!bcm->initialized) {
274 + fappend("Board not initialized.\n");
278 + /* This is where the information is written to the "sprom_dump" file */
279 + fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
282 + bcm43xx_unlock_mmio(bcm, flags);
283 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
284 + up(&big_buffer_sem);
288 +static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
289 + size_t count, loff_t *ppos)
291 + const size_t len = REALLY_BIG_BUFFER_SIZE;
293 + struct bcm43xx_private *bcm = file->private_data;
294 + char *buf = really_big_buffer;
297 + unsigned long flags;
300 + down(&big_buffer_sem);
301 + bcm43xx_lock_mmio(bcm, flags);
302 + if (!bcm->initialized) {
303 + fappend("Board not initialized.\n");
306 + bcm43xx_tsf_read(bcm, &tsf);
307 + fappend("0x%08x%08x\n",
308 + (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
309 + (unsigned int)(tsf & 0xFFFFFFFFULL));
312 + bcm43xx_unlock_mmio(bcm, flags);
313 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
314 + up(&big_buffer_sem);
318 +static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
319 + size_t count, loff_t *ppos)
321 + struct bcm43xx_private *bcm = file->private_data;
322 + char *buf = really_big_buffer;
325 + unsigned long flags;
328 + buf_size = min(count, sizeof (really_big_buffer) - 1);
329 + down(&big_buffer_sem);
330 + if (copy_from_user(buf, user_buf, buf_size)) {
334 + bcm43xx_lock_mmio(bcm, flags);
335 + if (!bcm->initialized) {
336 + printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
340 + if (sscanf(buf, "%lli", &tsf) != 1) {
341 + printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
345 + bcm43xx_tsf_write(bcm, tsf);
349 + bcm43xx_unlock_mmio(bcm, flags);
351 + up(&big_buffer_sem);
355 +static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
356 + size_t count, loff_t *ppos)
358 + const size_t len = REALLY_BIG_BUFFER_SIZE;
360 + struct bcm43xx_private *bcm = file->private_data;
361 + char *buf = really_big_buffer;
364 + unsigned long flags;
365 + struct bcm43xx_dfsentry *e;
366 + struct bcm43xx_xmitstatus *status;
369 + down(&big_buffer_sem);
370 + bcm43xx_lock(bcm, flags);
372 + fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
373 + BCM43xx_NR_LOGGED_XMITSTATUS);
375 + if (e->xmitstatus_printing == 0) {
376 + /* At the beginning, make a copy of all data to avoid
377 + * concurrency, as this function is called multiple
378 + * times for big logs. Without copying, the data might
379 + * change between reads. This would result in total trash.
381 + e->xmitstatus_printing = 1;
382 + e->saved_xmitstatus_ptr = e->xmitstatus_ptr;
383 + e->saved_xmitstatus_cnt = e->xmitstatus_cnt;
384 + memcpy(e->xmitstatus_print_buffer, e->xmitstatus_buffer,
385 + BCM43xx_NR_LOGGED_XMITSTATUS * sizeof(*(e->xmitstatus_buffer)));
387 + i = e->saved_xmitstatus_ptr - 1;
389 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
390 + cnt = e->saved_xmitstatus_cnt;
392 + status = e->xmitstatus_print_buffer + i;
393 + fappend("0x%02x: cookie: 0x%04x, flags: 0x%02x, "
394 + "cnt1: 0x%02x, cnt2: 0x%02x, seq: 0x%04x, "
395 + "unk: 0x%04x\n", j,
396 + status->cookie, status->flags,
397 + status->cnt1, status->cnt2, status->seq,
403 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
406 + bcm43xx_unlock(bcm, flags);
407 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
408 + bcm43xx_lock(bcm, flags);
409 + if (*ppos == pos) {
410 + /* Done. Drop the copied data. */
411 + e->xmitstatus_printing = 0;
413 + bcm43xx_unlock(bcm, flags);
414 + up(&big_buffer_sem);
421 +static struct file_operations devinfo_fops = {
422 + .read = devinfo_read_file,
423 + .write = write_file_dummy,
424 + .open = open_file_generic,
427 +static struct file_operations spromdump_fops = {
428 + .read = spromdump_read_file,
429 + .write = write_file_dummy,
430 + .open = open_file_generic,
433 +static struct file_operations drvinfo_fops = {
434 + .read = drvinfo_read_file,
435 + .write = write_file_dummy,
436 + .open = open_file_generic,
439 +static struct file_operations tsf_fops = {
440 + .read = tsf_read_file,
441 + .write = tsf_write_file,
442 + .open = open_file_generic,
445 +static struct file_operations txstat_fops = {
446 + .read = txstat_read_file,
447 + .write = write_file_dummy,
448 + .open = open_file_generic,
452 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
454 + struct bcm43xx_dfsentry *e;
455 + char devdir[IFNAMSIZ];
458 + e = kzalloc(sizeof(*e), GFP_KERNEL);
460 + printk(KERN_ERR PFX "out of memory\n");
464 + e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
465 + * sizeof(*(e->xmitstatus_buffer)),
467 + if (!e->xmitstatus_buffer) {
468 + printk(KERN_ERR PFX "out of memory\n");
472 + e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
473 + * sizeof(*(e->xmitstatus_buffer)),
475 + if (!e->xmitstatus_print_buffer) {
476 + printk(KERN_ERR PFX "out of memory\n");
484 + strncpy(devdir, bcm->net_dev->name, ARRAY_SIZE(devdir));
485 + e->subdir = debugfs_create_dir(devdir, fs.root);
486 + e->dentry_devinfo = debugfs_create_file("devinfo", 0444, e->subdir,
487 + bcm, &devinfo_fops);
488 + if (!e->dentry_devinfo)
489 + printk(KERN_ERR PFX "debugfs: creating \"devinfo\" for \"%s\" failed!\n", devdir);
490 + e->dentry_spromdump = debugfs_create_file("sprom_dump", 0444, e->subdir,
491 + bcm, &spromdump_fops);
492 + if (!e->dentry_spromdump)
493 + printk(KERN_ERR PFX "debugfs: creating \"sprom_dump\" for \"%s\" failed!\n", devdir);
494 + e->dentry_tsf = debugfs_create_file("tsf", 0666, e->subdir,
496 + if (!e->dentry_tsf)
497 + printk(KERN_ERR PFX "debugfs: creating \"tsf\" for \"%s\" failed!\n", devdir);
498 + e->dentry_txstat = debugfs_create_file("tx_status", 0444, e->subdir,
499 + bcm, &txstat_fops);
500 + if (!e->dentry_txstat)
501 + printk(KERN_ERR PFX "debugfs: creating \"tx_status\" for \"%s\" failed!\n", devdir);
504 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
506 + struct bcm43xx_dfsentry *e;
513 + debugfs_remove(e->dentry_spromdump);
514 + debugfs_remove(e->dentry_devinfo);
515 + debugfs_remove(e->dentry_tsf);
516 + debugfs_remove(e->dentry_txstat);
517 + debugfs_remove(e->subdir);
518 + kfree(e->xmitstatus_buffer);
519 + kfree(e->xmitstatus_print_buffer);
523 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
524 + struct bcm43xx_xmitstatus *status)
526 + struct bcm43xx_dfsentry *e;
527 + struct bcm43xx_xmitstatus *savedstatus;
529 + /* This is protected by bcm->_lock */
532 + savedstatus = e->xmitstatus_buffer + e->xmitstatus_ptr;
533 + memcpy(savedstatus, status, sizeof(*status));
534 + e->xmitstatus_ptr++;
535 + if (e->xmitstatus_ptr >= BCM43xx_NR_LOGGED_XMITSTATUS)
536 + e->xmitstatus_ptr = 0;
537 + if (e->xmitstatus_cnt < BCM43xx_NR_LOGGED_XMITSTATUS)
538 + e->xmitstatus_cnt++;
541 +void bcm43xx_debugfs_init(void)
543 + memset(&fs, 0, sizeof(fs));
544 + fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
546 + printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "\" subdir failed!\n");
547 + fs.dentry_driverinfo = debugfs_create_file("driver", 0444, fs.root, NULL, &drvinfo_fops);
548 + if (!fs.dentry_driverinfo)
549 + printk(KERN_ERR PFX "debugfs: creating \"" KBUILD_MODNAME "/driver\" failed!\n");
552 +void bcm43xx_debugfs_exit(void)
554 + debugfs_remove(fs.dentry_driverinfo);
555 + debugfs_remove(fs.root);
558 +void bcm43xx_printk_dump(const char *data,
560 + const char *description)
565 + printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
566 + description, size);
567 + for (i = 0; i < size; i++) {
570 + printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
572 + printk("0x%02x, ", c & 0xff);
577 +void bcm43xx_printk_bitdump(const unsigned char *data,
578 + size_t bytes, int msb_to_lsb,
579 + const char *description)
583 + const unsigned char *d;
585 + printk(KERN_INFO PFX "*** Bitdump (%s, %u bytes, %s) ***",
586 + description, bytes, msb_to_lsb ? "MSB to LSB" : "LSB to MSB");
587 + for (i = 0; i < bytes; i++) {
590 + printk("\n" KERN_INFO PFX "0x%08x: ", i);
592 + for (j = 7; j >= 0; j--) {
599 + for (j = 0; j < 8; j++) {
610 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
611 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h 1970-01-01 01:00:00.000000000 +0100
612 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_debugfs.h 2006-03-28 22:16:14.000000000 +0200
614 +#ifndef BCM43xx_DEBUGFS_H_
615 +#define BCM43xx_DEBUGFS_H_
617 +struct bcm43xx_private;
618 +struct bcm43xx_xmitstatus;
620 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
622 +#include <linux/list.h>
623 +#include <asm/semaphore.h>
627 +/* limited by the size of the "really_big_buffer" */
628 +#define BCM43xx_NR_LOGGED_XMITSTATUS 100
630 +struct bcm43xx_dfsentry {
631 + struct dentry *subdir;
632 + struct dentry *dentry_devinfo;
633 + struct dentry *dentry_spromdump;
634 + struct dentry *dentry_tsf;
635 + struct dentry *dentry_txstat;
637 + struct bcm43xx_private *bcm;
639 + /* saved xmitstatus. */
640 + struct bcm43xx_xmitstatus *xmitstatus_buffer;
641 + int xmitstatus_ptr;
642 + int xmitstatus_cnt;
643 + /* We need a seperate buffer while printing to avoid
644 + * concurrency issues. (New xmitstatus can arrive
645 + * while we are printing).
647 + struct bcm43xx_xmitstatus *xmitstatus_print_buffer;
648 + int saved_xmitstatus_ptr;
649 + int saved_xmitstatus_cnt;
650 + int xmitstatus_printing;
653 +struct bcm43xx_debugfs {
654 + struct dentry *root;
655 + struct dentry *dentry_driverinfo;
658 +void bcm43xx_debugfs_init(void);
659 +void bcm43xx_debugfs_exit(void);
660 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm);
661 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm);
662 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
663 + struct bcm43xx_xmitstatus *status);
665 +/* Debug helper: Dump binary data through printk. */
666 +void bcm43xx_printk_dump(const char *data,
668 + const char *description);
669 +/* Debug helper: Dump bitwise binary data through printk. */
670 +void bcm43xx_printk_bitdump(const unsigned char *data,
671 + size_t bytes, int msb_to_lsb,
672 + const char *description);
673 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) \
675 + bcm43xx_printk_bitdump((const unsigned char *)(pointer), \
676 + sizeof(*(pointer)), \
681 +#else /* CONFIG_BCM43XX_D80211_DEBUG*/
684 +void bcm43xx_debugfs_init(void) { }
686 +void bcm43xx_debugfs_exit(void) { }
688 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm) { }
690 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm) { }
692 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
693 + struct bcm43xx_xmitstatus *status) { }
696 +void bcm43xx_printk_dump(const char *data,
698 + const char *description)
702 +void bcm43xx_printk_bitdump(const unsigned char *data,
703 + size_t bytes, int msb_to_lsb,
704 + const char *description)
707 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) do { /* nothing */ } while (0)
709 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
711 +/* Ugly helper macros to make incomplete code more verbose on runtime */
717 + printk(KERN_INFO PFX "TODO: Incomplete code in %s() at %s:%d\n", \
718 + __FUNCTION__, __FILE__, __LINE__); \
726 + printk(KERN_INFO PFX "FIXME: Possibly broken code in %s() at %s:%d\n", \
727 + __FUNCTION__, __FILE__, __LINE__); \
730 +#endif /* BCM43xx_DEBUGFS_H_ */
731 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
732 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c 1970-01-01 01:00:00.000000000 +0100
733 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.c 2006-03-28 22:16:14.000000000 +0200
737 + Broadcom BCM43xx wireless driver
739 + DMA ringbuffer and descriptor allocation/management
741 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
743 + Some code in this file is derived from the b44.c driver
744 + Copyright (C) 2002 David S. Miller
745 + Copyright (C) Pekka Pietikainen
747 + This program is free software; you can redistribute it and/or modify
748 + it under the terms of the GNU General Public License as published by
749 + the Free Software Foundation; either version 2 of the License, or
750 + (at your option) any later version.
752 + This program is distributed in the hope that it will be useful,
753 + but WITHOUT ANY WARRANTY; without even the implied warranty of
754 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
755 + GNU General Public License for more details.
757 + You should have received a copy of the GNU General Public License
758 + along with this program; see the file COPYING. If not, write to
759 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
760 + Boston, MA 02110-1301, USA.
764 +#include "bcm43xx.h"
765 +#include "bcm43xx_dma.h"
766 +#include "bcm43xx_main.h"
767 +#include "bcm43xx_debugfs.h"
768 +#include "bcm43xx_power.h"
769 +#include "bcm43xx_xmit.h"
771 +#include <linux/dma-mapping.h>
772 +#include <linux/pci.h>
773 +#include <linux/delay.h>
774 +#include <linux/skbuff.h>
777 +static inline int free_slots(struct bcm43xx_dmaring *ring)
779 + return (ring->nr_slots - ring->used_slots);
782 +static inline int next_slot(struct bcm43xx_dmaring *ring, int slot)
784 + assert(slot >= -1 && slot <= ring->nr_slots - 1);
785 + if (slot == ring->nr_slots - 1)
790 +static inline int prev_slot(struct bcm43xx_dmaring *ring, int slot)
792 + assert(slot >= 0 && slot <= ring->nr_slots - 1);
794 + return ring->nr_slots - 1;
798 +/* Request a slot for usage. */
800 +int request_slot(struct bcm43xx_dmaring *ring)
805 + assert(!ring->suspended);
806 + assert(free_slots(ring) != 0);
808 + slot = next_slot(ring, ring->current_slot);
809 + ring->current_slot = slot;
810 + ring->used_slots++;
812 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
813 + if (ring->used_slots > ring->max_used_slots)
814 + ring->max_used_slots = ring->used_slots;
815 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
820 +/* Return a slot to the free slots. */
822 +void return_slot(struct bcm43xx_dmaring *ring, int slot)
826 + ring->used_slots--;
830 +dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
831 + unsigned char *buf,
835 + dma_addr_t dmaaddr;
838 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
842 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
851 +void unmap_descbuffer(struct bcm43xx_dmaring *ring,
857 + dma_unmap_single(&ring->bcm->pci_dev->dev,
861 + dma_unmap_single(&ring->bcm->pci_dev->dev,
868 +void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
874 + dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev,
875 + addr, len, DMA_FROM_DEVICE);
879 +void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
885 + dma_sync_single_for_device(&ring->bcm->pci_dev->dev,
886 + addr, len, DMA_FROM_DEVICE);
889 +/* Unmap and free a descriptor buffer. */
891 +void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
892 + struct bcm43xx_dmadesc *desc,
893 + struct bcm43xx_dmadesc_meta *meta,
898 + dev_kfree_skb_irq(meta->skb);
900 + dev_kfree_skb(meta->skb);
904 +static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
906 + struct device *dev = &(ring->bcm->pci_dev->dev);
908 + ring->vbase = dma_alloc_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
909 + &(ring->dmabase), GFP_KERNEL);
910 + if (!ring->vbase) {
911 + printk(KERN_ERR PFX "DMA ringmemory allocation failed\n");
914 + if (ring->dmabase + BCM43xx_DMA_RINGMEMSIZE > BCM43xx_DMA_BUSADDRMAX) {
915 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RINGMEMORY >1G "
916 + "(0x%08x, len: %lu)\n",
917 + ring->dmabase, BCM43xx_DMA_RINGMEMSIZE);
918 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
919 + ring->vbase, ring->dmabase);
922 + assert(!(ring->dmabase & 0x000003FF));
923 + memset(ring->vbase, 0, BCM43xx_DMA_RINGMEMSIZE);
928 +static void free_ringmemory(struct bcm43xx_dmaring *ring)
930 + struct device *dev = &(ring->bcm->pci_dev->dev);
932 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
933 + ring->vbase, ring->dmabase);
936 +/* Reset the RX DMA channel */
937 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
943 + bcm43xx_write32(bcm,
944 + mmio_base + BCM43xx_DMA_RX_CONTROL,
946 + for (i = 0; i < 1000; i++) {
947 + value = bcm43xx_read32(bcm,
948 + mmio_base + BCM43xx_DMA_RX_STATUS);
949 + value &= BCM43xx_DMA_RXSTAT_STAT_MASK;
950 + if (value == BCM43xx_DMA_RXSTAT_STAT_DISABLED) {
957 + printk(KERN_ERR PFX "Error: Wait on DMA RX status timed out.\n");
964 +/* Reset the RX DMA channel */
965 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
971 + for (i = 0; i < 1000; i++) {
972 + value = bcm43xx_read32(bcm,
973 + mmio_base + BCM43xx_DMA_TX_STATUS);
974 + value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
975 + if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED ||
976 + value == BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT ||
977 + value == BCM43xx_DMA_TXSTAT_STAT_STOPPED)
981 + bcm43xx_write32(bcm,
982 + mmio_base + BCM43xx_DMA_TX_CONTROL,
984 + for (i = 0; i < 1000; i++) {
985 + value = bcm43xx_read32(bcm,
986 + mmio_base + BCM43xx_DMA_TX_STATUS);
987 + value &= BCM43xx_DMA_TXSTAT_STAT_MASK;
988 + if (value == BCM43xx_DMA_TXSTAT_STAT_DISABLED) {
995 + printk(KERN_ERR PFX "Error: Wait on DMA TX status timed out.\n");
998 + /* ensure the reset is completed. */
1004 +static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
1005 + struct bcm43xx_dmadesc *desc,
1006 + struct bcm43xx_dmadesc_meta *meta,
1009 + struct bcm43xx_rxhdr *rxhdr;
1010 + dma_addr_t dmaaddr;
1013 + const int slot = (int)(desc - ring->vbase);
1014 + struct sk_buff *skb;
1016 + assert(slot >= 0 && slot < ring->nr_slots);
1017 + assert(!ring->tx);
1019 + skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
1020 + if (unlikely(!skb))
1022 + dmaaddr = map_descbuffer(ring, skb->data,
1023 + ring->rx_buffersize, 0);
1024 + if (unlikely(dmaaddr + ring->rx_buffersize > BCM43xx_DMA_BUSADDRMAX)) {
1025 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
1026 + dev_kfree_skb_any(skb);
1027 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA RX SKB >1G "
1028 + "(0x%08x, len: %u)\n",
1029 + dmaaddr, ring->rx_buffersize);
1033 + meta->dmaaddr = dmaaddr;
1034 + skb->dev = ring->bcm->net_dev;
1035 + desc_addr = (u32)(dmaaddr + ring->memoffset);
1036 + desc_ctl = (BCM43xx_DMADTOR_BYTECNT_MASK &
1037 + (u32)(ring->rx_buffersize - ring->frameoffset));
1038 + if (slot == ring->nr_slots - 1)
1039 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
1040 + set_desc_addr(desc, desc_addr);
1041 + set_desc_ctl(desc, desc_ctl);
1043 + rxhdr = (struct bcm43xx_rxhdr *)(skb->data);
1044 + rxhdr->frame_length = 0;
1045 + rxhdr->flags1 = 0;
1050 +/* Allocate the initial descbuffers.
1051 + * This is used for an RX ring only.
1053 +static int alloc_initial_descbuffers(struct bcm43xx_dmaring *ring)
1055 + int i, err = -ENOMEM;
1056 + struct bcm43xx_dmadesc *desc;
1057 + struct bcm43xx_dmadesc_meta *meta;
1059 + for (i = 0; i < ring->nr_slots; i++) {
1060 + desc = ring->vbase + i;
1061 + meta = ring->meta + i;
1063 + err = setup_rx_descbuffer(ring, desc, meta, GFP_KERNEL);
1067 + ring->used_slots = ring->nr_slots;
1073 + for (i--; i >= 0; i--) {
1074 + desc = ring->vbase + i;
1075 + meta = ring->meta + i;
1077 + unmap_descbuffer(ring, meta->dmaaddr, ring->rx_buffersize, 0);
1078 + dev_kfree_skb(meta->skb);
1083 +/* Do initial setup of the DMA controller.
1084 + * Reset the controller, write the ring busaddress
1085 + * and switch the "enable" bit on.
1087 +static int dmacontroller_setup(struct bcm43xx_dmaring *ring)
1093 + /* Set Transmit Control register to "transmit enable" */
1094 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
1095 + BCM43xx_DMA_TXCTRL_ENABLE);
1096 + /* Set Transmit Descriptor ring address. */
1097 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING,
1098 + ring->dmabase + ring->memoffset);
1100 + err = alloc_initial_descbuffers(ring);
1103 + /* Set Receive Control "receive enable" and frame offset */
1104 + value = (ring->frameoffset << BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT);
1105 + value |= BCM43xx_DMA_RXCTRL_ENABLE;
1106 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_CONTROL, value);
1107 + /* Set Receive Descriptor ring address. */
1108 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING,
1109 + ring->dmabase + ring->memoffset);
1110 + /* Init the descriptor pointer. */
1111 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX, 200);
1118 +/* Shutdown the DMA controller. */
1119 +static void dmacontroller_cleanup(struct bcm43xx_dmaring *ring)
1122 + bcm43xx_dmacontroller_tx_reset(ring->bcm, ring->mmio_base);
1123 + /* Zero out Transmit Descriptor ring address. */
1124 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_RING, 0);
1126 + bcm43xx_dmacontroller_rx_reset(ring->bcm, ring->mmio_base);
1127 + /* Zero out Receive Descriptor ring address. */
1128 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_RING, 0);
1132 +static void free_all_descbuffers(struct bcm43xx_dmaring *ring)
1134 + struct bcm43xx_dmadesc *desc;
1135 + struct bcm43xx_dmadesc_meta *meta;
1138 + if (!ring->used_slots)
1140 + for (i = 0; i < ring->nr_slots; i++) {
1141 + desc = ring->vbase + i;
1142 + meta = ring->meta + i;
1149 + unmap_descbuffer(ring, meta->dmaaddr,
1150 + meta->skb->len, 1);
1152 + unmap_descbuffer(ring, meta->dmaaddr,
1153 + ring->rx_buffersize, 0);
1155 + free_descriptor_buffer(ring, desc, meta, 0);
1159 +/* Main initialization function. */
1161 +struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
1162 + u16 dma_controller_base,
1163 + int nr_descriptor_slots,
1166 + struct bcm43xx_dmaring *ring;
1169 + ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1173 + ring->meta = kzalloc(sizeof(*ring->meta) * nr_descriptor_slots,
1176 + goto err_kfree_ring;
1178 + ring->memoffset = BCM43xx_DMA_DMABUSADDROFFSET;
1179 +#ifdef CONFIG_BCM947XX
1180 + if (bcm->pci_dev->bus->number == 0)
1181 + ring->memoffset = 0;
1185 + ring->nr_slots = nr_descriptor_slots;
1186 + ring->mmio_base = dma_controller_base;
1189 + ring->current_slot = -1;
1191 + switch (dma_controller_base) {
1192 + case BCM43xx_MMIO_DMA1_BASE:
1193 + ring->rx_buffersize = BCM43xx_DMA1_RXBUFFERSIZE;
1194 + ring->frameoffset = BCM43xx_DMA1_RX_FRAMEOFFSET;
1196 + case BCM43xx_MMIO_DMA4_BASE:
1197 + ring->rx_buffersize = BCM43xx_DMA4_RXBUFFERSIZE;
1198 + ring->frameoffset = BCM43xx_DMA4_RX_FRAMEOFFSET;
1205 + err = alloc_ringmemory(ring);
1207 + goto err_kfree_meta;
1208 + err = dmacontroller_setup(ring);
1210 + goto err_free_ringmemory;
1215 +err_free_ringmemory:
1216 + free_ringmemory(ring);
1218 + kfree(ring->meta);
1225 +/* Main cleanup function. */
1226 +static void bcm43xx_destroy_dmaring(struct bcm43xx_dmaring *ring)
1231 + dprintk(KERN_INFO PFX "DMA 0x%04x (%s) max used slots: %d/%d\n",
1233 + (ring->tx) ? "TX" : "RX",
1234 + ring->max_used_slots, ring->nr_slots);
1235 + /* Device IRQs are disabled prior entering this function,
1236 + * so no need to take care of concurrency with rx handler stuff.
1238 + dmacontroller_cleanup(ring);
1239 + free_all_descbuffers(ring);
1240 + free_ringmemory(ring);
1242 + kfree(ring->meta);
1246 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1248 + struct bcm43xx_dma *dma;
1250 + if (bcm43xx_using_pio(bcm))
1252 + dma = bcm43xx_current_dma(bcm);
1254 + bcm43xx_destroy_dmaring(dma->rx_ring1);
1255 + dma->rx_ring1 = NULL;
1256 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1257 + dma->rx_ring0 = NULL;
1258 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1259 + dma->tx_ring3 = NULL;
1260 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1261 + dma->tx_ring2 = NULL;
1262 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1263 + dma->tx_ring1 = NULL;
1264 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1265 + dma->tx_ring0 = NULL;
1268 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1270 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1271 + struct bcm43xx_dmaring *ring;
1272 + int err = -ENOMEM;
1274 + /* setup TX DMA channels. */
1275 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1276 + BCM43xx_TXRING_SLOTS, 1);
1279 + dma->tx_ring0 = ring;
1281 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA2_BASE,
1282 + BCM43xx_TXRING_SLOTS, 1);
1284 + goto err_destroy_tx0;
1285 + dma->tx_ring1 = ring;
1287 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA3_BASE,
1288 + BCM43xx_TXRING_SLOTS, 1);
1290 + goto err_destroy_tx1;
1291 + dma->tx_ring2 = ring;
1293 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1294 + BCM43xx_TXRING_SLOTS, 1);
1296 + goto err_destroy_tx2;
1297 + dma->tx_ring3 = ring;
1299 + /* setup RX DMA channels. */
1300 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1301 + BCM43xx_RXRING_SLOTS, 0);
1303 + goto err_destroy_tx3;
1304 + dma->rx_ring0 = ring;
1306 + if (bcm->current_core->rev < 5) {
1307 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1308 + BCM43xx_RXRING_SLOTS, 0);
1310 + goto err_destroy_rx0;
1311 + dma->rx_ring1 = ring;
1314 + dprintk(KERN_INFO PFX "DMA initialized\n");
1320 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1321 + dma->rx_ring0 = NULL;
1323 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1324 + dma->tx_ring3 = NULL;
1326 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1327 + dma->tx_ring2 = NULL;
1329 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1330 + dma->tx_ring1 = NULL;
1332 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1333 + dma->tx_ring0 = NULL;
1337 +/* Generate a cookie for the TX header. */
1338 +static u16 generate_cookie(struct bcm43xx_dmaring *ring,
1341 + u16 cookie = 0x0000;
1343 + /* Use the upper 4 bits of the cookie as
1344 + * DMA controller ID and store the slot number
1345 + * in the lower 12 bits
1347 + switch (ring->mmio_base) {
1350 + case BCM43xx_MMIO_DMA1_BASE:
1352 + case BCM43xx_MMIO_DMA2_BASE:
1355 + case BCM43xx_MMIO_DMA3_BASE:
1358 + case BCM43xx_MMIO_DMA4_BASE:
1362 + assert(((u16)slot & 0xF000) == 0x0000);
1363 + cookie |= (u16)slot;
1368 +/* Inspect a cookie and find out to which controller/slot it belongs. */
1370 +struct bcm43xx_dmaring * parse_cookie(struct bcm43xx_private *bcm,
1371 + u16 cookie, int *slot)
1373 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1374 + struct bcm43xx_dmaring *ring = NULL;
1376 + switch (cookie & 0xF000) {
1378 + ring = dma->tx_ring0;
1381 + ring = dma->tx_ring1;
1384 + ring = dma->tx_ring2;
1387 + ring = dma->tx_ring3;
1392 + *slot = (cookie & 0x0FFF);
1393 + assert(*slot >= 0 && *slot < ring->nr_slots);
1398 +static void dmacontroller_poke_tx(struct bcm43xx_dmaring *ring,
1401 + /* Everything is ready to start. Buffers are DMA mapped and
1402 + * associated with slots.
1403 + * "slot" is the last slot of the new frame we want to transmit.
1404 + * Close your seat belts now, please.
1407 + slot = next_slot(ring, slot);
1408 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_INDEX,
1409 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1412 +static int dma_tx_fragment(struct bcm43xx_dmaring *ring,
1413 + struct sk_buff *skb,
1414 + struct ieee80211_tx_control *ctl)
1416 + struct sk_buff *hdr_skb;
1418 + struct bcm43xx_dmadesc *desc;
1419 + struct bcm43xx_dmadesc_meta *meta;
1423 + assert(skb_shinfo(skb)->nr_frags == 0);
1425 + hdr_skb = dev_alloc_skb(sizeof(struct bcm43xx_txhdr));
1426 + if (unlikely(!hdr_skb))
1428 + skb_put(hdr_skb, sizeof(struct bcm43xx_txhdr));
1430 + slot = request_slot(ring);
1431 + desc = ring->vbase + slot;
1432 + meta = ring->meta + slot;
1434 + bcm43xx_generate_txhdr(ring->bcm,
1435 + (struct bcm43xx_txhdr *)hdr_skb->data,
1436 + skb->data, skb->len,
1438 + generate_cookie(ring, slot),
1441 + meta->skb = hdr_skb;
1442 + meta->dmaaddr = map_descbuffer(ring, hdr_skb->data, hdr_skb->len, 1);
1443 + if (unlikely(meta->dmaaddr + hdr_skb->len > BCM43xx_DMA_BUSADDRMAX)) {
1444 + return_slot(ring, slot);
1445 + dev_kfree_skb_irq(hdr_skb);
1446 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA TX SKB >1G "
1447 + "(0x%08x, len: %u)\n",
1448 + meta->dmaaddr, hdr_skb->len);
1452 + desc_addr = (u32)(meta->dmaaddr + ring->memoffset);
1453 + desc_ctl = BCM43xx_DMADTOR_FRAMESTART |
1454 + (BCM43xx_DMADTOR_BYTECNT_MASK & (u32)(hdr_skb->len));
1455 + if (slot == ring->nr_slots - 1)
1456 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
1457 + set_desc_ctl(desc, desc_ctl);
1458 + set_desc_addr(desc, desc_addr);
1460 + slot = request_slot(ring);
1461 + desc = ring->vbase + slot;
1462 + meta = ring->meta + slot;
1464 + /* We inspect the txstatus on the FRAMESTART descriptor later
1465 + * on xmit-status IRQ.
1467 + meta->must_xmit_txstat = 1;
1468 + memset(&meta->txstat, 0, sizeof(meta->txstat));
1469 + memcpy(&meta->txstat.control, ctl, sizeof(*ctl));
1472 + meta->dmaaddr = map_descbuffer(ring, skb->data, skb->len, 1);
1473 + if (unlikely(meta->dmaaddr + skb->len > BCM43xx_DMA_BUSADDRMAX)) {
1474 + return_slot(ring, prev_slot(ring, slot));
1475 + return_slot(ring, slot);
1476 + dev_kfree_skb_irq(hdr_skb);
1477 + printk(KERN_ERR PFX ">>>FATAL ERROR<<< DMA TX SKB >1G "
1478 + "(0x%08x, len: %u)\n",
1479 + meta->dmaaddr, skb->len);
1483 + desc_addr = (u32)(meta->dmaaddr + ring->memoffset);
1484 + desc_ctl = (BCM43xx_DMADTOR_BYTECNT_MASK & (u32)(skb->len));
1485 + if (slot == ring->nr_slots - 1)
1486 + desc_ctl |= BCM43xx_DMADTOR_DTABLEEND;
1488 + desc_ctl |= BCM43xx_DMADTOR_FRAMEEND | BCM43xx_DMADTOR_COMPIRQ;
1489 + set_desc_ctl(desc, desc_ctl);
1490 + set_desc_addr(desc, desc_addr);
1491 + /* Now transfer the whole frame. */
1492 + dmacontroller_poke_tx(ring, slot);
1497 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1498 + struct sk_buff *skb,
1499 + struct ieee80211_tx_control *ctl)
1501 + struct bcm43xx_dmaring *ring = bcm43xx_current_dma(bcm)->tx_ring1;
1506 +#define SLOTS_PER_PACKET 2
1507 + if (unlikely(free_slots(ring) < SLOTS_PER_PACKET)) {
1508 + /* This should never trigger, as the ieee80211 stack
1509 + * recognizes if the device queue is full and does
1510 + * not send data anymore.
1512 + printk(KERN_ERR PFX "DMA queue overflow\n");
1516 + err = dma_tx_fragment(ring, skb, ctl);
1518 + ring->nr_tx_packets++;
1523 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1524 + struct bcm43xx_xmitstatus *status)
1526 + struct bcm43xx_dmaring *ring;
1527 + struct bcm43xx_dmadesc *desc;
1528 + struct bcm43xx_dmadesc_meta *meta;
1529 + int is_last_fragment;
1532 + ring = parse_cookie(bcm, status->cookie, &slot);
1535 + assert(get_desc_ctl(ring->vbase + slot) & BCM43xx_DMADTOR_FRAMESTART);
1537 + assert(slot >= 0 && slot < ring->nr_slots);
1538 + desc = ring->vbase + slot;
1539 + meta = ring->meta + slot;
1541 + is_last_fragment = !!(get_desc_ctl(desc) & BCM43xx_DMADTOR_FRAMEEND);
1542 + unmap_descbuffer(ring, meta->dmaaddr, meta->skb->len, 1);
1544 + if (meta->must_xmit_txstat) {
1545 + meta->must_xmit_txstat = 0;
1546 + /* Call back to inform the ieee80211 subsystem about the
1547 + * status of the transmission.
1548 + * Some fields of txstat are already filled in dma_tx().
1550 + meta->txstat.ack = !!(status->flags & BCM43xx_TXSTAT_FLAG_ACK);
1551 + meta->txstat.retry_count = status->cnt2 - 1;
1552 + //FIXME: Fill in more information?
1553 + ieee80211_tx_status_irqsafe(bcm->net_dev, meta->skb, &(meta->txstat));
1556 + free_descriptor_buffer(ring, desc, meta, 1);
1557 + /* Everything belonging to the slot is unmapped
1558 + * and freed, so we can return it.
1560 + return_slot(ring, slot);
1562 + if (is_last_fragment)
1564 + slot = next_slot(ring, slot);
1566 + bcm->stats.last_tx = jiffies;
1569 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1570 + struct ieee80211_tx_queue_stats *stats)
1572 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1573 + struct bcm43xx_dmaring *ring;
1574 + struct ieee80211_tx_queue_stats_data *data;
1576 + ring = dma->tx_ring1;
1577 + data = &(stats->data[0]);
1578 + data->len = ring->used_slots / SLOTS_PER_PACKET;
1579 + data->limit = ring->nr_slots / SLOTS_PER_PACKET;
1580 + data->count = ring->nr_tx_packets;
1583 +static void dma_rx(struct bcm43xx_dmaring *ring,
1586 + struct bcm43xx_dmadesc *desc;
1587 + struct bcm43xx_dmadesc_meta *meta;
1588 + struct bcm43xx_rxhdr *rxhdr;
1589 + struct sk_buff *skb;
1592 + dma_addr_t dmaaddr;
1594 + desc = ring->vbase + *slot;
1595 + meta = ring->meta + *slot;
1597 + sync_descbuffer_for_cpu(ring, meta->dmaaddr, ring->rx_buffersize);
1600 + if (ring->mmio_base == BCM43xx_MMIO_DMA4_BASE) {
1601 + /* We received an xmit status. */
1602 + struct bcm43xx_hwxmitstatus *hw = (struct bcm43xx_hwxmitstatus *)skb->data;
1603 + struct bcm43xx_xmitstatus stat;
1605 + stat.cookie = le16_to_cpu(hw->cookie);
1606 + stat.flags = hw->flags;
1607 + stat.cnt1 = hw->cnt1;
1608 + stat.cnt2 = hw->cnt2;
1609 + stat.seq = le16_to_cpu(hw->seq);
1610 + stat.unknown = le16_to_cpu(hw->unknown);
1612 + bcm43xx_debugfs_log_txstat(ring->bcm, &stat);
1613 + bcm43xx_dma_handle_xmitstatus(ring->bcm, &stat);
1614 + /* recycle the descriptor buffer. */
1615 + sync_descbuffer_for_device(ring, meta->dmaaddr, ring->rx_buffersize);
1619 + rxhdr = (struct bcm43xx_rxhdr *)skb->data;
1620 + len = le16_to_cpu(rxhdr->frame_length);
1627 + len = le16_to_cpu(rxhdr->frame_length);
1628 + } while (len == 0 && i++ < 5);
1629 + if (unlikely(len == 0)) {
1630 + /* recycle the descriptor buffer. */
1631 + sync_descbuffer_for_device(ring, meta->dmaaddr,
1632 + ring->rx_buffersize);
1636 + if (unlikely(len > ring->rx_buffersize)) {
1637 + /* The data did not fit into one descriptor buffer
1638 + * and is split over multiple buffers.
1639 + * This should never happen, as we try to allocate buffers
1640 + * big enough. So simply ignore this packet.
1646 + desc = ring->vbase + *slot;
1647 + meta = ring->meta + *slot;
1648 + /* recycle the descriptor buffer. */
1649 + sync_descbuffer_for_device(ring, meta->dmaaddr,
1650 + ring->rx_buffersize);
1651 + *slot = next_slot(ring, *slot);
1653 + tmp -= ring->rx_buffersize;
1657 + printkl(KERN_ERR PFX "DMA RX buffer too small "
1658 + "(len: %u, buffer: %u, nr-dropped: %d)\n",
1659 + len, ring->rx_buffersize, cnt);
1663 + dmaaddr = meta->dmaaddr;
1664 + err = setup_rx_descbuffer(ring, desc, meta, GFP_ATOMIC);
1665 + if (unlikely(err)) {
1666 + dprintkl(KERN_ERR PFX "DMA RX: setup_rx_descbuffer() failed\n");
1667 + sync_descbuffer_for_device(ring, dmaaddr,
1668 + ring->rx_buffersize);
1672 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
1673 + skb_put(skb, len + ring->frameoffset);
1674 + skb_pull(skb, ring->frameoffset);
1676 + bcm43xx_rx(ring->bcm, skb, rxhdr);
1681 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1685 + int slot, current_slot;
1686 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1687 + int used_slots = 0;
1690 + assert(!ring->tx);
1691 + status = bcm43xx_dma_read(ring, BCM43xx_DMA_RX_STATUS);
1692 + descptr = (status & BCM43xx_DMA_RXSTAT_DPTR_MASK);
1693 + current_slot = descptr / sizeof(struct bcm43xx_dmadesc);
1694 + assert(current_slot >= 0 && current_slot < ring->nr_slots);
1696 + slot = ring->current_slot;
1697 + for ( ; slot != current_slot; slot = next_slot(ring, slot)) {
1698 + dma_rx(ring, &slot);
1699 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1700 + if (++used_slots > ring->max_used_slots)
1701 + ring->max_used_slots = used_slots;
1704 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX,
1705 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1706 + ring->current_slot = slot;
1709 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring)
1712 + bcm43xx_power_saving_ctl_bits(ring->bcm, -1, 1);
1713 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
1714 + bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
1715 + | BCM43xx_DMA_TXCTRL_SUSPEND);
1718 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring)
1721 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_CONTROL,
1722 + bcm43xx_dma_read(ring, BCM43xx_DMA_TX_CONTROL)
1723 + & ~BCM43xx_DMA_TXCTRL_SUSPEND);
1724 + bcm43xx_power_saving_ctl_bits(ring->bcm, -1, -1);
1726 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
1727 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h 1970-01-01 01:00:00.000000000 +0100
1728 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_dma.h 2006-03-28 22:16:14.000000000 +0200
1730 +#ifndef BCM43xx_DMA_H_
1731 +#define BCM43xx_DMA_H_
1733 +#include <linux/list.h>
1734 +#include <linux/spinlock.h>
1735 +#include <linux/workqueue.h>
1736 +#include <linux/linkage.h>
1737 +#include <asm/atomic.h>
1739 +#include "bcm43xx.h"
1742 +/* DMA-Interrupt reasons. */
1743 +#define BCM43xx_DMAIRQ_FATALMASK ((1 << 10) | (1 << 11) | (1 << 12) \
1744 + | (1 << 14) | (1 << 15))
1745 +#define BCM43xx_DMAIRQ_NONFATALMASK (1 << 13)
1746 +#define BCM43xx_DMAIRQ_RX_DONE (1 << 16)
1748 +/* DMA controller register offsets. (relative to BCM43xx_DMA#_BASE) */
1749 +#define BCM43xx_DMA_TX_CONTROL 0x00
1750 +#define BCM43xx_DMA_TX_DESC_RING 0x04
1751 +#define BCM43xx_DMA_TX_DESC_INDEX 0x08
1752 +#define BCM43xx_DMA_TX_STATUS 0x0c
1753 +#define BCM43xx_DMA_RX_CONTROL 0x10
1754 +#define BCM43xx_DMA_RX_DESC_RING 0x14
1755 +#define BCM43xx_DMA_RX_DESC_INDEX 0x18
1756 +#define BCM43xx_DMA_RX_STATUS 0x1c
1758 +/* DMA controller channel control word values. */
1759 +#define BCM43xx_DMA_TXCTRL_ENABLE (1 << 0)
1760 +#define BCM43xx_DMA_TXCTRL_SUSPEND (1 << 1)
1761 +#define BCM43xx_DMA_TXCTRL_LOOPBACK (1 << 2)
1762 +#define BCM43xx_DMA_TXCTRL_FLUSH (1 << 4)
1763 +#define BCM43xx_DMA_RXCTRL_ENABLE (1 << 0)
1764 +#define BCM43xx_DMA_RXCTRL_FRAMEOFF_MASK 0x000000fe
1765 +#define BCM43xx_DMA_RXCTRL_FRAMEOFF_SHIFT 1
1766 +#define BCM43xx_DMA_RXCTRL_PIO (1 << 8)
1767 +/* DMA controller channel status word values. */
1768 +#define BCM43xx_DMA_TXSTAT_DPTR_MASK 0x00000fff
1769 +#define BCM43xx_DMA_TXSTAT_STAT_MASK 0x0000f000
1770 +#define BCM43xx_DMA_TXSTAT_STAT_DISABLED 0x00000000
1771 +#define BCM43xx_DMA_TXSTAT_STAT_ACTIVE 0x00001000
1772 +#define BCM43xx_DMA_TXSTAT_STAT_IDLEWAIT 0x00002000
1773 +#define BCM43xx_DMA_TXSTAT_STAT_STOPPED 0x00003000
1774 +#define BCM43xx_DMA_TXSTAT_STAT_SUSP 0x00004000
1775 +#define BCM43xx_DMA_TXSTAT_ERROR_MASK 0x000f0000
1776 +#define BCM43xx_DMA_TXSTAT_FLUSHED (1 << 20)
1777 +#define BCM43xx_DMA_RXSTAT_DPTR_MASK 0x00000fff
1778 +#define BCM43xx_DMA_RXSTAT_STAT_MASK 0x0000f000
1779 +#define BCM43xx_DMA_RXSTAT_STAT_DISABLED 0x00000000
1780 +#define BCM43xx_DMA_RXSTAT_STAT_ACTIVE 0x00001000
1781 +#define BCM43xx_DMA_RXSTAT_STAT_IDLEWAIT 0x00002000
1782 +#define BCM43xx_DMA_RXSTAT_STAT_RESERVED 0x00003000
1783 +#define BCM43xx_DMA_RXSTAT_STAT_ERRORS 0x00004000
1784 +#define BCM43xx_DMA_RXSTAT_ERROR_MASK 0x000f0000
1786 +/* DMA descriptor control field values. */
1787 +#define BCM43xx_DMADTOR_BYTECNT_MASK 0x00001fff
1788 +#define BCM43xx_DMADTOR_DTABLEEND (1 << 28) /* End of descriptor table */
1789 +#define BCM43xx_DMADTOR_COMPIRQ (1 << 29) /* IRQ on completion request */
1790 +#define BCM43xx_DMADTOR_FRAMEEND (1 << 30)
1791 +#define BCM43xx_DMADTOR_FRAMESTART (1 << 31)
1793 +/* Misc DMA constants */
1794 +#define BCM43xx_DMA_RINGMEMSIZE PAGE_SIZE
1795 +#define BCM43xx_DMA_BUSADDRMAX 0x3FFFFFFF
1796 +#define BCM43xx_DMA_DMABUSADDROFFSET (1 << 30)
1797 +#define BCM43xx_DMA1_RX_FRAMEOFFSET 30
1798 +#define BCM43xx_DMA4_RX_FRAMEOFFSET 0
1800 +/* DMA engine tuning knobs */
1801 +#define BCM43xx_TXRING_SLOTS 512
1802 +#define BCM43xx_RXRING_SLOTS 64
1803 +#define BCM43xx_DMA1_RXBUFFERSIZE (2304 + 100)
1804 +#define BCM43xx_DMA4_RXBUFFERSIZE 16
1808 +#ifdef CONFIG_BCM43XX_D80211_DMA
1812 +struct bcm43xx_private;
1813 +struct bcm43xx_xmitstatus;
1816 +struct bcm43xx_dmadesc {
1819 +} __attribute__((__packed__));
1821 +/* Macros to access the bcm43xx_dmadesc struct */
1822 +#define get_desc_ctl(desc) le32_to_cpu((desc)->_control)
1823 +#define set_desc_ctl(desc, ctl) do { (desc)->_control = cpu_to_le32(ctl); } while (0)
1824 +#define get_desc_addr(desc) le32_to_cpu((desc)->_address)
1825 +#define set_desc_addr(desc, addr) do { (desc)->_address = cpu_to_le32(addr); } while (0)
1827 +struct bcm43xx_dmadesc_meta {
1828 + /* The kernel DMA-able buffer. */
1829 + struct sk_buff *skb;
1830 + /* DMA base bus-address of the descriptor buffer. */
1831 + dma_addr_t dmaaddr;
1832 + /* ieee80211 TX status. Only used once per 802.11 frag. */
1833 + u8 must_xmit_txstat:1;
1834 + struct ieee80211_tx_status txstat;
1837 +struct bcm43xx_dmaring {
1838 + struct bcm43xx_private *bcm;
1839 + /* Kernel virtual base address of the ring memory. */
1840 + struct bcm43xx_dmadesc *vbase;
1841 + /* DMA memory offset */
1842 + dma_addr_t memoffset;
1843 + /* (Unadjusted) DMA base bus-address of the ring memory. */
1844 + dma_addr_t dmabase;
1845 + /* Meta data about all descriptors. */
1846 + struct bcm43xx_dmadesc_meta *meta;
1847 + /* Number of descriptor slots in the ring. */
1849 + /* Number of used descriptor slots. */
1851 + /* Currently used slot in the ring. */
1853 + /* Total number of packets sent. Statistics only. */
1854 + unsigned int nr_tx_packets;
1855 + /* Frameoffset in octets. */
1857 + /* Descriptor buffer size. */
1858 + u16 rx_buffersize;
1859 + /* The MMIO base register of the DMA controller, this
1860 + * ring is posted to.
1863 + u8 tx:1, /* TRUE, if this is a TX ring. */
1864 + suspended:1; /* TRUE, if transfers are suspended on this ring. */
1865 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1866 + /* Maximum number of used slots. */
1867 + int max_used_slots;
1868 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
1873 +u32 bcm43xx_dma_read(struct bcm43xx_dmaring *ring,
1876 + return bcm43xx_read32(ring->bcm, ring->mmio_base + offset);
1880 +void bcm43xx_dma_write(struct bcm43xx_dmaring *ring,
1881 + u16 offset, u32 value)
1883 + bcm43xx_write32(ring->bcm, ring->mmio_base + offset, value);
1887 +int bcm43xx_dma_init(struct bcm43xx_private *bcm);
1888 +void bcm43xx_dma_free(struct bcm43xx_private *bcm);
1890 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1891 + u16 dmacontroller_mmio_base);
1892 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1893 + u16 dmacontroller_mmio_base);
1895 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring);
1896 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring);
1898 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1899 + struct ieee80211_tx_queue_stats *stats);
1901 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1902 + struct sk_buff *skb,
1903 + struct ieee80211_tx_control *ctl);
1904 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1905 + struct bcm43xx_xmitstatus *status);
1907 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring);
1910 +#else /* CONFIG_BCM43XX_D80211_DMA */
1914 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1919 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1923 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1924 + u16 dmacontroller_mmio_base)
1929 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1930 + u16 dmacontroller_mmio_base)
1935 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1936 + struct ieee80211_tx_queue_stats *stats)
1940 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1941 + struct sk_buff *skb,
1942 + struct ieee80211_tx_control *ctl)
1947 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1948 + struct bcm43xx_xmitstatus *status)
1952 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1956 +#endif /* CONFIG_BCM43XX_D80211_DMA */
1957 +#endif /* BCM43xx_DMA_H_ */
1958 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
1959 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c 1970-01-01 01:00:00.000000000 +0100
1960 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.c 2006-03-28 22:16:14.000000000 +0200
1964 + Broadcom BCM43xx wireless driver
1968 + Copyright (c) 2006 Jason Lunz <lunz@falooley.org>
1970 + Some code in this file is derived from the 8139too.c driver
1971 + Copyright (C) 2002 Jeff Garzik
1973 + This program is free software; you can redistribute it and/or modify
1974 + it under the terms of the GNU General Public License as published by
1975 + the Free Software Foundation; either version 2 of the License, or
1976 + (at your option) any later version.
1978 + This program is distributed in the hope that it will be useful,
1979 + but WITHOUT ANY WARRANTY; without even the implied warranty of
1980 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1981 + GNU General Public License for more details.
1983 + You should have received a copy of the GNU General Public License
1984 + along with this program; see the file COPYING. If not, write to
1985 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
1986 + Boston, MA 02110-1301, USA.
1990 +#include "bcm43xx.h"
1991 +#include "bcm43xx_ethtool.h"
1993 +#include <linux/netdevice.h>
1994 +#include <linux/pci.h>
1995 +#include <linux/string.h>
1996 +#include <linux/version.h>
1999 +static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2001 + struct bcm43xx_private *bcm = bcm43xx_priv(dev);
2003 + strncpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
2004 + strncpy(info->version, UTS_RELEASE, sizeof(info->version));
2005 + strncpy(info->bus_info, pci_name(bcm->pci_dev), ETHTOOL_BUSINFO_LEN);
2008 +struct ethtool_ops bcm43xx_ethtool_ops = {
2009 + .get_drvinfo = bcm43xx_get_drvinfo,
2010 + .get_link = ethtool_op_get_link,
2012 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
2013 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h 1970-01-01 01:00:00.000000000 +0100
2014 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ethtool.h 2006-03-28 22:16:14.000000000 +0200
2016 +#ifndef BCM43xx_ETHTOOL_H_
2017 +#define BCM43xx_ETHTOOL_H_
2019 +#include <linux/ethtool.h>
2021 +extern struct ethtool_ops bcm43xx_ethtool_ops;
2023 +#endif /* BCM43xx_ETHTOOL_H_ */
2024 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
2025 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h 1970-01-01 01:00:00.000000000 +0100
2026 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx.h 2006-03-28 22:16:14.000000000 +0200
2031 +#include <linux/version.h>
2032 +#include <linux/kernel.h>
2033 +#include <linux/spinlock.h>
2034 +#include <linux/interrupt.h>
2035 +#include <linux/stringify.h>
2036 +#include <linux/netdevice.h>
2037 +#include <linux/pci.h>
2038 +#include <asm/atomic.h>
2039 +#include <asm/io.h>
2041 +#include <linux/wireless.h>
2042 +#include <net/d80211.h>
2043 +#include <net/d80211_mgmt.h>
2044 +#include <net/d80211_common.h>
2046 +#include "bcm43xx_debugfs.h"
2047 +#include "bcm43xx_leds.h"
2048 +#include "bcm43xx_sysfs.h"
2051 +#define PFX KBUILD_MODNAME ": "
2053 +#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
2054 +#define BCM43xx_IRQWAIT_MAX_RETRIES 50
2056 +#define BCM43xx_IO_SIZE 8192
2058 +/* Active Core PCI Configuration Register. */
2059 +#define BCM43xx_PCICFG_ACTIVE_CORE 0x80
2060 +/* SPROM control register. */
2061 +#define BCM43xx_PCICFG_SPROMCTL 0x88
2062 +/* Interrupt Control PCI Configuration Register. (Only on PCI cores with rev >= 6) */
2063 +#define BCM43xx_PCICFG_ICR 0x94
2066 +#define BCM43xx_MMIO_DMA1_REASON 0x20
2067 +#define BCM43xx_MMIO_DMA1_IRQ_MASK 0x24
2068 +#define BCM43xx_MMIO_DMA2_REASON 0x28
2069 +#define BCM43xx_MMIO_DMA2_IRQ_MASK 0x2C
2070 +#define BCM43xx_MMIO_DMA3_REASON 0x30
2071 +#define BCM43xx_MMIO_DMA3_IRQ_MASK 0x34
2072 +#define BCM43xx_MMIO_DMA4_REASON 0x38
2073 +#define BCM43xx_MMIO_DMA4_IRQ_MASK 0x3C
2074 +#define BCM43xx_MMIO_STATUS_BITFIELD 0x120
2075 +#define BCM43xx_MMIO_STATUS2_BITFIELD 0x124
2076 +#define BCM43xx_MMIO_GEN_IRQ_REASON 0x128
2077 +#define BCM43xx_MMIO_GEN_IRQ_MASK 0x12C
2078 +#define BCM43xx_MMIO_RAM_CONTROL 0x130
2079 +#define BCM43xx_MMIO_RAM_DATA 0x134
2080 +#define BCM43xx_MMIO_PS_STATUS 0x140
2081 +#define BCM43xx_MMIO_RADIO_HWENABLED_HI 0x158
2082 +#define BCM43xx_MMIO_SHM_CONTROL 0x160
2083 +#define BCM43xx_MMIO_SHM_DATA 0x164
2084 +#define BCM43xx_MMIO_SHM_DATA_UNALIGNED 0x166
2085 +#define BCM43xx_MMIO_XMITSTAT_0 0x170
2086 +#define BCM43xx_MMIO_XMITSTAT_1 0x174
2087 +#define BCM43xx_MMIO_REV3PLUS_TSF_LOW 0x180 /* core rev >= 3 only */
2088 +#define BCM43xx_MMIO_REV3PLUS_TSF_HIGH 0x184 /* core rev >= 3 only */
2089 +#define BCM43xx_MMIO_DMA1_BASE 0x200
2090 +#define BCM43xx_MMIO_DMA2_BASE 0x220
2091 +#define BCM43xx_MMIO_DMA3_BASE 0x240
2092 +#define BCM43xx_MMIO_DMA4_BASE 0x260
2093 +#define BCM43xx_MMIO_PIO1_BASE 0x300
2094 +#define BCM43xx_MMIO_PIO2_BASE 0x310
2095 +#define BCM43xx_MMIO_PIO3_BASE 0x320
2096 +#define BCM43xx_MMIO_PIO4_BASE 0x330
2097 +#define BCM43xx_MMIO_PHY_VER 0x3E0
2098 +#define BCM43xx_MMIO_PHY_RADIO 0x3E2
2099 +#define BCM43xx_MMIO_ANTENNA 0x3E8
2100 +#define BCM43xx_MMIO_CHANNEL 0x3F0
2101 +#define BCM43xx_MMIO_CHANNEL_EXT 0x3F4
2102 +#define BCM43xx_MMIO_RADIO_CONTROL 0x3F6
2103 +#define BCM43xx_MMIO_RADIO_DATA_HIGH 0x3F8
2104 +#define BCM43xx_MMIO_RADIO_DATA_LOW 0x3FA
2105 +#define BCM43xx_MMIO_PHY_CONTROL 0x3FC
2106 +#define BCM43xx_MMIO_PHY_DATA 0x3FE
2107 +#define BCM43xx_MMIO_MACFILTER_CONTROL 0x420
2108 +#define BCM43xx_MMIO_MACFILTER_DATA 0x422
2109 +#define BCM43xx_MMIO_RADIO_HWENABLED_LO 0x49A
2110 +#define BCM43xx_MMIO_GPIO_CONTROL 0x49C
2111 +#define BCM43xx_MMIO_GPIO_MASK 0x49E
2112 +#define BCM43xx_MMIO_TSF_0 0x632 /* core rev < 3 only */
2113 +#define BCM43xx_MMIO_TSF_1 0x634 /* core rev < 3 only */
2114 +#define BCM43xx_MMIO_TSF_2 0x636 /* core rev < 3 only */
2115 +#define BCM43xx_MMIO_TSF_3 0x638 /* core rev < 3 only */
2116 +#define BCM43xx_MMIO_POWERUP_DELAY 0x6A8
2118 +/* SPROM offsets. */
2119 +#define BCM43xx_SPROM_BASE 0x1000
2120 +#define BCM43xx_SPROM_BOARDFLAGS2 0x1c
2121 +#define BCM43xx_SPROM_IL0MACADDR 0x24
2122 +#define BCM43xx_SPROM_ET0MACADDR 0x27
2123 +#define BCM43xx_SPROM_ET1MACADDR 0x2a
2124 +#define BCM43xx_SPROM_ETHPHY 0x2d
2125 +#define BCM43xx_SPROM_BOARDREV 0x2e
2126 +#define BCM43xx_SPROM_PA0B0 0x2f
2127 +#define BCM43xx_SPROM_PA0B1 0x30
2128 +#define BCM43xx_SPROM_PA0B2 0x31
2129 +#define BCM43xx_SPROM_WL0GPIO0 0x32
2130 +#define BCM43xx_SPROM_WL0GPIO2 0x33
2131 +#define BCM43xx_SPROM_MAXPWR 0x34
2132 +#define BCM43xx_SPROM_PA1B0 0x35
2133 +#define BCM43xx_SPROM_PA1B1 0x36
2134 +#define BCM43xx_SPROM_PA1B2 0x37
2135 +#define BCM43xx_SPROM_IDL_TSSI_TGT 0x38
2136 +#define BCM43xx_SPROM_BOARDFLAGS 0x39
2137 +#define BCM43xx_SPROM_ANTENNA_GAIN 0x3a
2138 +#define BCM43xx_SPROM_VERSION 0x3f
2140 +/* BCM43xx_SPROM_BOARDFLAGS values */
2141 +#define BCM43xx_BFL_BTCOEXIST 0x0001 /* implements Bluetooth coexistance */
2142 +#define BCM43xx_BFL_PACTRL 0x0002 /* GPIO 9 controlling the PA */
2143 +#define BCM43xx_BFL_AIRLINEMODE 0x0004 /* implements GPIO 13 radio disable indication */
2144 +#define BCM43xx_BFL_RSSI 0x0008 /* software calculates nrssi slope. */
2145 +#define BCM43xx_BFL_ENETSPI 0x0010 /* has ephy roboswitch spi */
2146 +#define BCM43xx_BFL_XTAL_NOSLOW 0x0020 /* no slow clock available */
2147 +#define BCM43xx_BFL_CCKHIPWR 0x0040 /* can do high power CCK transmission */
2148 +#define BCM43xx_BFL_ENETADM 0x0080 /* has ADMtek switch */
2149 +#define BCM43xx_BFL_ENETVLAN 0x0100 /* can do vlan */
2150 +#define BCM43xx_BFL_AFTERBURNER 0x0200 /* supports Afterburner mode */
2151 +#define BCM43xx_BFL_NOPCI 0x0400 /* leaves PCI floating */
2152 +#define BCM43xx_BFL_FEM 0x0800 /* supports the Front End Module */
2153 +#define BCM43xx_BFL_EXTLNA 0x1000 /* has an external LNA */
2154 +#define BCM43xx_BFL_HGPA 0x2000 /* had high gain PA */
2155 +#define BCM43xx_BFL_BTCMOD 0x4000 /* BFL_BTCOEXIST is given in alternate GPIOs */
2156 +#define BCM43xx_BFL_ALTIQ 0x8000 /* alternate I/Q settings */
2158 +/* GPIO register offset, in both ChipCommon and PCI core. */
2159 +#define BCM43xx_GPIO_CONTROL 0x6c
2162 +#define BCM43xx_SHM_SHARED 0x0001
2163 +#define BCM43xx_SHM_WIRELESS 0x0002
2164 +#define BCM43xx_SHM_PCM 0x0003
2165 +#define BCM43xx_SHM_HWMAC 0x0004
2166 +#define BCM43xx_SHM_UCODE 0x0300
2168 +/* MacFilter offsets. */
2169 +#define BCM43xx_MACFILTER_SELF 0x0000
2170 +#define BCM43xx_MACFILTER_ASSOC 0x0003
2172 +/* Chipcommon registers. */
2173 +#define BCM43xx_CHIPCOMMON_CAPABILITIES 0x04
2174 +#define BCM43xx_CHIPCOMMON_PLLONDELAY 0xB0
2175 +#define BCM43xx_CHIPCOMMON_FREFSELDELAY 0xB4
2176 +#define BCM43xx_CHIPCOMMON_SLOWCLKCTL 0xB8
2177 +#define BCM43xx_CHIPCOMMON_SYSCLKCTL 0xC0
2179 +/* PCI core specific registers. */
2180 +#define BCM43xx_PCICORE_BCAST_ADDR 0x50
2181 +#define BCM43xx_PCICORE_BCAST_DATA 0x54
2182 +#define BCM43xx_PCICORE_SBTOPCI2 0x108
2184 +/* SBTOPCI2 values. */
2185 +#define BCM43xx_SBTOPCI2_PREFETCH 0x4
2186 +#define BCM43xx_SBTOPCI2_BURST 0x8
2188 +/* Chipcommon capabilities. */
2189 +#define BCM43xx_CAPABILITIES_PCTL 0x00040000
2190 +#define BCM43xx_CAPABILITIES_PLLMASK 0x00030000
2191 +#define BCM43xx_CAPABILITIES_PLLSHIFT 16
2192 +#define BCM43xx_CAPABILITIES_FLASHMASK 0x00000700
2193 +#define BCM43xx_CAPABILITIES_FLASHSHIFT 8
2194 +#define BCM43xx_CAPABILITIES_EXTBUSPRESENT 0x00000040
2195 +#define BCM43xx_CAPABILITIES_UARTGPIO 0x00000020
2196 +#define BCM43xx_CAPABILITIES_UARTCLOCKMASK 0x00000018
2197 +#define BCM43xx_CAPABILITIES_UARTCLOCKSHIFT 3
2198 +#define BCM43xx_CAPABILITIES_MIPSBIGENDIAN 0x00000004
2199 +#define BCM43xx_CAPABILITIES_NRUARTSMASK 0x00000003
2202 +#define BCM43xx_PCTL_IN 0xB0
2203 +#define BCM43xx_PCTL_OUT 0xB4
2204 +#define BCM43xx_PCTL_OUTENABLE 0xB8
2205 +#define BCM43xx_PCTL_XTAL_POWERUP 0x40
2206 +#define BCM43xx_PCTL_PLL_POWERDOWN 0x80
2208 +/* PowerControl Clock Modes */
2209 +#define BCM43xx_PCTL_CLK_FAST 0x00
2210 +#define BCM43xx_PCTL_CLK_SLOW 0x01
2211 +#define BCM43xx_PCTL_CLK_DYNAMIC 0x02
2213 +#define BCM43xx_PCTL_FORCE_SLOW 0x0800
2214 +#define BCM43xx_PCTL_FORCE_PLL 0x1000
2215 +#define BCM43xx_PCTL_DYN_XTAL 0x2000
2218 +#define BCM43xx_COREID_CHIPCOMMON 0x800
2219 +#define BCM43xx_COREID_ILINE20 0x801
2220 +#define BCM43xx_COREID_SDRAM 0x803
2221 +#define BCM43xx_COREID_PCI 0x804
2222 +#define BCM43xx_COREID_MIPS 0x805
2223 +#define BCM43xx_COREID_ETHERNET 0x806
2224 +#define BCM43xx_COREID_V90 0x807
2225 +#define BCM43xx_COREID_USB11_HOSTDEV 0x80a
2226 +#define BCM43xx_COREID_IPSEC 0x80b
2227 +#define BCM43xx_COREID_PCMCIA 0x80d
2228 +#define BCM43xx_COREID_EXT_IF 0x80f
2229 +#define BCM43xx_COREID_80211 0x812
2230 +#define BCM43xx_COREID_MIPS_3302 0x816
2231 +#define BCM43xx_COREID_USB11_HOST 0x817
2232 +#define BCM43xx_COREID_USB11_DEV 0x818
2233 +#define BCM43xx_COREID_USB20_HOST 0x819
2234 +#define BCM43xx_COREID_USB20_DEV 0x81a
2235 +#define BCM43xx_COREID_SDIO_HOST 0x81b
2237 +/* Core Information Registers */
2238 +#define BCM43xx_CIR_BASE 0xf00
2239 +#define BCM43xx_CIR_SBTPSFLAG (BCM43xx_CIR_BASE + 0x18)
2240 +#define BCM43xx_CIR_SBIMSTATE (BCM43xx_CIR_BASE + 0x90)
2241 +#define BCM43xx_CIR_SBINTVEC (BCM43xx_CIR_BASE + 0x94)
2242 +#define BCM43xx_CIR_SBTMSTATELOW (BCM43xx_CIR_BASE + 0x98)
2243 +#define BCM43xx_CIR_SBTMSTATEHIGH (BCM43xx_CIR_BASE + 0x9c)
2244 +#define BCM43xx_CIR_SBIMCONFIGLOW (BCM43xx_CIR_BASE + 0xa8)
2245 +#define BCM43xx_CIR_SB_ID_HI (BCM43xx_CIR_BASE + 0xfc)
2247 +/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
2248 +#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
2250 +/* SBIMCONFIGLOW values/masks. */
2251 +#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK 0x00000007
2252 +#define BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT 0
2253 +#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK 0x00000070
2254 +#define BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT 4
2255 +#define BCM43xx_SBIMCONFIGLOW_CONNID_MASK 0x00ff0000
2256 +#define BCM43xx_SBIMCONFIGLOW_CONNID_SHIFT 16
2258 +/* sbtmstatelow state flags */
2259 +#define BCM43xx_SBTMSTATELOW_RESET 0x01
2260 +#define BCM43xx_SBTMSTATELOW_REJECT 0x02
2261 +#define BCM43xx_SBTMSTATELOW_CLOCK 0x10000
2262 +#define BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK 0x20000
2264 +/* sbtmstatehigh state flags */
2265 +#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
2266 +#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
2268 +/* sbimstate flags */
2269 +#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
2270 +#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
2272 +/* PHYVersioning */
2273 +#define BCM43xx_PHYTYPE_A 0x00
2274 +#define BCM43xx_PHYTYPE_B 0x01
2275 +#define BCM43xx_PHYTYPE_G 0x02
2278 +#define BCM43xx_PHY_ILT_A_CTRL 0x0072
2279 +#define BCM43xx_PHY_ILT_A_DATA1 0x0073
2280 +#define BCM43xx_PHY_ILT_A_DATA2 0x0074
2281 +#define BCM43xx_PHY_G_LO_CONTROL 0x0810
2282 +#define BCM43xx_PHY_ILT_G_CTRL 0x0472
2283 +#define BCM43xx_PHY_ILT_G_DATA1 0x0473
2284 +#define BCM43xx_PHY_ILT_G_DATA2 0x0474
2285 +#define BCM43xx_PHY_A_PCTL 0x007B
2286 +#define BCM43xx_PHY_G_PCTL 0x0029
2287 +#define BCM43xx_PHY_A_CRS 0x0029
2288 +#define BCM43xx_PHY_RADIO_BITFIELD 0x0401
2289 +#define BCM43xx_PHY_G_CRS 0x0429
2290 +#define BCM43xx_PHY_NRSSILT_CTRL 0x0803
2291 +#define BCM43xx_PHY_NRSSILT_DATA 0x0804
2293 +/* RadioRegisters */
2294 +#define BCM43xx_RADIOCTL_ID 0x01
2296 +/* StatusBitField */
2297 +#define BCM43xx_SBF_MAC_ENABLED 0x00000001
2298 +#define BCM43xx_SBF_2 0x00000002 /*FIXME: fix name*/
2299 +#define BCM43xx_SBF_CORE_READY 0x00000004
2300 +#define BCM43xx_SBF_400 0x00000400 /*FIXME: fix name*/
2301 +#define BCM43xx_SBF_4000 0x00004000 /*FIXME: fix name*/
2302 +#define BCM43xx_SBF_8000 0x00008000 /*FIXME: fix name*/
2303 +#define BCM43xx_SBF_XFER_REG_BYTESWAP 0x00010000
2304 +#define BCM43xx_SBF_MODE_NOTADHOC 0x00020000
2305 +#define BCM43xx_SBF_MODE_AP 0x00040000
2306 +#define BCM43xx_SBF_RADIOREG_LOCK 0x00080000
2307 +#define BCM43xx_SBF_MODE_MONITOR 0x00400000
2308 +#define BCM43xx_SBF_MODE_PROMISC 0x01000000
2309 +#define BCM43xx_SBF_PS1 0x02000000
2310 +#define BCM43xx_SBF_PS2 0x04000000
2311 +#define BCM43xx_SBF_NO_SSID_BCAST 0x08000000
2312 +#define BCM43xx_SBF_TIME_UPDATE 0x10000000
2313 +#define BCM43xx_SBF_80000000 0x80000000 /*FIXME: fix name*/
2315 +/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
2316 +#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
2318 +#define BCM43xx_UCODEFLAG_AUTODIV 0x0001
2319 +#define BCM43xx_UCODEFLAG_UNKBGPHY 0x0002
2320 +#define BCM43xx_UCODEFLAG_UNKBPHY 0x0004
2321 +#define BCM43xx_UCODEFLAG_UNKGPHY 0x0020
2322 +#define BCM43xx_UCODEFLAG_UNKPACTRL 0x0040
2323 +#define BCM43xx_UCODEFLAG_JAPAN 0x0080
2325 +/* Generic-Interrupt reasons. */
2326 +#define BCM43xx_IRQ_READY (1 << 0)
2327 +#define BCM43xx_IRQ_BEACON (1 << 1)
2328 +#define BCM43xx_IRQ_PS (1 << 2)
2329 +#define BCM43xx_IRQ_REG124 (1 << 5)
2330 +#define BCM43xx_IRQ_PMQ (1 << 6)
2331 +#define BCM43xx_IRQ_PIO_WORKAROUND (1 << 8)
2332 +#define BCM43xx_IRQ_XMIT_ERROR (1 << 11)
2333 +#define BCM43xx_IRQ_RX (1 << 15)
2334 +#define BCM43xx_IRQ_SCAN (1 << 16)
2335 +#define BCM43xx_IRQ_NOISE (1 << 18)
2336 +#define BCM43xx_IRQ_XMIT_STATUS (1 << 29)
2338 +#define BCM43xx_IRQ_ALL 0xffffffff
2339 +#define BCM43xx_IRQ_INITIAL (BCM43xx_IRQ_PS | \
2340 + BCM43xx_IRQ_REG124 | \
2341 + BCM43xx_IRQ_PMQ | \
2342 + BCM43xx_IRQ_XMIT_ERROR | \
2343 + BCM43xx_IRQ_RX | \
2344 + BCM43xx_IRQ_SCAN | \
2345 + BCM43xx_IRQ_NOISE | \
2346 + BCM43xx_IRQ_XMIT_STATUS)
2348 +/* Bus type PCI. */
2349 +#define BCM43xx_BUSTYPE_PCI 0
2350 +/* Bus type Silicone Backplane Bus. */
2351 +#define BCM43xx_BUSTYPE_SB 1
2352 +/* Bus type PCMCIA. */
2353 +#define BCM43xx_BUSTYPE_PCMCIA 2
2356 +#define BCM43xx_CCK_RATE_1MB 0x02
2357 +#define BCM43xx_CCK_RATE_2MB 0x04
2358 +#define BCM43xx_CCK_RATE_5MB 0x0B
2359 +#define BCM43xx_CCK_RATE_11MB 0x16
2360 +#define BCM43xx_OFDM_RATE_6MB 0x0C
2361 +#define BCM43xx_OFDM_RATE_9MB 0x12
2362 +#define BCM43xx_OFDM_RATE_12MB 0x18
2363 +#define BCM43xx_OFDM_RATE_18MB 0x24
2364 +#define BCM43xx_OFDM_RATE_24MB 0x30
2365 +#define BCM43xx_OFDM_RATE_36MB 0x48
2366 +#define BCM43xx_OFDM_RATE_48MB 0x60
2367 +#define BCM43xx_OFDM_RATE_54MB 0x6C
2369 +#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
2370 +#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
2372 +/* Max size of a security key */
2373 +#define BCM43xx_SEC_KEYSIZE 16
2374 +/* Security algorithms. */
2376 + BCM43xx_SEC_ALGO_NONE = 0, /* unencrypted, as of TX header. */
2377 + BCM43xx_SEC_ALGO_WEP,
2378 + BCM43xx_SEC_ALGO_UNKNOWN,
2379 + BCM43xx_SEC_ALGO_AES,
2380 + BCM43xx_SEC_ALGO_WEP104,
2381 + BCM43xx_SEC_ALGO_TKIP,
2388 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2389 +#define assert(expr) \
2391 + if (unlikely(!(expr))) { \
2392 + printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
2393 + #expr, __FILE__, __LINE__, __FUNCTION__); \
2397 +#define assert(expr) do { /* nothing */ } while (0)
2400 +/* rate limited printk(). */
2404 +#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
2405 +/* rate limited printk() for debugging */
2409 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2410 +# define dprintkl printkl
2412 +# define dprintkl(f, x...) do { /* nothing */ } while (0)
2415 +/* debugging printk() */
2419 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2420 +# define dprintk(f, x...) do { printk(f ,##x); } while (0)
2422 +# define dprintk(f, x...) do { /* nothing */ } while (0)
2428 +struct bcm43xx_dmaring;
2429 +struct bcm43xx_pioqueue;
2431 +struct bcm43xx_initval {
2435 +} __attribute__((__packed__));
2437 +/* Values for bcm430x_sprominfo.locale */
2439 + BCM43xx_LOCALE_WORLD = 0,
2440 + BCM43xx_LOCALE_THAILAND,
2441 + BCM43xx_LOCALE_ISRAEL,
2442 + BCM43xx_LOCALE_JORDAN,
2443 + BCM43xx_LOCALE_CHINA,
2444 + BCM43xx_LOCALE_JAPAN,
2445 + BCM43xx_LOCALE_USA_CANADA_ANZ,
2446 + BCM43xx_LOCALE_EUROPE,
2447 + BCM43xx_LOCALE_USA_LOW,
2448 + BCM43xx_LOCALE_JAPAN_HIGH,
2449 + BCM43xx_LOCALE_ALL,
2450 + BCM43xx_LOCALE_NONE,
2453 +#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
2454 +struct bcm43xx_sprominfo {
2465 + u8 antennas_aphy:2;
2466 + u8 antennas_bgphy:2;
2475 + u8 maxpower_bgphy;
2479 + u8 idle_tssi_tgt_aphy;
2480 + u8 idle_tssi_tgt_bgphy;
2482 + u16 antennagain_aphy;
2483 + u16 antennagain_bgphy;
2486 +/* Value pair to measure the LocalOscillator. */
2487 +struct bcm43xx_lopair {
2492 +#define BCM43xx_LO_COUNT (14*4)
2494 +struct bcm43xx_phyinfo {
2495 + /* Hardware Data */
2499 + u16 antenna_diversity;
2502 + u16 minlowsigpos[2];
2505 + is_locked:1, /* used in bcm43xx_phy_{un}lock() */
2506 + dyn_tssi_tbl:1; /* used in bcm43xx_phy_init_tssi2dbm_table() */
2507 + /* LO Measurement Data.
2508 + * Use bcm43xx_get_lopair() to get a value.
2510 + struct bcm43xx_lopair *_lo_pairs;
2512 + /* TSSI to dBm table in use */
2513 + const s8 *tssi2dbm;
2514 + /* idle TSSI value */
2517 + /* Values from bcm43xx_calc_loopback_gain() */
2518 + u16 loopback_gain[2];
2520 + /* PHY lock for core.rev < 3
2521 + * This lock is only used by bcm43xx_phy_{un}lock()
2527 +struct bcm43xx_radioinfo {
2532 + /* Desired TX power level (in dBm).
2533 + * This is set by the user and adjusted in bcm43xx_phy_xmitpower(). */
2535 + /* TX Power control values. */
2539 + u16 baseband_atten;
2550 + /* Current Interference Mitigation mode */
2552 + /* Stack of saved values from the Interference Mitigation code.
2553 + * Each value in the stack is layed out as follows:
2554 + * bit 0-11: offset
2555 + * bit 12-15: register ID
2556 + * bit 16-32: value
2557 + * register ID is: 0x1 PHY, 0x2 Radio, 0x3 ILT
2559 +#define BCM43xx_INTERFSTACK_SIZE 26
2560 + u32 interfstack[BCM43xx_INTERFSTACK_SIZE];
2562 + /* Saved values from the NRSSI Slope calculation */
2565 + /* In memory nrssi lookup table. */
2568 + /* current channel */
2570 + u8 initial_channel;
2577 + /* ACI (adjacent channel interference) flags. */
2579 + aci_wlan_automatic:1,
2583 +/* Data structures for DMA transmission, per 80211 core. */
2584 +struct bcm43xx_dma {
2585 + struct bcm43xx_dmaring *tx_ring0;
2586 + struct bcm43xx_dmaring *tx_ring1;
2587 + struct bcm43xx_dmaring *tx_ring2;
2588 + struct bcm43xx_dmaring *tx_ring3;
2589 + struct bcm43xx_dmaring *rx_ring0;
2590 + struct bcm43xx_dmaring *rx_ring1; /* only available on core.rev < 5 */
2593 +/* Data structures for PIO transmission, per 80211 core. */
2594 +struct bcm43xx_pio {
2595 + struct bcm43xx_pioqueue *queue0;
2596 + struct bcm43xx_pioqueue *queue1;
2597 + struct bcm43xx_pioqueue *queue2;
2598 + struct bcm43xx_pioqueue *queue3;
2601 +#define BCM43xx_MAX_80211_CORES 2
2603 +#ifdef CONFIG_BCM947XX
2604 +#define core_offset(bcm) (bcm)->current_core_offset
2606 +#define core_offset(bcm) 0
2609 +/* Generic information about a core. */
2610 +struct bcm43xx_coreinfo {
2614 + /** core_id ID number */
2616 + /** core_rev revision number */
2618 + /** Index number for _switch_core() */
2622 +/* Additional information for each 80211 core. */
2623 +struct bcm43xx_coreinfo_80211 {
2625 + struct bcm43xx_phyinfo phy;
2626 + /* Radio device. */
2627 + struct bcm43xx_radioinfo radio;
2629 + /* DMA context. */
2630 + struct bcm43xx_dma dma;
2631 + /* PIO context. */
2632 + struct bcm43xx_pio pio;
2636 +/* Context information for a noise calculation (Link Quality). */
2637 +struct bcm43xx_noise_calculation {
2638 + struct bcm43xx_coreinfo *core_at_start;
2639 + u8 channel_at_start;
2640 + u8 calculation_running:1;
2645 +struct bcm43xx_stats {
2647 + /* Store the last TX/RX times here for updating the leds. */
2648 + unsigned long last_tx;
2649 + unsigned long last_rx;
2652 +struct bcm43xx_key {
2657 +struct bcm43xx_private {
2658 + struct bcm43xx_sysfs sysfs;
2660 + struct ieee80211_hw *ieee;
2661 + struct ieee80211_low_level_stats ieee_stats;
2664 + struct net_device *net_dev;
2665 + struct pci_dev *pci_dev;
2668 + void __iomem *mmio_addr;
2669 + unsigned int mmio_len;
2671 + /* Do not use the lock directly. Use the bcm43xx_lock* helper
2672 + * functions, to be MMIO-safe. */
2675 + /* Driver status flags. */
2676 + u32 initialized:1, /* init_board() succeed */
2677 + was_initialized:1, /* for PCI suspend/resume. */
2678 + shutting_down:1, /* free_board() in progress */
2679 + __using_pio:1, /* Internal, use bcm43xx_using_pio(). */
2680 + bad_frames_preempt:1, /* Use "Bad Frames Preemption" (default off) */
2681 + reg124_set_0x4:1, /* Some variable to keep track of IRQ stuff. */
2682 + powersaving:1, /* TRUE if we are in PowerSaving mode. FALSE otherwise. */
2683 + short_preamble:1, /* TRUE, if short preamble is enabled. */
2684 + short_slot:1, /* TRUE, if short slot timing is enabled. */
2685 + firmware_norelease:1; /* Do not release the firmware. Used on suspend. */
2687 + struct bcm43xx_stats stats;
2689 + /* Bus type we are connected to.
2690 + * This is currently always BCM43xx_BUSTYPE_PCI
2696 + u16 board_revision;
2702 + struct bcm43xx_sprominfo sprom;
2703 +#define BCM43xx_NR_LEDS 4
2704 + struct bcm43xx_led leds[BCM43xx_NR_LEDS];
2706 + /* The currently active core. */
2707 + struct bcm43xx_coreinfo *current_core;
2708 +#ifdef CONFIG_BCM947XX
2709 + /** current core memory offset */
2710 + u32 current_core_offset;
2712 + struct bcm43xx_coreinfo *active_80211_core;
2713 + /* coreinfo structs for all possible cores follow.
2714 + * Note that a core might not exist.
2715 + * So check the coreinfo flags before using it.
2717 + struct bcm43xx_coreinfo core_chipcommon;
2718 + struct bcm43xx_coreinfo core_pci;
2719 + struct bcm43xx_coreinfo core_80211[ BCM43xx_MAX_80211_CORES ];
2720 + /* Additional information, specific to the 80211 cores. */
2721 + struct bcm43xx_coreinfo_80211 core_80211_ext[ BCM43xx_MAX_80211_CORES ];
2722 + /* Index of the current 80211 core. If current_core is not
2723 + * an 80211 core, this is -1.
2725 + int current_80211_core_idx;
2726 + /* Number of available 80211 cores. */
2727 + int nr_80211_available;
2729 + u32 chipcommon_capabilities;
2731 + /* Reason code of the last interrupt. */
2733 + u32 dma_reason[4];
2734 + /* saved irq enable/disable state bitfield. */
2735 + u32 irq_savedstate;
2736 + /* Link Quality calculation context. */
2737 + struct bcm43xx_noise_calculation noisecalc;
2739 + /* Interrupt Service Routine tasklet (bottom-half) */
2740 + struct tasklet_struct isr_tasklet;
2742 + /* Periodic tasks */
2743 + struct timer_list periodic_tasks;
2744 + unsigned int periodic_state;
2746 + struct work_struct restart_work;
2748 + /* Informational stuff. */
2749 + char nick[IW_ESSID_MAX_SIZE + 1];
2750 + u8 bssid[ETH_ALEN];
2752 + /* encryption/decryption */
2753 + u16 security_offset;
2754 + struct bcm43xx_key key[54];
2755 + u8 default_key_idx;
2758 + const struct firmware *ucode;
2759 + const struct firmware *pcm;
2760 + const struct firmware *initvals0;
2761 + const struct firmware *initvals1;
2763 + /* Cached beacon template while uploading the template. */
2764 + struct sk_buff *cached_beacon;
2766 + /* Debugging stuff follows. */
2767 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2768 + struct bcm43xx_dfsentry *dfsentry;
2772 +/* bcm43xx_(un)lock() protect struct bcm43xx_private.
2773 + * Note that _NO_ MMIO writes are allowed. If you want to
2774 + * write to the device through MMIO in the critical section, use
2775 + * the *_mmio lock functions.
2776 + * MMIO read-access is allowed, though.
2778 +#define bcm43xx_lock(bcm, flags) spin_lock_irqsave(&(bcm)->_lock, flags)
2779 +#define bcm43xx_unlock(bcm, flags) spin_unlock_irqrestore(&(bcm)->_lock, flags)
2780 +/* bcm43xx_(un)lock_mmio() protect struct bcm43xx_private and MMIO.
2781 + * MMIO write-access to the device is allowed.
2782 + * All MMIO writes are flushed on unlock, so it is guaranteed to not
2783 + * interfere with other threads writing MMIO registers.
2785 +#define bcm43xx_lock_mmio(bcm, flags) bcm43xx_lock(bcm, flags)
2786 +#define bcm43xx_unlock_mmio(bcm, flags) do { mmiowb(); bcm43xx_unlock(bcm, flags); } while (0)
2789 +struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
2791 + return ieee80211_dev_hw_data(dev);
2794 +/* Helper function, which returns a boolean.
2795 + * TRUE, if PIO is used; FALSE, if DMA is used.
2797 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
2799 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2801 + return bcm->__using_pio;
2803 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
2805 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2809 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
2811 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2816 +# error "Using neither DMA nor PIO? Confused..."
2819 +/* Helper functions to access data structures private to the 80211 cores.
2820 + * Note that we _must_ have an 80211 core mapped when calling
2821 + * any of these functions.
2824 +struct bcm43xx_pio * bcm43xx_current_pio(struct bcm43xx_private *bcm)
2826 + assert(bcm43xx_using_pio(bcm));
2827 + assert(bcm->current_80211_core_idx >= 0);
2828 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2829 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].pio);
2832 +struct bcm43xx_dma * bcm43xx_current_dma(struct bcm43xx_private *bcm)
2834 + assert(!bcm43xx_using_pio(bcm));
2835 + assert(bcm->current_80211_core_idx >= 0);
2836 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2837 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].dma);
2840 +struct bcm43xx_phyinfo * bcm43xx_current_phy(struct bcm43xx_private *bcm)
2842 + assert(bcm->current_80211_core_idx >= 0);
2843 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2844 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].phy);
2847 +struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
2849 + assert(bcm->current_80211_core_idx >= 0);
2850 + assert(bcm->current_80211_core_idx < BCM43xx_MAX_80211_CORES);
2851 + return &(bcm->core_80211_ext[bcm->current_80211_core_idx].radio);
2854 +/* Are we running in init_board() context? */
2856 +int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
2858 + if (bcm->initialized)
2860 + if (bcm->shutting_down)
2866 +struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
2867 + u16 radio_attenuation,
2868 + u16 baseband_attenuation)
2870 + return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
2875 +u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
2877 + return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
2881 +void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
2883 + iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
2887 +u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
2889 + return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
2893 +void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
2895 + iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
2899 +int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
2901 + return pci_read_config_word(bcm->pci_dev, offset, value);
2905 +int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
2907 + return pci_read_config_dword(bcm->pci_dev, offset, value);
2911 +int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
2913 + return pci_write_config_word(bcm->pci_dev, offset, value);
2917 +int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
2919 + return pci_write_config_dword(bcm->pci_dev, offset, value);
2922 +/** Limit a value between two limits */
2924 +# undef limit_value
2926 +#define limit_value(value, min, max) \
2928 + typeof(value) __value = (value); \
2929 + typeof(value) __min = (min); \
2930 + typeof(value) __max = (max); \
2931 + if (__value < __min) \
2932 + __value = __min; \
2933 + else if (__value > __max) \
2934 + __value = __max; \
2938 +/** Helpers to print MAC addresses. */
2939 +#define BCM43xx_MACFMT "%02x:%02x:%02x:%02x:%02x:%02x"
2940 +#define BCM43xx_MACARG(x) ((u8*)(x))[0], ((u8*)(x))[1], \
2941 + ((u8*)(x))[2], ((u8*)(x))[3], \
2942 + ((u8*)(x))[4], ((u8*)(x))[5]
2944 +#endif /* BCM43xx_H_ */
2945 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
2946 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c 1970-01-01 01:00:00.000000000 +0100
2947 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.c 2006-03-28 22:16:14.000000000 +0200
2951 + Broadcom BCM43xx wireless driver
2953 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
2954 + Stefano Brivio <st3@riseup.net>
2955 + Michael Buesch <mbuesch@freenet.de>
2956 + Danny van Dyk <kugelfang@gentoo.org>
2957 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
2959 + This program is free software; you can redistribute it and/or modify
2960 + it under the terms of the GNU General Public License as published by
2961 + the Free Software Foundation; either version 2 of the License, or
2962 + (at your option) any later version.
2964 + This program is distributed in the hope that it will be useful,
2965 + but WITHOUT ANY WARRANTY; without even the implied warranty of
2966 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2967 + GNU General Public License for more details.
2969 + You should have received a copy of the GNU General Public License
2970 + along with this program; see the file COPYING. If not, write to
2971 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
2972 + Boston, MA 02110-1301, USA.
2976 +#include "bcm43xx.h"
2977 +#include "bcm43xx_ilt.h"
2978 +#include "bcm43xx_phy.h"
2981 +/**** Initial Internal Lookup Tables ****/
2983 +const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE] = {
2984 + 0xFEB93FFD, 0xFEC63FFD, /* 0 */
2985 + 0xFED23FFD, 0xFEDF3FFD,
2986 + 0xFEEC3FFE, 0xFEF83FFE,
2987 + 0xFF053FFE, 0xFF113FFE,
2988 + 0xFF1E3FFE, 0xFF2A3FFF, /* 8 */
2989 + 0xFF373FFF, 0xFF443FFF,
2990 + 0xFF503FFF, 0xFF5D3FFF,
2991 + 0xFF693FFF, 0xFF763FFF,
2992 + 0xFF824000, 0xFF8F4000, /* 16 */
2993 + 0xFF9B4000, 0xFFA84000,
2994 + 0xFFB54000, 0xFFC14000,
2995 + 0xFFCE4000, 0xFFDA4000,
2996 + 0xFFE74000, 0xFFF34000, /* 24 */
2997 + 0x00004000, 0x000D4000,
2998 + 0x00194000, 0x00264000,
2999 + 0x00324000, 0x003F4000,
3000 + 0x004B4000, 0x00584000, /* 32 */
3001 + 0x00654000, 0x00714000,
3002 + 0x007E4000, 0x008A3FFF,
3003 + 0x00973FFF, 0x00A33FFF,
3004 + 0x00B03FFF, 0x00BC3FFF, /* 40 */
3005 + 0x00C93FFF, 0x00D63FFF,
3006 + 0x00E23FFE, 0x00EF3FFE,
3007 + 0x00FB3FFE, 0x01083FFE,
3008 + 0x01143FFE, 0x01213FFD, /* 48 */
3009 + 0x012E3FFD, 0x013A3FFD,
3013 +const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE] = {
3014 + 0xDB93CB87, 0xD666CF64, /* 0 */
3015 + 0xD1FDD358, 0xCDA6D826,
3016 + 0xCA38DD9F, 0xC729E2B4,
3017 + 0xC469E88E, 0xC26AEE2B,
3018 + 0xC0DEF46C, 0xC073FA62, /* 8 */
3019 + 0xC01D00D5, 0xC0760743,
3020 + 0xC1560D1E, 0xC2E51369,
3021 + 0xC4ED18FF, 0xC7AC1ED7,
3022 + 0xCB2823B2, 0xCEFA28D9, /* 16 */
3023 + 0xD2F62D3F, 0xD7BB3197,
3024 + 0xDCE53568, 0xE1FE3875,
3025 + 0xE7D13B35, 0xED663D35,
3026 + 0xF39B3EC4, 0xF98E3FA7, /* 24 */
3027 + 0x00004000, 0x06723FA7,
3028 + 0x0C653EC4, 0x129A3D35,
3029 + 0x182F3B35, 0x1E023875,
3030 + 0x231B3568, 0x28453197, /* 32 */
3031 + 0x2D0A2D3F, 0x310628D9,
3032 + 0x34D823B2, 0x38541ED7,
3033 + 0x3B1318FF, 0x3D1B1369,
3034 + 0x3EAA0D1E, 0x3F8A0743, /* 40 */
3035 + 0x3FE300D5, 0x3F8DFA62,
3036 + 0x3F22F46C, 0x3D96EE2B,
3037 + 0x3B97E88E, 0x38D7E2B4,
3038 + 0x35C8DD9F, 0x325AD826, /* 48 */
3039 + 0x2E03D358, 0x299ACF64,
3043 +const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE] = {
3044 + 0x0082, 0x0082, 0x0102, 0x0182, /* 0 */
3045 + 0x0202, 0x0282, 0x0302, 0x0382,
3046 + 0x0402, 0x0482, 0x0502, 0x0582,
3047 + 0x05E2, 0x0662, 0x06E2, 0x0762,
3048 + 0x07E2, 0x0842, 0x08C2, 0x0942, /* 16 */
3049 + 0x09C2, 0x0A22, 0x0AA2, 0x0B02,
3050 + 0x0B82, 0x0BE2, 0x0C62, 0x0CC2,
3051 + 0x0D42, 0x0DA2, 0x0E02, 0x0E62,
3052 + 0x0EE2, 0x0F42, 0x0FA2, 0x1002, /* 32 */
3053 + 0x1062, 0x10C2, 0x1122, 0x1182,
3054 + 0x11E2, 0x1242, 0x12A2, 0x12E2,
3055 + 0x1342, 0x13A2, 0x1402, 0x1442,
3056 + 0x14A2, 0x14E2, 0x1542, 0x1582, /* 48 */
3057 + 0x15E2, 0x1622, 0x1662, 0x16C1,
3058 + 0x1701, 0x1741, 0x1781, 0x17E1,
3059 + 0x1821, 0x1861, 0x18A1, 0x18E1,
3060 + 0x1921, 0x1961, 0x19A1, 0x19E1, /* 64 */
3061 + 0x1A21, 0x1A61, 0x1AA1, 0x1AC1,
3062 + 0x1B01, 0x1B41, 0x1B81, 0x1BA1,
3063 + 0x1BE1, 0x1C21, 0x1C41, 0x1C81,
3064 + 0x1CA1, 0x1CE1, 0x1D01, 0x1D41, /* 80 */
3065 + 0x1D61, 0x1DA1, 0x1DC1, 0x1E01,
3066 + 0x1E21, 0x1E61, 0x1E81, 0x1EA1,
3067 + 0x1EE1, 0x1F01, 0x1F21, 0x1F41,
3068 + 0x1F81, 0x1FA1, 0x1FC1, 0x1FE1, /* 96 */
3069 + 0x2001, 0x2041, 0x2061, 0x2081,
3070 + 0x20A1, 0x20C1, 0x20E1, 0x2101,
3071 + 0x2121, 0x2141, 0x2161, 0x2181,
3072 + 0x21A1, 0x21C1, 0x21E1, 0x2201, /* 112 */
3073 + 0x2221, 0x2241, 0x2261, 0x2281,
3074 + 0x22A1, 0x22C1, 0x22C1, 0x22E1,
3075 + 0x2301, 0x2321, 0x2341, 0x2361,
3076 + 0x2361, 0x2381, 0x23A1, 0x23C1, /* 128 */
3077 + 0x23E1, 0x23E1, 0x2401, 0x2421,
3078 + 0x2441, 0x2441, 0x2461, 0x2481,
3079 + 0x2481, 0x24A1, 0x24C1, 0x24C1,
3080 + 0x24E1, 0x2501, 0x2501, 0x2521, /* 144 */
3081 + 0x2541, 0x2541, 0x2561, 0x2561,
3082 + 0x2581, 0x25A1, 0x25A1, 0x25C1,
3083 + 0x25C1, 0x25E1, 0x2601, 0x2601,
3084 + 0x2621, 0x2621, 0x2641, 0x2641, /* 160 */
3085 + 0x2661, 0x2661, 0x2681, 0x2681,
3086 + 0x26A1, 0x26A1, 0x26C1, 0x26C1,
3087 + 0x26E1, 0x26E1, 0x2701, 0x2701,
3088 + 0x2721, 0x2721, 0x2740, 0x2740, /* 176 */
3089 + 0x2760, 0x2760, 0x2780, 0x2780,
3090 + 0x2780, 0x27A0, 0x27A0, 0x27C0,
3091 + 0x27C0, 0x27E0, 0x27E0, 0x27E0,
3092 + 0x2800, 0x2800, 0x2820, 0x2820, /* 192 */
3093 + 0x2820, 0x2840, 0x2840, 0x2840,
3094 + 0x2860, 0x2860, 0x2880, 0x2880,
3095 + 0x2880, 0x28A0, 0x28A0, 0x28A0,
3096 + 0x28C0, 0x28C0, 0x28C0, 0x28E0, /* 208 */
3097 + 0x28E0, 0x28E0, 0x2900, 0x2900,
3098 + 0x2900, 0x2920, 0x2920, 0x2920,
3099 + 0x2940, 0x2940, 0x2940, 0x2960,
3100 + 0x2960, 0x2960, 0x2960, 0x2980, /* 224 */
3101 + 0x2980, 0x2980, 0x29A0, 0x29A0,
3102 + 0x29A0, 0x29A0, 0x29C0, 0x29C0,
3103 + 0x29C0, 0x29E0, 0x29E0, 0x29E0,
3104 + 0x29E0, 0x2A00, 0x2A00, 0x2A00, /* 240 */
3105 + 0x2A00, 0x2A20, 0x2A20, 0x2A20,
3106 + 0x2A20, 0x2A40, 0x2A40, 0x2A40,
3107 + 0x2A40, 0x2A60, 0x2A60, 0x2A60,
3110 +const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE] = {
3111 + 0x0089, 0x02E9, 0x0409, 0x04E9, /* 0 */
3112 + 0x05A9, 0x0669, 0x0709, 0x0789,
3113 + 0x0829, 0x08A9, 0x0929, 0x0989,
3114 + 0x0A09, 0x0A69, 0x0AC9, 0x0B29,
3115 + 0x0BA9, 0x0BE9, 0x0C49, 0x0CA9, /* 16 */
3116 + 0x0D09, 0x0D69, 0x0DA9, 0x0E09,
3117 + 0x0E69, 0x0EA9, 0x0F09, 0x0F49,
3118 + 0x0FA9, 0x0FE9, 0x1029, 0x1089,
3119 + 0x10C9, 0x1109, 0x1169, 0x11A9, /* 32 */
3120 + 0x11E9, 0x1229, 0x1289, 0x12C9,
3121 + 0x1309, 0x1349, 0x1389, 0x13C9,
3122 + 0x1409, 0x1449, 0x14A9, 0x14E9,
3123 + 0x1529, 0x1569, 0x15A9, 0x15E9, /* 48 */
3124 + 0x1629, 0x1669, 0x16A9, 0x16E8,
3125 + 0x1728, 0x1768, 0x17A8, 0x17E8,
3126 + 0x1828, 0x1868, 0x18A8, 0x18E8,
3127 + 0x1928, 0x1968, 0x19A8, 0x19E8, /* 64 */
3128 + 0x1A28, 0x1A68, 0x1AA8, 0x1AE8,
3129 + 0x1B28, 0x1B68, 0x1BA8, 0x1BE8,
3130 + 0x1C28, 0x1C68, 0x1CA8, 0x1CE8,
3131 + 0x1D28, 0x1D68, 0x1DC8, 0x1E08, /* 80 */
3132 + 0x1E48, 0x1E88, 0x1EC8, 0x1F08,
3133 + 0x1F48, 0x1F88, 0x1FE8, 0x2028,
3134 + 0x2068, 0x20A8, 0x2108, 0x2148,
3135 + 0x2188, 0x21C8, 0x2228, 0x2268, /* 96 */
3136 + 0x22C8, 0x2308, 0x2348, 0x23A8,
3137 + 0x23E8, 0x2448, 0x24A8, 0x24E8,
3138 + 0x2548, 0x25A8, 0x2608, 0x2668,
3139 + 0x26C8, 0x2728, 0x2787, 0x27E7, /* 112 */
3140 + 0x2847, 0x28C7, 0x2947, 0x29A7,
3141 + 0x2A27, 0x2AC7, 0x2B47, 0x2BE7,
3142 + 0x2CA7, 0x2D67, 0x2E47, 0x2F67,
3143 + 0x3247, 0x3526, 0x3646, 0x3726, /* 128 */
3144 + 0x3806, 0x38A6, 0x3946, 0x39E6,
3145 + 0x3A66, 0x3AE6, 0x3B66, 0x3BC6,
3146 + 0x3C45, 0x3CA5, 0x3D05, 0x3D85,
3147 + 0x3DE5, 0x3E45, 0x3EA5, 0x3EE5, /* 144 */
3148 + 0x3F45, 0x3FA5, 0x4005, 0x4045,
3149 + 0x40A5, 0x40E5, 0x4145, 0x4185,
3150 + 0x41E5, 0x4225, 0x4265, 0x42C5,
3151 + 0x4305, 0x4345, 0x43A5, 0x43E5, /* 160 */
3152 + 0x4424, 0x4464, 0x44C4, 0x4504,
3153 + 0x4544, 0x4584, 0x45C4, 0x4604,
3154 + 0x4644, 0x46A4, 0x46E4, 0x4724,
3155 + 0x4764, 0x47A4, 0x47E4, 0x4824, /* 176 */
3156 + 0x4864, 0x48A4, 0x48E4, 0x4924,
3157 + 0x4964, 0x49A4, 0x49E4, 0x4A24,
3158 + 0x4A64, 0x4AA4, 0x4AE4, 0x4B23,
3159 + 0x4B63, 0x4BA3, 0x4BE3, 0x4C23, /* 192 */
3160 + 0x4C63, 0x4CA3, 0x4CE3, 0x4D23,
3161 + 0x4D63, 0x4DA3, 0x4DE3, 0x4E23,
3162 + 0x4E63, 0x4EA3, 0x4EE3, 0x4F23,
3163 + 0x4F63, 0x4FC3, 0x5003, 0x5043, /* 208 */
3164 + 0x5083, 0x50C3, 0x5103, 0x5143,
3165 + 0x5183, 0x51E2, 0x5222, 0x5262,
3166 + 0x52A2, 0x52E2, 0x5342, 0x5382,
3167 + 0x53C2, 0x5402, 0x5462, 0x54A2, /* 224 */
3168 + 0x5502, 0x5542, 0x55A2, 0x55E2,
3169 + 0x5642, 0x5682, 0x56E2, 0x5722,
3170 + 0x5782, 0x57E1, 0x5841, 0x58A1,
3171 + 0x5901, 0x5961, 0x59C1, 0x5A21, /* 240 */
3172 + 0x5AA1, 0x5B01, 0x5B81, 0x5BE1,
3173 + 0x5C61, 0x5D01, 0x5D80, 0x5E20,
3174 + 0x5EE0, 0x5FA0, 0x6080, 0x61C0,
3177 +const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE] = {
3178 + 0x0001, 0x0001, 0x0001, 0xFFFE,
3179 + 0xFFFE, 0x3FFF, 0x1000, 0x0393,
3182 +const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE] = {
3183 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3184 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3187 +const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE] = {
3188 + 0x013C, 0x01F5, 0x031A, 0x0631,
3189 + 0x0001, 0x0001, 0x0001, 0x0001,
3192 +const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE] = {
3193 + 0x5484, 0x3C40, 0x0000, 0x0000,
3194 + 0x0000, 0x0000, 0x0000, 0x0000,
3197 +const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3198 + 0x6C77, 0x5162, 0x3B40, 0x3335, /* 0 */
3199 + 0x2F2D, 0x2A2A, 0x2527, 0x1F21,
3200 + 0x1A1D, 0x1719, 0x1616, 0x1414,
3201 + 0x1414, 0x1400, 0x1414, 0x1614,
3202 + 0x1716, 0x1A19, 0x1F1D, 0x2521, /* 16 */
3203 + 0x2A27, 0x2F2A, 0x332D, 0x3B35,
3204 + 0x5140, 0x6C62, 0x0077,
3207 +const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3208 + 0xD8DD, 0xCBD4, 0xBCC0, 0XB6B7, /* 0 */
3209 + 0xB2B0, 0xADAD, 0xA7A9, 0x9FA1,
3210 + 0x969B, 0x9195, 0x8F8F, 0x8A8A,
3211 + 0x8A8A, 0x8A00, 0x8A8A, 0x8F8A,
3212 + 0x918F, 0x9695, 0x9F9B, 0xA7A1, /* 16 */
3213 + 0xADA9, 0xB2AD, 0xB6B0, 0xBCB7,
3214 + 0xCBC0, 0xD8D4, 0x00DD,
3217 +const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE] = {
3218 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 0 */
3219 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3220 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3221 + 0xA4A4, 0xA400, 0xA4A4, 0xA4A4,
3222 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 16 */
3223 + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4,
3224 + 0xA4A4, 0xA4A4, 0x00A4,
3227 +const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE] = {
3228 + 0x007A, 0x0075, 0x0071, 0x006C, /* 0 */
3229 + 0x0067, 0x0063, 0x005E, 0x0059,
3230 + 0x0054, 0x0050, 0x004B, 0x0046,
3231 + 0x0042, 0x003D, 0x003D, 0x003D,
3232 + 0x003D, 0x003D, 0x003D, 0x003D, /* 16 */
3233 + 0x003D, 0x003D, 0x003D, 0x003D,
3234 + 0x003D, 0x003D, 0x0000, 0x003D,
3235 + 0x003D, 0x003D, 0x003D, 0x003D,
3236 + 0x003D, 0x003D, 0x003D, 0x003D, /* 32 */
3237 + 0x003D, 0x003D, 0x003D, 0x003D,
3238 + 0x0042, 0x0046, 0x004B, 0x0050,
3239 + 0x0054, 0x0059, 0x005E, 0x0063,
3240 + 0x0067, 0x006C, 0x0071, 0x0075, /* 48 */
3244 +const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE] = {
3245 + 0x00DE, 0x00DC, 0x00DA, 0x00D8, /* 0 */
3246 + 0x00D6, 0x00D4, 0x00D2, 0x00CF,
3247 + 0x00CD, 0x00CA, 0x00C7, 0x00C4,
3248 + 0x00C1, 0x00BE, 0x00BE, 0x00BE,
3249 + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 16 */
3250 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3251 + 0x00BE, 0x00BE, 0x0000, 0x00BE,
3252 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3253 + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 32 */
3254 + 0x00BE, 0x00BE, 0x00BE, 0x00BE,
3255 + 0x00C1, 0x00C4, 0x00C7, 0x00CA,
3256 + 0x00CD, 0x00CF, 0x00D2, 0x00D4,
3257 + 0x00D6, 0x00D8, 0x00DA, 0x00DC, /* 48 */
3261 +/**** Helper functions to access the device Internal Lookup Tables ****/
3263 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
3265 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3266 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3268 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val);
3270 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3272 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val);
3276 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
3278 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3279 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3280 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_A_DATA1);
3282 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3283 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_G_DATA1);
3286 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
3287 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h 1970-01-01 01:00:00.000000000 +0100
3288 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_ilt.h 2006-03-28 22:16:14.000000000 +0200
3290 +#ifndef BCM43xx_ILT_H_
3291 +#define BCM43xx_ILT_H_
3293 +#define BCM43xx_ILT_ROTOR_SIZE 53
3294 +extern const u32 bcm43xx_ilt_rotor[BCM43xx_ILT_ROTOR_SIZE];
3295 +#define BCM43xx_ILT_RETARD_SIZE 53
3296 +extern const u32 bcm43xx_ilt_retard[BCM43xx_ILT_RETARD_SIZE];
3297 +#define BCM43xx_ILT_FINEFREQA_SIZE 256
3298 +extern const u16 bcm43xx_ilt_finefreqa[BCM43xx_ILT_FINEFREQA_SIZE];
3299 +#define BCM43xx_ILT_FINEFREQG_SIZE 256
3300 +extern const u16 bcm43xx_ilt_finefreqg[BCM43xx_ILT_FINEFREQG_SIZE];
3301 +#define BCM43xx_ILT_NOISEA2_SIZE 8
3302 +extern const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE];
3303 +#define BCM43xx_ILT_NOISEA3_SIZE 8
3304 +extern const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE];
3305 +#define BCM43xx_ILT_NOISEG1_SIZE 8
3306 +extern const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE];
3307 +#define BCM43xx_ILT_NOISEG2_SIZE 8
3308 +extern const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE];
3309 +#define BCM43xx_ILT_NOISESCALEG_SIZE 27
3310 +extern const u16 bcm43xx_ilt_noisescaleg1[BCM43xx_ILT_NOISESCALEG_SIZE];
3311 +extern const u16 bcm43xx_ilt_noisescaleg2[BCM43xx_ILT_NOISESCALEG_SIZE];
3312 +extern const u16 bcm43xx_ilt_noisescaleg3[BCM43xx_ILT_NOISESCALEG_SIZE];
3313 +#define BCM43xx_ILT_SIGMASQR_SIZE 53
3314 +extern const u16 bcm43xx_ilt_sigmasqr1[BCM43xx_ILT_SIGMASQR_SIZE];
3315 +extern const u16 bcm43xx_ilt_sigmasqr2[BCM43xx_ILT_SIGMASQR_SIZE];
3318 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
3319 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
3321 +#endif /* BCM43xx_ILT_H_ */
3322 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
3323 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c 1970-01-01 01:00:00.000000000 +0100
3324 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.c 2006-03-28 22:16:14.000000000 +0200
3328 + Broadcom BCM43xx wireless driver
3330 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
3331 + Stefano Brivio <st3@riseup.net>
3332 + Michael Buesch <mbuesch@freenet.de>
3333 + Danny van Dyk <kugelfang@gentoo.org>
3334 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
3336 + This program is free software; you can redistribute it and/or modify
3337 + it under the terms of the GNU General Public License as published by
3338 + the Free Software Foundation; either version 2 of the License, or
3339 + (at your option) any later version.
3341 + This program is distributed in the hope that it will be useful,
3342 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3343 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3344 + GNU General Public License for more details.
3346 + You should have received a copy of the GNU General Public License
3347 + along with this program; see the file COPYING. If not, write to
3348 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
3349 + Boston, MA 02110-1301, USA.
3353 +#include "bcm43xx_leds.h"
3354 +#include "bcm43xx.h"
3356 +#include <asm/bitops.h>
3359 +static void bcm43xx_led_changestate(struct bcm43xx_led *led)
3361 + struct bcm43xx_private *bcm = led->bcm;
3362 + const int index = bcm43xx_led_index(led);
3363 + const u16 mask = (1 << index);
3366 + assert(index >= 0 && index < BCM43xx_NR_LEDS);
3367 + assert(led->blink_interval);
3368 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3369 + ledctl = (ledctl & mask) ? (ledctl & ~mask) : (ledctl | mask);
3370 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3373 +static void bcm43xx_led_blink(unsigned long d)
3375 + struct bcm43xx_led *led = (struct bcm43xx_led *)d;
3376 + struct bcm43xx_private *bcm = led->bcm;
3377 + unsigned long flags;
3379 + bcm43xx_lock_mmio(bcm, flags);
3380 + if (led->blink_interval) {
3381 + bcm43xx_led_changestate(led);
3382 + mod_timer(&led->blink_timer, jiffies + led->blink_interval);
3384 + bcm43xx_unlock_mmio(bcm, flags);
3387 +static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
3388 + unsigned long interval)
3390 + if (led->blink_interval)
3392 + led->blink_interval = interval;
3393 + bcm43xx_led_changestate(led);
3394 + led->blink_timer.expires = jiffies + interval;
3395 + add_timer(&led->blink_timer);
3398 +static void bcm43xx_led_blink_stop(struct bcm43xx_led *led, int sync)
3400 + struct bcm43xx_private *bcm = led->bcm;
3401 + const int index = bcm43xx_led_index(led);
3404 + if (!led->blink_interval)
3406 + if (unlikely(sync))
3407 + del_timer_sync(&led->blink_timer);
3409 + del_timer(&led->blink_timer);
3410 + led->blink_interval = 0;
3412 + /* Make sure the LED is turned off. */
3413 + assert(index >= 0 && index < BCM43xx_NR_LEDS);
3414 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3415 + if (led->activelow)
3416 + ledctl |= (1 << index);
3418 + ledctl &= ~(1 << index);
3419 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3422 +static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
3423 + struct bcm43xx_led *led,
3426 + /* This function is called, if the behaviour (and activelow)
3427 + * information for a LED is missing in the SPROM.
3428 + * We hardcode the behaviour values for various devices here.
3429 + * Note that the BCM43xx_LED_TEST_XXX behaviour values can
3430 + * be used to figure out which led is mapped to which index.
3433 + switch (led_index) {
3435 + led->behaviour = BCM43xx_LED_ACTIVITY;
3436 + if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
3437 + led->behaviour = BCM43xx_LED_RADIO_ALL;
3440 + led->behaviour = BCM43xx_LED_RADIO_B;
3441 + if (bcm->board_vendor == PCI_VENDOR_ID_ASUSTEK)
3442 + led->behaviour = BCM43xx_LED_ASSOC;
3445 + led->behaviour = BCM43xx_LED_RADIO_A;
3448 + led->behaviour = BCM43xx_LED_OFF;
3455 +int bcm43xx_leds_init(struct bcm43xx_private *bcm)
3457 + struct bcm43xx_led *led;
3461 + sprom[0] = bcm->sprom.wl0gpio0;
3462 + sprom[1] = bcm->sprom.wl0gpio1;
3463 + sprom[2] = bcm->sprom.wl0gpio2;
3464 + sprom[3] = bcm->sprom.wl0gpio3;
3466 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3467 + led = &(bcm->leds[i]);
3469 + setup_timer(&led->blink_timer,
3470 + bcm43xx_led_blink,
3471 + (unsigned long)led);
3473 + if (sprom[i] == 0xFF) {
3474 + bcm43xx_led_init_hardcoded(bcm, led, i);
3476 + led->behaviour = sprom[i] & BCM43xx_LED_BEHAVIOUR;
3477 + led->activelow = !!(sprom[i] & BCM43xx_LED_ACTIVELOW);
3484 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm)
3486 + struct bcm43xx_led *led;
3489 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3490 + led = &(bcm->leds[i]);
3491 + bcm43xx_led_blink_stop(led, 1);
3493 + bcm43xx_leds_switch_all(bcm, 0);
3496 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
3498 + struct bcm43xx_led *led;
3499 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
3500 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
3501 + const int transferring = (jiffies - bcm->stats.last_tx) < BCM43xx_LED_XFER_THRES;
3503 + unsigned long interval = 0;
3506 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3507 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3508 + led = &(bcm->leds[i]);
3511 + switch (led->behaviour) {
3512 + case BCM43xx_LED_INACTIVE:
3514 + case BCM43xx_LED_OFF:
3516 + case BCM43xx_LED_ON:
3519 + case BCM43xx_LED_ACTIVITY:
3520 + turn_on = activity;
3522 + case BCM43xx_LED_RADIO_ALL:
3523 + turn_on = radio->enabled;
3525 + case BCM43xx_LED_RADIO_A:
3526 + turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
3528 + case BCM43xx_LED_RADIO_B:
3529 + turn_on = (radio->enabled &&
3530 + (phy->type == BCM43xx_PHYTYPE_B ||
3531 + phy->type == BCM43xx_PHYTYPE_G));
3533 + case BCM43xx_LED_MODE_BG:
3534 + if (phy->type == BCM43xx_PHYTYPE_G &&
3535 + 1/*FIXME: using G rates.*/)
3538 + case BCM43xx_LED_TRANSFER:
3540 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3542 + bcm43xx_led_blink_stop(led, 0);
3544 + case BCM43xx_LED_APTRANSFER:
3545 + if (bcm->iw_mode == IW_MODE_MASTER) {
3546 + if (transferring) {
3547 + interval = BCM43xx_LEDBLINK_FAST;
3552 + if (0/*TODO: not assoc*/)
3553 + interval = BCM43xx_LEDBLINK_SLOW;
3554 + else if (transferring)
3555 + interval = BCM43xx_LEDBLINK_FAST;
3560 + bcm43xx_led_blink_start(led, interval);
3562 + bcm43xx_led_blink_stop(led, 0);
3564 + case BCM43xx_LED_WEIRD:
3567 + case BCM43xx_LED_ASSOC:
3568 + if (1/*bcm->softmac->associated*/)
3571 +#ifdef CONFIG_BCM43XX_DEBUG
3572 + case BCM43xx_LED_TEST_BLINKSLOW:
3573 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_SLOW);
3575 + case BCM43xx_LED_TEST_BLINKMEDIUM:
3576 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3578 + case BCM43xx_LED_TEST_BLINKFAST:
3579 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_FAST);
3581 +#endif /* CONFIG_BCM43XX_DEBUG */
3586 + if (led->activelow)
3587 + turn_on = !turn_on;
3589 + ledctl |= (1 << i);
3591 + ledctl &= ~(1 << i);
3593 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3596 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
3598 + struct bcm43xx_led *led;
3603 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3604 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3605 + led = &(bcm->leds[i]);
3606 + if (led->behaviour == BCM43xx_LED_INACTIVE)
3609 + bit_on = led->activelow ? 0 : 1;
3611 + bit_on = led->activelow ? 1 : 0;
3613 + ledctl |= (1 << i);
3615 + ledctl &= ~(1 << i);
3617 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3619 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
3620 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h 1970-01-01 01:00:00.000000000 +0100
3621 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_leds.h 2006-03-28 22:16:14.000000000 +0200
3623 +#ifndef BCM43xx_LEDS_H_
3624 +#define BCM43xx_LEDS_H_
3626 +#include <linux/types.h>
3627 +#include <linux/timer.h>
3630 +struct bcm43xx_led {
3634 + struct bcm43xx_private *bcm;
3635 + struct timer_list blink_timer;
3636 + unsigned long blink_interval;
3638 +#define bcm43xx_led_index(led) ((int)((led) - (led)->bcm->leds))
3640 +/* Delay between state changes when blinking in jiffies */
3641 +#define BCM43xx_LEDBLINK_SLOW (HZ / 1)
3642 +#define BCM43xx_LEDBLINK_MEDIUM (HZ / 4)
3643 +#define BCM43xx_LEDBLINK_FAST (HZ / 8)
3645 +#define BCM43xx_LED_XFER_THRES (HZ / 100)
3647 +#define BCM43xx_LED_BEHAVIOUR 0x7F
3648 +#define BCM43xx_LED_ACTIVELOW 0x80
3649 +enum { /* LED behaviour values */
3652 + BCM43xx_LED_ACTIVITY,
3653 + BCM43xx_LED_RADIO_ALL,
3654 + BCM43xx_LED_RADIO_A,
3655 + BCM43xx_LED_RADIO_B,
3656 + BCM43xx_LED_MODE_BG,
3657 + BCM43xx_LED_TRANSFER,
3658 + BCM43xx_LED_APTRANSFER,
3659 + BCM43xx_LED_WEIRD,//FIXME
3660 + BCM43xx_LED_ASSOC,
3661 + BCM43xx_LED_INACTIVE,
3663 + /* Behaviour values for testing.
3664 + * With these values it is easier to figure out
3665 + * the real behaviour of leds, in case the SPROM
3666 + * is missing information.
3668 + BCM43xx_LED_TEST_BLINKSLOW,
3669 + BCM43xx_LED_TEST_BLINKMEDIUM,
3670 + BCM43xx_LED_TEST_BLINKFAST,
3673 +int bcm43xx_leds_init(struct bcm43xx_private *bcm);
3674 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm);
3675 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity);
3676 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on);
3678 +#endif /* BCM43xx_LEDS_H_ */
3679 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
3680 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c 1970-01-01 01:00:00.000000000 +0100
3681 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.c 2006-03-28 22:16:14.000000000 +0200
3685 + Broadcom BCM43xx wireless driver
3687 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>
3688 + Copyright (c) 2005 Stefano Brivio <st3@riseup.net>
3689 + Copyright (c) 2005, 2006 Michael Buesch <mbuesch@freenet.de>
3690 + Copyright (c) 2005 Danny van Dyk <kugelfang@gentoo.org>
3691 + Copyright (c) 2005 Andreas Jaggi <andreas.jaggi@waterwave.ch>
3693 + Some parts of the code in this file are derived from the ipw2200
3694 + driver Copyright(c) 2003 - 2004 Intel Corporation.
3696 + This program is free software; you can redistribute it and/or modify
3697 + it under the terms of the GNU General Public License as published by
3698 + the Free Software Foundation; either version 2 of the License, or
3699 + (at your option) any later version.
3701 + This program is distributed in the hope that it will be useful,
3702 + but WITHOUT ANY WARRANTY; without even the implied warranty of
3703 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3704 + GNU General Public License for more details.
3706 + You should have received a copy of the GNU General Public License
3707 + along with this program; see the file COPYING. If not, write to
3708 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
3709 + Boston, MA 02110-1301, USA.
3713 +#include <linux/delay.h>
3714 +#include <linux/init.h>
3715 +#include <linux/moduleparam.h>
3716 +#include <linux/if_arp.h>
3717 +#include <linux/etherdevice.h>
3718 +#include <linux/version.h>
3719 +#include <linux/firmware.h>
3720 +#include <linux/wireless.h>
3721 +#include <linux/workqueue.h>
3722 +#include <linux/skbuff.h>
3723 +#include <linux/dma-mapping.h>
3724 +#include <net/iw_handler.h>
3726 +#include "bcm43xx.h"
3727 +#include "bcm43xx_main.h"
3728 +#include "bcm43xx_debugfs.h"
3729 +#include "bcm43xx_radio.h"
3730 +#include "bcm43xx_phy.h"
3731 +#include "bcm43xx_dma.h"
3732 +#include "bcm43xx_pio.h"
3733 +#include "bcm43xx_power.h"
3734 +#include "bcm43xx_sysfs.h"
3735 +#include "bcm43xx_ethtool.h"
3736 +#include "bcm43xx_xmit.h"
3739 +MODULE_DESCRIPTION("Broadcom BCM43xx wireless driver");
3740 +MODULE_AUTHOR("Martin Langer");
3741 +MODULE_AUTHOR("Stefano Brivio");
3742 +MODULE_AUTHOR("Michael Buesch");
3743 +MODULE_LICENSE("GPL");
3745 +#ifdef CONFIG_BCM947XX
3746 +extern char *nvram_get(char *name);
3749 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
3750 +static int modparam_pio;
3751 +module_param_named(pio, modparam_pio, int, 0444);
3752 +MODULE_PARM_DESC(pio, "enable(1) / disable(0) PIO mode");
3753 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
3754 +# define modparam_pio 0
3755 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
3756 +# define modparam_pio 1
3759 +static int modparam_bad_frames_preempt;
3760 +module_param_named(bad_frames_preempt, modparam_bad_frames_preempt, int, 0444);
3761 +MODULE_PARM_DESC(bad_frames_preempt, "enable(1) / disable(0) Bad Frames Preemption");
3763 +static int modparam_short_retry = BCM43xx_DEFAULT_SHORT_RETRY_LIMIT;
3764 +module_param_named(short_retry, modparam_short_retry, int, 0444);
3765 +MODULE_PARM_DESC(short_retry, "Short-Retry-Limit (0 - 15)");
3767 +static int modparam_long_retry = BCM43xx_DEFAULT_LONG_RETRY_LIMIT;
3768 +module_param_named(long_retry, modparam_long_retry, int, 0444);
3769 +MODULE_PARM_DESC(long_retry, "Long-Retry-Limit (0 - 15)");
3771 +static int modparam_noleds;
3772 +module_param_named(noleds, modparam_noleds, int, 0444);
3773 +MODULE_PARM_DESC(noleds, "Turn off all LED activity");
3775 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
3776 +static char modparam_fwpostfix[64];
3777 +module_param_string(fwpostfix, modparam_fwpostfix, 64, 0444);
3778 +MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for debugging.");
3780 +# define modparam_fwpostfix ""
3781 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
3784 +/* If you want to debug with just a single device, enable this,
3785 + * where the string is the pci device ID (as given by the kernel's
3786 + * pci_name function) of the device to be used.
3788 +//#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
3790 +/* If you want to enable printing of each MMIO access, enable this. */
3791 +//#define DEBUG_ENABLE_MMIO_PRINT
3793 +/* If you want to enable printing of MMIO access within
3794 + * ucode/pcm upload, initvals write, enable this.
3796 +//#define DEBUG_ENABLE_UCODE_MMIO_PRINT
3798 +/* If you want to enable printing of PCI Config Space access, enable this */
3799 +//#define DEBUG_ENABLE_PCILOG
3802 +/* Detailed list maintained at:
3803 + * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
3805 +static struct pci_device_id bcm43xx_pci_tbl[] = {
3806 + /* Broadcom 4303 802.11b */
3807 + { PCI_VENDOR_ID_BROADCOM, 0x4301, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3808 + /* Broadcom 4307 802.11b */
3809 + { PCI_VENDOR_ID_BROADCOM, 0x4307, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3810 + /* Broadcom 4318 802.11b/g */
3811 + { PCI_VENDOR_ID_BROADCOM, 0x4318, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3812 + /* Broadcom 4306 802.11b/g */
3813 + { PCI_VENDOR_ID_BROADCOM, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3814 + /* Broadcom 4306 802.11a */
3815 +// { PCI_VENDOR_ID_BROADCOM, 0x4321, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3816 + /* Broadcom 4309 802.11a/b/g */
3817 + { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3818 + /* Broadcom 43XG 802.11b/g */
3819 + { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3820 +#ifdef CONFIG_BCM947XX
3821 + /* SB bus on BCM947xx */
3822 + { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
3826 +MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
3829 +static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
3833 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3834 + if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
3835 + val = swab32(val);
3837 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
3839 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
3843 +void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
3844 + u16 routing, u16 offset)
3848 + /* "offset" is the WORD offset. */
3850 + control = routing;
3852 + control |= offset;
3853 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
3856 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
3857 + u16 routing, u16 offset)
3861 + if (routing == BCM43xx_SHM_SHARED) {
3862 + if (offset & 0x0003) {
3863 + /* Unaligned access */
3864 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3865 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
3867 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3868 + ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3874 + bcm43xx_shm_control_word(bcm, routing, offset);
3875 + ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
3880 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
3881 + u16 routing, u16 offset)
3885 + if (routing == BCM43xx_SHM_SHARED) {
3886 + if (offset & 0x0003) {
3887 + /* Unaligned access */
3888 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3889 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED);
3895 + bcm43xx_shm_control_word(bcm, routing, offset);
3896 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3901 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
3902 + u16 routing, u16 offset,
3905 + if (routing == BCM43xx_SHM_SHARED) {
3906 + if (offset & 0x0003) {
3907 + /* Unaligned access */
3908 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3910 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3911 + (value >> 16) & 0xffff);
3913 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3915 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
3921 + bcm43xx_shm_control_word(bcm, routing, offset);
3923 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
3926 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
3927 + u16 routing, u16 offset,
3930 + if (routing == BCM43xx_SHM_SHARED) {
3931 + if (offset & 0x0003) {
3932 + /* Unaligned access */
3933 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3935 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3941 + bcm43xx_shm_control_word(bcm, routing, offset);
3943 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
3946 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
3948 + /* We need to be careful. As we read the TSF from multiple
3949 + * registers, we should take care of register overflows.
3950 + * In theory, the whole tsf read process should be atomic.
3951 + * We try to be atomic here, by restaring the read process,
3952 + * if any of the high registers changed (overflew).
3954 + if (bcm->current_core->rev >= 3) {
3955 + u32 low, high, high2;
3958 + high = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
3959 + low = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW);
3960 + high2 = bcm43xx_read32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH);
3961 + } while (unlikely(high != high2));
3968 + u16 v0, v1, v2, v3;
3969 + u16 test1, test2, test3;
3972 + v3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
3973 + v2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
3974 + v1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
3975 + v0 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_0);
3977 + test3 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_3);
3978 + test2 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_2);
3979 + test1 = bcm43xx_read16(bcm, BCM43xx_MMIO_TSF_1);
3980 + } while (v3 != test3 || v2 != test2 || v1 != test1);
3994 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
3998 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3999 + status |= BCM43xx_SBF_TIME_UPDATE;
4000 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
4003 + /* Be careful with the in-progress timer.
4004 + * First zero out the low register, so we have a full
4005 + * register-overflow duration to complete the operation.
4007 + if (bcm->current_core->rev >= 3) {
4008 + u32 lo = (tsf & 0x00000000FFFFFFFFULL);
4009 + u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
4011 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
4013 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
4015 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
4017 + u16 v0 = (tsf & 0x000000000000FFFFULL);
4018 + u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
4019 + u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
4020 + u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
4022 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
4024 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
4026 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
4028 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
4030 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
4033 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
4034 + status &= ~BCM43xx_SBF_TIME_UPDATE;
4035 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
4039 +void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
4046 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
4049 + data |= mac[1] << 8;
4050 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4052 + data |= mac[3] << 8;
4053 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4055 + data |= mac[5] << 8;
4056 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4059 +static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
4062 + const u8 zero_addr[ETH_ALEN] = { 0 };
4064 + bcm43xx_macfilter_set(bcm, offset, zero_addr);
4067 +static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
4069 + const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
4070 + const u8 *bssid = bcm->bssid;
4071 + u8 mac_bssid[ETH_ALEN * 2];
4074 + memcpy(mac_bssid, mac, ETH_ALEN);
4075 + memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
4077 + /* Write our MAC address and BSSID to template ram */
4078 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
4079 + bcm43xx_ram_write(bcm, 0x20 + i, *((u32 *)(mac_bssid + i)));
4080 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
4081 + bcm43xx_ram_write(bcm, 0x78 + i, *((u32 *)(mac_bssid + i)));
4082 + for (i = 0; i < ARRAY_SIZE(mac_bssid); i += sizeof(u32))
4083 + bcm43xx_ram_write(bcm, 0x478 + i, *((u32 *)(mac_bssid + i)));
4086 +static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
4088 + /* slot_time is in usec. */
4089 + if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
4091 + bcm43xx_write16(bcm, 0x684, 510 + slot_time);
4092 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
4095 +static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
4097 + bcm43xx_set_slot_time(bcm, 9);
4098 + bcm->short_slot = 1;
4101 +static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
4103 + bcm43xx_set_slot_time(bcm, 20);
4104 + bcm->short_slot = 0;
4107 +/* FIXME: To get the MAC-filter working, we need to implement the
4108 + * following functions (and rename them :)
4111 +static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
4113 + bcm43xx_mac_suspend(bcm);
4114 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
4116 + bcm43xx_ram_write(bcm, 0x0026, 0x0000);
4117 + bcm43xx_ram_write(bcm, 0x0028, 0x0000);
4118 + bcm43xx_ram_write(bcm, 0x007E, 0x0000);
4119 + bcm43xx_ram_write(bcm, 0x0080, 0x0000);
4120 + bcm43xx_ram_write(bcm, 0x047E, 0x0000);
4121 + bcm43xx_ram_write(bcm, 0x0480, 0x0000);
4123 + if (bcm->current_core->rev < 3) {
4124 + bcm43xx_write16(bcm, 0x0610, 0x8000);
4125 + bcm43xx_write16(bcm, 0x060E, 0x0000);
4127 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
4129 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
4132 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G &&
4133 + ieee80211_is_ofdm_rate(bcm->softmac->txrates.default_rate))
4134 + bcm43xx_short_slot_timing_enable(bcm);
4137 + bcm43xx_mac_enable(bcm);
4140 +static void bcm43xx_associate(struct bcm43xx_private *bcm,
4143 + bcm43xx_mac_suspend(bcm);
4144 + bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_ASSOC, mac);
4145 + bcm43xx_write_mac_bssid_templates(bcm);
4146 + bcm43xx_mac_enable(bcm);
4150 +/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
4151 + * Returns the _previously_ enabled IRQ mask.
4153 +static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
4157 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4158 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
4163 +/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
4164 + * Returns the _previously_ enabled IRQ mask.
4166 +static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
4170 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4171 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
4176 +/* Make sure we don't receive more data from the device. */
4177 +static int bcm43xx_disable_interrupts_sync(struct bcm43xx_private *bcm, u32 *oldstate)
4180 + unsigned long flags;
4182 + bcm43xx_lock_mmio(bcm, flags);
4183 + if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
4184 + bcm43xx_unlock_mmio(bcm, flags);
4187 + old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4188 + tasklet_disable(&bcm->isr_tasklet);
4189 + bcm43xx_unlock_mmio(bcm, flags);
4196 +static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
4198 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4199 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4206 + if (bcm->chip_id == 0x4317) {
4207 + if (bcm->chip_rev == 0x00)
4208 + radio_id = 0x3205017F;
4209 + else if (bcm->chip_rev == 0x01)
4210 + radio_id = 0x4205017F;
4212 + radio_id = 0x5205017F;
4214 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4215 + radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
4217 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4218 + radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
4221 + manufact = (radio_id & 0x00000FFF);
4222 + version = (radio_id & 0x0FFFF000) >> 12;
4223 + revision = (radio_id & 0xF0000000) >> 28;
4225 + dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
4226 + radio_id, manufact, version, revision);
4228 + switch (phy->type) {
4229 + case BCM43xx_PHYTYPE_A:
4230 + if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
4231 + goto err_unsupported_radio;
4233 + case BCM43xx_PHYTYPE_B:
4234 + if ((version & 0xFFF0) != 0x2050)
4235 + goto err_unsupported_radio;
4237 + case BCM43xx_PHYTYPE_G:
4238 + if (version != 0x2050)
4239 + goto err_unsupported_radio;
4243 + radio->manufact = manufact;
4244 + radio->version = version;
4245 + radio->revision = revision;
4247 + /* Set default attenuation values. */
4248 + radio->baseband_atten = bcm43xx_default_baseband_attenuation(bcm);
4249 + radio->radio_atten = bcm43xx_default_radio_attenuation(bcm);
4250 + radio->txctl1 = bcm43xx_default_txctl1(bcm);
4251 + radio->txctl2 = 0xFFFF;
4252 + radio->power_level = ~0;
4254 + /* Initialize the in-memory nrssi Lookup Table. */
4255 + for (i = 0; i < 64; i++)
4256 + radio->nrssi_lt[i] = i;
4260 +err_unsupported_radio:
4261 + printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
4265 +static inline u8 bcm43xx_crc8(u8 crc, u8 data)
4267 + static const u8 t[] = {
4268 + 0x00, 0xF7, 0xB9, 0x4E, 0x25, 0xD2, 0x9C, 0x6B,
4269 + 0x4A, 0xBD, 0xF3, 0x04, 0x6F, 0x98, 0xD6, 0x21,
4270 + 0x94, 0x63, 0x2D, 0xDA, 0xB1, 0x46, 0x08, 0xFF,
4271 + 0xDE, 0x29, 0x67, 0x90, 0xFB, 0x0C, 0x42, 0xB5,
4272 + 0x7F, 0x88, 0xC6, 0x31, 0x5A, 0xAD, 0xE3, 0x14,
4273 + 0x35, 0xC2, 0x8C, 0x7B, 0x10, 0xE7, 0xA9, 0x5E,
4274 + 0xEB, 0x1C, 0x52, 0xA5, 0xCE, 0x39, 0x77, 0x80,
4275 + 0xA1, 0x56, 0x18, 0xEF, 0x84, 0x73, 0x3D, 0xCA,
4276 + 0xFE, 0x09, 0x47, 0xB0, 0xDB, 0x2C, 0x62, 0x95,
4277 + 0xB4, 0x43, 0x0D, 0xFA, 0x91, 0x66, 0x28, 0xDF,
4278 + 0x6A, 0x9D, 0xD3, 0x24, 0x4F, 0xB8, 0xF6, 0x01,
4279 + 0x20, 0xD7, 0x99, 0x6E, 0x05, 0xF2, 0xBC, 0x4B,
4280 + 0x81, 0x76, 0x38, 0xCF, 0xA4, 0x53, 0x1D, 0xEA,
4281 + 0xCB, 0x3C, 0x72, 0x85, 0xEE, 0x19, 0x57, 0xA0,
4282 + 0x15, 0xE2, 0xAC, 0x5B, 0x30, 0xC7, 0x89, 0x7E,
4283 + 0x5F, 0xA8, 0xE6, 0x11, 0x7A, 0x8D, 0xC3, 0x34,
4284 + 0xAB, 0x5C, 0x12, 0xE5, 0x8E, 0x79, 0x37, 0xC0,
4285 + 0xE1, 0x16, 0x58, 0xAF, 0xC4, 0x33, 0x7D, 0x8A,
4286 + 0x3F, 0xC8, 0x86, 0x71, 0x1A, 0xED, 0xA3, 0x54,
4287 + 0x75, 0x82, 0xCC, 0x3B, 0x50, 0xA7, 0xE9, 0x1E,
4288 + 0xD4, 0x23, 0x6D, 0x9A, 0xF1, 0x06, 0x48, 0xBF,
4289 + 0x9E, 0x69, 0x27, 0xD0, 0xBB, 0x4C, 0x02, 0xF5,
4290 + 0x40, 0xB7, 0xF9, 0x0E, 0x65, 0x92, 0xDC, 0x2B,
4291 + 0x0A, 0xFD, 0xB3, 0x44, 0x2F, 0xD8, 0x96, 0x61,
4292 + 0x55, 0xA2, 0xEC, 0x1B, 0x70, 0x87, 0xC9, 0x3E,
4293 + 0x1F, 0xE8, 0xA6, 0x51, 0x3A, 0xCD, 0x83, 0x74,
4294 + 0xC1, 0x36, 0x78, 0x8F, 0xE4, 0x13, 0x5D, 0xAA,
4295 + 0x8B, 0x7C, 0x32, 0xC5, 0xAE, 0x59, 0x17, 0xE0,
4296 + 0x2A, 0xDD, 0x93, 0x64, 0x0F, 0xF8, 0xB6, 0x41,
4297 + 0x60, 0x97, 0xD9, 0x2E, 0x45, 0xB2, 0xFC, 0x0B,
4298 + 0xBE, 0x49, 0x07, 0xF0, 0x9B, 0x6C, 0x22, 0xD5,
4299 + 0xF4, 0x03, 0x4D, 0xBA, 0xD1, 0x26, 0x68, 0x9F,
4301 + return t[crc ^ data];
4304 +static u8 bcm43xx_sprom_crc(const u16 *sprom)
4309 + for (word = 0; word < BCM43xx_SPROM_SIZE - 1; word++) {
4310 + crc = bcm43xx_crc8(crc, sprom[word] & 0x00FF);
4311 + crc = bcm43xx_crc8(crc, (sprom[word] & 0xFF00) >> 8);
4313 + crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
4319 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
4322 + u8 crc, expected_crc;
4324 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++)
4325 + sprom[i] = bcm43xx_read16(bcm, BCM43xx_SPROM_BASE + (i * 2));
4326 + /* CRC-8 check. */
4327 + crc = bcm43xx_sprom_crc(sprom);
4328 + expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
4329 + if (crc != expected_crc) {
4330 + printk(KERN_WARNING PFX "WARNING: Invalid SPROM checksum "
4331 + "(0x%02X, expected: 0x%02X)\n",
4332 + crc, expected_crc);
4339 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
4342 + u8 crc, expected_crc;
4345 + /* CRC-8 validation of the input data. */
4346 + crc = bcm43xx_sprom_crc(sprom);
4347 + expected_crc = (sprom[BCM43xx_SPROM_VERSION] & 0xFF00) >> 8;
4348 + if (crc != expected_crc) {
4349 + printk(KERN_ERR PFX "SPROM input data: Invalid CRC\n");
4353 + printk(KERN_INFO PFX "Writing SPROM. Do NOT turn off the power! Please stand by...\n");
4354 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_SPROMCTL, &spromctl);
4357 + spromctl |= 0x10; /* SPROM WRITE enable. */
4358 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4361 + /* We must burn lots of CPU cycles here, but that does not
4362 + * really matter as one does not write the SPROM every other minute...
4364 + printk(KERN_INFO PFX "[ 0%%");
4366 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
4375 + bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
4379 + spromctl &= ~0x10; /* SPROM WRITE enable. */
4380 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4384 + printk("100%% ]\n");
4385 + printk(KERN_INFO PFX "SPROM written.\n");
4386 + bcm43xx_controller_restart(bcm, "SPROM update");
4390 + printk(KERN_ERR PFX "Could not access SPROM control register.\n");
4394 +static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
4398 +#ifdef CONFIG_BCM947XX
4402 + sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
4405 + printk(KERN_ERR PFX "sprom_extract OOM\n");
4408 +#ifdef CONFIG_BCM947XX
4409 + sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
4410 + sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
4412 + if ((c = nvram_get("il0macaddr")) != NULL)
4413 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
4415 + if ((c = nvram_get("et1macaddr")) != NULL)
4416 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
4418 + sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
4419 + sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
4420 + sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
4422 + sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
4423 + sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
4424 + sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
4426 + sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
4428 + bcm43xx_sprom_read(bcm, sprom);
4432 + value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
4433 + bcm->sprom.boardflags2 = value;
4436 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 0];
4437 + *(((u16 *)bcm->sprom.il0macaddr) + 0) = cpu_to_be16(value);
4438 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 1];
4439 + *(((u16 *)bcm->sprom.il0macaddr) + 1) = cpu_to_be16(value);
4440 + value = sprom[BCM43xx_SPROM_IL0MACADDR + 2];
4441 + *(((u16 *)bcm->sprom.il0macaddr) + 2) = cpu_to_be16(value);
4444 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 0];
4445 + *(((u16 *)bcm->sprom.et0macaddr) + 0) = cpu_to_be16(value);
4446 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 1];
4447 + *(((u16 *)bcm->sprom.et0macaddr) + 1) = cpu_to_be16(value);
4448 + value = sprom[BCM43xx_SPROM_ET0MACADDR + 2];
4449 + *(((u16 *)bcm->sprom.et0macaddr) + 2) = cpu_to_be16(value);
4452 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 0];
4453 + *(((u16 *)bcm->sprom.et1macaddr) + 0) = cpu_to_be16(value);
4454 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 1];
4455 + *(((u16 *)bcm->sprom.et1macaddr) + 1) = cpu_to_be16(value);
4456 + value = sprom[BCM43xx_SPROM_ET1MACADDR + 2];
4457 + *(((u16 *)bcm->sprom.et1macaddr) + 2) = cpu_to_be16(value);
4459 + /* ethernet phy settings */
4460 + value = sprom[BCM43xx_SPROM_ETHPHY];
4461 + bcm->sprom.et0phyaddr = (value & 0x001F);
4462 + bcm->sprom.et1phyaddr = (value & 0x03E0) >> 5;
4463 + bcm->sprom.et0mdcport = (value & (1 << 14)) >> 14;
4464 + bcm->sprom.et1mdcport = (value & (1 << 15)) >> 15;
4466 + /* boardrev, antennas, locale */
4467 + value = sprom[BCM43xx_SPROM_BOARDREV];
4468 + bcm->sprom.boardrev = (value & 0x00FF);
4469 + bcm->sprom.locale = (value & 0x0F00) >> 8;
4470 + bcm->sprom.antennas_aphy = (value & 0x3000) >> 12;
4471 + bcm->sprom.antennas_bgphy = (value & 0xC000) >> 14;
4474 + value = sprom[BCM43xx_SPROM_PA0B0];
4475 + bcm->sprom.pa0b0 = value;
4476 + value = sprom[BCM43xx_SPROM_PA0B1];
4477 + bcm->sprom.pa0b1 = value;
4478 + value = sprom[BCM43xx_SPROM_PA0B2];
4479 + bcm->sprom.pa0b2 = value;
4482 + value = sprom[BCM43xx_SPROM_WL0GPIO0];
4483 + if (value == 0x0000)
4485 + bcm->sprom.wl0gpio0 = value & 0x00FF;
4486 + bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
4487 + value = sprom[BCM43xx_SPROM_WL0GPIO2];
4488 + if (value == 0x0000)
4490 + bcm->sprom.wl0gpio2 = value & 0x00FF;
4491 + bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
4494 + value = sprom[BCM43xx_SPROM_MAXPWR];
4495 + bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
4496 + bcm->sprom.maxpower_bgphy = value & 0x00FF;
4499 + value = sprom[BCM43xx_SPROM_PA1B0];
4500 + bcm->sprom.pa1b0 = value;
4501 + value = sprom[BCM43xx_SPROM_PA1B1];
4502 + bcm->sprom.pa1b1 = value;
4503 + value = sprom[BCM43xx_SPROM_PA1B2];
4504 + bcm->sprom.pa1b2 = value;
4506 + /* idle tssi target */
4507 + value = sprom[BCM43xx_SPROM_IDL_TSSI_TGT];
4508 + bcm->sprom.idle_tssi_tgt_aphy = value & 0x00FF;
4509 + bcm->sprom.idle_tssi_tgt_bgphy = (value & 0xFF00) >> 8;
4512 + value = sprom[BCM43xx_SPROM_BOARDFLAGS];
4513 + if (value == 0xFFFF)
4515 + bcm->sprom.boardflags = value;
4516 + /* boardflags workarounds */
4517 + if (bcm->board_vendor == PCI_VENDOR_ID_DELL &&
4518 + bcm->chip_id == 0x4301 &&
4519 + bcm->board_revision == 0x74)
4520 + bcm->sprom.boardflags |= BCM43xx_BFL_BTCOEXIST;
4521 + if (bcm->board_vendor == PCI_VENDOR_ID_APPLE &&
4522 + bcm->board_type == 0x4E &&
4523 + bcm->board_revision > 0x40)
4524 + bcm->sprom.boardflags |= BCM43xx_BFL_PACTRL;
4526 + /* antenna gain */
4527 + value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
4528 + if (value == 0x0000 || value == 0xFFFF)
4530 + /* convert values to Q5.2 */
4531 + bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
4532 + bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
4539 +/* DummyTransmission function, as documented on
4540 + * http://bcm-specs.sipsolutions.net/DummyTransmission
4542 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
4544 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4545 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4546 + unsigned int i, max_loop;
4556 + switch (phy->type) {
4557 + case BCM43xx_PHYTYPE_A:
4559 + buffer[0] = 0xCC010200;
4561 + case BCM43xx_PHYTYPE_B:
4562 + case BCM43xx_PHYTYPE_G:
4564 + buffer[0] = 0x6E840B00;
4571 + for (i = 0; i < 5; i++)
4572 + bcm43xx_ram_write(bcm, i * 4, buffer[i]);
4574 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
4576 + bcm43xx_write16(bcm, 0x0568, 0x0000);
4577 + bcm43xx_write16(bcm, 0x07C0, 0x0000);
4578 + bcm43xx_write16(bcm, 0x050C, ((phy->type == BCM43xx_PHYTYPE_A) ? 1 : 0));
4579 + bcm43xx_write16(bcm, 0x0508, 0x0000);
4580 + bcm43xx_write16(bcm, 0x050A, 0x0000);
4581 + bcm43xx_write16(bcm, 0x054C, 0x0000);
4582 + bcm43xx_write16(bcm, 0x056A, 0x0014);
4583 + bcm43xx_write16(bcm, 0x0568, 0x0826);
4584 + bcm43xx_write16(bcm, 0x0500, 0x0000);
4585 + bcm43xx_write16(bcm, 0x0502, 0x0030);
4587 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4588 + bcm43xx_radio_write16(bcm, 0x0051, 0x0017);
4589 + for (i = 0x00; i < max_loop; i++) {
4590 + value = bcm43xx_read16(bcm, 0x050E);
4591 + if (value & 0x0080)
4595 + for (i = 0x00; i < 0x0A; i++) {
4596 + value = bcm43xx_read16(bcm, 0x050E);
4597 + if (value & 0x0400)
4601 + for (i = 0x00; i < 0x0A; i++) {
4602 + value = bcm43xx_read16(bcm, 0x0690);
4603 + if (!(value & 0x0100))
4607 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4608 + bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
4611 +static void key_write(struct bcm43xx_private *bcm,
4612 + u8 index, u8 algorithm, const u16 *key)
4614 + unsigned int i, basic_wep = 0;
4618 + /* Write associated key information */
4619 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
4620 + ((index << 4) | (algorithm & 0x0F)));
4622 + /* The first 4 WEP keys need extra love */
4623 + if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
4624 + (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
4627 + /* Write key payload, 8 little endian words */
4628 + offset = bcm->security_offset + (index * BCM43xx_SEC_KEYSIZE);
4629 + for (i = 0; i < (BCM43xx_SEC_KEYSIZE / sizeof(u16)); i++) {
4630 + value = cpu_to_le16(key[i]);
4631 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4632 + offset + (i * 2), value);
4637 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4638 + offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
4643 +static void keymac_write(struct bcm43xx_private *bcm,
4644 + u8 index, const u32 *addr)
4646 + /* for keys 0-3 there is no associated mac address */
4651 + if (bcm->current_core->rev >= 5) {
4652 + bcm43xx_shm_write32(bcm,
4653 + BCM43xx_SHM_HWMAC,
4655 + cpu_to_be32(*addr));
4656 + bcm43xx_shm_write16(bcm,
4657 + BCM43xx_SHM_HWMAC,
4659 + cpu_to_be16(*((u16 *)(addr + 1))));
4662 + TODO(); /* Put them in the macaddress filter */
4665 + /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
4666 + Keep in mind to update the count of keymacs in 0x003E as well! */
4671 +static int bcm43xx_key_write(struct bcm43xx_private *bcm,
4672 + u8 index, u8 algorithm,
4673 + const u8 *_key, int key_len,
4674 + const u8 *mac_addr)
4676 + u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
4678 + if (index >= ARRAY_SIZE(bcm->key))
4680 + if (key_len > ARRAY_SIZE(key))
4682 + if (algorithm < 1 || algorithm > 5)
4685 + memcpy(key, _key, key_len);
4686 + key_write(bcm, index, algorithm, (const u16 *)key);
4687 + keymac_write(bcm, index, (const u32 *)mac_addr);
4689 + bcm->key[index].algorithm = algorithm;
4694 +static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
4696 + static const u32 zero_mac[2] = { 0 };
4697 + unsigned int i,j, nr_keys = 54;
4700 + if (bcm->current_core->rev < 5)
4702 + assert(nr_keys <= ARRAY_SIZE(bcm->key));
4704 + for (i = 0; i < nr_keys; i++) {
4705 + bcm->key[i].enabled = 0;
4706 + /* returns for i < 4 immediately */
4707 + keymac_write(bcm, i, zero_mac);
4708 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4709 + 0x100 + (i * 2), 0x0000);
4710 + for (j = 0; j < 8; j++) {
4711 + offset = bcm->security_offset + (j * 4) + (i * BCM43xx_SEC_KEYSIZE);
4712 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4716 + dprintk(KERN_INFO PFX "Keys cleared\n");
4719 +/* Lowlevel core-switch function. This is only to be used in
4720 + * bcm43xx_switch_core() and bcm43xx_probe_cores()
4722 +static int _switch_core(struct bcm43xx_private *bcm, int core)
4728 + assert(core >= 0);
4730 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4731 + (core * 0x1000) + 0x18000000);
4732 + if (unlikely(err))
4734 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4736 + if (unlikely(err))
4738 + current_core = (current_core - 0x18000000) / 0x1000;
4739 + if (current_core == core)
4742 + if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
4746 +#ifdef CONFIG_BCM947XX
4747 + if (bcm->pci_dev->bus->number == 0)
4748 + bcm->current_core_offset = 0x1000 * core;
4750 + bcm->current_core_offset = 0;
4755 + printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
4759 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
4763 + if (unlikely(!new_core))
4765 + if (!new_core->available)
4767 + if (bcm->current_core == new_core)
4769 + err = _switch_core(bcm, new_core->index);
4770 + if (unlikely(err))
4773 + bcm->current_core = new_core;
4774 + bcm->current_80211_core_idx = -1;
4775 + if (new_core->id == BCM43xx_COREID_80211)
4776 + bcm->current_80211_core_idx = (int)(new_core - &(bcm->core_80211[0]));
4782 +static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
4786 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4787 + value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
4788 + | BCM43xx_SBTMSTATELOW_REJECT;
4790 + return (value == BCM43xx_SBTMSTATELOW_CLOCK);
4793 +/* disable current core */
4794 +static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
4797 + u32 sbtmstatehigh;
4800 + /* fetch sbtmstatelow from core information registers */
4801 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4803 + /* core is already in reset */
4804 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
4807 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
4808 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4809 + BCM43xx_SBTMSTATELOW_REJECT;
4810 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4812 + for (i = 0; i < 1000; i++) {
4813 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4814 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
4821 + printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
4825 + for (i = 0; i < 1000; i++) {
4826 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4827 + if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
4834 + printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
4838 + sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4839 + BCM43xx_SBTMSTATELOW_REJECT |
4840 + BCM43xx_SBTMSTATELOW_RESET |
4841 + BCM43xx_SBTMSTATELOW_CLOCK |
4843 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4847 + sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
4848 + BCM43xx_SBTMSTATELOW_REJECT |
4850 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4853 + bcm->current_core->enabled = 0;
4858 +/* enable (reset) current core */
4859 +static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
4862 + u32 sbtmstatehigh;
4866 + err = bcm43xx_core_disable(bcm, core_flags);
4870 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4871 + BCM43xx_SBTMSTATELOW_RESET |
4872 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4874 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4877 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4878 + if (sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_SERROR) {
4879 + sbtmstatehigh = 0x00000000;
4880 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATEHIGH, sbtmstatehigh);
4883 + sbimstate = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMSTATE);
4884 + if (sbimstate & (BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT)) {
4885 + sbimstate &= ~(BCM43xx_SBIMSTATE_IB_ERROR | BCM43xx_SBIMSTATE_TIMEOUT);
4886 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMSTATE, sbimstate);
4889 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4890 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4892 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4895 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
4896 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4899 + bcm->current_core->enabled = 1;
4905 +/* http://bcm-specs.sipsolutions.net/80211CoreReset */
4906 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
4908 + u32 flags = 0x00040000;
4910 + if ((bcm43xx_core_enabled(bcm)) &&
4911 + !bcm43xx_using_pio(bcm)) {
4912 +//FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
4913 +#ifndef CONFIG_BCM947XX
4914 + /* reset all used DMA controllers. */
4915 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
4916 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
4917 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
4918 + bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
4919 + bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
4920 + if (bcm->current_core->rev < 5)
4921 + bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
4924 + if (bcm->shutting_down) {
4925 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
4926 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
4927 + & ~(BCM43xx_SBF_MAC_ENABLED | 0x00000002));
4930 + flags |= 0x20000000;
4931 + bcm43xx_phy_connect(bcm, connect_phy);
4932 + bcm43xx_core_enable(bcm, flags);
4933 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
4934 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
4935 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
4936 + | BCM43xx_SBF_400);
4940 +static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
4942 + bcm43xx_radio_turn_off(bcm);
4943 + bcm43xx_write16(bcm, 0x03E6, 0x00F4);
4944 + bcm43xx_core_disable(bcm, 0);
4947 +/* Mark the current 80211 core inactive.
4948 + * "active_80211_core" is the other 80211 core, which is used.
4950 +static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
4951 + struct bcm43xx_coreinfo *active_80211_core)
4954 + struct bcm43xx_coreinfo *old_core;
4957 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4958 + bcm43xx_radio_turn_off(bcm);
4959 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4960 + sbtmstatelow &= ~0x200a0000;
4961 + sbtmstatelow |= 0xa0000;
4962 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4964 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4965 + sbtmstatelow &= ~0xa0000;
4966 + sbtmstatelow |= 0x80000;
4967 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4970 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
4971 + old_core = bcm->current_core;
4972 + err = bcm43xx_switch_core(bcm, active_80211_core);
4975 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4976 + sbtmstatelow &= ~0x20000000;
4977 + sbtmstatelow |= 0x20000000;
4978 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4979 + err = bcm43xx_switch_core(bcm, old_core);
4986 +static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
4990 + struct bcm43xx_xmitstatus stat;
4993 + v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
4996 + v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
4998 + stat.cookie = (v0 >> 16) & 0x0000FFFF;
4999 + tmp = (u16)((v0 & 0xFFF0) | ((v0 & 0xF) >> 1));
5000 + stat.flags = tmp & 0xFF;
5001 + stat.cnt1 = (tmp & 0x0F00) >> 8;
5002 + stat.cnt2 = (tmp & 0xF000) >> 12;
5003 + stat.seq = (u16)(v1 & 0xFFFF);
5004 + stat.unknown = (u16)((v1 >> 16) & 0xFF);
5006 + bcm43xx_debugfs_log_txstat(bcm, &stat);
5008 + if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
5010 + if (!(stat.flags & BCM43xx_TXSTAT_FLAG_ACK))
5011 + bcm->ieee_stats.dot11ACKFailureCount++;
5012 + //TODO: There are more (unknown) flags to test. see bcm43xx_main.h
5014 + if (bcm43xx_using_pio(bcm))
5015 + bcm43xx_pio_handle_xmitstatus(bcm, &stat);
5017 + bcm43xx_dma_handle_xmitstatus(bcm, &stat);
5021 +static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
5023 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x408, 0x7F7F);
5024 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x40A, 0x7F7F);
5025 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
5026 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD) | (1 << 4));
5027 + assert(bcm->noisecalc.core_at_start == bcm->current_core);
5028 + assert(bcm->noisecalc.channel_at_start == bcm43xx_current_radio(bcm)->channel);
5031 +static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
5033 + /* Top half of Link Quality calculation. */
5035 + if (bcm->noisecalc.calculation_running)
5037 + bcm->noisecalc.core_at_start = bcm->current_core;
5038 + bcm->noisecalc.channel_at_start = bcm43xx_current_radio(bcm)->channel;
5039 + bcm->noisecalc.calculation_running = 1;
5040 + bcm->noisecalc.nr_samples = 0;
5042 + bcm43xx_generate_noise_sample(bcm);
5045 +static void handle_irq_noise(struct bcm43xx_private *bcm)
5047 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5053 + /* Bottom half of Link Quality calculation. */
5055 + assert(bcm->noisecalc.calculation_running);
5056 + if (bcm->noisecalc.core_at_start != bcm->current_core ||
5057 + bcm->noisecalc.channel_at_start != radio->channel)
5058 + goto drop_calculation;
5059 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x408);
5060 + noise[0] = (tmp & 0x00FF);
5061 + noise[1] = (tmp & 0xFF00) >> 8;
5062 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40A);
5063 + noise[2] = (tmp & 0x00FF);
5064 + noise[3] = (tmp & 0xFF00) >> 8;
5065 + if (noise[0] == 0x7F || noise[1] == 0x7F ||
5066 + noise[2] == 0x7F || noise[3] == 0x7F)
5067 + goto generate_new;
5069 + /* Get the noise samples. */
5070 + assert(bcm->noisecalc.nr_samples <= 8);
5071 + i = bcm->noisecalc.nr_samples;
5072 + noise[0] = limit_value(noise[0], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
5073 + noise[1] = limit_value(noise[1], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
5074 + noise[2] = limit_value(noise[2], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
5075 + noise[3] = limit_value(noise[3], 0, ARRAY_SIZE(radio->nrssi_lt) - 1);
5076 + bcm->noisecalc.samples[i][0] = radio->nrssi_lt[noise[0]];
5077 + bcm->noisecalc.samples[i][1] = radio->nrssi_lt[noise[1]];
5078 + bcm->noisecalc.samples[i][2] = radio->nrssi_lt[noise[2]];
5079 + bcm->noisecalc.samples[i][3] = radio->nrssi_lt[noise[3]];
5080 + bcm->noisecalc.nr_samples++;
5081 + if (bcm->noisecalc.nr_samples == 8) {
5082 + /* Calculate the Link Quality by the noise samples. */
5084 + for (i = 0; i < 8; i++) {
5085 + for (j = 0; j < 4; j++)
5086 + average += bcm->noisecalc.samples[i][j];
5088 + average /= (8 * 4);
5092 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
5093 + tmp = (tmp / 128) & 0x1F;
5103 + if (average > -65)
5104 + bcm->stats.link_quality = 0;
5105 + else if (average > -75)
5106 + bcm->stats.link_quality = 1;
5107 + else if (average > -85)
5108 + bcm->stats.link_quality = 2;
5110 + bcm->stats.link_quality = 3;
5111 +// dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
5113 + bcm->noisecalc.calculation_running = 0;
5117 + bcm43xx_generate_noise_sample(bcm);
5120 +static void handle_irq_ps(struct bcm43xx_private *bcm)
5122 + if (bcm->iw_mode == IW_MODE_MASTER) {
5125 + if (1/*FIXME: the last PSpoll frame was sent successfully */)
5126 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5128 + if (bcm->iw_mode == IW_MODE_ADHOC)
5129 + bcm->reg124_set_0x4 = 1;
5130 + //FIXME else set to false?
5133 +static void handle_irq_reg124(struct bcm43xx_private *bcm)
5135 + if (!bcm->reg124_set_0x4)
5137 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
5138 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
5140 + //FIXME: reset reg124_set_0x4 to false?
5143 +static void handle_irq_pmq(struct bcm43xx_private *bcm)
5150 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
5151 + if (!(tmp & 0x00000008))
5154 + /* 16bit write is odd, but correct. */
5155 + bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
5158 +static void bcm43xx_write_beacon_template(struct bcm43xx_private *bcm,
5160 + u16 shm_size_offset)
5166 + data = (const u8 *)(bcm->cached_beacon->data);
5167 + size = min(bcm->cached_beacon->len, (unsigned int)17);
5169 + for (i = 0; i < size; i += sizeof(u32)) {
5170 + tmp = (u32)((data + i)[0]);
5171 + tmp |= (u32)((data + i)[1]) << 8;
5172 + tmp |= (u32)((data + i)[2]) << 16;
5173 + tmp |= (u32)((data + i)[3]) << 24;
5174 + bcm43xx_ram_write(bcm, ram_offset + i, tmp);
5176 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
5179 +static void handle_irq_beacon(struct bcm43xx_private *bcm)
5183 + bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
5184 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
5186 + if (!bcm->cached_beacon) {
5187 + struct ieee80211_tx_control control;
5189 + /* No cached template available, yet.
5190 + * Request the 80211 subsystem to generate a new beacon
5191 + * frame and use it as template.
5193 + bcm->cached_beacon = ieee80211_beacon_get(bcm->net_dev, 0, &control);
5194 + if (unlikely(!bcm->cached_beacon)) {
5195 + dprintkl(KERN_WARNING PFX "Could not generate beacon template.\n");
5200 + if ((status & 0x1) && (status & 0x2)) {
5202 + /* ACK beacon IRQ. */
5203 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON,
5204 + BCM43xx_IRQ_BEACON);
5205 + bcm->irq_savedstate |= BCM43xx_IRQ_BEACON;
5206 + if (likely(bcm->cached_beacon))
5207 + kfree_skb(bcm->cached_beacon);
5208 + bcm->cached_beacon = NULL;
5211 + if (!(status & 0x1)) {
5212 + bcm43xx_write_beacon_template(bcm, 0x68, 0x18);
5214 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5216 + if (!(status & 0x2)) {
5217 + bcm43xx_write_beacon_template(bcm, 0x468, 0x1A);
5219 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5223 +/* Interrupt handler bottom-half */
5224 +static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
5227 + u32 dma_reason[4];
5229 + unsigned long flags;
5231 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5232 + u32 _handled = 0x00000000;
5233 +# define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
5235 +# define bcmirq_handled(irq) do { /* nothing */ } while (0)
5236 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
5238 + bcm43xx_lock_mmio(bcm, flags);
5239 + reason = bcm->irq_reason;
5240 + dma_reason[0] = bcm->dma_reason[0];
5241 + dma_reason[1] = bcm->dma_reason[1];
5242 + dma_reason[2] = bcm->dma_reason[2];
5243 + dma_reason[3] = bcm->dma_reason[3];
5245 + if (unlikely(reason & BCM43xx_IRQ_XMIT_ERROR)) {
5246 + /* TX error. We get this when Template Ram is written in wrong endianess
5247 + * in dummy_tx(). We also get this if something is wrong with the TX header
5248 + * on DMA or PIO queues.
5249 + * Maybe we get this in other error conditions, too.
5251 + printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
5252 + bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
5254 + if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_FATALMASK) |
5255 + (dma_reason[1] & BCM43xx_DMAIRQ_FATALMASK) |
5256 + (dma_reason[2] & BCM43xx_DMAIRQ_FATALMASK) |
5257 + (dma_reason[3] & BCM43xx_DMAIRQ_FATALMASK))) {
5258 + printkl(KERN_ERR PFX "FATAL ERROR: Fatal DMA error: "
5259 + "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
5260 + dma_reason[0], dma_reason[1],
5261 + dma_reason[2], dma_reason[3]);
5262 + bcm43xx_controller_restart(bcm, "DMA error");
5263 + bcm43xx_unlock_mmio(bcm, flags);
5266 + if (unlikely((dma_reason[0] & BCM43xx_DMAIRQ_NONFATALMASK) |
5267 + (dma_reason[1] & BCM43xx_DMAIRQ_NONFATALMASK) |
5268 + (dma_reason[2] & BCM43xx_DMAIRQ_NONFATALMASK) |
5269 + (dma_reason[3] & BCM43xx_DMAIRQ_NONFATALMASK))) {
5270 + printkl(KERN_ERR PFX "DMA error: "
5271 + "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
5272 + dma_reason[0], dma_reason[1],
5273 + dma_reason[2], dma_reason[3]);
5276 + if (reason & BCM43xx_IRQ_PS) {
5277 + handle_irq_ps(bcm);
5278 + bcmirq_handled(BCM43xx_IRQ_PS);
5281 + if (reason & BCM43xx_IRQ_REG124) {
5282 + handle_irq_reg124(bcm);
5283 + bcmirq_handled(BCM43xx_IRQ_REG124);
5286 + if (reason & BCM43xx_IRQ_BEACON) {
5287 + if (bcm->iw_mode == IW_MODE_MASTER)
5288 + handle_irq_beacon(bcm);
5289 + bcmirq_handled(BCM43xx_IRQ_BEACON);
5292 + if (reason & BCM43xx_IRQ_PMQ) {
5293 + handle_irq_pmq(bcm);
5294 + bcmirq_handled(BCM43xx_IRQ_PMQ);
5297 + if (reason & BCM43xx_IRQ_SCAN) {
5299 + //bcmirq_handled(BCM43xx_IRQ_SCAN);
5302 + if (reason & BCM43xx_IRQ_NOISE) {
5303 + handle_irq_noise(bcm);
5304 + bcmirq_handled(BCM43xx_IRQ_NOISE);
5307 + /* Check the DMA reason registers for received data. */
5308 + assert(!(dma_reason[1] & BCM43xx_DMAIRQ_RX_DONE));
5309 + assert(!(dma_reason[2] & BCM43xx_DMAIRQ_RX_DONE));
5310 + if (dma_reason[0] & BCM43xx_DMAIRQ_RX_DONE) {
5311 + if (bcm43xx_using_pio(bcm))
5312 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue0);
5314 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
5315 + /* We intentionally don't set "activity" to 1, here. */
5317 + if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
5318 + if (bcm43xx_using_pio(bcm))
5319 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
5321 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
5324 + bcmirq_handled(BCM43xx_IRQ_RX);
5326 + if (reason & BCM43xx_IRQ_XMIT_STATUS) {
5327 + handle_irq_transmit_status(bcm);
5329 + //TODO: In AP mode, this also causes sending of powersave responses.
5330 + bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
5333 + /* IRQ_PIO_WORKAROUND is handled in the top-half. */
5334 + bcmirq_handled(BCM43xx_IRQ_PIO_WORKAROUND);
5335 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5336 + if (unlikely(reason & ~_handled)) {
5337 + printkl(KERN_WARNING PFX
5338 + "Unhandled IRQ! Reason: 0x%08x, Unhandled: 0x%08x, "
5339 + "DMA: 0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
5340 + reason, (reason & ~_handled),
5341 + dma_reason[0], dma_reason[1],
5342 + dma_reason[2], dma_reason[3]);
5345 +#undef bcmirq_handled
5347 + if (!modparam_noleds)
5348 + bcm43xx_leds_update(bcm, activity);
5349 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
5350 + bcm43xx_unlock_mmio(bcm, flags);
5353 +static void pio_irq_workaround(struct bcm43xx_private *bcm,
5354 + u16 base, int queueidx)
5358 + rxctl = bcm43xx_read16(bcm, base + BCM43xx_PIO_RXCTL);
5359 + if (rxctl & BCM43xx_PIO_RXCTL_DATAAVAILABLE)
5360 + bcm->dma_reason[queueidx] |= BCM43xx_DMAIRQ_RX_DONE;
5362 + bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
5365 +static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
5367 + if (bcm43xx_using_pio(bcm) &&
5368 + (bcm->current_core->rev < 3) &&
5369 + (!(reason & BCM43xx_IRQ_PIO_WORKAROUND))) {
5370 + /* Apply a PIO specific workaround to the dma_reasons */
5371 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO1_BASE, 0);
5372 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO2_BASE, 1);
5373 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO3_BASE, 2);
5374 + pio_irq_workaround(bcm, BCM43xx_MMIO_PIO4_BASE, 3);
5377 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
5379 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_REASON,
5380 + bcm->dma_reason[0]);
5381 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_REASON,
5382 + bcm->dma_reason[1]);
5383 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_REASON,
5384 + bcm->dma_reason[2]);
5385 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_REASON,
5386 + bcm->dma_reason[3]);
5389 +/* Interrupt handler top-half */
5390 +static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
5392 + irqreturn_t ret = IRQ_HANDLED;
5393 + struct bcm43xx_private *bcm = dev_id;
5399 + spin_lock(&bcm->_lock);
5401 + reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5402 + if (reason == 0xffffffff) {
5403 + /* irq not for us (shared irq) */
5407 + reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
5411 + bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
5413 + bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
5415 + bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
5417 + bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
5420 + bcm43xx_interrupt_ack(bcm, reason);
5422 + /* Only accept IRQs, if we are initialized properly.
5423 + * This avoids an RX race while initializing.
5424 + * We should probably not enable IRQs before we are initialized
5425 + * completely, but some careful work is needed to fix this. I think it
5426 + * is best to stay with this cheap workaround for now... .
5428 + if (likely(bcm->initialized)) {
5429 + /* disable all IRQs. They are enabled again in the bottom half. */
5430 + bcm->irq_savedstate = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
5431 + /* save the reason code and call our bottom half. */
5432 + bcm->irq_reason = reason;
5433 + tasklet_schedule(&bcm->isr_tasklet);
5438 + spin_unlock(&bcm->_lock);
5443 +static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
5445 + if (bcm->firmware_norelease && !force)
5446 + return; /* Suspending or controller reset. */
5447 + release_firmware(bcm->ucode);
5448 + bcm->ucode = NULL;
5449 + release_firmware(bcm->pcm);
5451 + release_firmware(bcm->initvals0);
5452 + bcm->initvals0 = NULL;
5453 + release_firmware(bcm->initvals1);
5454 + bcm->initvals1 = NULL;
5457 +static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
5459 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5460 + u8 rev = bcm->current_core->rev;
5463 + char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
5465 + if (!bcm->ucode) {
5466 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_microcode%d%s.fw",
5467 + (rev >= 5 ? 5 : rev),
5468 + modparam_fwpostfix);
5469 + err = request_firmware(&bcm->ucode, buf, &bcm->pci_dev->dev);
5471 + printk(KERN_ERR PFX
5472 + "Error: Microcode \"%s\" not available or load failed.\n",
5479 + snprintf(buf, ARRAY_SIZE(buf),
5480 + "bcm43xx_pcm%d%s.fw",
5481 + (rev < 5 ? 4 : 5),
5482 + modparam_fwpostfix);
5483 + err = request_firmware(&bcm->pcm, buf, &bcm->pci_dev->dev);
5485 + printk(KERN_ERR PFX
5486 + "Error: PCM \"%s\" not available or load failed.\n",
5492 + if (!bcm->initvals0) {
5493 + if (rev == 2 || rev == 4) {
5494 + switch (phy->type) {
5495 + case BCM43xx_PHYTYPE_A:
5498 + case BCM43xx_PHYTYPE_B:
5499 + case BCM43xx_PHYTYPE_G:
5503 + goto err_noinitval;
5506 + } else if (rev >= 5) {
5507 + switch (phy->type) {
5508 + case BCM43xx_PHYTYPE_A:
5511 + case BCM43xx_PHYTYPE_B:
5512 + case BCM43xx_PHYTYPE_G:
5516 + goto err_noinitval;
5519 + goto err_noinitval;
5520 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5521 + nr, modparam_fwpostfix);
5523 + err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
5525 + printk(KERN_ERR PFX
5526 + "Error: InitVals \"%s\" not available or load failed.\n",
5530 + if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
5531 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5536 + if (!bcm->initvals1) {
5538 + u32 sbtmstatehigh;
5540 + switch (phy->type) {
5541 + case BCM43xx_PHYTYPE_A:
5542 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
5543 + if (sbtmstatehigh & 0x00010000)
5548 + case BCM43xx_PHYTYPE_B:
5549 + case BCM43xx_PHYTYPE_G:
5553 + goto err_noinitval;
5555 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5556 + nr, modparam_fwpostfix);
5558 + err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
5560 + printk(KERN_ERR PFX
5561 + "Error: InitVals \"%s\" not available or load failed.\n",
5565 + if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
5566 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5575 + bcm43xx_release_firmware(bcm, 1);
5578 + printk(KERN_ERR PFX "Error: No InitVals available!\n");
5583 +static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
5586 + unsigned int i, len;
5588 + /* Upload Microcode. */
5589 + data = (u32 *)(bcm->ucode->data);
5590 + len = bcm->ucode->size / sizeof(u32);
5591 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_UCODE, 0x0000);
5592 + for (i = 0; i < len; i++) {
5593 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
5594 + be32_to_cpu(data[i]));
5598 + /* Upload PCM data. */
5599 + data = (u32 *)(bcm->pcm->data);
5600 + len = bcm->pcm->size / sizeof(u32);
5601 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01ea);
5602 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, 0x00004000);
5603 + bcm43xx_shm_control_word(bcm, BCM43xx_SHM_PCM, 0x01eb);
5604 + for (i = 0; i < len; i++) {
5605 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA,
5606 + be32_to_cpu(data[i]));
5611 +static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
5612 + const struct bcm43xx_initval *data,
5613 + const unsigned int len)
5619 + for (i = 0; i < len; i++) {
5620 + offset = be16_to_cpu(data[i].offset);
5621 + size = be16_to_cpu(data[i].size);
5622 + value = be32_to_cpu(data[i].value);
5624 + if (unlikely(offset >= 0x1000))
5627 + if (unlikely(value & 0xFFFF0000))
5629 + bcm43xx_write16(bcm, offset, (u16)value);
5630 + } else if (size == 4) {
5631 + bcm43xx_write32(bcm, offset, value);
5639 + printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
5640 + "Please fix your bcm43xx firmware files.\n");
5644 +static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
5648 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
5649 + bcm->initvals0->size / sizeof(struct bcm43xx_initval));
5652 + if (bcm->initvals1) {
5653 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
5654 + bcm->initvals1->size / sizeof(struct bcm43xx_initval));
5662 +static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
5668 + bcm->irq = bcm->pci_dev->irq;
5669 +#ifdef CONFIG_BCM947XX
5670 + if (bcm->pci_dev->bus->number == 0) {
5671 + struct pci_dev *d = NULL;
5672 + /* FIXME: we will probably need more device IDs here... */
5673 + d = pci_find_device(PCI_VENDOR_ID_BROADCOM, 0x4324, NULL);
5675 + bcm->irq = d->irq;
5679 + res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
5680 + SA_SHIRQ, KBUILD_MODNAME, bcm);
5682 + printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
5685 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
5686 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
5689 + data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5690 + if (data == BCM43xx_IRQ_READY)
5693 + if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
5694 + printk(KERN_ERR PFX "Card IRQ register not responding. "
5696 + free_irq(bcm->irq, bcm);
5702 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5707 +/* Switch to the core used to write the GPIO register.
5708 + * This is either the ChipCommon, or the PCI core.
5710 +static int switch_to_gpio_core(struct bcm43xx_private *bcm)
5714 + /* Where to find the GPIO register depends on the chipset.
5715 + * If it has a ChipCommon, its register at offset 0x6c is the GPIO
5716 + * control register. Otherwise the register at offset 0x6c in the
5717 + * PCI core is the GPIO control register.
5719 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
5720 + if (err == -ENODEV) {
5721 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
5722 + if (unlikely(err == -ENODEV)) {
5723 + printk(KERN_ERR PFX "gpio error: "
5724 + "Neither ChipCommon nor PCI core available!\n");
5731 +/* Initialize the GPIOs
5732 + * http://bcm-specs.sipsolutions.net/GPIO
5734 +static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
5736 + struct bcm43xx_coreinfo *old_core;
5740 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5741 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5744 + bcm43xx_leds_switch_all(bcm, 0);
5745 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5746 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
5748 + mask = 0x0000001F;
5750 + if (bcm->chip_id == 0x4301) {
5754 + if (0 /* FIXME: conditional unknown */) {
5755 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5756 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5761 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
5762 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5763 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5768 + if (bcm->current_core->rev >= 2)
5769 + mask |= 0x0010; /* FIXME: This is redundant. */
5771 + old_core = bcm->current_core;
5772 + err = switch_to_gpio_core(bcm);
5775 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
5776 + (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
5777 + err = bcm43xx_switch_core(bcm, old_core);
5782 +/* Turn off all GPIO stuff. Call this on module unload, for example. */
5783 +static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
5785 + struct bcm43xx_coreinfo *old_core;
5788 + old_core = bcm->current_core;
5789 + err = switch_to_gpio_core(bcm);
5792 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
5793 + err = bcm43xx_switch_core(bcm, old_core);
5799 +/* http://bcm-specs.sipsolutions.net/EnableMac */
5800 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
5802 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5803 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5804 + | BCM43xx_SBF_MAC_ENABLED);
5805 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, BCM43xx_IRQ_READY);
5806 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
5807 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
5808 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5811 +/* http://bcm-specs.sipsolutions.net/SuspendMAC */
5812 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
5817 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
5818 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5819 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5820 + & ~BCM43xx_SBF_MAC_ENABLED);
5821 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON); /* dummy read */
5822 + for (i = 100000; i; i--) {
5823 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5824 + if (tmp & BCM43xx_IRQ_READY)
5828 + printkl(KERN_ERR PFX "MAC suspend failed\n");
5831 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
5834 + struct net_device *net_dev = bcm->net_dev;
5838 + bcm->iw_mode = iw_mode;
5839 + if (iw_mode == IW_MODE_MONITOR)
5840 + net_dev->type = ARPHRD_IEEE80211;
5842 + net_dev->type = ARPHRD_ETHER;
5844 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5845 + /* Reset status to infrastructured mode */
5846 + status &= ~(BCM43xx_SBF_MODE_AP | BCM43xx_SBF_MODE_MONITOR);
5847 + status &= ~BCM43xx_SBF_MODE_PROMISC;
5848 + status |= BCM43xx_SBF_MODE_NOTADHOC;
5850 +/* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
5851 +status |= BCM43xx_SBF_MODE_PROMISC;
5853 + switch (iw_mode) {
5854 + case IW_MODE_MONITOR:
5855 + status |= BCM43xx_SBF_MODE_MONITOR;
5856 + status |= BCM43xx_SBF_MODE_PROMISC;
5858 + case IW_MODE_ADHOC:
5859 + status &= ~BCM43xx_SBF_MODE_NOTADHOC;
5861 + case IW_MODE_MASTER:
5862 + status |= BCM43xx_SBF_MODE_AP;
5864 + case IW_MODE_SECOND:
5865 + case IW_MODE_REPEAT:
5866 + TODO(); /* TODO */
5868 + case IW_MODE_INFRA:
5869 + /* nothing to be done here... */
5872 + dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
5874 + if (net_dev->flags & IFF_PROMISC)
5875 + status |= BCM43xx_SBF_MODE_PROMISC;
5876 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
5879 + if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
5880 + if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
5885 + bcm43xx_write16(bcm, 0x0612, value);
5888 +/* This is the opposite of bcm43xx_chip_init() */
5889 +static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
5891 + bcm43xx_radio_turn_off(bcm);
5892 + if (!modparam_noleds)
5893 + bcm43xx_leds_exit(bcm);
5894 + bcm43xx_gpio_cleanup(bcm);
5895 + free_irq(bcm->irq, bcm);
5896 + bcm43xx_release_firmware(bcm, 0);
5899 +/* Initialize the chip
5900 + * http://bcm-specs.sipsolutions.net/ChipInit
5902 +static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
5904 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5905 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5911 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5912 + BCM43xx_SBF_CORE_READY
5913 + | BCM43xx_SBF_400);
5915 + err = bcm43xx_request_firmware(bcm);
5918 + bcm43xx_upload_microcode(bcm);
5919 + err = bcm43xx_initialize_irq(bcm);
5921 + goto err_release_fw;
5922 + err = bcm43xx_gpio_init(bcm);
5924 + goto err_free_irq;
5925 + err = bcm43xx_upload_initvals(bcm);
5927 + goto err_gpio_cleanup;
5928 + bcm43xx_radio_turn_on(bcm);
5930 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
5931 + err = bcm43xx_phy_init(bcm);
5933 + goto err_radio_off;
5935 + /* Select initial Interference Mitigation. */
5936 + tmp = radio->interfmode;
5937 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
5938 + bcm43xx_radio_set_interference_mitigation(bcm, tmp);
5940 + bcm43xx_phy_set_antenna_diversity(bcm);
5941 + bcm43xx_radio_set_txantenna(bcm, BCM43xx_RADIO_TXANTENNA_DEFAULT);
5942 + if (phy->type == BCM43xx_PHYTYPE_B) {
5943 + value16 = bcm43xx_read16(bcm, 0x005E);
5944 + value16 |= 0x0004;
5945 + bcm43xx_write16(bcm, 0x005E, value16);
5947 + bcm43xx_write32(bcm, 0x0100, 0x01000000);
5948 + if (bcm->current_core->rev < 5)
5949 + bcm43xx_write32(bcm, 0x010C, 0x01000000);
5951 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5952 + value32 &= ~ BCM43xx_SBF_MODE_NOTADHOC;
5953 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5954 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5955 + value32 |= BCM43xx_SBF_MODE_NOTADHOC;
5956 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5958 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5959 + value32 |= 0x100000;
5960 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5962 + if (bcm43xx_using_pio(bcm)) {
5963 + bcm43xx_write32(bcm, 0x0210, 0x00000100);
5964 + bcm43xx_write32(bcm, 0x0230, 0x00000100);
5965 + bcm43xx_write32(bcm, 0x0250, 0x00000100);
5966 + bcm43xx_write32(bcm, 0x0270, 0x00000100);
5967 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0034, 0x0000);
5970 + /* Probe Response Timeout value */
5971 + /* FIXME: Default to 0, has to be set by ioctl probably... :-/ */
5972 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0074, 0x0000);
5974 + /* Initially set the wireless operation mode. */
5975 + bcm43xx_set_iwmode(bcm, bcm->iw_mode);
5977 + if (bcm->current_core->rev < 3) {
5978 + bcm43xx_write16(bcm, 0x060E, 0x0000);
5979 + bcm43xx_write16(bcm, 0x0610, 0x8000);
5980 + bcm43xx_write16(bcm, 0x0604, 0x0000);
5981 + bcm43xx_write16(bcm, 0x0606, 0x0200);
5983 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
5984 + bcm43xx_write32(bcm, 0x018C, 0x02000000);
5986 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0x00004000);
5987 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA1_IRQ_MASK, 0x0001DC00);
5988 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA2_IRQ_MASK, 0x0000DC00);
5989 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA3_IRQ_MASK, 0x0000DC00);
5990 + bcm43xx_write32(bcm, BCM43xx_MMIO_DMA4_IRQ_MASK, 0x0001DC00);
5992 + value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
5993 + value32 |= 0x00100000;
5994 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
5996 + bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
5999 + dprintk(KERN_INFO PFX "Chip initialized\n");
6004 + bcm43xx_radio_turn_off(bcm);
6006 + bcm43xx_gpio_cleanup(bcm);
6008 + free_irq(bcm->irq, bcm);
6010 + bcm43xx_release_firmware(bcm, 1);
6014 +/* Validate chip access
6015 + * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
6016 +static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
6021 + shm_backup = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000);
6022 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0xAA5555AA);
6023 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0xAA5555AA)
6025 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
6026 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
6028 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
6030 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
6031 + if ((value | 0x80000000) != 0x80000400)
6034 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
6035 + if (value != 0x00000000)
6040 + printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
6044 +static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
6046 + /* Initialize a "phyinfo" structure. The structure is already
6049 + phy->antenna_diversity = 0xFFFF;
6050 + phy->savedpctlreg = 0xFFFF;
6051 + phy->minlowsig[0] = 0xFFFF;
6052 + phy->minlowsig[1] = 0xFFFF;
6053 + spin_lock_init(&phy->lock);
6056 +static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
6058 + /* Initialize a "radioinfo" structure. The structure is already
6061 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
6062 + radio->channel = 0xFF;
6063 + radio->initial_channel = 0xFF;
6064 + radio->lofcal = 0xFFFF;
6065 + radio->initval = 0xFFFF;
6066 + radio->nrssi[0] = -1000;
6067 + radio->nrssi[1] = -1000;
6070 +static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
6074 + u32 core_vendor, core_id, core_rev;
6075 + u32 sb_id_hi, chip_id_32 = 0;
6076 + u16 pci_device, chip_id_16;
6079 + memset(&bcm->core_chipcommon, 0, sizeof(struct bcm43xx_coreinfo));
6080 + memset(&bcm->core_pci, 0, sizeof(struct bcm43xx_coreinfo));
6081 + memset(&bcm->core_80211, 0, sizeof(struct bcm43xx_coreinfo)
6082 + * BCM43xx_MAX_80211_CORES);
6083 + memset(&bcm->core_80211_ext, 0, sizeof(struct bcm43xx_coreinfo_80211)
6084 + * BCM43xx_MAX_80211_CORES);
6085 + bcm->current_80211_core_idx = -1;
6086 + bcm->nr_80211_available = 0;
6087 + bcm->current_core = NULL;
6088 + bcm->active_80211_core = NULL;
6091 + err = _switch_core(bcm, 0);
6095 + /* fetch sb_id_hi from core information registers */
6096 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
6098 + core_id = (sb_id_hi & 0xFFF0) >> 4;
6099 + core_rev = (sb_id_hi & 0xF);
6100 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
6102 + /* if present, chipcommon is always core 0; read the chipid from it */
6103 + if (core_id == BCM43xx_COREID_CHIPCOMMON) {
6104 + chip_id_32 = bcm43xx_read32(bcm, 0);
6105 + chip_id_16 = chip_id_32 & 0xFFFF;
6106 + bcm->core_chipcommon.available = 1;
6107 + bcm->core_chipcommon.id = core_id;
6108 + bcm->core_chipcommon.rev = core_rev;
6109 + bcm->core_chipcommon.index = 0;
6110 + /* While we are at it, also read the capabilities. */
6111 + bcm->chipcommon_capabilities = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_CAPABILITIES);
6113 + /* without a chipCommon, use a hard coded table. */
6114 + pci_device = bcm->pci_dev->device;
6115 + if (pci_device == 0x4301)
6116 + chip_id_16 = 0x4301;
6117 + else if ((pci_device >= 0x4305) && (pci_device <= 0x4307))
6118 + chip_id_16 = 0x4307;
6119 + else if ((pci_device >= 0x4402) && (pci_device <= 0x4403))
6120 + chip_id_16 = 0x4402;
6121 + else if ((pci_device >= 0x4610) && (pci_device <= 0x4615))
6122 + chip_id_16 = 0x4610;
6123 + else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
6124 + chip_id_16 = 0x4710;
6125 +#ifdef CONFIG_BCM947XX
6126 + else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
6127 + chip_id_16 = 0x4309;
6130 + printk(KERN_ERR PFX "Could not determine Chip ID\n");
6135 + /* ChipCommon with Core Rev >=4 encodes number of cores,
6136 + * otherwise consult hardcoded table */
6137 + if ((core_id == BCM43xx_COREID_CHIPCOMMON) && (core_rev >= 4)) {
6138 + core_count = (chip_id_32 & 0x0F000000) >> 24;
6140 + switch (chip_id_16) {
6163 + /* SOL if we get here */
6169 + bcm->chip_id = chip_id_16;
6170 + bcm->chip_rev = (chip_id_32 & 0x000F0000) >> 16;
6171 + bcm->chip_package = (chip_id_32 & 0x00F00000) >> 20;
6173 + dprintk(KERN_INFO PFX "Chip ID 0x%x, rev 0x%x\n",
6174 + bcm->chip_id, bcm->chip_rev);
6175 + dprintk(KERN_INFO PFX "Number of cores: %d\n", core_count);
6176 + if (bcm->core_chipcommon.available) {
6177 + dprintk(KERN_INFO PFX "Core 0: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
6178 + core_id, core_rev, core_vendor,
6179 + bcm43xx_core_enabled(bcm) ? "enabled" : "disabled");
6182 + if (bcm->core_chipcommon.available)
6186 + for ( ; current_core < core_count; current_core++) {
6187 + struct bcm43xx_coreinfo *core;
6188 + struct bcm43xx_coreinfo_80211 *ext_80211;
6190 + err = _switch_core(bcm, current_core);
6193 + /* Gather information */
6194 + /* fetch sb_id_hi from core information registers */
6195 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
6197 + /* extract core_id, core_rev, core_vendor */
6198 + core_id = (sb_id_hi & 0xFFF0) >> 4;
6199 + core_rev = (sb_id_hi & 0xF);
6200 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
6202 + dprintk(KERN_INFO PFX "Core %d: ID 0x%x, rev 0x%x, vendor 0x%x, %s\n",
6203 + current_core, core_id, core_rev, core_vendor,
6204 + bcm43xx_core_enabled(bcm) ? "enabled" : "disabled" );
6207 + switch (core_id) {
6208 + case BCM43xx_COREID_PCI:
6209 + core = &bcm->core_pci;
6210 + if (core->available) {
6211 + printk(KERN_WARNING PFX "Multiple PCI cores found.\n");
6215 + case BCM43xx_COREID_80211:
6216 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
6217 + core = &(bcm->core_80211[i]);
6218 + ext_80211 = &(bcm->core_80211_ext[i]);
6219 + if (!core->available)
6224 + printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
6225 + BCM43xx_MAX_80211_CORES);
6229 + /* More than one 80211 core is only supported
6230 + * by special chips.
6231 + * There are chips with two 80211 cores, but with
6232 + * dangling pins on the second core. Be careful
6233 + * and ignore these cores here.
6235 + if (bcm->pci_dev->device != 0x4324) {
6236 + dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
6240 + switch (core_rev) {
6249 + printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
6254 + bcm->nr_80211_available++;
6255 + bcm43xx_init_struct_phyinfo(&ext_80211->phy);
6256 + bcm43xx_init_struct_radioinfo(&ext_80211->radio);
6258 + case BCM43xx_COREID_CHIPCOMMON:
6259 + printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
6263 + core->available = 1;
6264 + core->id = core_id;
6265 + core->rev = core_rev;
6266 + core->index = current_core;
6270 + if (!bcm->core_80211[0].available) {
6271 + printk(KERN_ERR PFX "Error: No 80211 core found!\n");
6276 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
6283 +static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
6285 + const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
6286 + u8 *bssid = bcm->bssid;
6288 + switch (bcm->iw_mode) {
6289 + case IW_MODE_ADHOC:
6290 + random_ether_addr(bssid);
6292 + case IW_MODE_MASTER:
6293 + case IW_MODE_INFRA:
6294 + case IW_MODE_REPEAT:
6295 + case IW_MODE_SECOND:
6296 + case IW_MODE_MONITOR:
6297 + memcpy(bssid, mac, ETH_ALEN);
6304 +static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
6312 + offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
6315 + offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
6317 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
6318 + bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
6321 +static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
6323 + switch (bcm43xx_current_phy(bcm)->type) {
6324 + case BCM43xx_PHYTYPE_A:
6325 + case BCM43xx_PHYTYPE_G:
6326 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_6MB, 1);
6327 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_12MB, 1);
6328 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_18MB, 1);
6329 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_24MB, 1);
6330 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_36MB, 1);
6331 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_48MB, 1);
6332 + bcm43xx_rate_memory_write(bcm, BCM43xx_OFDM_RATE_54MB, 1);
6333 + case BCM43xx_PHYTYPE_B:
6334 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_1MB, 0);
6335 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_2MB, 0);
6336 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_5MB, 0);
6337 + bcm43xx_rate_memory_write(bcm, BCM43xx_CCK_RATE_11MB, 0);
6344 +static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
6346 + bcm43xx_chip_cleanup(bcm);
6347 + bcm43xx_pio_free(bcm);
6348 + bcm43xx_dma_free(bcm);
6350 + bcm->current_core->initialized = 0;
6353 +/* http://bcm-specs.sipsolutions.net/80211Init */
6354 +static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
6356 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6357 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6360 + u32 sbimconfiglow;
6363 + if (bcm->chip_rev < 5) {
6364 + sbimconfiglow = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
6365 + sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
6366 + sbimconfiglow &= ~ BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
6367 + if (bcm->bustype == BCM43xx_BUSTYPE_PCI)
6368 + sbimconfiglow |= 0x32;
6369 + else if (bcm->bustype == BCM43xx_BUSTYPE_SB)
6370 + sbimconfiglow |= 0x53;
6373 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
6376 + bcm43xx_phy_calibrate(bcm);
6377 + err = bcm43xx_chip_init(bcm);
6381 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0016, bcm->current_core->rev);
6382 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, BCM43xx_UCODEFLAGS_OFFSET);
6384 + if (0 /*FIXME: which condition has to be used here? */)
6385 + ucodeflags |= 0x00000010;
6387 + /* HW decryption needs to be set now. */
6388 + ucodeflags |= 0x40000000;
6390 + if (phy->type == BCM43xx_PHYTYPE_G) {
6391 + ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
6392 + if (phy->rev == 1)
6393 + ucodeflags |= BCM43xx_UCODEFLAG_UNKGPHY;
6394 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
6395 + ucodeflags |= BCM43xx_UCODEFLAG_UNKPACTRL;
6396 + } else if (phy->type == BCM43xx_PHYTYPE_B) {
6397 + ucodeflags |= BCM43xx_UCODEFLAG_UNKBGPHY;
6398 + if (phy->rev >= 2 && radio->version == 0x2050)
6399 + ucodeflags &= ~BCM43xx_UCODEFLAG_UNKGPHY;
6402 + if (ucodeflags != bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
6403 + BCM43xx_UCODEFLAGS_OFFSET)) {
6404 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
6405 + BCM43xx_UCODEFLAGS_OFFSET, ucodeflags);
6408 + /* Short/Long Retry Limit.
6409 + * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
6410 + * the chip-internal counter.
6412 + limit = limit_value(modparam_short_retry, 0, 0xF);
6413 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0006, limit);
6414 + limit = limit_value(modparam_long_retry, 0, 0xF);
6415 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0007, limit);
6417 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
6418 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
6420 + bcm43xx_rate_memory_init(bcm);
6422 + /* Minimum Contention Window */
6423 + if (phy->type == BCM43xx_PHYTYPE_B)
6424 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
6426 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
6427 + /* Maximum Contention Window */
6428 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
6430 + bcm43xx_gen_bssid(bcm);
6431 + bcm43xx_write_mac_bssid_templates(bcm);
6433 + if (bcm->current_core->rev >= 5)
6434 + bcm43xx_write16(bcm, 0x043C, 0x000C);
6436 + if (bcm43xx_using_pio(bcm))
6437 + err = bcm43xx_pio_init(bcm);
6439 + err = bcm43xx_dma_init(bcm);
6441 + goto err_chip_cleanup;
6442 + bcm43xx_write16(bcm, 0x0612, 0x0050);
6443 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0416, 0x0050);
6444 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0414, 0x01F4);
6446 + bcm43xx_mac_enable(bcm);
6447 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
6449 + bcm->current_core->initialized = 1;
6454 + bcm43xx_chip_cleanup(bcm);
6458 +static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
6463 + err = bcm43xx_pctl_set_crystal(bcm, 1);
6466 + bcm43xx_pci_read_config16(bcm, PCI_STATUS, &pci_status);
6467 + bcm43xx_pci_write_config16(bcm, PCI_STATUS, pci_status & ~PCI_STATUS_SIG_TARGET_ABORT);
6473 +static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
6475 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
6476 + bcm43xx_pctl_set_crystal(bcm, 0);
6479 +static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
6483 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
6484 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
6487 +static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
6490 + struct bcm43xx_coreinfo *old_core;
6492 + old_core = bcm->current_core;
6493 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6497 + bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
6499 + bcm43xx_switch_core(bcm, old_core);
6505 +/* Make an I/O Core usable. "core_mask" is the bitmask of the cores to enable.
6506 + * To enable core 0, pass a core_mask of 1<<0
6508 +static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
6511 + u32 backplane_flag_nr;
6513 + struct bcm43xx_coreinfo *old_core;
6516 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
6517 + backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
6519 + old_core = bcm->current_core;
6520 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6524 + if (bcm->core_pci.rev < 6) {
6525 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBINTVEC);
6526 + value |= (1 << backplane_flag_nr);
6527 + bcm43xx_write32(bcm, BCM43xx_CIR_SBINTVEC, value);
6529 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
6531 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6532 + goto out_switch_back;
6534 + value |= core_mask << 8;
6535 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
6537 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6538 + goto out_switch_back;
6542 + value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
6543 + value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
6544 + bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
6546 + if (bcm->core_pci.rev < 5) {
6547 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBIMCONFIGLOW);
6548 + value |= (2 << BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_SHIFT)
6549 + & BCM43xx_SBIMCONFIGLOW_SERVICE_TOUT_MASK;
6550 + value |= (3 << BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_SHIFT)
6551 + & BCM43xx_SBIMCONFIGLOW_REQUEST_TOUT_MASK;
6552 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, value);
6553 + err = bcm43xx_pcicore_commit_settings(bcm);
6558 + err = bcm43xx_switch_core(bcm, old_core);
6563 +static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
6565 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6567 + if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
6570 + bcm43xx_mac_suspend(bcm);
6571 + bcm43xx_phy_lo_g_measure(bcm);
6572 + bcm43xx_mac_enable(bcm);
6575 +static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
6577 + bcm43xx_phy_lo_mark_all_unused(bcm);
6578 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
6579 + bcm43xx_mac_suspend(bcm);
6580 + bcm43xx_calc_nrssi_slope(bcm);
6581 + bcm43xx_mac_enable(bcm);
6585 +static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
6587 + /* Update device statistics. */
6588 + bcm43xx_calculate_link_quality(bcm);
6591 +static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
6593 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6594 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6596 + if (phy->type == BCM43xx_PHYTYPE_G) {
6597 + //TODO: update_aci_moving_average
6598 + if (radio->aci_enable && radio->aci_wlan_automatic) {
6599 + bcm43xx_mac_suspend(bcm);
6600 + if (!radio->aci_enable && 1 /*TODO: not scanning? */) {
6601 + if (0 /*TODO: bunch of conditions*/) {
6602 + bcm43xx_radio_set_interference_mitigation(bcm,
6603 + BCM43xx_RADIO_INTERFMODE_MANUALWLAN);
6605 + } else if (1/*TODO*/) {
6607 + if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
6608 + bcm43xx_radio_set_interference_mitigation(bcm,
6609 + BCM43xx_RADIO_INTERFMODE_NONE);
6613 + bcm43xx_mac_enable(bcm);
6614 + } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
6616 + //TODO: implement rev1 workaround
6619 + bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
6620 + //TODO for APHY (temperature?)
6623 +static void bcm43xx_periodic_task_handler(unsigned long d)
6625 + struct bcm43xx_private *bcm = (struct bcm43xx_private *)d;
6626 + unsigned long flags;
6627 + unsigned int state;
6629 + bcm43xx_lock_mmio(bcm, flags);
6631 + assert(bcm->initialized);
6632 + state = bcm->periodic_state;
6633 + if (state % 8 == 0)
6634 + bcm43xx_periodic_every120sec(bcm);
6635 + if (state % 4 == 0)
6636 + bcm43xx_periodic_every60sec(bcm);
6637 + if (state % 2 == 0)
6638 + bcm43xx_periodic_every30sec(bcm);
6639 + bcm43xx_periodic_every15sec(bcm);
6640 + bcm->periodic_state = state + 1;
6642 + mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15));
6644 + bcm43xx_unlock_mmio(bcm, flags);
6647 +static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
6649 + del_timer_sync(&bcm->periodic_tasks);
6652 +static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
6654 + struct timer_list *timer = &(bcm->periodic_tasks);
6656 + assert(bcm->initialized);
6657 + setup_timer(timer,
6658 + bcm43xx_periodic_task_handler,
6659 + (unsigned long)bcm);
6660 + timer->expires = jiffies;
6664 +static void bcm43xx_free_modes(struct bcm43xx_private *bcm)
6666 + struct ieee80211_hw *ieee = bcm->ieee;
6669 + for (i = 0; i < ieee->num_modes; i++) {
6670 + kfree(ieee->modes[i].channels);
6671 + kfree(ieee->modes[i].rates);
6673 + kfree(ieee->modes);
6674 + ieee->modes = NULL;
6675 + ieee->num_modes = 0;
6678 +static int bcm43xx_append_mode(struct ieee80211_hw *ieee,
6681 + const struct ieee80211_channel *channels,
6683 + const struct ieee80211_rate *rates)
6685 + struct ieee80211_hw_modes *mode;
6686 + int err = -ENOMEM;
6688 + mode = &(ieee->modes[ieee->num_modes]);
6690 + mode->mode = mode_id;
6691 + mode->num_channels = nr_channels;
6692 + mode->channels = kzalloc(sizeof(*channels) * nr_channels, GFP_KERNEL);
6693 + if (!mode->channels)
6695 + memcpy(mode->channels, channels, sizeof(*channels) * nr_channels);
6697 + mode->num_rates = nr_rates;
6698 + mode->rates = kzalloc(sizeof(*rates) * nr_rates, GFP_KERNEL);
6700 + goto err_free_channels;
6701 + memcpy(mode->rates, rates, sizeof(*rates) * nr_rates);
6703 + ieee->num_modes++;
6709 + kfree(mode->channels);
6713 +static int bcm43xx_setup_modes_aphy(struct bcm43xx_private *bcm)
6717 + static const struct ieee80211_rate rates[] = {
6720 + .val = BCM43xx_OFDM_RATE_6MB,
6721 + .flags = IEEE80211_RATE_OFDM,
6722 + .val2 = BCM43xx_OFDM_RATE_6MB,
6725 + .val = BCM43xx_OFDM_RATE_9MB,
6726 + .flags = IEEE80211_RATE_OFDM,
6727 + .val2 = BCM43xx_OFDM_RATE_9MB,
6730 + .val = BCM43xx_OFDM_RATE_12MB,
6731 + .flags = IEEE80211_RATE_OFDM,
6732 + .val2 = BCM43xx_OFDM_RATE_12MB,
6735 + .val = BCM43xx_OFDM_RATE_18MB,
6736 + .flags = IEEE80211_RATE_OFDM,
6737 + .val2 = BCM43xx_OFDM_RATE_18MB,
6740 + .val = BCM43xx_OFDM_RATE_24MB,
6741 + .flags = IEEE80211_RATE_OFDM,
6742 + .val2 = BCM43xx_OFDM_RATE_24MB,
6745 + .val = BCM43xx_OFDM_RATE_36MB,
6746 + .flags = IEEE80211_RATE_OFDM,
6747 + .val2 = BCM43xx_OFDM_RATE_36MB,
6750 + .val = BCM43xx_OFDM_RATE_48MB,
6751 + .flags = IEEE80211_RATE_OFDM,
6752 + .val2 = BCM43xx_OFDM_RATE_48MB,
6755 + .val = BCM43xx_OFDM_RATE_54MB,
6756 + .flags = IEEE80211_RATE_OFDM,
6757 + .val2 = BCM43xx_OFDM_RATE_54MB,
6760 + static const struct ieee80211_channel channels[] = {
6765 + .flag = IEEE80211_CHAN_W_SCAN |
6766 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6767 + IEEE80211_CHAN_W_IBSS,
6768 + .power_level = 0xFF,
6769 + .antenna_max = 0xFF,
6774 + .flag = IEEE80211_CHAN_W_SCAN |
6775 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6776 + IEEE80211_CHAN_W_IBSS,
6777 + .power_level = 0xFF,
6778 + .antenna_max = 0xFF,
6783 + .flag = IEEE80211_CHAN_W_SCAN |
6784 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6785 + IEEE80211_CHAN_W_IBSS,
6786 + .power_level = 0xFF,
6787 + .antenna_max = 0xFF,
6792 + .flag = IEEE80211_CHAN_W_SCAN |
6793 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6794 + IEEE80211_CHAN_W_IBSS,
6795 + .power_level = 0xFF,
6796 + .antenna_max = 0xFF,
6801 + .flag = IEEE80211_CHAN_W_SCAN |
6802 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6803 + IEEE80211_CHAN_W_IBSS,
6804 + .power_level = 0xFF,
6805 + .antenna_max = 0xFF,
6810 + .flag = IEEE80211_CHAN_W_SCAN |
6811 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6812 + IEEE80211_CHAN_W_IBSS,
6813 + .power_level = 0xFF,
6814 + .antenna_max = 0xFF,
6819 + .flag = IEEE80211_CHAN_W_SCAN |
6820 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6821 + IEEE80211_CHAN_W_IBSS,
6822 + .power_level = 0xFF,
6823 + .antenna_max = 0xFF,
6828 + .flag = IEEE80211_CHAN_W_SCAN |
6829 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6830 + IEEE80211_CHAN_W_IBSS,
6831 + .power_level = 0xFF,
6832 + .antenna_max = 0xFF,
6837 + .flag = IEEE80211_CHAN_W_SCAN |
6838 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6839 + IEEE80211_CHAN_W_IBSS,
6840 + .power_level = 0xFF,
6841 + .antenna_max = 0xFF,
6846 + .flag = IEEE80211_CHAN_W_SCAN |
6847 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6848 + IEEE80211_CHAN_W_IBSS,
6849 + .power_level = 0xFF,
6850 + .antenna_max = 0xFF,
6855 + .flag = IEEE80211_CHAN_W_SCAN |
6856 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6857 + IEEE80211_CHAN_W_IBSS,
6858 + .power_level = 0xFF,
6859 + .antenna_max = 0xFF,
6864 + .flag = IEEE80211_CHAN_W_SCAN |
6865 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6866 + IEEE80211_CHAN_W_IBSS,
6867 + .power_level = 0xFF,
6868 + .antenna_max = 0xFF,
6873 + .flag = IEEE80211_CHAN_W_SCAN |
6874 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6875 + IEEE80211_CHAN_W_IBSS,
6876 + .power_level = 0xFF,
6877 + .antenna_max = 0xFF,
6881 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
6882 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211A,
6883 + ARRAY_SIZE(channels), channels,
6884 + ARRAY_SIZE(rates), rates);
6890 +static int bcm43xx_setup_modes_bphy(struct bcm43xx_private *bcm)
6894 + static const struct ieee80211_rate rates[] = {
6897 + .val = BCM43xx_CCK_RATE_1MB,
6898 + .flags = IEEE80211_RATE_CCK,
6899 + .val2 = BCM43xx_CCK_RATE_1MB,
6902 + .val = BCM43xx_CCK_RATE_2MB,
6903 + .flags = IEEE80211_RATE_CCK_2,
6904 + .val2 = BCM43xx_CCK_RATE_2MB,
6907 + .val = BCM43xx_CCK_RATE_5MB,
6908 + .flags = IEEE80211_RATE_CCK_2,
6909 + .val2 = BCM43xx_CCK_RATE_5MB,
6912 + .val = BCM43xx_CCK_RATE_11MB,
6913 + .flags = IEEE80211_RATE_CCK_2,
6914 + .val2 = BCM43xx_CCK_RATE_11MB,
6917 + static const struct ieee80211_channel channels[] = {
6922 + .flag = IEEE80211_CHAN_W_SCAN |
6923 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6924 + IEEE80211_CHAN_W_IBSS,
6925 + .power_level = 0xFF,
6926 + .antenna_max = 0xFF,
6931 + .flag = IEEE80211_CHAN_W_SCAN |
6932 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6933 + IEEE80211_CHAN_W_IBSS,
6934 + .power_level = 0xFF,
6935 + .antenna_max = 0xFF,
6940 + .flag = IEEE80211_CHAN_W_SCAN |
6941 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6942 + IEEE80211_CHAN_W_IBSS,
6943 + .power_level = 0xFF,
6944 + .antenna_max = 0xFF,
6949 + .flag = IEEE80211_CHAN_W_SCAN |
6950 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6951 + IEEE80211_CHAN_W_IBSS,
6952 + .power_level = 0xFF,
6953 + .antenna_max = 0xFF,
6958 + .flag = IEEE80211_CHAN_W_SCAN |
6959 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6960 + IEEE80211_CHAN_W_IBSS,
6961 + .power_level = 0xFF,
6962 + .antenna_max = 0xFF,
6967 + .flag = IEEE80211_CHAN_W_SCAN |
6968 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6969 + IEEE80211_CHAN_W_IBSS,
6970 + .power_level = 0xFF,
6971 + .antenna_max = 0xFF,
6976 + .flag = IEEE80211_CHAN_W_SCAN |
6977 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6978 + IEEE80211_CHAN_W_IBSS,
6979 + .power_level = 0xFF,
6980 + .antenna_max = 0xFF,
6985 + .flag = IEEE80211_CHAN_W_SCAN |
6986 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6987 + IEEE80211_CHAN_W_IBSS,
6988 + .power_level = 0xFF,
6989 + .antenna_max = 0xFF,
6994 + .flag = IEEE80211_CHAN_W_SCAN |
6995 + IEEE80211_CHAN_W_ACTIVE_SCAN |
6996 + IEEE80211_CHAN_W_IBSS,
6997 + .power_level = 0xFF,
6998 + .antenna_max = 0xFF,
7003 + .flag = IEEE80211_CHAN_W_SCAN |
7004 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7005 + IEEE80211_CHAN_W_IBSS,
7006 + .power_level = 0xFF,
7007 + .antenna_max = 0xFF,
7012 + .flag = IEEE80211_CHAN_W_SCAN |
7013 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7014 + IEEE80211_CHAN_W_IBSS,
7015 + .power_level = 0xFF,
7016 + .antenna_max = 0xFF,
7021 + .flag = IEEE80211_CHAN_W_SCAN |
7022 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7023 + IEEE80211_CHAN_W_IBSS,
7024 + .power_level = 0xFF,
7025 + .antenna_max = 0xFF,
7030 + .flag = IEEE80211_CHAN_W_SCAN |
7031 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7032 + IEEE80211_CHAN_W_IBSS,
7033 + .power_level = 0xFF,
7034 + .antenna_max = 0xFF,
7039 + .flag = IEEE80211_CHAN_W_SCAN |
7040 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7041 + IEEE80211_CHAN_W_IBSS,
7042 + .power_level = 0xFF,
7043 + .antenna_max = 0xFF,
7047 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_B ||
7048 + bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
7049 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211B,
7050 + ARRAY_SIZE(channels), channels,
7051 + ARRAY_SIZE(rates), rates);
7057 +static int bcm43xx_setup_modes_gphy(struct bcm43xx_private *bcm)
7061 + static const struct ieee80211_rate rates[] = {
7064 + .val = BCM43xx_CCK_RATE_1MB,
7065 + .flags = IEEE80211_RATE_CCK,
7066 + .val2 = BCM43xx_CCK_RATE_1MB,
7069 + .val = BCM43xx_CCK_RATE_2MB,
7070 + .flags = IEEE80211_RATE_CCK_2,
7071 + .val2 = BCM43xx_CCK_RATE_2MB,
7074 + .val = BCM43xx_CCK_RATE_5MB,
7075 + .flags = IEEE80211_RATE_CCK_2,
7076 + .val2 = BCM43xx_CCK_RATE_5MB,
7079 + .val = BCM43xx_OFDM_RATE_6MB,
7080 + .flags = IEEE80211_RATE_OFDM,
7081 + .val2 = BCM43xx_OFDM_RATE_6MB,
7084 + .val = BCM43xx_OFDM_RATE_9MB,
7085 + .flags = IEEE80211_RATE_OFDM,
7086 + .val2 = BCM43xx_OFDM_RATE_9MB,
7089 + .val = BCM43xx_CCK_RATE_11MB,
7090 + .flags = IEEE80211_RATE_CCK_2,
7091 + .val2 = BCM43xx_CCK_RATE_11MB,
7094 + .val = BCM43xx_OFDM_RATE_12MB,
7095 + .flags = IEEE80211_RATE_OFDM,
7096 + .val2 = BCM43xx_OFDM_RATE_12MB,
7099 + .val = BCM43xx_OFDM_RATE_18MB,
7100 + .flags = IEEE80211_RATE_OFDM,
7101 + .val2 = BCM43xx_OFDM_RATE_18MB,
7104 + .val = BCM43xx_OFDM_RATE_24MB,
7105 + .flags = IEEE80211_RATE_OFDM,
7106 + .val2 = BCM43xx_OFDM_RATE_24MB,
7109 + .val = BCM43xx_OFDM_RATE_36MB,
7110 + .flags = IEEE80211_RATE_OFDM,
7111 + .val2 = BCM43xx_OFDM_RATE_36MB,
7114 + .val = BCM43xx_OFDM_RATE_48MB,
7115 + .flags = IEEE80211_RATE_OFDM,
7116 + .val2 = BCM43xx_OFDM_RATE_48MB,
7119 + .val = BCM43xx_OFDM_RATE_54MB,
7120 + .flags = IEEE80211_RATE_OFDM,
7121 + .val2 = BCM43xx_OFDM_RATE_54MB,
7124 + static const struct ieee80211_channel channels[] = {
7129 + .flag = IEEE80211_CHAN_W_SCAN |
7130 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7131 + IEEE80211_CHAN_W_IBSS,
7132 + .power_level = 0xFF,
7133 + .antenna_max = 0xFF,
7138 + .flag = IEEE80211_CHAN_W_SCAN |
7139 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7140 + IEEE80211_CHAN_W_IBSS,
7141 + .power_level = 0xFF,
7142 + .antenna_max = 0xFF,
7147 + .flag = IEEE80211_CHAN_W_SCAN |
7148 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7149 + IEEE80211_CHAN_W_IBSS,
7150 + .power_level = 0xFF,
7151 + .antenna_max = 0xFF,
7156 + .flag = IEEE80211_CHAN_W_SCAN |
7157 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7158 + IEEE80211_CHAN_W_IBSS,
7159 + .power_level = 0xFF,
7160 + .antenna_max = 0xFF,
7165 + .flag = IEEE80211_CHAN_W_SCAN |
7166 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7167 + IEEE80211_CHAN_W_IBSS,
7168 + .power_level = 0xFF,
7169 + .antenna_max = 0xFF,
7174 + .flag = IEEE80211_CHAN_W_SCAN |
7175 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7176 + IEEE80211_CHAN_W_IBSS,
7177 + .power_level = 0xFF,
7178 + .antenna_max = 0xFF,
7183 + .flag = IEEE80211_CHAN_W_SCAN |
7184 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7185 + IEEE80211_CHAN_W_IBSS,
7186 + .power_level = 0xFF,
7187 + .antenna_max = 0xFF,
7192 + .flag = IEEE80211_CHAN_W_SCAN |
7193 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7194 + IEEE80211_CHAN_W_IBSS,
7195 + .power_level = 0xFF,
7196 + .antenna_max = 0xFF,
7201 + .flag = IEEE80211_CHAN_W_SCAN |
7202 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7203 + IEEE80211_CHAN_W_IBSS,
7204 + .power_level = 0xFF,
7205 + .antenna_max = 0xFF,
7210 + .flag = IEEE80211_CHAN_W_SCAN |
7211 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7212 + IEEE80211_CHAN_W_IBSS,
7213 + .power_level = 0xFF,
7214 + .antenna_max = 0xFF,
7219 + .flag = IEEE80211_CHAN_W_SCAN |
7220 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7221 + IEEE80211_CHAN_W_IBSS,
7222 + .power_level = 0xFF,
7223 + .antenna_max = 0xFF,
7228 + .flag = IEEE80211_CHAN_W_SCAN |
7229 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7230 + IEEE80211_CHAN_W_IBSS,
7231 + .power_level = 0xFF,
7232 + .antenna_max = 0xFF,
7237 + .flag = IEEE80211_CHAN_W_SCAN |
7238 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7239 + IEEE80211_CHAN_W_IBSS,
7240 + .power_level = 0xFF,
7241 + .antenna_max = 0xFF,
7246 + .flag = IEEE80211_CHAN_W_SCAN |
7247 + IEEE80211_CHAN_W_ACTIVE_SCAN |
7248 + IEEE80211_CHAN_W_IBSS,
7249 + .power_level = 0xFF,
7250 + .antenna_max = 0xFF,
7254 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_G) {
7255 + err = bcm43xx_append_mode(bcm->ieee, MODE_IEEE80211G,
7256 + ARRAY_SIZE(channels), channels,
7257 + ARRAY_SIZE(rates), rates);
7263 +static int bcm43xx_setup_modes(struct bcm43xx_private *bcm)
7265 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7266 + int err = -ENOMEM;
7268 + struct ieee80211_hw *ieee = bcm->ieee;
7270 + if (phy->type == BCM43xx_PHYTYPE_A)
7272 + else if (phy->type == BCM43xx_PHYTYPE_B)
7276 + ieee->modes = kzalloc(sizeof(*(ieee->modes)) * nr, GFP_KERNEL);
7279 + ieee->num_modes = 0;
7281 + err = bcm43xx_setup_modes_aphy(bcm);
7284 + err = bcm43xx_setup_modes_gphy(bcm);
7287 + err = bcm43xx_setup_modes_bphy(bcm);
7291 + assert(ieee->num_modes == nr && nr > 0);
7296 + bcm43xx_free_modes(bcm);
7300 +static void bcm43xx_security_init(struct bcm43xx_private *bcm)
7302 + bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
7304 + bcm43xx_clear_keys(bcm);
7307 +/* This is the opposite of bcm43xx_init_board() */
7308 +static void bcm43xx_free_board(struct bcm43xx_private *bcm)
7311 + unsigned long flags;
7313 + bcm43xx_sysfs_unregister(bcm);
7315 + bcm43xx_periodic_tasks_delete(bcm);
7317 + bcm43xx_lock(bcm, flags);
7318 + bcm->initialized = 0;
7319 + bcm->shutting_down = 1;
7320 + bcm43xx_unlock(bcm, flags);
7322 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7323 + if (!bcm->core_80211[i].available)
7325 + if (!bcm->core_80211[i].initialized)
7328 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7330 + bcm43xx_wireless_core_cleanup(bcm);
7333 + bcm43xx_pctl_set_crystal(bcm, 0);
7334 + bcm43xx_free_modes(bcm);
7336 + bcm43xx_lock(bcm, flags);
7337 + bcm->shutting_down = 0;
7338 + bcm43xx_unlock(bcm, flags);
7341 +static int bcm43xx_init_board(struct bcm43xx_private *bcm)
7345 + unsigned long flags;
7349 + bcm43xx_lock(bcm, flags);
7350 + bcm->initialized = 0;
7351 + bcm->shutting_down = 0;
7352 + bcm43xx_unlock(bcm, flags);
7354 + err = bcm43xx_pctl_set_crystal(bcm, 1);
7357 + err = bcm43xx_pctl_init(bcm);
7359 + goto err_crystal_off;
7360 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
7362 + goto err_crystal_off;
7364 + tasklet_enable(&bcm->isr_tasklet);
7365 + for (i = 0; i < bcm->nr_80211_available; i++) {
7366 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7367 + assert(err != -ENODEV);
7369 + goto err_80211_unwind;
7371 + /* Enable the selected wireless core.
7372 + * Connect PHY only on the first core.
7374 + if (!bcm43xx_core_enabled(bcm)) {
7375 + if (bcm->nr_80211_available == 1) {
7376 + connect_phy = bcm43xx_current_phy(bcm)->connected;
7383 + bcm43xx_wireless_core_reset(bcm, connect_phy);
7387 + bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
7389 + err = bcm43xx_wireless_core_init(bcm);
7391 + goto err_80211_unwind;
7394 + bcm43xx_mac_suspend(bcm);
7395 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7396 + bcm43xx_radio_turn_off(bcm);
7399 + bcm->active_80211_core = &bcm->core_80211[0];
7400 + if (bcm->nr_80211_available >= 2) {
7401 + bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
7402 + bcm43xx_mac_enable(bcm);
7404 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
7405 + bcm43xx_macfilter_set(bcm, BCM43xx_MACFILTER_SELF, (u8 *)(bcm->net_dev->dev_addr));
7406 + dprintk(KERN_INFO PFX "80211 cores initialized\n");
7407 + bcm43xx_setup_modes(bcm);
7408 + bcm43xx_security_init(bcm);
7409 + ieee80211_update_hw(bcm->net_dev, bcm->ieee);
7410 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
7411 + ieee80211_netif_oper(bcm->net_dev, NETIF_START);
7412 + ieee80211_netif_oper(bcm->net_dev, NETIF_WAKE);
7414 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
7416 + if (bcm43xx_current_radio(bcm)->initial_channel != 0xFF) {
7417 + bcm43xx_mac_suspend(bcm);
7418 + bcm43xx_radio_selectchannel(bcm, bcm43xx_current_radio(bcm)->initial_channel, 0);
7419 + bcm43xx_mac_enable(bcm);
7422 + /* Initialization of the board is done. Flag it as such. */
7423 + bcm43xx_lock(bcm, flags);
7424 + bcm->initialized = 1;
7425 + bcm43xx_unlock(bcm, flags);
7427 + bcm43xx_periodic_tasks_setup(bcm);
7428 + bcm43xx_sysfs_register(bcm);
7435 + tasklet_disable(&bcm->isr_tasklet);
7436 + /* unwind all 80211 initialization */
7437 + for (i = 0; i < bcm->nr_80211_available; i++) {
7438 + if (!bcm->core_80211[i].initialized)
7440 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7441 + bcm43xx_wireless_core_cleanup(bcm);
7444 + bcm43xx_pctl_set_crystal(bcm, 0);
7448 +static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
7450 + struct pci_dev *pci_dev = bcm->pci_dev;
7453 + bcm43xx_chipset_detach(bcm);
7454 + /* Do _not_ access the chip, after it is detached. */
7455 + iounmap(bcm->mmio_addr);
7457 + pci_release_regions(pci_dev);
7458 + pci_disable_device(pci_dev);
7460 + /* Free allocated structures/fields */
7461 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7462 + kfree(bcm->core_80211_ext[i].phy._lo_pairs);
7463 + if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
7464 + kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
7468 +static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
7470 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7475 + int phy_rev_ok = 1;
7478 + value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
7480 + phy_version = (value & 0xF000) >> 12;
7481 + phy_type = (value & 0x0F00) >> 8;
7482 + phy_rev = (value & 0x000F);
7484 + dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
7485 + phy_version, phy_type, phy_rev);
7487 + switch (phy_type) {
7488 + case BCM43xx_PHYTYPE_A:
7492 + case BCM43xx_PHYTYPE_B:
7493 + if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
7496 + case BCM43xx_PHYTYPE_G:
7501 + printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
7505 + if (!phy_rev_ok) {
7506 + printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
7510 + phy->version = phy_version;
7511 + phy->type = phy_type;
7512 + phy->rev = phy_rev;
7513 + if ((phy_type == BCM43xx_PHYTYPE_B) || (phy_type == BCM43xx_PHYTYPE_G)) {
7514 + p = kzalloc(sizeof(struct bcm43xx_lopair) * BCM43xx_LO_COUNT,
7518 + phy->_lo_pairs = p;
7524 +static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
7526 + struct pci_dev *pci_dev = bcm->pci_dev;
7527 + struct net_device *net_dev = bcm->net_dev;
7530 + unsigned long mmio_start, mmio_flags, mmio_len;
7533 + err = pci_enable_device(pci_dev);
7535 + printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
7538 + mmio_start = pci_resource_start(pci_dev, 0);
7539 + mmio_flags = pci_resource_flags(pci_dev, 0);
7540 + mmio_len = pci_resource_len(pci_dev, 0);
7541 + if (!(mmio_flags & IORESOURCE_MEM)) {
7542 + printk(KERN_ERR PFX
7543 + "%s, region #0 not an MMIO resource, aborting\n",
7544 + pci_name(pci_dev));
7546 + goto err_pci_disable;
7548 + err = pci_request_regions(pci_dev, KBUILD_MODNAME);
7550 + printk(KERN_ERR PFX
7551 + "could not access PCI resources (%i)\n", err);
7552 + goto err_pci_disable;
7554 + /* enable PCI bus-mastering */
7555 + pci_set_master(pci_dev);
7556 + bcm->mmio_addr = ioremap(mmio_start, mmio_len);
7557 + if (!bcm->mmio_addr) {
7558 + printk(KERN_ERR PFX "%s: cannot remap MMIO, aborting\n",
7559 + pci_name(pci_dev));
7561 + goto err_pci_release;
7563 + bcm->mmio_len = mmio_len;
7564 + net_dev->base_addr = (unsigned long)bcm->mmio_addr;
7566 + bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_VENDOR_ID,
7567 + &bcm->board_vendor);
7568 + bcm43xx_pci_read_config16(bcm, PCI_SUBSYSTEM_ID,
7569 + &bcm->board_type);
7570 + bcm43xx_pci_read_config16(bcm, PCI_REVISION_ID,
7571 + &bcm->board_revision);
7573 + err = bcm43xx_chipset_attach(bcm);
7576 + err = bcm43xx_pctl_init(bcm);
7578 + goto err_chipset_detach;
7579 + err = bcm43xx_probe_cores(bcm);
7581 + goto err_chipset_detach;
7583 + /* Attach all IO cores to the backplane. */
7585 + for (i = 0; i < bcm->nr_80211_available; i++)
7586 + coremask |= (1 << bcm->core_80211[i].index);
7587 + //FIXME: Also attach some non80211 cores?
7588 + err = bcm43xx_setup_backplane_pci_connection(bcm, coremask);
7590 + printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
7591 + goto err_chipset_detach;
7594 + err = bcm43xx_sprom_extract(bcm);
7596 + goto err_chipset_detach;
7597 + err = bcm43xx_leds_init(bcm);
7599 + goto err_chipset_detach;
7601 + for (i = 0; i < bcm->nr_80211_available; i++) {
7602 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7603 + assert(err != -ENODEV);
7605 + goto err_80211_unwind;
7607 + /* Enable the selected wireless core.
7608 + * Connect PHY only on the first core.
7610 + bcm43xx_wireless_core_reset(bcm, (i == 0));
7612 + err = bcm43xx_read_phyinfo(bcm);
7613 + if (err && (i == 0))
7614 + goto err_80211_unwind;
7616 + err = bcm43xx_read_radioinfo(bcm);
7617 + if (err && (i == 0))
7618 + goto err_80211_unwind;
7620 + err = bcm43xx_validate_chip(bcm);
7621 + if (err && (i == 0))
7622 + goto err_80211_unwind;
7624 + bcm43xx_radio_turn_off(bcm);
7625 + err = bcm43xx_phy_init_tssi2dbm_table(bcm);
7627 + goto err_80211_unwind;
7628 + bcm43xx_wireless_core_disable(bcm);
7630 + bcm43xx_pctl_set_crystal(bcm, 0);
7632 + /* Set the MAC address in the networking subsystem */
7633 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
7634 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.et1macaddr, 6);
7636 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
7638 + snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
7639 + "Broadcom %04X", bcm->chip_id);
7646 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7647 + kfree(bcm->core_80211_ext[i].phy._lo_pairs);
7648 + if (bcm->core_80211_ext[i].phy.dyn_tssi_tbl)
7649 + kfree(bcm->core_80211_ext[i].phy.tssi2dbm);
7651 +err_chipset_detach:
7652 + bcm43xx_chipset_detach(bcm);
7654 + iounmap(bcm->mmio_addr);
7656 + pci_release_regions(pci_dev);
7658 + pci_disable_device(pci_dev);
7662 +/* hard_start_xmit() callback in struct ieee80211_device */
7663 +static int bcm43xx_net_hard_start_xmit(struct net_device *net_dev,
7664 + struct sk_buff *skb,
7665 + struct ieee80211_tx_control *ctl)
7667 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7668 + int err = -ENODEV;
7669 + unsigned long flags;
7671 + bcm43xx_lock_mmio(bcm, flags);
7672 + if (likely(bcm->initialized)) {
7673 + if (bcm43xx_using_pio(bcm))
7674 + err = bcm43xx_pio_tx(bcm, skb, ctl);
7676 + err = bcm43xx_dma_tx(bcm, skb, ctl);
7678 + bcm43xx_unlock_mmio(bcm, flags);
7683 +static int bcm43xx_net_reset(struct net_device *net_dev)
7685 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7686 + unsigned long flags;
7688 + bcm43xx_lock_mmio(bcm, flags);
7689 + bcm43xx_controller_restart(bcm, "IEEE reset");
7690 + bcm43xx_unlock_mmio(bcm, flags);
7695 +static int bcm43xx_net_config(struct net_device *net_dev,
7696 + struct ieee80211_conf *conf)
7698 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7699 + struct bcm43xx_radioinfo *radio;
7700 + struct bcm43xx_phyinfo *phy;
7701 + unsigned long flags;
7703 + bcm43xx_lock_mmio(bcm, flags);
7704 + if (!bcm->initialized) {
7705 + bcm43xx_unlock_mmio(bcm, flags);
7708 + radio = bcm43xx_current_radio(bcm);
7709 + phy = bcm43xx_current_phy(bcm);
7711 + if (conf->channel != radio->channel)
7712 + bcm43xx_radio_selectchannel(bcm, conf->channel, 0);
7714 + if (conf->mode != bcm->iw_mode)
7715 + bcm43xx_set_iwmode(bcm, conf->mode);
7717 + if (conf->short_slot_time != bcm->short_slot) {
7718 + assert(phy->type == BCM43xx_PHYTYPE_G);
7719 + if (conf->short_slot_time)
7720 + bcm43xx_short_slot_timing_enable(bcm);
7722 + bcm43xx_short_slot_timing_disable(bcm);
7725 + if (conf->power_level != 0) {
7726 + radio->power_level = conf->power_level;
7727 + bcm43xx_phy_xmitpower(bcm);
7729 +//FIXME: This does not seem to wake up:
7731 + if (conf->power_level == 0) {
7732 + if (radio->enabled)
7733 + bcm43xx_radio_turn_off(bcm);
7735 + if (!radio->enabled)
7736 + bcm43xx_radio_turn_on(bcm);
7743 + bcm43xx_unlock_mmio(bcm, flags);
7748 +static int bcm43xx_net_set_key(struct net_device *net_dev,
7751 + struct ieee80211_key_conf *key,
7754 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7755 + unsigned long flags;
7758 + int err = -EINVAL;
7760 + switch (key->alg) {
7764 + algorithm = BCM43xx_SEC_ALGO_NONE;
7767 + if (key->keylen == 5)
7768 + algorithm = BCM43xx_SEC_ALGO_WEP;
7770 + algorithm = BCM43xx_SEC_ALGO_WEP104;
7773 + algorithm = BCM43xx_SEC_ALGO_TKIP;
7776 + algorithm = BCM43xx_SEC_ALGO_AES;
7780 + index = (u8)(key->keyidx);
7781 + if (index >= ARRAY_SIZE(bcm->key))
7783 + bcm43xx_lock_mmio(bcm, flags);
7786 + err = bcm43xx_key_write(bcm, index, algorithm,
7787 + key->key, key->keylen,
7791 + key->hw_key_idx = index;
7792 + key->force_sw_encrypt = 0;
7793 + if (key->default_tx_key)
7794 + bcm->default_key_idx = index;
7795 + bcm->key[index].enabled = 1;
7798 + bcm->key[index].enabled = 0;
7801 + case REMOVE_ALL_KEYS:
7802 + bcm43xx_clear_keys(bcm);
7805 + case ENABLE_COMPRESSION:
7806 + case DISABLE_COMPRESSION:
7811 + bcm43xx_unlock_mmio(bcm, flags);
7816 +static int bcm43xx_net_conf_tx(struct net_device *net_dev,
7818 + const struct ieee80211_tx_queue_params *params)
7823 +static int bcm43xx_net_get_tx_stats(struct net_device *net_dev,
7824 + struct ieee80211_tx_queue_stats *stats)
7826 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7827 + unsigned long flags;
7829 + bcm43xx_lock(bcm, flags);
7830 + if (bcm43xx_using_pio(bcm))
7831 + bcm43xx_pio_get_tx_stats(bcm, stats);
7833 + bcm43xx_dma_get_tx_stats(bcm, stats);
7834 + bcm43xx_unlock(bcm, flags);
7839 +static int bcm43xx_net_get_stats(struct net_device *net_dev,
7840 + struct ieee80211_low_level_stats *stats)
7842 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7843 + unsigned long flags;
7845 + bcm43xx_lock(bcm, flags);
7846 + memcpy(stats, &bcm->ieee_stats, sizeof(*stats));
7847 + bcm43xx_unlock(bcm, flags);
7852 +#ifdef CONFIG_NET_POLL_CONTROLLER
7853 +static void bcm43xx_net_poll_controller(struct net_device *net_dev)
7855 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7856 + unsigned long flags;
7858 + local_irq_save(flags);
7859 + bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
7860 + local_irq_restore(flags);
7862 +#endif /* CONFIG_NET_POLL_CONTROLLER */
7864 +static int bcm43xx_net_open(struct net_device *net_dev)
7866 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7868 + return bcm43xx_init_board(bcm);
7871 +static int bcm43xx_net_stop(struct net_device *net_dev)
7873 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7875 + if (bcm->initialized) {
7876 + bcm43xx_disable_interrupts_sync(bcm, NULL);
7877 + bcm43xx_free_board(bcm);
7883 +/* Initialization of struct net_device, just after allocation. */
7884 +static void bcm43xx_netdev_setup(struct net_device *net_dev)
7886 +#ifdef CONFIG_NET_POLL_CONTROLLER
7887 + net_dev->poll_controller = bcm43xx_net_poll_controller;
7889 + SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
7892 +static int bcm43xx_init_private(struct bcm43xx_private *bcm,
7893 + struct net_device *net_dev,
7894 + struct pci_dev *pci_dev,
7895 + struct ieee80211_hw *ieee)
7900 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
7901 + bcm->pci_dev = pci_dev;
7902 + bcm->net_dev = net_dev;
7903 + bcm->bad_frames_preempt = modparam_bad_frames_preempt;
7904 + spin_lock_init(&bcm->_lock);
7905 + tasklet_init(&bcm->isr_tasklet,
7906 + (void (*)(unsigned long))bcm43xx_interrupt_tasklet,
7907 + (unsigned long)bcm);
7908 + tasklet_disable_nosync(&bcm->isr_tasklet);
7909 + if (modparam_pio) {
7910 + bcm->__using_pio = 1;
7912 + err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
7913 + err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
7915 +#ifdef CONFIG_BCM43XX_D80211_PIO
7916 + printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
7917 + bcm->__using_pio = 1;
7919 + printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
7920 + "Recompile the driver with PIO support, please.\n");
7922 +#endif /* CONFIG_BCM43XX_D80211_PIO */
7929 +static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
7930 + const struct pci_device_id *ent)
7932 + struct net_device *net_dev;
7933 + struct bcm43xx_private *bcm;
7934 + struct ieee80211_hw *ieee;
7935 + int err = -ENOMEM;
7937 +#ifdef CONFIG_BCM947XX
7938 + if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
7942 +#ifdef DEBUG_SINGLE_DEVICE_ONLY
7943 + if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
7947 + ieee = kzalloc(sizeof(*ieee), GFP_KERNEL);
7950 + ieee->version = IEEE80211_VERSION;
7951 + ieee->name = KBUILD_MODNAME;
7952 + ieee->host_gen_beacon = 1;
7953 + ieee->rx_includes_fcs = 1;
7954 + ieee->tx = bcm43xx_net_hard_start_xmit;
7955 + ieee->open = bcm43xx_net_open;
7956 + ieee->stop = bcm43xx_net_stop;
7957 + ieee->reset = bcm43xx_net_reset;
7958 + ieee->config = bcm43xx_net_config;
7959 +//TODO ieee->set_key = bcm43xx_net_set_key;
7960 + ieee->get_stats = bcm43xx_net_get_stats;
7962 + ieee->get_tx_stats = bcm43xx_net_get_tx_stats;
7963 + ieee->conf_tx = bcm43xx_net_conf_tx;
7964 + ieee->wep_include_iv = 1;
7966 + net_dev = ieee80211_alloc_hw(sizeof(*bcm), bcm43xx_netdev_setup);
7968 + printk(KERN_ERR PFX
7969 + "could not allocate ieee80211 device %s\n",
7971 + goto err_free_ieee;
7973 + /* initialize the bcm43xx_private struct */
7974 + bcm = bcm43xx_priv(net_dev);
7975 + memset(bcm, 0, sizeof(*bcm));
7976 + err = bcm43xx_init_private(bcm, net_dev, pdev, ieee);
7978 + goto err_free_netdev;
7980 + pci_set_drvdata(pdev, net_dev);
7982 + err = bcm43xx_attach_board(bcm);
7984 + goto err_free_netdev;
7985 + err = ieee80211_register_hw(net_dev, ieee);
7987 + goto err_detach_board;
7989 + bcm43xx_debugfs_add_device(bcm);
7996 + bcm43xx_detach_board(bcm);
7998 + ieee80211_free_hw(net_dev);
8004 +static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
8006 + struct net_device *net_dev = pci_get_drvdata(pdev);
8007 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8008 + struct ieee80211_hw *ieee = bcm->ieee;
8010 + bcm43xx_debugfs_remove_device(bcm);
8012 + /* Bring down the device early to stop all TX and RX operation. */
8013 + ieee80211_netif_oper(net_dev, NETIF_DETACH);
8014 + bcm43xx_net_stop(net_dev);
8016 + ieee80211_unregister_hw(net_dev);
8017 + bcm43xx_detach_board(bcm);
8018 + if (bcm->cached_beacon)
8019 + kfree_skb(bcm->cached_beacon);
8020 + bcm->cached_beacon = NULL;
8021 + assert(bcm->ucode == NULL);
8022 + ieee80211_free_hw(net_dev);
8026 +/* Hard-reset the chip. Do not call this directly.
8027 + * Use bcm43xx_controller_restart()
8029 +static void bcm43xx_chip_reset(void *_bcm)
8031 + struct bcm43xx_private *bcm = _bcm;
8032 + struct net_device *net_dev = bcm->net_dev;
8033 + struct pci_dev *pci_dev = bcm->pci_dev;
8034 + struct ieee80211_hw *ieee = bcm->ieee;
8036 + int was_initialized = bcm->initialized;
8038 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
8039 + tasklet_disable(&bcm->isr_tasklet);
8041 + bcm->firmware_norelease = 1;
8042 + if (was_initialized)
8043 + bcm43xx_free_board(bcm);
8044 + bcm->firmware_norelease = 0;
8045 + bcm43xx_detach_board(bcm);
8046 + err = bcm43xx_init_private(bcm, net_dev, pci_dev, ieee);
8049 + err = bcm43xx_attach_board(bcm);
8052 + if (was_initialized) {
8053 + err = bcm43xx_init_board(bcm);
8057 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8058 + printk(KERN_INFO PFX "Controller restarted\n");
8062 + printk(KERN_ERR PFX "Controller restart failed\n");
8065 +/* Hard-reset the chip.
8066 + * This can be called from interrupt or process context.
8067 + * Make sure to _not_ re-enable device interrupts after this has been called.
8069 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
8071 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
8072 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
8073 + printk(KERN_ERR PFX "Controller RESET (%s) ...\n", reason);
8074 + INIT_WORK(&bcm->restart_work, bcm43xx_chip_reset, bcm);
8075 + schedule_work(&bcm->restart_work);
8080 +static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
8082 + struct net_device *net_dev = pci_get_drvdata(pdev);
8083 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8084 + unsigned long flags;
8085 + int try_to_shutdown = 0, err;
8087 + dprintk(KERN_INFO PFX "Suspending...\n");
8089 + bcm43xx_lock(bcm, flags);
8090 + bcm->was_initialized = bcm->initialized;
8091 + if (bcm->initialized)
8092 + try_to_shutdown = 1;
8093 + bcm43xx_unlock(bcm, flags);
8095 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
8096 + if (try_to_shutdown) {
8097 + err = bcm43xx_disable_interrupts_sync(bcm, &bcm->irq_savedstate);
8098 + if (unlikely(err)) {
8099 + dprintk(KERN_ERR PFX "Suspend failed.\n");
8102 + bcm->firmware_norelease = 1;
8103 + bcm43xx_free_board(bcm);
8104 + bcm->firmware_norelease = 0;
8106 + bcm43xx_chipset_detach(bcm);
8108 + pci_save_state(pdev);
8109 + pci_disable_device(pdev);
8110 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
8112 + dprintk(KERN_INFO PFX "Device suspended.\n");
8117 +static int bcm43xx_resume(struct pci_dev *pdev)
8119 + struct net_device *net_dev = pci_get_drvdata(pdev);
8120 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8123 + dprintk(KERN_INFO PFX "Resuming...\n");
8125 + pci_set_power_state(pdev, 0);
8126 + pci_enable_device(pdev);
8127 + pci_restore_state(pdev);
8129 + bcm43xx_chipset_attach(bcm);
8130 + if (bcm->was_initialized) {
8131 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
8132 + err = bcm43xx_init_board(bcm);
8135 + printk(KERN_ERR PFX "Resume failed!\n");
8139 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8141 + dprintk(KERN_INFO PFX "Device resumed.\n");
8146 +#endif /* CONFIG_PM */
8148 +static struct pci_driver bcm43xx_pci_driver = {
8149 + .name = KBUILD_MODNAME,
8150 + .id_table = bcm43xx_pci_tbl,
8151 + .probe = bcm43xx_init_one,
8152 + .remove = __devexit_p(bcm43xx_remove_one),
8154 + .suspend = bcm43xx_suspend,
8155 + .resume = bcm43xx_resume,
8156 +#endif /* CONFIG_PM */
8159 +static int __init bcm43xx_init(void)
8161 + printk(KERN_INFO KBUILD_MODNAME " driver\n");
8162 + bcm43xx_debugfs_init();
8163 + return pci_register_driver(&bcm43xx_pci_driver);
8166 +static void __exit bcm43xx_exit(void)
8168 + pci_unregister_driver(&bcm43xx_pci_driver);
8169 + bcm43xx_debugfs_exit();
8172 +module_init(bcm43xx_init)
8173 +module_exit(bcm43xx_exit)
8174 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
8175 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h 1970-01-01 01:00:00.000000000 +0100
8176 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_main.h 2006-03-28 22:16:14.000000000 +0200
8180 + Broadcom BCM43xx wireless driver
8182 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
8183 + Stefano Brivio <st3@riseup.net>
8184 + Michael Buesch <mbuesch@freenet.de>
8185 + Danny van Dyk <kugelfang@gentoo.org>
8186 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
8188 + Some parts of the code in this file are derived from the ipw2200
8189 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8191 + This program is free software; you can redistribute it and/or modify
8192 + it under the terms of the GNU General Public License as published by
8193 + the Free Software Foundation; either version 2 of the License, or
8194 + (at your option) any later version.
8196 + This program is distributed in the hope that it will be useful,
8197 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8198 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8199 + GNU General Public License for more details.
8201 + You should have received a copy of the GNU General Public License
8202 + along with this program; see the file COPYING. If not, write to
8203 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
8204 + Boston, MA 02110-1301, USA.
8208 +#ifndef BCM43xx_MAIN_H_
8209 +#define BCM43xx_MAIN_H_
8211 +#include "bcm43xx.h"
8213 +#ifdef CONFIG_BCM947XX
8214 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
8216 +static inline void e_aton(char *str, char *dest)
8219 + u16 *d = (u16 *) dest;
8222 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
8224 + if (!*str++ || i == 6)
8227 + for (i = 0; i < 3; i++)
8228 + d[i] = cpu_to_be16(d[i]);
8232 +#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
8233 +#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
8234 +/* Magic helper macro to pad structures. Ignore those above. It's magic. */
8235 +#define PAD_BYTES(nr_bytes) P4D_BYTES( __LINE__ , (nr_bytes))
8238 +/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
8240 +u8 bcm43xx_freq_to_channel_a(int freq)
8242 + return ((freq - 5000) / 5);
8245 +u8 bcm43xx_freq_to_channel_bg(int freq)
8252 + channel = (freq - 2407) / 5;
8257 +u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
8260 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8261 + return bcm43xx_freq_to_channel_a(freq);
8262 + return bcm43xx_freq_to_channel_bg(freq);
8265 +/* Lightweight function to convert a channel number to a frequency (in Mhz). */
8267 +int bcm43xx_channel_to_freq_a(u8 channel)
8269 + return (5000 + (5 * channel));
8272 +int bcm43xx_channel_to_freq_bg(u8 channel)
8276 + if (channel == 14)
8279 + freq = 2407 + (5 * channel);
8284 +int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
8287 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8288 + return bcm43xx_channel_to_freq_a(channel);
8289 + return bcm43xx_channel_to_freq_bg(channel);
8292 +/* Lightweight function to check if a channel number is valid.
8293 + * Note that this does _NOT_ check for geographical restrictions!
8296 +int bcm43xx_is_valid_channel_a(u8 channel)
8298 + return (channel <= 200);
8301 +int bcm43xx_is_valid_channel_bg(u8 channel)
8303 + return (channel >= 1 && channel <= 14);
8306 +int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
8309 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A)
8310 + return bcm43xx_is_valid_channel_a(channel);
8311 + return bcm43xx_is_valid_channel_bg(channel);
8315 +int bcm43xx_is_cck_rate(int rate)
8317 + return (rate == BCM43xx_CCK_RATE_1MB ||
8318 + rate == BCM43xx_CCK_RATE_2MB ||
8319 + rate == BCM43xx_CCK_RATE_5MB ||
8320 + rate == BCM43xx_CCK_RATE_11MB);
8323 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
8324 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
8326 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
8329 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
8330 + u16 routing, u16 offset);
8331 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
8332 + u16 routing, u16 offset);
8333 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
8334 + u16 routing, u16 offset,
8336 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
8337 + u16 routing, u16 offset,
8340 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
8342 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
8344 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
8346 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
8347 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
8349 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
8351 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
8352 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
8354 +#endif /* BCM43xx_MAIN_H_ */
8355 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
8356 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c 1970-01-01 01:00:00.000000000 +0100
8357 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.c 2006-03-28 22:16:14.000000000 +0200
8361 + Broadcom BCM43xx wireless driver
8363 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
8364 + Stefano Brivio <st3@riseup.net>
8365 + Michael Buesch <mbuesch@freenet.de>
8366 + Danny van Dyk <kugelfang@gentoo.org>
8367 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
8369 + Some parts of the code in this file are derived from the ipw2200
8370 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8372 + This program is free software; you can redistribute it and/or modify
8373 + it under the terms of the GNU General Public License as published by
8374 + the Free Software Foundation; either version 2 of the License, or
8375 + (at your option) any later version.
8377 + This program is distributed in the hope that it will be useful,
8378 + but WITHOUT ANY WARRANTY; without even the implied warranty of
8379 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8380 + GNU General Public License for more details.
8382 + You should have received a copy of the GNU General Public License
8383 + along with this program; see the file COPYING. If not, write to
8384 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
8385 + Boston, MA 02110-1301, USA.
8389 +#include <linux/delay.h>
8390 +#include <linux/pci.h>
8391 +#include <linux/types.h>
8393 +#include "bcm43xx.h"
8394 +#include "bcm43xx_phy.h"
8395 +#include "bcm43xx_main.h"
8396 +#include "bcm43xx_radio.h"
8397 +#include "bcm43xx_ilt.h"
8398 +#include "bcm43xx_power.h"
8401 +static const s8 bcm43xx_tssi2dbm_b_table[] = {
8402 + 0x4D, 0x4C, 0x4B, 0x4A,
8403 + 0x4A, 0x49, 0x48, 0x47,
8404 + 0x47, 0x46, 0x45, 0x45,
8405 + 0x44, 0x43, 0x42, 0x42,
8406 + 0x41, 0x40, 0x3F, 0x3E,
8407 + 0x3D, 0x3C, 0x3B, 0x3A,
8408 + 0x39, 0x38, 0x37, 0x36,
8409 + 0x35, 0x34, 0x32, 0x31,
8410 + 0x30, 0x2F, 0x2D, 0x2C,
8411 + 0x2B, 0x29, 0x28, 0x26,
8412 + 0x25, 0x23, 0x21, 0x1F,
8413 + 0x1D, 0x1A, 0x17, 0x14,
8414 + 0x10, 0x0C, 0x06, 0x00,
8420 +static const s8 bcm43xx_tssi2dbm_g_table[] = {
8435 + -20, -20, -20, -20,
8436 + -20, -20, -20, -20,
8439 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
8442 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
8444 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8446 + assert(irqs_disabled());
8447 + if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
8448 + phy->is_locked = 0;
8451 + if (bcm->current_core->rev < 3) {
8452 + bcm43xx_mac_suspend(bcm);
8453 + spin_lock(&phy->lock);
8455 + if (bcm->iw_mode != IW_MODE_MASTER)
8456 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
8458 + phy->is_locked = 1;
8461 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
8463 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8465 + assert(irqs_disabled());
8466 + if (bcm->current_core->rev < 3) {
8467 + if (phy->is_locked) {
8468 + spin_unlock(&phy->lock);
8469 + bcm43xx_mac_enable(bcm);
8472 + if (bcm->iw_mode != IW_MODE_MASTER)
8473 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
8475 + phy->is_locked = 0;
8478 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
8480 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8481 + return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
8484 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
8486 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8488 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
8491 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
8493 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8494 + unsigned long flags;
8496 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
8497 + if (phy->calibrated)
8499 + if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
8500 + /* We do not want to be preempted while calibrating
8503 + local_irq_save(flags);
8505 + bcm43xx_wireless_core_reset(bcm, 0);
8506 + bcm43xx_phy_initg(bcm);
8507 + bcm43xx_wireless_core_reset(bcm, 1);
8509 + local_irq_restore(flags);
8511 + phy->calibrated = 1;
8515 + * http://bcm-specs.sipsolutions.net/SetPHY
8517 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
8519 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8522 + if (bcm->current_core->rev < 5)
8525 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
8527 + if (!(flags & 0x00010000))
8529 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8530 + flags |= (0x800 << 18);
8531 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8533 + if (!(flags & 0x00020000))
8535 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8536 + flags &= ~(0x800 << 18);
8537 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8540 + phy->connected = connect;
8542 + dprintk(KERN_INFO PFX "PHY connected\n");
8544 + dprintk(KERN_INFO PFX "PHY disconnected\n");
8549 +/* intialize B PHY power control
8550 + * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
8552 +static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
8554 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8555 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8556 + u16 saved_batt = 0, saved_ratt = 0, saved_txctl1 = 0;
8557 + int must_reset_txpower = 0;
8559 + assert(phy->type != BCM43xx_PHYTYPE_A);
8560 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8561 + (bcm->board_type == 0x0416))
8564 + bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
8565 + bcm43xx_phy_write(bcm, 0x0028, 0x8018);
8567 + if (phy->type == BCM43xx_PHYTYPE_G) {
8568 + if (!phy->connected)
8570 + bcm43xx_phy_write(bcm, 0x047A, 0xC111);
8572 + if (phy->savedpctlreg != 0xFFFF)
8575 + if (phy->type == BCM43xx_PHYTYPE_B &&
8577 + radio->version == 0x2050) {
8578 + bcm43xx_radio_write16(bcm, 0x0076,
8579 + bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
8581 + saved_batt = radio->baseband_atten;
8582 + saved_ratt = radio->radio_atten;
8583 + saved_txctl1 = radio->txctl1;
8584 + if ((radio->revision >= 6) && (radio->revision <= 8)
8585 + && /*FIXME: incomplete specs for 5 < revision < 9 */ 0)
8586 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 0x1F, 0);
8588 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
8589 + must_reset_txpower = 1;
8591 + bcm43xx_dummy_transmission(bcm);
8593 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
8595 + if (must_reset_txpower)
8596 + bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
8598 + bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
8599 + bcm43xx_radio_clear_tssi(bcm);
8602 +static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
8604 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8605 + u16 offset = 0x0000;
8607 + if (phy->rev == 1)
8610 + bcm43xx_ilt_write(bcm, offset, 0x00FE);
8611 + bcm43xx_ilt_write(bcm, offset + 1, 0x000D);
8612 + bcm43xx_ilt_write(bcm, offset + 2, 0x0013);
8613 + bcm43xx_ilt_write(bcm, offset + 3, 0x0019);
8615 + if (phy->rev == 1) {
8616 + bcm43xx_ilt_write(bcm, 0x1800, 0x2710);
8617 + bcm43xx_ilt_write(bcm, 0x1801, 0x9B83);
8618 + bcm43xx_ilt_write(bcm, 0x1802, 0x9B83);
8619 + bcm43xx_ilt_write(bcm, 0x1803, 0x0F8D);
8620 + bcm43xx_phy_write(bcm, 0x0455, 0x0004);
8623 + bcm43xx_phy_write(bcm, 0x04A5, (bcm43xx_phy_read(bcm, 0x04A5) & 0x00FF) | 0x5700);
8624 + bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xFF80) | 0x000F);
8625 + bcm43xx_phy_write(bcm, 0x041A, (bcm43xx_phy_read(bcm, 0x041A) & 0xC07F) | 0x2B80);
8626 + bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xF0FF) | 0x0300);
8628 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
8630 + bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xFFF0) | 0x0008);
8631 + bcm43xx_phy_write(bcm, 0x04A1, (bcm43xx_phy_read(bcm, 0x04A1) & 0xF0FF) | 0x0600);
8632 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xF0FF) | 0x0700);
8633 + bcm43xx_phy_write(bcm, 0x04A0, (bcm43xx_phy_read(bcm, 0x04A0) & 0xF0FF) | 0x0100);
8635 + if (phy->rev == 1)
8636 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
8638 + bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xFF00) | 0x001C);
8639 + bcm43xx_phy_write(bcm, 0x0488, (bcm43xx_phy_read(bcm, 0x0488) & 0xC0FF) | 0x0200);
8640 + bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0xFF00) | 0x001C);
8641 + bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xFF00) | 0x0020);
8642 + bcm43xx_phy_write(bcm, 0x0489, (bcm43xx_phy_read(bcm, 0x0489) & 0xC0FF) | 0x0200);
8643 + bcm43xx_phy_write(bcm, 0x0482, (bcm43xx_phy_read(bcm, 0x0482) & 0xFF00) | 0x002E);
8644 + bcm43xx_phy_write(bcm, 0x0496, (bcm43xx_phy_read(bcm, 0x0496) & 0x00FF) | 0x1A00);
8645 + bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0xFF00) | 0x0028);
8646 + bcm43xx_phy_write(bcm, 0x0481, (bcm43xx_phy_read(bcm, 0x0481) & 0x00FF) | 0x2C00);
8648 + if (phy->rev == 1) {
8649 + bcm43xx_phy_write(bcm, 0x0430, 0x092B);
8650 + bcm43xx_phy_write(bcm, 0x041B, (bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1) | 0x0002);
8652 + bcm43xx_phy_write(bcm, 0x041B, bcm43xx_phy_read(bcm, 0x041B) & 0xFFE1);
8653 + bcm43xx_phy_write(bcm, 0x041F, 0x287A);
8654 + bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0xFFF0) | 0x0004);
8657 + if (phy->rev > 2) {
8658 + bcm43xx_phy_write(bcm, 0x0422, 0x287A);
8659 + bcm43xx_phy_write(bcm, 0x0420, (bcm43xx_phy_read(bcm, 0x0420) & 0x0FFF) | 0x3000);
8662 + bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
8663 + bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
8665 + if (phy->rev == 1) {
8666 + bcm43xx_phy_write(bcm, 0x04AB, (bcm43xx_phy_read(bcm, 0x04AB) & 0xF0FF) | 0x0600);
8667 + bcm43xx_phy_write(bcm, 0x048B, 0x005E);
8668 + bcm43xx_phy_write(bcm, 0x048C, (bcm43xx_phy_read(bcm, 0x048C) & 0xFF00) | 0x001E);
8669 + bcm43xx_phy_write(bcm, 0x048D, 0x0002);
8672 + bcm43xx_ilt_write(bcm, offset + 0x0800, 0);
8673 + bcm43xx_ilt_write(bcm, offset + 0x0801, 7);
8674 + bcm43xx_ilt_write(bcm, offset + 0x0802, 16);
8675 + bcm43xx_ilt_write(bcm, offset + 0x0803, 28);
8678 +static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
8680 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8683 + assert(phy->type == BCM43xx_PHYTYPE_G);
8684 + if (phy->rev == 1) {
8685 + bcm43xx_phy_write(bcm, 0x0406, 0x4F19);
8686 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
8687 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0xFC3F) | 0x0340);
8688 + bcm43xx_phy_write(bcm, 0x042C, 0x005A);
8689 + bcm43xx_phy_write(bcm, 0x0427, 0x001A);
8691 + for (i = 0; i < BCM43xx_ILT_FINEFREQG_SIZE; i++)
8692 + bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqg[i]);
8693 + for (i = 0; i < BCM43xx_ILT_NOISEG1_SIZE; i++)
8694 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg1[i]);
8695 + for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
8696 + bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
8698 + /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
8699 + bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
8701 + if (phy->rev == 2) {
8702 + bcm43xx_phy_write(bcm, 0x04C0, 0x1861);
8703 + bcm43xx_phy_write(bcm, 0x04C1, 0x0271);
8704 + } else if (phy->rev > 2) {
8705 + bcm43xx_phy_write(bcm, 0x04C0, 0x0098);
8706 + bcm43xx_phy_write(bcm, 0x04C1, 0x0070);
8707 + bcm43xx_phy_write(bcm, 0x04C9, 0x0080);
8709 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
8711 + for (i = 0; i < 64; i++)
8712 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8713 + for (i = 0; i < BCM43xx_ILT_NOISEG2_SIZE; i++)
8714 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noiseg2[i]);
8717 + if (phy->rev <= 2)
8718 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8719 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg1[i]);
8720 + else if ((phy->rev == 7) && (bcm43xx_phy_read(bcm, 0x0449) & 0x0200))
8721 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8722 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg3[i]);
8724 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8725 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
8727 + if (phy->rev == 2)
8728 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8729 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
8730 + else if ((phy->rev > 2) && (phy->rev <= 7))
8731 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8732 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr2[i]);
8734 + if (phy->rev == 1) {
8735 + for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
8736 + bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
8737 + for (i = 0; i < 4; i++) {
8738 + bcm43xx_ilt_write(bcm, 0x5404 + i, 0x0020);
8739 + bcm43xx_ilt_write(bcm, 0x5408 + i, 0x0020);
8740 + bcm43xx_ilt_write(bcm, 0x540C + i, 0x0020);
8741 + bcm43xx_ilt_write(bcm, 0x5410 + i, 0x0020);
8743 + bcm43xx_phy_agcsetup(bcm);
8745 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8746 + (bcm->board_type == 0x0416) &&
8747 + (bcm->board_revision == 0x0017))
8750 + bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
8751 + bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
8753 + for (i = 0; i <= 0x2F; i++)
8754 + bcm43xx_ilt_write(bcm, 0x1000 + i, 0x0820);
8755 + bcm43xx_phy_agcsetup(bcm);
8756 + bcm43xx_phy_read(bcm, 0x0400); /* dummy read */
8757 + bcm43xx_phy_write(bcm, 0x0403, 0x1000);
8758 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8759 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8761 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8762 + (bcm->board_type == 0x0416) &&
8763 + (bcm->board_revision == 0x0017))
8766 + bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
8767 + bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
8771 +/* Initialize the noisescaletable for APHY */
8772 +static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
8774 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8777 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, 0x1400);
8778 + for (i = 0; i < 12; i++) {
8779 + if (phy->rev == 2)
8780 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
8782 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8784 + if (phy->rev == 2)
8785 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
8787 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2300);
8788 + for (i = 0; i < 11; i++) {
8789 + if (phy->rev == 2)
8790 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6767);
8792 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8794 + if (phy->rev == 2)
8795 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
8797 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
8800 +static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
8802 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8805 + assert(phy->type == BCM43xx_PHYTYPE_A);
8806 + switch (phy->rev) {
8808 + bcm43xx_phy_write(bcm, 0x008E, 0x3800);
8809 + bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
8810 + bcm43xx_phy_write(bcm, 0x0036, 0x0400);
8812 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8814 + bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
8815 + bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
8816 + bcm43xx_ilt_write(bcm, 0x3C0C, 0x07BF);
8817 + bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
8819 + bcm43xx_phy_write(bcm, 0x0024, 0x4680);
8820 + bcm43xx_phy_write(bcm, 0x0020, 0x0003);
8821 + bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
8822 + bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
8824 + bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
8825 + bcm43xx_phy_write(bcm, 0x002B, bcm43xx_phy_read(bcm, 0x002B) & 0xFBFF);
8826 + bcm43xx_phy_write(bcm, 0x008E, 0x58C1);
8828 + bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
8829 + bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
8830 + bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
8831 + bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
8832 + bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
8834 + bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
8835 + bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
8836 + bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
8837 + bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
8838 + bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
8839 + bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
8840 + bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
8842 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8843 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8844 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8846 + for (i = 0; i < 16; i++)
8847 + bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
8849 + bcm43xx_ilt_write(bcm, 0x3003, 0x1044);
8850 + bcm43xx_ilt_write(bcm, 0x3004, 0x7201);
8851 + bcm43xx_ilt_write(bcm, 0x3006, 0x0040);
8852 + bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
8854 + for (i = 0; i < BCM43xx_ILT_FINEFREQA_SIZE; i++)
8855 + bcm43xx_ilt_write(bcm, 0x5800 + i, bcm43xx_ilt_finefreqa[i]);
8856 + for (i = 0; i < BCM43xx_ILT_NOISEA2_SIZE; i++)
8857 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea2[i]);
8858 + for (i = 0; i < BCM43xx_ILT_ROTOR_SIZE; i++)
8859 + bcm43xx_ilt_write(bcm, 0x2000 + i, bcm43xx_ilt_rotor[i]);
8860 + bcm43xx_phy_init_noisescaletbl(bcm);
8861 + for (i = 0; i < BCM43xx_ILT_RETARD_SIZE; i++)
8862 + bcm43xx_ilt_write(bcm, 0x2400 + i, bcm43xx_ilt_retard[i]);
8865 + for (i = 0; i < 64; i++)
8866 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8868 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8870 + bcm43xx_phy_write(bcm, 0x001C, 0x0FF9);
8871 + bcm43xx_phy_write(bcm, 0x0020, bcm43xx_phy_read(bcm, 0x0020) & 0xFF0F);
8872 + bcm43xx_radio_write16(bcm, 0x0002, 0x07BF);
8874 + bcm43xx_phy_write(bcm, 0x0024, 0x4680);
8875 + bcm43xx_phy_write(bcm, 0x0020, 0x0003);
8876 + bcm43xx_phy_write(bcm, 0x001D, 0x0F40);
8877 + bcm43xx_phy_write(bcm, 0x001F, 0x1C00);
8878 + bcm43xx_phy_write(bcm, 0x002A, (bcm43xx_phy_read(bcm, 0x002A) & 0x00FF) | 0x0400);
8880 + bcm43xx_ilt_write(bcm, 0x3001, (bcm43xx_ilt_read(bcm, 0x3001) & 0x0010) | 0x0008);
8881 + for (i = 0; i < BCM43xx_ILT_NOISEA3_SIZE; i++)
8882 + bcm43xx_ilt_write(bcm, 0x1800 + i, bcm43xx_ilt_noisea3[i]);
8883 + bcm43xx_phy_init_noisescaletbl(bcm);
8884 + for (i = 0; i < BCM43xx_ILT_SIGMASQR_SIZE; i++)
8885 + bcm43xx_ilt_write(bcm, 0x5000 + i, bcm43xx_ilt_sigmasqr1[i]);
8887 + bcm43xx_phy_write(bcm, 0x0003, 0x1808);
8889 + bcm43xx_ilt_write(bcm, 0x0803, 0x000F);
8890 + bcm43xx_ilt_write(bcm, 0x0804, 0x001F);
8891 + bcm43xx_ilt_write(bcm, 0x0805, 0x002A);
8892 + bcm43xx_ilt_write(bcm, 0x0805, 0x0030);
8893 + bcm43xx_ilt_write(bcm, 0x0807, 0x003A);
8895 + bcm43xx_ilt_write(bcm, 0x0000, 0x0013);
8896 + bcm43xx_ilt_write(bcm, 0x0001, 0x0013);
8897 + bcm43xx_ilt_write(bcm, 0x0002, 0x0013);
8898 + bcm43xx_ilt_write(bcm, 0x0003, 0x0013);
8899 + bcm43xx_ilt_write(bcm, 0x0004, 0x0015);
8900 + bcm43xx_ilt_write(bcm, 0x0005, 0x0015);
8901 + bcm43xx_ilt_write(bcm, 0x0006, 0x0019);
8903 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8904 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8905 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8907 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8908 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8915 +/* Initialize APHY. This is also called for the GPHY in some cases. */
8916 +static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
8918 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8919 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8922 + if (phy->type == BCM43xx_PHYTYPE_A) {
8923 + bcm43xx_phy_setupa(bcm);
8925 + bcm43xx_phy_setupg(bcm);
8926 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
8927 + bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
8931 + bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
8932 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) & 0xF83C) | 0x0340);
8933 + bcm43xx_phy_write(bcm, 0x0034, 0x0001);
8935 + TODO();//TODO: RSSI AGC
8936 + bcm43xx_phy_write(bcm, BCM43xx_PHY_A_CRS,
8937 + bcm43xx_phy_read(bcm, BCM43xx_PHY_A_CRS) | (1 << 14));
8938 + bcm43xx_radio_init2060(bcm);
8940 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM)
8941 + && ((bcm->board_type == 0x0416) || (bcm->board_type == 0x040A))) {
8942 + if (radio->lofcal == 0xFFFF) {
8943 + TODO();//TODO: LOF Cal
8944 + bcm43xx_radio_set_tx_iq(bcm);
8946 + bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
8949 + bcm43xx_phy_write(bcm, 0x007A, 0xF111);
8951 + if (phy->savedpctlreg == 0xFFFF) {
8952 + bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
8953 + bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
8955 + tval = bcm43xx_ilt_read(bcm, 0x3001);
8956 + if (phy->rev == 1) {
8957 + bcm43xx_ilt_write(bcm, 0x3001,
8958 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFF87)
8961 + bcm43xx_ilt_write(bcm, 0x3001,
8962 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
8965 + bcm43xx_dummy_transmission(bcm);
8966 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
8967 + bcm43xx_ilt_write(bcm, 0x3001, tval);
8969 + bcm43xx_radio_set_txpower_a(bcm, 0x0018);
8971 + bcm43xx_radio_clear_tssi(bcm);
8974 +static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
8976 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8979 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
8980 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
8981 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
8982 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
8983 + bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
8985 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8986 + bcm43xx_phy_write(bcm, offset, val);
8989 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8990 + if (radio->channel == 0xFF)
8991 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
8993 + bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
8994 + if (radio->version != 0x2050) {
8995 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
8996 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
8998 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
8999 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9000 + if (radio->version == 0x2050) {
9001 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9002 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9003 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9004 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9005 + bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
9006 + bcm43xx_phy_write(bcm, 0x0038, 0x0677);
9007 + bcm43xx_radio_init2050(bcm);
9009 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9010 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9011 + bcm43xx_phy_write(bcm, 0x0032, 0x00CC);
9012 + bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
9013 + bcm43xx_phy_lo_b_measure(bcm);
9014 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9015 + if (radio->version != 0x2050)
9016 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
9017 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1000);
9018 + bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
9019 + if (radio->version != 0x2050)
9020 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
9021 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9022 + bcm43xx_phy_init_pctl(bcm);
9025 +static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
9027 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9030 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
9031 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
9032 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
9033 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
9034 + bcm43xx_phy_write(bcm, 0x0088, 0x3E00);
9036 + for (offset = 0x0089; offset < 0x00A7; offset++) {
9037 + bcm43xx_phy_write(bcm, offset, val);
9040 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
9041 + if (radio->channel == 0xFF)
9042 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9044 + bcm43xx_radio_selectchannel(bcm, radio->channel, 0);
9045 + if (radio->version != 0x2050) {
9046 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
9047 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
9049 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9050 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9051 + if (radio->version == 0x2050) {
9052 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9053 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9054 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9055 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9056 + bcm43xx_radio_write16(bcm, 0x007A, 0x000F);
9057 + bcm43xx_phy_write(bcm, 0x0038, 0x0677);
9058 + bcm43xx_radio_init2050(bcm);
9060 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9061 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9062 + if (radio->version == 0x2050)
9063 + bcm43xx_phy_write(bcm, 0x0032, 0x00E0);
9064 + bcm43xx_phy_write(bcm, 0x0035, 0x07C2);
9066 + bcm43xx_phy_lo_b_measure(bcm);
9068 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9069 + if (radio->version == 0x2050)
9070 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
9071 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x1100);
9072 + bcm43xx_phy_write(bcm, 0x002A, 0x88A3);
9073 + if (radio->version == 0x2050)
9074 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
9075 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9076 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
9077 + bcm43xx_calc_nrssi_slope(bcm);
9078 + bcm43xx_calc_nrssi_threshold(bcm);
9080 + bcm43xx_phy_init_pctl(bcm);
9083 +static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
9085 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9086 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9089 + if (phy->version == 1 &&
9090 + radio->version == 0x2050) {
9091 + bcm43xx_radio_write16(bcm, 0x007A,
9092 + bcm43xx_radio_read16(bcm, 0x007A)
9095 + if ((bcm->board_vendor != PCI_VENDOR_ID_BROADCOM) &&
9096 + (bcm->board_type != 0x0416)) {
9097 + for (offset = 0x00A8 ; offset < 0x00C7; offset++) {
9098 + bcm43xx_phy_write(bcm, offset,
9099 + (bcm43xx_phy_read(bcm, offset) + 0x2020)
9103 + bcm43xx_phy_write(bcm, 0x0035,
9104 + (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
9106 + if (radio->version == 0x2050)
9107 + bcm43xx_phy_write(bcm, 0x0038, 0x0667);
9109 + if (phy->connected) {
9110 + if (radio->version == 0x2050) {
9111 + bcm43xx_radio_write16(bcm, 0x007A,
9112 + bcm43xx_radio_read16(bcm, 0x007A)
9114 + bcm43xx_radio_write16(bcm, 0x0051,
9115 + bcm43xx_radio_read16(bcm, 0x0051)
9118 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
9120 + bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9121 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9123 + bcm43xx_phy_write(bcm, 0x001C, 0x186A);
9125 + bcm43xx_phy_write(bcm, 0x0013, (bcm43xx_phy_read(bcm, 0x0013) & 0x00FF) | 0x1900);
9126 + bcm43xx_phy_write(bcm, 0x0035, (bcm43xx_phy_read(bcm, 0x0035) & 0xFFC0) | 0x0064);
9127 + bcm43xx_phy_write(bcm, 0x005D, (bcm43xx_phy_read(bcm, 0x005D) & 0xFF80) | 0x000A);
9130 + if (bcm->bad_frames_preempt) {
9131 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
9132 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | (1 << 11));
9135 + if (phy->version == 1 && radio->version == 0x2050) {
9136 + bcm43xx_phy_write(bcm, 0x0026, 0xCE00);
9137 + bcm43xx_phy_write(bcm, 0x0021, 0x3763);
9138 + bcm43xx_phy_write(bcm, 0x0022, 0x1BC3);
9139 + bcm43xx_phy_write(bcm, 0x0023, 0x06F9);
9140 + bcm43xx_phy_write(bcm, 0x0024, 0x037E);
9142 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9143 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
9144 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
9146 + if (phy->version == 1 && radio->version == 0x2050)
9147 + bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
9149 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
9151 + if (phy->version == 0)
9152 + bcm43xx_write16(bcm, 0x03E4, 0x3000);
9154 + /* Force to channel 7, even if not supported. */
9155 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9157 + if (radio->version != 0x2050) {
9158 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
9159 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
9162 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9163 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9165 + if (radio->version == 0x2050) {
9166 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9167 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9170 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9171 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9173 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
9175 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9177 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9178 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9179 + bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
9181 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9183 + if (radio->version == 0x2050)
9184 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9186 + bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
9189 +static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
9191 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9192 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9195 + bcm43xx_phy_write(bcm, 0x003E, 0x817A);
9196 + bcm43xx_radio_write16(bcm, 0x007A,
9197 + (bcm43xx_radio_read16(bcm, 0x007A) | 0x0058));
9198 + if ((radio->manufact == 0x17F) &&
9199 + (radio->version == 0x2050) &&
9200 + (radio->revision == 3 ||
9201 + radio->revision == 4 ||
9202 + radio->revision == 5)) {
9203 + bcm43xx_radio_write16(bcm, 0x0051, 0x001F);
9204 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9205 + bcm43xx_radio_write16(bcm, 0x0053, 0x005B);
9206 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9207 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9208 + bcm43xx_radio_write16(bcm, 0x005B, 0x0088);
9209 + bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
9210 + bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
9211 + bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
9213 + if ((radio->manufact == 0x17F) &&
9214 + (radio->version == 0x2050) &&
9215 + (radio->revision == 6)) {
9216 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9217 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9218 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9219 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9220 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9221 + bcm43xx_radio_write16(bcm, 0x005B, 0x008B);
9222 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B5);
9223 + bcm43xx_radio_write16(bcm, 0x005D, 0x0088);
9224 + bcm43xx_radio_write16(bcm, 0x005E, 0x0088);
9225 + bcm43xx_radio_write16(bcm, 0x007D, 0x0088);
9226 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9227 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9229 + if ((radio->manufact == 0x17F) &&
9230 + (radio->version == 0x2050) &&
9231 + (radio->revision == 7)) {
9232 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9233 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9234 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9235 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9236 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9237 + bcm43xx_radio_write16(bcm, 0x005B, 0x00A8);
9238 + bcm43xx_radio_write16(bcm, 0x005C, 0x0075);
9239 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9240 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
9241 + bcm43xx_radio_write16(bcm, 0x007D, 0x00E8);
9242 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9243 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9244 + bcm43xx_radio_write16(bcm, 0x007B, 0x0000);
9246 + if ((radio->manufact == 0x17F) &&
9247 + (radio->version == 0x2050) &&
9248 + (radio->revision == 8)) {
9249 + bcm43xx_radio_write16(bcm, 0x0051, 0x0000);
9250 + bcm43xx_radio_write16(bcm, 0x0052, 0x0040);
9251 + bcm43xx_radio_write16(bcm, 0x0053, 0x00B7);
9252 + bcm43xx_radio_write16(bcm, 0x0054, 0x0098);
9253 + bcm43xx_radio_write16(bcm, 0x005A, 0x0088);
9254 + bcm43xx_radio_write16(bcm, 0x005B, 0x006B);
9255 + bcm43xx_radio_write16(bcm, 0x005C, 0x000F);
9256 + if (bcm->sprom.boardflags & 0x8000) {
9257 + bcm43xx_radio_write16(bcm, 0x005D, 0x00FA);
9258 + bcm43xx_radio_write16(bcm, 0x005E, 0x00D8);
9260 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9261 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
9263 + bcm43xx_radio_write16(bcm, 0x0073, 0x0003);
9264 + bcm43xx_radio_write16(bcm, 0x007D, 0x00A8);
9265 + bcm43xx_radio_write16(bcm, 0x007C, 0x0001);
9266 + bcm43xx_radio_write16(bcm, 0x007E, 0x0008);
9269 + for (offset = 0x0088; offset < 0x0098; offset++) {
9270 + bcm43xx_phy_write(bcm, offset, val);
9274 + for (offset = 0x0098; offset < 0x00A8; offset++) {
9275 + bcm43xx_phy_write(bcm, offset, val);
9279 + for (offset = 0x00A8; offset < 0x00C8; offset++) {
9280 + bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
9283 + if (phy->type == BCM43xx_PHYTYPE_G) {
9284 + bcm43xx_radio_write16(bcm, 0x007A,
9285 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0020);
9286 + bcm43xx_radio_write16(bcm, 0x0051,
9287 + bcm43xx_radio_read16(bcm, 0x0051) | 0x0004);
9288 + bcm43xx_phy_write(bcm, 0x0802,
9289 + bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9290 + bcm43xx_phy_write(bcm, 0x042B,
9291 + bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9294 + /* Force to channel 7, even if not supported. */
9295 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9297 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9298 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9300 + bcm43xx_radio_write16(bcm, 0x007C, (bcm43xx_radio_read16(bcm, 0x007C) | 0x0002));
9301 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9302 + if (radio->manufact == 0x17F &&
9303 + radio->version == 0x2050 &&
9304 + radio->revision <= 2) {
9305 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9306 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9307 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9308 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9310 + bcm43xx_radio_write16(bcm, 0x007A,
9311 + (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
9313 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9315 + bcm43xx_phy_write(bcm, 0x0014, 0x0200);
9316 + if (radio->version == 0x2050){
9317 + if (radio->revision == 3 ||
9318 + radio->revision == 4 ||
9319 + radio->revision == 5)
9320 + bcm43xx_phy_write(bcm, 0x002A, 0x8AC0);
9322 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
9324 + bcm43xx_phy_write(bcm, 0x0038, 0x0668);
9325 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9326 + if (radio->version == 0x2050) {
9327 + if (radio->revision == 3 ||
9328 + radio->revision == 4 ||
9329 + radio->revision == 5)
9330 + bcm43xx_phy_write(bcm, 0x005D, bcm43xx_phy_read(bcm, 0x005D) | 0x0003);
9331 + else if (radio->revision <= 2)
9332 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9335 + if (phy->rev == 4)
9336 + bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
9338 + bcm43xx_write16(bcm, 0x03E4, 0x0009);
9339 + if (phy->type == BCM43xx_PHYTYPE_B) {
9340 + bcm43xx_write16(bcm, 0x03E6, 0x8140);
9341 + bcm43xx_phy_write(bcm, 0x0016, 0x0410);
9342 + bcm43xx_phy_write(bcm, 0x0017, 0x0820);
9343 + bcm43xx_phy_write(bcm, 0x0062, 0x0007);
9344 + (void) bcm43xx_radio_calibrationvalue(bcm);
9345 + bcm43xx_phy_lo_b_measure(bcm);
9346 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
9347 + bcm43xx_calc_nrssi_slope(bcm);
9348 + bcm43xx_calc_nrssi_threshold(bcm);
9350 + bcm43xx_phy_init_pctl(bcm);
9352 + bcm43xx_write16(bcm, 0x03E6, 0x0);
9355 +static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
9357 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9358 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9359 + u16 backup_phy[15];
9360 + u16 backup_radio[3];
9363 + u16 loop1_cnt, loop1_done, loop1_omitted;
9366 + backup_phy[0] = bcm43xx_phy_read(bcm, 0x0429);
9367 + backup_phy[1] = bcm43xx_phy_read(bcm, 0x0001);
9368 + backup_phy[2] = bcm43xx_phy_read(bcm, 0x0811);
9369 + backup_phy[3] = bcm43xx_phy_read(bcm, 0x0812);
9370 + backup_phy[4] = bcm43xx_phy_read(bcm, 0x0814);
9371 + backup_phy[5] = bcm43xx_phy_read(bcm, 0x0815);
9372 + backup_phy[6] = bcm43xx_phy_read(bcm, 0x005A);
9373 + backup_phy[7] = bcm43xx_phy_read(bcm, 0x0059);
9374 + backup_phy[8] = bcm43xx_phy_read(bcm, 0x0058);
9375 + backup_phy[9] = bcm43xx_phy_read(bcm, 0x000A);
9376 + backup_phy[10] = bcm43xx_phy_read(bcm, 0x0003);
9377 + backup_phy[11] = bcm43xx_phy_read(bcm, 0x080F);
9378 + backup_phy[12] = bcm43xx_phy_read(bcm, 0x0810);
9379 + backup_phy[13] = bcm43xx_phy_read(bcm, 0x002B);
9380 + backup_phy[14] = bcm43xx_phy_read(bcm, 0x0015);
9381 + bcm43xx_phy_read(bcm, 0x002D); /* dummy read */
9382 + backup_bband = radio->baseband_atten;
9383 + backup_radio[0] = bcm43xx_radio_read16(bcm, 0x0052);
9384 + backup_radio[1] = bcm43xx_radio_read16(bcm, 0x0043);
9385 + backup_radio[2] = bcm43xx_radio_read16(bcm, 0x007A);
9387 + bcm43xx_phy_write(bcm, 0x0429,
9388 + bcm43xx_phy_read(bcm, 0x0429) & 0x3FFF);
9389 + bcm43xx_phy_write(bcm, 0x0001,
9390 + bcm43xx_phy_read(bcm, 0x0001) & 0x8000);
9391 + bcm43xx_phy_write(bcm, 0x0811,
9392 + bcm43xx_phy_read(bcm, 0x0811) | 0x0002);
9393 + bcm43xx_phy_write(bcm, 0x0812,
9394 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFFD);
9395 + bcm43xx_phy_write(bcm, 0x0811,
9396 + bcm43xx_phy_read(bcm, 0x0811) | 0x0001);
9397 + bcm43xx_phy_write(bcm, 0x0812,
9398 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFFE);
9399 + bcm43xx_phy_write(bcm, 0x0814,
9400 + bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
9401 + bcm43xx_phy_write(bcm, 0x0815,
9402 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
9403 + bcm43xx_phy_write(bcm, 0x0814,
9404 + bcm43xx_phy_read(bcm, 0x0814) | 0x0002);
9405 + bcm43xx_phy_write(bcm, 0x0815,
9406 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFD);
9407 + bcm43xx_phy_write(bcm, 0x0811,
9408 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
9409 + bcm43xx_phy_write(bcm, 0x0812,
9410 + bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
9412 + bcm43xx_phy_write(bcm, 0x0811,
9413 + (bcm43xx_phy_read(bcm, 0x0811)
9414 + & 0xFFCF) | 0x0030);
9415 + bcm43xx_phy_write(bcm, 0x0812,
9416 + (bcm43xx_phy_read(bcm, 0x0812)
9417 + & 0xFFCF) | 0x0010);
9419 + bcm43xx_phy_write(bcm, 0x005A, 0x0780);
9420 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
9421 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
9422 + if (phy->version == 0) {
9423 + bcm43xx_phy_write(bcm, 0x0003, 0x0122);
9425 + bcm43xx_phy_write(bcm, 0x000A,
9426 + bcm43xx_phy_read(bcm, 0x000A)
9429 + bcm43xx_phy_write(bcm, 0x0814,
9430 + bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
9431 + bcm43xx_phy_write(bcm, 0x0815,
9432 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
9433 + bcm43xx_phy_write(bcm, 0x0003,
9434 + (bcm43xx_phy_read(bcm, 0x0003)
9435 + & 0xFF9F) | 0x0040);
9436 + if (radio->version == 0x2050 && radio->revision == 2) {
9437 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9438 + bcm43xx_radio_write16(bcm, 0x0043,
9439 + (bcm43xx_radio_read16(bcm, 0x0043)
9440 + & 0xFFF0) | 0x0009);
9442 + } else if (radio->revision == 8) {
9443 + bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
9448 + bcm43xx_phy_set_baseband_attenuation(bcm, 11);
9450 + if (phy->rev >= 3)
9451 + bcm43xx_phy_write(bcm, 0x080F, 0xC020);
9453 + bcm43xx_phy_write(bcm, 0x080F, 0x8020);
9454 + bcm43xx_phy_write(bcm, 0x0810, 0x0000);
9456 + bcm43xx_phy_write(bcm, 0x002B,
9457 + (bcm43xx_phy_read(bcm, 0x002B)
9458 + & 0xFFC0) | 0x0001);
9459 + bcm43xx_phy_write(bcm, 0x002B,
9460 + (bcm43xx_phy_read(bcm, 0x002B)
9461 + & 0xC0FF) | 0x0800);
9462 + bcm43xx_phy_write(bcm, 0x0811,
9463 + bcm43xx_phy_read(bcm, 0x0811) | 0x0100);
9464 + bcm43xx_phy_write(bcm, 0x0812,
9465 + bcm43xx_phy_read(bcm, 0x0812) & 0xCFFF);
9466 + if (bcm->sprom.boardflags & BCM43xx_BFL_EXTLNA) {
9467 + if (phy->rev >= 7) {
9468 + bcm43xx_phy_write(bcm, 0x0811,
9469 + bcm43xx_phy_read(bcm, 0x0811)
9471 + bcm43xx_phy_write(bcm, 0x0812,
9472 + bcm43xx_phy_read(bcm, 0x0812)
9476 + bcm43xx_radio_write16(bcm, 0x007A,
9477 + bcm43xx_radio_read16(bcm, 0x007A)
9480 + for (i = 0; i < loop1_cnt; i++) {
9481 + bcm43xx_radio_write16(bcm, 0x0043, loop1_cnt);
9482 + bcm43xx_phy_write(bcm, 0x0812,
9483 + (bcm43xx_phy_read(bcm, 0x0812)
9484 + & 0xF0FF) | (i << 8));
9485 + bcm43xx_phy_write(bcm, 0x0015,
9486 + (bcm43xx_phy_read(bcm, 0x0015)
9487 + & 0x0FFF) | 0xA000);
9488 + bcm43xx_phy_write(bcm, 0x0015,
9489 + (bcm43xx_phy_read(bcm, 0x0015)
9490 + & 0x0FFF) | 0xF000);
9492 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9496 + loop1_omitted = loop1_cnt - loop1_done;
9499 + if (loop1_done >= 8) {
9500 + bcm43xx_phy_write(bcm, 0x0812,
9501 + bcm43xx_phy_read(bcm, 0x0812)
9503 + for (i = loop1_done - 8; i < 16; i++) {
9504 + bcm43xx_phy_write(bcm, 0x0812,
9505 + (bcm43xx_phy_read(bcm, 0x0812)
9506 + & 0xF0FF) | (i << 8));
9507 + bcm43xx_phy_write(bcm, 0x0015,
9508 + (bcm43xx_phy_read(bcm, 0x0015)
9509 + & 0x0FFF) | 0xA000);
9510 + bcm43xx_phy_write(bcm, 0x0015,
9511 + (bcm43xx_phy_read(bcm, 0x0015)
9512 + & 0x0FFF) | 0xF000);
9514 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9519 + bcm43xx_phy_write(bcm, 0x0814, backup_phy[4]);
9520 + bcm43xx_phy_write(bcm, 0x0815, backup_phy[5]);
9521 + bcm43xx_phy_write(bcm, 0x005A, backup_phy[6]);
9522 + bcm43xx_phy_write(bcm, 0x0059, backup_phy[7]);
9523 + bcm43xx_phy_write(bcm, 0x0058, backup_phy[8]);
9524 + bcm43xx_phy_write(bcm, 0x000A, backup_phy[9]);
9525 + bcm43xx_phy_write(bcm, 0x0003, backup_phy[10]);
9526 + bcm43xx_phy_write(bcm, 0x080F, backup_phy[11]);
9527 + bcm43xx_phy_write(bcm, 0x0810, backup_phy[12]);
9528 + bcm43xx_phy_write(bcm, 0x002B, backup_phy[13]);
9529 + bcm43xx_phy_write(bcm, 0x0015, backup_phy[14]);
9531 + bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
9533 + bcm43xx_radio_write16(bcm, 0x0052, backup_radio[0]);
9534 + bcm43xx_radio_write16(bcm, 0x0043, backup_radio[1]);
9535 + bcm43xx_radio_write16(bcm, 0x007A, backup_radio[2]);
9537 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
9539 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2]);
9540 + bcm43xx_phy_write(bcm, 0x0812, backup_phy[3]);
9541 + bcm43xx_phy_write(bcm, 0x0429, backup_phy[0]);
9542 + bcm43xx_phy_write(bcm, 0x0001, backup_phy[1]);
9544 + phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
9545 + phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
9548 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
9550 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9551 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9554 + if (phy->rev == 1)
9555 + bcm43xx_phy_initb5(bcm);
9556 + else if (phy->rev >= 2 && phy->rev <= 7)
9557 + bcm43xx_phy_initb6(bcm);
9558 + if (phy->rev >= 2 || phy->connected)
9559 + bcm43xx_phy_inita(bcm);
9561 + if (phy->rev >= 2) {
9562 + bcm43xx_phy_write(bcm, 0x0814, 0x0000);
9563 + bcm43xx_phy_write(bcm, 0x0815, 0x0000);
9564 + if (phy->rev == 2)
9565 + bcm43xx_phy_write(bcm, 0x0811, 0x0000);
9566 + else if (phy->rev >= 3)
9567 + bcm43xx_phy_write(bcm, 0x0811, 0x0400);
9568 + bcm43xx_phy_write(bcm, 0x0015, 0x00C0);
9569 + if (phy->connected) {
9570 + tmp = bcm43xx_phy_read(bcm, 0x0400) & 0xFF;
9572 + bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
9573 + bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
9575 + bcm43xx_phy_write(bcm, 0x04CC,
9576 + (bcm43xx_phy_read(bcm, 0x04CC)
9577 + & 0x00FF) | 0x1F00);
9582 + if (phy->rev < 3 && phy->connected)
9583 + bcm43xx_phy_write(bcm, 0x047E, 0x0078);
9584 + if (phy->rev >= 6 && phy->rev <= 8) {
9585 + bcm43xx_phy_write(bcm, 0x0801, bcm43xx_phy_read(bcm, 0x0801) | 0x0080);
9586 + bcm43xx_phy_write(bcm, 0x043E, bcm43xx_phy_read(bcm, 0x043E) | 0x0004);
9588 + if (phy->rev >= 2 && phy->connected)
9589 + bcm43xx_calc_loopback_gain(bcm);
9590 + if (radio->revision != 8) {
9591 + if (radio->initval == 0xFFFF)
9592 + radio->initval = bcm43xx_radio_init2050(bcm);
9594 + bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
9596 + if (radio->txctl2 == 0xFFFF) {
9597 + bcm43xx_phy_lo_g_measure(bcm);
9599 + if (radio->version == 0x2050 && radio->revision == 8) {
9602 + bcm43xx_radio_write16(bcm, 0x0052,
9603 + (bcm43xx_radio_read16(bcm, 0x0052)
9604 + & 0xFFF0) | radio->txctl1);
9606 + if (phy->rev >= 6) {
9608 + bcm43xx_phy_write(bcm, 0x0036,
9609 + (bcm43xx_phy_read(bcm, 0x0036)
9610 + & 0xF000) | (FIXME << 12));
9613 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
9614 + bcm43xx_phy_write(bcm, 0x002E, 0x8075);
9616 + bcm43xx_phy_write(bcm, 0x003E, 0x807F);
9618 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
9620 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
9622 + if (phy->connected) {
9623 + bcm43xx_phy_lo_adjust(bcm, 0);
9624 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
9627 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
9628 + /* The specs state to update the NRSSI LT with
9629 + * the value 0x7FFFFFFF here. I think that is some weird
9630 + * compiler optimization in the original driver.
9631 + * Essentially, what we do here is resetting all NRSSI LT
9632 + * entries to -32 (see the limit_value() in nrssi_hw_update())
9634 + bcm43xx_nrssi_hw_update(bcm, 0xFFFF);
9635 + bcm43xx_calc_nrssi_threshold(bcm);
9636 + } else if (phy->connected) {
9637 + if (radio->nrssi[0] == -1000) {
9638 + assert(radio->nrssi[1] == -1000);
9639 + bcm43xx_calc_nrssi_slope(bcm);
9641 + assert(radio->nrssi[1] != -1000);
9642 + bcm43xx_calc_nrssi_threshold(bcm);
9645 + if (radio->revision == 8)
9646 + bcm43xx_phy_write(bcm, 0x0805, 0x3230);
9647 + bcm43xx_phy_init_pctl(bcm);
9648 + if (bcm->chip_id == 0x4306 && bcm->chip_package != 2) {
9649 + bcm43xx_phy_write(bcm, 0x0429,
9650 + bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);
9651 + bcm43xx_phy_write(bcm, 0x04C3,
9652 + bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);
9656 +static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
9661 + for (i = 0; i < 10; i++){
9662 + bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
9664 + bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
9666 + bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
9668 + ret += bcm43xx_phy_read(bcm, 0x002C);
9674 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
9676 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9677 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9678 + u16 regstack[12] = { 0 };
9683 + regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
9684 + regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
9686 + if (radio->version == 0x2053) {
9687 + regstack[2] = bcm43xx_phy_read(bcm, 0x000A);
9688 + regstack[3] = bcm43xx_phy_read(bcm, 0x002A);
9689 + regstack[4] = bcm43xx_phy_read(bcm, 0x0035);
9690 + regstack[5] = bcm43xx_phy_read(bcm, 0x0003);
9691 + regstack[6] = bcm43xx_phy_read(bcm, 0x0001);
9692 + regstack[7] = bcm43xx_phy_read(bcm, 0x0030);
9694 + regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);
9695 + regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);
9696 + regstack[10] = bcm43xx_read16(bcm, 0x03EC);
9697 + regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;
9699 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
9700 + bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
9701 + bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);
9702 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);
9704 + bcm43xx_phy_write(bcm, 0x0015, 0xB000);
9705 + bcm43xx_phy_write(bcm, 0x002B, 0x0004);
9707 + if (radio->version == 0x2053) {
9708 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
9709 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
9712 + phy->minlowsig[0] = 0xFFFF;
9714 + for (i = 0; i < 4; i++) {
9715 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9716 + bcm43xx_phy_lo_b_r15_loop(bcm);
9718 + for (i = 0; i < 10; i++) {
9719 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9720 + mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
9721 + if (mls < phy->minlowsig[0]) {
9722 + phy->minlowsig[0] = mls;
9723 + phy->minlowsigpos[0] = i;
9726 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
9728 + phy->minlowsig[1] = 0xFFFF;
9730 + for (i = -4; i < 5; i += 2) {
9731 + for (j = -4; j < 5; j += 2) {
9733 + fval = (0x0100 * i) + j + 0x0100;
9735 + fval = (0x0100 * i) + j;
9736 + bcm43xx_phy_write(bcm, 0x002F, fval);
9737 + mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;
9738 + if (mls < phy->minlowsig[1]) {
9739 + phy->minlowsig[1] = mls;
9740 + phy->minlowsigpos[1] = fval;
9744 + phy->minlowsigpos[1] += 0x0101;
9746 + bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);
9747 + if (radio->version == 0x2053) {
9748 + bcm43xx_phy_write(bcm, 0x000A, regstack[2]);
9749 + bcm43xx_phy_write(bcm, 0x002A, regstack[3]);
9750 + bcm43xx_phy_write(bcm, 0x0035, regstack[4]);
9751 + bcm43xx_phy_write(bcm, 0x0003, regstack[5]);
9752 + bcm43xx_phy_write(bcm, 0x0001, regstack[6]);
9753 + bcm43xx_phy_write(bcm, 0x0030, regstack[7]);
9755 + bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
9756 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
9758 + bcm43xx_radio_write16(bcm, 0x0052,
9759 + (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
9762 + bcm43xx_write16(bcm, 0x03EC, regstack[10]);
9764 + bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
9768 +u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
9770 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9772 + if (phy->connected) {
9773 + bcm43xx_phy_write(bcm, 0x15, 0xE300);
9775 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
9777 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
9779 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
9781 + bcm43xx_phy_write(bcm, 0x0015, 0xF300);
9784 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
9786 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
9788 + bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
9792 + return bcm43xx_phy_read(bcm, 0x002D);
9795 +static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
9800 + for (i = 0; i < 8; i++)
9801 + ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
9806 +/* Write the LocalOscillator CONTROL */
9808 +void bcm43xx_lo_write(struct bcm43xx_private *bcm,
9809 + struct bcm43xx_lopair *pair)
9813 + value = (u8)(pair->low);
9814 + value |= ((u8)(pair->high)) << 8;
9816 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
9817 + /* Sanity check. */
9818 + if (pair->low < -8 || pair->low > 8 ||
9819 + pair->high < -8 || pair->high > 8) {
9820 + printk(KERN_WARNING PFX
9821 + "WARNING: Writing invalid LOpair "
9822 + "(low: %d, high: %d, index: %lu)\n",
9823 + pair->low, pair->high,
9824 + (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));
9829 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
9833 +struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
9834 + u16 baseband_attenuation,
9835 + u16 radio_attenuation,
9838 + static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };
9839 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9841 + if (baseband_attenuation > 6)
9842 + baseband_attenuation = 6;
9843 + assert(radio_attenuation < 10);
9846 + return bcm43xx_get_lopair(phy,
9847 + radio_attenuation,
9848 + baseband_attenuation);
9850 + return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
9854 +struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
9856 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9858 + return bcm43xx_find_lopair(bcm,
9859 + radio->baseband_atten,
9860 + radio->radio_atten,
9864 +/* Adjust B/G LO */
9865 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
9867 + struct bcm43xx_lopair *pair;
9870 + /* Use fixed values. Only for initialization. */
9871 + pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
9873 + pair = bcm43xx_current_lopair(bcm);
9874 + bcm43xx_lo_write(bcm, pair);
9877 +static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
9879 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9880 + u16 txctl2 = 0, i;
9881 + u32 smallest, tmp;
9883 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9885 + smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9886 + for (i = 0; i < 16; i++) {
9887 + bcm43xx_radio_write16(bcm, 0x0052, i);
9889 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9890 + if (tmp < smallest) {
9895 + radio->txctl2 = txctl2;
9899 +void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
9900 + const struct bcm43xx_lopair *in_pair,
9901 + struct bcm43xx_lopair *out_pair,
9904 + static const struct bcm43xx_lopair transitions[8] = {
9905 + { .high = 1, .low = 1, },
9906 + { .high = 1, .low = 0, },
9907 + { .high = 1, .low = -1, },
9908 + { .high = 0, .low = -1, },
9909 + { .high = -1, .low = -1, },
9910 + { .high = -1, .low = 0, },
9911 + { .high = -1, .low = 1, },
9912 + { .high = 0, .low = 1, },
9914 + struct bcm43xx_lopair lowest_transition = {
9915 + .high = in_pair->high,
9916 + .low = in_pair->low,
9918 + struct bcm43xx_lopair tmp_pair;
9919 + struct bcm43xx_lopair transition;
9923 + int j, begin, end;
9924 + u32 lowest_deviation;
9927 + /* Note that in_pair and out_pair can point to the same pair. Be careful. */
9929 + bcm43xx_lo_write(bcm, &lowest_transition);
9930 + lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9933 + assert(state >= 0 && state <= 8);
9937 + } else if (state % 2 == 0) {
9938 + begin = state - 1;
9941 + begin = state - 2;
9950 + tmp_pair.high = lowest_transition.high;
9951 + tmp_pair.low = lowest_transition.low;
9953 + assert(j >= 1 && j <= 8);
9954 + transition.high = tmp_pair.high + transitions[j - 1].high;
9955 + transition.low = tmp_pair.low + transitions[j - 1].low;
9956 + if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {
9957 + bcm43xx_lo_write(bcm, &transition);
9958 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9959 + if (tmp < lowest_deviation) {
9960 + lowest_deviation = tmp;
9964 + lowest_transition.high = transition.high;
9965 + lowest_transition.low = transition.low;
9975 + } while (i-- && found_lower);
9977 + out_pair->high = lowest_transition.high;
9978 + out_pair->low = lowest_transition.low;
9981 +/* Set the baseband attenuation value on chip. */
9982 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
9983 + u16 baseband_attenuation)
9985 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9988 + if (phy->version == 0) {
9989 + value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
9990 + value |= (baseband_attenuation & 0x000F);
9991 + bcm43xx_write16(bcm, 0x03E6, value);
9995 + if (phy->version > 1) {
9996 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
9997 + value |= (baseband_attenuation << 2) & 0x003C;
9999 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
10000 + value |= (baseband_attenuation << 3) & 0x0078;
10002 + bcm43xx_phy_write(bcm, 0x0060, value);
10005 +/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
10006 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
10008 + static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };
10009 + const int is_initializing = bcm43xx_is_initializing(bcm);
10010 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10011 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10012 + u16 h, i, oldi = 0, j;
10013 + struct bcm43xx_lopair control;
10014 + struct bcm43xx_lopair *tmp_control;
10016 + u16 regstack[16] = { 0 };
10019 + //XXX: What are these?
10022 + oldchannel = radio->channel;
10024 + if (phy->connected) {
10025 + regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
10026 + regstack[1] = bcm43xx_phy_read(bcm, 0x0802);
10027 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
10028 + bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
10030 + regstack[3] = bcm43xx_read16(bcm, 0x03E2);
10031 + bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);
10032 + regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
10033 + regstack[5] = bcm43xx_phy_read(bcm, 0x15);
10034 + regstack[6] = bcm43xx_phy_read(bcm, 0x2A);
10035 + regstack[7] = bcm43xx_phy_read(bcm, 0x35);
10036 + regstack[8] = bcm43xx_phy_read(bcm, 0x60);
10037 + regstack[9] = bcm43xx_radio_read16(bcm, 0x43);
10038 + regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);
10039 + regstack[11] = bcm43xx_radio_read16(bcm, 0x52);
10040 + if (phy->connected) {
10041 + regstack[12] = bcm43xx_phy_read(bcm, 0x0811);
10042 + regstack[13] = bcm43xx_phy_read(bcm, 0x0812);
10043 + regstack[14] = bcm43xx_phy_read(bcm, 0x0814);
10044 + regstack[15] = bcm43xx_phy_read(bcm, 0x0815);
10046 + bcm43xx_radio_selectchannel(bcm, 6, 0);
10047 + if (phy->connected) {
10048 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);
10049 + bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);
10050 + bcm43xx_dummy_transmission(bcm);
10052 + bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
10054 + bcm43xx_phy_set_baseband_attenuation(bcm, 2);
10056 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);
10057 + bcm43xx_phy_write(bcm, 0x002E, 0x007F);
10058 + bcm43xx_phy_write(bcm, 0x080F, 0x0078);
10059 + bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));
10060 + bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);
10061 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
10062 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
10063 + if (phy->connected) {
10064 + bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);
10065 + bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);
10066 + bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
10067 + bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
10069 + if (is_initializing)
10070 + bcm43xx_phy_lo_g_measure_txctl2(bcm);
10071 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
10075 + control.high = 0;
10076 + for (h = 0; h < 10; h++) {
10077 + /* Loop over each possible RadioAttenuation (0-9) */
10078 + i = pairorder[h];
10079 + if (is_initializing) {
10082 + control.high = 0;
10083 + } else if (((i % 2 == 1) && (oldi % 2 == 1)) ||
10084 + ((i % 2 == 0) && (oldi % 2 == 0))) {
10085 + tmp_control = bcm43xx_get_lopair(phy, oldi, 0);
10086 + memcpy(&control, tmp_control, sizeof(control));
10088 + tmp_control = bcm43xx_get_lopair(phy, 3, 0);
10089 + memcpy(&control, tmp_control, sizeof(control));
10092 + /* Loop over each possible BasebandAttenuation/2 */
10093 + for (j = 0; j < 4; j++) {
10094 + if (is_initializing) {
10106 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10107 + if (!tmp_control->used)
10109 + memcpy(&control, tmp_control, sizeof(control));
10113 + bcm43xx_radio_write16(bcm, 0x43, i);
10114 + bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
10117 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10119 + tmp = (regstack[10] & 0xFFF0);
10122 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
10124 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10125 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10129 + /* Loop over each possible RadioAttenuation (10-13) */
10130 + for (i = 10; i < 14; i++) {
10131 + /* Loop over each possible BasebandAttenuation/2 */
10132 + for (j = 0; j < 4; j++) {
10133 + if (is_initializing) {
10134 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10135 + memcpy(&control, tmp_control, sizeof(control));
10136 + tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.
10147 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10148 + if (!tmp_control->used)
10150 + memcpy(&control, tmp_control, sizeof(control));
10154 + bcm43xx_radio_write16(bcm, 0x43, i - 9);
10155 + bcm43xx_radio_write16(bcm, 0x52,
10157 + | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
10160 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10162 + tmp = (regstack[10] & 0xFFF0);
10165 + bcm43xx_radio_write16(bcm, 0x7A, tmp);
10167 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10168 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10172 + /* Restoration */
10173 + if (phy->connected) {
10174 + bcm43xx_phy_write(bcm, 0x0015, 0xE300);
10175 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
10177 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
10179 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
10181 + bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);
10182 + bcm43xx_phy_lo_adjust(bcm, is_initializing);
10183 + bcm43xx_phy_write(bcm, 0x002E, 0x807F);
10184 + if (phy->connected)
10185 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
10187 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
10188 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);
10189 + bcm43xx_phy_write(bcm, 0x0015, regstack[5]);
10190 + bcm43xx_phy_write(bcm, 0x002A, regstack[6]);
10191 + bcm43xx_phy_write(bcm, 0x0035, regstack[7]);
10192 + bcm43xx_phy_write(bcm, 0x0060, regstack[8]);
10193 + bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);
10194 + bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);
10195 + regstack[11] &= 0x00F0;
10196 + regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);
10197 + bcm43xx_radio_write16(bcm, 0x52, regstack[11]);
10198 + bcm43xx_write16(bcm, 0x03E2, regstack[3]);
10199 + if (phy->connected) {
10200 + bcm43xx_phy_write(bcm, 0x0811, regstack[12]);
10201 + bcm43xx_phy_write(bcm, 0x0812, regstack[13]);
10202 + bcm43xx_phy_write(bcm, 0x0814, regstack[14]);
10203 + bcm43xx_phy_write(bcm, 0x0815, regstack[15]);
10204 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);
10205 + bcm43xx_phy_write(bcm, 0x0802, regstack[1]);
10207 + bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
10209 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
10211 + /* Sanity check for all lopairs. */
10212 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10213 + tmp_control = phy->_lo_pairs + i;
10214 + if (tmp_control->low < -8 || tmp_control->low > 8 ||
10215 + tmp_control->high < -8 || tmp_control->high > 8) {
10216 + printk(KERN_WARNING PFX
10217 + "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",
10218 + tmp_control->low, tmp_control->high, i);
10222 +#endif /* CONFIG_BCM43XX_D80211_DEBUG */
10226 +void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
10228 + struct bcm43xx_lopair *pair;
10230 + pair = bcm43xx_current_lopair(bcm);
10234 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
10236 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10237 + struct bcm43xx_lopair *pair;
10240 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10241 + pair = phy->_lo_pairs + i;
10246 +/* http://bcm-specs.sipsolutions.net/EstimatePowerOut
10247 + * This function converts a TSSI value to dBm in Q5.2
10249 +static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
10251 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10255 + tmp = phy->idle_tssi;
10257 + tmp -= phy->savedpctlreg;
10259 + switch (phy->type) {
10260 + case BCM43xx_PHYTYPE_A:
10262 + tmp = limit_value(tmp, 0x00, 0xFF);
10263 + dbm = phy->tssi2dbm[tmp];
10264 + TODO(); //TODO: There's a FIXME on the specs
10266 + case BCM43xx_PHYTYPE_B:
10267 + case BCM43xx_PHYTYPE_G:
10268 + tmp = limit_value(tmp, 0x00, 0x3F);
10269 + dbm = phy->tssi2dbm[tmp];
10278 +/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
10279 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
10281 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10282 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10284 + if (phy->savedpctlreg == 0xFFFF)
10286 + if ((bcm->board_type == 0x0416) &&
10287 + (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
10290 + switch (phy->type) {
10291 + case BCM43xx_PHYTYPE_A: {
10293 + TODO(); //TODO: Nothing for A PHYs yet :-/
10297 + case BCM43xx_PHYTYPE_B:
10298 + case BCM43xx_PHYTYPE_G: {
10301 + s8 v0, v1, v2, v3;
10304 + s16 desired_pwr, estimated_pwr, pwr_adjust;
10305 + s16 radio_att_delta, baseband_att_delta;
10306 + s16 radio_attenuation, baseband_attenuation;
10307 + unsigned long phylock_flags;
10309 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0058);
10310 + v0 = (s8)(tmp & 0x00FF);
10311 + v1 = (s8)((tmp & 0xFF00) >> 8);
10312 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005A);
10313 + v2 = (s8)(tmp & 0x00FF);
10314 + v3 = (s8)((tmp & 0xFF00) >> 8);
10317 + if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F) {
10318 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0070);
10319 + v0 = (s8)(tmp & 0x00FF);
10320 + v1 = (s8)((tmp & 0xFF00) >> 8);
10321 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0072);
10322 + v2 = (s8)(tmp & 0x00FF);
10323 + v3 = (s8)((tmp & 0xFF00) >> 8);
10324 + if (v0 == 0x7F || v1 == 0x7F || v2 == 0x7F || v3 == 0x7F)
10326 + v0 = (v0 + 0x20) & 0x3F;
10327 + v1 = (v1 + 0x20) & 0x3F;
10328 + v2 = (v2 + 0x20) & 0x3F;
10329 + v3 = (v3 + 0x20) & 0x3F;
10332 + bcm43xx_radio_clear_tssi(bcm);
10334 + average = (v0 + v1 + v2 + v3 + 2) / 4;
10336 + if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
10339 + estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
10341 + max_pwr = bcm->sprom.maxpower_bgphy;
10343 + if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
10344 + (phy->type == BCM43xx_PHYTYPE_G))
10348 + max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
10349 + where REG is the max power as per the regulatory domain
10352 + desired_pwr = radio->power_level;
10353 + /* Convert the desired_pwr to Q5.2 and limit it. */
10354 + desired_pwr = limit_value((desired_pwr << 2), 0, max_pwr);
10356 + pwr_adjust = desired_pwr - estimated_pwr;
10357 + radio_att_delta = -(pwr_adjust + 7) >> 3;
10358 + baseband_att_delta = -(pwr_adjust >> 1) - (4 * radio_att_delta);
10359 + if ((radio_att_delta == 0) && (baseband_att_delta == 0)) {
10360 + bcm43xx_phy_lo_mark_current_used(bcm);
10364 + /* Calculate the new attenuation values. */
10365 + baseband_attenuation = radio->baseband_atten;
10366 + baseband_attenuation += baseband_att_delta;
10367 + radio_attenuation = radio->radio_atten;
10368 + radio_attenuation += radio_att_delta;
10370 + /* Get baseband and radio attenuation values into their permitted ranges.
10371 + * baseband 0-11, radio 0-9.
10372 + * Radio attenuation affects power level 4 times as much as baseband.
10374 + if (radio_attenuation < 0) {
10375 + baseband_attenuation -= (4 * -radio_attenuation);
10376 + radio_attenuation = 0;
10377 + } else if (radio_attenuation > 9) {
10378 + baseband_attenuation += (4 * (radio_attenuation - 9));
10379 + radio_attenuation = 9;
10381 + while (baseband_attenuation < 0 && radio_attenuation > 0) {
10382 + baseband_attenuation += 4;
10383 + radio_attenuation--;
10385 + while (baseband_attenuation > 11 && radio_attenuation < 9) {
10386 + baseband_attenuation -= 4;
10387 + radio_attenuation++;
10390 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10392 + txpower = radio->txctl1;
10393 + if ((radio->version == 0x2050) && (radio->revision == 2)) {
10394 + if (radio_attenuation <= 1) {
10395 + if (txpower == 0) {
10397 + radio_attenuation += 2;
10398 + baseband_attenuation += 2;
10399 + } else if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
10400 + baseband_attenuation += 4 * (radio_attenuation - 2);
10401 + radio_attenuation = 2;
10403 + } else if (radio_attenuation > 4 && txpower != 0) {
10405 + if (baseband_attenuation < 3) {
10406 + radio_attenuation -= 3;
10407 + baseband_attenuation += 2;
10409 + radio_attenuation -= 2;
10410 + baseband_attenuation -= 2;
10414 + radio->txctl1 = txpower;
10415 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10416 + radio_attenuation = limit_value(radio_attenuation, 0, 9);
10418 + bcm43xx_phy_lock(bcm, phylock_flags);
10419 + bcm43xx_radio_lock(bcm);
10420 + bcm43xx_radio_set_txpower_bg(bcm, baseband_attenuation,
10421 + radio_attenuation, txpower);
10422 + bcm43xx_phy_lo_mark_current_used(bcm);
10423 + bcm43xx_radio_unlock(bcm);
10424 + bcm43xx_phy_unlock(bcm, phylock_flags);
10433 +s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
10438 + return (num+den/2)/den;
10442 +s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
10444 + s32 m1, m2, f = 256, q, delta;
10447 + m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
10448 + m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
10452 + q = bcm43xx_tssi2dbm_ad(f * 4096 -
10453 + bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
10454 + delta = abs(q - f);
10457 + } while (delta >= 2);
10458 + entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
10462 +/* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
10463 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
10465 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10466 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10467 + s16 pab0, pab1, pab2;
10469 + s8 *dyn_tssi2dbm;
10471 + if (phy->type == BCM43xx_PHYTYPE_A) {
10472 + pab0 = (s16)(bcm->sprom.pa1b0);
10473 + pab1 = (s16)(bcm->sprom.pa1b1);
10474 + pab2 = (s16)(bcm->sprom.pa1b2);
10476 + pab0 = (s16)(bcm->sprom.pa0b0);
10477 + pab1 = (s16)(bcm->sprom.pa0b1);
10478 + pab2 = (s16)(bcm->sprom.pa0b2);
10481 + if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
10482 + phy->idle_tssi = 0x34;
10483 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10487 + if (pab0 != 0 && pab1 != 0 && pab2 != 0 &&
10488 + pab0 != -1 && pab1 != -1 && pab2 != -1) {
10489 + /* The pabX values are set in SPROM. Use them. */
10490 + if (phy->type == BCM43xx_PHYTYPE_A) {
10491 + if ((s8)bcm->sprom.idle_tssi_tgt_aphy != 0 &&
10492 + (s8)bcm->sprom.idle_tssi_tgt_aphy != -1)
10493 + phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_aphy);
10495 + phy->idle_tssi = 62;
10497 + if ((s8)bcm->sprom.idle_tssi_tgt_bgphy != 0 &&
10498 + (s8)bcm->sprom.idle_tssi_tgt_bgphy != -1)
10499 + phy->idle_tssi = (s8)(bcm->sprom.idle_tssi_tgt_bgphy);
10501 + phy->idle_tssi = 62;
10503 + dyn_tssi2dbm = kmalloc(64, GFP_KERNEL);
10504 + if (dyn_tssi2dbm == NULL) {
10505 + printk(KERN_ERR PFX "Could not allocate memory"
10506 + "for tssi2dbm table\n");
10509 + for (idx = 0; idx < 64; idx++)
10510 + if (bcm43xx_tssi2dbm_entry(dyn_tssi2dbm, idx, pab0, pab1, pab2)) {
10511 + phy->tssi2dbm = NULL;
10512 + printk(KERN_ERR PFX "Could not generate "
10513 + "tssi2dBm table\n");
10516 + phy->tssi2dbm = dyn_tssi2dbm;
10517 + phy->dyn_tssi_tbl = 1;
10519 + /* pabX values not set in SPROM. */
10520 + switch (phy->type) {
10521 + case BCM43xx_PHYTYPE_A:
10522 + /* APHY needs a generated table. */
10523 + phy->tssi2dbm = NULL;
10524 + printk(KERN_ERR PFX "Could not generate tssi2dBm "
10525 + "table (wrong SPROM info)!\n");
10527 + case BCM43xx_PHYTYPE_B:
10528 + phy->idle_tssi = 0x34;
10529 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10531 + case BCM43xx_PHYTYPE_G:
10532 + phy->idle_tssi = 0x34;
10533 + phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
10541 +int bcm43xx_phy_init(struct bcm43xx_private *bcm)
10543 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10544 + int err = -ENODEV;
10545 + unsigned long flags;
10547 + /* We do not want to be preempted while calibrating
10550 + local_irq_save(flags);
10552 + switch (phy->type) {
10553 + case BCM43xx_PHYTYPE_A:
10554 + if (phy->rev == 2 || phy->rev == 3) {
10555 + bcm43xx_phy_inita(bcm);
10559 + case BCM43xx_PHYTYPE_B:
10560 + switch (phy->rev) {
10562 + bcm43xx_phy_initb2(bcm);
10566 + bcm43xx_phy_initb4(bcm);
10570 + bcm43xx_phy_initb5(bcm);
10574 + bcm43xx_phy_initb6(bcm);
10579 + case BCM43xx_PHYTYPE_G:
10580 + bcm43xx_phy_initg(bcm);
10584 + local_irq_restore(flags);
10586 + printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
10591 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
10593 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10599 + antennadiv = phy->antenna_diversity;
10601 + if (antennadiv == 0xFFFF)
10603 + assert(antennadiv <= 3);
10605 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
10606 + BCM43xx_UCODEFLAGS_OFFSET);
10607 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
10608 + BCM43xx_UCODEFLAGS_OFFSET,
10609 + ucodeflags & ~BCM43xx_UCODEFLAG_AUTODIV);
10611 + switch (phy->type) {
10612 + case BCM43xx_PHYTYPE_A:
10613 + case BCM43xx_PHYTYPE_G:
10614 + if (phy->type == BCM43xx_PHYTYPE_A)
10619 + if (antennadiv == 2)
10620 + value = (3/*automatic*/ << 7);
10622 + value = (antennadiv << 7);
10623 + bcm43xx_phy_write(bcm, offset + 1,
10624 + (bcm43xx_phy_read(bcm, offset + 1)
10625 + & 0x7E7F) | value);
10627 + if (antennadiv >= 2) {
10628 + if (antennadiv == 2)
10629 + value = (antennadiv << 7);
10631 + value = (0/*force0*/ << 7);
10632 + bcm43xx_phy_write(bcm, offset + 0x2B,
10633 + (bcm43xx_phy_read(bcm, offset + 0x2B)
10634 + & 0xFEFF) | value);
10637 + if (phy->type == BCM43xx_PHYTYPE_G) {
10638 + if (antennadiv >= 2)
10639 + bcm43xx_phy_write(bcm, 0x048C,
10640 + bcm43xx_phy_read(bcm, 0x048C)
10643 + bcm43xx_phy_write(bcm, 0x048C,
10644 + bcm43xx_phy_read(bcm, 0x048C)
10646 + if (phy->rev >= 2) {
10647 + bcm43xx_phy_write(bcm, 0x0461,
10648 + bcm43xx_phy_read(bcm, 0x0461)
10650 + bcm43xx_phy_write(bcm, 0x04AD,
10651 + (bcm43xx_phy_read(bcm, 0x04AD)
10652 + & 0x00FF) | 0x0015);
10653 + if (phy->rev == 2)
10654 + bcm43xx_phy_write(bcm, 0x0427, 0x0008);
10656 + bcm43xx_phy_write(bcm, 0x0427,
10657 + (bcm43xx_phy_read(bcm, 0x0427)
10658 + & 0x00FF) | 0x0008);
10660 + else if (phy->rev >= 6)
10661 + bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
10663 + if (phy->rev < 3)
10664 + bcm43xx_phy_write(bcm, 0x002B,
10665 + (bcm43xx_phy_read(bcm, 0x002B)
10666 + & 0x00FF) | 0x0024);
10668 + bcm43xx_phy_write(bcm, 0x0061,
10669 + bcm43xx_phy_read(bcm, 0x0061)
10671 + if (phy->rev == 3) {
10672 + bcm43xx_phy_write(bcm, 0x0093, 0x001D);
10673 + bcm43xx_phy_write(bcm, 0x0027, 0x0008);
10675 + bcm43xx_phy_write(bcm, 0x0093, 0x003A);
10676 + bcm43xx_phy_write(bcm, 0x0027,
10677 + (bcm43xx_phy_read(bcm, 0x0027)
10678 + & 0x00FF) | 0x0008);
10683 + case BCM43xx_PHYTYPE_B:
10684 + if (bcm->current_core->rev == 2)
10685 + value = (3/*automatic*/ << 7);
10687 + value = (antennadiv << 7);
10688 + bcm43xx_phy_write(bcm, 0x03E2,
10689 + (bcm43xx_phy_read(bcm, 0x03E2)
10690 + & 0xFE7F) | value);
10696 + if (antennadiv >= 2) {
10697 + ucodeflags = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
10698 + BCM43xx_UCODEFLAGS_OFFSET);
10699 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
10700 + BCM43xx_UCODEFLAGS_OFFSET,
10701 + ucodeflags | BCM43xx_UCODEFLAG_AUTODIV);
10704 + phy->antenna_diversity = antennadiv;
10706 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
10707 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h 1970-01-01 01:00:00.000000000 +0100
10708 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_phy.h 2006-03-28 22:16:14.000000000 +0200
10712 + Broadcom BCM43xx wireless driver
10714 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
10715 + Stefano Brivio <st3@riseup.net>
10716 + Michael Buesch <mbuesch@freenet.de>
10717 + Danny van Dyk <kugelfang@gentoo.org>
10718 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
10720 + Some parts of the code in this file are derived from the ipw2200
10721 + driver Copyright(c) 2003 - 2004 Intel Corporation.
10723 + This program is free software; you can redistribute it and/or modify
10724 + it under the terms of the GNU General Public License as published by
10725 + the Free Software Foundation; either version 2 of the License, or
10726 + (at your option) any later version.
10728 + This program is distributed in the hope that it will be useful,
10729 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10730 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10731 + GNU General Public License for more details.
10733 + You should have received a copy of the GNU General Public License
10734 + along with this program; see the file COPYING. If not, write to
10735 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
10736 + Boston, MA 02110-1301, USA.
10740 +#ifndef BCM43xx_PHY_H_
10741 +#define BCM43xx_PHY_H_
10743 +#include <linux/types.h>
10745 +struct bcm43xx_private;
10747 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm);
10748 +#define bcm43xx_phy_lock(bcm, flags) \
10750 + local_irq_save(flags); \
10751 + bcm43xx_raw_phy_lock(bcm); \
10753 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm);
10754 +#define bcm43xx_phy_unlock(bcm, flags) \
10756 + bcm43xx_raw_phy_unlock(bcm); \
10757 + local_irq_restore(flags); \
10760 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset);
10761 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
10763 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm);
10764 +int bcm43xx_phy_init(struct bcm43xx_private *bcm);
10766 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm);
10767 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm);
10768 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect);
10770 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm);
10771 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm);
10772 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm);
10774 +/* Adjust the LocalOscillator to the saved values.
10775 + * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
10777 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed);
10778 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm);
10780 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
10781 + u16 baseband_attenuation);
10783 +#endif /* BCM43xx_PHY_H_ */
10784 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
10785 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c 1970-01-01 01:00:00.000000000 +0100
10786 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.c 2006-03-28 22:16:14.000000000 +0200
10790 + Broadcom BCM43xx wireless driver
10794 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
10796 + This program is free software; you can redistribute it and/or modify
10797 + it under the terms of the GNU General Public License as published by
10798 + the Free Software Foundation; either version 2 of the License, or
10799 + (at your option) any later version.
10801 + This program is distributed in the hope that it will be useful,
10802 + but WITHOUT ANY WARRANTY; without even the implied warranty of
10803 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10804 + GNU General Public License for more details.
10806 + You should have received a copy of the GNU General Public License
10807 + along with this program; see the file COPYING. If not, write to
10808 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
10809 + Boston, MA 02110-1301, USA.
10813 +#include "bcm43xx.h"
10814 +#include "bcm43xx_pio.h"
10815 +#include "bcm43xx_main.h"
10816 +#include "bcm43xx_xmit.h"
10818 +#include <linux/delay.h>
10821 +static void tx_start(struct bcm43xx_pioqueue *queue)
10823 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10824 + BCM43xx_PIO_TXCTL_INIT);
10827 +static void tx_octet(struct bcm43xx_pioqueue *queue,
10830 + if (queue->need_workarounds) {
10831 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10833 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10834 + BCM43xx_PIO_TXCTL_WRITEHI);
10836 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10837 + BCM43xx_PIO_TXCTL_WRITEHI);
10838 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10843 +static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr,
10844 + const u8 *packet,
10845 + unsigned int *pos)
10847 + const u8 *source;
10848 + unsigned int i = *pos;
10851 + if (i < sizeof(*txhdr)) {
10852 + source = (const u8 *)txhdr;
10855 + i -= sizeof(*txhdr);
10857 + ret = le16_to_cpu( *((u16 *)(source + i)) );
10863 +static void tx_data(struct bcm43xx_pioqueue *queue,
10864 + struct bcm43xx_txhdr *txhdr,
10865 + const u8 *packet,
10866 + unsigned int octets)
10869 + unsigned int i = 0;
10871 + if (queue->need_workarounds) {
10872 + data = tx_get_next_word(txhdr, packet, &i);
10873 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
10875 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10876 + BCM43xx_PIO_TXCTL_WRITELO |
10877 + BCM43xx_PIO_TXCTL_WRITEHI);
10878 + while (i < octets - 1) {
10879 + data = tx_get_next_word(txhdr, packet, &i);
10880 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
10883 + tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]);
10886 +static void tx_complete(struct bcm43xx_pioqueue *queue,
10887 + struct sk_buff *skb)
10889 + if (queue->need_workarounds) {
10890 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10891 + skb->data[skb->len - 1]);
10892 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10893 + BCM43xx_PIO_TXCTL_WRITEHI |
10894 + BCM43xx_PIO_TXCTL_COMPLETE);
10896 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10897 + BCM43xx_PIO_TXCTL_COMPLETE);
10901 +static u16 generate_cookie(struct bcm43xx_pioqueue *queue,
10904 + u16 cookie = 0x0000;
10906 + /* We use the upper 4 bits for the PIO
10907 + * controller ID and the lower 12 bits
10908 + * for the packet index (in the cache).
10910 + switch (queue->mmio_base) {
10911 + case BCM43xx_MMIO_PIO1_BASE:
10913 + case BCM43xx_MMIO_PIO2_BASE:
10916 + case BCM43xx_MMIO_PIO3_BASE:
10919 + case BCM43xx_MMIO_PIO4_BASE:
10925 + assert(((u16)packetindex & 0xF000) == 0x0000);
10926 + cookie |= (u16)packetindex;
10932 +struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm,
10934 + struct bcm43xx_pio_txpacket **packet)
10936 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
10937 + struct bcm43xx_pioqueue *queue = NULL;
10940 + switch (cookie & 0xF000) {
10942 + queue = pio->queue0;
10945 + queue = pio->queue1;
10948 + queue = pio->queue2;
10951 + queue = pio->queue3;
10956 + packetindex = (cookie & 0x0FFF);
10957 + assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS);
10958 + *packet = &(queue->tx_packets_cache[packetindex]);
10963 +static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue,
10964 + struct sk_buff *skb,
10965 + struct bcm43xx_pio_txpacket *packet)
10967 + struct bcm43xx_txhdr txhdr;
10968 + unsigned int octets;
10970 + assert(skb_shinfo(skb)->nr_frags == 0);
10971 + bcm43xx_generate_txhdr(queue->bcm,
10972 + &txhdr, skb->data, skb->len,
10974 + generate_cookie(queue, pio_txpacket_getindex(packet)),
10978 + octets = skb->len + sizeof(txhdr);
10979 + if (queue->need_workarounds)
10981 + tx_data(queue, &txhdr, (u8 *)skb->data, octets);
10982 + tx_complete(queue, skb);
10985 +static void free_txpacket(struct bcm43xx_pio_txpacket *packet,
10988 + struct bcm43xx_pioqueue *queue = packet->queue;
10991 + dev_kfree_skb_irq(packet->skb);
10993 + dev_kfree_skb(packet->skb);
10994 + list_move(&packet->list, &queue->txfree);
10995 + queue->nr_txfree++;
10998 +static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet)
11000 + struct bcm43xx_pioqueue *queue = packet->queue;
11001 + struct sk_buff *skb = packet->skb;
11004 + octets = (u16)skb->len + sizeof(struct bcm43xx_txhdr);
11005 + if (queue->tx_devq_size < octets) {
11006 + dprintkl(KERN_WARNING PFX "PIO queue too small. "
11007 + "Dropping packet.\n");
11008 + /* Drop it silently (return success) */
11009 + free_txpacket(packet, 1);
11012 + assert(queue->tx_devq_packets <= BCM43xx_PIO_MAXTXDEVQPACKETS);
11013 + assert(queue->tx_devq_used <= queue->tx_devq_size);
11014 + /* Check if there is sufficient free space on the device
11015 + * TX queue. If not, return and let the TX tasklet
11018 + if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS)
11020 + if (queue->tx_devq_used + octets > queue->tx_devq_size)
11022 + /* Now poke the device. */
11023 + pio_tx_write_fragment(queue, skb, packet);
11025 + /* Account for the packet size.
11026 + * (We must not overflow the device TX queue)
11028 + queue->tx_devq_packets++;
11029 + queue->tx_devq_used += octets;
11031 + /* Transmission started, everything ok, move the
11032 + * packet to the txrunning list.
11034 + list_move_tail(&packet->list, &queue->txrunning);
11039 +static void tx_tasklet(unsigned long d)
11041 + struct bcm43xx_pioqueue *queue = (struct bcm43xx_pioqueue *)d;
11042 + struct bcm43xx_private *bcm = queue->bcm;
11043 + unsigned long flags;
11044 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
11047 + bcm43xx_lock_mmio(bcm, flags);
11048 + list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list) {
11049 + /* Try to transmit the packet. This can fail, if
11050 + * the device queue is full. In case of failure, the
11051 + * packet is left in the txqueue.
11052 + * If transmission succeed, the packet is moved to txrunning.
11053 + * If it is impossible to transmit the packet, it
11056 + err = pio_tx_packet(packet);
11060 + bcm43xx_unlock_mmio(bcm, flags);
11063 +static void setup_txqueues(struct bcm43xx_pioqueue *queue)
11065 + struct bcm43xx_pio_txpacket *packet;
11068 + queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS;
11069 + for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) {
11070 + packet = &(queue->tx_packets_cache[i]);
11072 + packet->queue = queue;
11073 + INIT_LIST_HEAD(&packet->list);
11075 + list_add(&packet->list, &queue->txfree);
11080 +struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm,
11081 + u16 pio_mmio_base)
11083 + struct bcm43xx_pioqueue *queue;
11087 + queue = kzalloc(sizeof(*queue), GFP_KERNEL);
11091 + queue->bcm = bcm;
11092 + queue->mmio_base = pio_mmio_base;
11093 + queue->need_workarounds = (bcm->current_core->rev < 3);
11095 + INIT_LIST_HEAD(&queue->txfree);
11096 + INIT_LIST_HEAD(&queue->txqueue);
11097 + INIT_LIST_HEAD(&queue->txrunning);
11098 + tasklet_init(&queue->txtask, tx_tasklet,
11099 + (unsigned long)queue);
11101 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11102 + value |= BCM43xx_SBF_XFER_REG_BYTESWAP;
11103 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value);
11105 + qsize = bcm43xx_read16(bcm, queue->mmio_base + BCM43xx_PIO_TXQBUFSIZE);
11106 + if (qsize <= BCM43xx_PIO_TXQADJUST) {
11107 + printk(KERN_ERR PFX "PIO tx device-queue too small (%u)\n", qsize);
11108 + goto err_freequeue;
11110 + qsize -= BCM43xx_PIO_TXQADJUST;
11111 + queue->tx_devq_size = qsize;
11113 + setup_txqueues(queue);
11124 +static void cancel_transfers(struct bcm43xx_pioqueue *queue)
11126 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
11128 + ieee80211_netif_oper(queue->bcm->net_dev, NETIF_DETACH);
11129 + assert(queue->bcm->shutting_down);
11130 + tasklet_disable(&queue->txtask);
11132 + list_for_each_entry_safe(packet, tmp_packet, &queue->txrunning, list)
11133 + free_txpacket(packet, 0);
11134 + list_for_each_entry_safe(packet, tmp_packet, &queue->txqueue, list)
11135 + free_txpacket(packet, 0);
11138 +static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue)
11143 + cancel_transfers(queue);
11147 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11149 + struct bcm43xx_pio *pio;
11151 + if (!bcm43xx_using_pio(bcm))
11153 + pio = bcm43xx_current_pio(bcm);
11155 + bcm43xx_destroy_pioqueue(pio->queue3);
11156 + pio->queue3 = NULL;
11157 + bcm43xx_destroy_pioqueue(pio->queue2);
11158 + pio->queue2 = NULL;
11159 + bcm43xx_destroy_pioqueue(pio->queue1);
11160 + pio->queue1 = NULL;
11161 + bcm43xx_destroy_pioqueue(pio->queue0);
11162 + pio->queue0 = NULL;
11165 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11167 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11168 + struct bcm43xx_pioqueue *queue;
11169 + int err = -ENOMEM;
11171 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE);
11174 + pio->queue0 = queue;
11176 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE);
11178 + goto err_destroy0;
11179 + pio->queue1 = queue;
11181 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE);
11183 + goto err_destroy1;
11184 + pio->queue2 = queue;
11186 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE);
11188 + goto err_destroy2;
11189 + pio->queue3 = queue;
11191 + if (bcm->current_core->rev < 3)
11192 + bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND;
11194 + dprintk(KERN_INFO PFX "PIO initialized\n");
11200 + bcm43xx_destroy_pioqueue(pio->queue2);
11201 + pio->queue2 = NULL;
11203 + bcm43xx_destroy_pioqueue(pio->queue1);
11204 + pio->queue1 = NULL;
11206 + bcm43xx_destroy_pioqueue(pio->queue0);
11207 + pio->queue0 = NULL;
11211 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11212 + struct sk_buff *skb,
11213 + struct ieee80211_tx_control *ctl)
11215 + struct bcm43xx_pioqueue *queue = bcm43xx_current_pio(bcm)->queue1;
11216 + struct bcm43xx_pio_txpacket *packet;
11219 + assert(!queue->tx_suspended);
11220 + assert(!list_empty(&queue->txfree));
11222 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
11223 + if (tmp & BCM43xx_PIO_TXCTL_SUSPEND)
11226 + packet = list_entry(queue->txfree.next, struct bcm43xx_pio_txpacket, list);
11227 + packet->skb = skb;
11228 + packet->ctl = ctl;
11229 + list_move_tail(&packet->list, &queue->txqueue);
11230 + queue->nr_txfree--;
11231 + assert(queue->nr_txfree < BCM43xx_PIO_MAXTXPACKETS);
11233 + tasklet_schedule(&queue->txtask);
11238 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11239 + struct bcm43xx_xmitstatus *status)
11241 + struct bcm43xx_pioqueue *queue;
11242 + struct bcm43xx_pio_txpacket *packet;
11244 + queue = parse_cookie(bcm, status->cookie, &packet);
11249 + free_txpacket(packet, 1);
11250 + /* If there are packets on the txqueue, poke the tasklet. */
11251 + if (!list_empty(&queue->txqueue))
11252 + tasklet_schedule(&queue->txtask);
11255 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11256 + struct ieee80211_tx_queue_stats *stats)
11258 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11259 + struct bcm43xx_pioqueue *queue;
11260 + struct ieee80211_tx_queue_stats_data *data;
11262 + queue = pio->queue1;
11263 + data = &(stats->data[0]);
11264 + data->len = BCM43xx_PIO_MAXTXPACKETS - queue->nr_txfree;
11265 + data->limit = BCM43xx_PIO_MAXTXPACKETS;
11266 + data->count = queue->nr_tx_packets;
11269 +static void pio_rx_error(struct bcm43xx_pioqueue *queue,
11270 + int clear_buffers,
11271 + const char *error)
11275 + printkl("PIO RX error: %s\n", error);
11276 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11277 + BCM43xx_PIO_RXCTL_READY);
11278 + if (clear_buffers) {
11279 + assert(queue->mmio_base == BCM43xx_MMIO_PIO1_BASE);
11280 + for (i = 0; i < 15; i++) {
11281 + /* Dummy read. */
11282 + bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11287 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11289 + u16 preamble[21] = { 0 };
11290 + struct bcm43xx_rxhdr *rxhdr;
11291 + u16 tmp, len, rxflags2;
11292 + int i, preamble_readwords;
11293 + struct sk_buff *skb;
11296 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11297 + if (!(tmp & BCM43xx_PIO_RXCTL_DATAAVAILABLE)) {
11298 + dprintkl(KERN_ERR PFX "PIO RX: No data available\n");//TODO: remove this printk.
11301 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11302 + BCM43xx_PIO_RXCTL_DATAAVAILABLE);
11304 + for (i = 0; i < 10; i++) {
11305 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11306 + if (tmp & BCM43xx_PIO_RXCTL_READY)
11310 + dprintkl(KERN_ERR PFX "PIO RX timed out\n");
11314 +//FIXME: endianess in this function.
11315 + len = le16_to_cpu(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
11316 + if (unlikely(len > 0x700)) {
11317 + pio_rx_error(queue, 0, "len > 0x700");
11320 + if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) {
11321 + pio_rx_error(queue, 0, "len == 0");
11324 + preamble[0] = cpu_to_le16(len);
11325 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE)
11326 + preamble_readwords = 14 / sizeof(u16);
11328 + preamble_readwords = 18 / sizeof(u16);
11329 + for (i = 0; i < preamble_readwords; i++) {
11330 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11331 + preamble[i + 1] = cpu_to_be16(tmp);//FIXME?
11333 + rxhdr = (struct bcm43xx_rxhdr *)preamble;
11334 + rxflags2 = le16_to_cpu(rxhdr->flags2);
11335 + if (unlikely(rxflags2 & BCM43xx_RXHDR_FLAGS2_INVALIDFRAME)) {
11336 + pio_rx_error(queue,
11337 + (queue->mmio_base == BCM43xx_MMIO_PIO1_BASE),
11338 + "invalid frame");
11341 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE) {
11342 + /* We received an xmit status. */
11343 + struct bcm43xx_hwxmitstatus *hw;
11344 + struct bcm43xx_xmitstatus stat;
11346 + hw = (struct bcm43xx_hwxmitstatus *)(preamble + 1);
11347 + stat.cookie = le16_to_cpu(hw->cookie);
11348 + stat.flags = hw->flags;
11349 + stat.cnt1 = hw->cnt1;
11350 + stat.cnt2 = hw->cnt2;
11351 + stat.seq = le16_to_cpu(hw->seq);
11352 + stat.unknown = le16_to_cpu(hw->unknown);
11354 + bcm43xx_debugfs_log_txstat(queue->bcm, &stat);
11355 + bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat);
11360 + skb = dev_alloc_skb(len);
11361 + if (unlikely(!skb)) {
11362 + pio_rx_error(queue, 1, "OOM");
11365 + skb_put(skb, len);
11366 + for (i = 0; i < len - 1; i += 2) {
11367 + tmp = cpu_to_be16(bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA));
11368 + *((u16 *)(skb->data + i)) = tmp;
11371 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXDATA);
11372 + skb->data[len - 1] = (tmp & 0x00FF);
11373 + if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME)
11374 + skb->data[0x20] = (tmp & 0xFF00) >> 8;
11376 + skb->data[0x1E] = (tmp & 0xFF00) >> 8;
11378 + bcm43xx_rx(queue->bcm, skb, rxhdr);
11380 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
11381 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h 1970-01-01 01:00:00.000000000 +0100
11382 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_pio.h 2006-03-28 22:16:14.000000000 +0200
11384 +#ifndef BCM43xx_PIO_H_
11385 +#define BCM43xx_PIO_H_
11387 +#include "bcm43xx.h"
11389 +#include <linux/interrupt.h>
11390 +#include <linux/list.h>
11391 +#include <linux/skbuff.h>
11394 +#define BCM43xx_PIO_TXCTL 0x00
11395 +#define BCM43xx_PIO_TXDATA 0x02
11396 +#define BCM43xx_PIO_TXQBUFSIZE 0x04
11397 +#define BCM43xx_PIO_RXCTL 0x08
11398 +#define BCM43xx_PIO_RXDATA 0x0A
11400 +#define BCM43xx_PIO_TXCTL_WRITEHI (1 << 0)
11401 +#define BCM43xx_PIO_TXCTL_WRITELO (1 << 1)
11402 +#define BCM43xx_PIO_TXCTL_COMPLETE (1 << 2)
11403 +#define BCM43xx_PIO_TXCTL_INIT (1 << 3)
11404 +#define BCM43xx_PIO_TXCTL_SUSPEND (1 << 7)
11406 +#define BCM43xx_PIO_RXCTL_DATAAVAILABLE (1 << 0)
11407 +#define BCM43xx_PIO_RXCTL_READY (1 << 1)
11409 +/* PIO constants */
11410 +#define BCM43xx_PIO_MAXTXDEVQPACKETS 31
11411 +#define BCM43xx_PIO_TXQADJUST 80
11413 +/* PIO tuning knobs */
11414 +#define BCM43xx_PIO_MAXTXPACKETS 256
11418 +#ifdef CONFIG_BCM43XX_D80211_PIO
11421 +struct bcm43xx_pioqueue;
11422 +struct bcm43xx_xmitstatus;
11424 +struct bcm43xx_pio_txpacket {
11425 + struct bcm43xx_pioqueue *queue;
11426 + struct sk_buff *skb;
11427 + struct ieee80211_tx_control *ctl;
11428 + struct list_head list;
11431 +#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
11433 +struct bcm43xx_pioqueue {
11434 + struct bcm43xx_private *bcm;
11437 + u8 tx_suspended:1,
11438 + need_workarounds:1; /* Workarounds needed for core.rev < 3 */
11440 + /* Adjusted size of the device internal TX buffer. */
11441 + u16 tx_devq_size;
11442 + /* Used octets of the device internal TX buffer. */
11443 + u16 tx_devq_used;
11444 + /* Used packet slots in the device internal TX buffer. */
11445 + u8 tx_devq_packets;
11446 + /* Packets from the txfree list can
11447 + * be taken on incoming TX requests.
11449 + struct list_head txfree;
11450 + unsigned int nr_txfree;
11451 + /* Packets on the txqueue are queued,
11452 + * but not completely written to the chip, yet.
11454 + struct list_head txqueue;
11455 + /* Packets on the txrunning queue are completely
11456 + * posted to the device. We are waiting for the txstatus.
11458 + struct list_head txrunning;
11459 + /* Total number or packets sent.
11460 + * (This counter can obviously wrap).
11462 + unsigned int nr_tx_packets;
11463 + struct tasklet_struct txtask;
11464 + struct bcm43xx_pio_txpacket tx_packets_cache[BCM43xx_PIO_MAXTXPACKETS];
11468 +u16 bcm43xx_pio_read(struct bcm43xx_pioqueue *queue,
11471 + return bcm43xx_read16(queue->bcm, queue->mmio_base + offset);
11475 +void bcm43xx_pio_write(struct bcm43xx_pioqueue *queue,
11476 + u16 offset, u16 value)
11478 + bcm43xx_write16(queue->bcm, queue->mmio_base + offset, value);
11482 +int bcm43xx_pio_init(struct bcm43xx_private *bcm);
11483 +void bcm43xx_pio_free(struct bcm43xx_private *bcm);
11485 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11486 + struct sk_buff *skb,
11487 + struct ieee80211_tx_control *ctl);
11488 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11489 + struct bcm43xx_xmitstatus *status);
11490 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11491 + struct ieee80211_tx_queue_stats *stats);
11493 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue);
11495 +#else /* CONFIG_BCM43XX_D80211_PIO */
11498 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11503 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11507 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11508 + struct sk_buff *skb,
11509 + struct ieee80211_tx_control *ctl)
11514 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11515 + struct bcm43xx_xmitstatus *status)
11519 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11520 + struct ieee80211_tx_queue_stats *stats)
11524 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11528 +#endif /* CONFIG_BCM43XX_D80211_PIO */
11529 +#endif /* BCM43xx_PIO_H_ */
11530 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
11531 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c 1970-01-01 01:00:00.000000000 +0100
11532 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.c 2006-03-28 22:16:14.000000000 +0200
11536 + Broadcom BCM43xx wireless driver
11538 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11539 + Stefano Brivio <st3@riseup.net>
11540 + Michael Buesch <mbuesch@freenet.de>
11541 + Danny van Dyk <kugelfang@gentoo.org>
11542 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11544 + Some parts of the code in this file are derived from the ipw2200
11545 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11547 + This program is free software; you can redistribute it and/or modify
11548 + it under the terms of the GNU General Public License as published by
11549 + the Free Software Foundation; either version 2 of the License, or
11550 + (at your option) any later version.
11552 + This program is distributed in the hope that it will be useful,
11553 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11554 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11555 + GNU General Public License for more details.
11557 + You should have received a copy of the GNU General Public License
11558 + along with this program; see the file COPYING. If not, write to
11559 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11560 + Boston, MA 02110-1301, USA.
11564 +#include <linux/delay.h>
11566 +#include "bcm43xx.h"
11567 +#include "bcm43xx_power.h"
11568 +#include "bcm43xx_main.h"
11571 +/* Get max/min slowclock frequency
11572 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11574 +static int bcm43xx_pctl_clockfreqlimit(struct bcm43xx_private *bcm,
11582 + struct bcm43xx_coreinfo *old_core;
11584 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11586 + old_core = bcm->current_core;
11587 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11591 + if (bcm->current_core->rev < 6) {
11592 + if ((bcm->bustype == BCM43xx_BUSTYPE_PCMCIA) ||
11593 + (bcm->bustype == BCM43xx_BUSTYPE_SB)) {
11597 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &tmp);
11599 + printk(KERN_ERR PFX "clockfreqlimit pcicfg read failure\n");
11600 + goto out_switchback;
11602 + if (tmp & 0x10) {
11612 + } else if (bcm->current_core->rev < 10) {
11613 + selection = (tmp & 0x07);
11615 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11616 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11620 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SYSCLKCTL);
11621 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11625 + switch (selection) {
11636 + limit = 20200000;
11638 + limit = 19800000;
11643 + limit = 34000000;
11645 + limit = 25000000;
11650 + limit /= divisor;
11653 + err = bcm43xx_switch_core(bcm, old_core);
11654 + assert(err == 0);
11660 +/* init power control
11661 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11663 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm)
11665 + int err, maxfreq;
11666 + struct bcm43xx_coreinfo *old_core;
11668 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11670 + old_core = bcm->current_core;
11671 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11672 + if (err == -ENODEV)
11677 + maxfreq = bcm43xx_pctl_clockfreqlimit(bcm, 1);
11678 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY,
11679 + (maxfreq * 150 + 999999) / 1000000);
11680 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_FREFSELDELAY,
11681 + (maxfreq * 15 + 999999) / 1000000);
11683 + err = bcm43xx_switch_core(bcm, old_core);
11684 + assert(err == 0);
11690 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm)
11694 + u32 pll_on_delay;
11695 + struct bcm43xx_coreinfo *old_core;
11698 + if (bcm->bustype != BCM43xx_BUSTYPE_PCI)
11700 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11702 + old_core = bcm->current_core;
11703 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11704 + if (err == -ENODEV)
11707 + minfreq = bcm43xx_pctl_clockfreqlimit(bcm, 0);
11708 + pll_on_delay = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_PLLONDELAY);
11709 + delay = (((pll_on_delay + 2) * 1000000) + (minfreq - 1)) / minfreq;
11711 + err = bcm43xx_switch_core(bcm, old_core);
11712 + assert(err == 0);
11718 +/* set the powercontrol clock
11719 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11721 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode)
11724 + struct bcm43xx_coreinfo *old_core;
11727 + old_core = bcm->current_core;
11728 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11729 + if (err == -ENODEV)
11734 + if (bcm->core_chipcommon.rev < 6) {
11735 + if (mode == BCM43xx_PCTL_CLK_FAST) {
11736 + err = bcm43xx_pctl_set_crystal(bcm, 1);
11741 + if ((bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL) &&
11742 + (bcm->core_chipcommon.rev < 10)) {
11744 + case BCM43xx_PCTL_CLK_FAST:
11745 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11746 + tmp = (tmp & ~BCM43xx_PCTL_FORCE_SLOW) | BCM43xx_PCTL_FORCE_PLL;
11747 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11749 + case BCM43xx_PCTL_CLK_SLOW:
11750 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11751 + tmp |= BCM43xx_PCTL_FORCE_SLOW;
11752 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11754 + case BCM43xx_PCTL_CLK_DYNAMIC:
11755 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11756 + tmp &= ~BCM43xx_PCTL_FORCE_SLOW;
11757 + tmp |= BCM43xx_PCTL_FORCE_PLL;
11758 + tmp &= ~BCM43xx_PCTL_DYN_XTAL;
11759 + bcm43xx_write32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL, tmp);
11764 + err = bcm43xx_switch_core(bcm, old_core);
11765 + assert(err == 0);
11771 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on)
11774 + u32 in, out, outenable;
11776 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_IN, &in);
11779 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &out);
11782 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUTENABLE, &outenable);
11786 + outenable |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11792 + out |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11794 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11797 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11802 + out &= ~BCM43xx_PCTL_PLL_POWERDOWN;
11803 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11808 + if (bcm->current_core->rev < 5)
11810 + if (bcm->sprom.boardflags & BCM43xx_BFL_XTAL_NOSLOW)
11813 +/* XXX: Why BCM43xx_MMIO_RADIO_HWENABLED_xx can't be read at this time?
11814 + * err = bcm43xx_switch_core(bcm, bcm->active_80211_core);
11817 + * if (((bcm->current_core->rev >= 3) &&
11818 + * (bcm43xx_read32(bcm, BCM43xx_MMIO_RADIO_HWENABLED_HI) & (1 << 16))) ||
11819 + * ((bcm->current_core->rev < 3) &&
11820 + * !(bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_HWENABLED_LO) & (1 << 4))))
11822 + * err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11827 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
11830 + out &= ~BCM43xx_PCTL_XTAL_POWERUP;
11831 + out |= BCM43xx_PCTL_PLL_POWERDOWN;
11832 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11835 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11844 + printk(KERN_ERR PFX "Error: pctl_set_clock() could not access PCI config space!\n");
11849 +/* Set the PowerSavingControlBits.
11851 + * 0 => unset the bit
11852 + * 1 => set the bit
11853 + * -1 => calculate the bit
11855 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11856 + int bit25, int bit26)
11861 +//FIXME: Force 25 to off and 26 to on for now:
11865 + if (bit25 == -1) {
11866 + //TODO: If powersave is not off and FIXME is not set and we are not in adhoc
11867 + // and thus is not an AP and we are associated, set bit 25
11869 + if (bit26 == -1) {
11870 + //TODO: If the device is awake or this is an AP, or we are scanning, or FIXME,
11871 + // or we are associated, or FIXME, or the latest PS-Poll packet sent was
11872 + // successful, set bit26
11874 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11876 + status |= BCM43xx_SBF_PS1;
11878 + status &= ~BCM43xx_SBF_PS1;
11880 + status |= BCM43xx_SBF_PS2;
11882 + status &= ~BCM43xx_SBF_PS2;
11883 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
11884 + if (bit26 && bcm->current_core->rev >= 5) {
11885 + for (i = 0; i < 100; i++) {
11886 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0040) != 4)
11892 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
11893 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h 1970-01-01 01:00:00.000000000 +0100
11894 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_power.h 2006-03-28 22:16:14.000000000 +0200
11898 + Broadcom BCM43xx wireless driver
11900 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11901 + Stefano Brivio <st3@riseup.net>
11902 + Michael Buesch <mbuesch@freenet.de>
11903 + Danny van Dyk <kugelfang@gentoo.org>
11904 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11906 + Some parts of the code in this file are derived from the ipw2200
11907 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11909 + This program is free software; you can redistribute it and/or modify
11910 + it under the terms of the GNU General Public License as published by
11911 + the Free Software Foundation; either version 2 of the License, or
11912 + (at your option) any later version.
11914 + This program is distributed in the hope that it will be useful,
11915 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11916 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11917 + GNU General Public License for more details.
11919 + You should have received a copy of the GNU General Public License
11920 + along with this program; see the file COPYING. If not, write to
11921 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11922 + Boston, MA 02110-1301, USA.
11926 +#ifndef BCM43xx_POWER_H_
11927 +#define BCM43xx_POWER_H_
11929 +#include <linux/types.h>
11932 +struct bcm43xx_private;
11934 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm);
11935 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode);
11936 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on);
11937 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm);
11939 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11940 + int bit25, int bit26);
11942 +#endif /* BCM43xx_POWER_H_ */
11943 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
11944 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c 1970-01-01 01:00:00.000000000 +0100
11945 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.c 2006-03-28 22:16:14.000000000 +0200
11949 + Broadcom BCM43xx wireless driver
11951 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
11952 + Stefano Brivio <st3@riseup.net>
11953 + Michael Buesch <mbuesch@freenet.de>
11954 + Danny van Dyk <kugelfang@gentoo.org>
11955 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
11957 + Some parts of the code in this file are derived from the ipw2200
11958 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11960 + This program is free software; you can redistribute it and/or modify
11961 + it under the terms of the GNU General Public License as published by
11962 + the Free Software Foundation; either version 2 of the License, or
11963 + (at your option) any later version.
11965 + This program is distributed in the hope that it will be useful,
11966 + but WITHOUT ANY WARRANTY; without even the implied warranty of
11967 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11968 + GNU General Public License for more details.
11970 + You should have received a copy of the GNU General Public License
11971 + along with this program; see the file COPYING. If not, write to
11972 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
11973 + Boston, MA 02110-1301, USA.
11977 +#include <linux/delay.h>
11979 +#include "bcm43xx.h"
11980 +#include "bcm43xx_main.h"
11981 +#include "bcm43xx_phy.h"
11982 +#include "bcm43xx_radio.h"
11983 +#include "bcm43xx_ilt.h"
11986 +/* Table for bcm43xx_radio_calibrationvalue() */
11987 +static const u16 rcc_table[16] = {
11988 + 0x0002, 0x0003, 0x0001, 0x000F,
11989 + 0x0006, 0x0007, 0x0005, 0x000F,
11990 + 0x000A, 0x000B, 0x0009, 0x000F,
11991 + 0x000E, 0x000F, 0x000D, 0x000F,
11994 +/* Reverse the bits of a 4bit value.
11995 + * Example: 1101 is flipped 1011
11997 +static u16 flip_4bit(u16 value)
11999 + u16 flipped = 0x0000;
12001 + assert((value & ~0x000F) == 0x0000);
12003 + flipped |= (value & 0x0001) << 3;
12004 + flipped |= (value & 0x0002) << 1;
12005 + flipped |= (value & 0x0004) >> 1;
12006 + flipped |= (value & 0x0008) >> 3;
12011 +/* Get the freq, as it has to be written to the device. */
12013 +u16 channel2freq_bg(u8 channel)
12015 + /* Frequencies are given as frequencies_bg[index] + 2.4GHz
12016 + * Starting with channel 1
12018 + static const u16 frequencies_bg[14] = {
12025 + assert(channel >= 1 && channel <= 14);
12027 + return frequencies_bg[channel - 1];
12030 +/* Get the freq, as it has to be written to the device. */
12032 +u16 channel2freq_a(u8 channel)
12034 + assert(channel <= 200);
12036 + return (5000 + 5 * channel);
12039 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm)
12043 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
12044 + status |= BCM43xx_SBF_RADIOREG_LOCK;
12045 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
12050 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm)
12054 + bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER); /* dummy read */
12055 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
12056 + status &= ~BCM43xx_SBF_RADIOREG_LOCK;
12057 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
12061 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset)
12063 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12064 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12066 + switch (phy->type) {
12067 + case BCM43xx_PHYTYPE_A:
12068 + offset |= 0x0040;
12070 + case BCM43xx_PHYTYPE_B:
12071 + if (radio->version == 0x2053) {
12072 + if (offset < 0x70)
12074 + else if (offset < 0x80)
12076 + } else if (radio->version == 0x2050) {
12081 + case BCM43xx_PHYTYPE_G:
12086 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
12087 + return bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
12090 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val)
12092 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
12094 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW, val);
12097 +static void bcm43xx_set_all_gains(struct bcm43xx_private *bcm,
12098 + s16 first, s16 second, s16 third)
12100 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12102 + u16 start = 0x08, end = 0x18;
12103 + u16 offset = 0x0400;
12106 + if (phy->rev <= 1) {
12112 + for (i = 0; i < 4; i++)
12113 + bcm43xx_ilt_write(bcm, offset + i, first);
12115 + for (i = start; i < end; i++)
12116 + bcm43xx_ilt_write(bcm, offset + i, second);
12118 + if (third != -1) {
12119 + tmp = ((u16)third << 14) | ((u16)third << 6);
12120 + bcm43xx_phy_write(bcm, 0x04A0,
12121 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | tmp);
12122 + bcm43xx_phy_write(bcm, 0x04A1,
12123 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | tmp);
12124 + bcm43xx_phy_write(bcm, 0x04A2,
12125 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | tmp);
12127 + bcm43xx_dummy_transmission(bcm);
12130 +static void bcm43xx_set_original_gains(struct bcm43xx_private *bcm)
12132 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12134 + u16 offset = 0x0400;
12135 + u16 start = 0x0008, end = 0x0018;
12137 + if (phy->rev <= 1) {
12143 + for (i = 0; i < 4; i++) {
12144 + tmp = (i & 0xFFFC);
12145 + tmp |= (i & 0x0001) << 1;
12146 + tmp |= (i & 0x0002) >> 1;
12148 + bcm43xx_ilt_write(bcm, offset + i, tmp);
12151 + for (i = start; i < end; i++)
12152 + bcm43xx_ilt_write(bcm, offset + i, i - start);
12154 + bcm43xx_phy_write(bcm, 0x04A0,
12155 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xBFBF) | 0x4040);
12156 + bcm43xx_phy_write(bcm, 0x04A1,
12157 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xBFBF) | 0x4040);
12158 + bcm43xx_phy_write(bcm, 0x04A2,
12159 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xBFBF) | 0x4000);
12160 + bcm43xx_dummy_transmission(bcm);
12163 +/* Synthetic PU workaround */
12164 +static void bcm43xx_synth_pu_workaround(struct bcm43xx_private *bcm, u8 channel)
12166 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12168 + if (radio->version != 0x2050 || radio->revision >= 6) {
12169 + /* We do not need the workaround. */
12173 + if (channel <= 10) {
12174 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12175 + channel2freq_bg(channel + 4));
12177 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12178 + channel2freq_bg(1));
12181 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12182 + channel2freq_bg(channel));
12185 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel)
12187 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12189 + u16 saved, rssi, temp;
12192 + saved = bcm43xx_phy_read(bcm, 0x0403);
12193 + bcm43xx_radio_selectchannel(bcm, channel, 0);
12194 + bcm43xx_phy_write(bcm, 0x0403, (saved & 0xFFF8) | 5);
12195 + if (radio->aci_hw_rssi)
12196 + rssi = bcm43xx_phy_read(bcm, 0x048A) & 0x3F;
12198 + rssi = saved & 0x3F;
12199 + /* clamp temp to signed 5bit */
12202 + for (i = 0;i < 100; i++) {
12203 + temp = (bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x3F;
12211 + bcm43xx_phy_write(bcm, 0x0403, saved);
12216 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm)
12218 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12219 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12221 + unsigned int channel = radio->channel;
12222 + unsigned int i, j, start, end;
12223 + unsigned long phylock_flags;
12225 + if (!((phy->type == BCM43xx_PHYTYPE_G) && (phy->rev > 0)))
12228 + bcm43xx_phy_lock(bcm, phylock_flags);
12229 + bcm43xx_radio_lock(bcm);
12230 + bcm43xx_phy_write(bcm, 0x0802,
12231 + bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
12232 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12233 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
12234 + bcm43xx_set_all_gains(bcm, 3, 8, 1);
12236 + start = (channel - 5 > 0) ? channel - 5 : 1;
12237 + end = (channel + 5 < 14) ? channel + 5 : 13;
12239 + for (i = start; i <= end; i++) {
12240 + if (abs(channel - i) > 2)
12241 + ret[i-1] = bcm43xx_radio_aci_detect(bcm, i);
12243 + bcm43xx_radio_selectchannel(bcm, channel, 0);
12244 + bcm43xx_phy_write(bcm, 0x0802,
12245 + (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC) | 0x0003);
12246 + bcm43xx_phy_write(bcm, 0x0403,
12247 + bcm43xx_phy_read(bcm, 0x0403) & 0xFFF8);
12248 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12249 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
12250 + bcm43xx_set_original_gains(bcm);
12251 + for (i = 0; i < 13; i++) {
12254 + end = (i + 5 < 13) ? i + 5 : 13;
12255 + for (j = i; j < end; j++)
12258 + bcm43xx_radio_unlock(bcm);
12259 + bcm43xx_phy_unlock(bcm, phylock_flags);
12261 + return ret[channel - 1];
12264 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12265 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val)
12267 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12269 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_DATA, (u16)val);
12272 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12273 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset)
12277 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12278 + val = bcm43xx_phy_read(bcm, BCM43xx_PHY_NRSSILT_DATA);
12283 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12284 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val)
12289 + for (i = 0; i < 64; i++) {
12290 + tmp = bcm43xx_nrssi_hw_read(bcm, i);
12292 + tmp = limit_value(tmp, -32, 31);
12293 + bcm43xx_nrssi_hw_write(bcm, i, tmp);
12297 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12298 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm)
12300 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12304 + delta = 0x1F - radio->nrssi[0];
12305 + for (i = 0; i < 64; i++) {
12306 + tmp = (i - delta) * radio->nrssislope;
12309 + tmp = limit_value(tmp, 0, 0x3F);
12310 + radio->nrssi_lt[i] = tmp;
12314 +static void bcm43xx_calc_nrssi_offset(struct bcm43xx_private *bcm)
12316 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12317 + u16 backup[20] = { 0 };
12320 + u16 saved = 0xFFFF;
12322 + backup[0] = bcm43xx_phy_read(bcm, 0x0001);
12323 + backup[1] = bcm43xx_phy_read(bcm, 0x0811);
12324 + backup[2] = bcm43xx_phy_read(bcm, 0x0812);
12325 + backup[3] = bcm43xx_phy_read(bcm, 0x0814);
12326 + backup[4] = bcm43xx_phy_read(bcm, 0x0815);
12327 + backup[5] = bcm43xx_phy_read(bcm, 0x005A);
12328 + backup[6] = bcm43xx_phy_read(bcm, 0x0059);
12329 + backup[7] = bcm43xx_phy_read(bcm, 0x0058);
12330 + backup[8] = bcm43xx_phy_read(bcm, 0x000A);
12331 + backup[9] = bcm43xx_phy_read(bcm, 0x0003);
12332 + backup[10] = bcm43xx_radio_read16(bcm, 0x007A);
12333 + backup[11] = bcm43xx_radio_read16(bcm, 0x0043);
12335 + bcm43xx_phy_write(bcm, 0x0429,
12336 + bcm43xx_phy_read(bcm, 0x0429) & 0x7FFF);
12337 + bcm43xx_phy_write(bcm, 0x0001,
12338 + (bcm43xx_phy_read(bcm, 0x0001) & 0x3FFF) | 0x4000);
12339 + bcm43xx_phy_write(bcm, 0x0811,
12340 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
12341 + bcm43xx_phy_write(bcm, 0x0812,
12342 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFF3) | 0x0004);
12343 + bcm43xx_phy_write(bcm, 0x0802,
12344 + bcm43xx_phy_read(bcm, 0x0802) & ~(0x1 | 0x2));
12345 + if (phy->rev >= 6) {
12346 + backup[12] = bcm43xx_phy_read(bcm, 0x002E);
12347 + backup[13] = bcm43xx_phy_read(bcm, 0x002F);
12348 + backup[14] = bcm43xx_phy_read(bcm, 0x080F);
12349 + backup[15] = bcm43xx_phy_read(bcm, 0x0810);
12350 + backup[16] = bcm43xx_phy_read(bcm, 0x0801);
12351 + backup[17] = bcm43xx_phy_read(bcm, 0x0060);
12352 + backup[18] = bcm43xx_phy_read(bcm, 0x0014);
12353 + backup[19] = bcm43xx_phy_read(bcm, 0x0478);
12355 + bcm43xx_phy_write(bcm, 0x002E, 0);
12356 + bcm43xx_phy_write(bcm, 0x002F, 0);
12357 + bcm43xx_phy_write(bcm, 0x080F, 0);
12358 + bcm43xx_phy_write(bcm, 0x0810, 0);
12359 + bcm43xx_phy_write(bcm, 0x0478,
12360 + bcm43xx_phy_read(bcm, 0x0478) | 0x0100);
12361 + bcm43xx_phy_write(bcm, 0x0801,
12362 + bcm43xx_phy_read(bcm, 0x0801) | 0x0040);
12363 + bcm43xx_phy_write(bcm, 0x0060,
12364 + bcm43xx_phy_read(bcm, 0x0060) | 0x0040);
12365 + bcm43xx_phy_write(bcm, 0x0014,
12366 + bcm43xx_phy_read(bcm, 0x0014) | 0x0200);
12368 + bcm43xx_radio_write16(bcm, 0x007A,
12369 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
12370 + bcm43xx_radio_write16(bcm, 0x007A,
12371 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12374 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12375 + if (v47F >= 0x20)
12377 + if (v47F == 31) {
12378 + for (i = 7; i >= 4; i--) {
12379 + bcm43xx_radio_write16(bcm, 0x007B, i);
12381 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12382 + if (v47F >= 0x20)
12384 + if (v47F < 31 && saved == 0xFFFF)
12387 + if (saved == 0xFFFF)
12390 + bcm43xx_radio_write16(bcm, 0x007A,
12391 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12392 + bcm43xx_phy_write(bcm, 0x0814,
12393 + bcm43xx_phy_read(bcm, 0x0814) | 0x0001);
12394 + bcm43xx_phy_write(bcm, 0x0815,
12395 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFE);
12396 + bcm43xx_phy_write(bcm, 0x0811,
12397 + bcm43xx_phy_read(bcm, 0x0811) | 0x000C);
12398 + bcm43xx_phy_write(bcm, 0x0812,
12399 + bcm43xx_phy_read(bcm, 0x0812) | 0x000C);
12400 + bcm43xx_phy_write(bcm, 0x0811,
12401 + bcm43xx_phy_read(bcm, 0x0811) | 0x0030);
12402 + bcm43xx_phy_write(bcm, 0x0812,
12403 + bcm43xx_phy_read(bcm, 0x0812) | 0x0030);
12404 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12405 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12406 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12407 + if (phy->rev == 0) {
12408 + bcm43xx_phy_write(bcm, 0x0003, 0x0122);
12410 + bcm43xx_phy_write(bcm, 0x000A,
12411 + bcm43xx_phy_read(bcm, 0x000A)
12414 + bcm43xx_phy_write(bcm, 0x0814,
12415 + bcm43xx_phy_read(bcm, 0x0814) | 0x0004);
12416 + bcm43xx_phy_write(bcm, 0x0815,
12417 + bcm43xx_phy_read(bcm, 0x0815) & 0xFFFB);
12418 + bcm43xx_phy_write(bcm, 0x0003,
12419 + (bcm43xx_phy_read(bcm, 0x0003) & 0xFF9F)
12421 + bcm43xx_radio_write16(bcm, 0x007A,
12422 + bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
12423 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12424 + bcm43xx_radio_write16(bcm, 0x0043,
12425 + (bcm43xx_radio_read16(bcm, 0x0043)
12426 + & 0x00F0) | 0x000F);
12428 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12429 + if (v47F >= 0x20)
12431 + if (v47F == -32) {
12432 + for (i = 0; i < 4; i++) {
12433 + bcm43xx_radio_write16(bcm, 0x007B, i);
12435 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12436 + if (v47F >= 0x20)
12438 + if (v47F > -31 && saved == 0xFFFF)
12441 + if (saved == 0xFFFF)
12446 + bcm43xx_radio_write16(bcm, 0x007B, saved);
12448 + if (phy->rev >= 6) {
12449 + bcm43xx_phy_write(bcm, 0x002E, backup[12]);
12450 + bcm43xx_phy_write(bcm, 0x002F, backup[13]);
12451 + bcm43xx_phy_write(bcm, 0x080F, backup[14]);
12452 + bcm43xx_phy_write(bcm, 0x0810, backup[15]);
12454 + bcm43xx_phy_write(bcm, 0x0814, backup[3]);
12455 + bcm43xx_phy_write(bcm, 0x0815, backup[4]);
12456 + bcm43xx_phy_write(bcm, 0x005A, backup[5]);
12457 + bcm43xx_phy_write(bcm, 0x0059, backup[6]);
12458 + bcm43xx_phy_write(bcm, 0x0058, backup[7]);
12459 + bcm43xx_phy_write(bcm, 0x000A, backup[8]);
12460 + bcm43xx_phy_write(bcm, 0x0003, backup[9]);
12461 + bcm43xx_radio_write16(bcm, 0x0043, backup[11]);
12462 + bcm43xx_radio_write16(bcm, 0x007A, backup[10]);
12463 + bcm43xx_phy_write(bcm, 0x0802,
12464 + bcm43xx_phy_read(bcm, 0x0802) | 0x1 | 0x2);
12465 + bcm43xx_phy_write(bcm, 0x0429,
12466 + bcm43xx_phy_read(bcm, 0x0429) | 0x8000);
12467 + bcm43xx_set_original_gains(bcm);
12468 + if (phy->rev >= 6) {
12469 + bcm43xx_phy_write(bcm, 0x0801, backup[16]);
12470 + bcm43xx_phy_write(bcm, 0x0060, backup[17]);
12471 + bcm43xx_phy_write(bcm, 0x0014, backup[18]);
12472 + bcm43xx_phy_write(bcm, 0x0478, backup[19]);
12474 + bcm43xx_phy_write(bcm, 0x0001, backup[0]);
12475 + bcm43xx_phy_write(bcm, 0x0812, backup[2]);
12476 + bcm43xx_phy_write(bcm, 0x0811, backup[1]);
12479 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm)
12481 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12482 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12483 + u16 backup[18] = { 0 };
12485 + s16 nrssi0, nrssi1;
12487 + switch (phy->type) {
12488 + case BCM43xx_PHYTYPE_B:
12489 + backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
12490 + backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
12491 + backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
12492 + backup[3] = bcm43xx_phy_read(bcm, 0x0030);
12493 + backup[4] = bcm43xx_phy_read(bcm, 0x0026);
12494 + backup[5] = bcm43xx_phy_read(bcm, 0x0015);
12495 + backup[6] = bcm43xx_phy_read(bcm, 0x002A);
12496 + backup[7] = bcm43xx_phy_read(bcm, 0x0020);
12497 + backup[8] = bcm43xx_phy_read(bcm, 0x005A);
12498 + backup[9] = bcm43xx_phy_read(bcm, 0x0059);
12499 + backup[10] = bcm43xx_phy_read(bcm, 0x0058);
12500 + backup[11] = bcm43xx_read16(bcm, 0x03E2);
12501 + backup[12] = bcm43xx_read16(bcm, 0x03E6);
12502 + backup[13] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
12504 + tmp = bcm43xx_radio_read16(bcm, 0x007A);
12505 + tmp &= (phy->rev >= 5) ? 0x007F : 0x000F;
12506 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
12507 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
12508 + bcm43xx_write16(bcm, 0x03EC, 0x7F7F);
12509 + bcm43xx_phy_write(bcm, 0x0026, 0x0000);
12510 + bcm43xx_phy_write(bcm, 0x0015,
12511 + bcm43xx_phy_read(bcm, 0x0015) | 0x0020);
12512 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
12513 + bcm43xx_radio_write16(bcm, 0x007A,
12514 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12516 + nrssi0 = (s16)bcm43xx_phy_read(bcm, 0x0027);
12517 + bcm43xx_radio_write16(bcm, 0x007A,
12518 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12519 + if (phy->rev >= 2) {
12520 + bcm43xx_write16(bcm, 0x03E6, 0x0040);
12521 + } else if (phy->rev == 0) {
12522 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
12524 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12525 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) & 0x2000);
12527 + bcm43xx_phy_write(bcm, 0x0020, 0x3F3F);
12528 + bcm43xx_phy_write(bcm, 0x0015, 0xF330);
12529 + bcm43xx_radio_write16(bcm, 0x005A, 0x0060);
12530 + bcm43xx_radio_write16(bcm, 0x0043,
12531 + bcm43xx_radio_read16(bcm, 0x0043) & 0x00F0);
12532 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12533 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12534 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12537 + nrssi1 = (s16)bcm43xx_phy_read(bcm, 0x0027);
12538 + bcm43xx_phy_write(bcm, 0x0030, backup[3]);
12539 + bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
12540 + bcm43xx_write16(bcm, 0x03E2, backup[11]);
12541 + bcm43xx_phy_write(bcm, 0x0026, backup[4]);
12542 + bcm43xx_phy_write(bcm, 0x0015, backup[5]);
12543 + bcm43xx_phy_write(bcm, 0x002A, backup[6]);
12544 + bcm43xx_synth_pu_workaround(bcm, radio->channel);
12545 + if (phy->rev != 0)
12546 + bcm43xx_write16(bcm, 0x03F4, backup[13]);
12548 + bcm43xx_phy_write(bcm, 0x0020, backup[7]);
12549 + bcm43xx_phy_write(bcm, 0x005A, backup[8]);
12550 + bcm43xx_phy_write(bcm, 0x0059, backup[9]);
12551 + bcm43xx_phy_write(bcm, 0x0058, backup[10]);
12552 + bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
12553 + bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
12555 + if (nrssi0 == nrssi1)
12556 + radio->nrssislope = 0x00010000;
12558 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12560 + if (nrssi0 <= -4) {
12561 + radio->nrssi[0] = nrssi0;
12562 + radio->nrssi[1] = nrssi1;
12565 + case BCM43xx_PHYTYPE_G:
12566 + if (radio->revision >= 9)
12568 + if (radio->revision == 8)
12569 + bcm43xx_calc_nrssi_offset(bcm);
12571 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12572 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF);
12573 + bcm43xx_phy_write(bcm, 0x0802,
12574 + bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC);
12575 + backup[7] = bcm43xx_read16(bcm, 0x03E2);
12576 + bcm43xx_write16(bcm, 0x03E2,
12577 + bcm43xx_read16(bcm, 0x03E2) | 0x8000);
12578 + backup[0] = bcm43xx_radio_read16(bcm, 0x007A);
12579 + backup[1] = bcm43xx_radio_read16(bcm, 0x0052);
12580 + backup[2] = bcm43xx_radio_read16(bcm, 0x0043);
12581 + backup[3] = bcm43xx_phy_read(bcm, 0x0015);
12582 + backup[4] = bcm43xx_phy_read(bcm, 0x005A);
12583 + backup[5] = bcm43xx_phy_read(bcm, 0x0059);
12584 + backup[6] = bcm43xx_phy_read(bcm, 0x0058);
12585 + backup[8] = bcm43xx_read16(bcm, 0x03E6);
12586 + backup[9] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
12587 + if (phy->rev >= 3) {
12588 + backup[10] = bcm43xx_phy_read(bcm, 0x002E);
12589 + backup[11] = bcm43xx_phy_read(bcm, 0x002F);
12590 + backup[12] = bcm43xx_phy_read(bcm, 0x080F);
12591 + backup[13] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_LO_CONTROL);
12592 + backup[14] = bcm43xx_phy_read(bcm, 0x0801);
12593 + backup[15] = bcm43xx_phy_read(bcm, 0x0060);
12594 + backup[16] = bcm43xx_phy_read(bcm, 0x0014);
12595 + backup[17] = bcm43xx_phy_read(bcm, 0x0478);
12596 + bcm43xx_phy_write(bcm, 0x002E, 0);
12597 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, 0);
12598 + switch (phy->rev) {
12599 + case 4: case 6: case 7:
12600 + bcm43xx_phy_write(bcm, 0x0478,
12601 + bcm43xx_phy_read(bcm, 0x0478)
12603 + bcm43xx_phy_write(bcm, 0x0801,
12604 + bcm43xx_phy_read(bcm, 0x0801)
12608 + bcm43xx_phy_write(bcm, 0x0801,
12609 + bcm43xx_phy_read(bcm, 0x0801)
12613 + bcm43xx_phy_write(bcm, 0x0060,
12614 + bcm43xx_phy_read(bcm, 0x0060)
12616 + bcm43xx_phy_write(bcm, 0x0014,
12617 + bcm43xx_phy_read(bcm, 0x0014)
12620 + bcm43xx_radio_write16(bcm, 0x007A,
12621 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0070);
12622 + bcm43xx_set_all_gains(bcm, 0, 8, 0);
12623 + bcm43xx_radio_write16(bcm, 0x007A,
12624 + bcm43xx_radio_read16(bcm, 0x007A) & 0x00F7);
12625 + if (phy->rev >= 2) {
12626 + bcm43xx_phy_write(bcm, 0x0811,
12627 + (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0030);
12628 + bcm43xx_phy_write(bcm, 0x0812,
12629 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0010);
12631 + bcm43xx_radio_write16(bcm, 0x007A,
12632 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12635 + nrssi0 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12636 + if (nrssi0 >= 0x0020)
12637 + nrssi0 -= 0x0040;
12639 + bcm43xx_radio_write16(bcm, 0x007A,
12640 + bcm43xx_radio_read16(bcm, 0x007A) & 0x007F);
12641 + if (phy->rev >= 2) {
12642 + bcm43xx_phy_write(bcm, 0x0003,
12643 + (bcm43xx_phy_read(bcm, 0x0003)
12644 + & 0xFF9F) | 0x0040);
12647 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12648 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
12650 + bcm43xx_radio_write16(bcm, 0x007A,
12651 + bcm43xx_radio_read16(bcm, 0x007A) | 0x000F);
12652 + bcm43xx_phy_write(bcm, 0x0015, 0xF330);
12653 + if (phy->rev >= 2) {
12654 + bcm43xx_phy_write(bcm, 0x0812,
12655 + (bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF) | 0x0020);
12656 + bcm43xx_phy_write(bcm, 0x0811,
12657 + (bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF) | 0x0020);
12660 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12661 + if (radio->revision == 8) {
12662 + bcm43xx_radio_write16(bcm, 0x0043, 0x001F);
12664 + tmp = bcm43xx_radio_read16(bcm, 0x0052) & 0xFF0F;
12665 + bcm43xx_radio_write16(bcm, 0x0052, tmp | 0x0060);
12666 + tmp = bcm43xx_radio_read16(bcm, 0x0043) & 0xFFF0;
12667 + bcm43xx_radio_write16(bcm, 0x0043, tmp | 0x0009);
12669 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12670 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12671 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12673 + nrssi1 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12674 + if (nrssi1 >= 0x0020)
12675 + nrssi1 -= 0x0040;
12676 + if (nrssi0 == nrssi1)
12677 + radio->nrssislope = 0x00010000;
12679 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12680 + if (nrssi0 >= -4) {
12681 + radio->nrssi[0] = nrssi1;
12682 + radio->nrssi[1] = nrssi0;
12684 + if (phy->rev >= 3) {
12685 + bcm43xx_phy_write(bcm, 0x002E, backup[10]);
12686 + bcm43xx_phy_write(bcm, 0x002F, backup[11]);
12687 + bcm43xx_phy_write(bcm, 0x080F, backup[12]);
12688 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, backup[13]);
12690 + if (phy->rev >= 2) {
12691 + bcm43xx_phy_write(bcm, 0x0812,
12692 + bcm43xx_phy_read(bcm, 0x0812) & 0xFFCF);
12693 + bcm43xx_phy_write(bcm, 0x0811,
12694 + bcm43xx_phy_read(bcm, 0x0811) & 0xFFCF);
12697 + bcm43xx_radio_write16(bcm, 0x007A, backup[0]);
12698 + bcm43xx_radio_write16(bcm, 0x0052, backup[1]);
12699 + bcm43xx_radio_write16(bcm, 0x0043, backup[2]);
12700 + bcm43xx_write16(bcm, 0x03E2, backup[7]);
12701 + bcm43xx_write16(bcm, 0x03E6, backup[8]);
12702 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[9]);
12703 + bcm43xx_phy_write(bcm, 0x0015, backup[3]);
12704 + bcm43xx_phy_write(bcm, 0x005A, backup[4]);
12705 + bcm43xx_phy_write(bcm, 0x0059, backup[5]);
12706 + bcm43xx_phy_write(bcm, 0x0058, backup[6]);
12707 + bcm43xx_synth_pu_workaround(bcm, radio->channel);
12708 + bcm43xx_phy_write(bcm, 0x0802,
12709 + bcm43xx_phy_read(bcm, 0x0802) | (0x0001 | 0x0002));
12710 + bcm43xx_set_original_gains(bcm);
12711 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12712 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x8000);
12713 + if (phy->rev >= 3) {
12714 + bcm43xx_phy_write(bcm, 0x0801, backup[14]);
12715 + bcm43xx_phy_write(bcm, 0x0060, backup[15]);
12716 + bcm43xx_phy_write(bcm, 0x0014, backup[16]);
12717 + bcm43xx_phy_write(bcm, 0x0478, backup[17]);
12719 + bcm43xx_nrssi_mem_update(bcm);
12720 + bcm43xx_calc_nrssi_threshold(bcm);
12727 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm)
12729 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12730 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12736 + switch (phy->type) {
12737 + case BCM43xx_PHYTYPE_B: {
12738 + if (radio->version != 0x2050)
12740 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI))
12743 + if (radio->revision >= 6) {
12744 + threshold = (radio->nrssi[1] - radio->nrssi[0]) * 32;
12745 + threshold += 20 * (radio->nrssi[0] + 1);
12748 + threshold = radio->nrssi[1] - 5;
12750 + threshold = limit_value(threshold, 0, 0x3E);
12751 + bcm43xx_phy_read(bcm, 0x0020); /* dummy read */
12752 + bcm43xx_phy_write(bcm, 0x0020, (((u16)threshold) << 8) | 0x001C);
12754 + if (radio->revision >= 6) {
12755 + bcm43xx_phy_write(bcm, 0x0087, 0x0E0D);
12756 + bcm43xx_phy_write(bcm, 0x0086, 0x0C0B);
12757 + bcm43xx_phy_write(bcm, 0x0085, 0x0A09);
12758 + bcm43xx_phy_write(bcm, 0x0084, 0x0808);
12759 + bcm43xx_phy_write(bcm, 0x0083, 0x0808);
12760 + bcm43xx_phy_write(bcm, 0x0082, 0x0604);
12761 + bcm43xx_phy_write(bcm, 0x0081, 0x0302);
12762 + bcm43xx_phy_write(bcm, 0x0080, 0x0100);
12766 + case BCM43xx_PHYTYPE_G:
12767 + if (!phy->connected ||
12768 + !(bcm->sprom.boardflags & BCM43xx_BFL_RSSI)) {
12769 + tmp16 = bcm43xx_nrssi_hw_read(bcm, 0x20);
12770 + if (tmp16 >= 0x20)
12773 + bcm43xx_phy_write(bcm, 0x048A,
12774 + (bcm43xx_phy_read(bcm, 0x048A)
12775 + & 0xF000) | 0x09EB);
12777 + bcm43xx_phy_write(bcm, 0x048A,
12778 + (bcm43xx_phy_read(bcm, 0x048A)
12779 + & 0xF000) | 0x0AED);
12782 + if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
12785 + } else if (!radio->aci_wlan_automatic && radio->aci_enable) {
12793 + a = a * (radio->nrssi[1] - radio->nrssi[0]);
12794 + a += (radio->nrssi[0] << 6);
12800 + a = limit_value(a, -31, 31);
12802 + b = b * (radio->nrssi[1] - radio->nrssi[0]);
12803 + b += (radio->nrssi[0] << 6);
12809 + b = limit_value(b, -31, 31);
12811 + tmp_u16 = bcm43xx_phy_read(bcm, 0x048A) & 0xF000;
12812 + tmp_u16 |= ((u32)b & 0x0000003F);
12813 + tmp_u16 |= (((u32)a & 0x0000003F) << 6);
12814 + bcm43xx_phy_write(bcm, 0x048A, tmp_u16);
12822 +/* Stack implementation to save/restore values from the
12823 + * interference mitigation code.
12824 + * It is save to restore values in random order.
12826 +static void _stack_save(u32 *_stackptr, size_t *stackidx,
12827 + u8 id, u16 offset, u16 value)
12829 + u32 *stackptr = &(_stackptr[*stackidx]);
12831 + assert((offset & 0xF000) == 0x0000);
12832 + assert((id & 0xF0) == 0x00);
12833 + *stackptr = offset;
12834 + *stackptr |= ((u32)id) << 12;
12835 + *stackptr |= ((u32)value) << 16;
12837 + assert(*stackidx < BCM43xx_INTERFSTACK_SIZE);
12840 +static u16 _stack_restore(u32 *stackptr,
12841 + u8 id, u16 offset)
12845 + assert((offset & 0xF000) == 0x0000);
12846 + assert((id & 0xF0) == 0x00);
12847 + for (i = 0; i < BCM43xx_INTERFSTACK_SIZE; i++, stackptr++) {
12848 + if ((*stackptr & 0x00000FFF) != offset)
12850 + if (((*stackptr & 0x0000F000) >> 12) != id)
12852 + return ((*stackptr & 0xFFFF0000) >> 16);
12859 +#define phy_stacksave(offset) \
12861 + _stack_save(stack, &stackidx, 0x1, (offset), \
12862 + bcm43xx_phy_read(bcm, (offset))); \
12864 +#define phy_stackrestore(offset) \
12866 + bcm43xx_phy_write(bcm, (offset), \
12867 + _stack_restore(stack, 0x1, \
12870 +#define radio_stacksave(offset) \
12872 + _stack_save(stack, &stackidx, 0x2, (offset), \
12873 + bcm43xx_radio_read16(bcm, (offset))); \
12875 +#define radio_stackrestore(offset) \
12877 + bcm43xx_radio_write16(bcm, (offset), \
12878 + _stack_restore(stack, 0x2, \
12881 +#define ilt_stacksave(offset) \
12883 + _stack_save(stack, &stackidx, 0x3, (offset), \
12884 + bcm43xx_ilt_read(bcm, (offset))); \
12886 +#define ilt_stackrestore(offset) \
12888 + bcm43xx_ilt_write(bcm, (offset), \
12889 + _stack_restore(stack, 0x3, \
12894 +bcm43xx_radio_interference_mitigation_enable(struct bcm43xx_private *bcm,
12897 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12898 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12899 + u16 tmp, flipped;
12901 + size_t stackidx = 0;
12902 + u32 *stack = radio->interfstack;
12905 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
12906 + if (phy->rev != 1) {
12907 + bcm43xx_phy_write(bcm, 0x042B,
12908 + bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
12909 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
12910 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & ~0x4000);
12913 + radio_stacksave(0x0078);
12914 + tmp = (bcm43xx_radio_read16(bcm, 0x0078) & 0x001E);
12915 + flipped = flip_4bit(tmp);
12916 + if (flipped < 10 && flipped >= 8)
12918 + else if (flipped >= 10)
12920 + flipped = flip_4bit(flipped);
12921 + flipped = (flipped << 1) | 0x0020;
12922 + bcm43xx_radio_write16(bcm, 0x0078, flipped);
12924 + bcm43xx_calc_nrssi_threshold(bcm);
12926 + phy_stacksave(0x0406);
12927 + bcm43xx_phy_write(bcm, 0x0406, 0x7E28);
12929 + bcm43xx_phy_write(bcm, 0x042B,
12930 + bcm43xx_phy_read(bcm, 0x042B) | 0x0800);
12931 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
12932 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD) | 0x1000);
12934 + phy_stacksave(0x04A0);
12935 + bcm43xx_phy_write(bcm, 0x04A0,
12936 + (bcm43xx_phy_read(bcm, 0x04A0) & 0xC0C0) | 0x0008);
12937 + phy_stacksave(0x04A1);
12938 + bcm43xx_phy_write(bcm, 0x04A1,
12939 + (bcm43xx_phy_read(bcm, 0x04A1) & 0xC0C0) | 0x0605);
12940 + phy_stacksave(0x04A2);
12941 + bcm43xx_phy_write(bcm, 0x04A2,
12942 + (bcm43xx_phy_read(bcm, 0x04A2) & 0xC0C0) | 0x0204);
12943 + phy_stacksave(0x04A8);
12944 + bcm43xx_phy_write(bcm, 0x04A8,
12945 + (bcm43xx_phy_read(bcm, 0x04A8) & 0xC0C0) | 0x0803);
12946 + phy_stacksave(0x04AB);
12947 + bcm43xx_phy_write(bcm, 0x04AB,
12948 + (bcm43xx_phy_read(bcm, 0x04AB) & 0xC0C0) | 0x0605);
12950 + phy_stacksave(0x04A7);
12951 + bcm43xx_phy_write(bcm, 0x04A7, 0x0002);
12952 + phy_stacksave(0x04A3);
12953 + bcm43xx_phy_write(bcm, 0x04A3, 0x287A);
12954 + phy_stacksave(0x04A9);
12955 + bcm43xx_phy_write(bcm, 0x04A9, 0x2027);
12956 + phy_stacksave(0x0493);
12957 + bcm43xx_phy_write(bcm, 0x0493, 0x32F5);
12958 + phy_stacksave(0x04AA);
12959 + bcm43xx_phy_write(bcm, 0x04AA, 0x2027);
12960 + phy_stacksave(0x04AC);
12961 + bcm43xx_phy_write(bcm, 0x04AC, 0x32F5);
12963 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
12964 + if (bcm43xx_phy_read(bcm, 0x0033) & 0x0800)
12967 + radio->aci_enable = 1;
12969 + phy_stacksave(BCM43xx_PHY_RADIO_BITFIELD);
12970 + phy_stacksave(BCM43xx_PHY_G_CRS);
12971 + if (phy->rev < 2) {
12972 + phy_stacksave(0x0406);
12974 + phy_stacksave(0x04C0);
12975 + phy_stacksave(0x04C1);
12977 + phy_stacksave(0x0033);
12978 + phy_stacksave(0x04A7);
12979 + phy_stacksave(0x04A3);
12980 + phy_stacksave(0x04A9);
12981 + phy_stacksave(0x04AA);
12982 + phy_stacksave(0x04AC);
12983 + phy_stacksave(0x0493);
12984 + phy_stacksave(0x04A1);
12985 + phy_stacksave(0x04A0);
12986 + phy_stacksave(0x04A2);
12987 + phy_stacksave(0x048A);
12988 + phy_stacksave(0x04A8);
12989 + phy_stacksave(0x04AB);
12990 + if (phy->rev == 2) {
12991 + phy_stacksave(0x04AD);
12992 + phy_stacksave(0x04AE);
12993 + } else if (phy->rev >= 3) {
12994 + phy_stacksave(0x04AD);
12995 + phy_stacksave(0x0415);
12996 + phy_stacksave(0x0416);
12997 + phy_stacksave(0x0417);
12998 + ilt_stacksave(0x1A00 + 0x2);
12999 + ilt_stacksave(0x1A00 + 0x3);
13001 + phy_stacksave(0x042B);
13002 + phy_stacksave(0x048C);
13004 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
13005 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
13007 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13008 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS)
13009 + & 0xFFFC) | 0x0002);
13011 + bcm43xx_phy_write(bcm, 0x0033, 0x0800);
13012 + bcm43xx_phy_write(bcm, 0x04A3, 0x2027);
13013 + bcm43xx_phy_write(bcm, 0x04A9, 0x1CA8);
13014 + bcm43xx_phy_write(bcm, 0x0493, 0x287A);
13015 + bcm43xx_phy_write(bcm, 0x04AA, 0x1CA8);
13016 + bcm43xx_phy_write(bcm, 0x04AC, 0x287A);
13018 + bcm43xx_phy_write(bcm, 0x04A0,
13019 + (bcm43xx_phy_read(bcm, 0x04A0)
13020 + & 0xFFC0) | 0x001A);
13021 + bcm43xx_phy_write(bcm, 0x04A7, 0x000D);
13023 + if (phy->rev < 2) {
13024 + bcm43xx_phy_write(bcm, 0x0406, 0xFF0D);
13025 + } else if (phy->rev == 2) {
13026 + bcm43xx_phy_write(bcm, 0x04C0, 0xFFFF);
13027 + bcm43xx_phy_write(bcm, 0x04C1, 0x00A9);
13029 + bcm43xx_phy_write(bcm, 0x04C0, 0x00C1);
13030 + bcm43xx_phy_write(bcm, 0x04C1, 0x0059);
13033 + bcm43xx_phy_write(bcm, 0x04A1,
13034 + (bcm43xx_phy_read(bcm, 0x04A1)
13035 + & 0xC0FF) | 0x1800);
13036 + bcm43xx_phy_write(bcm, 0x04A1,
13037 + (bcm43xx_phy_read(bcm, 0x04A1)
13038 + & 0xFFC0) | 0x0015);
13039 + bcm43xx_phy_write(bcm, 0x04A8,
13040 + (bcm43xx_phy_read(bcm, 0x04A8)
13041 + & 0xCFFF) | 0x1000);
13042 + bcm43xx_phy_write(bcm, 0x04A8,
13043 + (bcm43xx_phy_read(bcm, 0x04A8)
13044 + & 0xF0FF) | 0x0A00);
13045 + bcm43xx_phy_write(bcm, 0x04AB,
13046 + (bcm43xx_phy_read(bcm, 0x04AB)
13047 + & 0xCFFF) | 0x1000);
13048 + bcm43xx_phy_write(bcm, 0x04AB,
13049 + (bcm43xx_phy_read(bcm, 0x04AB)
13050 + & 0xF0FF) | 0x0800);
13051 + bcm43xx_phy_write(bcm, 0x04AB,
13052 + (bcm43xx_phy_read(bcm, 0x04AB)
13053 + & 0xFFCF) | 0x0010);
13054 + bcm43xx_phy_write(bcm, 0x04AB,
13055 + (bcm43xx_phy_read(bcm, 0x04AB)
13056 + & 0xFFF0) | 0x0005);
13057 + bcm43xx_phy_write(bcm, 0x04A8,
13058 + (bcm43xx_phy_read(bcm, 0x04A8)
13059 + & 0xFFCF) | 0x0010);
13060 + bcm43xx_phy_write(bcm, 0x04A8,
13061 + (bcm43xx_phy_read(bcm, 0x04A8)
13062 + & 0xFFF0) | 0x0006);
13063 + bcm43xx_phy_write(bcm, 0x04A2,
13064 + (bcm43xx_phy_read(bcm, 0x04A2)
13065 + & 0xF0FF) | 0x0800);
13066 + bcm43xx_phy_write(bcm, 0x04A0,
13067 + (bcm43xx_phy_read(bcm, 0x04A0)
13068 + & 0xF0FF) | 0x0500);
13069 + bcm43xx_phy_write(bcm, 0x04A2,
13070 + (bcm43xx_phy_read(bcm, 0x04A2)
13071 + & 0xFFF0) | 0x000B);
13073 + if (phy->rev >= 3) {
13074 + bcm43xx_phy_write(bcm, 0x048A,
13075 + bcm43xx_phy_read(bcm, 0x048A)
13077 + bcm43xx_phy_write(bcm, 0x0415,
13078 + (bcm43xx_phy_read(bcm, 0x0415)
13079 + & 0x8000) | 0x36D8);
13080 + bcm43xx_phy_write(bcm, 0x0416,
13081 + (bcm43xx_phy_read(bcm, 0x0416)
13082 + & 0x8000) | 0x36D8);
13083 + bcm43xx_phy_write(bcm, 0x0417,
13084 + (bcm43xx_phy_read(bcm, 0x0417)
13085 + & 0xFE00) | 0x016D);
13087 + bcm43xx_phy_write(bcm, 0x048A,
13088 + bcm43xx_phy_read(bcm, 0x048A)
13090 + bcm43xx_phy_write(bcm, 0x048A,
13091 + (bcm43xx_phy_read(bcm, 0x048A)
13092 + & 0x9FFF) | 0x2000);
13093 + tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13094 + BCM43xx_UCODEFLAGS_OFFSET);
13095 + if (!(tmp32 & 0x800)) {
13097 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13098 + BCM43xx_UCODEFLAGS_OFFSET,
13102 + if (phy->rev >= 2) {
13103 + bcm43xx_phy_write(bcm, 0x042B,
13104 + bcm43xx_phy_read(bcm, 0x042B)
13107 + bcm43xx_phy_write(bcm, 0x048C,
13108 + (bcm43xx_phy_read(bcm, 0x048C)
13109 + & 0xF0FF) | 0x0200);
13110 + if (phy->rev == 2) {
13111 + bcm43xx_phy_write(bcm, 0x04AE,
13112 + (bcm43xx_phy_read(bcm, 0x04AE)
13113 + & 0xFF00) | 0x007F);
13114 + bcm43xx_phy_write(bcm, 0x04AD,
13115 + (bcm43xx_phy_read(bcm, 0x04AD)
13116 + & 0x00FF) | 0x1300);
13117 + } else if (phy->rev >= 6) {
13118 + bcm43xx_ilt_write(bcm, 0x1A00 + 0x3, 0x007F);
13119 + bcm43xx_ilt_write(bcm, 0x1A00 + 0x2, 0x007F);
13120 + bcm43xx_phy_write(bcm, 0x04AD,
13121 + bcm43xx_phy_read(bcm, 0x04AD)
13124 + bcm43xx_calc_nrssi_slope(bcm);
13132 +bcm43xx_radio_interference_mitigation_disable(struct bcm43xx_private *bcm,
13135 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13136 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13138 + u32 *stack = radio->interfstack;
13141 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13142 + if (phy->rev != 1) {
13143 + bcm43xx_phy_write(bcm, 0x042B,
13144 + bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
13145 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13146 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
13149 + phy_stackrestore(0x0078);
13150 + bcm43xx_calc_nrssi_threshold(bcm);
13151 + phy_stackrestore(0x0406);
13152 + bcm43xx_phy_write(bcm, 0x042B,
13153 + bcm43xx_phy_read(bcm, 0x042B) & ~0x0800);
13154 + if (!bcm->bad_frames_preempt) {
13155 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
13156 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
13159 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13160 + bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) | 0x4000);
13161 + phy_stackrestore(0x04A0);
13162 + phy_stackrestore(0x04A1);
13163 + phy_stackrestore(0x04A2);
13164 + phy_stackrestore(0x04A8);
13165 + phy_stackrestore(0x04AB);
13166 + phy_stackrestore(0x04A7);
13167 + phy_stackrestore(0x04A3);
13168 + phy_stackrestore(0x04A9);
13169 + phy_stackrestore(0x0493);
13170 + phy_stackrestore(0x04AA);
13171 + phy_stackrestore(0x04AC);
13173 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13174 + if (!(bcm43xx_phy_read(bcm, 0x0033) & 0x0800))
13177 + radio->aci_enable = 0;
13179 + phy_stackrestore(BCM43xx_PHY_RADIO_BITFIELD);
13180 + phy_stackrestore(BCM43xx_PHY_G_CRS);
13181 + phy_stackrestore(0x0033);
13182 + phy_stackrestore(0x04A3);
13183 + phy_stackrestore(0x04A9);
13184 + phy_stackrestore(0x0493);
13185 + phy_stackrestore(0x04AA);
13186 + phy_stackrestore(0x04AC);
13187 + phy_stackrestore(0x04A0);
13188 + phy_stackrestore(0x04A7);
13189 + if (phy->rev >= 2) {
13190 + phy_stackrestore(0x04C0);
13191 + phy_stackrestore(0x04C1);
13193 + phy_stackrestore(0x0406);
13194 + phy_stackrestore(0x04A1);
13195 + phy_stackrestore(0x04AB);
13196 + phy_stackrestore(0x04A8);
13197 + if (phy->rev == 2) {
13198 + phy_stackrestore(0x04AD);
13199 + phy_stackrestore(0x04AE);
13200 + } else if (phy->rev >= 3) {
13201 + phy_stackrestore(0x04AD);
13202 + phy_stackrestore(0x0415);
13203 + phy_stackrestore(0x0416);
13204 + phy_stackrestore(0x0417);
13205 + ilt_stackrestore(0x1A00 + 0x2);
13206 + ilt_stackrestore(0x1A00 + 0x3);
13208 + phy_stackrestore(0x04A2);
13209 + phy_stackrestore(0x04A8);
13210 + phy_stackrestore(0x042B);
13211 + phy_stackrestore(0x048C);
13212 + tmp32 = bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13213 + BCM43xx_UCODEFLAGS_OFFSET);
13214 + if (tmp32 & 0x800) {
13216 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13217 + BCM43xx_UCODEFLAGS_OFFSET,
13220 + bcm43xx_calc_nrssi_slope(bcm);
13227 +#undef phy_stacksave
13228 +#undef phy_stackrestore
13229 +#undef radio_stacksave
13230 +#undef radio_stackrestore
13231 +#undef ilt_stacksave
13232 +#undef ilt_stackrestore
13234 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm,
13237 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13238 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13241 + if ((phy->type != BCM43xx_PHYTYPE_G) ||
13242 + (phy->rev == 0) ||
13243 + (!phy->connected))
13246 + radio->aci_wlan_automatic = 0;
13248 + case BCM43xx_RADIO_INTERFMODE_AUTOWLAN:
13249 + radio->aci_wlan_automatic = 1;
13250 + if (radio->aci_enable)
13251 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
13253 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
13255 + case BCM43xx_RADIO_INTERFMODE_NONE:
13256 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13257 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13263 + currentmode = radio->interfmode;
13264 + if (currentmode == mode)
13266 + if (currentmode != BCM43xx_RADIO_INTERFMODE_NONE)
13267 + bcm43xx_radio_interference_mitigation_disable(bcm, currentmode);
13269 + if (mode == BCM43xx_RADIO_INTERFMODE_NONE) {
13270 + radio->aci_enable = 0;
13271 + radio->aci_hw_rssi = 0;
13273 + bcm43xx_radio_interference_mitigation_enable(bcm, mode);
13274 + radio->interfmode = mode;
13279 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm)
13281 + u16 reg, index, ret;
13283 + reg = bcm43xx_radio_read16(bcm, 0x0060);
13284 + index = (reg & 0x001E) >> 1;
13285 + ret = rcc_table[index] << 1;
13286 + ret |= (reg & 0x0001);
13292 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
13294 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13295 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13296 + u16 backup[19] = { 0 };
13299 + u32 tmp1 = 0, tmp2 = 0;
13301 + backup[0] = bcm43xx_radio_read16(bcm, 0x0043);
13302 + backup[14] = bcm43xx_radio_read16(bcm, 0x0051);
13303 + backup[15] = bcm43xx_radio_read16(bcm, 0x0052);
13304 + backup[1] = bcm43xx_phy_read(bcm, 0x0015);
13305 + backup[16] = bcm43xx_phy_read(bcm, 0x005A);
13306 + backup[17] = bcm43xx_phy_read(bcm, 0x0059);
13307 + backup[18] = bcm43xx_phy_read(bcm, 0x0058);
13308 + if (phy->type == BCM43xx_PHYTYPE_B) {
13309 + backup[2] = bcm43xx_phy_read(bcm, 0x0030);
13310 + backup[3] = bcm43xx_read16(bcm, 0x03EC);
13311 + bcm43xx_phy_write(bcm, 0x0030, 0x00FF);
13312 + bcm43xx_write16(bcm, 0x03EC, 0x3F3F);
13314 + if (phy->connected) {
13315 + backup[4] = bcm43xx_phy_read(bcm, 0x0811);
13316 + backup[5] = bcm43xx_phy_read(bcm, 0x0812);
13317 + backup[6] = bcm43xx_phy_read(bcm, 0x0814);
13318 + backup[7] = bcm43xx_phy_read(bcm, 0x0815);
13319 + backup[8] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);
13320 + backup[9] = bcm43xx_phy_read(bcm, 0x0802);
13321 + bcm43xx_phy_write(bcm, 0x0814,
13322 + (bcm43xx_phy_read(bcm, 0x0814) | 0x0003));
13323 + bcm43xx_phy_write(bcm, 0x0815,
13324 + (bcm43xx_phy_read(bcm, 0x0815) & 0xFFFC));
13325 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13326 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS) & 0x7FFF));
13327 + bcm43xx_phy_write(bcm, 0x0802,
13328 + (bcm43xx_phy_read(bcm, 0x0802) & 0xFFFC));
13329 + bcm43xx_phy_write(bcm, 0x0811, 0x01B3);
13330 + bcm43xx_phy_write(bcm, 0x0812, 0x0FB2);
13332 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13333 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) | 0x8000));
13335 + backup[10] = bcm43xx_phy_read(bcm, 0x0035);
13336 + bcm43xx_phy_write(bcm, 0x0035,
13337 + (bcm43xx_phy_read(bcm, 0x0035) & 0xFF7F));
13338 + backup[11] = bcm43xx_read16(bcm, 0x03E6);
13339 + backup[12] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);
13341 + // Initialization
13342 + if (phy->version == 0) {
13343 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
13345 + if (phy->version >= 2)
13346 + bcm43xx_write16(bcm, 0x03E6, 0x0040);
13347 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13348 + (bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) | 0x2000));
13351 + ret = bcm43xx_radio_calibrationvalue(bcm);
13353 + if (phy->type == BCM43xx_PHYTYPE_B)
13354 + bcm43xx_radio_write16(bcm, 0x0078, 0x0003);
13356 + bcm43xx_phy_write(bcm, 0x0015, 0xBFAF);
13357 + bcm43xx_phy_write(bcm, 0x002B, 0x1403);
13358 + if (phy->connected)
13359 + bcm43xx_phy_write(bcm, 0x0812, 0x00B2);
13360 + bcm43xx_phy_write(bcm, 0x0015, 0xBFA0);
13361 + bcm43xx_radio_write16(bcm, 0x0051,
13362 + (bcm43xx_radio_read16(bcm, 0x0051) | 0x0004));
13363 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
13364 + bcm43xx_radio_write16(bcm, 0x0043,
13365 + bcm43xx_radio_read16(bcm, 0x0043) | 0x0009);
13366 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13368 + for (i = 0; i < 16; i++) {
13369 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
13370 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
13371 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
13372 + if (phy->connected)
13373 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13374 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13376 + if (phy->connected)
13377 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13378 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13380 + if (phy->connected)
13381 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13382 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13384 + tmp1 += bcm43xx_phy_read(bcm, 0x002D);
13385 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13386 + if (phy->connected)
13387 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13388 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13394 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13396 + for (i = 0; i < 16; i++) {
13397 + bcm43xx_radio_write16(bcm, 0x0078, (flip_4bit(i) << 1) | 0x0020);
13398 + backup[13] = bcm43xx_radio_read16(bcm, 0x0078);
13400 + for (j = 0; j < 16; j++) {
13401 + bcm43xx_phy_write(bcm, 0x005A, 0x0D80);
13402 + bcm43xx_phy_write(bcm, 0x0059, 0xC810);
13403 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
13404 + if (phy->connected)
13405 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13406 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13408 + if (phy->connected)
13409 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13410 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13412 + if (phy->connected)
13413 + bcm43xx_phy_write(bcm, 0x0812, 0x30B3); /* 0x30B3 is not a typo */
13414 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13416 + tmp2 += bcm43xx_phy_read(bcm, 0x002D);
13417 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13418 + if (phy->connected)
13419 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13420 + bcm43xx_phy_write(bcm, 0x0015, 0xAFB0);
13428 + /* Restore the registers */
13429 + bcm43xx_phy_write(bcm, 0x0015, backup[1]);
13430 + bcm43xx_radio_write16(bcm, 0x0051, backup[14]);
13431 + bcm43xx_radio_write16(bcm, 0x0052, backup[15]);
13432 + bcm43xx_radio_write16(bcm, 0x0043, backup[0]);
13433 + bcm43xx_phy_write(bcm, 0x005A, backup[16]);
13434 + bcm43xx_phy_write(bcm, 0x0059, backup[17]);
13435 + bcm43xx_phy_write(bcm, 0x0058, backup[18]);
13436 + bcm43xx_write16(bcm, 0x03E6, backup[11]);
13437 + if (phy->version != 0)
13438 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, backup[12]);
13439 + bcm43xx_phy_write(bcm, 0x0035, backup[10]);
13440 + bcm43xx_radio_selectchannel(bcm, radio->channel, 1);
13441 + if (phy->type == BCM43xx_PHYTYPE_B) {
13442 + bcm43xx_phy_write(bcm, 0x0030, backup[2]);
13443 + bcm43xx_write16(bcm, 0x03EC, backup[3]);
13445 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13446 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) & 0x7FFF));
13447 + if (phy->connected) {
13448 + bcm43xx_phy_write(bcm, 0x0811, backup[4]);
13449 + bcm43xx_phy_write(bcm, 0x0812, backup[5]);
13450 + bcm43xx_phy_write(bcm, 0x0814, backup[6]);
13451 + bcm43xx_phy_write(bcm, 0x0815, backup[7]);
13452 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, backup[8]);
13453 + bcm43xx_phy_write(bcm, 0x0802, backup[9]);
13457 + ret = backup[13];
13462 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm)
13466 + bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
13467 + bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
13468 + bcm43xx_radio_write16(bcm, 0x0009, 0x0040);
13469 + bcm43xx_radio_write16(bcm, 0x0005, 0x00AA);
13470 + bcm43xx_radio_write16(bcm, 0x0032, 0x008F);
13471 + bcm43xx_radio_write16(bcm, 0x0006, 0x008F);
13472 + bcm43xx_radio_write16(bcm, 0x0034, 0x008F);
13473 + bcm43xx_radio_write16(bcm, 0x002C, 0x0007);
13474 + bcm43xx_radio_write16(bcm, 0x0082, 0x0080);
13475 + bcm43xx_radio_write16(bcm, 0x0080, 0x0000);
13476 + bcm43xx_radio_write16(bcm, 0x003F, 0x00DA);
13477 + bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
13478 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0010);
13479 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
13480 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020);
13483 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020) | 0x0010);
13486 + bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008) | 0x0008);
13487 + bcm43xx_radio_write16(bcm, 0x0085, bcm43xx_radio_read16(bcm, 0x0085) & ~0x0010);
13488 + bcm43xx_radio_write16(bcm, 0x0005, bcm43xx_radio_read16(bcm, 0x0005) & ~0x0008);
13489 + bcm43xx_radio_write16(bcm, 0x0081, bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040);
13490 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0040) | 0x0040);
13491 + bcm43xx_radio_write16(bcm, 0x0005, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0008) | 0x0008);
13492 + bcm43xx_phy_write(bcm, 0x0063, 0xDDC6);
13493 + bcm43xx_phy_write(bcm, 0x0069, 0x07BE);
13494 + bcm43xx_phy_write(bcm, 0x006A, 0x0000);
13496 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_A, 0);
13497 + assert(err == 0);
13502 +u16 freq_r3A_value(u16 frequency)
13506 + if (frequency < 5091)
13508 + else if (frequency < 5321)
13510 + else if (frequency < 5806)
13518 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm)
13520 + static const u8 data_high[5] = { 0x00, 0x40, 0x80, 0x90, 0xD0 };
13521 + static const u8 data_low[5] = { 0x00, 0x01, 0x05, 0x06, 0x0A };
13522 + u16 tmp = bcm43xx_radio_read16(bcm, 0x001E);
13525 + for (i = 0; i < 5; i++) {
13526 + for (j = 0; j < 5; j++) {
13527 + if (tmp == (data_high[i] << 4 | data_low[j])) {
13528 + bcm43xx_phy_write(bcm, 0x0069, (i - j) << 8 | 0x00C0);
13535 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
13537 + int synthetic_pu_workaround)
13539 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13543 + if ((radio->manufact == 0x17F) &&
13544 + (radio->version == 0x2060) &&
13545 + (radio->revision == 1)) {
13546 + if (channel > 200)
13548 + freq = channel2freq_a(channel);
13550 + r8 = bcm43xx_radio_read16(bcm, 0x0008);
13551 + bcm43xx_write16(bcm, 0x03F0, freq);
13552 + bcm43xx_radio_write16(bcm, 0x0008, r8);
13554 + TODO();//TODO: write max channel TX power? to Radio 0x2D
13555 + tmp = bcm43xx_radio_read16(bcm, 0x002E);
13557 + TODO();//TODO: OR tmp with the Power out estimation for this channel?
13558 + bcm43xx_radio_write16(bcm, 0x002E, tmp);
13560 + if (freq >= 4920 && freq <= 5500) {
13562 + * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
13563 + * = (freq * 0.025862069
13565 + r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
13567 + bcm43xx_radio_write16(bcm, 0x0007, (r8 << 4) | r8);
13568 + bcm43xx_radio_write16(bcm, 0x0020, (r8 << 4) | r8);
13569 + bcm43xx_radio_write16(bcm, 0x0021, (r8 << 4) | r8);
13570 + bcm43xx_radio_write16(bcm, 0x0022,
13571 + (bcm43xx_radio_read16(bcm, 0x0022)
13572 + & 0x000F) | (r8 << 4));
13573 + bcm43xx_radio_write16(bcm, 0x002A, (r8 << 4));
13574 + bcm43xx_radio_write16(bcm, 0x002B, (r8 << 4));
13575 + bcm43xx_radio_write16(bcm, 0x0008,
13576 + (bcm43xx_radio_read16(bcm, 0x0008)
13577 + & 0x00F0) | (r8 << 4));
13578 + bcm43xx_radio_write16(bcm, 0x0029,
13579 + (bcm43xx_radio_read16(bcm, 0x0029)
13580 + & 0xFF0F) | 0x00B0);
13581 + bcm43xx_radio_write16(bcm, 0x0035, 0x00AA);
13582 + bcm43xx_radio_write16(bcm, 0x0036, 0x0085);
13583 + bcm43xx_radio_write16(bcm, 0x003A,
13584 + (bcm43xx_radio_read16(bcm, 0x003A)
13585 + & 0xFF20) | freq_r3A_value(freq));
13586 + bcm43xx_radio_write16(bcm, 0x003D,
13587 + bcm43xx_radio_read16(bcm, 0x003D) & 0x00FF);
13588 + bcm43xx_radio_write16(bcm, 0x0081,
13589 + (bcm43xx_radio_read16(bcm, 0x0081)
13590 + & 0xFF7F) | 0x0080);
13591 + bcm43xx_radio_write16(bcm, 0x0035,
13592 + bcm43xx_radio_read16(bcm, 0x0035) & 0xFFEF);
13593 + bcm43xx_radio_write16(bcm, 0x0035,
13594 + (bcm43xx_radio_read16(bcm, 0x0035)
13595 + & 0xFFEF) | 0x0010);
13596 + bcm43xx_radio_set_tx_iq(bcm);
13597 + TODO(); //TODO: TSSI2dbm workaround
13598 + bcm43xx_phy_xmitpower(bcm);//FIXME correct?
13600 + if ((channel < 1) || (channel > 14))
13603 + if (synthetic_pu_workaround)
13604 + bcm43xx_synth_pu_workaround(bcm, channel);
13606 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
13607 + channel2freq_bg(channel));
13609 + if (channel == 14) {
13610 + if (bcm->sprom.locale == BCM43xx_LOCALE_JAPAN) {
13611 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13612 + BCM43xx_UCODEFLAGS_OFFSET,
13613 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13614 + BCM43xx_UCODEFLAGS_OFFSET)
13617 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13618 + BCM43xx_UCODEFLAGS_OFFSET,
13619 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13620 + BCM43xx_UCODEFLAGS_OFFSET)
13623 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13624 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13627 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13628 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13633 + radio->channel = channel;
13634 + //XXX: Using the longer of 2 timeouts (8000 vs 2000 usecs). Specs states
13635 + // that 2000 usecs might suffice.
13641 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val)
13646 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0022) & 0xFCFF;
13647 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0022, tmp | val);
13648 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x03A8) & 0xFCFF;
13649 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x03A8, tmp | val);
13650 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x0054) & 0xFCFF;
13651 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0054, tmp | val);
13654 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
13655 +static u16 bcm43xx_get_txgain_base_band(u16 txpower)
13659 + assert(txpower <= 63);
13661 + if (txpower >= 54)
13663 + else if (txpower >= 49)
13665 + else if (txpower >= 44)
13673 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
13674 +static u16 bcm43xx_get_txgain_freq_power_amp(u16 txpower)
13678 + assert(txpower <= 63);
13680 + if (txpower >= 32)
13682 + else if (txpower >= 25)
13684 + else if (txpower >= 20)
13686 + else if (txpower >= 12)
13694 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
13695 +static u16 bcm43xx_get_txgain_dac(u16 txpower)
13699 + assert(txpower <= 63);
13701 + if (txpower >= 54)
13702 + ret = txpower - 53;
13703 + else if (txpower >= 49)
13704 + ret = txpower - 42;
13705 + else if (txpower >= 44)
13706 + ret = txpower - 37;
13707 + else if (txpower >= 32)
13708 + ret = txpower - 32;
13709 + else if (txpower >= 25)
13710 + ret = txpower - 20;
13711 + else if (txpower >= 20)
13712 + ret = txpower - 13;
13713 + else if (txpower >= 12)
13714 + ret = txpower - 8;
13721 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower)
13723 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13724 + u16 pamp, base, dac, ilt;
13726 + txpower = limit_value(txpower, 0, 63);
13728 + pamp = bcm43xx_get_txgain_freq_power_amp(txpower);
13731 + bcm43xx_phy_write(bcm, 0x0019, pamp);
13733 + base = bcm43xx_get_txgain_base_band(txpower);
13735 + bcm43xx_phy_write(bcm, 0x0017, base | 0x0020);
13737 + ilt = bcm43xx_ilt_read(bcm, 0x3001);
13740 + dac = bcm43xx_get_txgain_dac(txpower);
13744 + bcm43xx_ilt_write(bcm, 0x3001, dac);
13746 + radio->txpwr_offset = txpower;
13749 + //TODO: FuncPlaceholder (Adjust BB loft cancel)
13752 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
13753 + u16 baseband_attenuation, u16 radio_attenuation,
13756 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13757 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13759 + if (baseband_attenuation == 0xFFFF)
13760 + baseband_attenuation = radio->baseband_atten;
13761 + if (radio_attenuation == 0xFFFF)
13762 + radio_attenuation = radio->radio_atten;
13763 + if (txpower == 0xFFFF)
13764 + txpower = radio->txctl1;
13765 + radio->baseband_atten = baseband_attenuation;
13766 + radio->radio_atten = radio_attenuation;
13767 + radio->txctl1 = txpower;
13769 + assert(/*baseband_attenuation >= 0 &&*/ baseband_attenuation <= 11);
13770 + if (radio->revision < 6)
13771 + assert(/*radio_attenuation >= 0 &&*/ radio_attenuation <= 9);
13773 + assert(/* radio_attenuation >= 0 &&*/ radio_attenuation <= 31);
13774 + assert(/*txpower >= 0 &&*/ txpower <= 7);
13776 + bcm43xx_phy_set_baseband_attenuation(bcm, baseband_attenuation);
13777 + bcm43xx_radio_write16(bcm, 0x0043, radio_attenuation);
13778 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0064, radio_attenuation);
13779 + if (radio->version == 0x2050) {
13780 + bcm43xx_radio_write16(bcm, 0x0052,
13781 + (bcm43xx_radio_read16(bcm, 0x0052) & ~0x0070)
13782 + | ((txpower << 4) & 0x0070));
13784 + //FIXME: The spec is very weird and unclear here.
13785 + if (phy->type == BCM43xx_PHYTYPE_G)
13786 + bcm43xx_phy_lo_adjust(bcm, 0);
13789 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm)
13791 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13793 + if (radio->version == 0x2050 && radio->revision < 6)
13798 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm)
13800 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13801 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13802 + u16 att = 0xFFFF;
13804 + if (phy->type == BCM43xx_PHYTYPE_A)
13807 + switch (radio->version) {
13809 + switch (radio->revision) {
13816 + switch (radio->revision) {
13821 + if (phy->type == BCM43xx_PHYTYPE_G) {
13822 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13823 + bcm->board_type == 0x421 &&
13824 + bcm->board_revision >= 30)
13826 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13827 + bcm->board_type == 0x416)
13832 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13833 + bcm->board_type == 0x421 &&
13834 + bcm->board_revision >= 30)
13841 + if (phy->type == BCM43xx_PHYTYPE_G) {
13842 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13843 + bcm->board_type == 0x421 &&
13844 + bcm->board_revision >= 30)
13846 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13847 + bcm->board_type == 0x416)
13849 + else if (bcm->chip_id == 0x4320)
13875 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13876 + bcm->board_type == 0x421) {
13877 + if (bcm->board_revision < 0x43)
13879 + else if (bcm->board_revision < 0x51)
13882 + if (att == 0xFFFF)
13888 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm)
13890 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13892 + if (radio->version != 0x2050)
13894 + if (radio->revision == 1)
13896 + if (radio->revision < 6)
13898 + if (radio->revision == 8)
13903 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
13905 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13906 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13909 + if (radio->enabled)
13912 + switch (phy->type) {
13913 + case BCM43xx_PHYTYPE_A:
13914 + bcm43xx_radio_write16(bcm, 0x0004, 0x00C0);
13915 + bcm43xx_radio_write16(bcm, 0x0005, 0x0008);
13916 + bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) & 0xFFF7);
13917 + bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) & 0xFFF7);
13918 + bcm43xx_radio_init2060(bcm);
13920 + case BCM43xx_PHYTYPE_B:
13921 + case BCM43xx_PHYTYPE_G:
13922 + bcm43xx_phy_write(bcm, 0x0015, 0x8000);
13923 + bcm43xx_phy_write(bcm, 0x0015, 0xCC00);
13924 + bcm43xx_phy_write(bcm, 0x0015, (phy->connected ? 0x00C0 : 0x0000));
13925 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 1);
13926 + assert(err == 0);
13931 + radio->enabled = 1;
13932 + dprintk(KERN_INFO PFX "Radio turned on\n");
13935 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
13937 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13938 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13940 + if (phy->type == BCM43xx_PHYTYPE_A) {
13941 + bcm43xx_radio_write16(bcm, 0x0004, 0x00FF);
13942 + bcm43xx_radio_write16(bcm, 0x0005, 0x00FB);
13943 + bcm43xx_phy_write(bcm, 0x0010, bcm43xx_phy_read(bcm, 0x0010) | 0x0008);
13944 + bcm43xx_phy_write(bcm, 0x0011, bcm43xx_phy_read(bcm, 0x0011) | 0x0008);
13946 + if (phy->type == BCM43xx_PHYTYPE_G && bcm->current_core->rev >= 5) {
13947 + bcm43xx_phy_write(bcm, 0x0811, bcm43xx_phy_read(bcm, 0x0811) | 0x008C);
13948 + bcm43xx_phy_write(bcm, 0x0812, bcm43xx_phy_read(bcm, 0x0812) & 0xFF73);
13950 + bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
13951 + radio->enabled = 0;
13952 + dprintk(KERN_INFO PFX "Radio turned off\n");
13955 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
13957 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13959 + switch (phy->type) {
13960 + case BCM43xx_PHYTYPE_A:
13961 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0068, 0x7F7F);
13962 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x006a, 0x7F7F);
13964 + case BCM43xx_PHYTYPE_B:
13965 + case BCM43xx_PHYTYPE_G:
13966 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0058, 0x7F7F);
13967 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x005a, 0x7F7F);
13968 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0070, 0x7F7F);
13969 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0072, 0x7F7F);
13973 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
13974 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h 1970-01-01 01:00:00.000000000 +0100
13975 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_radio.h 2006-03-28 22:16:14.000000000 +0200
13979 + Broadcom BCM43xx wireless driver
13981 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
13982 + Stefano Brivio <st3@riseup.net>
13983 + Michael Buesch <mbuesch@freenet.de>
13984 + Danny van Dyk <kugelfang@gentoo.org>
13985 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
13987 + Some parts of the code in this file are derived from the ipw2200
13988 + driver Copyright(c) 2003 - 2004 Intel Corporation.
13990 + This program is free software; you can redistribute it and/or modify
13991 + it under the terms of the GNU General Public License as published by
13992 + the Free Software Foundation; either version 2 of the License, or
13993 + (at your option) any later version.
13995 + This program is distributed in the hope that it will be useful,
13996 + but WITHOUT ANY WARRANTY; without even the implied warranty of
13997 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13998 + GNU General Public License for more details.
14000 + You should have received a copy of the GNU General Public License
14001 + along with this program; see the file COPYING. If not, write to
14002 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
14003 + Boston, MA 02110-1301, USA.
14007 +#ifndef BCM43xx_RADIO_H_
14008 +#define BCM43xx_RADIO_H_
14010 +#include "bcm43xx.h"
14013 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_A 36
14014 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_BG 6
14016 +/* Force antenna 0. */
14017 +#define BCM43xx_RADIO_TXANTENNA_0 0
14018 +/* Force antenna 1. */
14019 +#define BCM43xx_RADIO_TXANTENNA_1 1
14020 +/* Use the RX antenna, that was selected for the most recently
14021 + * received good PLCP header.
14023 +#define BCM43xx_RADIO_TXANTENNA_LASTPLCP 3
14024 +#define BCM43xx_RADIO_TXANTENNA_DEFAULT BCM43xx_RADIO_TXANTENNA_LASTPLCP
14026 +#define BCM43xx_RADIO_INTERFMODE_NONE 0
14027 +#define BCM43xx_RADIO_INTERFMODE_NONWLAN 1
14028 +#define BCM43xx_RADIO_INTERFMODE_MANUALWLAN 2
14029 +#define BCM43xx_RADIO_INTERFMODE_AUTOWLAN 3
14032 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm);
14033 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm);
14035 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset);
14036 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val);
14038 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm);
14039 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
14041 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
14042 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
14044 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
14045 + int synthetic_pu_workaround);
14047 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower);
14048 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
14049 + u16 baseband_attenuation, u16 attenuation,
14052 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm);
14053 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm);
14054 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm);
14056 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val);
14058 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm);
14060 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel);
14061 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm);
14063 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm, int mode);
14065 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm);
14066 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm);
14067 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset);
14068 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val);
14069 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val);
14070 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm);
14072 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm);
14073 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm);
14075 +#endif /* BCM43xx_RADIO_H_ */
14076 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
14077 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c 1970-01-01 01:00:00.000000000 +0100
14078 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.c 2006-03-28 22:16:14.000000000 +0200
14082 + Broadcom BCM43xx wireless driver
14084 + SYSFS support routines
14086 + Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
14088 + This program is free software; you can redistribute it and/or modify
14089 + it under the terms of the GNU General Public License as published by
14090 + the Free Software Foundation; either version 2 of the License, or
14091 + (at your option) any later version.
14093 + This program is distributed in the hope that it will be useful,
14094 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14095 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14096 + GNU General Public License for more details.
14098 + You should have received a copy of the GNU General Public License
14099 + along with this program; see the file COPYING. If not, write to
14100 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
14101 + Boston, MA 02110-1301, USA.
14105 +#include "bcm43xx_sysfs.h"
14106 +#include "bcm43xx.h"
14107 +#include "bcm43xx_main.h"
14108 +#include "bcm43xx_radio.h"
14110 +#include <linux/capability.h>
14113 +#define GENERIC_FILESIZE 64
14116 +static int get_integer(const char *buf, size_t count)
14118 + char tmp[10 + 1] = { 0 };
14119 + int ret = -EINVAL;
14123 + count = min(count, (size_t)10);
14124 + memcpy(tmp, buf, count);
14125 + ret = simple_strtol(tmp, NULL, 10);
14130 +static int get_boolean(const char *buf, size_t count)
14132 + if (count != 0) {
14133 + if (buf[0] == '1')
14135 + if (buf[0] == '0')
14137 + if (count >= 4 && memcmp(buf, "true", 4) == 0)
14139 + if (count >= 5 && memcmp(buf, "false", 5) == 0)
14141 + if (count >= 3 && memcmp(buf, "yes", 3) == 0)
14143 + if (count >= 2 && memcmp(buf, "no", 2) == 0)
14145 + if (count >= 2 && memcmp(buf, "on", 2) == 0)
14147 + if (count >= 3 && memcmp(buf, "off", 3) == 0)
14153 +static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
14154 + struct device_attribute *attr,
14157 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14159 + unsigned long flags;
14162 + if (!capable(CAP_NET_ADMIN))
14165 + assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
14166 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14170 + bcm43xx_lock_mmio(bcm, flags);
14171 + assert(bcm->initialized);
14172 + err = bcm43xx_sprom_read(bcm, sprom);
14174 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
14175 + buf[i * 2] = sprom[i] & 0x00FF;
14176 + buf[i * 2 + 1] = (sprom[i] & 0xFF00) >> 8;
14179 + bcm43xx_unlock_mmio(bcm, flags);
14182 + return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
14185 +static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
14186 + struct device_attribute *attr,
14187 + const char *buf, size_t count)
14189 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14191 + unsigned long flags;
14194 + if (!capable(CAP_NET_ADMIN))
14197 + if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
14199 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14203 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
14204 + sprom[i] = buf[i * 2] & 0xFF;
14205 + sprom[i] |= ((u16)(buf[i * 2 + 1] & 0xFF)) << 8;
14207 + bcm43xx_lock_mmio(bcm, flags);
14208 + assert(bcm->initialized);
14209 + err = bcm43xx_sprom_write(bcm, sprom);
14210 + bcm43xx_unlock_mmio(bcm, flags);
14213 + return err ? err : count;
14217 +static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
14218 + struct device_attribute *attr,
14221 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14222 + unsigned long flags;
14224 + ssize_t count = 0;
14226 + if (!capable(CAP_NET_ADMIN))
14229 + bcm43xx_lock(bcm, flags);
14230 + assert(bcm->initialized);
14232 + switch (bcm43xx_current_radio(bcm)->interfmode) {
14233 + case BCM43xx_RADIO_INTERFMODE_NONE:
14234 + count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
14236 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
14237 + count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
14239 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
14240 + count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
14247 + bcm43xx_unlock(bcm, flags);
14249 + return err ? err : count;
14253 +static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
14254 + struct device_attribute *attr,
14255 + const char *buf, size_t count)
14257 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14258 + unsigned long flags;
14262 + if (!capable(CAP_NET_ADMIN))
14265 + mode = get_integer(buf, count);
14268 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
14271 + mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
14274 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
14277 + mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
14283 + bcm43xx_lock_mmio(bcm, flags);
14284 + assert(bcm->initialized);
14286 + err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
14288 + printk(KERN_ERR PFX "Interference Mitigation not "
14289 + "supported by device\n");
14292 + bcm43xx_unlock_mmio(bcm, flags);
14294 + return err ? err : count;
14297 +static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
14298 + struct device_attribute *attr,
14301 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14302 + unsigned long flags;
14306 + if (!capable(CAP_NET_ADMIN))
14309 + bcm43xx_lock(bcm, flags);
14310 + assert(bcm->initialized);
14312 + if (bcm->short_preamble)
14313 + count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
14315 + count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
14318 + bcm43xx_unlock(bcm, flags);
14320 + return err ? err : count;
14323 +static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
14324 + struct device_attribute *attr,
14325 + const char *buf, size_t count)
14327 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14328 + unsigned long flags;
14332 + if (!capable(CAP_NET_ADMIN))
14335 + value = get_boolean(buf, count);
14338 + bcm43xx_lock(bcm, flags);
14339 + assert(bcm->initialized);
14341 + bcm->short_preamble = !!value;
14344 + bcm43xx_unlock(bcm, flags);
14346 + return err ? err : count;
14349 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
14351 + struct device *dev = &bcm->pci_dev->dev;
14352 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14355 + assert(bcm->initialized);
14357 + sysfs->attr_sprom.attr.name = "sprom";
14358 + sysfs->attr_sprom.attr.owner = THIS_MODULE;
14359 + sysfs->attr_sprom.attr.mode = 0600;
14360 + sysfs->attr_sprom.show = bcm43xx_attr_sprom_show;
14361 + sysfs->attr_sprom.store = bcm43xx_attr_sprom_store;
14362 + err = device_create_file(dev, &sysfs->attr_sprom);
14366 + sysfs->attr_interfmode.attr.name = "interference";
14367 + sysfs->attr_interfmode.attr.owner = THIS_MODULE;
14368 + sysfs->attr_interfmode.attr.mode = 0600;
14369 + sysfs->attr_interfmode.show = bcm43xx_attr_interfmode_show;
14370 + sysfs->attr_interfmode.store = bcm43xx_attr_interfmode_store;
14371 + err = device_create_file(dev, &sysfs->attr_interfmode);
14373 + goto err_remove_sprom;
14375 + sysfs->attr_preamble.attr.name = "shortpreamble";
14376 + sysfs->attr_preamble.attr.owner = THIS_MODULE;
14377 + sysfs->attr_preamble.attr.mode = 0600;
14378 + sysfs->attr_preamble.show = bcm43xx_attr_preamble_show;
14379 + sysfs->attr_preamble.store = bcm43xx_attr_preamble_store;
14380 + err = device_create_file(dev, &sysfs->attr_preamble);
14382 + goto err_remove_interfmode;
14386 +err_remove_interfmode:
14387 + device_remove_file(dev, &sysfs->attr_interfmode);
14389 + device_remove_file(dev, &sysfs->attr_sprom);
14393 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
14395 + struct device *dev = &bcm->pci_dev->dev;
14396 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14398 + device_remove_file(dev, &sysfs->attr_preamble);
14399 + device_remove_file(dev, &sysfs->attr_interfmode);
14400 + device_remove_file(dev, &sysfs->attr_sprom);
14402 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
14403 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h 1970-01-01 01:00:00.000000000 +0100
14404 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_sysfs.h 2006-03-28 22:16:14.000000000 +0200
14406 +#ifndef BCM43xx_SYSFS_H_
14407 +#define BCM43xx_SYSFS_H_
14409 +#include <linux/device.h>
14412 +struct bcm43xx_sysfs {
14413 + struct device_attribute attr_sprom;
14414 + struct device_attribute attr_interfmode;
14415 + struct device_attribute attr_preamble;
14418 +#define devattr_to_bcm(attr, attr_name) ({ \
14419 + struct bcm43xx_sysfs *__s; struct bcm43xx_private *__p; \
14420 + __s = container_of((attr), struct bcm43xx_sysfs, attr_name); \
14421 + __p = container_of(__s, struct bcm43xx_private, sysfs); \
14425 +struct bcm43xx_private;
14427 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
14428 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
14430 +#endif /* BCM43xx_SYSFS_H_ */
14431 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
14432 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c 1970-01-01 01:00:00.000000000 +0100
14433 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.c 2006-03-28 22:16:14.000000000 +0200
14437 + Broadcom BCM43xx wireless driver
14439 + Transmission (TX/RX) related functions.
14441 + Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
14442 + Stefano Brivio <st3@riseup.net>
14443 + Michael Buesch <mbuesch@freenet.de>
14444 + Danny van Dyk <kugelfang@gentoo.org>
14445 + Andreas Jaggi <andreas.jaggi@waterwave.ch>
14447 + This program is free software; you can redistribute it and/or modify
14448 + it under the terms of the GNU General Public License as published by
14449 + the Free Software Foundation; either version 2 of the License, or
14450 + (at your option) any later version.
14452 + This program is distributed in the hope that it will be useful,
14453 + but WITHOUT ANY WARRANTY; without even the implied warranty of
14454 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14455 + GNU General Public License for more details.
14457 + You should have received a copy of the GNU General Public License
14458 + along with this program; see the file COPYING. If not, write to
14459 + the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
14460 + Boston, MA 02110-1301, USA.
14464 +#include "bcm43xx_xmit.h"
14467 +/* Extract the bitrate out of a CCK PLCP header. */
14468 +static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr4 *plcp)
14470 + switch (plcp->raw[0]) {
14472 + return BCM43xx_CCK_RATE_1MB;
14474 + return BCM43xx_CCK_RATE_2MB;
14476 + return BCM43xx_CCK_RATE_5MB;
14478 + return BCM43xx_CCK_RATE_11MB;
14484 +/* Extract the bitrate out of an OFDM PLCP header. */
14485 +static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr4 *plcp)
14487 + switch (plcp->raw[0] & 0xF) {
14489 + return BCM43xx_OFDM_RATE_6MB;
14491 + return BCM43xx_OFDM_RATE_9MB;
14493 + return BCM43xx_OFDM_RATE_12MB;
14495 + return BCM43xx_OFDM_RATE_18MB;
14497 + return BCM43xx_OFDM_RATE_24MB;
14499 + return BCM43xx_OFDM_RATE_36MB;
14501 + return BCM43xx_OFDM_RATE_48MB;
14503 + return BCM43xx_OFDM_RATE_54MB;
14509 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
14511 + switch (bitrate) {
14512 + case BCM43xx_CCK_RATE_1MB:
14514 + case BCM43xx_CCK_RATE_2MB:
14516 + case BCM43xx_CCK_RATE_5MB:
14518 + case BCM43xx_CCK_RATE_11MB:
14525 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
14527 + switch (bitrate) {
14528 + case BCM43xx_OFDM_RATE_6MB:
14530 + case BCM43xx_OFDM_RATE_9MB:
14532 + case BCM43xx_OFDM_RATE_12MB:
14534 + case BCM43xx_OFDM_RATE_18MB:
14536 + case BCM43xx_OFDM_RATE_24MB:
14538 + case BCM43xx_OFDM_RATE_36MB:
14540 + case BCM43xx_OFDM_RATE_48MB:
14542 + case BCM43xx_OFDM_RATE_54MB:
14549 +static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
14550 + const u16 octets, const u8 bitrate,
14551 + const int ofdm_modulation)
14553 + __le32 *data = &(plcp->data);
14554 + __u8 *raw = plcp->raw;
14556 + if (ofdm_modulation) {
14557 + *data = bcm43xx_plcp_get_ratecode_ofdm(bitrate);
14558 + assert(!(octets & 0xF000));
14559 + *data |= (octets << 5);
14560 + *data = cpu_to_le32(*data);
14564 + plen = octets * 16 / bitrate;
14565 + if ((octets * 16 % bitrate) > 0) {
14567 + if ((bitrate == BCM43xx_CCK_RATE_11MB)
14568 + && ((octets * 8 % 11) < 4)) {
14574 + *data |= cpu_to_le32(plen << 16);
14575 + raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
14579 +static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
14581 + switch (bitrate) {
14582 + case BCM43xx_CCK_RATE_1MB:
14583 + return BCM43xx_CCK_RATE_1MB;
14584 + case BCM43xx_CCK_RATE_2MB:
14585 + return BCM43xx_CCK_RATE_1MB;
14586 + case BCM43xx_CCK_RATE_5MB:
14587 + return BCM43xx_CCK_RATE_2MB;
14588 + case BCM43xx_CCK_RATE_11MB:
14589 + return BCM43xx_CCK_RATE_5MB;
14590 + case BCM43xx_OFDM_RATE_6MB:
14591 + return BCM43xx_CCK_RATE_5MB;
14592 + case BCM43xx_OFDM_RATE_9MB:
14593 + return BCM43xx_OFDM_RATE_6MB;
14594 + case BCM43xx_OFDM_RATE_12MB:
14595 + return BCM43xx_OFDM_RATE_9MB;
14596 + case BCM43xx_OFDM_RATE_18MB:
14597 + return BCM43xx_OFDM_RATE_12MB;
14598 + case BCM43xx_OFDM_RATE_24MB:
14599 + return BCM43xx_OFDM_RATE_18MB;
14600 + case BCM43xx_OFDM_RATE_36MB:
14601 + return BCM43xx_OFDM_RATE_24MB;
14602 + case BCM43xx_OFDM_RATE_48MB:
14603 + return BCM43xx_OFDM_RATE_36MB;
14604 + case BCM43xx_OFDM_RATE_54MB:
14605 + return BCM43xx_OFDM_RATE_48MB;
14612 +__le16 bcm43xx_calc_duration_id(const struct ieee80211_hdr *wireless_header,
14615 + const u16 frame_ctl = le16_to_cpu(wireless_header->frame_control);
14616 + __le16 duration_id = wireless_header->duration_id;
14618 + switch (WLAN_FC_GET_TYPE(frame_ctl)) {
14619 + case WLAN_FC_TYPE_DATA:
14620 + case WLAN_FC_TYPE_MGMT:
14621 + //TODO: Steal the code from ieee80211, once it is completed there.
14623 + case WLAN_FC_TYPE_CTRL:
14624 + /* Use the original duration/id. */
14630 + return duration_id;
14634 +u16 ceiling_div(u16 dividend, u16 divisor)
14636 + return ((dividend + divisor - 1) / divisor);
14639 +static void bcm43xx_generate_rts(const struct bcm43xx_phyinfo *phy,
14640 + struct bcm43xx_txhdr *txhdr,
14643 + const struct ieee80211_hdr *wlhdr)
14647 + u8 fallback_bitrate;
14648 + int ofdm_modulation;
14649 + int fallback_ofdm_modulation;
14653 + sa = ieee80211_get_SA((struct ieee80211_hdr *)wlhdr);
14654 + da = ieee80211_get_DA((struct ieee80211_hdr *)wlhdr);
14655 + fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
14656 + ofdm_modulation = !(bcm43xx_is_cck_rate(bitrate));
14657 + fallback_ofdm_modulation = !(bcm43xx_is_cck_rate(fallback_bitrate));
14659 + flen = sizeof(u16) + sizeof(u16) + ETH_ALEN + ETH_ALEN + FCS_LEN,
14660 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_plcp),
14662 + !bcm43xx_is_cck_rate(bitrate));
14663 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->rts_cts_fallback_plcp),
14664 + flen, fallback_bitrate,
14665 + !bcm43xx_is_cck_rate(fallback_bitrate));
14666 + fctl = WLAN_FC_TYPE_CTRL << 2;
14667 + fctl |= WLAN_FC_STYPE_RTS << 4;
14668 + dur = le16_to_cpu(wlhdr->duration_id);
14669 +/*FIXME: should we test for dur==0 here and let it unmodified in this case?
14670 + * The following assert checks for this case...
14673 +/*FIXME: The duration calculation is not really correct.
14674 + * I am not 100% sure which bitrate to use. We use the RTS rate here,
14675 + * but this is likely to be wrong.
14677 + if (phy->type == BCM43xx_PHYTYPE_A) {
14678 + /* Three times SIFS */
14680 + /* Add ACK duration. */
14681 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14683 + /* Add CTS duration. */
14684 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14687 + /* Three times SIFS */
14689 + /* Add ACK duration. */
14690 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14692 + /* Add CTS duration. */
14693 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14697 + txhdr->rts_cts_frame_control = cpu_to_le16(fctl);
14698 + txhdr->rts_cts_dur = cpu_to_le16(dur);
14699 +//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(wlhdr->addr1), BCM43xx_MACARG(wlhdr->addr2), BCM43xx_MACARG(wlhdr->addr3));
14700 +//printk(BCM43xx_MACFMT " " BCM43xx_MACFMT "\n", BCM43xx_MACARG(sa), BCM43xx_MACARG(da));
14701 + memcpy(txhdr->rts_cts_mac1, wlhdr->addr1, ETH_ALEN);//FIXME!
14702 + memcpy(txhdr->rts_cts_mac2, sa, ETH_ALEN);
14704 + *flags |= BCM43xx_TXHDRFLAG_RTSCTS;
14705 + *flags |= BCM43xx_TXHDRFLAG_RTS;
14706 + if (ofdm_modulation)
14707 + *flags |= BCM43xx_TXHDRFLAG_RTSCTS_OFDM;
14708 + if (fallback_ofdm_modulation)
14709 + *flags |= BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM;
14712 +void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
14713 + struct bcm43xx_txhdr *txhdr,
14714 + const unsigned char *fragment_data,
14715 + const unsigned int fragment_len,
14716 + const int is_first_fragment,
14717 + const u16 cookie,
14718 + struct ieee80211_tx_control *txctl)
14720 + const struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14721 + const struct ieee80211_hdr *wireless_header = (const struct ieee80211_hdr *)fragment_data;
14722 + const int use_encryption = (!txctl->do_not_encrypt && txctl->key_idx >= 0);
14724 + u8 fallback_bitrate;
14725 + int ofdm_modulation;
14726 + int fallback_ofdm_modulation;
14727 + u16 plcp_fragment_len = fragment_len;
14730 + u16 wsec_rate = 0;
14732 + /* Now construct the TX header. */
14733 + memset(txhdr, 0, sizeof(*txhdr));
14735 + bitrate = txctl->tx_rate;
14736 + ofdm_modulation = !(bcm43xx_is_cck_rate(bitrate));
14737 + fallback_bitrate = bcm43xx_calc_fallback_rate(bitrate);
14738 + fallback_ofdm_modulation = !(bcm43xx_is_cck_rate(fallback_bitrate));
14740 + /* Set Frame Control from 80211 header. */
14741 + txhdr->frame_control = wireless_header->frame_control;
14742 + /* Copy address1 from 80211 header. */
14743 + memcpy(txhdr->mac1, wireless_header->addr1, 6);
14744 + /* Set the fallback duration ID. */
14745 + txhdr->fallback_dur_id = bcm43xx_calc_duration_id(wireless_header,
14746 + fallback_bitrate);
14747 + /* Set the cookie (used as driver internal ID for the frame) */
14748 + txhdr->cookie = cpu_to_le16(cookie);
14750 + /* Hardware appends FCS. */
14751 + plcp_fragment_len += FCS_LEN;
14752 + if (use_encryption) {
14753 + u16 key_idx = (u16)(txctl->key_idx);
14754 + struct bcm43xx_key *key = &(bcm->key[key_idx]);
14757 + if (key->enabled) {
14758 + /* Hardware appends ICV. */
14759 + plcp_fragment_len += txctl->icv_len;
14761 + wsec_rate |= ((key_idx & 0x000F) << 4);
14762 + wsec_rate |= key->algorithm;
14763 + wlhdr_len = ieee80211_get_hdrlen(le16_to_cpu(wireless_header->frame_control));
14764 + memcpy(txhdr->wep_iv, ((u8 *)wireless_header) + wlhdr_len, 4);
14767 + /* Generate the PLCP header and the fallback PLCP header. */
14768 + bcm43xx_generate_plcp_hdr((struct bcm43xx_plcp_hdr4 *)(&txhdr->plcp),
14769 + plcp_fragment_len,
14770 + bitrate, ofdm_modulation);
14771 + bcm43xx_generate_plcp_hdr(&txhdr->fallback_plcp, plcp_fragment_len,
14772 + fallback_bitrate, fallback_ofdm_modulation);
14774 + /* Set the CONTROL field */
14775 + if (ofdm_modulation)
14776 + control |= BCM43xx_TXHDRCTL_OFDM;
14777 + if (bcm->short_preamble) //FIXME: could be the other way around, please test
14778 + control |= BCM43xx_TXHDRCTL_SHORT_PREAMBLE;
14779 + control |= (phy->antenna_diversity << BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT)
14780 + & BCM43xx_TXHDRCTL_ANTENNADIV_MASK;
14782 + /* Set the FLAGS field */
14783 + if (!txctl->no_ack)
14784 + flags |= BCM43xx_TXHDRFLAG_EXPECTACK;
14785 + if (1 /* FIXME: PS poll?? */)
14786 + flags |= 0x10; // FIXME: unknown meaning.
14787 + if (fallback_ofdm_modulation)
14788 + flags |= BCM43xx_TXHDRFLAG_FALLBACKOFDM;
14789 + if (is_first_fragment)
14790 + flags |= BCM43xx_TXHDRFLAG_FIRSTFRAGMENT;
14792 + /* Set WSEC/RATE field */
14793 + wsec_rate |= (txhdr->plcp.raw[0] << BCM43xx_TXHDR_RATE_SHIFT)
14794 + & BCM43xx_TXHDR_RATE_MASK;
14796 + /* Generate the RTS/CTS packet, if required. */
14797 + /* FIXME: We should first try with CTS-to-self,
14798 + * if we are on 80211g. If we get too many
14799 + * failures (hidden nodes), we should switch back to RTS/CTS.
14801 + if (txctl->use_rts_cts) {
14802 + bcm43xx_generate_rts(phy, txhdr, &flags,
14803 + txctl->rts_cts_rate,
14804 + wireless_header);
14807 + txhdr->flags = cpu_to_le16(flags);
14808 + txhdr->control = cpu_to_le16(control);
14809 + txhdr->wsec_rate = cpu_to_le16(wsec_rate);
14812 +static s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm,
14813 + u8 in_rssi, int ofdm,
14814 + int adjust_2053, int adjust_2050)
14816 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14817 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14820 + switch (radio->version) {
14833 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
14834 + if (in_rssi > 63)
14836 + tmp = radio->nrssi_lt[in_rssi];
14848 + if (phy->type == BCM43xx_PHYTYPE_G &&
14854 + if (in_rssi > 127)
14855 + tmp = in_rssi - 256;
14875 +static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm,
14878 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14881 + if (phy->type == BCM43xx_PHYTYPE_A) {
14882 + //TODO: Incomplete specs.
14885 + ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
14891 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14892 + struct sk_buff *skb,
14893 + struct bcm43xx_rxhdr *rxhdr)
14895 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14896 + struct bcm43xx_plcp_hdr4 *plcp;
14897 + struct ieee80211_rx_status status;
14898 + const u16 rxflags1 = le16_to_cpu(rxhdr->flags1);
14899 + const u16 rxflags2 = le16_to_cpu(rxhdr->flags2);
14900 + const u16 rxflags3 = le16_to_cpu(rxhdr->flags3);
14901 + const int is_ofdm = !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_OFDM);
14903 + if (rxflags2 & BCM43xx_RXHDR_FLAGS2_TYPE2FRAME) {
14904 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data + 2);
14905 + /* Skip two unknown bytes and the PLCP header. */
14906 + skb_pull(skb, 2 + sizeof(struct bcm43xx_plcp_hdr6));
14908 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
14909 + /* Skip the PLCP header. */
14910 + skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
14912 + /* The SKB contains the PAYLOAD (wireless header + data)
14916 + memset(&status, 0, sizeof(status));
14917 + status.ssi = bcm43xx_rssi_postprocess(bcm, rxhdr->rssi, is_ofdm,
14918 + !!(rxflags1 & BCM43xx_RXHDR_FLAGS1_2053RSSIADJ),
14919 + !!(rxflags3 & BCM43xx_RXHDR_FLAGS3_2050RSSIADJ));
14921 + status.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
14923 + status.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
14924 + status.channel = radio->channel;
14926 + bcm->stats.last_rx = jiffies;
14927 + ieee80211_rx_irqsafe(bcm->net_dev, skb, &status);
14929 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
14930 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h 1970-01-01 01:00:00.000000000 +0100
14931 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/bcm43xx_xmit.h 2006-03-28 22:16:14.000000000 +0200
14933 +#ifndef BCM43xx_XMIT_H_
14934 +#define BCM43xx_XMIT_H_
14936 +#include "bcm43xx_main.h"
14939 +#define _bcm43xx_declare_plcp_hdr(size) \
14940 + struct bcm43xx_plcp_hdr##size { \
14943 + __u8 raw[size]; \
14944 + } __attribute__((__packed__)); \
14945 + } __attribute__((__packed__))
14947 +/* struct bcm43xx_plcp_hdr4 */
14948 +_bcm43xx_declare_plcp_hdr(4);
14949 +/* struct bcm43xx_plcp_hdr6 */
14950 +_bcm43xx_declare_plcp_hdr(6);
14952 +#undef _bcm43xx_declare_plcp_hdr
14954 +/* Device specific TX header. To be prepended to TX frames. */
14955 +struct bcm43xx_txhdr {
14959 + __le16 wsec_rate;
14960 + __le16 frame_control;
14961 + u16 unknown_zeroed_0;
14964 + u8 unknown_wsec_tkip_data[3]; //FIXME
14967 + u16 unknown_zeroed_1;
14968 + struct bcm43xx_plcp_hdr4 rts_cts_fallback_plcp;
14969 + __le16 rts_cts_dur_fallback;
14970 + struct bcm43xx_plcp_hdr4 fallback_plcp;
14971 + __le16 fallback_dur_id;
14974 + __le16 unknown_scb_stuff; //FIXME
14975 + struct bcm43xx_plcp_hdr6 rts_cts_plcp;
14976 + __le16 rts_cts_frame_control;
14977 + __le16 rts_cts_dur;
14978 + u8 rts_cts_mac1[6];
14979 + u8 rts_cts_mac2[6];
14981 + struct bcm43xx_plcp_hdr6 plcp;
14982 + } __attribute__((__packed__));
14984 + } __attribute__((__packed__));
14985 +} __attribute__((__packed__));
14987 +/* Values/Masks for the device TX header */
14988 +#define BCM43xx_TXHDRFLAG_EXPECTACK 0x0001
14989 +#define BCM43xx_TXHDRFLAG_RTSCTS 0x0002
14990 +#define BCM43xx_TXHDRFLAG_RTS 0x0004
14991 +#define BCM43xx_TXHDRFLAG_FIRSTFRAGMENT 0x0008
14992 +#define BCM43xx_TXHDRFLAG_DESTPSMODE 0x0020
14993 +#define BCM43xx_TXHDRFLAG_RTSCTS_OFDM 0x0080
14994 +#define BCM43xx_TXHDRFLAG_FALLBACKOFDM 0x0100
14995 +#define BCM43xx_TXHDRFLAG_RTSCTSFALLBACK_OFDM 0x0200
14996 +#define BCM43xx_TXHDRFLAG_CTS 0x0400
14997 +#define BCM43xx_TXHDRFLAG_FRAMEBURST 0x0800
14999 +#define BCM43xx_TXHDRCTL_OFDM 0x0001
15000 +#define BCM43xx_TXHDRCTL_SHORT_PREAMBLE 0x0010
15001 +#define BCM43xx_TXHDRCTL_ANTENNADIV_MASK 0x0030
15002 +#define BCM43xx_TXHDRCTL_ANTENNADIV_SHIFT 8
15004 +#define BCM43xx_TXHDR_RATE_MASK 0x0F00
15005 +#define BCM43xx_TXHDR_RATE_SHIFT 8
15006 +#define BCM43xx_TXHDR_RTSRATE_MASK 0xF000
15007 +#define BCM43xx_TXHDR_RTSRATE_SHIFT 12
15008 +#define BCM43xx_TXHDR_WSEC_KEYINDEX_MASK 0x00F0
15009 +#define BCM43xx_TXHDR_WSEC_KEYINDEX_SHIFT 4
15010 +#define BCM43xx_TXHDR_WSEC_ALGO_MASK 0x0003
15011 +#define BCM43xx_TXHDR_WSEC_ALGO_SHIFT 0
15013 +void bcm43xx_generate_txhdr(struct bcm43xx_private *bcm,
15014 + struct bcm43xx_txhdr *txhdr,
15015 + const unsigned char *fragment_data,
15016 + const unsigned int fragment_len,
15017 + const int is_first_fragment,
15018 + const u16 cookie,
15019 + struct ieee80211_tx_control *txctl);
15021 +/* RX header as received from the hardware. */
15022 +struct bcm43xx_rxhdr {
15023 + /* Frame Length. Must be generated explicitely in PIO mode. */
15024 + __le16 frame_length;
15026 + /* Flags field 1 */
15029 + u8 signal_quality;
15031 + /* Flags field 3 */
15033 + /* Flags field 2 */
15035 + /* Lower 16bits of the TSF at the time the frame started. */
15038 +} __attribute__((__packed__));
15040 +#define BCM43xx_RXHDR_FLAGS1_OFDM (1 << 0)
15041 +/*#define BCM43xx_RXHDR_FLAGS1_SIGNAL??? (1 << 3) FIXME */
15042 +#define BCM43xx_RXHDR_FLAGS1_SHORTPREAMBLE (1 << 7)
15043 +#define BCM43xx_RXHDR_FLAGS1_2053RSSIADJ (1 << 14)
15045 +#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
15046 +#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
15047 +/*FIXME: WEP related flags */
15049 +#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
15051 +/* Transmit Status as received from the hardware. */
15052 +struct bcm43xx_hwxmitstatus {
15060 + __le16 unknown; //FIXME
15061 +} __attribute__((__packed__));
15063 +/* Transmit Status in CPU byteorder. */
15064 +struct bcm43xx_xmitstatus {
15070 + u16 unknown; //FIXME
15073 +#define BCM43xx_TXSTAT_FLAG_ACK 0x01
15074 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x02
15075 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x04
15076 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x08
15077 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x10
15078 +#define BCM43xx_TXSTAT_FLAG_IGNORE 0x20
15079 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x40
15080 +//TODO #define BCM43xx_TXSTAT_FLAG_??? 0x80
15082 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
15083 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
15085 +void bcm43xx_rx(struct bcm43xx_private *bcm,
15086 + struct sk_buff *skb,
15087 + struct bcm43xx_rxhdr *rxhdr);
15089 +#endif /* BCM43xx_XMIT_H_ */
15090 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Kconfig linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Kconfig
15091 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Kconfig 1970-01-01 01:00:00.000000000 +0100
15092 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Kconfig 2006-03-28 22:16:14.000000000 +0200
15094 +config BCM43XX_D80211
15095 + tristate "Broadcom BCM43xx wireless support (DeviceScape stack)"
15096 + depends on PCI && D80211 && NET_RADIO && EXPERIMENTAL
15099 + This is an experimental driver for the Broadcom 43xx wireless chip,
15100 + found in the Apple Airport Extreme and various other devices.
15102 +config BCM43XX_D80211_DEBUG
15103 + bool "Broadcom BCM43xx debugging (RECOMMENDED)"
15104 + depends on BCM43XX_D80211
15107 + Broadcom 43xx debugging messages.
15108 + Say Y, because the driver is still very experimental and
15109 + this will help you get it running.
15111 +config BCM43XX_D80211_DMA
15113 +config BCM43XX_D80211_PIO
15117 + prompt "BCM43xx data transfer mode"
15118 + depends on BCM43XX_D80211
15119 + default BCM43XX_D80211_DMA_AND_PIO_MODE
15121 +config BCM43XX_D80211_DMA_AND_PIO_MODE
15123 + select BCM43XX_D80211_DMA
15124 + select BCM43XX_D80211_PIO
15126 + Include both, Direct Memory Access (DMA) and Programmed I/O (PIO)
15127 + data transfer modes.
15128 + The actually used mode is selectable through the module
15129 + parameter "pio". If the module parameter is pio=0, DMA is used.
15130 + Otherwise PIO is used. DMA is default.
15132 + If unsure, choose this option.
15134 +config BCM43XX_D80211_DMA_MODE
15135 + bool "DMA (Direct Memory Access) only"
15136 + select BCM43XX_D80211_DMA
15138 + Only include Direct Memory Access (DMA).
15139 + This reduces the size of the driver module, by omitting the PIO code.
15141 +config BCM43XX_D80211_PIO_MODE
15142 + bool "PIO (Programmed I/O) only"
15143 + select BCM43XX_D80211_PIO
15145 + Only include Programmed I/O (PIO).
15146 + This reduces the size of the driver module, by omitting the DMA code.
15147 + Please note that PIO transfers are slow (compared to DMA).
15149 + Also note that not all devices of the 43xx series support PIO.
15150 + The 4306 (Apple Airport Extreme and others) supports PIO, while
15151 + the 4318 is known to _not_ support PIO.
15153 + Only use PIO, if DMA does not work for you.
15156 diff -Nur linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Makefile linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Makefile
15157 --- linux-2.6.16/drivers/net/wireless/bcm43xx-d80211/Makefile 1970-01-01 01:00:00.000000000 +0100
15158 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/bcm43xx-d80211/Makefile 2006-03-28 22:16:14.000000000 +0200
15160 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211.o
15161 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DEBUG) += bcm43xx_debugfs.o
15163 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DMA) += bcm43xx_dma.o
15164 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_PIO) += bcm43xx_pio.o
15166 +bcm43xx-d80211-objs := bcm43xx_main.o bcm43xx_ilt.o \
15167 + bcm43xx_radio.o bcm43xx_phy.o \
15168 + bcm43xx_power.o bcm43xx_sysfs.o \
15169 + bcm43xx_leds.o bcm43xx_ethtool.o \
15171 + $(bcm43xx-d80211-obj-y)
15172 diff -Nur linux-2.6.16/drivers/net/wireless/Kconfig linux-2.6.16-bcm43xx/drivers/net/wireless/Kconfig
15173 --- linux-2.6.16/drivers/net/wireless/Kconfig 2006-03-20 06:53:29.000000000 +0100
15174 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/Kconfig 2006-03-28 22:16:38.000000000 +0200
15175 @@ -472,6 +472,7 @@
15176 will be called prism54.ko.
15178 source "drivers/net/wireless/hostap/Kconfig"
15179 +source "drivers/net/wireless/bcm43xx-d80211/Kconfig"
15181 # yes, this works even when no drivers are selected
15182 config NET_WIRELESS
15183 diff -Nur linux-2.6.16/drivers/net/wireless/Makefile linux-2.6.16-bcm43xx/drivers/net/wireless/Makefile
15184 --- linux-2.6.16/drivers/net/wireless/Makefile 2006-03-20 06:53:29.000000000 +0100
15185 +++ linux-2.6.16-bcm43xx/drivers/net/wireless/Makefile 2006-03-28 22:16:46.000000000 +0200
15187 obj-$(CONFIG_PRISM54) += prism54/
15189 obj-$(CONFIG_HOSTAP) += hostap/
15190 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211/
15192 # 16-bit wireless PCMCIA client drivers
15193 obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
15194 diff -Nur linux-2.6.16/include/net/d80211_common.h linux-2.6.16-bcm43xx/include/net/d80211_common.h
15195 --- linux-2.6.16/include/net/d80211_common.h 1970-01-01 01:00:00.000000000 +0100
15196 +++ linux-2.6.16-bcm43xx/include/net/d80211_common.h 2006-03-28 22:16:14.000000000 +0200
15199 + * IEEE 802.11 driver (80211.o) -- hostapd interface
15200 + * Copyright 2002-2004, Instant802 Networks, Inc.
15202 + * This program is free software; you can redistribute it and/or modify
15203 + * it under the terms of the GNU General Public License version 2 as
15204 + * published by the Free Software Foundation.
15207 +#ifndef D80211_COMMON_H
15208 +#define D80211_COMMON_H
15210 +#include <linux/types.h>
15213 + * This is common header information with user space. It is used on all
15214 + * frames sent to wlan#ap interface.
15217 +#define IEEE80211_FI_VERSION 0x80211001
15219 +struct ieee80211_frame_info {
15235 + /* Note: this structure is otherwise identical to capture format used
15236 + * in linux-wlan-ng, but this additional field is used to provide meta
15237 + * data about the frame to hostapd. This was the easiest method for
15238 + * providing this information, but this might change in the future. */
15240 +} __attribute__ ((packed));
15243 +enum ieee80211_msg_type {
15244 + ieee80211_msg_normal = 0,
15245 + ieee80211_msg_tx_callback_ack = 1,
15246 + ieee80211_msg_tx_callback_fail = 2,
15247 + ieee80211_msg_passive_scan = 3,
15248 + ieee80211_msg_wep_frame_unknown_key = 4,
15249 + ieee80211_msg_michael_mic_failure = 5,
15250 + ieee80211_msg_monitor = 6,
15251 + ieee80211_msg_sta_not_assoc = 7,
15252 + ieee80211_msg_set_aid_for_sta = 8 /* used by Intersil MVC driver */,
15253 + ieee80211_msg_key_threshold_notification = 9,
15254 + ieee80211_msg_radar = 11,
15257 +struct ieee80211_msg_set_aid_for_sta {
15258 + char sta_address[ETH_ALEN];
15262 +struct ieee80211_msg_key_notification {
15264 + char ifname[IFNAMSIZ];
15265 + u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
15269 +enum ieee80211_phytype {
15270 + ieee80211_phytype_fhss_dot11_97 = 1,
15271 + ieee80211_phytype_dsss_dot11_97 = 2,
15272 + ieee80211_phytype_irbaseband = 3,
15273 + ieee80211_phytype_dsss_dot11_b = 4,
15274 + ieee80211_phytype_pbcc_dot11_b = 5,
15275 + ieee80211_phytype_ofdm_dot11_g = 6,
15276 + ieee80211_phytype_pbcc_dot11_g = 7,
15277 + ieee80211_phytype_ofdm_dot11_a = 8,
15278 + ieee80211_phytype_dsss_dot11_turbog = 255,
15279 + ieee80211_phytype_dsss_dot11_turbo = 256,
15282 +enum ieee80211_ssi_type {
15283 + ieee80211_ssi_none = 0,
15284 + ieee80211_ssi_norm = 1, /* normalized, 0-1000 */
15285 + ieee80211_ssi_dbm = 2,
15286 + ieee80211_ssi_raw = 3, /* raw SSI */
15289 +struct ieee80211_radar_info {
15295 +#endif /* D80211_COMMON_H */
15296 diff -Nur linux-2.6.16/include/net/d80211.h linux-2.6.16-bcm43xx/include/net/d80211.h
15297 --- linux-2.6.16/include/net/d80211.h 1970-01-01 01:00:00.000000000 +0100
15298 +++ linux-2.6.16-bcm43xx/include/net/d80211.h 2006-03-28 22:16:14.000000000 +0200
15301 + * Low-level hardware driver -- IEEE 802.11 driver (80211.o) interface
15302 + * Copyright 2002-2005, Devicescape Software, Inc.
15304 + * This program is free software; you can redistribute it and/or modify
15305 + * it under the terms of the GNU General Public License version 2 as
15306 + * published by the Free Software Foundation.
15312 +#include <linux/kernel.h>
15313 +#include <linux/if_ether.h>
15314 +#include <linux/netdevice.h>
15315 +#include <linux/skbuff.h>
15316 +#include <linux/wireless.h>
15317 +#include "d80211_shared.h"
15319 +/* Note! Only ieee80211_tx_status_irqsafe() and ieee80211_rx_irqsave() can be
15320 + * called in hardware interrupt context. The low-level driver must not call any
15321 + * other functions in hardware interrupt context. If there is a need for such
15322 + * call, the low-level driver should first ACK the interrupt and perform the
15323 + * IEEE 802.11 code call after this, e.g., from a scheduled tasklet (in
15324 + * software interrupt context).
15328 + * Frame format used when passing frame between low-level hardware drivers
15329 + * and IEEE 802.11 driver the same as used in the wireless media, i.e.,
15330 + * buffers start with IEEE 802.11 header and include the same octets that
15331 + * are sent over air.
15333 + * If hardware uses IEEE 802.3 headers (and perform 802.3 <-> 802.11
15334 + * conversion in firmware), upper layer 802.11 code needs to be changed to
15337 + * If the receive frame format is not the same as the real frame sent
15338 + * on the wireless media (e.g., due to padding etc.), upper layer 802.11 code
15339 + * could be updated to provide support for such format assuming this would
15340 + * optimize the performance, e.g., by removing need to re-allocation and
15341 + * copying of the data.
15344 +/* Interface version (used for compatibility verification) */
15345 +#define IEEE80211_VERSION 2
15348 +/* Channel information structure. Low-level driver is expected to fill in chan,
15349 + * freq, and val fields. Other fields will be filled in by 80211.o based on
15350 + * hostapd information and low-level driver does not need to use them. The
15351 + * limits for each channel will be provided in 'struct ieee80211_conf' when
15352 + * configuring the low-level driver with hw->config callback. */
15353 +struct ieee80211_channel {
15354 + short chan; /* channel number (IEEE 802.11) */
15355 + short freq; /* frequency in MHz */
15356 + int val; /* hw specific value for the channel */
15357 + int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
15358 + unsigned char power_level;
15359 + unsigned char antenna_max;
15362 +struct ieee80211_rate {
15363 + int rate; /* rate in 100 kbps */
15364 + int val; /* hw specific value for the rate */
15365 + int flags; /* IEEE80211_RATE_ flags */
15366 + int val2; /* hw specific value for the rate when using short preamble
15367 + * (only when IEEE80211_RATE_PREAMBLE2 flag is set, i.e., for
15368 + * 2, 5.5, and 11 Mbps) */
15369 + signed char min_rssi_ack;
15370 + unsigned char min_rssi_ack_delta;
15372 + /* following fields are set by 80211.o and need not be filled by the
15373 + * low-level driver */
15374 + int rate_inv; /* inverse of the rate (LCM(all rates) / rate) for
15375 + * optimizing channel utilization estimates */
15378 +struct ieee80211_hw_modes {
15380 + int num_channels;
15381 + struct ieee80211_channel *channels;
15383 + struct ieee80211_rate *rates;
15384 + int xr_end; /* only used with Atheros XR */
15387 +struct ieee80211_tx_queue_params {
15388 + int aifs; /* 0 .. 255; -1 = use default */
15389 + int cw_min; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
15390 + int cw_max; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
15391 + int burst_time; /* maximum burst time in 0.1 ms (i.e., 10 = 1 ms);
15392 + * 0 = disabled */
15395 +#define NUM_TX_DATA_QUEUES 6
15397 +struct ieee80211_tx_queue_stats_data {
15398 + unsigned int len; /* num packets in queue */
15399 + unsigned int limit; /* queue len (soft) limit */
15400 + unsigned int count; /* total num frames sent */
15403 +struct ieee80211_tx_queue_stats {
15404 + struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES];
15407 +#ifndef IEEE80211_TX_QUEUE_NUMS
15408 +#define IEEE80211_TX_QUEUE_NUMS
15409 +/* TODO: these need to be synchronized with hostapd_ioctl.h; make a shared
15410 + * header file that can be included into low-level drivers, 80211.o, and
15413 + IEEE80211_TX_QUEUE_DATA0 = 0,
15414 + IEEE80211_TX_QUEUE_DATA1 = 1,
15415 + IEEE80211_TX_QUEUE_DATA2 = 2,
15416 + IEEE80211_TX_QUEUE_DATA3 = 3,
15417 + IEEE80211_TX_QUEUE_DATA4 = 4,
15418 + IEEE80211_TX_QUEUE_SVP = 5,
15419 + IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
15420 + IEEE80211_TX_QUEUE_BEACON = 7
15422 +#endif /* IEEE80211_TX_QUEUE_NUMS */
15425 +struct ieee80211_low_level_stats {
15426 + unsigned int dot11ACKFailureCount;
15427 + unsigned int dot11RTSFailureCount;
15428 + unsigned int dot11FCSErrorCount;
15429 + unsigned int dot11RTSSuccessCount;
15432 +/* Transmit control fields. This data structure is passed to low-level driver
15433 + * with each TX frame. The low-level driver is responsible of configuring
15434 + * hardware to use given values (depending on what is supported). */
15435 +#define HW_KEY_IDX_INVALID -1
15437 +struct ieee80211_tx_control {
15438 + enum { PKT_NORMAL = 0, PKT_PROBE_RESP } pkt_type;
15439 + int tx_rate; /* Transmit rate, given as the hw specific value for the
15440 + * rate (from struct ieee80211_rate) */
15441 + int rts_cts_rate; /* Transmit rate for RTS/CTS frame, given as the hw
15442 + * specific value for the rate (from
15443 + * struct ieee80211_rate) */
15444 + /* 1 = only first attempt, 2 = one retry, .. */
15445 + unsigned int retry_limit:8;
15446 + /* duration field for RTS/CTS frame */
15447 + unsigned int rts_cts_duration:16;
15448 + unsigned int req_tx_status:1; /* request TX status callback for this
15450 + unsigned int do_not_encrypt:1; /* send this frame without encryption;
15451 + * e.g., for EAPOL frames */
15452 + unsigned int use_rts_cts:1; /* Use RTS-CTS before sending frame. */
15453 + unsigned int use_cts_protect:1; /* Use CTS protection for the frame
15454 + * (e.g., for combined 802.11g /
15455 + * 802.11b networks) */
15456 + unsigned int no_ack:1; /* Tell the low level not to wait for an ack */
15457 + unsigned int rate_ctrl_probe:1;
15458 + unsigned int clear_dst_mask:1;
15459 + unsigned int requeue:1;
15460 + /* following three flags are only used with Atheros Super A/G */
15461 + unsigned int compress:1;
15462 + unsigned int turbo_prime_notify:1; /* notify HostaAPd after frame
15463 + * transmission */
15464 + unsigned int fast_frame:1;
15466 + unsigned int atheros_xr:1; /* only used with Atheros XR */
15468 + unsigned int power_level:8; /* per-packet transmit power level, in dBm
15470 + unsigned int antenna_sel:4; /* 0 = default/diversity,
15471 + * 1 = Ant0, 2 = Ant1 */
15472 + int key_idx:8; /* -1 = do not encrypt, >= 0 keyidx from hw->set_key()
15474 + int icv_len:8; /* Length of the ICV/MIC field in octets */
15475 + int iv_len:8; /* Length of the IV field in octets */
15476 + unsigned int queue:4; /* hardware queue to use for this frame;
15477 + * 0 = highest, hw->queues-1 = lowest */
15478 + unsigned int sw_retry_attempt:4; /* no. of times hw has tried to
15479 + * transmit frame (not incl. hw retries) */
15481 + int rateidx; /* internal 80211.o rateidx */
15482 + int alt_retry_rate; /* retry rate for the last retries, given as the
15483 + * hw specific value for the rate (from
15484 + * struct ieee80211_rate). To be used to limit
15485 + * packet dropping when probing higher rates, if hw
15486 + * supports multiple retry rates. -1 = not used */
15487 + struct ieee80211_sub_if_data *sdata; /* internal */
15490 +/* Stored in sk_buff->cb */
15491 +struct ieee80211_tx_packet_data {
15492 + struct ieee80211_sub_if_data *sdata;
15493 + unsigned long jiffies;
15494 + unsigned int req_tx_status:1;
15495 + unsigned int do_not_encrypt:1;
15496 + unsigned int pkt_probe_resp:1;
15497 + unsigned int requeue:1;
15498 + unsigned int queue:4;
15501 +#define RX_FLAG_MMIC_ERROR 0x1
15502 +#define RX_FLAG_DECRYPTED 0x2
15503 +#define RX_FLAG_XR_DOUBLE_CHIRP 0x4
15505 +/* Receive status. The low-level driver should provide this information
15506 + * (the subset supported by hardware) to the 802.11 code with each received
15508 +struct ieee80211_rx_status {
15511 + int freq; /* receive frequency in Mhz */
15520 +/* Transmit status. The low-level driver should provide this information
15521 + * (the subset supported by hardware) to the 802.11 code for each transmit
15523 +struct ieee80211_tx_status {
15524 + /* copied ieee80211_tx_control structure */
15525 + struct ieee80211_tx_control control;
15527 + unsigned int tx_filtered:1;
15528 + unsigned int ack:1; /* whether the TX frame was ACKed */
15529 + int ack_signal; /* measured signal strength of the ACK frame */
15530 + int excessive_retries;
15533 + /* following two fields are only used with Atheros Super A/G */
15534 + int queue_length; /* information about TX queue */
15535 + int queue_number;
15539 +struct ieee80211_conf {
15540 + int channel; /* IEEE 802.11 channel number */
15541 + int freq; /* MHz */
15542 + int channel_val; /* hw specific value for the channel */
15544 + int mode; /* IW_MODE_ */
15546 + int phymode; /* MODE_IEEE80211A, .. */
15547 + unsigned int regulatory_domain;
15552 + /* Bitfields, grouped together */
15554 + int sw_encrypt:1;
15555 + int sw_decrypt:1;
15556 + int short_slot_time:1; /* use IEEE 802.11g Short Slot Time */
15557 + int ssid_hidden:1; /* do not broadcast the ssid */
15559 + /* these fields are used by low level drivers for hardware
15560 + * that generate beacons independently */
15563 + u8 *generic_elem;
15564 + size_t generic_elem_len;
15566 + u8 power_level; /* transmit power limit for current
15567 + * regulatory domain; in dBm */
15568 + u8 antenna_max; /* maximum antenna gain */
15569 + short tx_power_reduction; /* in 0.1 dBm */
15571 + int antenna_sel; /* default antenna conf:
15572 + * 0 = default/diversity,
15576 + int calib_int; /* hw/radio calibration interval in
15579 + int antenna_mode;
15581 + u8 bssid_mask[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff = 1 BSSID */
15584 + int atheros_super_ag_compression;
15585 + int atheros_super_ag_fast_frame;
15586 + int atheros_super_ag_burst;
15587 + int atheros_super_ag_wme_ele;
15588 + int atheros_super_ag_turbo_g;
15589 + int atheros_super_ag_turbo_prime;
15593 + u8 client_bssid[ETH_ALEN];
15595 + /* Following five fields are used for IEEE 802.11H */
15596 + unsigned int radar_detect;
15597 + unsigned int spect_mgmt;
15598 + unsigned int quiet_duration; /* duration of quiet period */
15599 + unsigned int quiet_offset; /* how far into the beacon is the quiet
15601 + unsigned int quiet_period;
15602 + u8 radar_firpwr_threshold;
15603 + u8 radar_rssi_threshold;
15604 + u8 pulse_height_threshold;
15605 + u8 pulse_rssi_threshold;
15606 + u8 pulse_inband_threshold;
15610 +typedef enum { ALG_NONE, ALG_WEP, ALG_TKIP, ALG_CCMP, ALG_NULL }
15611 +ieee80211_key_alg;
15614 +struct ieee80211_key_conf {
15616 + int hw_key_idx; /* filled + used by low-level driver */
15617 + ieee80211_key_alg alg;
15620 + int force_sw_encrypt:1; /* to be cleared by low-level driver */
15621 + int keyidx:8; /* WEP key index */
15622 + int default_tx_key:1; /* This key is the new default TX key
15623 + * (used only for broadcast keys). */
15624 + int default_wep_only:1; /* static WEP is the only configured security
15625 + * policy; this allows some low-level drivers
15626 + * to determine when hwaccel can be used */
15630 +#define IEEE80211_SCAN_START 1
15631 +#define IEEE80211_SCAN_END 2
15633 +struct ieee80211_scan_conf {
15634 + int scan_channel; /* IEEE 802.11 channel number to do passive scan
15636 + int scan_freq; /* new freq in MHz to switch to for passive scan
15638 + int scan_channel_val; /* hw specific value for the channel */
15639 + int scan_phymode; /* MODE_IEEE80211A, .. */
15640 + unsigned char scan_power_level;
15641 + unsigned char scan_antenna_max;
15644 + int running_channel; /* IEEE 802.11 channel number we operate on
15646 + int running_freq; /* freq in MHz we're operating on normally */
15647 + int running_channel_val; /* hw specific value for the channel */
15648 + int running_phymode;
15649 + unsigned char running_power_level;
15650 + unsigned char running_antenna_max;
15652 + int scan_time; /* time a scan will take in us */
15655 + struct sk_buff *skb; /* skb to transmit before changing channels, maybe
15656 + * NULL for none */
15657 + struct ieee80211_tx_control *tx_control;
15661 +#ifndef IW_MODE_ADHOC
15662 +#define IW_MODE_ADHOC 1
15665 +#ifndef IW_MODE_INFRA
15666 +#define IW_MODE_INFRA 2
15669 +#ifndef IW_MODE_MASTER
15670 +#define IW_MODE_MASTER 3
15673 +#ifndef IW_MODE_MONITOR
15674 +#define IW_MODE_MONITOR 6
15677 +#define IEEE80211_SEQ_COUNTER_RX 0
15678 +#define IEEE80211_SEQ_COUNTER_TX 1
15681 + SET_KEY, DISABLE_KEY, REMOVE_ALL_KEYS,
15682 + ENABLE_COMPRESSION, DISABLE_COMPRESSION
15685 +/* Configuration block used by the low-level driver to tell 802.11 code about
15686 + * supported hardware features and to pass function pointers for callback
15688 +struct ieee80211_hw {
15689 + int version; /* IEEE80211_VERSION */
15691 + /* Driver name */
15694 + /* TODO: frame_type 802.11/802.3, sw_encryption requirements */
15696 + /* Some wireless LAN chipsets generate beacons in the hardware/firmware
15697 + * and others rely on host generated beacons. This option is used to
15698 + * configure upper layer IEEE 802.11 module to generate beacons. The
15699 + * low-level driver can use ieee80211_beacon_get() to fetch next
15700 + * beacon frame. */
15701 + int host_gen_beacon:1;
15704 + /* Some devices handle decryption internally and do not
15705 + * indicate whether the frame was encrypted (unencrypted frames
15706 + * will be dropped by the hardware, unless specifically allowed
15708 + int device_hides_wep:1;
15710 + /* Whether RX frames passed to ieee80211_rx() include FCS in the end
15712 + int rx_includes_fcs:1;
15714 + /* Some wireless LAN chipsets buffer broadcast/multicast frames for
15715 + * power saving stations in the hardware/firmware and others rely on
15716 + * the host system for such buffering. This option is used to
15717 + * configure upper layer IEEE 802.11 to buffer broadcast/multicast
15718 + * frames when there are power saving stations so that low-level driver
15719 + * can fetch them with ieee80211_get_buffered_bc(). */
15720 + int host_broadcast_ps_buffering:1;
15722 + int wep_include_iv:1;
15723 + int data_nullfunc_ack:1; /* will data nullfunc frames get proper
15724 + * TX status callback */
15726 + /* Force sw version of encryption for TKIP packets if WMM is enabled.
15728 + int no_tkip_wmm_hwaccel:1;
15730 + /* 1 if the payload needs to be padded at even boundaries after the
15732 + unsigned int extra_hdr_room:1;
15734 + /* Some devices handle Michael MIC internally and do not include MIC in
15735 + * the received packets given to 80211.o. device_strips_mic must be set
15736 + * for such devices. ISWEP bit is still expected to be set in the IEEE
15737 + * 802.11 header with this option unlike with device_hides_wep option.
15739 + unsigned int device_strips_mic:1;
15741 + /* 1 = low-level driver supports skb fraglist (NETIF_F_FRAGLIST), i.e.,
15742 + * more than one skb per frame */
15743 + unsigned int fraglist;
15745 + /* This is the time in us to change channels
15747 + int channel_change_time;
15750 + struct ieee80211_hw_modes *modes;
15752 + /* Handler that 802.11 module calls for each transmitted frame.
15753 + * skb contains the buffer starting from the IEEE 802.11 header.
15754 + * The low-level driver should send the frame out based on
15755 + * configuration in the TX control data. */
15756 + int (*tx)(struct net_device *dev, struct sk_buff *skb,
15757 + struct ieee80211_tx_control *control);
15759 + /* Handler for performing hardware reset. */
15760 + int (*reset)(struct net_device *dev);
15762 + /* Handler that is called when any netdevice attached to the hardware
15763 + * device is set UP for the first time. This can be used, e.g., to
15764 + * enable interrupts and beacon sending. */
15765 + int (*open)(struct net_device *dev);
15767 + /* Handler that is called when the last netdevice attached to the
15768 + * hardware device is set DOWN. This can be used, e.g., to disable
15769 + * interrupts and beacon sending. */
15770 + int (*stop)(struct net_device *dev);
15772 + /* Handler for configuration requests. IEEE 802.11 code calls this
15773 + * function to change hardware configuration, e.g., channel. */
15774 + int (*config)(struct net_device *dev, struct ieee80211_conf *conf);
15776 + /* Set TIM bit handler. If the hardware/firmware takes care of beacon
15777 + * generation, IEEE 802.11 code uses this function to tell the
15778 + * low-level to set (or clear if set==0) TIM bit for the given aid. If
15779 + * host system is used to generate beacons, this handler is not used
15780 + * and low-level driver should set it to NULL. */
15781 + int (*set_tim)(struct net_device *dev, int aid, int set);
15783 + /* Set encryption key. IEEE 802.11 module calls this function to set
15784 + * encryption keys. addr is ff:ff:ff:ff:ff:ff for default keys and
15785 + * station hwaddr for individual keys. aid of the station is given
15786 + * to help low-level driver in selecting which key->hw_key_idx to use
15787 + * for this key. TX control data will use the hw_key_idx selected by
15788 + * the low-level driver. */
15789 + int (*set_key)(struct net_device *dev, set_key_cmd cmd, u8 *addr,
15790 + struct ieee80211_key_conf *key, int aid);
15792 + /* Set TX key index for default/broadcast keys. This is needed in cases
15793 + * where wlan card is doing full WEP/TKIP encapsulation (wep_include_iv
15794 + * is not set), in other cases, this function pointer can be set to
15795 + * NULL since 80211.o takes care of selecting the key index for each
15797 + int (*set_key_idx)(struct net_device *dev, int idx);
15799 + /* Enable/disable IEEE 802.1X. This item requests wlan card to pass
15800 + * unencrypted EAPOL-Key frames even when encryption is configured.
15801 + * If the wlan card does not require such a configuration, this
15802 + * function pointer can be set to NULL. 80211.o */
15803 + int (*set_ieee8021x)(struct net_device *dev, int use_ieee8021x);
15805 + /* Set port authorization state (IEEE 802.1X PAE) to be authorized
15806 + * (authorized=1) or unauthorized (authorized=0). This function can be
15807 + * used if the wlan hardware or low-level driver implements PAE.
15808 + * 80211.o module will anyway filter frames based on authorization
15809 + * state, so this function pointer can be NULL if low-level driver does
15810 + * not require event notification about port state changes. */
15811 + int (*set_port_auth)(struct net_device *dev, u8 *addr, int authorized);
15813 + /* Ask the hardware to do a passive scan on a new channel. The hardware
15814 + * will do what ever is required to nicely leave the current channel
15815 + * including transmit any CTS packets, etc. */
15816 + int (*passive_scan)(struct net_device *dev, int state,
15817 + struct ieee80211_scan_conf *conf);
15819 + /* return low-level statistics */
15820 + int (*get_stats)(struct net_device *dev,
15821 + struct ieee80211_low_level_stats *stats);
15823 + /* Enable/disable test modes; mode = IEEE80211_TEST_* */
15824 + int (*test_mode)(struct net_device *dev, int mode);
15826 + /* Configuration of test parameters */
15827 + int (*test_param)(struct net_device *dev, int param, int value);
15829 + /* Change MAC address. addr is pointer to struct sockaddr. */
15830 + int (*set_mac_address)(struct net_device *dev, void *addr);
15832 + /* For devices that generate their own beacons and probe response
15833 + * or association responses this updates the state of privacy_invoked
15834 + * returns 0 for success or an error number */
15836 + int (*set_privacy_invoked)(struct net_device *dev,
15837 + int privacy_invoked);
15839 + /* For devices that have internal sequence counters, allow 802.11
15840 + * code to access the current value of a counter */
15841 + int (*get_sequence_counter)(struct net_device *dev,
15842 + u8* addr, u8 keyidx, u8 txrx,
15843 + u32* iv32, u16* iv16);
15845 + /* Configuration of RTS threshold (if device needs it) */
15846 + int (*set_rts_threshold)(struct net_device *dev, u32 value);
15848 + /* Configuration of fragmentation threshold (if device needs it) */
15849 + int (*set_frag_threshold)(struct net_device *dev, u32 value);
15851 + /* Configuration of retry limits (if device needs it) */
15852 + int (*set_retry_limit)(struct net_device *dev, u32 short_retry,
15855 + /* Number of STAs in STA table notification (NULL = disabled) */
15856 + void (*sta_table_notification)(struct net_device *dev, int num_sta);
15858 + /* Configure TX queue parameters (EDCF (aifs, cw_min, cw_max),
15859 + * bursting) for a hardware TX queue.
15860 + * queue = IEEE80211_TX_QUEUE_*. */
15861 + int (*conf_tx)(struct net_device *dev, int queue,
15862 + const struct ieee80211_tx_queue_params *params);
15864 + /* Get statistics of the current TX queue status. This is used to get
15865 + * number of currently queued packets (queue length), maximum queue
15866 + * size (limit), and total number of packets sent using each TX queue
15867 + * (count). This information is used for WMM to find out which TX
15868 + * queues have room for more packets and by hostapd to provide
15869 + * statistics about the current queueing state to external programs. */
15870 + int (*get_tx_stats)(struct net_device *dev,
15871 + struct ieee80211_tx_queue_stats *stats);
15873 + /* Number of available hardware TX queues for data packets.
15874 + * WMM requires at least four queues. */
15877 + /* Get the current TSF timer value from firmware/hardware. Currently,
15878 + * this is only used for IBSS mode debugging and, as such, is not a
15879 + * required function. */
15880 + u64 (*get_tsf)(struct net_device *dev);
15882 + /* Reset the TSF timer and allow firmware/hardware to synchronize with
15883 + * other STAs in the IBSS. This is only used in IBSS mode. This
15884 + * function is optional if the firmware/hardware takes full care of
15885 + * TSF synchronization. */
15886 + void (*reset_tsf)(struct net_device *dev);
15888 + /* Setup beacon data for IBSS beacons. Unlike access point (Master),
15889 + * IBSS uses a fixed beacon frame which is configured using this
15890 + * function. This handler is required only for IBSS mode. */
15891 + int (*beacon_update)(struct net_device *dev, struct sk_buff *skb,
15892 + struct ieee80211_tx_control *control);
15894 + /* Determine whether the last IBSS beacon was sent by us. This is
15895 + * needed only for IBSS mode and the result of this function is used to
15896 + * determine whether to reply to Probe Requests. */
15897 + int (*tx_last_beacon)(struct net_device *dev);
15899 + /* Optional handler for XR-in-use notification. */
15900 + int (*atheros_xr_in_use)(struct net_device *dev, int in_use);
15903 +/* Allocate a new hardware device. This must be called once for each
15904 + * hardware device. The returned pointer must be used to refer to this
15905 + * device when calling other functions. 802.11 code allocates a private data
15906 + * area for the low-level driver. The size of this area is given as
15907 + * priv_data_len. ieee80211_dev_hw_data() is used to get a pointer to the
15908 + * private data area.
15910 + * Note: in this version of the interface the returned pointer is struct
15911 + * net_device *. This may change in the future and low-level driver should
15912 + * not refer the device data directly to remain compatible with the future
15913 + * versions of the interface. */
15914 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
15915 + void (*setup)(struct net_device *));
15917 +/* Register hardware device to the IEEE 802.11 code and kernel. Low-level
15918 + * drivers must call this function before using any other IEEE 802.11
15920 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw);
15922 +/* This function is allowed to update hardware configuration (e.g., list of
15923 + * supported operation modes and rates). */
15924 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw);
15926 +/* Unregister a hardware device. This function instructs 802.11 code to free
15927 + * allocated resources and unregister netdevices from the kernel. */
15928 +void ieee80211_unregister_hw(struct net_device *dev);
15930 +/* Free allocated net_device including private data of a driver. */
15931 +void ieee80211_free_hw(struct net_device *dev);
15933 +/* Receive frame callback function. The low-level driver uses this function to
15934 + * send received frames to the IEEE 802.11 code. Receive buffer (skb) must
15935 + * start with IEEE 802.11 header. */
15936 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
15937 + struct ieee80211_rx_status *status);
15938 +void ieee80211_rx_irqsafe(struct net_device *dev, struct sk_buff *skb,
15939 + struct ieee80211_rx_status *status);
15941 +/* Transmit status callback function. The low-level driver must call this
15942 + * function to report transmit status for all the TX frames that had
15943 + * req_tx_status set in the transmit control fields. In addition, this should
15944 + * be called at least for all unicast frames to provide information for TX rate
15945 + * control algorithm. In order to maintain all statistics, this function is
15946 + * recommended to be called after each frame, including multicast/broadcast, is
15948 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
15949 + struct ieee80211_tx_status *status);
15950 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
15951 + struct ieee80211_tx_status *status);
15953 +/* Beacon generation function. If the beacon frames are generated by the host
15954 + * system (i.e., not in hardware/firmware), the low-level driver uses this
15955 + * function to receive the next beacon frame from the 802.11 code. The
15956 + * low-level is responsible for calling this function before beacon data is
15957 + * needed (e.g., based on hardware interrupt). Returned skb is used only once
15958 + * and low-level driver is responsible of freeing it. */
15959 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
15960 + struct ieee80211_tx_control *control);
15962 +/* Function for accessing buffered broadcast and multicast frames. If
15963 + * hardware/firmware does not implement buffering of broadcast/multicast
15964 + * frames when power saving is used, 802.11 code buffers them in the host
15965 + * memory. The low-level driver uses this function to fetch next buffered
15966 + * frame. In most cases, this is used when generating beacon frame. This
15967 + * function returns a pointer to the next buffered skb or NULL if no more
15968 + * buffered frames are available.
15970 + * Note: buffered frames are returned only after DTIM beacon frame was
15971 + * generated with ieee80211_beacon_get() and the low-level driver must thus
15972 + * call ieee80211_beacon_get() first. ieee80211_get_buffered_bc() returns
15973 + * NULL if the previous generated beacon was not DTIM, so the low-level driver
15974 + * does not need to check for DTIM beacons separately and should be able to
15975 + * use common code for all beacons. */
15977 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
15978 + struct ieee80211_tx_control *control);
15980 +/* Low level drivers that have their own MLME and MAC indicate
15981 + * the aid for an associating station with this call */
15982 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
15986 +/* Given an sk_buff with a raw 802.11 header at the data pointer this function
15987 + * returns the 802.11 header length in bytes (not including encryption
15988 + * headers). If the data in the sk_buff is too short to contain a valid 802.11
15989 + * header the function returns 0.
15991 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb);
15993 +/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */
15994 +int ieee80211_get_hdrlen(u16 fc);
15996 +/* Function for net interface operation. IEEE 802.11 may use multiple kernel
15997 + * netdevices for each hardware device. The low-level driver does not "see"
15998 + * these interfaces, so it should use this function to perform netif
15999 + * operations on all interface. */
16001 + NETIF_ATTACH, NETIF_DETACH, NETIF_START, NETIF_STOP, NETIF_WAKE,
16002 + NETIF_IS_STOPPED, NETIF_UPDATE_TX_START
16004 +int ieee80211_netif_oper(struct net_device *dev, Netif_Oper op);
16008 + * Function to get hardware configuration information
16009 + * by the low level driver should it need it.
16011 +struct ieee80211_conf *
16012 +ieee80211_get_hw_conf(struct net_device *dev);
16015 +/* Return a pointer to the low-level private data area for the given device. */
16016 +void * ieee80211_dev_hw_data(struct net_device *dev);
16017 +/* Return a pointer to network statistics data area for the given device. */
16018 +void * ieee80211_dev_stats(struct net_device *dev);
16020 +/* Function to indicate Radar Detection. The low level driver must call this
16021 + * function to indicate the presence of radar in the current channel.
16022 + * Additionally the radar type also could be sent */
16023 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
16028 + IEEE80211_TEST_DISABLE = 0 /* terminate testing */,
16029 + IEEE80211_TEST_UNMASK_CHANNELS = 1 /* allow all channels to be used */,
16030 + IEEE80211_TEST_CONTINUOUS_TX = 2,
16033 +/* Test parameters */
16035 + /* TX power in hardware specific raw value */
16036 + IEEE80211_TEST_PARAM_TX_POWER_RAW = 0,
16037 + /* TX rate in hardware specific raw value */
16038 + IEEE80211_TEST_PARAM_TX_RATE_RAW = 1,
16039 + /* Continuous TX pattern (32-bit) */
16040 + IEEE80211_TEST_PARAM_TX_PATTERN = 2,
16041 + /* TX power in 0.1 dBm, 100 = 10 dBm */
16042 + IEEE80211_TEST_PARAM_TX_POWER = 3,
16043 + /* TX rate in 100 kbps, 540 = 54 Mbps */
16044 + IEEE80211_TEST_PARAM_TX_RATE = 4,
16045 + IEEE80211_TEST_PARAM_TX_ANT_SEL_RAW = 5,
16048 +/* ieee80211_tx_led called with state == 1 when the first frame is queued
16049 + * with state == 0 when the last frame is transmitted and tx queue is empty
16051 +void ieee80211_tx_led(int state, struct net_device *dev);
16052 +/* ieee80211_rx_led is called each time frame is received, state is not used
16055 +void ieee80211_rx_led(int state, struct net_device *dev);
16058 +/* IEEE 802.11 defines */
16062 +#define WLAN_FC_PVER 0x0003
16063 +#define WLAN_FC_TODS 0x0100
16064 +#define WLAN_FC_FROMDS 0x0200
16065 +#define WLAN_FC_MOREFRAG 0x0400
16066 +#define WLAN_FC_RETRY 0x0800
16067 +#define WLAN_FC_PWRMGT 0x1000
16068 +#define WLAN_FC_MOREDATA 0x2000
16069 +#define WLAN_FC_ISWEP 0x4000
16070 +#define WLAN_FC_ORDER 0x8000
16072 +#define WLAN_FC_GET_TYPE(fc) (((fc) & 0x000c) >> 2)
16073 +#define WLAN_FC_GET_STYPE(fc) (((fc) & 0x00f0) >> 4)
16075 +#define WLAN_GET_SEQ_FRAG(seq) ((seq) & 0x000f)
16076 +#define WLAN_GET_SEQ_SEQ(seq) ((seq) >> 4)
16078 +#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
16080 +#define WLAN_FC_TYPE_MGMT 0
16081 +#define WLAN_FC_TYPE_CTRL 1
16082 +#define WLAN_FC_TYPE_DATA 2
16085 +#define WLAN_FC_STYPE_ASSOC_REQ 0
16086 +#define WLAN_FC_STYPE_ASSOC_RESP 1
16087 +#define WLAN_FC_STYPE_REASSOC_REQ 2
16088 +#define WLAN_FC_STYPE_REASSOC_RESP 3
16089 +#define WLAN_FC_STYPE_PROBE_REQ 4
16090 +#define WLAN_FC_STYPE_PROBE_RESP 5
16091 +#define WLAN_FC_STYPE_BEACON 8
16092 +#define WLAN_FC_STYPE_ATIM 9
16093 +#define WLAN_FC_STYPE_DISASSOC 10
16094 +#define WLAN_FC_STYPE_AUTH 11
16095 +#define WLAN_FC_STYPE_DEAUTH 12
16096 +#define WLAN_FC_STYPE_ACTION 13
16099 +#define WLAN_FC_STYPE_PSPOLL 10
16100 +#define WLAN_FC_STYPE_RTS 11
16101 +#define WLAN_FC_STYPE_CTS 12
16102 +#define WLAN_FC_STYPE_ACK 13
16103 +#define WLAN_FC_STYPE_CFEND 14
16104 +#define WLAN_FC_STYPE_CFENDACK 15
16107 +#define WLAN_FC_STYPE_DATA 0
16108 +#define WLAN_FC_STYPE_DATA_CFACK 1
16109 +#define WLAN_FC_STYPE_DATA_CFPOLL 2
16110 +#define WLAN_FC_STYPE_DATA_CFACKPOLL 3
16111 +#define WLAN_FC_STYPE_NULLFUNC 4
16112 +#define WLAN_FC_STYPE_CFACK 5
16113 +#define WLAN_FC_STYPE_CFPOLL 6
16114 +#define WLAN_FC_STYPE_CFACKPOLL 7
16115 +#define WLAN_FC_STYPE_QOS_DATA 8
16116 +#define WLAN_FC_STYPE_QOS_DATA_CFACK 9
16117 +#define WLAN_FC_STYPE_QOS_DATA_CFPOLL 10
16118 +#define WLAN_FC_STYPE_QOS_DATA_CFACKPOLL 11
16119 +#define WLAN_FC_STYPE_QOS_NULLFUNC 12
16120 +#define WLAN_FC_STYPE_QOS_CFACK 13
16121 +#define WLAN_FC_STYPE_QOS_CFPOLL 14
16122 +#define WLAN_FC_STYPE_QOS_CFACKPOLL 15
16125 +#define IEEE80211_MAX_FRAG_THRESHOLD 2346
16126 +#define IEEE80211_MAX_RTS_THRESHOLD 2347
16128 +struct ieee80211_hdr {
16129 + u16 frame_control;
16136 +} __attribute__ ((packed));
16138 +/* return a pointer to the source address (SA) */
16139 +static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
16141 + u8 *raw = (u8 *) hdr;
16142 + u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
16144 + switch (tofrom) {
16146 + return hdr->addr3;
16148 + return hdr->addr4;
16150 + return hdr->addr2;
16153 +/* return a pointer to the destination address (DA) */
16154 +static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
16156 + u8 *raw = (u8 *) hdr;
16157 + u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
16160 + return hdr->addr3;
16161 + return hdr->addr1;
16164 +static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
16166 + return (le16_to_cpu(hdr->frame_control) & WLAN_FC_MOREFRAG) != 0;
16169 +#endif /* D80211_H */
16170 diff -Nur linux-2.6.16/include/net/d80211_mgmt.h linux-2.6.16-bcm43xx/include/net/d80211_mgmt.h
16171 --- linux-2.6.16/include/net/d80211_mgmt.h 1970-01-01 01:00:00.000000000 +0100
16172 +++ linux-2.6.16-bcm43xx/include/net/d80211_mgmt.h 2006-03-28 22:16:14.000000000 +0200
16175 + * IEEE 802.11 -- shared defines for 80211.o and hostapd
16176 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
16177 + * Copyright 2002-2004, Instant802 Networks, Inc.
16178 + * Copyright 2005, Devicescape Software, Inc.
16180 + * This program is free software; you can redistribute it and/or modify
16181 + * it under the terms of the GNU General Public License version 2 as
16182 + * published by the Free Software Foundation.
16185 +#ifndef D802_11_MGMT_H
16186 +#define D802_11_MGMT_H
16188 +#include <linux/types.h>
16190 +struct ieee80211_mgmt {
16191 + u16 frame_control;
16200 + u16 auth_transaction;
16202 + /* possibly followed by Challenge text */
16204 + } __attribute__ ((packed)) auth;
16207 + } __attribute__ ((packed)) deauth;
16210 + u16 listen_interval;
16211 + /* followed by SSID and Supported rates */
16213 + } __attribute__ ((packed)) assoc_req;
16218 + /* followed by Supported rates */
16220 + } __attribute__ ((packed)) assoc_resp, reassoc_resp;
16223 + u16 listen_interval;
16224 + u8 current_ap[6];
16225 + /* followed by SSID and Supported rates */
16227 + } __attribute__ ((packed)) reassoc_req;
16230 + } __attribute__ ((packed)) disassoc;
16235 + /* followed by some of SSID, Supported rates,
16236 + * FH Params, DS Params, CF Params, IBSS Params, TIM */
16238 + } __attribute__ ((packed)) beacon;
16240 + /* only variable items: SSID, Supported rates */
16242 + } __attribute__ ((packed)) probe_req;
16247 + /* followed by some of SSID, Supported rates,
16248 + * FH Params, DS Params, CF Params, IBSS Params */
16250 + } __attribute__ ((packed)) probe_resp;
16259 + } __attribute__ ((packed)) wme_action;
16267 + } __attribute__((packed)) chan_switch;
16269 + } __attribute__ ((packed)) action;
16271 +} __attribute__ ((packed));
16274 +/* Authentication algorithms */
16275 +#define WLAN_AUTH_OPEN 0
16276 +#define WLAN_AUTH_SHARED_KEY 1
16277 +#define WLAN_AUTH_LEAP 128
16279 +#define WLAN_AUTH_CHALLENGE_LEN 128
16281 +#define WLAN_CAPABILITY_ESS BIT(0)
16282 +#define WLAN_CAPABILITY_IBSS BIT(1)
16283 +#define WLAN_CAPABILITY_CF_POLLABLE BIT(2)
16284 +#define WLAN_CAPABILITY_CF_POLL_REQUEST BIT(3)
16285 +#define WLAN_CAPABILITY_PRIVACY BIT(4)
16286 +#define WLAN_CAPABILITY_SHORT_PREAMBLE BIT(5)
16287 +#define WLAN_CAPABILITY_PBCC BIT(6)
16288 +#define WLAN_CAPABILITY_CHANNEL_AGILITY BIT(7)
16290 +#define WLAN_CAPABILITY_SPECTRUM_MGMT BIT(8)
16291 +#define WLAN_CAPABILITY_SHORT_SLOT_TIME BIT(10)
16292 +#define WLAN_CAPABILITY_DSSS_OFDM BIT(13)
16294 +/* Status codes */
16295 +#define WLAN_STATUS_SUCCESS 0
16296 +#define WLAN_STATUS_UNSPECIFIED_FAILURE 1
16297 +#define WLAN_STATUS_CAPS_UNSUPPORTED 10
16298 +#define WLAN_STATUS_REASSOC_NO_ASSOC 11
16299 +#define WLAN_STATUS_ASSOC_DENIED_UNSPEC 12
16300 +#define WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG 13
16301 +#define WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION 14
16302 +#define WLAN_STATUS_CHALLENGE_FAIL 15
16303 +#define WLAN_STATUS_AUTH_TIMEOUT 16
16304 +#define WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA 17
16305 +#define WLAN_STATUS_ASSOC_DENIED_RATES 18
16307 +#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
16308 +#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
16309 +#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
16311 +#define WLAN_STATUS_SPEC_MGMT_REQUIRED 22
16312 +#define WLAN_STATUS_PWR_CAPABILITY_NOT_VALID 23
16313 +#define WLAN_STATUS_SUPPORTED_CHANNEL_NOT_VALID 24
16315 +#define WLAN_STATUS_ASSOC_DENOED_NO_SHORT_SLOT_TIME 25
16316 +#define WLAN_STATUS_ASSOC_DENOED_NO_ER_PBCC 26
16317 +#define WLAN_STATUS_ASSOC_DENOED_NO_DSSS_OFDM 27
16320 +/* Reason codes */
16321 +#define WLAN_REASON_UNSPECIFIED 1
16322 +#define WLAN_REASON_PREV_AUTH_NOT_VALID 2
16323 +#define WLAN_REASON_DEAUTH_LEAVING 3
16324 +#define WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY 4
16325 +#define WLAN_REASON_DISASSOC_AP_BUSY 5
16326 +#define WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA 6
16327 +#define WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA 7
16328 +#define WLAN_REASON_DISASSOC_STA_HAS_LEFT 8
16329 +#define WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH 9
16331 +#define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10
16332 +#define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
16334 +#define WLAN_REASON_MIC_FAILURE 14
16337 +/* Information Element IDs */
16338 +#define WLAN_EID_SSID 0
16339 +#define WLAN_EID_SUPP_RATES 1
16340 +#define WLAN_EID_FH_PARAMS 2
16341 +#define WLAN_EID_DS_PARAMS 3
16342 +#define WLAN_EID_CF_PARAMS 4
16343 +#define WLAN_EID_TIM 5
16344 +#define WLAN_EID_IBSS_PARAMS 6
16345 +#define WLAN_EID_COUNTRY 7
16346 +#define WLAN_EID_CHALLENGE 16
16347 +/* EIDs defined as part fo 11h - starts */
16348 +#define WLAN_EID_PWR_CONSTRAINT 32
16349 +#define WLAN_EID_PWR_CAPABILITY 33
16350 +#define WLAN_EID_TPC_REQUEST 34
16351 +#define WLAN_EID_TPC_REPORT 35
16352 +#define WLAN_EID_SUPPORTED_CHANNELS 36
16353 +#define WLAN_EID_CHANNEL_SWITCH 37
16354 +#define WLAN_EID_MEASURE_REQUEST 38
16355 +#define WLAN_EID_MEASURE_REPORT 39
16356 +#define WLAN_EID_QUITE 40
16357 +#define WLAN_EID_IBSS_DFS 41
16358 +/* EIDs defined as part fo 11h - ends */
16359 +#define WLAN_EID_ERP_INFO 42
16360 +#define WLAN_EID_RSN 48
16361 +#define WLAN_EID_EXT_SUPP_RATES 50
16362 +#define WLAN_EID_WPA 221
16363 +#define WLAN_EID_GENERIC 221
16364 +#define WLAN_EID_VENDOR_SPECIFIC 221
16368 +#define ATHEROS_INFO_USEXR BIT(3)
16370 +#endif /* D802_11_MGMT_H */
16371 diff -Nur linux-2.6.16/include/net/d80211_shared.h linux-2.6.16-bcm43xx/include/net/d80211_shared.h
16372 --- linux-2.6.16/include/net/d80211_shared.h 1970-01-01 01:00:00.000000000 +0100
16373 +++ linux-2.6.16-bcm43xx/include/net/d80211_shared.h 2006-03-28 22:16:14.000000000 +0200
16376 + * IEEE 802.11 -- shared defines for low-level drivers, 80211.o, and hostapd
16377 + * Copyright 2002-2004, Instant802 Networks, Inc.
16378 + * Copyright 2005, Devicescape Software, Inc.
16380 + * This program is free software; you can redistribute it and/or modify
16381 + * it under the terms of the GNU General Public License version 2 as
16382 + * published by the Free Software Foundation.
16385 +#ifndef D80211_SHARED_H
16386 +#define D80211_SHARED_H
16388 +/* 802.11g is backwards-compatible with 802.11b, so a wlan card can
16389 + * actually be both in 11b and 11g modes at the same time. */
16391 + MODE_IEEE80211A = 0 /* IEEE 802.11a */,
16392 + MODE_IEEE80211B = 1 /* IEEE 802.11b only */,
16393 + MODE_ATHEROS_TURBO = 2 /* Atheros Turbo mode (2x.11a at 5 GHz) */,
16394 + MODE_IEEE80211G = 3 /* IEEE 802.11g (and 802.11b compatibility) */,
16395 + MODE_ATHEROS_TURBOG = 4 /* Atheros Turbo mode (2x.11g at 2.4 GHz) */,
16396 + MODE_ATHEROS_PRIME = 5 /* Atheros Dynamic Turbo mode */,
16397 + MODE_ATHEROS_PRIMEG = 6 /* Atheros Dynamic Turbo mode G */,
16398 + MODE_ATHEROS_XR = 7 /* Atheros XR mode */,
16399 + NUM_IEEE80211_MODES = 8
16402 +#define IEEE80211_CHAN_W_SCAN 0x00000001
16403 +#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
16404 +#define IEEE80211_CHAN_W_IBSS 0x00000004
16406 +/* Low-level driver should set PREAMBLE2, OFDM, CCK, and TURBO flags.
16407 + * BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the
16408 + * configuration. */
16409 +#define IEEE80211_RATE_ERP 0x00000001
16410 +#define IEEE80211_RATE_BASIC 0x00000002
16411 +#define IEEE80211_RATE_PREAMBLE2 0x00000004
16412 +#define IEEE80211_RATE_SUPPORTED 0x00000010
16413 +#define IEEE80211_RATE_OFDM 0x00000020
16414 +#define IEEE80211_RATE_CCK 0x00000040
16415 +#define IEEE80211_RATE_TURBO 0x00000080
16416 +#define IEEE80211_RATE_MANDATORY 0x00000100
16417 +#define IEEE80211_RATE_XR 0x00000200
16419 +#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2)
16420 +#define IEEE80211_RATE_MODULATION(f) \
16421 +(f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM))
16424 +#endif /* D80211_SHARED_H */
16425 diff -Nur linux-2.6.16/include/net/ieee80211_crypt.h linux-2.6.16-bcm43xx/include/net/ieee80211_crypt.h
16426 --- linux-2.6.16/include/net/ieee80211_crypt.h 2006-03-20 06:53:29.000000000 +0100
16427 +++ linux-2.6.16-bcm43xx/include/net/ieee80211_crypt.h 2006-03-28 22:16:14.000000000 +0200
16429 /* deinitialize crypto context and free allocated private data */
16430 void (*deinit) (void *priv);
16432 - int (*build_iv) (struct sk_buff * skb, int hdr_len, void *priv);
16433 + int (*build_iv) (struct sk_buff * skb, int hdr_len,
16434 + u8 *key, int keylen, void *priv);
16436 /* encrypt/decrypt return < 0 on error or >= 0 on success. The return
16437 * value from decrypt_mpdu is passed as the keyidx value for
16438 diff -Nur linux-2.6.16/include/net/ieee80211.h linux-2.6.16-bcm43xx/include/net/ieee80211.h
16439 --- linux-2.6.16/include/net/ieee80211.h 2006-03-20 06:53:29.000000000 +0100
16440 +++ linux-2.6.16-bcm43xx/include/net/ieee80211.h 2006-03-28 22:16:14.000000000 +0200
16441 @@ -220,6 +220,7 @@
16442 /* Authentication algorithms */
16443 #define WLAN_AUTH_OPEN 0
16444 #define WLAN_AUTH_SHARED_KEY 1
16445 +#define WLAN_AUTH_LEAP 2
16447 #define WLAN_AUTH_CHALLENGE_LEN 128
16449 @@ -299,6 +300,23 @@
16450 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
16453 +/* Action categories - 802.11h */
16454 +enum ieee80211_actioncategories {
16455 + WLAN_ACTION_SPECTRUM_MGMT = 0,
16456 + /* Reserved 1-127 */
16457 + /* Error 128-255 */
16460 +/* Action details - 802.11h */
16461 +enum ieee80211_actiondetails {
16462 + WLAN_ACTION_CATEGORY_MEASURE_REQUEST = 0,
16463 + WLAN_ACTION_CATEGORY_MEASURE_REPORT = 1,
16464 + WLAN_ACTION_CATEGORY_TPC_REQUEST = 2,
16465 + WLAN_ACTION_CATEGORY_TPC_REPORT = 3,
16466 + WLAN_ACTION_CATEGORY_CHANNEL_SWITCH = 4,
16467 + /* 5 - 255 Reserved */
16470 #define IEEE80211_STATMASK_SIGNAL (1<<0)
16471 #define IEEE80211_STATMASK_RSSI (1<<1)
16472 #define IEEE80211_STATMASK_NOISE (1<<2)
16473 @@ -377,6 +395,8 @@
16481 /* IEEE 802.11 requires that STA supports concurrent reception of at least
16482 @@ -608,6 +628,28 @@
16483 struct ieee80211_info_element info_element[0];
16484 } __attribute__ ((packed));
16486 +struct ieee80211_channel_switch {
16492 +} __attribute__ ((packed));
16494 +struct ieee80211_action {
16495 + struct ieee80211_hdr_3addr header;
16499 + struct ieee80211_action_exchange {
16501 + struct ieee80211_info_element info_element[0];
16503 + struct ieee80211_channel_switch channel_switch;
16506 +} __attribute__ ((packed));
16508 struct ieee80211_disassoc {
16509 struct ieee80211_hdr_3addr header;
16511 @@ -692,7 +734,15 @@
16512 /* QoS structure */
16513 #define NETWORK_HAS_QOS_PARAMETERS (1<<3)
16514 #define NETWORK_HAS_QOS_INFORMATION (1<<4)
16515 -#define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | NETWORK_HAS_QOS_INFORMATION)
16516 +#define NETWORK_HAS_QOS_MASK (NETWORK_HAS_QOS_PARAMETERS | \
16517 + NETWORK_HAS_QOS_INFORMATION)
16520 +#define NETWORK_HAS_POWER_CONSTRAINT (1<<5)
16521 +#define NETWORK_HAS_CSA (1<<6)
16522 +#define NETWORK_HAS_QUIET (1<<7)
16523 +#define NETWORK_HAS_IBSS_DFS (1<<8)
16524 +#define NETWORK_HAS_TPC_REPORT (1<<9)
16526 #define QOS_QUEUE_NUM 4
16527 #define QOS_OUI_LEN 3
16528 @@ -748,6 +798,91 @@
16530 /*******************************************************/
16532 +enum { /* ieee80211_basic_report.map */
16533 + IEEE80211_BASIC_MAP_BSS = (1 << 0),
16534 + IEEE80211_BASIC_MAP_OFDM = (1 << 1),
16535 + IEEE80211_BASIC_MAP_UNIDENTIFIED = (1 << 2),
16536 + IEEE80211_BASIC_MAP_RADAR = (1 << 3),
16537 + IEEE80211_BASIC_MAP_UNMEASURED = (1 << 4),
16538 + /* Bits 5-7 are reserved */
16541 +struct ieee80211_basic_report {
16543 + __le64 start_time;
16546 +} __attribute__ ((packed));
16548 +enum { /* ieee80211_measurement_request.mode */
16549 + /* Bit 0 is reserved */
16550 + IEEE80211_MEASUREMENT_ENABLE = (1 << 1),
16551 + IEEE80211_MEASUREMENT_REQUEST = (1 << 2),
16552 + IEEE80211_MEASUREMENT_REPORT = (1 << 3),
16553 + /* Bits 4-7 are reserved */
16557 + IEEE80211_REPORT_BASIC = 0, /* required */
16558 + IEEE80211_REPORT_CCA = 1, /* optional */
16559 + IEEE80211_REPORT_RPI = 2, /* optional */
16560 + /* 3-255 reserved */
16563 +struct ieee80211_measurement_params {
16565 + __le64 start_time;
16567 +} __attribute__ ((packed));
16569 +struct ieee80211_measurement_request {
16570 + struct ieee80211_info_element ie;
16574 + struct ieee80211_measurement_params params[0];
16575 +} __attribute__ ((packed));
16577 +struct ieee80211_measurement_report {
16578 + struct ieee80211_info_element ie;
16583 + struct ieee80211_basic_report basic[0];
16585 +} __attribute__ ((packed));
16587 +struct ieee80211_tpc_report {
16588 + u8 transmit_power;
16590 +} __attribute__ ((packed));
16592 +struct ieee80211_channel_map {
16595 +} __attribute__ ((packed));
16597 +struct ieee80211_ibss_dfs {
16598 + struct ieee80211_info_element ie;
16599 + u8 owner[ETH_ALEN];
16600 + u8 recovery_interval;
16601 + struct ieee80211_channel_map channel_map[0];
16604 +struct ieee80211_csa {
16608 +} __attribute__ ((packed));
16610 +struct ieee80211_quiet {
16615 +} __attribute__ ((packed));
16617 struct ieee80211_network {
16618 /* These entries are used to identify a unique network */
16619 u8 bssid[ETH_ALEN];
16620 @@ -767,7 +902,7 @@
16622 unsigned long last_scanned;
16626 u32 last_associate;
16628 u16 beacon_interval;
16629 @@ -779,6 +914,25 @@
16630 u8 rsn_ie[MAX_WPA_IE_LEN];
16632 struct ieee80211_tim_parameters tim;
16634 + /* 802.11h info */
16636 + /* Power Constraint - mandatory if spctrm mgmt required */
16637 + u8 power_constraint;
16639 + /* TPC Report - mandatory if spctrm mgmt required */
16640 + struct ieee80211_tpc_report tpc_report;
16642 + /* IBSS DFS - mandatory if spctrm mgmt required and IBSS
16643 + * NOTE: This is variable length and so must be allocated dynamically */
16644 + struct ieee80211_ibss_dfs *ibss_dfs;
16646 + /* Channel Switch Announcement - optional if spctrm mgmt required */
16647 + struct ieee80211_csa csa;
16649 + /* Quiet - optional if spctrm mgmt required */
16650 + struct ieee80211_quiet quiet;
16652 struct list_head list;
16655 @@ -924,7 +1078,10 @@
16656 int (*handle_auth) (struct net_device * dev,
16657 struct ieee80211_auth * auth);
16658 int (*handle_deauth) (struct net_device * dev,
16659 - struct ieee80211_auth * auth);
16660 + struct ieee80211_deauth * auth);
16661 + int (*handle_action) (struct net_device * dev,
16662 + struct ieee80211_action * action,
16663 + struct ieee80211_rx_stats * stats);
16664 int (*handle_disassoc) (struct net_device * dev,
16665 struct ieee80211_disassoc * assoc);
16666 int (*handle_beacon) (struct net_device * dev,
16667 @@ -1093,6 +1250,7 @@
16668 extern void ieee80211_rx_mgt(struct ieee80211_device *ieee,
16669 struct ieee80211_hdr_4addr *header,
16670 struct ieee80211_rx_stats *stats);
16671 +extern void ieee80211_network_reset(struct ieee80211_network *network);
16673 /* ieee80211_geo.c */
16674 extern const struct ieee80211_geo *ieee80211_get_geo(struct ieee80211_device
16675 @@ -1105,6 +1263,11 @@
16676 extern int ieee80211_channel_to_index(struct ieee80211_device *ieee,
16678 extern u8 ieee80211_freq_to_channel(struct ieee80211_device *ieee, u32 freq);
16679 +extern u8 ieee80211_get_channel_flags(struct ieee80211_device *ieee,
16681 +extern const struct ieee80211_channel *ieee80211_get_channel(struct
16683 + *ieee, u8 channel);
16685 /* ieee80211_wx.c */
16686 extern int ieee80211_wx_get_scan(struct ieee80211_device *ieee,
16687 @@ -1122,6 +1285,14 @@
16688 extern int ieee80211_wx_get_encodeext(struct ieee80211_device *ieee,
16689 struct iw_request_info *info,
16690 union iwreq_data *wrqu, char *extra);
16691 +extern int ieee80211_wx_set_auth(struct net_device *dev,
16692 + struct iw_request_info *info,
16693 + union iwreq_data *wrqu,
16695 +extern int ieee80211_wx_get_auth(struct net_device *dev,
16696 + struct iw_request_info *info,
16697 + union iwreq_data *wrqu,
16700 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
16702 diff -Nur linux-2.6.16/include/net/sock.h linux-2.6.16-bcm43xx/include/net/sock.h
16703 --- linux-2.6.16/include/net/sock.h 2006-03-20 06:53:29.000000000 +0100
16704 +++ linux-2.6.16-bcm43xx/include/net/sock.h 2006-03-28 22:16:14.000000000 +0200
16705 @@ -478,9 +478,9 @@
16706 rc = __condition; \
16708 *(__timeo) = schedule_timeout(*(__timeo)); \
16709 + rc = __condition; \
16712 - rc = __condition; \
16716 diff -Nur linux-2.6.16/net/core/dev.c linux-2.6.16-bcm43xx/net/core/dev.c
16717 --- linux-2.6.16/net/core/dev.c 2006-03-20 06:53:29.000000000 +0100
16718 +++ linux-2.6.16-bcm43xx/net/core/dev.c 2006-03-29 14:12:58.000000000 +0200
16719 @@ -110,10 +110,8 @@
16720 #include <linux/netpoll.h>
16721 #include <linux/rcupdate.h>
16722 #include <linux/delay.h>
16723 -#ifdef CONFIG_NET_RADIO
16724 -#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
16725 +#include <linux/wireless.h> /* Note : will define CONFIG_WIRELESS_EXT */
16726 #include <net/iw_handler.h>
16727 -#endif /* CONFIG_NET_RADIO */
16728 #include <asm/current.h>
16731 @@ -2028,7 +2026,7 @@
16732 .release = seq_release,
16735 -#ifdef WIRELESS_EXT
16736 +#ifdef CONFIG_WIRELESS_EXT
16737 extern int wireless_proc_init(void);
16739 #define wireless_proc_init() 0
16740 @@ -2582,7 +2580,7 @@
16744 -#ifdef WIRELESS_EXT
16745 +#ifdef CONFIG_WIRELESS_EXT
16746 /* Take care of Wireless Extensions */
16747 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
16748 /* If command is `set a parameter', or
16749 @@ -2603,7 +2601,7 @@
16753 -#endif /* WIRELESS_EXT */
16754 +#endif /* CONFIG_WIRELESS_EXT */
16758 diff -Nur linux-2.6.16/net/core/Makefile linux-2.6.16-bcm43xx/net/core/Makefile
16759 --- linux-2.6.16/net/core/Makefile 2006-03-20 06:53:29.000000000 +0100
16760 +++ linux-2.6.16-bcm43xx/net/core/Makefile 2006-03-28 22:16:14.000000000 +0200
16762 obj-$(CONFIG_SYSFS) += net-sysfs.o
16763 obj-$(CONFIG_NET_DIVERT) += dv.o
16764 obj-$(CONFIG_NET_PKTGEN) += pktgen.o
16765 -obj-$(CONFIG_NET_RADIO) += wireless.o
16766 +obj-$(CONFIG_WIRELESS_EXT) += wireless.o
16767 obj-$(CONFIG_NETPOLL) += netpoll.o
16768 diff -Nur linux-2.6.16/net/d80211/aes.c linux-2.6.16-bcm43xx/net/d80211/aes.c
16769 --- linux-2.6.16/net/d80211/aes.c 1970-01-01 01:00:00.000000000 +0100
16770 +++ linux-2.6.16-bcm43xx/net/d80211/aes.c 2006-03-28 22:16:14.000000000 +0200
16772 +/* Based on Rijndael implementation that has been placed in the public domain,
16773 + * although heavily modified.
16775 + * Modifications Copyright 2003, Instant802 Networks, Inc.
16777 + * This program is free software; you can redistribute it and/or modify
16778 + * it under the terms of the GNU General Public License version 2 as
16779 + * published by the Free Software Foundation.
16781 + * Optimized both speed and size by removing not used key lengths (only
16782 + * 128-bit is used in IEEE 802.11i).
16785 +/* Use 256-byte Te4 table instead of larger 1024-byte */
16788 +/* Save data size by using only one 1k table, but with a drawback of having to
16789 + * rotate entries at lookup. This can be useful, if the CPU supports free
16790 + * rotate on memory read. However, if this is not the case, this is much slower
16791 + * than four-table implementation. */
16792 +/* #define ONLY_ONE_TABLE */
16795 +/* --- start of code that is based on public domain AES implementation --- */
16798 + * rijndael-alg-fst.c
16800 + * @version 3.0 (December 2000)
16802 + * Optimised ANSI C code for the Rijndael cipher (now AES)
16804 + * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
16805 + * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
16806 + * @author Paulo Barreto <paulo.barreto@terra.com.br>
16808 + * This code is hereby placed in the public domain.
16810 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
16811 + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16812 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16813 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
16814 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
16815 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
16816 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
16817 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
16818 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
16819 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
16820 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16824 +Te0[x] = S [x].[02, 01, 01, 03];
16825 +Te1[x] = S [x].[03, 02, 01, 01];
16826 +Te2[x] = S [x].[01, 03, 02, 01];
16827 +Te3[x] = S [x].[01, 01, 03, 02];
16828 +Te4[x] = S [x].[01, 01, 01, 01];
16831 +static const u32 Te0[256] =
16833 + 0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
16834 + 0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
16835 + 0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
16836 + 0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
16837 + 0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
16838 + 0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
16839 + 0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
16840 + 0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
16841 + 0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
16842 + 0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
16843 + 0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
16844 + 0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
16845 + 0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
16846 + 0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
16847 + 0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
16848 + 0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
16849 + 0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
16850 + 0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
16851 + 0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
16852 + 0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
16853 + 0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
16854 + 0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
16855 + 0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
16856 + 0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
16857 + 0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
16858 + 0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
16859 + 0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
16860 + 0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
16861 + 0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
16862 + 0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
16863 + 0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
16864 + 0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
16865 + 0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
16866 + 0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
16867 + 0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
16868 + 0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
16869 + 0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
16870 + 0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
16871 + 0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
16872 + 0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
16873 + 0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
16874 + 0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
16875 + 0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
16876 + 0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
16877 + 0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
16878 + 0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
16879 + 0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
16880 + 0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
16881 + 0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
16882 + 0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
16883 + 0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
16884 + 0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
16885 + 0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
16886 + 0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
16887 + 0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
16888 + 0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
16889 + 0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
16890 + 0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
16891 + 0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
16892 + 0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
16893 + 0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
16894 + 0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
16895 + 0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
16896 + 0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
16899 +#ifndef ONLY_ONE_TABLE
16900 +static const u32 Te1[256] =
16902 + 0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
16903 + 0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
16904 + 0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
16905 + 0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
16906 + 0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
16907 + 0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
16908 + 0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
16909 + 0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
16910 + 0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
16911 + 0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
16912 + 0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
16913 + 0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
16914 + 0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
16915 + 0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
16916 + 0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
16917 + 0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
16918 + 0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
16919 + 0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
16920 + 0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
16921 + 0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
16922 + 0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
16923 + 0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
16924 + 0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
16925 + 0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
16926 + 0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
16927 + 0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
16928 + 0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
16929 + 0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
16930 + 0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
16931 + 0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
16932 + 0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
16933 + 0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
16934 + 0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
16935 + 0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
16936 + 0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
16937 + 0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
16938 + 0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
16939 + 0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
16940 + 0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
16941 + 0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
16942 + 0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
16943 + 0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
16944 + 0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
16945 + 0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
16946 + 0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
16947 + 0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
16948 + 0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
16949 + 0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
16950 + 0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
16951 + 0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
16952 + 0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
16953 + 0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
16954 + 0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
16955 + 0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
16956 + 0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
16957 + 0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
16958 + 0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
16959 + 0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
16960 + 0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
16961 + 0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
16962 + 0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
16963 + 0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
16964 + 0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
16965 + 0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
16968 +static const u32 Te2[256] =
16970 + 0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
16971 + 0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
16972 + 0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
16973 + 0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
16974 + 0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
16975 + 0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
16976 + 0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
16977 + 0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
16978 + 0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
16979 + 0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
16980 + 0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
16981 + 0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
16982 + 0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
16983 + 0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
16984 + 0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
16985 + 0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
16986 + 0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
16987 + 0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
16988 + 0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
16989 + 0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
16990 + 0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
16991 + 0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
16992 + 0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
16993 + 0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
16994 + 0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
16995 + 0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
16996 + 0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
16997 + 0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
16998 + 0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
16999 + 0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
17000 + 0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
17001 + 0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
17002 + 0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
17003 + 0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
17004 + 0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
17005 + 0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
17006 + 0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
17007 + 0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
17008 + 0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
17009 + 0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
17010 + 0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
17011 + 0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
17012 + 0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
17013 + 0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
17014 + 0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
17015 + 0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
17016 + 0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
17017 + 0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
17018 + 0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
17019 + 0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
17020 + 0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
17021 + 0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
17022 + 0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
17023 + 0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
17024 + 0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
17025 + 0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
17026 + 0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
17027 + 0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
17028 + 0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
17029 + 0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
17030 + 0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
17031 + 0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
17032 + 0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
17033 + 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
17036 +static const u32 Te3[256] =
17038 + 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
17039 + 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
17040 + 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
17041 + 0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
17042 + 0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
17043 + 0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
17044 + 0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
17045 + 0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
17046 + 0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
17047 + 0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
17048 + 0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
17049 + 0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
17050 + 0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
17051 + 0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
17052 + 0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
17053 + 0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
17054 + 0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
17055 + 0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
17056 + 0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
17057 + 0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
17058 + 0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
17059 + 0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
17060 + 0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
17061 + 0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
17062 + 0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
17063 + 0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
17064 + 0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
17065 + 0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
17066 + 0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
17067 + 0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
17068 + 0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
17069 + 0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
17070 + 0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
17071 + 0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
17072 + 0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
17073 + 0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
17074 + 0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
17075 + 0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
17076 + 0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
17077 + 0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
17078 + 0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
17079 + 0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
17080 + 0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
17081 + 0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
17082 + 0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
17083 + 0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
17084 + 0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
17085 + 0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
17086 + 0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
17087 + 0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
17088 + 0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
17089 + 0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
17090 + 0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
17091 + 0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
17092 + 0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
17093 + 0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
17094 + 0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
17095 + 0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
17096 + 0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
17097 + 0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
17098 + 0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
17099 + 0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
17100 + 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
17101 + 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
17104 +#define TE0(v) (Te0[(v) >> 24])
17105 +#define TE1(v) (Te1[((v) >> 16) & 0xff])
17106 +#define TE2(v) (Te2[((v) >> 8) & 0xff])
17107 +#define TE3(v) (Te3[(v) & 0xff])
17109 +#else /* ONLY_ONE_TABLE */
17112 +static inline u32 ROR8(u32 v)
17114 + return (v >> 8) | (v << 24);
17117 +static inline u32 ROR16(u32 v)
17119 + return (v >> 16) | (v << 16);
17122 +static inline u32 ROR24(u32 v)
17124 + return (v >> 24) | (v << 8);
17127 +#define TE0(v) (Te0[(v) >> 24])
17128 +#define TE1(v) (ROR8(Te0[((v) >> 16) & 0xff]))
17129 +#define TE2(v) (ROR16(Te0[((v) >> 8) & 0xff]))
17130 +#define TE3(v) (ROR24(Te0[(v) & 0xff]))
17132 +#endif /* ONLY_ONE_TABLE */
17137 +static const u8 Te4s[256] = {
17138 + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5,
17139 + 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
17140 + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
17141 + 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
17142 + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc,
17143 + 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
17144 + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a,
17145 + 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
17146 + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
17147 + 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
17148 + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b,
17149 + 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
17150 + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85,
17151 + 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
17152 + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
17153 + 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
17154 + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17,
17155 + 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
17156 + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88,
17157 + 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
17158 + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
17159 + 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
17160 + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9,
17161 + 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
17162 + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6,
17163 + 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
17164 + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
17165 + 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
17166 + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94,
17167 + 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
17168 + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68,
17169 + 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16,
17172 +#define TE4_1(v) (Te4s[(v) & 0xff] << 24)
17173 +#define TE4_2(v) (Te4s[(v) & 0xff] << 16)
17174 +#define TE4_3(v) (Te4s[(v) & 0xff] << 8)
17175 +#define TE4_4(v) (Te4s[(v) & 0xff])
17177 +#else /* SMALL_TE4 */
17179 +static const u32 Te4[256] =
17181 + 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
17182 + 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
17183 + 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
17184 + 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
17185 + 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
17186 + 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
17187 + 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
17188 + 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
17189 + 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
17190 + 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
17191 + 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
17192 + 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
17193 + 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
17194 + 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
17195 + 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
17196 + 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
17197 + 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
17198 + 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
17199 + 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
17200 + 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
17201 + 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
17202 + 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
17203 + 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
17204 + 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
17205 + 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
17206 + 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
17207 + 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
17208 + 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
17209 + 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
17210 + 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
17211 + 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
17212 + 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
17213 + 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
17214 + 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
17215 + 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
17216 + 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
17217 + 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
17218 + 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
17219 + 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
17220 + 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
17221 + 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
17222 + 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
17223 + 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
17224 + 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
17225 + 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
17226 + 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
17227 + 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
17228 + 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
17229 + 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
17230 + 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
17231 + 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
17232 + 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
17233 + 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
17234 + 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
17235 + 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
17236 + 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
17237 + 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
17238 + 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
17239 + 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
17240 + 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
17241 + 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
17242 + 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
17243 + 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
17244 + 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
17247 +#define TE4_1(v) (Te4[(v) & 0xff] & 0xff000000)
17248 +#define TE4_2(v) (Te4[(v) & 0xff] & 0x00ff0000)
17249 +#define TE4_3(v) (Te4[(v) & 0xff] & 0x0000ff00)
17250 +#define TE4_4(v) (Te4[(v) & 0xff] & 0x000000ff)
17252 +#endif /* SMALL_TE4 */
17255 +static const u32 rcon[] = {
17256 + 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
17257 + 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
17260 +#define GETU32(pt) \
17261 +(((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ \
17263 +#define PUTU32(ct, st) \
17264 +{ (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); \
17265 +(ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
17268 +/* Expand the cipher key into the encryption key schedule. */
17269 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[])
17274 + rk[0] = GETU32(key );
17275 + rk[1] = GETU32(key + 4);
17276 + rk[2] = GETU32(key + 8);
17277 + rk[3] = GETU32(key + 12);
17279 + for (i = 0; i < 10; i++) {
17281 + rk[4] = rk[0] ^ TE4_1(temp >> 16) ^ TE4_2(temp >> 8) ^
17282 + TE4_3(temp) ^ TE4_4(temp >> 24) ^ rcon[i];
17283 + rk[5] = rk[1] ^ rk[4];
17284 + rk[6] = rk[2] ^ rk[5];
17285 + rk[7] = rk[3] ^ rk[6];
17291 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
17293 + const int Nr = 10;
17294 + u32 s0, s1, s2, s3, t0, t1, t2, t3;
17296 + /* Map byte array block to cipher state and add initial round key */
17297 + s0 = GETU32(pt ) ^ rk[0];
17298 + s1 = GETU32(pt + 4) ^ rk[1];
17299 + s2 = GETU32(pt + 8) ^ rk[2];
17300 + s3 = GETU32(pt + 12) ^ rk[3];
17302 +#define ROUND(r,d,s,i) \
17303 +d##0 = TE0(s##0) ^ TE1(s##1) ^ TE2(s##2) ^ TE3(s##3) ^ rk[i]; \
17304 +d##1 = TE0(s##1) ^ TE1(s##2) ^ TE2(s##3) ^ TE3(s##0) ^ rk[i + 1]; \
17305 +d##2 = TE0(s##2) ^ TE1(s##3) ^ TE2(s##0) ^ TE3(s##1) ^ rk[i + 2]; \
17306 +d##3 = TE0(s##3) ^ TE1(s##0) ^ TE2(s##1) ^ TE3(s##2) ^ rk[i + 3]
17320 + /* Apply the last round and map cipher state to byte array block */
17321 + s0 = TE4_1(t0 >> 24) ^ TE4_2(t1 >> 16) ^ TE4_3(t2 >> 8) ^ TE4_4(t3) ^
17324 + s0 = TE4_1(t1 >> 24) ^ TE4_2(t2 >> 16) ^ TE4_3(t3 >> 8) ^ TE4_4(t0) ^
17326 + PUTU32(ct + 4, s0);
17327 + s0 = TE4_1(t2 >> 24) ^ TE4_2(t3 >> 16) ^ TE4_3(t0 >> 8) ^ TE4_4(t1) ^
17329 + PUTU32(ct + 8, s0);
17330 + s0 = TE4_1(t3 >> 24) ^ TE4_2(t0 >> 16) ^ TE4_3(t1 >> 8) ^ TE4_4(t2) ^
17332 + PUTU32(ct + 12, s0);
17335 +/* --- end of code that is based on public domain AES implementation --- */
17336 diff -Nur linux-2.6.16/net/d80211/aes_ccm.c linux-2.6.16-bcm43xx/net/d80211/aes_ccm.c
17337 --- linux-2.6.16/net/d80211/aes_ccm.c 1970-01-01 01:00:00.000000000 +0100
17338 +++ linux-2.6.16-bcm43xx/net/d80211/aes_ccm.c 2006-03-28 22:16:14.000000000 +0200
17341 + * Copyright 2003-2004, Instant802 Networks, Inc.
17342 + * Copyright 2005, Devicescape Software, Inc.
17344 + * This program is free software; you can redistribute it and/or modify
17345 + * it under the terms of the GNU General Public License version 2 as
17346 + * published by the Free Software Foundation.
17349 +#include <linux/types.h>
17350 +#include <linux/netdevice.h>
17352 +#include <net/d80211.h>
17353 +#include "ieee80211_key.h"
17354 +#include "aes_ccm.h"
17358 +static inline void aes_ccm_prepare(u32 *rk, u8 *b_0, u8 *aad, u8 *b,
17363 + ieee80211_aes_encrypt(rk, b_0, b);
17365 + /* Extra Authenticate-only data (always two AES blocks) */
17366 + for (i = 0; i < AES_BLOCK_LEN; i++)
17368 + ieee80211_aes_encrypt(rk, aad, b);
17370 + aad += AES_BLOCK_LEN;
17372 + for (i = 0; i < AES_BLOCK_LEN; i++)
17374 + ieee80211_aes_encrypt(rk, aad, a);
17376 + /* Mask out bits from auth-only-b_0 */
17379 + /* S_0 is used to encrypt T (= MIC) */
17382 + ieee80211_aes_encrypt(rk, b_0, s_0);
17386 +void ieee80211_aes_ccm_encrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *data,
17387 + size_t data_len, u8 *cdata, u8 *mic)
17389 + int i, j, last_len, num_blocks;
17391 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], e[AES_BLOCK_LEN];
17393 + num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
17394 + last_len = data_len % AES_BLOCK_LEN;
17395 + aes_ccm_prepare(rk, b_0, aad, b, s_0, b);
17397 + /* Process payload blocks */
17400 + for (j = 1; j <= num_blocks; j++) {
17401 + int blen = (j == num_blocks && last_len) ?
17402 + last_len : AES_BLOCK_LEN;
17404 + /* Authentication followed by encryption */
17405 + for (i = 0; i < blen; i++)
17407 + ieee80211_aes_encrypt(rk, b, b);
17409 + b_0[14] = (j >> 8) & 0xff;
17410 + b_0[15] = j & 0xff;
17411 + ieee80211_aes_encrypt(rk, b_0, e);
17412 + for (i = 0; i < blen; i++)
17413 + *cpos++ = *pos++ ^ e[i];
17416 + for (i = 0; i < CCMP_MIC_LEN; i++)
17417 + mic[i] = b[i] ^ s_0[i];
17421 +int ieee80211_aes_ccm_decrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *cdata,
17422 + size_t data_len, u8 *mic, u8 *data)
17424 + int i, j, last_len, num_blocks;
17426 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], a[AES_BLOCK_LEN];
17428 + num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
17429 + last_len = data_len % AES_BLOCK_LEN;
17430 + aes_ccm_prepare(rk, b_0, aad, b, s_0, a);
17432 + /* Process payload blocks */
17435 + for (j = 1; j <= num_blocks; j++) {
17436 + int blen = (j == num_blocks && last_len) ?
17437 + last_len : AES_BLOCK_LEN;
17439 + /* Decryption followed by authentication */
17440 + b_0[14] = (j >> 8) & 0xff;
17441 + b_0[15] = j & 0xff;
17442 + ieee80211_aes_encrypt(rk, b_0, b);
17443 + for (i = 0; i < blen; i++) {
17444 + *pos = *cpos++ ^ b[i];
17448 + ieee80211_aes_encrypt(rk, a, a);
17451 + for (i = 0; i < CCMP_MIC_LEN; i++) {
17452 + if ((mic[i] ^ s_0[i]) != a[i])
17459 diff -Nur linux-2.6.16/net/d80211/aes_ccm.h linux-2.6.16-bcm43xx/net/d80211/aes_ccm.h
17460 --- linux-2.6.16/net/d80211/aes_ccm.h 1970-01-01 01:00:00.000000000 +0100
17461 +++ linux-2.6.16-bcm43xx/net/d80211/aes_ccm.h 2006-03-28 22:16:14.000000000 +0200
17464 + * Copyright 2003-2004, Instant802 Networks, Inc.
17466 + * This program is free software; you can redistribute it and/or modify
17467 + * it under the terms of the GNU General Public License version 2 as
17468 + * published by the Free Software Foundation.
17474 +#include <linux/types.h>
17476 +#define AES_BLOCK_LEN 16
17477 +#define AES_STATE_LEN 44
17479 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[]);
17480 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16]);
17481 +void ieee80211_aes_ccm_encrypt(u32 rk[/*44*/], u8 *b_0, u8 *aad, u8 *data,
17482 + size_t data_len, u8 *cdata, u8 *mic);
17483 +int ieee80211_aes_ccm_decrypt(u32 rk[/*44*/], u8 *b_0, u8 *aad, u8 *cdata,
17484 + size_t data_len, u8 *mic, u8 *data);
17486 +#endif /* AES_CCM_H */
17487 diff -Nur linux-2.6.16/net/d80211/fifo_qdisc.c linux-2.6.16-bcm43xx/net/d80211/fifo_qdisc.c
17488 --- linux-2.6.16/net/d80211/fifo_qdisc.c 1970-01-01 01:00:00.000000000 +0100
17489 +++ linux-2.6.16-bcm43xx/net/d80211/fifo_qdisc.c 2006-03-28 22:16:14.000000000 +0200
17492 + * Copyright 2005, Devicescape Software, Inc.
17494 + * This program is free software; you can redistribute it and/or modify
17495 + * it under the terms of the GNU General Public License version 2 as
17496 + * published by the Free Software Foundation.
17498 + * If building without CONFIG_NET_SCHED we need a simple
17499 + * fifo qdisc to install by default as the sub-qdisc.
17500 + * This is a simple replacement for sch_fifo.
17503 +#include <linux/config.h>
17504 +#include <linux/version.h>
17505 +#include <linux/netdevice.h>
17506 +#include <net/d80211.h>
17507 +#include "ieee80211_i.h"
17510 +static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* qd)
17512 + struct sk_buff_head *q = qdisc_priv(qd);
17514 + if (skb_queue_len(q) > qd->dev->tx_queue_len) {
17515 + qd->qstats.drops++;
17517 + return NET_XMIT_DROP;
17520 + skb_queue_tail(q, skb);
17522 + qd->bstats.bytes += skb->len;
17523 + qd->bstats.packets++;
17525 + return NET_XMIT_SUCCESS;
17529 +static int pfifo_requeue(struct sk_buff *skb, struct Qdisc* qd)
17531 + struct sk_buff_head *q = qdisc_priv(qd);
17533 + skb_queue_head(q, skb);
17535 + qd->bstats.bytes += skb->len;
17536 + qd->bstats.packets++;
17538 + return NET_XMIT_SUCCESS;
17542 +static struct sk_buff *pfifo_dequeue(struct Qdisc* qd)
17544 + struct sk_buff_head *q = qdisc_priv(qd);
17546 + return skb_dequeue(q);
17550 +static int pfifo_init(struct Qdisc* qd, struct rtattr *opt)
17552 + struct sk_buff_head *q = qdisc_priv(qd);
17554 + skb_queue_head_init(q);
17559 +static void pfifo_reset(struct Qdisc* qd)
17561 + struct sk_buff_head *q = qdisc_priv(qd);
17563 + skb_queue_purge(q);
17568 +static int pfifo_dump(struct Qdisc *qd, struct sk_buff *skb)
17574 +struct Qdisc_ops pfifo_qdisc_ops =
17578 + .id = "ieee80211_pfifo",
17579 + .priv_size = sizeof(struct sk_buff_head),
17581 + .enqueue = pfifo_enqueue,
17582 + .dequeue = pfifo_dequeue,
17583 + .requeue = pfifo_requeue,
17586 + .init = pfifo_init,
17587 + .reset = pfifo_reset,
17591 + .dump = pfifo_dump,
17594 diff -Nur linux-2.6.16/net/d80211/hostapd_ioctl.h linux-2.6.16-bcm43xx/net/d80211/hostapd_ioctl.h
17595 --- linux-2.6.16/net/d80211/hostapd_ioctl.h 1970-01-01 01:00:00.000000000 +0100
17596 +++ linux-2.6.16-bcm43xx/net/d80211/hostapd_ioctl.h 2006-03-28 22:16:14.000000000 +0200
17599 + * Host AP (software wireless LAN access point) user space daemon for
17600 + * Host AP kernel driver
17601 + * Copyright 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
17602 + * Copyright 2002-2004, Instant802 Networks, Inc.
17603 + * Copyright 2005, Devicescape Software, Inc.
17605 + * This program is free software; you can redistribute it and/or modify
17606 + * it under the terms of the GNU General Public License version 2 as
17607 + * published by the Free Software Foundation.
17610 +#ifndef HOSTAPD_IOCTL_H
17611 +#define HOSTAPD_IOCTL_H
17613 +#include <linux/types.h>
17615 +#ifndef __KERNEL__
17616 +#include "ieee80211_shared.h"
17617 +#endif /* __KERNEL__ */
17619 +#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
17620 +#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
17621 +#define PRISM2_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 3)
17622 +#define PRISM2_IOCTL_TEST_PARAM (SIOCIWFIRSTPRIV + 4)
17624 +/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
17626 + PRISM2_PARAM_PTYPE = 1,
17627 + PRISM2_PARAM_TXRATECTRL = 2,
17628 + PRISM2_PARAM_BEACON_INT = 3,
17629 + PRISM2_PARAM_PSEUDO_IBSS = 4,
17630 + PRISM2_PARAM_ALC = 5,
17631 + PRISM2_PARAM_TXPOWER = 6,
17632 + PRISM2_PARAM_DUMP = 7,
17633 + PRISM2_PARAM_OTHER_AP_POLICY = 8,
17634 + PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
17635 + PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
17636 + PRISM2_PARAM_DTIM_PERIOD = 11,
17637 + PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
17638 + PRISM2_PARAM_MAX_WDS = 13,
17639 + PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
17640 + PRISM2_PARAM_AP_AUTH_ALGS = 15,
17641 + PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
17642 + PRISM2_PARAM_HOST_ENCRYPT = 17,
17643 + PRISM2_PARAM_HOST_DECRYPT = 18,
17644 + PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
17645 + PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
17646 + PRISM2_PARAM_HOST_ROAMING = 21,
17647 + PRISM2_PARAM_BCRX_STA_KEY = 22,
17648 + PRISM2_PARAM_IEEE_802_1X = 23,
17649 + PRISM2_PARAM_ANTSEL_TX = 24,
17650 + PRISM2_PARAM_ANTSEL_RX = 25,
17651 + PRISM2_PARAM_MONITOR_TYPE = 26,
17652 + PRISM2_PARAM_WDS_TYPE = 27,
17653 + PRISM2_PARAM_HOSTSCAN = 28,
17654 + PRISM2_PARAM_AP_SCAN = 29,
17656 + /* Instant802 additions */
17657 + PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES = 1001,
17658 + PRISM2_PARAM_DROP_UNENCRYPTED = 1002,
17659 + PRISM2_PARAM_PREAMBLE = 1003,
17660 + PRISM2_PARAM_RATE_LIMIT = 1004,
17661 + PRISM2_PARAM_RATE_LIMIT_BURST = 1005,
17662 + PRISM2_PARAM_SHORT_SLOT_TIME = 1006,
17663 + PRISM2_PARAM_TEST_MODE = 1007,
17664 + PRISM2_PARAM_NEXT_MODE = 1008,
17665 + PRISM2_PARAM_CLEAR_KEYS = 1009,
17666 + PRISM2_PARAM_ADM_STATUS = 1010,
17667 + PRISM2_PARAM_ANTENNA_SEL = 1011,
17668 + PRISM2_PARAM_CALIB_INT = 1012,
17669 + PRISM2_PARAM_ANTENNA_MODE = 1013,
17670 + PRISM2_PARAM_PRIVACY_INVOKED = 1014,
17671 + PRISM2_PARAM_BROADCAST_SSID = 1015,
17672 + PRISM2_PARAM_STAT_TIME = 1016,
17673 + PRISM2_PARAM_STA_ANTENNA_SEL = 1017,
17674 + PRISM2_PARAM_FORCE_UNICAST_RATE = 1018,
17675 + PRISM2_PARAM_RATE_CTRL_NUM_UP = 1019,
17676 + PRISM2_PARAM_RATE_CTRL_NUM_DOWN = 1020,
17677 + PRISM2_PARAM_MAX_RATECTRL_RATE = 1021,
17678 + PRISM2_PARAM_TX_POWER_REDUCTION = 1022,
17679 + PRISM2_PARAM_EAPOL = 1023,
17680 + PRISM2_PARAM_KEY_TX_RX_THRESHOLD = 1024,
17681 + PRISM2_PARAM_KEY_INDEX = 1025,
17682 + PRISM2_PARAM_DEFAULT_WEP_ONLY = 1026,
17683 + PRISM2_PARAM_WIFI_WME_NOACK_TEST = 1033,
17684 + PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS = 1034,
17685 + PRISM2_PARAM_SCAN_FLAGS = 1035,
17686 + PRISM2_PARAM_HW_MODES = 1036,
17687 + PRISM2_PARAM_CREATE_IBSS = 1037,
17688 + PRISM2_PARAM_WMM_ENABLED = 1038,
17689 + PRISM2_PARAM_MIXED_CELL = 1039,
17690 + PRISM2_PARAM_KEY_MGMT = 1040,
17691 + PRISM2_PARAM_RADAR_DETECT = 1043,
17692 + PRISM2_PARAM_SPECTRUM_MGMT = 1044,
17693 + /* NOTE: Please try to coordinate with other active development
17694 + * branches before allocating new param numbers so that each new param
17695 + * will be unique within all branches and the allocated number will not
17696 + * need to be changed when merging new features. Existing numbers in
17697 + * the mainline (or main devel branch) must not be changed when merging
17698 + * in new features. */
17701 +/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
17703 + PRISM2_HOSTAPD_FLUSH = 1,
17704 + PRISM2_HOSTAPD_ADD_STA = 2,
17705 + PRISM2_HOSTAPD_REMOVE_STA = 3,
17706 + PRISM2_HOSTAPD_GET_INFO_STA = 4,
17707 + /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
17708 + PRISM2_SET_ENCRYPTION = 6,
17709 + PRISM2_GET_ENCRYPTION = 7,
17710 + PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
17711 + PRISM2_HOSTAPD_GET_RID = 9,
17712 + PRISM2_HOSTAPD_SET_RID = 10,
17713 + PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
17714 + PRISM2_HOSTAPD_MLME = 13,
17716 + /* Instant802 additions */
17717 + PRISM2_HOSTAPD_SET_BEACON = 1001,
17718 + PRISM2_HOSTAPD_GET_HW_FEATURES = 1002,
17719 + PRISM2_HOSTAPD_SCAN = 1003,
17720 + PRISM2_HOSTAPD_WPA_TRIGGER = 1004,
17721 + PRISM2_HOSTAPD_SET_RATE_SETS = 1005,
17722 + PRISM2_HOSTAPD_ADD_IF = 1006,
17723 + PRISM2_HOSTAPD_REMOVE_IF = 1007,
17724 + PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE = 1008,
17725 + PRISM2_HOSTAPD_GET_LOAD_STATS = 1009,
17726 + PRISM2_HOSTAPD_SET_STA_VLAN = 1010,
17727 + PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM = 1011,
17728 + PRISM2_HOSTAPD_SET_CHANNEL_FLAG = 1012,
17729 + PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN = 1013,
17730 + PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS = 1014,
17731 + PRISM2_HOSTAPD_SET_BSS = 1015,
17732 + PRISM2_HOSTAPD_GET_TX_STATS = 1016,
17733 + PRISM2_HOSTAPD_UPDATE_IF = 1017,
17734 + PRISM2_HOSTAPD_SCAN_REQ = 1019,
17735 + PRISM2_STA_GET_STATE = 1020,
17736 + PRISM2_HOSTAPD_FLUSH_IFS = 1021,
17737 + PRISM2_HOSTAPD_SET_RADAR_PARAMS = 1023,
17738 + PRISM2_HOSTAPD_SET_QUIET_PARAMS = 1024,
17739 + PRISM2_HOSTAPD_GET_TX_POWER = 1025,
17740 + /* NOTE: Please try to coordinate with other active development
17741 + * branches before allocating new param numbers so that each new param
17742 + * will be unique within all branches and the allocated number will not
17743 + * need to be changed when merging new features. Existing numbers in
17744 + * the mainline (or main devel branch) must not be changed when merging
17745 + * in new features. */
17748 + /* these definitions mirror the ieee80211_i.h
17749 + * IEEE80211_DISABLED, ... IEEE80211_ASSOCIATED enumeration */
17751 + PRISM2_PARAM_STA_DISABLED,
17752 + PRISM2_PARAM_STA_AUTHENTICATE,
17753 + PRISM2_PARAM_STA_ASSOCIATE,
17754 + PRISM2_PARAM_STA_ASSOCIATED,
17757 +#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
17758 +#define HOSTAP_CRYPT_ALG_NAME_LEN 16
17760 +/* Use this to make sure that structure elements are correctly aligned
17761 + * for access as other types. Most commonly, this affects the placeholder
17762 + * types used for data at the end of a structure in this union.
17766 +#define ALIGNED __attribute__ ((aligned))
17768 +/* Check if it has been defined elsewhere */
17770 +#error "Must define ALIGNED to generate aligned structure elements"
17774 +struct prism2_hostapd_param {
17776 + u8 sta_addr[ETH_ALEN];
17782 + u8 supp_rates[32];
17783 + /* atheros_super_ag and enc_flags are only used with
17784 + * IEEE80211_ATHEROS_SUPER_AG
17786 + u8 atheros_super_ag;
17787 + u8 atheros_xr_mode;
17789 +#define IEEE80211_STA_DYNAMIC_ENC BIT(0)
17793 + u32 inactive_msec;
17798 + u32 current_tx_rate; /* in 100 kbps */
17801 + u32 num_ps_buf_frames;
17802 + u32 tx_retry_failed;
17803 + u32 tx_retry_count;
17805 + u32 last_ack_rssi;
17808 + u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
17812 +#define HOSTAP_SEQ_COUNTER_SIZE 8
17813 + u8 seq_counter[HOSTAP_SEQ_COUNTER_SIZE];
17815 + u8 key[0] ALIGNED;
17824 + u8 data[0] ALIGNED;
17829 + u8 data[0] ALIGNED; /* head_len + tail_len bytes */
17834 + u8 data[0] ALIGNED; /* num_modes * feature data */
17838 + s8 our_mode_only;
17841 + s16 interval; /* seconds */
17842 + s32 listen; /* microseconds */
17845 +#define WPA_TRIGGER_FAIL_TX_MIC BIT(0)
17846 +#define WPA_TRIGGER_FAIL_TX_ICV BIT(1)
17847 +#define WPA_TRIGGER_FAIL_RX_MIC BIT(2)
17848 +#define WPA_TRIGGER_FAIL_RX_ICV BIT(3)
17849 +#define WPA_TRIGGER_TX_REPLAY BIT(4)
17850 +#define WPA_TRIGGER_TX_REPLAY_FRAG BIT(5)
17851 +#define WPA_TRIGGER_TX_SKIP_SEQ BIT(6)
17855 + u16 mode; /* MODE_* */
17856 + u16 num_supported_rates;
17857 + u16 num_basic_rates;
17858 + u8 data[0] ALIGNED; /* num_supported_rates * u16 +
17859 + * num_basic_rates * u16 */
17862 + u8 type; /* WDS, VLAN, etc */
17863 + u8 name[IFNAMSIZ];
17864 + u8 data[0] ALIGNED;
17866 + struct dot11_counters {
17867 + u32 dot11TransmittedFragmentCount;
17868 + u32 dot11MulticastTransmittedFrameCount;
17869 + u32 dot11FailedCount;
17870 + u32 dot11ReceivedFragmentCount;
17871 + u32 dot11MulticastReceivedFrameCount;
17872 + u32 dot11FCSErrorCount;
17873 + u32 dot11TransmittedFrameCount;
17874 + u32 dot11WEPUndecryptableCount;
17875 + u32 dot11ACKFailureCount;
17876 + u32 dot11RTSFailureCount;
17877 + u32 dot11RTSSuccessCount;
17878 + } dot11CountersTable;
17880 +#define LOAD_STATS_CLEAR BIT(1)
17883 + } get_load_stats;
17885 + char vlan_name[IFNAMSIZ];
17890 + u8 data[0] ALIGNED;
17891 + } set_generic_info_elem;
17893 + u16 mode; /* MODE_* */
17896 + u8 power_level; /* regulatory limit in dBm */
17898 + } set_channel_flag;
17901 + } set_regulatory_domain;
17907 + u32 burst_time; /* maximum burst time in 0.1 ms, i.e.,
17909 + } tx_queue_params;
17912 + u8 bssid_mask[ETH_ALEN];
17914 + struct ieee80211_tx_stats {
17916 + unsigned int len; /* num packets in queue */
17917 + unsigned int limit; /* queue len (soft) limit
17919 + unsigned int count; /* total num frames sent */
17924 + u8 ssid[0] ALIGNED;
17930 +#define MLME_STA_DEAUTH 0
17931 +#define MLME_STA_DISASSOC 1
17936 + u8 radar_firpwr_threshold;
17937 + u8 radar_rssi_threshold;
17938 + u8 pulse_height_threshold;
17939 + u8 pulse_rssi_threshold;
17940 + u8 pulse_inband_threshold;
17943 + unsigned int period;
17944 + unsigned int offset;
17945 + unsigned int duration;
17948 + unsigned int tx_power_min;
17949 + unsigned int tx_power_max;
17952 + u8 dummy[80]; /* Make sizeof() this struct large enough
17953 + * with some compiler versions. */
17959 +#ifndef IEEE80211_TX_QUEUE_NUMS
17960 +#define IEEE80211_TX_QUEUE_NUMS
17961 +/* TODO: these need to be synchronized with ieee80211.h; make a shared header
17962 + * file that can be included into low-level drivers, 80211.o, and hostapd */
17963 +/* tx_queue_params - queue */
17965 + IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
17966 + IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
17967 + IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
17968 + IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
17969 + IEEE80211_TX_QUEUE_DATA4 = 4,
17970 + IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
17971 + IEEE80211_TX_QUEUE_BEACON = 7
17973 +#endif /* IEEE80211_TX_QUEUE_NUMS */
17976 +#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
17977 +#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
17979 +#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
17980 +#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
17981 +#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
17982 +#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
17983 +#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
17984 +#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
17986 +#define HOSTAP_HW_FLAG_NULLFUNC_OK BIT(0)
17989 + IEEE80211_KEY_MGMT_NONE = 0,
17990 + IEEE80211_KEY_MGMT_IEEE8021X = 1,
17991 + IEEE80211_KEY_MGMT_WPA_PSK = 2,
17992 + IEEE80211_KEY_MGMT_WPA_EAP = 3,
17996 +/* Data structures used for get_hw_features ioctl */
17997 +struct hostapd_ioctl_hw_modes_hdr {
17999 + int num_channels;
18003 +struct ieee80211_channel_data {
18004 + short chan; /* channel number (IEEE 802.11) */
18005 + short freq; /* frequency in MHz */
18006 + int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
18009 +struct ieee80211_rate_data {
18010 + int rate; /* rate in 100 kbps */
18011 + int flags; /* IEEE80211_RATE_ flags */
18015 +/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
18017 + HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
18018 + HOSTAP_IF_STA = 4
18021 +struct hostapd_if_wds {
18022 + u8 remote_addr[ETH_ALEN];
18025 +struct hostapd_if_vlan {
18029 +struct hostapd_if_bss {
18030 + u8 bssid[ETH_ALEN];
18033 +struct hostapd_if_sta {
18036 +#endif /* HOSTAPD_IOCTL_H */
18037 diff -Nur linux-2.6.16/net/d80211/ieee80211.c linux-2.6.16-bcm43xx/net/d80211/ieee80211.c
18038 --- linux-2.6.16/net/d80211/ieee80211.c 1970-01-01 01:00:00.000000000 +0100
18039 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211.c 2006-03-28 22:16:14.000000000 +0200
18042 + * Copyright 2002-2005, Instant802 Networks, Inc.
18043 + * Copyright 2005-2006, Devicescape Software, Inc.
18045 + * This program is free software; you can redistribute it and/or modify
18046 + * it under the terms of the GNU General Public License version 2 as
18047 + * published by the Free Software Foundation.
18050 +#include <linux/config.h>
18051 +#include <linux/version.h>
18052 +#include <linux/module.h>
18053 +#include <linux/init.h>
18054 +#include <linux/netdevice.h>
18055 +#include <linux/types.h>
18056 +#include <linux/slab.h>
18057 +#include <linux/skbuff.h>
18058 +#include <linux/etherdevice.h>
18059 +#include <linux/if_arp.h>
18060 +#include <linux/wireless.h>
18061 +#include <net/iw_handler.h>
18062 +#include <linux/compiler.h>
18064 +#include <net/d80211.h>
18065 +#include <net/d80211_common.h>
18066 +#include <net/d80211_mgmt.h>
18067 +#include "ieee80211_i.h"
18068 +#include "ieee80211_proc.h"
18069 +#include "rate_control.h"
18076 +/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
18077 +/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
18078 +static unsigned char rfc1042_header[] =
18079 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
18080 +/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
18081 +static unsigned char bridge_tunnel_header[] =
18082 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
18083 +/* No encapsulation header if EtherType < 0x600 (=length) */
18085 +static unsigned char eapol_header[] =
18086 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
18089 +struct rate_control_algs {
18090 + struct rate_control_algs *next;
18091 + struct rate_control_ops *ops;
18094 +static struct rate_control_algs *ieee80211_rate_ctrl_algs;
18096 +static int rate_control_initialize(struct ieee80211_local *local);
18099 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
18102 +struct ieee80211_key_conf *
18103 +ieee80211_key_data2conf(struct ieee80211_local *local,
18104 + struct ieee80211_key *data)
18106 + struct ieee80211_key_conf *conf;
18108 + conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
18109 + if (conf == NULL)
18112 + conf->hw_key_idx = data->hw_key_idx;
18113 + conf->alg = data->alg;
18114 + conf->keylen = data->keylen;
18115 + conf->force_sw_encrypt = data->force_sw_encrypt;
18116 + conf->keyidx = data->keyidx;
18117 + conf->default_tx_key = data->default_tx_key;
18118 + conf->default_wep_only = local->default_wep_only;
18119 + memcpy(conf->key, data->key, data->keylen);
18125 +static int rate_list_match(int *rate_list, int rate)
18129 + if (rate_list == NULL)
18132 + for (i = 0; rate_list[i] >= 0; i++)
18133 + if (rate_list[i] == rate)
18140 +void ieee80211_prepare_rates(struct net_device *dev)
18142 + struct ieee80211_local *local = dev->priv;
18145 + for (i = 0; i < local->num_curr_rates; i++) {
18146 + struct ieee80211_rate *rate = &local->curr_rates[i];
18148 + rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
18149 + IEEE80211_RATE_BASIC);
18151 + if (local->supp_rates[local->conf.phymode]) {
18152 + if (!rate_list_match(local->supp_rates
18153 + [local->conf.phymode],
18158 + rate->flags |= IEEE80211_RATE_SUPPORTED;
18160 + /* Use configured basic rate set if it is available. If not,
18161 + * use defaults that are sane for most cases. */
18162 + if (local->basic_rates[local->conf.phymode]) {
18163 + if (rate_list_match(local->basic_rates
18164 + [local->conf.phymode],
18166 + rate->flags |= IEEE80211_RATE_BASIC;
18167 + } else switch (local->conf.phymode) {
18168 + case MODE_IEEE80211A:
18169 + if (rate->rate == 60 || rate->rate == 120 ||
18170 + rate->rate == 240)
18171 + rate->flags |= IEEE80211_RATE_BASIC;
18173 + case MODE_IEEE80211B:
18174 + if (rate->rate == 10 || rate->rate == 20)
18175 + rate->flags |= IEEE80211_RATE_BASIC;
18177 + case MODE_ATHEROS_TURBO:
18178 + if (rate->rate == 120 || rate->rate == 240 ||
18179 + rate->rate == 480)
18180 + rate->flags |= IEEE80211_RATE_BASIC;
18182 + case MODE_IEEE80211G:
18183 + if (rate->rate == 10 || rate->rate == 20 ||
18184 + rate->rate == 55 || rate->rate == 110)
18185 + rate->flags |= IEEE80211_RATE_BASIC;
18189 + /* Set ERP and MANDATORY flags based on phymode */
18190 + switch (local->conf.phymode) {
18191 + case MODE_IEEE80211A:
18192 + if (rate->rate == 60 || rate->rate == 120 ||
18193 + rate->rate == 240)
18194 + rate->flags |= IEEE80211_RATE_MANDATORY;
18196 + case MODE_IEEE80211B:
18197 + if (rate->rate == 10)
18198 + rate->flags |= IEEE80211_RATE_MANDATORY;
18200 + case MODE_ATHEROS_TURBO:
18202 + case MODE_IEEE80211G:
18203 + if (rate->rate == 10 || rate->rate == 20 ||
18204 + rate->rate == 55 || rate->rate == 110 ||
18205 + rate->rate == 60 || rate->rate == 120 ||
18206 + rate->rate == 240)
18207 + rate->flags |= IEEE80211_RATE_MANDATORY;
18208 + if (rate->rate != 10 && rate->rate != 20 &&
18209 + rate->rate != 55 && rate->rate != 110)
18210 + rate->flags |= IEEE80211_RATE_ERP;
18217 +static void ieee80211_key_threshold_notify(struct net_device *dev,
18218 + struct ieee80211_key *key,
18219 + struct sta_info *sta)
18221 + struct sk_buff *skb;
18222 + struct ieee80211_msg_key_notification *msg;
18224 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
18225 + sizeof(struct ieee80211_msg_key_notification));
18229 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
18230 + msg = (struct ieee80211_msg_key_notification *)
18231 + skb_put(skb, sizeof(struct ieee80211_msg_key_notification));
18232 + msg->tx_rx_count = key->tx_rx_count;
18233 + memcpy(msg->ifname, dev->name, IFNAMSIZ);
18235 + memcpy(msg->addr, sta->addr, ETH_ALEN);
18237 + memset(msg->addr, 0xff, ETH_ALEN);
18239 + key->tx_rx_count = 0;
18241 + ieee80211_rx_mgmt(dev, skb, 0,
18242 + ieee80211_msg_key_threshold_notification);
18246 +int ieee80211_get_hdrlen(u16 fc)
18250 + switch (WLAN_FC_GET_TYPE(fc)) {
18251 + case WLAN_FC_TYPE_DATA:
18252 + if ((fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS))
18253 + hdrlen = 30; /* Addr4 */
18254 + if (WLAN_FC_GET_STYPE(fc) & 0x08)
18255 + hdrlen += 2; /* QoS Control Field */
18257 + case WLAN_FC_TYPE_CTRL:
18258 + switch (WLAN_FC_GET_STYPE(fc)) {
18259 + case WLAN_FC_STYPE_CTS:
18260 + case WLAN_FC_STYPE_ACK:
18274 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb)
18276 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18279 + if (unlikely(skb->len < 10))
18281 + hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
18282 + if (unlikely(hdrlen > skb->len))
18288 +#ifdef IEEE80211_VERBOSE_DEBUG_FRAME_DUMP
18289 +static void ieee80211_dump_frame(const char *ifname, const char *title,
18290 + struct sk_buff *skb)
18292 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18296 + printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
18297 + if (skb->len < 4) {
18302 + fc = le16_to_cpu(hdr->frame_control);
18303 + hdrlen = ieee80211_get_hdrlen(fc);
18304 + if (hdrlen > skb->len)
18305 + hdrlen = skb->len;
18307 + printk(" FC=0x%04x DUR=0x%04x",
18308 + fc, le16_to_cpu(hdr->duration_id));
18309 + if (hdrlen >= 10)
18310 + printk(" A1=" MACSTR, MAC2STR(hdr->addr1));
18311 + if (hdrlen >= 16)
18312 + printk(" A2=" MACSTR, MAC2STR(hdr->addr2));
18313 + if (hdrlen >= 24)
18314 + printk(" A3=" MACSTR, MAC2STR(hdr->addr3));
18315 + if (hdrlen >= 30)
18316 + printk(" A4=" MACSTR, MAC2STR(hdr->addr4));
18319 +#else /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18320 +static inline void ieee80211_dump_frame(const char *ifname, const char *title,
18321 + struct sk_buff *skb)
18324 +#endif /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18327 +static int ieee80211_is_eapol(struct sk_buff *skb)
18329 + struct ieee80211_hdr *hdr;
18333 + if (unlikely(skb->len < 10))
18336 + hdr = (struct ieee80211_hdr *) skb->data;
18337 + fc = le16_to_cpu(hdr->frame_control);
18339 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
18342 + hdrlen = ieee80211_get_hdrlen(fc);
18344 + if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
18345 + memcmp(skb->data + hdrlen, eapol_header,
18346 + sizeof(eapol_header)) == 0))
18353 +static ieee80211_txrx_result
18354 +ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
18356 + struct rate_control_extra extra;
18358 + memset(&extra, 0, sizeof(extra));
18359 + extra.mgmt_data = tx->sdata &&
18360 + tx->sdata->type == IEEE80211_SUB_IF_TYPE_MGMT;
18361 + extra.ethertype = tx->ethertype;
18362 + extra.startidx = 0;
18363 + extra.endidx = tx->local->num_curr_rates;
18365 + tx->u.tx.rate = rate_control_get_rate(tx->dev, tx->skb, &extra);
18366 + if (unlikely(extra.probe != NULL)) {
18367 + tx->u.tx.control->rate_ctrl_probe = 1;
18368 + tx->u.tx.probe_last_frag = 1;
18369 + tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
18370 + tx->u.tx.rate = extra.probe;
18372 + tx->u.tx.control->alt_retry_rate = -1;
18374 + if (!tx->u.tx.rate)
18375 + return TXRX_DROP;
18376 + if (tx->local->conf.phymode == MODE_IEEE80211G &&
18377 + tx->local->cts_protect_erp_frames && tx->fragmented &&
18379 + tx->u.tx.last_frag_rate = tx->u.tx.rate;
18380 + tx->u.tx.last_frag_rateidx = extra.rateidx;
18381 + tx->u.tx.probe_last_frag = extra.probe ? 1 : 0;
18383 + tx->u.tx.rate = extra.nonerp;
18384 + tx->u.tx.control->rateidx = extra.nonerp_idx;
18385 + tx->u.tx.control->rate_ctrl_probe = 0;
18387 + tx->u.tx.last_frag_rate = tx->u.tx.rate;
18388 + tx->u.tx.last_frag_rateidx = extra.rateidx;
18389 + tx->u.tx.control->rateidx = extra.rateidx;
18391 + tx->u.tx.control->tx_rate = tx->u.tx.rate->val;
18392 + if ((tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
18393 + tx->local->short_preamble &&
18394 + (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
18395 + tx->u.tx.short_preamble = 1;
18396 + tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
18399 + return TXRX_CONTINUE;
18403 +static ieee80211_txrx_result
18404 +ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
18407 + tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
18409 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
18411 + if (unlikely(tx->u.tx.control->do_not_encrypt))
18413 + else if (tx->sta && tx->sta->key)
18414 + tx->key = tx->sta->key;
18415 + else if (tx->sdata->default_key)
18416 + tx->key = tx->sdata->default_key;
18417 + else if (tx->sdata->drop_unencrypted &&
18418 + !(tx->sdata->eapol && ieee80211_is_eapol(tx->skb))) {
18419 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
18420 + return TXRX_DROP;
18425 + tx->key->tx_rx_count++;
18426 + if (unlikely(tx->local->key_tx_rx_threshold &&
18427 + tx->key->tx_rx_count >
18428 + tx->local->key_tx_rx_threshold)) {
18429 + ieee80211_key_threshold_notify(tx->dev, tx->key,
18434 + return TXRX_CONTINUE;
18438 +static ieee80211_txrx_result
18439 +ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
18441 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18442 + size_t hdrlen, per_fragm, num_fragm, payload_len, left;
18443 + struct sk_buff **frags, *first, *frag;
18446 + int frag_threshold = tx->local->fragmentation_threshold;
18448 + if (!tx->fragmented)
18449 + return TXRX_CONTINUE;
18453 + hdrlen = ieee80211_get_hdrlen(tx->fc);
18454 + payload_len = first->len - hdrlen;
18455 + per_fragm = frag_threshold - hdrlen - 4 /* FCS */;
18456 + num_fragm = (payload_len + per_fragm - 1) / per_fragm;
18458 + frags = (struct sk_buff **)
18459 + kmalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
18460 + if (frags == NULL)
18462 + memset(frags, 0, num_fragm * sizeof(struct sk_buff *));
18464 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREFRAG);
18465 + pos = first->data + hdrlen + per_fragm;
18466 + left = payload_len - per_fragm;
18467 + for (i = 0; i < num_fragm - 1; i++) {
18468 + struct ieee80211_hdr *fhdr;
18474 + /* reserve enough extra head and tail room for possible
18476 +#define IEEE80211_ENCRYPT_HEADROOM 8
18477 +#define IEEE80211_ENCRYPT_TAILROOM 12
18478 + frag = frags[i] =
18479 + dev_alloc_skb(frag_threshold +
18480 + IEEE80211_ENCRYPT_HEADROOM +
18481 + IEEE80211_ENCRYPT_TAILROOM);
18484 + /* Make sure that all fragments use the same priority so
18485 + * that they end up using the same TX queue */
18486 + frag->priority = first->priority;
18487 + skb_reserve(frag, IEEE80211_ENCRYPT_HEADROOM);
18488 + fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
18489 + memcpy(fhdr, first->data, hdrlen);
18490 + if (i == num_fragm - 2)
18491 + fhdr->frame_control &= cpu_to_le16(~WLAN_FC_MOREFRAG);
18492 + fhdr->seq_ctrl = cpu_to_le16(i + 1);
18493 + copylen = left > per_fragm ? per_fragm : left;
18494 + memcpy(skb_put(frag, copylen), pos, copylen);
18499 + skb_trim(first, hdrlen + per_fragm);
18501 + tx->u.tx.num_extra_frag = num_fragm - 1;
18502 + tx->u.tx.extra_frag = frags;
18504 + return TXRX_CONTINUE;
18507 + printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
18509 + for (i = 0; i < num_fragm - 1; i++)
18511 + dev_kfree_skb(frags[i]);
18514 + I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
18515 + return TXRX_DROP;
18519 +static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
18521 + if (tx->key->force_sw_encrypt || tx->local->conf.sw_encrypt) {
18522 + if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
18525 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
18526 + if (tx->local->hw->wep_include_iv) {
18527 + if (ieee80211_wep_add_iv(tx->local, skb, tx->key) ==
18536 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
18538 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18540 + hdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18541 + if (tx->u.tx.extra_frag) {
18542 + struct ieee80211_hdr *fhdr;
18544 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18545 + fhdr = (struct ieee80211_hdr *)
18546 + tx->u.tx.extra_frag[i]->data;
18547 + fhdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18553 +static ieee80211_txrx_result
18554 +ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
18556 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18559 + fc = le16_to_cpu(hdr->frame_control);
18561 + if (!tx->key || tx->key->alg != ALG_WEP ||
18562 + (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA &&
18563 + (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
18564 + WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_AUTH)))
18565 + return TXRX_CONTINUE;
18567 + tx->u.tx.control->iv_len = WEP_IV_LEN;
18568 + tx->u.tx.control->icv_len = WEP_ICV_LEN;
18569 + ieee80211_tx_set_iswep(tx);
18571 + if (wep_encrypt_skb(tx, tx->skb) < 0) {
18572 + I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
18573 + return TXRX_DROP;
18576 + if (tx->u.tx.extra_frag) {
18578 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18579 + if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
18580 + I802_DEBUG_INC(tx->local->
18581 + tx_handlers_drop_wep);
18582 + return TXRX_DROP;
18587 + return TXRX_CONTINUE;
18591 +static inline int ceiling_div(int dividend, int divisor)
18593 + return ((dividend + divisor - 1) / divisor);
18597 +static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
18598 + int rate, int erp, int short_preamble)
18602 + /* calculate duration (in microseconds, rounded up to next higher
18603 + * integer if it includes a fractional microsecond) to send frame of
18604 + * len bytes (does not include FCS) at the given rate. Duration will
18605 + * also include SIFS.
18607 + * rate is in 100 kbps, so divident is multiplied by 10 in the
18608 + * ceiling_div() operations.
18611 + if (local->conf.phymode == MODE_IEEE80211A || erp ||
18612 + local->conf.phymode == MODE_ATHEROS_TURBO) {
18616 + * N_DBPS = DATARATE x 4
18617 + * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
18618 + * (16 = SIGNAL time, 6 = tail bits)
18619 + * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
18622 + * 802.11a - 17.5.2: aSIFSTime = 16 usec
18623 + * 802.11g - 19.8.4: aSIFSTime = 10 usec +
18624 + * signal ext = 6 usec
18626 + /* FIX: Atheros Turbo may have different (shorter) duration? */
18627 + dur = 16; /* SIFS + signal ext */
18628 + dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
18629 + dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
18630 + dur += 4 * ceiling_div((16 + 8 * (len + 4) + 6) * 10,
18631 + 4 * rate); /* T_SYM x N_SYM */
18634 + * 802.11b or 802.11g with 802.11b compatibility:
18635 + * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
18636 + * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
18638 + * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
18639 + * aSIFSTime = 10 usec
18640 + * aPreambleLength = 144 usec or 72 usec with short preamble
18641 + * aPLCPHeaderLength = 48 ms or 24 ms with short preamble
18643 + dur = 10; /* aSIFSTime = 10 usec */
18644 + dur += short_preamble ? (72 + 24) : (144 + 48);
18646 + dur += ceiling_div(8 * (len + 4) * 10, rate);
18653 +static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
18654 + int next_frag_len)
18656 + int rate, mrate, erp, dur, i;
18657 + struct ieee80211_rate *txrate = tx->u.tx.rate;
18658 + struct ieee80211_local *local = tx->local;
18660 + erp = txrate->flags & IEEE80211_RATE_ERP;
18663 + * data and mgmt (except PS Poll):
18664 + * - during CFP: 32768
18665 + * - during contention period:
18666 + * if addr1 is group address: 0
18667 + * if more fragments = 0 and addr1 is individual address: time to
18668 + * transmit one ACK plus SIFS
18669 + * if more fragments = 1 and addr1 is individual address: time to
18670 + * transmit next fragment plus 2 x ACK plus 3 x SIFS
18672 + * IEEE 802.11, 9.6:
18673 + * - control response frame (CTS or ACK) shall be transmitted using the
18674 + * same rate as the immediately previous frame in the frame exchange
18675 + * sequence, if this rate belongs to the PHY mandatory rates, or else
18676 + * at the highest possible rate belonging to the PHY rates in the
18677 + * BSSBasicRateSet
18680 + if (WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_CTRL) {
18681 + /* TODO: These control frames are not currently sent by
18682 + * 80211.o, but should they be implemented, this function
18683 + * needs to be updated to support duration field calculation.
18685 + * RTS: time needed to transmit pending data/mgmt frame plus
18686 + * one CTS frame plus one ACK frame plus 3 x SIFS
18687 + * CTS: duration of immediately previous RTS minus time
18688 + * required to transmit CTS and its SIFS
18689 + * ACK: 0 if immediately previous directed data/mgmt had
18690 + * more=0, with more=1 duration in ACK frame is duration
18691 + * from previous frame minus time needed to transmit ACK
18693 + * PS Poll: BIT(15) | BIT(14) | aid
18699 + if (0 /* FIX: data/mgmt during CFP */)
18702 + if (group_addr) /* Group address as the destination - no ACK */
18705 + /* Individual destination address:
18706 + * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
18707 + * CTS and ACK frames shall be transmitted using the highest rate in
18708 + * basic rate set that is less than or equal to the rate of the
18709 + * immediately previous frame and that is using the same modulation
18710 + * (CCK or OFDM). If no basic rate set matches with these requirements,
18711 + * the highest mandatory rate of the PHY that is less than or equal to
18712 + * the rate of the previous frame is used.
18713 + * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
18716 + mrate = 10; /* use 1 Mbps if everything fails */
18717 + for (i = 0; i < local->num_curr_rates; i++) {
18718 + struct ieee80211_rate *r = &local->curr_rates[i];
18719 + if (r->rate > txrate->rate)
18722 + if (IEEE80211_RATE_MODULATION(txrate->flags) !=
18723 + IEEE80211_RATE_MODULATION(r->flags))
18726 + if (r->flags & IEEE80211_RATE_BASIC)
18728 + else if (r->flags & IEEE80211_RATE_MANDATORY)
18731 + if (rate == -1) {
18732 + /* No matching basic rate found; use highest suitable mandatory
18737 + /* Time needed to transmit ACK
18738 + * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
18739 + * to closest integer */
18741 + dur = ieee80211_frame_duration(local, 10, rate, erp,
18742 + local->short_preamble);
18744 + if (next_frag_len) {
18745 + /* Frame is fragmented: duration increases with time needed to
18746 + * transmit next fragment plus ACK and 2 x SIFS. */
18747 + dur *= 2; /* ACK + SIFS */
18748 + /* next fragment */
18749 + dur += ieee80211_frame_duration(local, next_frag_len,
18750 + txrate->rate, erp,
18751 + local->short_preamble);
18758 +static ieee80211_txrx_result
18759 +ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
18761 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18763 + struct ieee80211_tx_control *control = tx->u.tx.control;
18765 + if (!MULTICAST_ADDR(hdr->addr1)) {
18766 + if (tx->skb->len >= tx->local->rts_threshold &&
18767 + tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD) {
18768 + control->use_rts_cts = 1;
18769 + control->retry_limit =
18770 + tx->local->long_retry_limit;
18772 + control->retry_limit =
18773 + tx->local->short_retry_limit;
18776 + control->retry_limit = 1;
18779 + if (tx->fragmented) {
18780 + /* Do not use multiple retry rates when sending fragmented
18782 + * TODO: The last fragment could still use multiple retry
18784 + control->alt_retry_rate = -1;
18787 + /* Use CTS protection for unicast frames sent using extended rates if
18788 + * there are associated non-ERP stations and RTS/CTS is not configured
18789 + * for the frame. */
18790 + if (tx->local->conf.phymode == MODE_IEEE80211G &&
18791 + (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
18792 + tx->u.tx.unicast &&
18793 + tx->local->cts_protect_erp_frames &&
18794 + !control->use_rts_cts)
18795 + control->use_cts_protect = 1;
18797 + /* Setup duration field for the first fragment of the frame. Duration
18798 + * for remaining fragments will be updated when they are being sent
18799 + * to low-level driver in ieee80211_tx(). */
18800 + dur = ieee80211_duration(tx, MULTICAST_ADDR(hdr->addr1),
18801 + tx->fragmented ? tx->u.tx.extra_frag[0]->len :
18803 + hdr->duration_id = cpu_to_le16(dur);
18805 + if (control->use_rts_cts || control->use_cts_protect) {
18806 + struct ieee80211_rate *rate;
18807 + int erp = tx->u.tx.rate->flags & IEEE80211_RATE_ERP;
18809 + /* Do not use multiple retry rates when using RTS/CTS */
18810 + control->alt_retry_rate = -1;
18812 + /* Use min(data rate, max base rate) as CTS/RTS rate */
18813 + rate = tx->u.tx.rate;
18814 + while (rate > tx->local->curr_rates &&
18815 + !(rate->flags & IEEE80211_RATE_BASIC))
18818 + if (control->use_rts_cts)
18819 + dur += ieee80211_frame_duration(tx->local, 10,
18823 + dur += ieee80211_frame_duration(tx->local, tx->skb->len,
18824 + tx->u.tx.rate->rate, erp,
18825 + tx->u.tx.short_preamble);
18826 + control->rts_cts_duration = dur;
18827 + control->rts_cts_rate = rate->val;
18831 + tx->sta->tx_packets++;
18832 + tx->sta->tx_fragments++;
18833 + tx->sta->tx_bytes += tx->skb->len;
18834 + if (tx->u.tx.extra_frag) {
18836 + tx->sta->tx_fragments += tx->u.tx.num_extra_frag;
18837 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
18838 + tx->sta->tx_bytes +=
18839 + tx->u.tx.extra_frag[i]->len;
18843 + tx->local->scan.txrx_count++;
18845 + return TXRX_CONTINUE;
18849 +static void ieee80211_rate_limit(unsigned long data)
18851 + struct ieee80211_local *local = (struct ieee80211_local *) data;
18853 + if (local->rate_limit) {
18854 + local->rate_limit_bucket += local->rate_limit;
18855 + if (local->rate_limit_bucket > local->rate_limit_burst)
18856 + local->rate_limit_bucket = local->rate_limit_burst;
18857 + local->rate_limit_timer.expires = jiffies + HZ;
18858 + add_timer(&local->rate_limit_timer);
18863 +static ieee80211_txrx_result
18864 +ieee80211_tx_h_rate_limit(struct ieee80211_txrx_data *tx)
18867 + if (likely(!tx->local->rate_limit || tx->u.tx.unicast))
18868 + return TXRX_CONTINUE;
18871 + if (tx->local->rate_limit_bucket) {
18872 + tx->local->rate_limit_bucket--;
18873 + return TXRX_CONTINUE;
18876 + I802_DEBUG_INC(tx->local->tx_handlers_drop_rate_limit);
18877 + return TXRX_DROP;
18881 +static ieee80211_txrx_result
18882 +ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
18884 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
18885 + struct sk_buff *skb = tx->skb;
18886 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18887 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
18890 + if (unlikely(tx->local->sta_scanning != 0) &&
18891 + (WLAN_FC_GET_TYPE(tx->fc) != WLAN_FC_TYPE_MGMT ||
18892 + WLAN_FC_GET_STYPE(tx->fc) != WLAN_FC_STYPE_PROBE_REQ))
18893 + return TXRX_DROP;
18895 + if (tx->u.tx.ps_buffered)
18896 + return TXRX_CONTINUE;
18898 + sta_flags = tx->sta ? tx->sta->flags : 0;
18900 + if (likely(tx->u.tx.unicast)) {
18901 + if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
18902 + tx->local->conf.mode != IW_MODE_ADHOC &&
18903 + WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_DATA)) {
18904 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
18905 + printk(KERN_DEBUG "%s: dropped data frame to not "
18906 + "associated station " MACSTR "\n",
18907 + tx->dev->name, MAC2STR(hdr->addr1));
18908 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
18909 + I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
18910 + return TXRX_DROP;
18913 + if (unlikely(WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_DATA &&
18914 + tx->local->num_sta == 0 &&
18915 + !tx->local->allow_broadcast_always &&
18916 + tx->local->conf.mode != IW_MODE_ADHOC)) {
18918 + * No associated STAs - no need to send multicast
18921 + return TXRX_DROP;
18923 + return TXRX_CONTINUE;
18926 + if (unlikely(!tx->u.tx.mgmt_interface && tx->sdata->ieee802_1x &&
18927 + !(sta_flags & WLAN_STA_AUTHORIZED))) {
18928 +#ifdef CONFIG_D80211_DEBUG
18929 + struct ieee80211_hdr *hdr =
18930 + (struct ieee80211_hdr *) tx->skb->data;
18931 + printk(KERN_DEBUG "%s: dropped frame to " MACSTR
18932 + " (unauthorized port)\n", tx->dev->name,
18933 + MAC2STR(hdr->addr1));
18935 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
18936 + return TXRX_DROP;
18939 + return TXRX_CONTINUE;
18943 +/* This function is called whenever the AP is about to exceed the maximum limit
18944 + * of buffered frames for power saving STAs. This situation should not really
18945 + * happen often during normal operation, so dropping the oldest buffered packet
18946 + * from each queue should be OK to make some room for new frames. */
18947 +static void purge_old_ps_buffers(struct ieee80211_local *local)
18949 + int total = 0, purged = 0;
18950 + struct sk_buff *skb;
18951 + struct list_head *ptr;
18953 + spin_lock_bh(&local->sub_if_lock);
18954 + list_for_each(ptr, &local->sub_if_list) {
18955 + struct ieee80211_if_ap *ap;
18956 + struct ieee80211_sub_if_data *sdata =
18957 + list_entry(ptr, struct ieee80211_sub_if_data, list);
18958 + if (sdata->dev == local->mdev ||
18959 + sdata->type != IEEE80211_SUB_IF_TYPE_AP)
18961 + ap = &sdata->u.ap;
18962 + skb = skb_dequeue(&ap->ps_bc_buf);
18965 + dev_kfree_skb(skb);
18967 + total += skb_queue_len(&ap->ps_bc_buf);
18969 + spin_unlock_bh(&local->sub_if_lock);
18971 + spin_lock_bh(&local->sta_lock);
18972 + list_for_each(ptr, &local->sta_list) {
18973 + struct sta_info *sta =
18974 + list_entry(ptr, struct sta_info, list);
18975 + skb = skb_dequeue(&sta->ps_tx_buf);
18978 + dev_kfree_skb(skb);
18980 + total += skb_queue_len(&sta->ps_tx_buf);
18982 + spin_unlock_bh(&local->sta_lock);
18984 + local->total_ps_buffered = total;
18985 + printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
18986 + local->mdev->name, purged);
18990 +static inline ieee80211_txrx_result
18991 +ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
18993 + /* broadcast/multicast frame */
18994 + /* If any of the associated stations is in power save mode,
18995 + * the frame is buffered to be sent after DTIM beacon frame */
18996 + if (tx->local->hw->host_broadcast_ps_buffering &&
18997 + tx->sdata->type != IEEE80211_SUB_IF_TYPE_WDS &&
18998 + tx->sdata->bss && atomic_read(&tx->sdata->bss->num_sta_ps) &&
18999 + !(tx->fc & WLAN_FC_ORDER)) {
19000 + if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
19001 + purge_old_ps_buffers(tx->local);
19002 + if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
19003 + AP_MAX_BC_BUFFER) {
19004 + if (net_ratelimit()) {
19005 + printk(KERN_DEBUG "%s: BC TX buffer full - "
19006 + "dropping the oldest frame\n",
19009 + dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
19011 + tx->local->total_ps_buffered++;
19012 + skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
19013 + return TXRX_QUEUED;
19016 + return TXRX_CONTINUE;
19020 +static inline ieee80211_txrx_result
19021 +ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
19023 + struct sta_info *sta = tx->sta;
19025 + if (unlikely(!sta ||
19026 + (WLAN_FC_GET_TYPE(tx->fc) == WLAN_FC_TYPE_MGMT &&
19027 + WLAN_FC_GET_STYPE(tx->fc) == WLAN_FC_STYPE_PROBE_RESP)))
19028 + return TXRX_CONTINUE;
19030 + if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
19031 + struct ieee80211_tx_packet_data *pkt_data;
19032 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
19033 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS buffer (entries "
19035 + MAC2STR(sta->addr), sta->aid,
19036 + skb_queue_len(&sta->ps_tx_buf));
19037 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
19038 + sta->flags |= WLAN_STA_TIM;
19039 + if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
19040 + purge_old_ps_buffers(tx->local);
19041 + if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
19042 + struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
19043 + if (net_ratelimit()) {
19044 + printk(KERN_DEBUG "%s: STA " MACSTR " TX "
19045 + "buffer full - dropping oldest frame\n",
19046 + tx->dev->name, MAC2STR(sta->addr));
19048 + dev_kfree_skb(old);
19050 + tx->local->total_ps_buffered++;
19051 + /* Queue frame to be sent after STA sends an PS Poll frame */
19052 + if (skb_queue_empty(&sta->ps_tx_buf) && tx->local->hw->set_tim)
19053 + tx->local->hw->set_tim(tx->dev, sta->aid, 1);
19054 + pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
19055 + pkt_data->jiffies = jiffies;
19056 + skb_queue_tail(&sta->ps_tx_buf, tx->skb);
19057 + return TXRX_QUEUED;
19059 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
19060 + else if (unlikely(sta->flags & WLAN_STA_PS)) {
19061 + printk(KERN_DEBUG "%s: STA " MACSTR " in PS mode, but pspoll "
19062 + "set -> send frame\n", tx->dev->name,
19063 + MAC2STR(sta->addr));
19065 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
19068 + return TXRX_CONTINUE;
19072 +static ieee80211_txrx_result
19073 +ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
19075 + if (unlikely(tx->u.tx.ps_buffered))
19076 + return TXRX_CONTINUE;
19078 + if (tx->u.tx.unicast)
19079 + return ieee80211_tx_h_unicast_ps_buf(tx);
19081 + return ieee80211_tx_h_multicast_ps_buf(tx);
19085 +static void inline ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
19086 + struct sk_buff *skb,
19087 + struct net_device *dev,
19088 + struct ieee80211_tx_control *control)
19090 + struct ieee80211_local *local = dev->priv;
19091 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
19092 + struct ieee80211_tx_packet_data *pkt_data;
19095 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19097 + memset(tx, 0, sizeof(*tx));
19099 + tx->dev = pkt_data->sdata->dev; /* use original interface */
19100 + tx->local = local;
19101 + tx->sdata = pkt_data->sdata;
19102 + tx->sta = sta_info_get(local, hdr->addr1);
19103 + tx->fc = le16_to_cpu(hdr->frame_control);
19104 + control->power_level = local->conf.power_level;
19105 + tx->u.tx.control = control;
19106 + tx->u.tx.unicast = !MULTICAST_ADDR(hdr->addr1);
19107 + control->no_ack = MULTICAST_ADDR(hdr->addr1);
19108 + tx->fragmented = local->fragmentation_threshold <
19109 + IEEE80211_MAX_FRAG_THRESHOLD && tx->u.tx.unicast &&
19110 + skb->len + 4 /* FCS */ > local->fragmentation_threshold &&
19111 + (local->hw->set_frag_threshold == NULL);
19112 + if (tx->sta == NULL)
19113 + control->clear_dst_mask = 1;
19114 + else if (tx->sta->clear_dst_mask) {
19115 + control->clear_dst_mask = 1;
19116 + tx->sta->clear_dst_mask = 0;
19118 + control->antenna_sel = local->conf.antenna_sel;
19119 + if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
19120 + control->antenna_sel = tx->sta->antenna_sel;
19121 + hdrlen = ieee80211_get_hdrlen(tx->fc);
19122 + if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
19123 + u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
19124 + tx->ethertype = (pos[0] << 8) | pos[1];
19130 +static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
19131 + struct ieee80211_tx_control *control, int mgmt)
19133 + struct ieee80211_local *local = dev->priv;
19134 + struct sta_info *sta;
19135 + ieee80211_tx_handler *handler;
19136 + struct ieee80211_txrx_data tx;
19137 + ieee80211_txrx_result res = TXRX_DROP;
19140 + if (unlikely(skb->len < 10)) {
19141 + dev_kfree_skb(skb);
19145 + ieee80211_tx_prepare(&tx, skb, dev, control);
19147 + tx.u.tx.mgmt_interface = mgmt;
19149 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19150 + res = (*handler)(&tx);
19151 + if (res != TXRX_CONTINUE)
19155 + skb = tx.skb; /* handlers are allowed to change skb */
19158 + sta_info_release(local, sta);
19160 + if (unlikely(res == TXRX_DROP)) {
19161 + I802_DEBUG_INC(local->tx_handlers_drop);
19165 + if (unlikely(res == TXRX_QUEUED)) {
19166 + I802_DEBUG_INC(local->tx_handlers_queued);
19170 + ieee80211_dump_frame(dev->name, "TX to low-level driver", skb);
19171 + ret = local->hw->tx(dev, skb, control);
19172 +#ifdef IEEE80211_LEDS
19173 + if (!ret && local->tx_led_counter++ == 0) {
19174 + ieee80211_tx_led(1, dev);
19176 +#endif /* IEEE80211_LEDS */
19177 + if (tx.u.tx.extra_frag) {
19179 + /* Must free all fragments and return 0 since skb data
19180 + * has been fragmented into multiple buffers.
19181 + * TODO: could free extra fragments and restore skb to
19182 + * the original form since the data is still there and
19183 + * then return nonzero so that Linux netif would
19188 + skb = NULL; /* skb is now owned by low-level driver */
19189 + control->use_rts_cts = 0;
19190 + control->use_cts_protect = 0;
19191 + control->clear_dst_mask = 0;
19192 + for (i = 0; i < tx.u.tx.num_extra_frag; i++) {
19193 + int next_len, dur;
19194 + struct ieee80211_hdr *hdr =
19195 + (struct ieee80211_hdr *)
19196 + tx.u.tx.extra_frag[i]->data;
19197 + if (i + 1 < tx.u.tx.num_extra_frag)
19198 + next_len = tx.u.tx.extra_frag[i + 1]->len;
19201 + tx.u.tx.rate = tx.u.tx.last_frag_rate;
19202 + tx.u.tx.control->tx_rate = tx.u.tx.rate->val;
19203 + tx.u.tx.control->rateidx =
19204 + tx.u.tx.last_frag_rateidx;
19205 + tx.u.tx.control->rate_ctrl_probe =
19206 + tx.u.tx.probe_last_frag;
19208 + dur = ieee80211_duration(&tx, 0, next_len);
19209 + hdr->duration_id = cpu_to_le16(dur);
19211 + ieee80211_dump_frame(dev->name,
19212 + "TX to low-level driver", skb);
19213 + ret = local->hw->tx(dev, tx.u.tx.extra_frag[i],
19217 +#ifdef IEEE80211_LEDS
19218 + if (local->tx_led_counter++ == 0) {
19219 + ieee80211_tx_led(1, dev);
19221 +#endif /* IEEE80211_LEDS */
19222 + tx.u.tx.extra_frag[i] = NULL;
19224 + kfree(tx.u.tx.extra_frag);
19232 + dev_kfree_skb(skb);
19233 + for (i = 0; i < tx.u.tx.num_extra_frag; i++)
19234 + if (tx.u.tx.extra_frag[i])
19235 + dev_kfree_skb(tx.u.tx.extra_frag[i]);
19236 + kfree(tx.u.tx.extra_frag);
19241 +static int ieee80211_master_start_xmit(struct sk_buff *skb,
19242 + struct net_device *dev)
19244 + struct ieee80211_tx_control control;
19245 + struct ieee80211_tx_packet_data *pkt_data;
19246 + struct ieee80211_sub_if_data *sdata;
19249 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19252 + * copy control out of the skb so other people can use skb->cb
19254 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19255 + memset(&control, 0, sizeof(struct ieee80211_tx_control));
19256 + control.sdata = pkt_data->sdata;
19257 + control.req_tx_status = pkt_data->req_tx_status;
19258 + control.do_not_encrypt = pkt_data->do_not_encrypt;
19259 + control.pkt_type =
19260 + pkt_data->pkt_probe_resp ? PKT_PROBE_RESP : PKT_NORMAL;
19261 + control.requeue = pkt_data->requeue;
19262 + control.queue = pkt_data->queue;
19264 + ret = ieee80211_tx(dev, skb, &control,
19265 + control.sdata->type == IEEE80211_SUB_IF_TYPE_MGMT);
19272 + * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
19273 + * subinterfaces (wlan#, WDS, and VLAN interfaces)
19274 + * @skb: packet to be sent
19275 + * @dev: incoming interface
19277 + * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
19278 + * not be freed, and caller is responsible for either retrying later or freeing
19281 + * This function takes in an Ethernet header and encapsulates it with suitable
19282 + * IEEE 802.11 header based on which interface the packet is coming in. The
19283 + * encapsulated packet will then be passed to master interface, wlan#.11, for
19284 + * transmission (through low-level driver).
19286 +static int ieee80211_subif_start_xmit(struct sk_buff *skb,
19287 + struct net_device *dev)
19289 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
19290 + struct ieee80211_tx_packet_data *pkt_data;
19291 + struct ieee80211_sub_if_data *sdata;
19292 + int ret = 1, head_need;
19293 + u16 ethertype, hdrlen, fc;
19294 + struct ieee80211_hdr hdr;
19296 + int encaps_len, skip_header_bytes;
19297 + int nh_pos, h_pos, no_encrypt = 0;
19298 + struct sta_info *sta;
19300 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19301 + if (unlikely(skb->len < ETH_HLEN)) {
19302 + printk(KERN_DEBUG "%s: short skb (len=%d)\n",
19303 + dev->name, skb->len);
19308 + nh_pos = skb->nh.raw - skb->data;
19309 + h_pos = skb->h.raw - skb->data;
19311 + /* convert Ethernet header to proper 802.11 header (based on
19312 + * operation mode) */
19313 + ethertype = (skb->data[12] << 8) | skb->data[13];
19314 + /* TODO: handling for 802.1x authorized/unauthorized port */
19315 + fc = (WLAN_FC_TYPE_DATA << 2) | (WLAN_FC_STYPE_DATA << 4);
19317 + if (likely(sdata->type == IEEE80211_SUB_IF_TYPE_AP ||
19318 + sdata->type == IEEE80211_SUB_IF_TYPE_VLAN)) {
19319 + if (local->conf.mode == IW_MODE_MASTER) {
19320 + fc |= WLAN_FC_FROMDS;
19321 + /* DA BSSID SA */
19322 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19323 + memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
19324 + memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
19325 + } else if (local->conf.mode == IW_MODE_INFRA) {
19326 + fc |= WLAN_FC_TODS;
19327 + /* BSSID SA DA */
19328 + memcpy(hdr.addr1, local->bssid, ETH_ALEN);
19329 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19330 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19331 + } else if (local->conf.mode == IW_MODE_ADHOC) {
19332 + /* DA SA BSSID */
19333 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19334 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19335 + memcpy(hdr.addr3, local->bssid, ETH_ALEN);
19338 + } else if (sdata->type == IEEE80211_SUB_IF_TYPE_WDS) {
19339 + fc |= WLAN_FC_FROMDS | WLAN_FC_TODS;
19340 + /* RA TA DA SA */
19341 + memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
19342 + memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
19343 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19344 + memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
19346 + } else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
19347 + if (local->conf.mode == IW_MODE_INFRA) {
19348 + fc |= WLAN_FC_TODS;
19349 + /* BSSID SA DA */
19350 + memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
19351 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19352 + memcpy(hdr.addr3, skb->data, ETH_ALEN);
19354 + /* DA SA BSSID */
19355 + memcpy(hdr.addr1, skb->data, ETH_ALEN);
19356 + memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
19357 + memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
19365 + /* receiver is QoS enabled, use a QoS type frame */
19366 + sta = sta_info_get(local, hdr.addr1);
19368 + if (sta->flags & WLAN_STA_WME) {
19369 + fc |= WLAN_FC_STYPE_QOS_DATA << 4;
19372 + sta_info_release(local, sta);
19375 + hdr.frame_control = cpu_to_le16(fc);
19376 + hdr.duration_id = 0;
19377 + hdr.seq_ctrl = 0;
19379 + skip_header_bytes = ETH_HLEN;
19380 + if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
19381 + encaps_data = bridge_tunnel_header;
19382 + encaps_len = sizeof(bridge_tunnel_header);
19383 + skip_header_bytes -= 2;
19384 + } else if (ethertype >= 0x600) {
19385 + encaps_data = rfc1042_header;
19386 + encaps_len = sizeof(rfc1042_header);
19387 + skip_header_bytes -= 2;
19389 + encaps_data = NULL;
19393 + skb_pull(skb, skip_header_bytes);
19394 + nh_pos -= skip_header_bytes;
19395 + h_pos -= skip_header_bytes;
19397 + /* TODO: implement support for fragments so that there is no need to
19398 + * reallocate and copy payload; it might be enough to support one
19399 + * extra fragment that would be copied in the beginning of the frame
19400 + * data.. anyway, it would be nice to include this into skb structure
19403 + * There are few options for this:
19404 + * use skb->cb as an extra space for 802.11 header
19405 + * allocate new buffer if not enough headroom
19406 + * make sure that there is enough headroom in every skb by increasing
19407 + * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
19408 + * alloc_skb() (net/core/skbuff.c)
19410 + head_need = hdrlen + encaps_len + (local->hw->extra_hdr_room ? 2 : 0);
19411 + head_need -= skb_headroom(skb);
19413 + /* We are going to modify skb data, so make a copy of it if happens to
19414 + * be cloned. This could happen, e.g., with Linux bridge code passing
19415 + * us broadcast frames. */
19417 + if (head_need > 0 || skb_cloned(skb)) {
19419 + printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
19420 + "of headroom\n", dev->name, head_need);
19423 + if (skb_cloned(skb))
19424 + I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
19426 + I802_DEBUG_INC(local->tx_expand_skb_head);
19427 + /* Since we have to reallocate the buffer, make sure that there
19428 + * is enough room for possible WEP IV/ICV and TKIP (8 bytes
19429 + * before payload and 12 after). */
19430 + if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8),
19431 + 12, GFP_ATOMIC)) {
19432 + printk(KERN_DEBUG "%s: failed to reallocate TX buffer"
19433 + "\n", dev->name);
19438 + if (encaps_data) {
19439 + memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
19440 + nh_pos += encaps_len;
19441 + h_pos += encaps_len;
19443 + memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
19444 + nh_pos += hdrlen;
19447 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19448 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
19449 + pkt_data->sdata = sdata;
19450 + pkt_data->do_not_encrypt = no_encrypt;
19452 + skb->dev = sdata->master;
19453 + sdata->stats.tx_packets++;
19454 + sdata->stats.tx_bytes += skb->len;
19456 + /* Update skb pointers to various headers since this modified frame
19457 + * is going to go through Linux networking code that may potentially
19458 + * need things like pointer to IP header. */
19459 + skb->mac.raw = skb->data;
19460 + skb->nh.raw = skb->data + nh_pos;
19461 + skb->h.raw = skb->data + h_pos;
19463 + dev_queue_xmit(skb);
19469 + dev_kfree_skb(skb);
19476 + * This is the transmit routine for the 802.11 type interfaces
19477 + * called by upper layers of the linux networking
19478 + * stack when it has a frame to transmit
19481 +ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
19483 + struct ieee80211_sub_if_data *sdata;
19484 + struct ieee80211_tx_packet_data *pkt_data;
19485 + struct ieee80211_hdr *hdr;
19488 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19490 + if (skb->len < 10) {
19491 + dev_kfree_skb(skb);
19495 + hdr = (struct ieee80211_hdr *) skb->data;
19496 + fc = le16_to_cpu(hdr->frame_control);
19498 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
19499 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
19500 + pkt_data->sdata = sdata;
19502 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
19503 + WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP)
19504 + pkt_data->pkt_probe_resp = 1;
19506 + skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
19507 + skb->dev = sdata->master;
19510 + * We're using the protocol field of the the frame control header
19511 + * to request TX callback for hostapd. BIT(1) is checked.
19513 + if ((fc & BIT(1)) == BIT(1)) {
19514 + pkt_data->req_tx_status = 1;
19516 + hdr->frame_control = cpu_to_le16(fc);
19519 + pkt_data->do_not_encrypt = !(fc & WLAN_FC_ISWEP);
19521 + sdata->stats.tx_packets++;
19522 + sdata->stats.tx_bytes += skb->len;
19524 + dev_queue_xmit(skb);
19530 +static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
19531 + struct ieee80211_if_ap *bss,
19532 + struct sk_buff *skb)
19536 + int i, num_bits = 0, n1, n2;
19539 + /* Generate bitmap for TIM only if there are any STAs in power save
19541 + if (atomic_read(&bss->num_sta_ps) > 0 && bss->max_aid > 0) {
19542 + memset(bitmap, 0, sizeof(bitmap));
19543 + spin_lock_bh(&local->sta_lock);
19544 + for (i = 0; i < bss->max_aid; i++) {
19545 + if (bss->sta_aid[i] &&
19546 + (!skb_queue_empty(&bss->sta_aid[i]->ps_tx_buf) ||
19547 + !skb_queue_empty(&bss->sta_aid[i]->tx_filtered)))
19549 + bitmap[(i + 1) / 8] |= 1 << (i + 1) % 8;
19553 + spin_unlock_bh(&local->sta_lock);
19556 + if (bss->dtim_count == 0)
19557 + bss->dtim_count = bss->dtim_period - 1;
19559 + bss->dtim_count--;
19561 + tim = pos = (u8 *) skb_put(skb, 6);
19562 + *pos++ = WLAN_EID_TIM;
19564 + *pos++ = bss->dtim_count;
19565 + *pos++ = bss->dtim_period;
19567 + if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) {
19572 + /* Find largest even number N1 so that bits numbered 1 through
19573 + * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
19574 + * (N2 + 1) x 8 through 2007 are 0. */
19576 + for (i = 0; i < sizeof(bitmap); i++) {
19583 + for (i = sizeof(bitmap) - 1; i >= n1; i--) {
19590 + /* Bitmap control */
19591 + *pos++ = n1 | (aid0 ? 1 : 0);
19592 + /* Part Virt Bitmap */
19593 + memcpy(pos, bitmap + n1, n2 - n1 + 1);
19595 + tim[1] = n2 - n1 + 4;
19596 + skb_put(skb, n2 - n1);
19598 + *pos++ = aid0 ? 1 : 0; /* Bitmap control */
19599 + *pos++ = 0; /* Part Virt Bitmap */
19604 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
19605 + struct ieee80211_tx_control *control)
19607 + struct ieee80211_local *local = dev->priv;
19608 + struct sk_buff *skb;
19609 + struct net_device *bdev;
19610 + struct ieee80211_sub_if_data *sdata = NULL;
19611 + struct ieee80211_if_ap *ap = NULL;
19612 + struct ieee80211_rate *rate;
19613 + struct rate_control_extra extra;
19614 + u8 *b_head, *b_tail;
19615 + int bh_len, bt_len;
19617 + spin_lock_bh(&local->sub_if_lock);
19618 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count)
19621 + bdev = local->bss_devs[bss_idx];
19622 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19623 + ap = &sdata->u.ap;
19625 + spin_unlock_bh(&local->sub_if_lock);
19627 + if (bdev == NULL || ap == NULL || ap->beacon_head == NULL) {
19628 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19629 + if (net_ratelimit())
19630 + printk(KERN_DEBUG "no beacon data avail for idx=%d "
19631 + "(%s)\n", bss_idx, bdev ? bdev->name : "N/A");
19632 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19636 + /* Assume we are generating the normal beacon locally */
19637 + b_head = ap->beacon_head;
19638 + b_tail = ap->beacon_tail;
19639 + bh_len = ap->beacon_head_len;
19640 + bt_len = ap->beacon_tail_len;
19642 + skb = dev_alloc_skb(bh_len + bt_len + 256 /* maximum TIM len */);
19646 + memcpy(skb_put(skb, bh_len), b_head, bh_len);
19648 + ieee80211_beacon_add_tim(local, ap, skb);
19651 + memcpy(skb_put(skb, bt_len), b_tail, bt_len);
19654 + memset(&extra, 0, sizeof(extra));
19655 + extra.endidx = local->num_curr_rates;
19657 + rate = rate_control_get_rate(dev, skb, &extra);
19658 + if (rate == NULL) {
19659 + if (net_ratelimit()) {
19660 + printk(KERN_DEBUG "%s: ieee80211_beacon_get: no rate "
19661 + "found\n", dev->name);
19663 + dev_kfree_skb(skb);
19667 + control->tx_rate = (local->short_preamble &&
19668 + (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
19669 + rate->val2 : rate->val;
19670 + control->antenna_sel = local->conf.antenna_sel;
19671 + control->power_level = local->conf.power_level;
19672 + control->no_ack = 1;
19673 + control->retry_limit = 1;
19674 + control->rts_cts_duration = 0;
19675 + control->clear_dst_mask = 1;
19677 + ap->num_beacons++;
19683 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
19684 + struct ieee80211_tx_control *control)
19686 + struct ieee80211_local *local = dev->priv;
19687 + struct sk_buff *skb;
19688 + struct sta_info *sta;
19689 + ieee80211_tx_handler *handler;
19690 + struct ieee80211_txrx_data tx;
19691 + ieee80211_txrx_result res = TXRX_DROP;
19692 + struct net_device *bdev;
19693 + struct ieee80211_sub_if_data *sdata;
19694 + struct ieee80211_if_ap *bss;
19696 + spin_lock_bh(&local->sub_if_lock);
19697 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count) {
19701 + bdev = local->bss_devs[bss_idx];
19702 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19703 + bss = &sdata->u.ap;
19705 + spin_unlock_bh(&local->sub_if_lock);
19706 + if (bdev == NULL || bss == NULL || bss->beacon_head == NULL)
19709 + if (bss->dtim_count != 0)
19710 + return NULL; /* send buffered bc/mc only after DTIM beacon */
19711 + skb = skb_dequeue(&bss->ps_bc_buf);
19712 + memset(control, 0, sizeof(*control));
19715 + local->total_ps_buffered--;
19717 + if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
19718 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
19719 + /* more buffered multicast/broadcast frames ==> set MoreData
19720 + * flag in IEEE 802.11 header to inform PS STAs */
19721 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
19724 + ieee80211_tx_prepare(&tx, skb, dev, control);
19726 + tx.u.tx.ps_buffered = 1;
19728 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19729 + res = (*handler)(&tx);
19730 + if (res == TXRX_DROP || res == TXRX_QUEUED)
19734 + if (res == TXRX_DROP) {
19735 + I802_DEBUG_INC(local->tx_handlers_drop);
19736 + dev_kfree_skb(skb);
19738 + } else if (res == TXRX_QUEUED) {
19739 + I802_DEBUG_INC(local->tx_handlers_queued);
19744 + sta_info_release(local, sta);
19750 +int ieee80211_hw_config(struct net_device *dev)
19752 + struct ieee80211_local *local = dev->priv;
19755 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19756 + printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d mode=%d "
19757 + "phymode=%d\n", local->conf.channel, local->conf.freq,
19758 + local->conf.mode, local->conf.phymode);
19759 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19761 + if (local->hw->config)
19762 + ret = local->hw->config(dev, &local->conf);
19764 + for (i = 0; i < local->hw->num_modes; i++) {
19765 + struct ieee80211_hw_modes *mode = &local->hw->modes[i];
19766 + if (mode->mode == local->conf.phymode) {
19767 + if (local->curr_rates != mode->rates) {
19768 + rate_control_clear(local);
19770 + local->curr_rates = mode->rates;
19771 + local->num_curr_rates = mode->num_rates;
19772 + ieee80211_prepare_rates(dev);
19781 +struct ieee80211_conf *ieee80211_get_hw_conf(struct net_device *dev)
19783 + struct ieee80211_local *local = dev->priv;
19784 + return &local->conf;
19788 +static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
19790 + /* FIX: what would be proper limits for MTU?
19791 + * This interface uses 802.3 frames. */
19792 + if (new_mtu < 256 || new_mtu > 2304 - 24 - 6) {
19793 + printk(KERN_WARNING "%s: invalid MTU %d\n",
19794 + dev->name, new_mtu);
19798 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19799 + printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
19800 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19801 + dev->mtu = new_mtu;
19806 +static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
19808 + /* FIX: what would be proper limits for MTU?
19809 + * This interface uses 802.11 frames. */
19810 + if (new_mtu < 256 || new_mtu > 2304) {
19811 + printk(KERN_WARNING "%s: invalid MTU %d\n",
19812 + dev->name, new_mtu);
19816 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
19817 + printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
19818 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
19819 + dev->mtu = new_mtu;
19824 +static void ieee80211_tx_timeout(struct net_device *dev)
19826 + struct ieee80211_local *local = dev->priv;
19828 + printk(KERN_WARNING "%s: resetting interface.\n", dev->name);
19830 + if (local->hw->reset(dev))
19831 + printk(KERN_ERR "%s: failed to reset interface.\n", dev->name);
19833 + netif_wake_queue(dev);
19837 +static int ieee80211_set_mac_address(struct net_device *dev, void *addr)
19839 + struct ieee80211_local *local = dev->priv;
19840 + struct sockaddr *a = addr;
19841 + struct list_head *ptr;
19844 + if (!local->hw->set_mac_address)
19845 + return -EOPNOTSUPP;
19847 + res = local->hw->set_mac_address(dev, addr);
19851 + list_for_each(ptr, &local->sub_if_list) {
19852 + struct ieee80211_sub_if_data *sdata =
19853 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19854 + memcpy(sdata->dev->dev_addr, a->sa_data, ETH_ALEN);
19861 +static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
19863 + struct ieee80211_sub_if_data *sdata;
19864 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19865 + return &(sdata->stats);
19869 +static int ieee80211_open(struct net_device *dev)
19871 + struct ieee80211_sub_if_data *sdata;
19872 + struct ieee80211_local *local = dev->priv;
19875 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19877 + if (local->open_count == 0) {
19878 + res = local->hw->open(sdata->master);
19881 + ieee80211_init_scan(sdata->master);
19883 + local->open_count++;
19885 + netif_start_queue(dev);
19890 +static int ieee80211_stop(struct net_device *dev)
19892 + struct ieee80211_sub_if_data *sdata;
19893 + struct ieee80211_local *local = dev->priv;
19896 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19898 + netif_stop_queue(dev);
19900 + local->open_count--;
19901 + if (local->open_count == 0) {
19902 + ieee80211_stop_scan(sdata->master);
19903 + res = local->hw->stop(sdata->master);
19912 +static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
19914 + memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
19919 +static struct net_device *
19920 +ieee80211_get_wds_dev(struct ieee80211_local *local, u8 *addr)
19922 + struct list_head *ptr;
19924 + list_for_each(ptr, &local->sub_if_list) {
19925 + struct ieee80211_sub_if_data *sdata =
19926 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19927 + if (sdata->type == IEEE80211_SUB_IF_TYPE_WDS &&
19928 + memcmp(addr, sdata->u.wds.remote_addr, ETH_ALEN) == 0)
19929 + return sdata->dev;
19936 +static struct net_device * ieee80211_own_bssid(struct ieee80211_local *local,
19940 + struct net_device *dev = NULL;
19942 + spin_lock_bh(&local->sub_if_lock);
19943 + for (i = 0; i < local->bss_dev_count; i++) {
19944 + if ((memcmp(local->bss_devs[i]->dev_addr, addr, ETH_ALEN) == 0)
19946 + dev = local->bss_devs[i];
19950 + spin_unlock_bh(&local->sub_if_lock);
19956 +static struct net_device * ieee80211_sta_bssid(struct ieee80211_local *local,
19957 + u8 *addr, u8 *a1,
19958 + int *sta_multicast)
19960 + struct list_head *ptr;
19962 + u8 *own_addr = local->mdev->dev_addr;
19964 + multicast = a1[0] & 0x01;
19966 + /* Try O(1) lookup for a common case of only one AP being used. */
19967 + if (own_addr[0] == a1[0] && own_addr[1] == a1[1] &&
19968 + own_addr[2] == a1[2]) {
19969 + int index = (((int) a1[3] << 16) | ((int) a1[4] << 8) | a1[5])
19970 + - (((int) own_addr[3] << 16) |
19971 + ((int) own_addr[4] << 8) | own_addr[5]);
19972 + if (index >= 0 && index < local->conf.bss_count &&
19973 + local->sta_devs[index]) {
19974 + struct net_device *dev = local->sta_devs[index];
19975 + struct ieee80211_sub_if_data *sdata;
19976 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19977 + if (memcmp(addr, sdata->u.sta.bssid, ETH_ALEN) == 0) {
19978 + *sta_multicast = multicast;
19987 + /* Could not find station interface, resort to O(n) lookup. */
19988 + list_for_each(ptr, &local->sub_if_list) {
19989 + struct ieee80211_sub_if_data *sdata =
19990 + list_entry(ptr, struct ieee80211_sub_if_data, list);
19991 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
19993 + if (!multicast &&
19994 + memcmp(a1, sdata->dev->dev_addr, ETH_ALEN) != 0)
19997 + if (memcmp(addr, sdata->u.sta.bssid, ETH_ALEN) == 0 ||
19998 + (memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0 &&
19999 + local->conf.mode == IW_MODE_ADHOC)) {
20000 + *sta_multicast = multicast;
20001 + return sdata->dev;
20009 +static int ieee80211_own_addr(struct net_device *dev, u8 *addr)
20011 + struct ieee80211_local *local = dev->priv;
20012 + u8 *own = dev->dev_addr;
20015 + /* Optimization: assume that BSSID mask does not change for first
20016 + * three octets. */
20017 + if (own[0] != addr[0] || own[1] != addr[1] || own[2] != addr[2])
20020 + index = (((int) addr[3] << 16) | ((int) addr[4] << 8) | addr[5]) -
20021 + (((int) own[3] << 16) | ((int) own[4] << 8) | own[5]);
20022 + if (index >= 0 && index < local->conf.bss_count &&
20023 + local->sta_devs[index])
20030 +static ieee80211_txrx_result
20031 +ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
20033 + struct net_device *dev = rx->dev;
20034 + struct ieee80211_local *local = rx->local;
20035 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
20036 + u16 fc, hdrlen, ethertype;
20038 + u8 dst[ETH_ALEN];
20039 + u8 src[ETH_ALEN];
20040 + struct sk_buff *skb = rx->skb, *skb2;
20041 + struct ieee80211_sub_if_data *sdata;
20044 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA))
20045 + return TXRX_CONTINUE;
20047 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
20048 + return TXRX_DROP;
20050 + hdrlen = ieee80211_get_hdrlen(fc);
20052 + /* convert IEEE 802.11 header + possible LLC headers into Ethernet
20054 + * IEEE 802.11 address fields:
20055 + * ToDS FromDS Addr1 Addr2 Addr3 Addr4
20056 + * 0 0 DA SA BSSID n/a
20057 + * 0 1 DA BSSID SA n/a
20058 + * 1 0 BSSID SA DA n/a
20059 + * 1 1 RA TA DA SA
20062 + switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
20063 + case WLAN_FC_TODS:
20064 + /* BSSID SA DA */
20065 + memcpy(dst, hdr->addr3, ETH_ALEN);
20066 + memcpy(src, hdr->addr2, ETH_ALEN);
20068 + if (unlikely(local->conf.mode != IW_MODE_MASTER ||
20069 + !ieee80211_own_bssid(local, hdr->addr1))) {
20070 + printk(KERN_DEBUG "%s: dropped ToDS frame (BSSID="
20071 + MACSTR " SA=" MACSTR " DA=" MACSTR ")\n",
20072 + dev->name, MAC2STR(hdr->addr1),
20073 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3));
20074 + return TXRX_DROP;
20077 + case (WLAN_FC_TODS | WLAN_FC_FROMDS):
20078 + /* RA TA DA SA */
20079 + memcpy(dst, hdr->addr3, ETH_ALEN);
20080 + memcpy(src, hdr->addr4, ETH_ALEN);
20082 + dev = ieee80211_get_wds_dev(local, hdr->addr2);
20083 + if (!dev || memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) != 0) {
20084 + printk(KERN_DEBUG "%s: dropped FromDS&ToDS frame (RA="
20085 + MACSTR " TA=" MACSTR " DA=" MACSTR " SA="
20087 + rx->dev->name, MAC2STR(hdr->addr1),
20088 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3),
20089 + MAC2STR(hdr->addr4));
20090 + return TXRX_DROP;
20093 + case WLAN_FC_FROMDS:
20094 + /* DA BSSID SA */
20095 + memcpy(dst, hdr->addr1, ETH_ALEN);
20096 + memcpy(src, hdr->addr3, ETH_ALEN);
20098 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20099 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA ||
20100 + memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0 ||
20101 + memcmp(hdr->addr2, sdata->u.sta.bssid, ETH_ALEN) != 0) {
20102 + return TXRX_DROP;
20106 + /* DA SA BSSID */
20107 + memcpy(dst, hdr->addr1, ETH_ALEN);
20108 + memcpy(src, hdr->addr2, ETH_ALEN);
20110 + if (local->conf.mode != IW_MODE_ADHOC ||
20111 + memcmp(hdr->addr3, local->bssid, ETH_ALEN) != 0) {
20112 + if (net_ratelimit()) {
20113 + printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
20114 + MACSTR " SA=" MACSTR " BSSID=" MACSTR
20116 + dev->name, MAC2STR(hdr->addr1),
20117 + MAC2STR(hdr->addr2),
20118 + MAC2STR(hdr->addr3));
20120 + return TXRX_DROP;
20125 + payload = skb->data + hdrlen;
20127 + if (unlikely(skb->len - hdrlen < 8)) {
20128 + if (net_ratelimit()) {
20129 + printk(KERN_DEBUG "%s: RX too short data frame "
20130 + "payload\n", dev->name);
20132 + return TXRX_DROP;
20135 + ethertype = (payload[6] << 8) | payload[7];
20137 + if (likely((memcmp(payload, rfc1042_header, 6) == 0 &&
20138 + ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
20139 + memcmp(payload, bridge_tunnel_header, 6) == 0)) {
20140 + /* remove RFC1042 or Bridge-Tunnel encapsulation and
20141 + * replace EtherType */
20142 + skb_pull(skb, hdrlen + 6);
20143 + memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
20144 + memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
20146 + struct ethhdr *ehdr;
20147 + unsigned short len;
20148 + skb_pull(skb, hdrlen);
20149 + len = htons(skb->len);
20150 + ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
20151 + memcpy(ehdr->h_dest, dst, ETH_ALEN);
20152 + memcpy(ehdr->h_source, src, ETH_ALEN);
20153 + ehdr->h_proto = len;
20156 + if (rx->sta && !rx->sta->assoc_ap &&
20157 + !(rx->sta && (rx->sta->flags & WLAN_STA_WDS)))
20158 + skb->dev = rx->sta->dev;
20163 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20166 + * don't count the master since the low level code
20167 + * counts it already for us.
20169 + if (skb->dev != sdata->master) {
20170 + sdata->stats.rx_packets++;
20171 + sdata->stats.rx_bytes += skb->len;
20174 + if (local->bridge_packets && sdata->type != IEEE80211_SUB_IF_TYPE_WDS
20175 + && sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
20176 + if (MULTICAST_ADDR(skb->data)) {
20177 + /* send multicast frames both to higher layers in
20178 + * local net stack and back to the wireless media */
20179 + skb2 = skb_copy(skb, GFP_ATOMIC);
20180 + if (skb2 == NULL)
20181 + printk(KERN_DEBUG "%s: failed to clone "
20182 + "multicast frame\n", dev->name);
20184 + struct sta_info *dsta;
20185 + dsta = sta_info_get(local, skb->data);
20186 + if (dsta && dsta->dev == NULL) {
20187 + printk(KERN_DEBUG "Station with null dev "
20189 + } else if (dsta && dsta->dev == dev) {
20190 + /* Destination station is associated to this
20191 + * AP, so send the frame directly to it and
20192 + * do not pass the frame to local net stack.
20198 + sta_info_release(local, dsta);
20203 + /* deliver to local stack */
20204 + skb->protocol = eth_type_trans(skb, dev);
20205 + memset(skb->cb, 0, sizeof(skb->cb));
20210 + /* send to wireless media */
20211 + skb2->protocol = __constant_htons(ETH_P_802_3);
20212 + skb2->mac.raw = skb2->nh.raw = skb2->data;
20213 + dev_queue_xmit(skb2);
20216 + return TXRX_QUEUED;
20220 +static struct ieee80211_rate *
20221 +ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
20225 + for (m = 0; m < local->hw->num_modes; m++) {
20226 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
20227 + if (mode->mode != phymode)
20229 + for (r = 0; r < mode->num_rates; r++) {
20230 + struct ieee80211_rate *rate = &mode->rates[r];
20231 + if (rate->val == hw_rate ||
20232 + (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
20233 + rate->val2 == hw_rate))
20243 +ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
20244 + struct ieee80211_rx_status *status, u32 msg_type)
20246 + struct ieee80211_local *local = dev->priv;
20247 + struct ieee80211_frame_info *fi;
20249 + struct ieee80211_sub_if_data *sdata;
20251 + dev = local->apdev;
20254 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20256 + if (skb_headroom(skb) < sizeof(struct ieee80211_frame_info)) {
20257 + I802_DEBUG_INC(local->rx_expand_skb_head);
20258 + if (pskb_expand_head(skb, sizeof(struct ieee80211_frame_info),
20259 + 0, GFP_ATOMIC)) {
20260 + dev_kfree_skb(skb);
20265 + hlen = sizeof(struct ieee80211_frame_info);
20266 + if (msg_type == ieee80211_msg_monitor)
20267 + hlen -= sizeof(fi->msg_type);
20269 + fi = (struct ieee80211_frame_info *) skb_push(skb, hlen);
20270 + memset(fi, 0, hlen);
20271 + if (msg_type != ieee80211_msg_monitor)
20272 + fi->msg_type = htonl(msg_type);
20273 + fi->version = htonl(IEEE80211_FI_VERSION);
20274 + fi->length = htonl(hlen);
20276 + struct timespec ts;
20277 + struct ieee80211_rate *rate;
20279 + jiffies_to_timespec(status->hosttime, &ts);
20280 + fi->hosttime = cpu_to_be64(ts.tv_sec * 1000000 +
20281 + ts.tv_nsec / 1000);
20282 + fi->mactime = cpu_to_be64(status->mactime);
20283 + switch (status->phymode) {
20284 + case MODE_IEEE80211A:
20285 + fi->phytype = htonl(ieee80211_phytype_ofdm_dot11_a);
20287 + case MODE_IEEE80211B:
20288 + fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
20290 + case MODE_IEEE80211G:
20291 + fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
20293 + case MODE_ATHEROS_TURBO:
20295 + htonl(ieee80211_phytype_dsss_dot11_turbo);
20298 + fi->phytype = 0xAAAAAAAA;
20301 + fi->channel = htonl(status->channel);
20302 + rate = ieee80211_get_rate(local, status->phymode,
20305 + fi->datarate = htonl(rate->rate);
20306 + if (rate->flags & IEEE80211_RATE_PREAMBLE2) {
20307 + if (status->rate == rate->val)
20308 + fi->preamble = htonl(2); /* long */
20309 + else if (status->rate == rate->val2)
20310 + fi->preamble = htonl(1); /* short */
20312 + fi->preamble = htonl(0);
20314 + fi->datarate = htonl(0);
20315 + fi->preamble = htonl(0);
20318 + fi->antenna = htonl(status->antenna);
20319 + fi->priority = 0xffffffff; /* no clue */
20320 + fi->ssi_type = htonl(ieee80211_ssi_raw);
20321 + fi->ssi_signal = htonl(status->ssi);
20322 + fi->ssi_noise = 0x00000000;
20323 + fi->encoding = 0;
20325 + fi->ssi_type = htonl(ieee80211_ssi_none);
20328 + sdata->stats.rx_packets++;
20329 + sdata->stats.rx_bytes += skb->len;
20331 + skb->mac.raw = skb->data;
20332 + skb->ip_summed = CHECKSUM_UNNECESSARY;
20333 + skb->pkt_type = PACKET_OTHERHOST;
20334 + skb->protocol = __constant_htons(ETH_P_802_2);
20335 + memset(skb->cb, 0, sizeof(skb->cb));
20340 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
20343 + struct sk_buff *skb;
20344 + struct ieee80211_radar_info *msg;
20346 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20347 + sizeof(struct ieee80211_radar_info));
20351 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20353 + msg = (struct ieee80211_radar_info *)
20354 + skb_put(skb, sizeof(struct ieee80211_radar_info));
20355 + msg->channel = channel;
20356 + msg->radar = radar;
20357 + msg->radar_type = radar_type;
20359 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_radar);
20364 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
20367 + struct sk_buff *skb;
20368 + struct ieee80211_msg_set_aid_for_sta *msg;
20370 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20371 + sizeof(struct ieee80211_msg_set_aid_for_sta));
20375 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20377 + msg = (struct ieee80211_msg_set_aid_for_sta *)
20378 + skb_put(skb, sizeof(struct ieee80211_msg_set_aid_for_sta));
20379 + memcpy(msg->sta_address, peer_address, ETH_ALEN);
20382 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_set_aid_for_sta);
20387 +static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
20389 + struct ieee80211_sub_if_data *sdata;
20390 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20393 + atomic_inc(&sdata->bss->num_sta_ps);
20394 + sta->flags |= WLAN_STA_PS;
20396 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20397 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d enters power "
20398 + "save mode\n", dev->name, MAC2STR(sta->addr), sta->aid);
20399 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20403 +static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
20405 + struct ieee80211_local *local = dev->priv;
20406 + struct sk_buff *skb;
20408 + struct ieee80211_sub_if_data *sdata;
20409 + struct ieee80211_tx_packet_data *pkt_data;
20411 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20413 + atomic_dec(&sdata->bss->num_sta_ps);
20414 + sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
20416 + if (!skb_queue_empty(&sta->ps_tx_buf) && local->hw->set_tim)
20417 + local->hw->set_tim(dev, sta->aid, 0);
20418 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20419 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d exits power "
20420 + "save mode\n", dev->name, MAC2STR(sta->addr), sta->aid);
20421 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20422 + /* Send all buffered frames to the station */
20423 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
20424 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
20426 + pkt_data->requeue = 1;
20427 + dev_queue_xmit(skb);
20429 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
20430 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
20431 + local->total_ps_buffered--;
20433 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20434 + printk(KERN_DEBUG "%s: STA " MACSTR " aid %d send PS frame "
20435 + "since STA not sleeping anymore\n", dev->name,
20436 + MAC2STR(sta->addr), sta->aid);
20437 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20438 + pkt_data->requeue = 1;
20439 + dev_queue_xmit(skb);
20446 +static ieee80211_txrx_result
20447 +ieee80211_rx_h_ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
20449 + struct sk_buff *skb;
20450 + int no_pending_pkts;
20452 + if (likely(!rx->sta || WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_CTRL ||
20453 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_PSPOLL))
20454 + return TXRX_CONTINUE;
20456 + skb = skb_dequeue(&rx->sta->tx_filtered);
20457 + if (skb == NULL) {
20458 + skb = skb_dequeue(&rx->sta->ps_tx_buf);
20460 + rx->local->total_ps_buffered--;
20462 + no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
20463 + skb_queue_empty(&rx->sta->ps_tx_buf);
20466 + struct ieee80211_hdr *hdr =
20467 + (struct ieee80211_hdr *) skb->data;
20469 + /* tell TX path to send one frame even though the STA may
20470 + * still remain is PS mode after this frame exchange */
20471 + rx->sta->pspoll = 1;
20473 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20474 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS Poll (entries "
20476 + MAC2STR(rx->sta->addr), rx->sta->aid,
20477 + skb_queue_len(&rx->sta->ps_tx_buf));
20478 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20480 + /* Use MoreData flag to indicate whether there are more
20481 + * buffered frames for this STA */
20482 + if (no_pending_pkts) {
20483 + hdr->frame_control &= cpu_to_le16(~WLAN_FC_MOREDATA);
20484 + rx->sta->flags &= ~WLAN_STA_TIM;
20486 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
20488 + dev_queue_xmit(skb);
20490 + if (no_pending_pkts && rx->local->hw->set_tim)
20491 + rx->local->hw->set_tim(rx->dev, rx->sta->aid, 0);
20492 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20493 + } else if (!rx->u.rx.sent_ps_buffered) {
20494 + printk(KERN_DEBUG "%s: STA " MACSTR " sent PS Poll even "
20495 + "though there is no buffered frames for it\n",
20496 + rx->dev->name, MAC2STR(rx->sta->addr));
20497 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20501 + /* Free PS Poll skb here instead of returning TXRX_DROP that would
20502 + * count as an dropped frame. */
20503 + dev_kfree_skb(rx->skb);
20505 + return TXRX_QUEUED;
20509 +static inline struct ieee80211_fragment_entry *
20510 +ieee80211_reassemble_add(struct ieee80211_local *local,
20511 + unsigned int frag, unsigned int seq, int rx_queue,
20512 + struct sk_buff **skb)
20514 + struct ieee80211_fragment_entry *entry;
20517 + idx = local->fragment_next;
20518 + entry = &local->fragments[local->fragment_next++];
20519 + if (local->fragment_next >= IEEE80211_FRAGMENT_MAX)
20520 + local->fragment_next = 0;
20522 + if (entry->skb) {
20523 +#ifdef CONFIG_D80211_DEBUG
20524 + struct ieee80211_hdr *hdr =
20525 + (struct ieee80211_hdr *) entry->skb->data;
20526 + printk(KERN_DEBUG "%s: RX reassembly removed oldest "
20527 + "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
20528 + "addr1=" MACSTR " addr2=" MACSTR "\n",
20529 + local->mdev->name, idx,
20530 + jiffies - entry->first_frag_time, entry->seq,
20531 + entry->last_frag, MAC2STR(hdr->addr1),
20532 + MAC2STR(hdr->addr2));
20533 +#endif /* CONFIG_D80211_DEBUG */
20534 + dev_kfree_skb(entry->skb);
20537 + entry->skb = *skb;
20539 + entry->first_frag_time = jiffies;
20540 + entry->seq = seq;
20541 + entry->rx_queue = rx_queue;
20542 + entry->last_frag = frag;
20549 +static inline struct ieee80211_fragment_entry *
20550 +ieee80211_reassemble_find(struct ieee80211_local *local,
20551 + u16 fc, unsigned int frag, unsigned int seq,
20552 + int rx_queue, struct ieee80211_hdr *hdr)
20554 + struct ieee80211_fragment_entry *entry;
20557 + idx = local->fragment_next;
20558 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
20559 + struct ieee80211_hdr *f_hdr;
20564 + idx = IEEE80211_FRAGMENT_MAX - 1;
20566 + entry = &local->fragments[idx];
20567 + if (!entry->skb || entry->seq != seq ||
20568 + entry->rx_queue != rx_queue ||
20569 + entry->last_frag + 1 != frag)
20572 + f_hdr = (struct ieee80211_hdr *) entry->skb->data;
20573 + f_fc = le16_to_cpu(f_hdr->frame_control);
20575 + if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_GET_TYPE(f_fc) ||
20576 + memcmp(hdr->addr1, f_hdr->addr1, ETH_ALEN) != 0 ||
20577 + memcmp(hdr->addr2, f_hdr->addr2, ETH_ALEN) != 0)
20580 + if (entry->first_frag_time + 2 * HZ < jiffies) {
20581 + dev_kfree_skb(entry->skb);
20582 + entry->skb = NULL;
20592 +static ieee80211_txrx_result
20593 +ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
20595 + struct ieee80211_hdr *hdr;
20597 + unsigned int frag, seq;
20598 + struct ieee80211_fragment_entry *entry;
20600 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20601 + sc = le16_to_cpu(hdr->seq_ctrl);
20602 + frag = WLAN_GET_SEQ_FRAG(sc);
20604 + if (likely((!(rx->fc & WLAN_FC_MOREFRAG) && frag == 0) ||
20605 + (rx->skb)->len < 24 || MULTICAST_ADDR(hdr->addr1))) {
20606 + /* not fragmented */
20609 + I802_DEBUG_INC(rx->local->rx_handlers_fragments);
20611 + seq = WLAN_GET_SEQ_SEQ(sc);
20614 + /* This is the first fragment of a new frame. */
20615 + entry = ieee80211_reassemble_add(rx->local, frag, seq,
20616 + rx->u.rx.queue, &(rx->skb));
20617 + if (rx->key && rx->key->alg == ALG_CCMP &&
20618 + (rx->fc & WLAN_FC_ISWEP)) {
20619 + /* Store CCMP PN so that we can verify that the next
20620 + * fragment has a sequential PN value. */
20622 + memcpy(entry->last_pn,
20623 + rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
20626 + return TXRX_QUEUED;
20629 + /* This is a fragment for a frame that should already be pending in
20630 + * fragment cache. Add this fragment to the end of the pending entry.
20632 + entry = ieee80211_reassemble_find(rx->local, rx->fc, frag, seq,
20633 + rx->u.rx.queue, hdr);
20635 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20636 + return TXRX_DROP;
20639 + /* Verify that MPDUs within one MSDU have sequential PN values.
20640 + * (IEEE 802.11i, 8.3.3.4.5) */
20641 + if (entry->ccmp) {
20643 + u8 pn[CCMP_PN_LEN], *rpn;
20644 + if (rx->key == NULL || rx->key->alg != ALG_CCMP)
20645 + return TXRX_DROP;
20646 + memcpy(pn, entry->last_pn, CCMP_PN_LEN);
20647 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
20652 + rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
20653 + if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
20654 + printk(KERN_DEBUG "%s: defrag: CCMP PN not sequential"
20655 + " A2=" MACSTR " PN=%02x%02x%02x%02x%02x%02x "
20656 + "(expected %02x%02x%02x%02x%02x%02x)\n",
20657 + rx->dev->name, MAC2STR(hdr->addr2),
20658 + rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], rpn[5],
20659 + pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]);
20660 + return TXRX_DROP;
20662 + memcpy(entry->last_pn, pn, CCMP_PN_LEN);
20665 + /* TODO: could gather list of skb's and reallocate data buffer only
20666 + * after finding out the total length of the frame */
20667 + skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
20668 + if (skb_tailroom(entry->skb) < rx->skb->len) {
20669 + I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
20670 + if (unlikely(pskb_expand_head(entry->skb, 0, rx->skb->len,
20672 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20673 + return TXRX_DROP;
20676 + memcpy(skb_put(entry->skb, rx->skb->len), rx->skb->data, rx->skb->len);
20677 + entry->last_frag = frag;
20678 + dev_kfree_skb(rx->skb);
20680 + if (rx->fc & WLAN_FC_MOREFRAG) {
20682 + return TXRX_QUEUED;
20685 + /* Complete frame has been reassembled - process it now */
20686 + rx->skb = entry->skb;
20687 + rx->fragmented = 1;
20688 + entry->skb = NULL;
20692 + rx->sta->rx_packets++;
20693 + if (MULTICAST_ADDR(hdr->addr1))
20694 + rx->local->dot11MulticastReceivedFrameCount++;
20695 +#ifdef IEEE80211_LEDS
20697 + ieee80211_rx_led(2, rx->dev);
20698 +#endif /* IEEE80211_LEDS */
20699 + return TXRX_CONTINUE;
20703 +static ieee80211_txrx_result
20704 +ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
20706 + if (rx->local->conf.mode == IW_MODE_MONITOR) {
20707 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20708 + ieee80211_msg_monitor);
20709 + return TXRX_QUEUED;
20712 + return TXRX_CONTINUE;
20716 +static ieee80211_txrx_result
20717 +ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
20719 + struct ieee80211_hdr *hdr;
20720 + int always_sta_key;
20721 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20723 + /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
20724 + if (rx->sta && !MULTICAST_ADDR(hdr->addr1)) {
20725 + if (unlikely(rx->fc & WLAN_FC_RETRY &&
20726 + rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
20727 + hdr->seq_ctrl)) {
20728 + rx->local->dot11FrameDuplicateCount++;
20729 + rx->sta->num_duplicates++;
20730 + return TXRX_DROP;
20732 + rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
20735 + if (rx->local->hw->rx_includes_fcs && rx->skb->len > FCS_LEN)
20736 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
20738 + if (unlikely(rx->skb->len < 16)) {
20739 + I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
20740 + return TXRX_DROP;
20743 + /* Filter out foreign unicast packets when in promiscuous mode.
20744 + * FIX: Filter out multicast to foreign BSSID. */
20745 + if (rx->local->conf.mode == IW_MODE_INFRA &&
20746 + !MULTICAST_ADDR(hdr->addr1) &&
20747 + !ieee80211_own_addr(rx->dev, hdr->addr1))
20748 + return TXRX_DROP;
20750 + /* Drop disallowed frame classes based on STA auth/assoc state;
20751 + * IEEE 802.11, Chap 5.5.
20753 + * 80211.o does filtering only based on association state, i.e., it
20754 + * drops Class 3 frames from not associated stations. hostapd sends
20755 + * deauth/disassoc frames when needed. In addition, hostapd is
20756 + * responsible for filtering on both auth and assoc states.
20758 + if (unlikely((WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA ||
20759 + (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_CTRL &&
20760 + WLAN_FC_GET_STYPE(rx->fc) == WLAN_FC_STYPE_PSPOLL)) &&
20761 + rx->local->conf.mode != IW_MODE_ADHOC &&
20762 + (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
20763 + if (!(rx->fc & WLAN_FC_FROMDS) && !(rx->fc & WLAN_FC_TODS)) {
20764 + /* Drop IBSS frames silently. */
20765 + return TXRX_DROP;
20768 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20769 + ieee80211_msg_sta_not_assoc);
20770 + return TXRX_QUEUED;
20773 + if (rx->local->conf.mode == IW_MODE_INFRA)
20774 + always_sta_key = 0;
20776 + always_sta_key = 1;
20778 + if (rx->sta && rx->sta->key && always_sta_key) {
20779 + rx->key = rx->sta->key;
20781 + if (!rx->sdata) {
20782 + printk(KERN_DEBUG "%s: sdata was null in packet!!\n",
20784 + printk(KERN_DEBUG "%s: Addr1: " MACSTR "\n",
20785 + rx->dev->name, MAC2STR(hdr->addr1));
20786 + printk(KERN_DEBUG "%s: Addr2: " MACSTR "\n",
20787 + rx->dev->name, MAC2STR(hdr->addr2));
20788 + printk(KERN_DEBUG "%s: Addr3: " MACSTR "\n",
20789 + rx->dev->name, MAC2STR(hdr->addr3));
20790 + return TXRX_DROP;
20792 + if (rx->sta && rx->sta->key)
20793 + rx->key = rx->sta->key;
20795 + rx->key = rx->sdata->default_key;
20797 + if (rx->local->hw->wep_include_iv &&
20798 + rx->fc & WLAN_FC_ISWEP) {
20799 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
20801 + if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
20802 + (rx->sta == NULL || rx->sta->key == NULL ||
20804 + rx->key = rx->sdata->keys[keyidx];
20807 + printk(KERN_DEBUG "%s: RX WEP frame with "
20808 + "unknown keyidx %d (A1=" MACSTR " A2="
20809 + MACSTR " A3=" MACSTR ")\n",
20810 + rx->dev->name, keyidx,
20811 + MAC2STR(hdr->addr1),
20812 + MAC2STR(hdr->addr2),
20813 + MAC2STR(hdr->addr3));
20814 + ieee80211_rx_mgmt(
20815 + rx->dev, rx->skb, rx->u.rx.status,
20816 + ieee80211_msg_wep_frame_unknown_key);
20817 + return TXRX_QUEUED;
20822 + if (rx->fc & WLAN_FC_ISWEP && rx->key) {
20823 + rx->key->tx_rx_count++;
20824 + if (unlikely(rx->local->key_tx_rx_threshold &&
20825 + rx->key->tx_rx_count >
20826 + rx->local->key_tx_rx_threshold)) {
20827 + ieee80211_key_threshold_notify(rx->dev, rx->key,
20832 + return TXRX_CONTINUE;
20836 +static ieee80211_txrx_result
20837 +ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
20839 + struct sta_info *sta = rx->sta;
20840 + struct net_device *dev = rx->dev;
20841 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
20844 + return TXRX_CONTINUE;
20846 + /* Update last_rx only for IBSS packets which are for the current
20847 + * BSSID to avoid keeping the current IBSS network alive in cases where
20848 + * other STAs are using different BSSID. */
20849 + if (rx->local->conf.mode == IW_MODE_ADHOC) {
20850 + u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
20851 + if (memcmp(bssid, rx->local->bssid, ETH_ALEN) == 0)
20852 + sta->last_rx = jiffies;
20854 + if (!MULTICAST_ADDR(hdr->addr1) ||
20855 + rx->local->conf.mode == IW_MODE_INFRA) {
20856 + /* Update last_rx only for unicast frames in order to prevent
20857 + * the Probe Request frames (the only broadcast frames from a
20858 + * STA in infrastructure mode) from keeping a connection alive.
20860 + sta->last_rx = jiffies;
20862 + sta->rx_fragments++;
20863 + sta->rx_bytes += rx->skb->len;
20864 + sta->last_rssi = rx->u.rx.status->ssi;
20866 + if (!(rx->fc & WLAN_FC_MOREFRAG)) {
20867 + /* Change STA power saving mode only in the end of a frame
20868 + * exchange sequence */
20869 + if ((sta->flags & WLAN_STA_PS) && !(rx->fc & WLAN_FC_PWRMGT))
20870 + rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
20871 + else if (!(sta->flags & WLAN_STA_PS) &&
20872 + (rx->fc & WLAN_FC_PWRMGT))
20873 + ap_sta_ps_start(dev, sta);
20876 + /* Drop data::nullfunc frames silently, since they are used only to
20877 + * control station power saving mode. */
20878 + if (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20879 + WLAN_FC_GET_STYPE(rx->fc) == WLAN_FC_STYPE_NULLFUNC) {
20880 + I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
20881 + /* Update counter and free packet here to avoid counting this
20882 + * as a dropped packed. */
20883 + sta->rx_packets++;
20884 + dev_kfree_skb(rx->skb);
20885 + return TXRX_QUEUED;
20888 + return TXRX_CONTINUE;
20892 +static ieee80211_txrx_result
20893 +ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
20895 + if (!rx->sta || !(rx->fc & WLAN_FC_ISWEP) ||
20896 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA || !rx->key ||
20897 + rx->key->alg != ALG_WEP)
20898 + return TXRX_CONTINUE;
20900 + /* Check for weak IVs, if hwaccel did not remove IV from the frame */
20901 + if (rx->local->hw->wep_include_iv ||
20902 + rx->key->force_sw_encrypt || rx->local->conf.sw_decrypt) {
20903 + u8 *iv = ieee80211_wep_is_weak_iv(rx->skb, rx->key);
20905 + rx->sta->wep_weak_iv_count++;
20909 + return TXRX_CONTINUE;
20913 +static ieee80211_txrx_result
20914 +ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
20916 + /* If the device handles decryption totally, skip this test */
20917 + if (rx->local->hw->device_hides_wep)
20918 + return TXRX_CONTINUE;
20920 + if ((rx->key && rx->key->alg != ALG_WEP) ||
20921 + !(rx->fc & WLAN_FC_ISWEP) ||
20922 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA &&
20923 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_MGMT ||
20924 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_AUTH)))
20925 + return TXRX_CONTINUE;
20928 + printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
20930 + return TXRX_DROP;
20933 + if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
20934 + rx->key->force_sw_encrypt || rx->local->conf.sw_decrypt) {
20935 + if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
20936 + printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
20937 + "failed\n", rx->dev->name);
20938 + return TXRX_DROP;
20940 + } else if (rx->local->hw->wep_include_iv) {
20941 + ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
20943 + skb_trim(rx->skb, rx->skb->len - 4);
20946 + return TXRX_CONTINUE;
20950 +static ieee80211_txrx_result
20951 +ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
20953 + if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
20954 + rx->local->conf.mode != IW_MODE_INFRA) {
20955 + /* Pass both encrypted and unencrypted EAPOL frames to user
20956 + * space for processing. */
20957 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20958 + ieee80211_msg_normal);
20959 + return TXRX_QUEUED;
20962 + if (unlikely(rx->sdata->ieee802_1x &&
20963 + WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20964 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_NULLFUNC &&
20965 + (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
20966 + !ieee80211_is_eapol(rx->skb))) {
20967 +#ifdef CONFIG_D80211_DEBUG
20968 + struct ieee80211_hdr *hdr =
20969 + (struct ieee80211_hdr *) rx->skb->data;
20970 + printk(KERN_DEBUG "%s: dropped frame from " MACSTR
20971 + " (unauthorized port)\n", rx->dev->name,
20972 + MAC2STR(hdr->addr2));
20973 +#endif /* CONFIG_D80211_DEBUG */
20974 + return TXRX_DROP;
20977 + return TXRX_CONTINUE;
20981 +static ieee80211_txrx_result
20982 +ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
20984 + /* If the device handles decryption totally, skip this test */
20985 + if (rx->local->hw->device_hides_wep)
20986 + return TXRX_CONTINUE;
20988 + /* Drop unencrypted frames if key is set. */
20989 + if (unlikely(!(rx->fc & WLAN_FC_ISWEP) &&
20990 + WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA &&
20991 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_NULLFUNC &&
20992 + (rx->key || rx->sdata->drop_unencrypted) &&
20993 + (rx->sdata->eapol == 0 ||
20994 + !ieee80211_is_eapol(rx->skb)))) {
20995 + printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
20996 + "encryption\n", rx->dev->name);
20997 + return TXRX_DROP;
20999 + return TXRX_CONTINUE;
21003 +static ieee80211_txrx_result
21004 +ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
21006 + struct ieee80211_sub_if_data *sdata;
21007 + sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
21008 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
21009 + ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
21011 + /* Management frames are sent to hostapd for processing */
21012 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21013 + ieee80211_msg_normal);
21015 + return TXRX_QUEUED;
21019 +static ieee80211_txrx_result
21020 +ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
21022 + struct ieee80211_local *local = rx->local;
21023 + struct sk_buff *skb = rx->skb;
21025 + if (unlikely(local->sta_scanning != 0)) {
21026 + ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
21027 + return TXRX_QUEUED;
21030 + if (WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_DATA)
21031 + local->scan.txrx_count++;
21032 + if (unlikely(local->scan.in_scan != 0 &&
21033 + rx->u.rx.status->freq == local->scan.freq)) {
21034 + struct ieee80211_hdr *hdr;
21037 + local->scan.rx_packets++;
21039 + hdr = (struct ieee80211_hdr *) skb->data;
21040 + fc = le16_to_cpu(hdr->frame_control);
21042 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
21043 + WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
21044 + local->scan.rx_beacon++;
21045 + /* Need to trim FCS here because it is normally
21046 + * removed only after this passive scan handler. */
21047 + if (rx->local->hw->rx_includes_fcs &&
21048 + rx->skb->len > FCS_LEN)
21049 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
21051 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21052 + ieee80211_msg_passive_scan);
21053 + return TXRX_QUEUED;
21055 + I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
21056 + return TXRX_DROP;
21060 + return TXRX_CONTINUE;
21064 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
21071 + fc = le16_to_cpu(hdr->frame_control);
21073 + switch (WLAN_FC_GET_TYPE(fc)) {
21074 + case WLAN_FC_TYPE_DATA:
21075 + switch (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
21076 + case WLAN_FC_TODS:
21077 + return hdr->addr1;
21078 + case (WLAN_FC_TODS | WLAN_FC_FROMDS):
21080 + case WLAN_FC_FROMDS:
21081 + return hdr->addr2;
21083 + return hdr->addr3;
21086 + case WLAN_FC_TYPE_MGMT:
21087 + return hdr->addr3;
21088 + case WLAN_FC_TYPE_CTRL:
21089 + if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PSPOLL)
21090 + return hdr->addr1;
21099 +static struct net_device * ieee80211_get_rx_dev(struct ieee80211_local *local,
21100 + struct ieee80211_hdr *hdr,
21101 + size_t len, int *sta_broadcast)
21104 + struct net_device *dev;
21107 + bssid = ieee80211_get_bssid(hdr, len);
21109 + dev = ieee80211_own_bssid(local, bssid);
21110 + if (!dev && (local->conf.mode == IW_MODE_INFRA ||
21111 + local->conf.mode == IW_MODE_ADHOC))
21112 + dev = ieee80211_sta_bssid(local, bssid, hdr->addr1,
21119 + fc = le16_to_cpu(hdr->frame_control);
21120 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
21121 + (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
21122 + (WLAN_FC_TODS | WLAN_FC_FROMDS)) {
21123 + dev = ieee80211_get_wds_dev(local, hdr->addr2);
21129 + /* Default to default device if nothing else matches */
21130 + return local->wdev;
21134 +static void ieee80211_rx_michael_mic_report(struct net_device *dev,
21135 + struct ieee80211_hdr *hdr,
21136 + struct sta_info *sta,
21137 + struct ieee80211_txrx_data *rx)
21139 + int keyidx, hdrlen;
21141 + hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
21142 + if (rx->skb->len >= hdrlen + 4)
21143 + keyidx = rx->skb->data[hdrlen + 3] >> 6;
21147 + /* TODO: verify that this is not triggered by fragmented
21148 + * frames (hw does not verify MIC for them). */
21149 + printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
21150 + "failure from " MACSTR " to " MACSTR " keyidx=%d\n",
21151 + dev->name, MAC2STR(hdr->addr2), MAC2STR(hdr->addr1), keyidx);
21153 + if (sta == NULL) {
21154 + /* Some hardware versions seem to generate incorrect
21155 + * Michael MIC reports; ignore them to avoid triggering
21156 + * countermeasures. */
21157 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21158 + "error for unknown address " MACSTR "\n",
21159 + dev->name, MAC2STR(hdr->addr2));
21163 + if (!(rx->fc & WLAN_FC_ISWEP)) {
21164 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21165 + "error for a frame with no ISWEP flag (src "
21166 + MACSTR ")\n", dev->name, MAC2STR(hdr->addr2));
21170 + if (rx->local->hw->wep_include_iv &&
21171 + rx->local->conf.mode == IW_MODE_MASTER) {
21172 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
21173 + /* AP with Pairwise keys support should never receive Michael
21174 + * MIC errors for non-zero keyidx because these are reserved
21175 + * for group keys and only the AP is sending real multicast
21176 + * frames in BSS. */
21178 + printk(KERN_DEBUG "%s: ignored Michael MIC error for "
21179 + "a frame with non-zero keyidx (%d) (src " MACSTR
21180 + ")\n", dev->name, keyidx, MAC2STR(hdr->addr2));
21185 + if (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA &&
21186 + (WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_MGMT ||
21187 + WLAN_FC_GET_STYPE(rx->fc) != WLAN_FC_STYPE_AUTH)) {
21188 + printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
21189 + "error for a frame that cannot be encrypted "
21190 + "(fc=0x%04x) (src " MACSTR ")\n",
21191 + dev->name, rx->fc, MAC2STR(hdr->addr2));
21196 + union iwreq_data wrqu;
21197 + char *buf = kmalloc(128, GFP_ATOMIC);
21201 + /* TODO: needed parameters: count, key type, TSC */
21202 + sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
21203 + "keyid=%d %scast addr=" MACSTR ")",
21204 + keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
21205 + MAC2STR(hdr->addr2));
21206 + memset(&wrqu, 0, sizeof(wrqu));
21207 + wrqu.data.length = strlen(buf);
21208 + wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
21212 + /* TODO: consider verifying the MIC error report with software
21213 + * implementation if we get too many spurious reports from the
21215 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21216 + ieee80211_msg_michael_mic_failure);
21220 + dev_kfree_skb(rx->skb);
21225 +static void ieee80211_sta_rx_broadcast(struct ieee80211_txrx_data *rx)
21227 + struct ieee80211_local *local = rx->dev->priv;
21228 + u8 *_bssid, bssid[ETH_ALEN];
21229 + struct sk_buff *orig_skb = rx->skb, *skb;
21230 + struct ieee80211_hdr *hdr;
21231 + ieee80211_rx_handler *handler;
21232 + ieee80211_txrx_result res;
21233 + struct list_head *ptr;
21235 + hdr = (struct ieee80211_hdr *) orig_skb->data;
21236 + _bssid = ieee80211_get_bssid(hdr, orig_skb->len);
21237 + if (_bssid == NULL) {
21238 + dev_kfree_skb(orig_skb);
21241 + memcpy(bssid, _bssid, ETH_ALEN);
21243 + list_for_each(ptr, &local->sub_if_list) {
21244 + struct ieee80211_sub_if_data *sdata =
21245 + list_entry(ptr, struct ieee80211_sub_if_data, list);
21246 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA ||
21247 + (memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) != 0 &&
21248 + !(bssid[0] & 0x01)))
21251 + skb = skb_copy(orig_skb, GFP_ATOMIC);
21252 + if (skb == NULL) {
21253 + if (net_ratelimit()) {
21254 + printk(KERN_DEBUG "%s: failed to copy "
21255 + "multicast frame for %s",
21256 + rx->dev->name, sdata->dev->name);
21261 + hdr = (struct ieee80211_hdr *) skb->data;
21263 + rx->dev = sdata->dev;
21264 + rx->sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
21267 + for (handler = local->rx_handlers; *handler != NULL; handler++)
21269 + res = (*handler)(rx);
21270 + if (res == TXRX_DROP || res == TXRX_QUEUED)
21274 + if (res == TXRX_DROP || *handler == NULL)
21275 + dev_kfree_skb(skb);
21278 + dev_kfree_skb(orig_skb);
21283 + * This is the receive path handler. It is called by a low level driver when an
21284 + * 802.11 MPDU is received from the hardware.
21286 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
21287 + struct ieee80211_rx_status *status)
21289 + struct ieee80211_local *local = dev->priv;
21290 + struct sta_info *sta;
21291 + struct ieee80211_hdr *hdr;
21292 + ieee80211_rx_handler *handler;
21293 + struct ieee80211_txrx_data rx;
21294 + ieee80211_txrx_result res = TXRX_DROP;
21296 + int sta_broadcast = 0;
21298 + hdr = (struct ieee80211_hdr *) skb->data;
21299 + memset(&rx, 0, sizeof(rx));
21301 + rx.local = local;
21302 + if (skb->len >= 16) {
21303 + sta = rx.sta = sta_info_get(local, hdr->addr2);
21304 + if (unlikely(sta == NULL &&
21305 + local->conf.mode == IW_MODE_ADHOC)) {
21306 + u8 *bssid = ieee80211_get_bssid(hdr, skb->len);
21308 + memcmp(bssid, local->bssid, ETH_ALEN) == 0)
21310 + ieee80211_ibss_add_sta(dev, skb, bssid,
21314 + sta = rx.sta = NULL;
21315 + if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS))
21316 + rx.dev = sta->dev;
21318 + rx.dev = ieee80211_get_rx_dev(local, hdr, skb->len,
21321 + rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
21322 + rx.u.rx.status = status;
21323 + rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
21324 + type = WLAN_FC_GET_TYPE(rx.fc);
21325 + if (type == WLAN_FC_TYPE_DATA || type == WLAN_FC_TYPE_MGMT)
21326 + local->dot11ReceivedFragmentCount++;
21327 + if (sta_broadcast) {
21328 + ieee80211_sta_rx_broadcast(&rx);
21332 + if ((status->flag & RX_FLAG_MMIC_ERROR)) {
21333 + ieee80211_rx_michael_mic_report(dev, hdr, sta, &rx);
21337 + for (handler = local->rx_handlers; *handler != NULL; handler++) {
21338 + res = (*handler)(&rx);
21339 + if (res != TXRX_CONTINUE) {
21340 + if (res == TXRX_DROP) {
21341 + I802_DEBUG_INC(local->rx_handlers_drop);
21343 + sta->rx_dropped++;
21345 + if (res == TXRX_QUEUED)
21346 + I802_DEBUG_INC(local->rx_handlers_queued);
21350 + skb = rx.skb; /* handlers are allowed to change skb */
21352 + if (res == TXRX_DROP || *handler == NULL)
21353 + dev_kfree_skb(skb);
21357 + sta_info_release(local, sta);
21361 +static ieee80211_txrx_result
21362 +ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
21364 + struct ieee80211_local *local = tx->local;
21365 + struct sk_buff *skb = tx->skb;
21366 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21367 + u32 load = 0, hdrtime;
21369 + /* TODO: this could be part of tx_status handling, so that the number
21370 + * of retries would be known; TX rate should in that case be stored
21371 + * somewhere with the packet */
21373 + /* Estimate total channel use caused by this frame */
21375 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21376 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21378 + if (local->conf.phymode == MODE_IEEE80211A ||
21379 + local->conf.phymode == MODE_ATHEROS_TURBO ||
21380 + local->conf.phymode == MODE_ATHEROS_TURBOG ||
21381 + (local->conf.phymode == MODE_IEEE80211G &&
21382 + tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
21383 + hdrtime = CHAN_UTIL_HDR_SHORT;
21385 + hdrtime = CHAN_UTIL_HDR_LONG;
21388 + if (!MULTICAST_ADDR(hdr->addr1))
21391 + if (tx->u.tx.control->use_rts_cts)
21392 + load += 2 * hdrtime;
21393 + else if (tx->u.tx.control->use_cts_protect)
21396 + load += skb->len * tx->u.tx.rate->rate_inv;
21398 + if (tx->u.tx.extra_frag) {
21400 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
21401 + load += 2 * hdrtime;
21402 + load += tx->u.tx.extra_frag[i]->len *
21403 + tx->u.tx.rate->rate;
21407 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21408 + load >>= CHAN_UTIL_SHIFT;
21409 + local->channel_use_raw += load;
21411 + tx->sta->channel_use_raw += load;
21412 + tx->sdata->channel_use_raw += load;
21414 + return TXRX_CONTINUE;
21418 +static ieee80211_txrx_result
21419 +ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
21421 + struct ieee80211_local *local = rx->local;
21422 + struct sk_buff *skb = rx->skb;
21423 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21424 + u32 load = 0, hdrtime;
21425 + struct ieee80211_rate *rate;
21428 + /* Estimate total channel use caused by this frame */
21430 + if (unlikely(local->num_curr_rates < 0))
21431 + return TXRX_CONTINUE;
21433 + rate = &local->curr_rates[0];
21434 + for (i = 0; i < local->num_curr_rates; i++) {
21435 + if (local->curr_rates[i].val == rx->u.rx.status->rate) {
21436 + rate = &local->curr_rates[i];
21441 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21442 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21444 + if (local->conf.phymode == MODE_IEEE80211A ||
21445 + local->conf.phymode == MODE_ATHEROS_TURBO ||
21446 + local->conf.phymode == MODE_ATHEROS_TURBOG ||
21447 + (local->conf.phymode == MODE_IEEE80211G &&
21448 + rate->flags & IEEE80211_RATE_ERP))
21449 + hdrtime = CHAN_UTIL_HDR_SHORT;
21451 + hdrtime = CHAN_UTIL_HDR_LONG;
21454 + if (!MULTICAST_ADDR(hdr->addr1))
21457 + load += skb->len * rate->rate_inv;
21459 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21460 + load >>= CHAN_UTIL_SHIFT;
21461 + local->channel_use_raw += load;
21463 + rx->sta->channel_use_raw += load;
21464 + rx->sdata->channel_use_raw += load;
21466 + return TXRX_CONTINUE;
21470 +static void ieee80211_stat_refresh(unsigned long data)
21472 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21473 + struct list_head *ptr, *n;
21475 + if (!local->stat_time)
21478 + /* go through all stations */
21479 + spin_lock_bh(&local->sta_lock);
21480 + list_for_each(ptr, &local->sta_list) {
21481 + struct sta_info *sta =
21482 + list_entry(ptr, struct sta_info, list);
21483 + sta->channel_use = (sta->channel_use_raw / local->stat_time) /
21484 + CHAN_UTIL_PER_10MS;
21485 + sta->channel_use_raw = 0;
21487 + spin_unlock_bh(&local->sta_lock);
21489 + /* go through all subinterfaces */
21490 + list_for_each_safe(ptr, n, &local->sub_if_list) {
21491 + struct ieee80211_sub_if_data *sdata =
21492 + list_entry(ptr, struct ieee80211_sub_if_data, list);
21493 + sdata->channel_use = (sdata->channel_use_raw /
21494 + local->stat_time) / CHAN_UTIL_PER_10MS;
21495 + sdata->channel_use_raw = 0;
21499 + /* hardware interface */
21500 + local->channel_use = (local->channel_use_raw /
21501 + local->stat_time) / CHAN_UTIL_PER_10MS;
21502 + local->channel_use_raw = 0;
21504 + local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
21505 + add_timer(&local->stat_timer);
21509 +/* This is a version of the rx handler that can be called from hard irq
21510 + * context. Post the skb on the queue and schedule the tasklet */
21511 +void ieee80211_rx_irqsafe(struct net_device *dev, struct sk_buff *skb,
21512 + struct ieee80211_rx_status *status)
21514 + struct ieee80211_local *local = dev->priv;
21515 + struct ieee80211_rx_status *saved;
21518 + saved = kmalloc(sizeof(struct ieee80211_rx_status), GFP_ATOMIC);
21520 + memcpy(saved, status, sizeof(struct ieee80211_rx_status));
21521 + memcpy(skb->cb, &saved, sizeof(saved));
21522 + skb->pkt_type = ieee80211_rx_msg;
21523 + skb_queue_tail(&local->skb_queue, skb);
21524 + tasklet_schedule(&local->tasklet);
21528 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
21529 + struct ieee80211_tx_status *status)
21531 + struct ieee80211_local *local = dev->priv;
21532 + struct ieee80211_tx_status *saved;
21536 + saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
21538 + memcpy(saved, status, sizeof(struct ieee80211_tx_status));
21539 + memcpy(skb->cb, &saved, sizeof(saved));
21540 + skb->pkt_type = ieee80211_tx_status_msg;
21541 + skb_queue_tail(status->control.req_tx_status ?
21542 + &local->skb_queue : &local->skb_queue_unreliable, skb);
21543 + tmp = skb_queue_len(&local->skb_queue) +
21544 + skb_queue_len(&local->skb_queue_unreliable);
21545 + while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
21546 + (skb = skb_dequeue(&local->skb_queue_unreliable))) {
21547 + memcpy(&saved, skb->cb, sizeof(saved));
21549 + dev_kfree_skb_irq(skb);
21551 + I802_DEBUG_INC(local->tx_status_drop);
21553 + tasklet_schedule(&local->tasklet);
21557 +static void ieee80211_tasklet_handler(unsigned long data)
21559 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21560 + struct sk_buff *skb;
21561 + struct ieee80211_rx_status *rx_status;
21562 + struct ieee80211_tx_status *tx_status;
21564 + while ((skb = skb_dequeue(&local->skb_queue)) ||
21565 + (skb = skb_dequeue(&local->skb_queue_unreliable))) {
21566 + switch (skb->pkt_type) {
21567 + case ieee80211_rx_msg:
21568 + memcpy(&rx_status, skb->cb, sizeof(rx_status));
21569 + if (!rx_status) {
21570 + if (net_ratelimit())
21571 + printk(KERN_WARNING "%s: Not enough "
21572 + "memory, dropping packet",
21574 + dev_kfree_skb(skb);
21577 + /* Clear skb->type in order to not confuse kernel
21579 + skb->pkt_type = 0;
21580 + __ieee80211_rx(skb->dev, skb, rx_status);
21581 + kfree(rx_status);
21583 + case ieee80211_tx_status_msg:
21584 + memcpy(&tx_status, skb->cb, sizeof(tx_status));
21585 + if (!tx_status) {
21586 + dev_kfree_skb(skb);
21589 + skb->pkt_type = 0;
21590 + ieee80211_tx_status(skb->dev, skb, tx_status);
21591 + kfree(tx_status);
21593 + default: /* should never get here! */
21594 + printk(KERN_ERR "%s: Unknown message type (%d)\n",
21595 + local->wdev->name, skb->pkt_type);
21596 + dev_kfree_skb(skb);
21603 +/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
21604 + * make a prepared TX frame (one that has been given to hw) to look like brand
21605 + * new IEEE 802.11 frame that is ready to go through TX processing again.
21606 + * Also, tx_packet_data in cb is restored from tx_control. */
21607 +static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
21608 + struct ieee80211_key *key,
21609 + struct sk_buff *skb,
21610 + struct ieee80211_tx_control *control)
21612 + int hdrlen, iv_len, mic_len;
21613 + struct ieee80211_tx_packet_data *pkt_data;
21615 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
21616 + pkt_data->sdata = control->sdata;
21617 + pkt_data->req_tx_status = control->req_tx_status;
21618 + pkt_data->do_not_encrypt = control->do_not_encrypt;
21619 + pkt_data->pkt_probe_resp = (control->pkt_type == PKT_PROBE_RESP);
21620 + pkt_data->requeue = control->requeue;
21621 + pkt_data->queue = control->queue;
21626 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
21628 + switch (key->alg) {
21630 + iv_len = WEP_IV_LEN;
21631 + mic_len = WEP_ICV_LEN;
21634 + iv_len = TKIP_IV_LEN;
21635 + mic_len = TKIP_ICV_LEN;
21638 + iv_len = CCMP_HDR_LEN;
21639 + mic_len = CCMP_MIC_LEN;
21645 + if (skb->len >= mic_len && key->force_sw_encrypt)
21646 + skb_trim(skb, skb->len - mic_len);
21647 + if (skb->len >= iv_len && skb->len > hdrlen) {
21648 + memmove(skb->data + iv_len, skb->data, hdrlen);
21649 + skb_pull(skb, iv_len);
21653 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21654 + u16 fc = le16_to_cpu(hdr->frame_control);
21655 + if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
21656 + fc &= ~(WLAN_FC_STYPE_QOS_DATA << 4);
21657 + hdr->frame_control = cpu_to_le16(fc);
21658 + memmove(skb->data + 2, skb->data, hdrlen - 2);
21659 + skb_pull(skb, 2);
21665 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
21666 + struct ieee80211_tx_status *status)
21668 + struct sk_buff *skb2;
21669 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21670 + struct ieee80211_local *local = dev->priv;
21676 + "%s: ieee80211_tx_status called with NULL status\n",
21678 + dev_kfree_skb(skb);
21682 + if (status->excessive_retries) {
21683 + struct sta_info *sta;
21684 + sta = sta_info_get(local, hdr->addr1);
21686 + if (sta->flags & WLAN_STA_PS) {
21687 + /* The STA is in power save mode, so assume
21688 + * that this TX packet failed because of that.
21690 + status->excessive_retries = 0;
21691 + status->tx_filtered = 1;
21693 + sta_info_release(local, sta);
21697 + if (status->tx_filtered) {
21698 + struct sta_info *sta;
21699 + sta = sta_info_get(local, hdr->addr1);
21701 + sta->tx_filtered_count++;
21703 + /* Clear the TX filter mask for this STA when sending
21704 + * the next packet. If the STA went to power save mode,
21705 + * this will happen when it is waking up for the next
21707 + sta->clear_dst_mask = 1;
21709 + /* TODO: Is the WLAN_STA_PS flag always set here or is
21710 + * the race between RX and TX status causing some
21711 + * packets to be filtered out before 80211.o gets an
21712 + * update for PS status? This seems to be the case, so
21713 + * no changes are likely to be needed. */
21714 + if (sta->flags & WLAN_STA_PS &&
21715 + skb_queue_len(&sta->tx_filtered) <
21716 + STA_MAX_TX_BUFFER) {
21717 + ieee80211_remove_tx_extra(local, sta->key,
21719 + &status->control);
21720 + skb_queue_tail(&sta->tx_filtered, skb);
21721 + } else if (!(sta->flags & WLAN_STA_PS) &&
21722 + !status->control.requeue) {
21723 + /* Software retry the packet once */
21724 + status->control.requeue = 1;
21725 + ieee80211_remove_tx_extra(local, sta->key,
21727 + &status->control);
21728 + dev_queue_xmit(skb);
21730 + if (net_ratelimit()) {
21731 + printk(KERN_DEBUG "%s: dropped TX "
21732 + "filtered frame queue_len=%d "
21736 + &sta->tx_filtered),
21737 + !!(sta->flags & WLAN_STA_PS),
21740 + dev_kfree_skb(skb);
21742 + sta_info_release(local, sta);
21746 + rate_control_tx_status(dev, skb, status);
21749 +#ifdef IEEE80211_LEDS
21750 + if (local->tx_led_counter && (local->tx_led_counter-- == 1)) {
21751 + ieee80211_tx_led(0, dev);
21753 +#endif /* IEEE80211_LEDS */
21755 + * Fragments are passed to low-level drivers as separate skbs, so these
21756 + * are actually fragments, not frames. Update frame counters only for
21757 + * the first fragment of the frame. */
21759 + frag = WLAN_GET_SEQ_FRAG(le16_to_cpu(hdr->seq_ctrl));
21760 + type = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_control));
21762 + if (status->ack) {
21764 + local->dot11TransmittedFrameCount++;
21765 + if (MULTICAST_ADDR(hdr->addr1))
21766 + local->dot11MulticastTransmittedFrameCount++;
21767 + if (status->retry_count > 0)
21768 + local->dot11RetryCount++;
21769 + if (status->retry_count > 1)
21770 + local->dot11MultipleRetryCount++;
21773 + /* This counter shall be incremented for an acknowledged MPDU
21774 + * with an individual address in the address 1 field or an MPDU
21775 + * with a multicast address in the address 1 field of type Data
21776 + * or Management. */
21777 + if (!MULTICAST_ADDR(hdr->addr1) || type == WLAN_FC_TYPE_DATA ||
21778 + type == WLAN_FC_TYPE_MGMT)
21779 + local->dot11TransmittedFragmentCount++;
21782 + local->dot11FailedCount++;
21785 + if (!status->control.req_tx_status) {
21786 + dev_kfree_skb(skb);
21790 + msg_type = status->ack ? ieee80211_msg_tx_callback_ack :
21791 + ieee80211_msg_tx_callback_fail;
21793 + /* skb was the original skb used for TX. Clone it and give the clone
21794 + * to netif_rx(). Free original skb. */
21795 + skb2 = skb_copy(skb, GFP_ATOMIC);
21797 + dev_kfree_skb(skb);
21800 + dev_kfree_skb(skb);
21803 + /* Send frame to hostapd */
21804 + ieee80211_rx_mgmt(dev, skb, NULL, msg_type);
21808 +/* TODO: implement register/unregister functions for adding TX/RX handlers
21809 + * into ordered list */
21811 +static ieee80211_rx_handler ieee80211_rx_handlers[] =
21813 + ieee80211_rx_h_parse_qos,
21814 + ieee80211_rx_h_load_stats,
21815 + ieee80211_rx_h_monitor,
21816 + ieee80211_rx_h_passive_scan,
21817 + ieee80211_rx_h_check,
21818 + ieee80211_rx_h_sta_process,
21819 + ieee80211_rx_h_ccmp_decrypt,
21820 + ieee80211_rx_h_tkip_decrypt,
21821 + ieee80211_rx_h_wep_weak_iv_detection,
21822 + ieee80211_rx_h_wep_decrypt,
21823 + ieee80211_rx_h_defragment,
21824 + ieee80211_rx_h_ieee80211_rx_h_ps_poll,
21825 + ieee80211_rx_h_michael_mic_verify,
21826 + /* this must be after decryption - so header is counted in MPDU mic
21827 + * must be before pae and data, so QOS_DATA format frames
21828 + * are not passed to user space by these functions
21830 + ieee80211_rx_h_remove_qos_control,
21831 + ieee80211_rx_h_802_1x_pae,
21832 + ieee80211_rx_h_drop_unencrypted,
21833 + ieee80211_rx_h_data,
21834 + ieee80211_rx_h_mgmt,
21838 +static ieee80211_tx_handler ieee80211_tx_handlers[] =
21840 + ieee80211_tx_h_rate_limit,
21841 + ieee80211_tx_h_check_assoc,
21842 + ieee80211_tx_h_ps_buf,
21843 + ieee80211_tx_h_select_key,
21844 + ieee80211_tx_h_michael_mic_add,
21845 + ieee80211_tx_h_fragment,
21846 + ieee80211_tx_h_tkip_encrypt,
21847 + ieee80211_tx_h_ccmp_encrypt,
21848 + ieee80211_tx_h_wep_encrypt,
21849 + ieee80211_tx_h_rate_ctrl,
21850 + ieee80211_tx_h_misc,
21851 + ieee80211_tx_h_load_stats,
21856 +static void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
21858 + /* Default values for sub-interface parameters */
21859 + sdata->drop_unencrypted = 0;
21860 + sdata->eapol = 1;
21864 +static struct net_device *ieee80211_if_add(struct net_device *dev,
21865 + const char *name, int locked)
21867 + struct net_device *wds_dev = NULL, *tmp_dev;
21868 + struct ieee80211_local *local = dev->priv;
21869 + struct ieee80211_sub_if_data *sdata = NULL, *sdata_parent;
21874 + /* ensure 32-bit alignment of our private data and hw private data */
21875 + alloc_size = sizeof(struct net_device) + 3 +
21876 + sizeof(struct ieee80211_sub_if_data) + 3;
21878 + wds_dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
21879 + if (wds_dev == NULL)
21882 + memset(wds_dev, 0, alloc_size);
21883 + wds_dev->priv = local;
21884 + ether_setup(wds_dev);
21885 + if (strlen(name) == 0) {
21888 + sprintf(wds_dev->name, "%s.%d", dev->name, i++);
21889 + tmp_dev = dev_get_by_name(wds_dev->name);
21890 + if (tmp_dev == NULL)
21892 + dev_put(tmp_dev);
21893 + } while (i < 10000);
21895 + snprintf(wds_dev->name, IFNAMSIZ, "%s", name);
21898 + memcpy(wds_dev->dev_addr, dev->dev_addr, ETH_ALEN);
21899 + wds_dev->hard_start_xmit = ieee80211_subif_start_xmit;
21900 + wds_dev->wireless_handlers =
21901 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
21902 + wds_dev->do_ioctl = ieee80211_ioctl;
21903 + wds_dev->change_mtu = ieee80211_change_mtu;
21904 + wds_dev->tx_timeout = ieee80211_tx_timeout;
21905 + wds_dev->get_stats = ieee80211_get_stats;
21906 + wds_dev->open = ieee80211_open;
21907 + wds_dev->stop = ieee80211_stop;
21908 + wds_dev->base_addr = dev->base_addr;
21909 + wds_dev->irq = dev->irq;
21910 + wds_dev->mem_start = dev->mem_start;
21911 + wds_dev->mem_end = dev->mem_end;
21912 + wds_dev->tx_queue_len = 0;
21914 + sdata = IEEE80211_DEV_TO_SUB_IF(wds_dev);
21915 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
21916 + sdata->master = local->mdev;
21917 + sdata->dev = wds_dev;
21918 + sdata->local = local;
21919 + memset(&sdata->stats, 0, sizeof(struct net_device_stats));
21920 + sdata_parent = IEEE80211_DEV_TO_SUB_IF(dev);
21921 + if (sdata_parent->type == IEEE80211_SUB_IF_TYPE_AP)
21922 + sdata->bss = &sdata_parent->u.ap;
21924 + printk(KERN_DEBUG "%s: could not set BSS pointer for new "
21925 + "interface %s\n", dev->name, wds_dev->name);
21927 + ieee80211_if_sdata_init(sdata);
21930 + ret = register_netdevice(wds_dev);
21932 + ret = register_netdev(wds_dev);
21938 + list_add(&sdata->list, &local->sub_if_list);
21944 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
21945 + struct ieee80211_if_wds *wds, int locked)
21947 + struct net_device *wds_dev = NULL;
21948 + struct ieee80211_sub_if_data *sdata = NULL;
21950 + if (strlen(name) != 0) {
21951 + wds_dev = dev_get_by_name(name);
21953 + dev_put(wds_dev);
21958 + wds_dev = ieee80211_if_add(dev, name, locked);
21959 + if (wds_dev == NULL)
21962 + sdata = IEEE80211_DEV_TO_SUB_IF(wds_dev);
21963 + sdata->type = IEEE80211_SUB_IF_TYPE_WDS;
21964 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
21966 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
21967 + printk(KERN_DEBUG
21968 + "%s: Added WDS Link to " MACSTR "\n",
21969 + wds_dev->name, MAC2STR(sdata->u.wds.remote_addr));
21970 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
21972 + ieee80211_proc_init_virtual(wds_dev);
21978 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
21979 + struct ieee80211_if_wds *wds, int locked)
21981 + struct net_device *wds_dev = NULL;
21982 + struct ieee80211_local *local = dev->priv;
21983 + struct ieee80211_sub_if_data *sdata = NULL;
21984 + struct sta_info *sta;
21985 + struct list_head *ptr;
21987 + list_for_each(ptr, &local->sub_if_list) {
21988 + sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
21989 + if (strcmp(name, sdata->dev->name) == 0) {
21990 + wds_dev = sdata->dev;
21995 + if (wds_dev == NULL || sdata->type != IEEE80211_SUB_IF_TYPE_WDS)
21998 + /* Remove STA entry for the old peer */
21999 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22001 + sta_info_release(local, sta);
22002 + sta_info_free(local, sta, 0);
22004 + printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
22005 + "%s peer " MACSTR "\n",
22006 + dev->name, wds_dev->name,
22007 + MAC2STR(sdata->u.wds.remote_addr));
22010 + /* Update WDS link data */
22011 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
22017 +static void ieee80211_if_init(struct net_device *dev)
22019 + struct ieee80211_local *local = dev->priv;
22021 + spin_lock_init(&local->sub_if_lock);
22022 + INIT_LIST_HEAD(&local->sub_if_list);
22026 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
22027 + struct ieee80211_if_vlan *vlan, int locked)
22029 + struct net_device *vlan_dev = NULL;
22030 + struct ieee80211_sub_if_data *sdata = NULL;
22032 + if (strlen(name) != 0) {
22033 + vlan_dev = dev_get_by_name(name);
22035 + dev_put(vlan_dev);
22040 + vlan_dev = ieee80211_if_add(dev, name, locked);
22041 + if (vlan_dev == NULL)
22044 + sdata = IEEE80211_DEV_TO_SUB_IF(vlan_dev);
22045 + sdata->type = IEEE80211_SUB_IF_TYPE_VLAN;
22046 + ieee80211_proc_init_virtual(vlan_dev);
22051 +static void ieee80211_if_ap_init(struct ieee80211_sub_if_data *sdata)
22053 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
22054 + sdata->u.ap.dtim_period = 2;
22055 + sdata->u.ap.force_unicast_rateidx = -1;
22056 + sdata->u.ap.max_ratectrl_rateidx = -1;
22057 + skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
22058 + sdata->bss = &sdata->u.ap;
22062 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
22065 + struct ieee80211_local *local = dev->priv;
22066 + struct net_device *ap_dev = NULL;
22067 + struct ieee80211_sub_if_data *sdata = NULL;
22069 + if (local->bss_dev_count >= local->conf.bss_count)
22072 + if (strlen(name) != 0) {
22073 + ap_dev = dev_get_by_name(name);
22080 + ap_dev = ieee80211_if_add(dev, name, locked);
22081 + if (ap_dev == NULL)
22084 + memcpy(ap_dev->dev_addr, bssid, ETH_ALEN);
22085 + sdata = IEEE80211_DEV_TO_SUB_IF(ap_dev);
22086 + ieee80211_if_ap_init(sdata);
22087 + ieee80211_proc_init_virtual(ap_dev);
22088 + spin_lock_bh(&local->sub_if_lock);
22089 + local->bss_devs[local->bss_dev_count] = ap_dev;
22090 + local->bss_dev_count++;
22091 + spin_unlock_bh(&local->sub_if_lock);
22097 +static void ieee80211_addr_inc(u8 *addr)
22100 + while (pos >= 0) {
22102 + if (addr[pos] != 0)
22109 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked)
22111 + struct ieee80211_local *local = dev->priv;
22112 + struct net_device *sta_dev;
22113 + struct ieee80211_sub_if_data *sdata;
22114 + struct ieee80211_if_sta *ifsta;
22117 + if (local->sta_dev_count >= local->conf.bss_count)
22120 + if (strlen(name) != 0) {
22121 + sta_dev = dev_get_by_name(name);
22123 + dev_put(sta_dev);
22128 + sta_dev = ieee80211_if_add(dev, name, locked);
22129 + if (sta_dev == NULL)
22132 + sdata = IEEE80211_DEV_TO_SUB_IF(sta_dev);
22133 + ifsta = &sdata->u.sta;
22134 + sdata->type = IEEE80211_SUB_IF_TYPE_STA;
22135 + ieee80211_proc_init_virtual(sta_dev);
22137 + spin_lock_bh(&local->sub_if_lock);
22138 + for (i = 0; i < local->conf.bss_count; i++) {
22139 + if (local->sta_devs[i] == NULL) {
22140 + local->sta_devs[i] = sta_dev;
22141 + local->sta_dev_count++;
22142 + printk(KERN_DEBUG "%s: using STA entry %d\n",
22143 + sta_dev->name, i);
22145 + ieee80211_addr_inc(sta_dev->dev_addr);
22148 + printk(KERN_DEBUG "%s: MAC address " MACSTR "\n",
22149 + sta_dev->name, MAC2STR(sta_dev->dev_addr));
22153 + spin_unlock_bh(&local->sub_if_lock);
22155 + init_timer(&ifsta->timer);
22156 + ifsta->timer.data = (unsigned long) sta_dev;
22157 + ifsta->timer.function = ieee80211_sta_timer;
22159 + ifsta->capab = WLAN_CAPABILITY_ESS;
22160 + ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
22161 + IEEE80211_AUTH_ALG_SHARED_KEY;
22162 + ifsta->create_ibss = 1;
22163 + ifsta->wmm_enabled = 1;
22169 +static void ieee80211_if_del(struct ieee80211_local *local,
22170 + struct ieee80211_sub_if_data *sdata, int locked)
22172 + struct sta_info *sta;
22173 + u8 addr[ETH_ALEN];
22175 + struct list_head *ptr, *n;
22177 + memset(addr, 0xff, ETH_ALEN);
22178 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
22179 + if (!sdata->keys[i])
22182 + /* Low-level driver has probably disabled hw
22183 + * already, so there is not really much point
22184 + * in disabling the keys at this point. */
22185 + if (local->hw->set_key)
22186 + local->hw->set_key(dev, DISABLE_KEY, addr,
22187 + local->keys[i], 0);
22189 + kfree(sdata->keys[i]);
22192 + switch (sdata->type) {
22193 + case IEEE80211_SUB_IF_TYPE_AP:
22194 + /* Remove all virtual interfaces that use this BSS
22195 + * as their sdata->bss */
22196 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22197 + struct ieee80211_sub_if_data *tsdata =
22198 + list_entry(ptr, struct ieee80211_sub_if_data,
22201 + if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
22202 + printk(KERN_DEBUG "%s: removing virtual "
22203 + "interface %s because its BSS interface"
22204 + " is being removed\n",
22205 + sdata->dev->name, tsdata->dev->name);
22206 + ieee80211_if_del(local, tsdata, locked);
22210 + kfree(sdata->u.ap.beacon_head);
22211 + kfree(sdata->u.ap.beacon_tail);
22212 + spin_lock_bh(&local->sub_if_lock);
22213 + for (j = 0; j < local->bss_dev_count; j++) {
22214 + if (sdata->dev == local->bss_devs[j]) {
22215 + if (j + 1 < local->bss_dev_count) {
22216 + memcpy(&local->bss_devs[j],
22217 + &local->bss_devs[j + 1],
22218 + (local->bss_dev_count - j - 1) *
22219 + sizeof(local->bss_devs[0]));
22220 + local->bss_devs[local->bss_dev_count -
22223 + local->bss_devs[j] = NULL;
22224 + local->bss_dev_count--;
22228 + spin_unlock_bh(&local->sub_if_lock);
22230 + if (sdata->dev != local->mdev) {
22231 + struct sk_buff *skb;
22232 + while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
22233 + local->total_ps_buffered--;
22234 + dev_kfree_skb(skb);
22239 + case IEEE80211_SUB_IF_TYPE_WDS:
22240 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22242 + sta_info_release(local, sta);
22243 + sta_info_free(local, sta, 0);
22245 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
22246 + printk(KERN_DEBUG "%s: Someone had deleted my STA "
22247 + "entry for the WDS link\n", local->mdev->name);
22248 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
22251 + case IEEE80211_SUB_IF_TYPE_STA:
22252 + del_timer_sync(&sdata->u.sta.timer);
22253 + if (local->scan_timer.data == (unsigned long) sdata->dev)
22254 + del_timer_sync(&local->scan_timer);
22255 + kfree(sdata->u.sta.extra_ie);
22256 + sdata->u.sta.extra_ie = NULL;
22257 + kfree(sdata->u.sta.assocreq_ies);
22258 + sdata->u.sta.assocreq_ies = NULL;
22259 + kfree(sdata->u.sta.assocresp_ies);
22260 + sdata->u.sta.assocresp_ies = NULL;
22261 + if (sdata->u.sta.probe_resp) {
22262 + dev_kfree_skb(sdata->u.sta.probe_resp);
22263 + sdata->u.sta.probe_resp = NULL;
22265 + for (i = 0; i < local->conf.bss_count; i++) {
22266 + if (local->sta_devs[i] == sdata->dev) {
22267 + local->sta_devs[i] = NULL;
22268 + local->sta_dev_count--;
22276 + /* remove all STAs that are bound to this virtual interface */
22277 + sta_info_flush(local, sdata->dev);
22279 + list_del(&sdata->list);
22280 + ieee80211_proc_deinit_virtual(sdata->dev);
22282 + unregister_netdevice(sdata->dev);
22284 + unregister_netdev(sdata->dev);
22285 + /* Default data device and management device are allocated with the
22286 + * master device. All other devices are separately allocated and will
22287 + * be freed here. */
22288 + if (sdata->dev != local->mdev && sdata->dev != local->wdev &&
22289 + sdata->dev != local->apdev)
22290 + kfree(sdata->dev);
22294 +static int ieee80211_if_remove(struct net_device *dev, const char *name,
22295 + int id, int locked)
22297 + struct ieee80211_local *local = dev->priv;
22298 + struct list_head *ptr, *n;
22300 + /* Make sure not to touch sdata->master since it may
22301 + * have already been deleted, etc. */
22303 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22304 + struct ieee80211_sub_if_data *sdata =
22305 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22307 + if (sdata->type == id && strcmp(name, sdata->dev->name) == 0) {
22308 + ieee80211_if_del(local, sdata, locked);
22317 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name,
22320 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_WDS,
22325 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name,
22328 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_VLAN,
22333 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name,
22336 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_AP,
22341 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name,
22344 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_STA,
22349 +int ieee80211_if_flush(struct net_device *dev, int locked)
22351 + struct ieee80211_local *local = dev->priv;
22352 + struct list_head *ptr, *n;
22354 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22355 + struct ieee80211_sub_if_data *sdata =
22356 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22358 + if (sdata->dev != local->mdev &&
22359 + sdata->dev != local->wdev &&
22360 + sdata->dev != local->apdev)
22361 + ieee80211_if_del(local, sdata, locked);
22368 +static void ieee80211_precalc_rates(struct ieee80211_hw *hw)
22370 + struct ieee80211_hw_modes *mode;
22371 + struct ieee80211_rate *rate;
22374 + for (m = 0; m < hw->num_modes; m++) {
22375 + mode = &hw->modes[m];
22376 + for (r = 0; r < mode->num_rates; r++) {
22377 + rate = &mode->rates[r];
22378 + rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
22384 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
22385 + void (*setup)(struct net_device *))
22387 + struct net_device *dev, *apdev, *mdev;
22388 + struct ieee80211_local *local;
22389 + struct ieee80211_sub_if_data *sdata;
22392 + /* Ensure 32-bit alignment of our private data and hw private data.
22393 + * Each net_device is followed by a sub_if_data which which is used
22394 + * for wds/vlan information; it is aligned as well.
22396 + * Sample memory map looks something like:
22398 + * 0000 *****************
22400 + * 015c *****************
22402 + * 017c *****************
22404 + * 0b84 *****************
22406 + * 1664 *****************
22408 + * 17c0 *****************
22410 + * *****************
22411 + * * master net_dev*
22412 + * *****************
22414 + * *****************
22416 + alloc_size = sizeof(struct net_device) +
22417 + sizeof(struct ieee80211_sub_if_data) + 3 +
22418 + sizeof(struct ieee80211_local) + 3 +
22419 + priv_data_len + 3 +
22420 + sizeof(struct net_device) + 3 +
22421 + sizeof(struct ieee80211_sub_if_data) + 3 +
22422 + sizeof(struct net_device) + 3 +
22423 + sizeof(struct ieee80211_sub_if_data) + 3 +
22425 + mdev = (struct net_device *) kzalloc(alloc_size, GFP_KERNEL);
22426 + if (mdev == NULL)
22429 + mdev->priv = (struct net_device *)
22431 + ((sizeof(struct net_device) + 3) & ~3) +
22432 + ((sizeof(struct ieee80211_sub_if_data) + 3) & ~3));
22433 + local = mdev->priv;
22434 + local->hw_priv = (void *)
22435 + ((char *) local + ((sizeof(struct ieee80211_local) + 3) & ~3));
22436 + apdev = (struct net_device *)
22437 + ((char *) local->hw_priv + ((priv_data_len + 3) & ~3));
22438 + dev = (struct net_device *)
22439 + ((char *) apdev +
22440 + ((sizeof(struct net_device) + 3) & ~3) +
22441 + ((sizeof(struct ieee80211_sub_if_data) + 3) & ~3));
22442 + dev->priv = local;
22444 + ether_setup(dev);
22445 + memcpy(dev->name, "wlan%d", 7);
22447 + dev->hard_start_xmit = ieee80211_subif_start_xmit;
22448 + dev->wireless_handlers =
22449 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
22450 + dev->do_ioctl = ieee80211_ioctl;
22451 + dev->change_mtu = ieee80211_change_mtu;
22452 + dev->tx_timeout = ieee80211_tx_timeout;
22453 + dev->get_stats = ieee80211_get_stats;
22454 + dev->open = ieee80211_open;
22455 + dev->stop = ieee80211_stop;
22456 + dev->tx_queue_len = 0;
22457 + dev->set_mac_address = ieee80211_set_mac_address;
22459 + local->dev_index = -1;
22460 + local->wdev = dev;
22461 + local->mdev = mdev;
22462 + local->rx_handlers = ieee80211_rx_handlers;
22463 + local->tx_handlers = ieee80211_tx_handlers;
22465 + local->bridge_packets = 1;
22467 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
22468 + local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
22469 + local->short_retry_limit = 7;
22470 + local->long_retry_limit = 4;
22471 + local->conf.calib_int = 60;
22472 + local->rate_ctrl_num_up = RATE_CONTROL_NUM_UP;
22473 + local->rate_ctrl_num_down = RATE_CONTROL_NUM_DOWN;
22474 + local->conf.bss_count = 1;
22475 + memset(local->conf.bssid_mask, 0xff, ETH_ALEN);
22476 + local->bss_devs = kmalloc(sizeof(struct net_device *), GFP_KERNEL);
22477 + if (local->bss_devs == NULL)
22479 + local->bss_devs[0] = local->wdev;
22480 + local->bss_dev_count = 1;
22481 + local->sta_devs = kmalloc(sizeof(struct net_device *), GFP_KERNEL);
22482 + if (local->sta_devs == NULL)
22484 + local->sta_devs[0] = NULL;
22486 + local->scan.in_scan = 0;
22487 + local->hw_modes = (unsigned int) -1;
22489 + init_timer(&local->scan.timer); /* clear it out */
22491 + spin_lock_init(&local->generic_lock);
22492 + init_timer(&local->rate_limit_timer);
22493 + local->rate_limit_timer.function = ieee80211_rate_limit;
22494 + local->rate_limit_timer.data = (unsigned long) local;
22495 + init_timer(&local->stat_timer);
22496 + local->stat_timer.function = ieee80211_stat_refresh;
22497 + local->stat_timer.data = (unsigned long) local;
22498 + ieee80211_rx_bss_list_init(dev);
22500 + sta_info_init(local);
22502 + ieee80211_if_init(dev);
22504 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22505 + sdata->dev = dev;
22506 + sdata->master = mdev;
22507 + sdata->local = local;
22508 + ieee80211_if_sdata_init(sdata);
22509 + ieee80211_if_ap_init(sdata);
22510 + list_add_tail(&sdata->list, &local->sub_if_list);
22512 + if (strlen(dev->name) + 2 >= sizeof(dev->name))
22515 + apdev = (struct net_device *)
22516 + ((char *) local->hw_priv + ((priv_data_len + 3) & ~3));
22517 + local->apdev = apdev;
22518 + ether_setup(apdev);
22519 + apdev->priv = local;
22520 + apdev->hard_start_xmit = ieee80211_mgmt_start_xmit;
22521 + apdev->change_mtu = ieee80211_change_mtu_apdev;
22522 + apdev->get_stats = ieee80211_get_stats;
22523 + apdev->open = ieee80211_open;
22524 + apdev->stop = ieee80211_stop;
22525 + apdev->type = ARPHRD_IEEE80211_PRISM;
22526 + apdev->hard_header_parse = header_parse_80211;
22527 + apdev->tx_queue_len = 0;
22528 + sprintf(apdev->name, "%sap", dev->name);
22530 + sdata = IEEE80211_DEV_TO_SUB_IF(apdev);
22531 + sdata->type = IEEE80211_SUB_IF_TYPE_MGMT;
22532 + sdata->dev = apdev;
22533 + sdata->master = mdev;
22534 + sdata->local = local;
22535 + list_add_tail(&sdata->list, &local->sub_if_list);
22537 + ether_setup(mdev);
22538 + mdev->hard_start_xmit = ieee80211_master_start_xmit;
22539 + mdev->wireless_handlers =
22540 + (struct iw_handler_def *) &ieee80211_iw_handler_def;
22541 + mdev->do_ioctl = ieee80211_ioctl;
22542 + mdev->change_mtu = ieee80211_change_mtu;
22543 + mdev->tx_timeout = ieee80211_tx_timeout;
22544 + mdev->get_stats = ieee80211_get_stats;
22545 + mdev->open = ieee80211_open;
22546 + mdev->stop = ieee80211_stop;
22547 + mdev->type = ARPHRD_IEEE80211;
22548 + mdev->hard_header_parse = header_parse_80211;
22549 + sprintf(mdev->name, "%s.11", dev->name);
22551 + sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
22552 + sdata->type = IEEE80211_SUB_IF_TYPE_AP;
22553 + sdata->dev = mdev;
22554 + sdata->master = mdev;
22555 + sdata->local = local;
22556 + list_add_tail(&sdata->list, &local->sub_if_list);
22558 + tasklet_init(&local->tasklet,
22559 + ieee80211_tasklet_handler,
22560 + (unsigned long) local);
22561 + skb_queue_head_init(&local->skb_queue);
22562 + skb_queue_head_init(&local->skb_queue_unreliable);
22570 + ieee80211_free_hw(mdev);
22575 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw)
22577 + struct ieee80211_local *local = dev->priv;
22583 + if (hw->version != IEEE80211_VERSION) {
22584 + printk("ieee80211_register_hw - version mismatch: 80211.o "
22585 + "version %d, low-level driver version %d\n",
22586 + IEEE80211_VERSION, hw->version);
22590 + result = ieee80211_dev_alloc_index(local);
22594 + local->class_dev.dev = dev->class_dev.dev;
22595 + result = ieee80211_register_sysfs(local);
22599 + local->conf.mode = IW_MODE_MASTER;
22600 + local->conf.beacon_int = 1000;
22602 + ieee80211_update_hw(dev, hw); /* Don't care about the result. */
22604 + sta_info_start(local);
22606 + result = register_netdev(local->wdev);
22608 + goto fail_1st_dev;
22610 + result = register_netdev(local->apdev);
22612 + goto fail_2nd_dev;
22614 + if (hw->fraglist)
22615 + dev->features |= NETIF_F_FRAGLIST;
22616 + result = register_netdev(dev);
22618 + goto fail_3rd_dev;
22620 + if (rate_control_initialize(local) < 0) {
22621 + printk(KERN_DEBUG "%s: Failed to initialize rate control "
22622 + "algorithm\n", dev->name);
22626 + /* TODO: add rtnl locking around device creation and qdisc install */
22627 + ieee80211_install_qdisc(dev);
22629 + ieee80211_wep_init(local);
22630 + ieee80211_proc_init_interface(local);
22634 + unregister_netdev(dev);
22636 + unregister_netdev(local->apdev);
22638 + unregister_netdev(local->wdev);
22640 + sta_info_stop(local);
22641 + ieee80211_unregister_sysfs(local);
22643 + ieee80211_dev_free_index(local);
22647 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw)
22649 + struct ieee80211_local *local = dev->priv;
22653 + /* Backwards compatibility for low-level drivers that do not set number
22654 + * of TX queues. */
22655 + if (hw->queues == 0)
22658 + memcpy(local->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
22659 + local->apdev->base_addr = dev->base_addr;
22660 + local->apdev->irq = dev->irq;
22661 + local->apdev->mem_start = dev->mem_start;
22662 + local->apdev->mem_end = dev->mem_end;
22664 + memcpy(local->wdev->dev_addr, dev->dev_addr, ETH_ALEN);
22665 + local->wdev->base_addr = dev->base_addr;
22666 + local->wdev->irq = dev->irq;
22667 + local->wdev->mem_start = dev->mem_start;
22668 + local->wdev->mem_end = dev->mem_end;
22670 + if (!hw->modes || !hw->modes->channels || !hw->modes->rates ||
22671 + !hw->modes->num_channels || !hw->modes->num_rates)
22674 + ieee80211_precalc_rates(hw);
22675 + local->conf.phymode = hw->modes[0].mode;
22676 + local->curr_rates = hw->modes[0].rates;
22677 + local->num_curr_rates = hw->modes[0].num_rates;
22678 + ieee80211_prepare_rates(dev);
22680 + local->conf.freq = local->hw->modes[0].channels[0].freq;
22681 + local->conf.channel = local->hw->modes[0].channels[0].chan;
22682 + local->conf.channel_val = local->hw->modes[0].channels[0].val;
22683 + /* FIXME: Invoke config to allow driver to set the channel. */
22689 +void ieee80211_unregister_hw(struct net_device *dev)
22691 + struct ieee80211_local *local = dev->priv;
22692 + struct list_head *ptr, *n;
22695 + tasklet_disable(&local->tasklet);
22696 + /* TODO: skb_queue should be empty here, no need to do anything? */
22698 + if (local->rate_limit)
22699 + del_timer_sync(&local->rate_limit_timer);
22700 + if (local->stat_time)
22701 + del_timer_sync(&local->stat_timer);
22702 + if (local->scan_timer.data)
22703 + del_timer_sync(&local->scan_timer);
22704 + ieee80211_rx_bss_list_deinit(dev);
22706 + list_for_each_safe(ptr, n, &local->sub_if_list) {
22707 + struct ieee80211_sub_if_data *sdata =
22708 + list_entry(ptr, struct ieee80211_sub_if_data, list);
22709 + ieee80211_if_del(local, sdata, 0);
22712 + sta_info_stop(local);
22713 + ieee80211_unregister_sysfs(local);
22715 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
22716 + if (local->fragments[i].skb)
22717 + dev_kfree_skb(local->fragments[i].skb);
22719 + for (i = 0; i < NUM_IEEE80211_MODES; i++) {
22720 + kfree(local->supp_rates[i]);
22721 + kfree(local->basic_rates[i]);
22724 + kfree(local->conf.ssid);
22725 + kfree(local->conf.generic_elem);
22727 + ieee80211_proc_deinit_interface(local);
22729 + if (skb_queue_len(&local->skb_queue)
22730 + || skb_queue_len(&local->skb_queue_unreliable))
22731 + printk(KERN_WARNING "%s: skb_queue not empty", dev->name);
22732 + skb_queue_purge(&local->skb_queue);
22733 + skb_queue_purge(&local->skb_queue_unreliable);
22735 + rate_control_free(local);
22736 + ieee80211_dev_free_index(local);
22739 +void ieee80211_free_hw(struct net_device *dev)
22741 + struct ieee80211_local *local = dev->priv;
22743 + kfree(local->sta_devs);
22744 + kfree(local->bss_devs);
22749 +/* Perform netif operations on all configured interfaces */
22750 +int ieee80211_netif_oper(struct net_device *sdev, Netif_Oper op)
22752 + struct ieee80211_local *local = sdev->priv;
22753 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(sdev);
22754 + struct net_device *dev = sdata->master;
22757 + case NETIF_ATTACH:
22758 + netif_device_attach(dev);
22760 + case NETIF_DETACH:
22761 + netif_device_detach(dev);
22763 + case NETIF_START:
22764 + netif_start_queue(dev);
22769 + if (local->scan.in_scan == 0) {
22770 + netif_wake_queue(dev);
22772 + if (/* FIX: 802.11 qdisc in use */ 1)
22773 + __netif_schedule(dev);
22777 + case NETIF_IS_STOPPED:
22778 + if (netif_queue_stopped(dev))
22781 + case NETIF_UPDATE_TX_START:
22782 + dev->trans_start = jiffies;
22790 +void * ieee80211_dev_hw_data(struct net_device *dev)
22792 + struct ieee80211_local *local = dev->priv;
22793 + return local->hw_priv;
22797 +void * ieee80211_dev_stats(struct net_device *dev)
22799 + struct ieee80211_sub_if_data *sdata;
22800 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22801 + return &(sdata->stats);
22805 +int ieee80211_rate_control_register(struct rate_control_ops *ops)
22807 + struct rate_control_algs *alg;
22809 + alg = kmalloc(sizeof(*alg), GFP_KERNEL);
22810 + if (alg == NULL) {
22813 + memset(alg, 0, sizeof(*alg));
22814 + alg->next = ieee80211_rate_ctrl_algs;
22816 + ieee80211_rate_ctrl_algs = alg;
22822 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops)
22824 + struct rate_control_algs *alg, *prev;
22827 + alg = ieee80211_rate_ctrl_algs;
22829 + if (alg->ops == ops) {
22831 + prev->next = alg->next;
22833 + ieee80211_rate_ctrl_algs = alg->next;
22843 +static int rate_control_initialize(struct ieee80211_local *local)
22845 + struct rate_control_algs *algs;
22847 + if (!ieee80211_rate_ctrl_algs)
22848 + request_module("ieee80211_rate_control");
22850 + for (algs = ieee80211_rate_ctrl_algs; algs; algs = algs->next) {
22851 + local->rate_ctrl = algs->ops;
22852 + local->rate_ctrl_priv = rate_control_alloc(local);
22853 + if (local->rate_ctrl_priv) {
22854 + printk(KERN_DEBUG "%s: Selected rate control "
22855 + "algorithm '%s'\n", local->wdev->name,
22856 + local->rate_ctrl->name);
22861 + printk(KERN_WARNING "%s: Failed to select rate control algorithm\n",
22862 + local->wdev->name);
22867 +static int __init ieee80211_init(void)
22869 + struct sk_buff *skb;
22872 + if (sizeof(struct ieee80211_tx_packet_data) > (sizeof(skb->cb))) {
22873 + printk("80211: ieee80211_tx_packet_data is bigger "
22874 + "than the skb->cb (%d > %d)\n",
22875 + (int) sizeof(struct ieee80211_tx_packet_data),
22876 + (int) sizeof(skb->cb));
22879 + if ((ret = ieee80211_sysfs_init())) {
22880 + printk(KERN_WARNING "ieee80211_init: sysfs initialization "
22885 + ieee80211_proc_init();
22887 + ret = ieee80211_wme_register();
22889 + printk(KERN_DEBUG "ieee80211_init: failed to "
22890 + "initialize WME (err=%d)\n", ret);
22891 + ieee80211_proc_deinit();
22900 +static void __exit ieee80211_exit(void)
22902 + ieee80211_wme_unregister();
22903 + ieee80211_proc_deinit();
22904 + ieee80211_sysfs_deinit();
22908 +EXPORT_SYMBOL(ieee80211_alloc_hw);
22909 +EXPORT_SYMBOL(ieee80211_register_hw);
22910 +EXPORT_SYMBOL(ieee80211_update_hw);
22911 +EXPORT_SYMBOL(ieee80211_unregister_hw);
22912 +EXPORT_SYMBOL(ieee80211_free_hw);
22913 +EXPORT_SYMBOL(__ieee80211_rx);
22914 +EXPORT_SYMBOL(ieee80211_tx_status);
22915 +EXPORT_SYMBOL(ieee80211_beacon_get);
22916 +EXPORT_SYMBOL(ieee80211_get_buffered_bc);
22917 +EXPORT_SYMBOL(ieee80211_netif_oper);
22918 +EXPORT_SYMBOL(ieee80211_dev_hw_data);
22919 +EXPORT_SYMBOL(ieee80211_dev_stats);
22920 +EXPORT_SYMBOL(ieee80211_get_hw_conf);
22921 +EXPORT_SYMBOL(ieee80211_set_aid_for_sta);
22922 +EXPORT_SYMBOL(ieee80211_rx_irqsafe);
22923 +EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
22924 +EXPORT_SYMBOL(ieee80211_get_hdrlen);
22925 +EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
22926 +EXPORT_SYMBOL(ieee80211_rate_control_register);
22927 +EXPORT_SYMBOL(ieee80211_rate_control_unregister);
22928 +EXPORT_SYMBOL(sta_info_get);
22929 +EXPORT_SYMBOL(sta_info_release);
22930 +EXPORT_SYMBOL(ieee80211_radar_status);
22932 +module_init(ieee80211_init);
22933 +module_exit(ieee80211_exit);
22935 +MODULE_DESCRIPTION("IEEE 802.11 subsystem");
22936 +MODULE_LICENSE("GPL");
22937 diff -Nur linux-2.6.16/net/d80211/ieee80211_dev.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_dev.c
22938 --- linux-2.6.16/net/d80211/ieee80211_dev.c 1970-01-01 01:00:00.000000000 +0100
22939 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_dev.c 2006-03-28 22:16:14.000000000 +0200
22942 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
22944 + * This program is free software; you can redistribute it and/or modify
22945 + * it under the terms of the GNU General Public License version 2 as
22946 + * published by the Free Software Foundation.
22949 +#include <linux/kernel.h>
22950 +#include <linux/interrupt.h>
22951 +#include <linux/if.h>
22952 +#include <linux/if_ether.h>
22953 +#include <linux/netdevice.h>
22954 +#include <net/d80211.h>
22955 +#include "ieee80211_i.h"
22957 +struct ieee80211_dev_list {
22958 + struct list_head list;
22960 + struct ieee80211_local *local;
22963 +static LIST_HEAD(dev_list);
22964 +static DEFINE_SPINLOCK(dev_list_lock);
22967 +/* Caller must hold dev_list_lock */
22968 +static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
22970 + struct ieee80211_dev_list *dev_item;
22972 + list_for_each_entry(dev_item, &dev_list, list) {
22973 + if (dev_item->dev_index == index)
22979 +int ieee80211_dev_alloc_index(struct ieee80211_local *local)
22981 + struct list_head *i;
22982 + struct ieee80211_dev_list *dev_item, *new;
22985 + new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
22988 + new->local = local;
22989 + spin_lock(&dev_list_lock);
22990 + list_for_each(i, &dev_list) {
22991 + dev_item = list_entry(i, struct ieee80211_dev_list, list);
22992 + if (index < dev_item->dev_index)
22996 + new->dev_index = index;
22997 + list_add_tail(&new->list, i);
22998 + spin_unlock(&dev_list_lock);
22999 + local->dev_index = index;
23003 +void ieee80211_dev_free_index(struct ieee80211_local *local)
23005 + struct ieee80211_dev_list *dev_item;
23007 + spin_lock(&dev_list_lock);
23008 + dev_item = __ieee80211_dev_find(local->dev_index);
23010 + list_del(&dev_item->list);
23011 + spin_unlock(&dev_list_lock);
23014 + local->dev_index = -1;
23017 +struct ieee80211_local *ieee80211_dev_find(int index)
23019 + struct ieee80211_dev_list *dev_item;
23021 + spin_lock(&dev_list_lock);
23022 + dev_item = __ieee80211_dev_find(index);
23023 + spin_unlock(&dev_list_lock);
23024 + return dev_item ? dev_item->local : NULL;
23026 diff -Nur linux-2.6.16/net/d80211/ieee80211_i.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_i.h
23027 --- linux-2.6.16/net/d80211/ieee80211_i.h 1970-01-01 01:00:00.000000000 +0100
23028 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_i.h 2006-03-28 22:16:14.000000000 +0200
23031 + * Copyright 2002-2005, Instant802 Networks, Inc.
23032 + * Copyright 2005, Devicescape Software, Inc.
23034 + * This program is free software; you can redistribute it and/or modify
23035 + * it under the terms of the GNU General Public License version 2 as
23036 + * published by the Free Software Foundation.
23039 +#ifndef IEEE80211_I_H
23040 +#define IEEE80211_I_H
23042 +#include <linux/kernel.h>
23043 +#include <linux/device.h>
23044 +#include <linux/if_ether.h>
23045 +#include <linux/interrupt.h>
23046 +#include <linux/list.h>
23047 +#include <linux/netdevice.h>
23048 +#include <linux/skbuff.h>
23049 +#include "ieee80211_key.h"
23050 +#include "sta_info.h"
23052 +/* ieee80211.o internal definitions, etc. These are not included into
23053 + * low-level drivers. */
23056 +#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
23057 +#endif /* ETH_P_PAE */
23059 +#define IEEE80211_MAX_SSID_LEN 32
23061 +struct ieee80211_local;
23063 +#define BIT(x) (1 << (x))
23065 +#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
23068 +/* Maximum number of broadcast/multicast frames to buffer when some of the
23069 + * associated stations are using power saving. */
23070 +#define AP_MAX_BC_BUFFER 128
23072 +/* Maximum number of frames buffered to all STAs, including multicast frames.
23073 + * Note: increasing this limit increases the potential memory requirement. Each
23074 + * frame can be up to about 2 kB long. */
23075 +#define TOTAL_MAX_TX_BUFFER 512
23078 +#define MAC2STR(a) ((a)[0] & 0xff), ((a)[1] & 0xff), ((a)[2] & 0xff), \
23079 + ((a)[3] & 0xff), ((a)[4] & 0xff), ((a)[5] & 0xff)
23080 +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
23082 +#define MULTICAST_ADDR(a) ((a)[0] & 0x01)
23085 +/* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
23086 + * reception of at least three fragmented frames. This limit can be increased
23087 + * by changing this define, at the cost of slower frame reassembly and
23088 + * increased memory use (about 2 kB of RAM per entry). */
23089 +#define IEEE80211_FRAGMENT_MAX 4
23091 +struct ieee80211_fragment_entry {
23092 + unsigned long first_frag_time;
23093 + unsigned int seq;
23094 + unsigned int rx_queue;
23095 + unsigned int last_frag;
23096 + struct sk_buff *skb;
23097 + int ccmp; /* Whether fragments were encrypted with CCMP */
23098 + u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
23102 +struct ieee80211_sta_bss {
23103 + struct list_head list;
23104 + struct ieee80211_sta_bss *hnext;
23107 + u8 bssid[ETH_ALEN];
23108 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23110 + u16 capability; /* host byte order */
23116 + size_t wpa_ie_len;
23118 + size_t rsn_ie_len;
23120 + size_t wmm_ie_len;
23121 +#define IEEE80211_MAX_SUPP_RATES 32
23122 + u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
23123 + size_t supp_rates_len;
23128 + unsigned long last_update;
23134 + TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
23135 +} ieee80211_txrx_result;
23137 +struct ieee80211_txrx_data {
23138 + struct sk_buff *skb;
23139 + struct net_device *dev;
23140 + struct ieee80211_local *local;
23141 + struct ieee80211_sub_if_data *sdata;
23142 + struct sta_info *sta;
23143 + u16 fc, ethertype;
23144 + struct ieee80211_key *key;
23145 + unsigned int fragmented:1; /* whether the MSDU was fragmented */
23148 + struct ieee80211_tx_control *control;
23150 + int ps_buffered:1;
23151 + int short_preamble:1;
23152 + int probe_last_frag:1;
23153 + struct ieee80211_rate *rate;
23154 + /* use this rate (if set) for last fragment; rate can
23155 + * be set to lower rate for the first fragments, e.g.,
23156 + * when using CTS protection with IEEE 802.11g. */
23157 + struct ieee80211_rate *last_frag_rate;
23158 + int last_frag_rateidx;
23159 + int mgmt_interface;
23161 + /* Extra fragments (in addition to the first fragment
23163 + int num_extra_frag;
23164 + struct sk_buff **extra_frag;
23167 + struct ieee80211_rx_status *status;
23168 + int sent_ps_buffered;
23172 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23174 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
23177 +struct ieee80211_passive_scan {
23178 + unsigned int in_scan:1; /* this must be cleared before calling
23179 + * netif_oper(WAKEUP) */
23180 + unsigned int our_mode_only:1; /* only scan our physical mode a/b/g/etc
23182 + int interval; /* time in seconds between scans */
23183 + int time; /* time in microseconds to scan for */
23184 + int channel; /* channel to be scanned */
23195 + struct timer_list timer;
23197 + struct sk_buff *skb; /* skb to transmit before changing channels,
23198 + * maybe null for none */
23199 + struct ieee80211_tx_control tx_control;
23201 + unsigned int num_scans;
23204 +typedef ieee80211_txrx_result (*ieee80211_tx_handler)
23205 +(struct ieee80211_txrx_data *tx);
23207 +typedef ieee80211_txrx_result (*ieee80211_rx_handler)
23208 +(struct ieee80211_txrx_data *rx);
23210 +struct ieee80211_if_ap {
23211 + u8 *beacon_head, *beacon_tail;
23212 + int beacon_head_len, beacon_tail_len;
23214 + /* TODO: sta_aid could be replaced by 2008-bit large bitfield of
23215 + * that could be used in TIM element generation. This would also
23216 + * make TIM element generation a bit faster. */
23217 + /* AID mapping to station data. NULL, if AID is free. AID is in the
23218 + * range 1..2007 and sta_aid[i] corresponds to AID i+1. */
23219 + struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
23220 + int max_aid; /* largest aid currently in use */
23221 + atomic_t num_sta_ps; /* number of stations in PS mode */
23222 + struct sk_buff_head ps_bc_buf;
23223 + int dtim_period, dtim_count;
23224 + int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
23225 + int max_ratectrl_rateidx; /* max TX rateidx for rate control */
23226 + int num_beacons; /* number of TXed beacon frames for this BSS */
23229 +struct ieee80211_if_wds {
23230 + u8 remote_addr[ETH_ALEN];
23231 + struct sta_info *sta;
23234 +struct ieee80211_if_vlan {
23238 +struct ieee80211_if_sta {
23240 + IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
23241 + IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
23242 + IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
23244 + struct timer_list timer;
23245 + u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
23246 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23249 + u16 ap_capab, capab;
23250 + u8 *extra_ie; /* to be added to the end of AssocReq */
23251 + size_t extra_ie_len;
23253 + /* The last AssocReq/Resp IEs */
23254 + u8 *assocreq_ies, *assocresp_ies;
23255 + size_t assocreq_ies_len, assocresp_ies_len;
23257 + int auth_tries, assoc_tries;
23261 + int prev_bssid_set:1;
23262 + int authenticated:1;
23263 + int associated:1;
23264 + int probereq_poll:1;
23265 + int use_protection:1;
23266 + int create_ibss:1;
23267 + int mixed_cell:1;
23268 + int wmm_enabled:1;
23271 + unsigned long last_probe;
23273 +#define IEEE80211_AUTH_ALG_OPEN BIT(0)
23274 +#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
23275 +#define IEEE80211_AUTH_ALG_LEAP BIT(2)
23276 + unsigned int auth_algs; /* bitfield of allowed auth algs */
23277 + int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
23278 + int auth_transaction;
23280 + unsigned long ibss_join_req;
23281 + struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
23282 + u32 supp_rates_bits;
23284 + int wmm_last_param_set;
23288 +#define IEEE80211_SUB_IF_TYPE_AP 0x00000000
23289 +#define IEEE80211_SUB_IF_TYPE_MGMT 0x00000001
23290 +#define IEEE80211_SUB_IF_TYPE_STA 0x00000002
23291 +#define IEEE80211_SUB_IF_TYPE_WDS 0x5A580211
23292 +#define IEEE80211_SUB_IF_TYPE_VLAN 0x00080211
23294 +struct ieee80211_sub_if_data {
23295 + struct list_head list;
23296 + unsigned int type;
23298 + struct net_device *dev;
23299 + struct net_device *master;
23300 + struct ieee80211_local *local;
23302 + struct net_device_stats stats;
23303 + int drop_unencrypted;
23304 + int eapol; /* 0 = process EAPOL frames as normal data frames,
23305 + * 1 = send EAPOL frames through wlan#ap to hostapd
23307 + int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
23310 +#define NUM_DEFAULT_KEYS 4
23311 + struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
23312 + struct ieee80211_key *default_key;
23314 + struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
23317 + struct ieee80211_if_ap ap;
23318 + struct ieee80211_if_wds wds;
23319 + struct ieee80211_if_vlan vlan;
23320 + struct ieee80211_if_sta sta;
23323 + int channel_use_raw;
23326 +#define IEEE80211_DEV_TO_SUB_IF(dev) ((struct ieee80211_sub_if_data *) \
23327 + ((char *)(dev) + ((sizeof(struct net_device) + 3) & ~3)))
23328 +#define IEEE80211_SUB_IF_TO_DEV(sub_if) ((struct net_device *) \
23329 + ((char *)(sub_if) - ((sizeof(struct net_device) + 3) & ~3)))
23332 +struct ieee80211_local {
23333 + struct ieee80211_hw *hw;
23335 + struct net_device *mdev; /* wlan#.11 - "master" 802.11 device */
23336 + struct net_device *wdev; /* wlan# - default Ethernet (data) devide */
23337 + struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
23339 + struct ieee80211_conf conf;
23342 + struct class_device class_dev;
23344 + /* Tasklet and skb queue to process calls from IRQ mode. All frames
23345 + * added to skb_queue will be processed, but frames in
23346 + * skb_queue_unreliable may be dropped if the total length of these
23347 + * queues increases over the limit. */
23348 +#define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
23349 + struct tasklet_struct tasklet;
23350 + struct sk_buff_head skb_queue;
23351 + struct sk_buff_head skb_queue_unreliable;
23353 + ieee80211_rx_msg = 1,
23354 + ieee80211_tx_status_msg = 2
23355 + } ieee80211_msg_enum;
23357 + spinlock_t generic_lock;
23358 + /* Station data structures */
23359 + spinlock_t sta_lock; /* mutex for STA data structures */
23360 + int num_sta; /* number of stations in sta_list */
23361 + struct list_head sta_list;
23362 + struct sta_info *sta_hash[STA_HASH_SIZE];
23363 + struct timer_list sta_cleanup;
23365 + /* Current rate table. This is a pointer to hw->modes structure. */
23366 + struct ieee80211_rate *curr_rates;
23367 + int num_curr_rates;
23369 + void *rate_ctrl_priv;
23370 + struct rate_control_ops *rate_ctrl;
23372 + int next_mode; /* MODE_IEEE80211*
23373 + * The mode preference for next channel change. This is
23374 + * used to select .11g vs. .11b channels (or 4.9 GHz vs.
23375 + * .11a) when the channel number is not unique. */
23377 + /* Supported and basic rate filters for different modes. These are
23378 + * pointers to -1 terminated lists and rates in 100 kbps units. */
23379 + int *supp_rates[NUM_IEEE80211_MODES];
23380 + int *basic_rates[NUM_IEEE80211_MODES];
23382 + int rts_threshold;
23383 + int cts_protect_erp_frames;
23384 + int fragmentation_threshold;
23385 + int short_retry_limit; /* dot11ShortRetryLimit */
23386 + int long_retry_limit; /* dot11LongRetryLimit */
23387 + int short_preamble; /* use short preamble with IEEE 802.11b */
23390 + int key_tx_rx_threshold; /* number of times any key can be used in TX
23391 + * or RX before generating a rekey
23392 + * notification; 0 = notification disabled. */
23394 + /* Fragment table for host-based reassembly */
23395 + struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
23396 + unsigned int fragment_next;
23398 + int bridge_packets; /* bridge packets between associated stations and
23399 + * deliver multicast frames both back to wireless
23400 + * media and to the local net stack */
23402 + struct ieee80211_passive_scan scan;
23405 + ieee80211_rx_handler *rx_handlers;
23406 + ieee80211_tx_handler *tx_handlers;
23408 + spinlock_t sub_if_lock; /* mutex for STA data structures */
23409 + struct list_head sub_if_list;
23410 + struct net_device **bss_devs; /* pointer to IF_TYPE_AP devices for
23411 + * quick access to BSS data */
23412 + int bss_dev_count; /* number of used entries in bss_devs; note: the
23413 + * total size of bss_devs array is stored in
23414 + * conf.bss_count */
23415 + struct net_device **sta_devs; /* pointer to IF_TYPE_STA devices */
23416 + int sta_dev_count; /* number of used entries in sta_devs */
23417 + int sta_scanning;
23418 + int scan_hw_mode_idx;
23419 + int scan_channel_idx;
23420 + enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
23421 + unsigned long last_scan_completed;
23422 + struct timer_list scan_timer;
23423 + int scan_oper_channel;
23424 + int scan_oper_channel_val;
23425 + int scan_oper_power_level;
23426 + int scan_oper_freq;
23427 + int scan_oper_phymode;
23428 + int scan_oper_antenna_max;
23429 + u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
23430 + size_t scan_ssid_len;
23431 + int scan_skip_11b;
23432 + struct list_head sta_bss_list;
23433 + struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
23434 + spinlock_t sta_bss_lock;
23435 +#define IEEE80211_SCAN_MATCH_SSID BIT(0)
23436 +#define IEEE80211_SCAN_WPA_ONLY BIT(1)
23437 +#define IEEE80211_SCAN_EXTRA_INFO BIT(2)
23440 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23442 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
23443 + /* SNMP counters */
23444 + /* dot11CountersTable */
23445 + u32 dot11TransmittedFragmentCount;
23446 + u32 dot11MulticastTransmittedFrameCount;
23447 + u32 dot11FailedCount;
23448 + u32 dot11RetryCount;
23449 + u32 dot11MultipleRetryCount;
23450 + u32 dot11FrameDuplicateCount;
23451 + u32 dot11ReceivedFragmentCount;
23452 + u32 dot11MulticastReceivedFrameCount;
23453 + u32 dot11TransmittedFrameCount;
23454 + u32 dot11WEPUndecryptableCount;
23456 + int tx_led_counter;
23459 + u32 channel_use_raw;
23461 + struct timer_list stat_timer;
23463 + u8 bssid[ETH_ALEN]; /* BSSID for STA modes (Adhoc/Managed) */
23464 + struct timer_list rate_limit_timer;
23466 + u32 rate_limit_burst;
23467 + u32 rate_limit_bucket;
23468 + struct proc_dir_entry *proc, *proc_sta, *proc_iface;
23470 + struct work_struct sta_proc_add;
23473 + STA_ANTENNA_SEL_AUTO = 0,
23474 + STA_ANTENNA_SEL_SW_CTRL = 1,
23475 + STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
23476 + } sta_antenna_sel;
23478 + int rate_ctrl_num_up, rate_ctrl_num_down;
23480 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
23481 + /* TX/RX handler statistics */
23482 + unsigned int tx_handlers_drop;
23483 + unsigned int tx_handlers_queued;
23484 + unsigned int tx_handlers_drop_unencrypted;
23485 + unsigned int tx_handlers_drop_fragment;
23486 + unsigned int tx_handlers_drop_wep;
23487 + unsigned int tx_handlers_drop_rate_limit;
23488 + unsigned int tx_handlers_drop_not_assoc;
23489 + unsigned int tx_handlers_drop_unauth_port;
23490 + unsigned int rx_handlers_drop;
23491 + unsigned int rx_handlers_queued;
23492 + unsigned int rx_handlers_drop_nullfunc;
23493 + unsigned int rx_handlers_drop_defrag;
23494 + unsigned int rx_handlers_drop_short;
23495 + unsigned int rx_handlers_drop_passive_scan;
23496 + unsigned int tx_expand_skb_head;
23497 + unsigned int tx_expand_skb_head_cloned;
23498 + unsigned int rx_expand_skb_head;
23499 + unsigned int rx_expand_skb_head2;
23500 + unsigned int rx_handlers_fragments;
23501 + unsigned int tx_status_drop;
23502 + unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
23503 + unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
23504 +#define I802_DEBUG_INC(c) (c)++
23505 +#else /* CONFIG_D80211_DEBUG_COUNTERS */
23506 +#define I802_DEBUG_INC(c) do { } while (0)
23507 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
23510 + int default_wep_only; /* only default WEP keys are used with this
23511 + * interface; this is used to decide when hwaccel
23512 + * can be used with default keys */
23513 + int total_ps_buffered; /* total number of all buffered unicast and
23514 + * multicast packets for power saving stations
23516 + int allow_broadcast_always; /* whether to allow TX of broadcast frames
23517 + * even when there are no associated STAs
23520 + int wifi_wme_noack_test;
23521 + unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
23523 + unsigned int hw_modes; /* bitfield of allowed hardware modes;
23524 + * (1 << MODE_*) */
23529 +int ieee80211_hw_config(struct net_device *dev);
23530 +struct ieee80211_key_conf *
23531 +ieee80211_key_data2conf(struct ieee80211_local *local,
23532 + struct ieee80211_key *data);
23533 +void ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
23534 + struct ieee80211_rx_status *status, u32 msg_type);
23535 +void ieee80211_prepare_rates(struct net_device *dev);
23536 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
23537 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
23538 + struct ieee80211_if_wds *wds, int locked);
23539 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
23540 + struct ieee80211_if_vlan *vlan, int locked);
23541 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
23544 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name, int locked);
23545 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name, int locked);
23546 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name, int locked);
23547 +int ieee80211_if_flush(struct net_device *dev, int locked);
23548 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
23549 + struct ieee80211_if_wds *wds, int locked);
23551 +/* ieee80211_ioctl.c */
23552 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
23553 +extern const struct iw_handler_def ieee80211_iw_handler_def;
23555 +/* Set hw encryption from ieee80211 */
23556 +int ieee80211_set_hw_encryption(struct net_device *dev,
23557 + struct sta_info *sta, u8 addr[ETH_ALEN],
23558 + struct ieee80211_key *key);
23560 +/* ieee80211_scan.c */
23561 +void ieee80211_init_scan(struct net_device *dev);
23562 +void ieee80211_stop_scan(struct net_device *dev);
23566 +/* Least common multiple of the used rates (in 100 kbps). This is used to
23567 + * calculate rate_inv values for each rate so that only integers are needed. */
23568 +#define CHAN_UTIL_RATE_LCM 95040
23569 +/* 1 usec is 1/8 * (95040/10) = 1188 */
23570 +#define CHAN_UTIL_PER_USEC 1188
23571 +/* Amount of bits to shift the result right to scale the total utilization
23572 + * to values that will not wrap around 32-bit integers. */
23573 +#define CHAN_UTIL_SHIFT 9
23574 +/* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
23575 + * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
23576 + * raw value with about 23 should give utilization in 10th of a percentage
23577 + * (1/1000). However, utilization is only estimated and not all intervals
23578 + * between frames etc. are calculated. 18 seems to give numbers that are closer
23579 + * to the real maximum. */
23580 +#define CHAN_UTIL_PER_10MS 18
23581 +#define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
23582 +#define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
23587 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked);
23588 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name, int locked);
23589 +/* ieee80211_ioctl.c */
23590 +int ieee80211_set_compression(struct ieee80211_local *local,
23591 + struct net_device *dev, struct sta_info *sta);
23592 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
23594 +/* ieee80211_sta.c */
23595 +void ieee80211_sta_timer(unsigned long ptr);
23596 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
23597 + struct ieee80211_rx_status *rx_status);
23598 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
23599 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
23600 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
23601 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
23602 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
23603 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
23604 + struct ieee80211_rx_status *rx_status);
23605 +void ieee80211_rx_bss_list_init(struct net_device *dev);
23606 +void ieee80211_rx_bss_list_deinit(struct net_device *dev);
23607 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
23608 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
23609 + struct sk_buff *skb, u8 *bssid,
23611 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
23612 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
23614 +/* ieee80211_dev.c */
23615 +int ieee80211_dev_alloc_index(struct ieee80211_local *local);
23616 +void ieee80211_dev_free_index(struct ieee80211_local *local);
23617 +struct ieee80211_local *ieee80211_dev_find(int index);
23619 +/* ieee80211_sysfs.c */
23620 +int ieee80211_register_sysfs(struct ieee80211_local *local);
23621 +void ieee80211_unregister_sysfs(struct ieee80211_local *local);
23622 +int ieee80211_sysfs_init(void);
23623 +void ieee80211_sysfs_deinit(void);
23625 +#endif /* IEEE80211_I_H */
23626 diff -Nur linux-2.6.16/net/d80211/ieee80211_ioctl.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_ioctl.c
23627 --- linux-2.6.16/net/d80211/ieee80211_ioctl.c 1970-01-01 01:00:00.000000000 +0100
23628 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_ioctl.c 2006-03-28 22:16:14.000000000 +0200
23631 + * Copyright 2002-2005, Instant802 Networks, Inc.
23632 + * Copyright 2005-2006, Devicescape Software, Inc.
23634 + * This program is free software; you can redistribute it and/or modify
23635 + * it under the terms of the GNU General Public License version 2 as
23636 + * published by the Free Software Foundation.
23639 +#include <linux/config.h>
23640 +#include <linux/version.h>
23641 +#include <linux/module.h>
23642 +#include <linux/init.h>
23643 +#include <linux/netdevice.h>
23644 +#include <linux/types.h>
23645 +#include <linux/slab.h>
23646 +#include <linux/skbuff.h>
23647 +#include <linux/if_arp.h>
23648 +#include <linux/wireless.h>
23649 +#include <net/iw_handler.h>
23650 +#include <asm/uaccess.h>
23652 +#include <net/d80211.h>
23653 +#include <net/d80211_mgmt.h>
23654 +#include "ieee80211_i.h"
23655 +#include "hostapd_ioctl.h"
23656 +#include "rate_control.h"
23658 +#include "aes_ccm.h"
23661 +static int ieee80211_regdom = 0x10; /* FCC */
23662 +MODULE_PARM(ieee80211_regdom, "i");
23663 +MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
23666 + * If firmware is upgraded by the vendor, additional channels can be used based
23667 + * on the new Japanese regulatory rules. This is indicated by setting
23668 + * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
23671 +static int ieee80211_japan_5ghz /* = 0 */;
23672 +MODULE_PARM(ieee80211_japan_5ghz, "i");
23673 +MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
23676 +static int ieee80211_ioctl_set_beacon(struct net_device *dev,
23677 + struct prism2_hostapd_param *param,
23681 + struct ieee80211_sub_if_data *sdata;
23682 + struct ieee80211_if_ap *ap;
23683 + u8 **b_head, **b_tail;
23684 + int *b_head_len, *b_tail_len;
23687 + len = ((char *) param->u.beacon.data - (char *) param) +
23688 + param->u.beacon.head_len + param->u.beacon.tail_len;
23690 + if (param_len > len)
23692 + else if (param_len != len)
23695 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23696 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
23698 + ap = &sdata->u.ap;
23702 + b_head = &ap->beacon_head;
23703 + b_tail = &ap->beacon_tail;
23704 + b_head_len = &ap->beacon_head_len;
23705 + b_tail_len = &ap->beacon_tail_len;
23708 + printk(KERN_DEBUG "%s: unknown beacon flag %d\n",
23709 + dev->name, flag);
23718 + *b_head_len = param->u.beacon.head_len;
23719 + *b_tail_len = param->u.beacon.tail_len;
23721 + *b_head = kmalloc(*b_head_len, GFP_KERNEL);
23723 + memcpy(*b_head, param->u.beacon.data, *b_head_len);
23725 + printk(KERN_DEBUG "%s: failed to allocate beacon_head\n",
23730 + if (*b_tail_len > 0) {
23731 + *b_tail = kmalloc(*b_tail_len, GFP_KERNEL);
23733 + memcpy(*b_tail, param->u.beacon.data + (*b_head_len),
23736 + printk(KERN_DEBUG "%s: failed to allocate "
23737 + "beacon_tail\n", dev->name);
23746 +static int ieee80211_ioctl_get_hw_features(struct net_device *dev,
23747 + struct prism2_hostapd_param *param,
23750 + struct ieee80211_local *local = dev->priv;
23751 + u8 *pos = param->u.hw_features.data;
23752 + int left = param_len - (pos - (u8 *) param);
23754 + struct hostapd_ioctl_hw_modes_hdr *hdr;
23755 + struct ieee80211_rate_data *rate;
23756 + struct ieee80211_channel_data *chan;
23758 + param->u.hw_features.flags = 0;
23759 + if (local->hw->data_nullfunc_ack)
23760 + param->u.hw_features.flags |= HOSTAP_HW_FLAG_NULLFUNC_OK;
23762 + param->u.hw_features.num_modes = local->hw->num_modes;
23763 + for (mode = 0; mode < local->hw->num_modes; mode++) {
23765 + struct ieee80211_hw_modes *m = &local->hw->modes[mode];
23766 + clen = m->num_channels * sizeof(struct ieee80211_channel_data);
23767 + rlen = m->num_rates * sizeof(struct ieee80211_rate_data);
23768 + if (left < sizeof(*hdr) + clen + rlen)
23770 + left -= sizeof(*hdr) + clen + rlen;
23772 + hdr = (struct hostapd_ioctl_hw_modes_hdr *) pos;
23773 + hdr->mode = m->mode;
23774 + hdr->num_channels = m->num_channels;
23775 + hdr->num_rates = m->num_rates;
23777 + pos = (u8 *) (hdr + 1);
23778 + chan = (struct ieee80211_channel_data *) pos;
23779 + for (i = 0; i < m->num_channels; i++) {
23780 + chan[i].chan = m->channels[i].chan;
23781 + chan[i].freq = m->channels[i].freq;
23782 + chan[i].flag = m->channels[i].flag;
23786 + rate = (struct ieee80211_rate_data *) pos;
23787 + for (i = 0; i < m->num_rates; i++) {
23788 + rate[i].rate = m->rates[i].rate;
23789 + rate[i].flags = m->rates[i].flags;
23798 +static int ieee80211_ioctl_scan(struct net_device *dev,
23799 + struct prism2_hostapd_param *param)
23801 + struct ieee80211_local *local = dev->priv;
23803 + if (local->hw->passive_scan == NULL)
23804 + return -EOPNOTSUPP;
23806 + if ((param->u.scan.now == 1) && (local->scan.in_scan == 1))
23809 + if (param->u.scan.our_mode_only >= 0)
23810 + local->scan.our_mode_only = param->u.scan.our_mode_only;
23811 + if (param->u.scan.interval >= 0)
23812 + local->scan.interval = param->u.scan.interval;
23813 + if (param->u.scan.listen >= 0)
23814 + local->scan.time = param->u.scan.listen;
23815 + if (param->u.scan.channel > 0)
23816 + local->scan.channel = param->u.scan.channel;
23817 + if (param->u.scan.now == 1) {
23818 + local->scan.in_scan = 0;
23819 + mod_timer(&local->scan.timer, jiffies);
23822 + param->u.scan.our_mode_only = local->scan.our_mode_only;
23823 + param->u.scan.interval = local->scan.interval;
23824 + param->u.scan.listen = local->scan.time;
23825 + if (local->scan.in_scan == 1)
23826 + param->u.scan.last_rx = -1;
23828 + param->u.scan.last_rx = local->scan.rx_packets;
23829 + local->scan.rx_packets = -1;
23831 + param->u.scan.channel = local->hw->modes[local->scan.mode_idx].
23832 + channels[local->scan.chan_idx].chan;
23838 +static int ieee80211_ioctl_flush(struct net_device *dev,
23839 + struct prism2_hostapd_param *param)
23841 + struct ieee80211_local *local = dev->priv;
23842 + sta_info_flush(local, NULL);
23847 +static int ieee80211_ioctl_add_sta(struct net_device *dev,
23848 + struct prism2_hostapd_param *param)
23850 + struct ieee80211_local *local = dev->priv;
23851 + struct sta_info *sta;
23854 + struct ieee80211_sub_if_data *sdata;
23855 + int add_key_entry = 1;
23857 + sta = sta_info_get(local, param->sta_addr);
23859 + if (sta == NULL) {
23860 + sta = sta_info_add(local, dev, param->sta_addr);
23865 + if (sta->dev != dev) {
23866 + /* Binding STA to a new interface, so remove all references to
23867 + * the old BSS. */
23868 + sta_info_remove_aid_ptr(sta);
23872 + * We "steal" the device in case someone owns it
23873 + * This will hurt WDS links and such when we have a
23874 + * WDS link and a client associating from the same station
23877 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
23879 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
23880 + sta->aid = param->u.add_sta.aid;
23881 + if (sta->aid > MAX_AID_TABLE_SIZE)
23883 + if (sta->aid > 0 && sdata->bss)
23884 + sdata->bss->sta_aid[sta->aid - 1] = sta;
23885 + if (sdata->bss && sta->aid > sdata->bss->max_aid)
23886 + sdata->bss->max_aid = sta->aid;
23889 + for (i = 0; i < sizeof(param->u.add_sta.supp_rates); i++) {
23890 + int rate = (param->u.add_sta.supp_rates[i] & 0x7f) * 5;
23891 + if (local->conf.phymode == MODE_ATHEROS_TURBO ||
23892 + local->conf.phymode == MODE_ATHEROS_TURBOG)
23894 + for (j = 0; j < local->num_curr_rates; j++) {
23895 + if (local->curr_rates[j].rate == rate)
23900 + sta->supp_rates = rates;
23902 + rate_control_rate_init(local, sta);
23904 + if (param->u.add_sta.wds_flags & 0x01)
23905 + sta->flags |= WLAN_STA_WDS;
23907 + sta->flags &= ~WLAN_STA_WDS;
23909 + if (add_key_entry && sta->key == NULL && sdata->default_key == NULL &&
23910 + local->hw->set_key) {
23911 + struct ieee80211_key_conf conf;
23912 + /* Add key cache entry with NULL key type because this may used
23913 + * for TX filtering. */
23914 + memset(&conf, 0, sizeof(conf));
23915 + conf.hw_key_idx = HW_KEY_IDX_INVALID;
23916 + conf.alg = ALG_NULL;
23917 + conf.force_sw_encrypt = 1;
23918 + if (local->hw->set_key(dev, SET_KEY, sta->addr, &conf,
23920 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
23922 + sta->key_idx_compression = conf.hw_key_idx;
23926 + sta_info_release(local, sta);
23932 +static int ieee80211_ioctl_remove_sta(struct net_device *dev,
23933 + struct prism2_hostapd_param *param)
23935 + struct ieee80211_local *local = dev->priv;
23936 + struct sta_info *sta;
23938 + sta = sta_info_get(local, param->sta_addr);
23940 + sta_info_release(local, sta);
23941 + sta_info_free(local, sta, 1);
23944 + return sta ? 0 : -ENOENT;
23948 +static int ieee80211_ioctl_get_dot11counterstable(struct net_device *dev,
23949 + struct prism2_hostapd_param *param)
23951 + struct ieee80211_local *local = dev->priv;
23952 + struct ieee80211_low_level_stats stats;
23954 + memset(&stats, 0, sizeof(stats));
23955 + if (local->hw->get_stats)
23956 + local->hw->get_stats(dev, &stats);
23957 + param->u.dot11CountersTable.dot11TransmittedFragmentCount =
23958 + local->dot11TransmittedFragmentCount;
23959 + param->u.dot11CountersTable.dot11MulticastTransmittedFrameCount =
23960 + local->dot11MulticastTransmittedFrameCount;
23961 + param->u.dot11CountersTable.dot11ReceivedFragmentCount =
23962 + local->dot11ReceivedFragmentCount;
23963 + param->u.dot11CountersTable.dot11MulticastReceivedFrameCount =
23964 + local->dot11MulticastReceivedFrameCount;
23965 + param->u.dot11CountersTable.dot11TransmittedFrameCount =
23966 + local->dot11TransmittedFrameCount;
23967 + param->u.dot11CountersTable.dot11FCSErrorCount =
23968 + stats.dot11FCSErrorCount;
23969 + param->u.dot11CountersTable.dot11ACKFailureCount =
23970 + stats.dot11ACKFailureCount;
23971 + param->u.dot11CountersTable.dot11RTSFailureCount =
23972 + stats.dot11RTSFailureCount;
23973 + param->u.dot11CountersTable.dot11RTSSuccessCount =
23974 + stats.dot11RTSSuccessCount;
23980 +static int ieee80211_ioctl_get_info_sta(struct net_device *dev,
23981 + struct prism2_hostapd_param *param)
23983 + struct ieee80211_local *local = dev->priv;
23984 + struct sta_info *sta;
23986 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
23987 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
23988 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
23989 + struct ieee80211_sub_if_data *sdata;
23990 + struct net_device_stats *stats;
23992 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23993 + stats = ieee80211_dev_stats(sdata->master);
23994 + param->u.get_info_sta.rx_bytes = stats->rx_bytes;
23995 + param->u.get_info_sta.tx_bytes = stats->tx_bytes;
23996 + /* go through all STAs and get STA with lowest max. rate */
23997 + param->u.get_info_sta.current_tx_rate =
23998 + local->curr_rates[sta_info_min_txrate_get(local)].rate;
24002 + sta = sta_info_get(local, param->sta_addr);
24007 + param->u.get_info_sta.inactive_msec =
24008 + jiffies_to_msecs(jiffies - sta->last_rx);
24009 + param->u.get_info_sta.rx_packets = sta->rx_packets;
24010 + param->u.get_info_sta.tx_packets = sta->tx_packets;
24011 + param->u.get_info_sta.rx_bytes = sta->rx_bytes;
24012 + param->u.get_info_sta.tx_bytes = sta->tx_bytes;
24013 + param->u.get_info_sta.channel_use = sta->channel_use;
24014 + param->u.get_info_sta.flags = sta->flags;
24015 + if (sta->txrate >= 0 && sta->txrate < local->num_curr_rates)
24016 + param->u.get_info_sta.current_tx_rate =
24017 + local->curr_rates[sta->txrate].rate;
24018 + param->u.get_info_sta.num_ps_buf_frames =
24019 + skb_queue_len(&sta->ps_tx_buf);
24020 + param->u.get_info_sta.tx_retry_failed = sta->tx_retry_failed;
24021 + param->u.get_info_sta.tx_retry_count = sta->tx_retry_count;
24022 + param->u.get_info_sta.last_rssi = sta->last_rssi;
24023 + param->u.get_info_sta.last_ack_rssi = sta->last_ack_rssi[2];
24025 + sta_info_release(local, sta);
24031 +static int ieee80211_ioctl_set_flags_sta(struct net_device *dev,
24032 + struct prism2_hostapd_param *param)
24034 + struct ieee80211_local *local = dev->priv;
24035 + struct sta_info *sta;
24037 + sta = sta_info_get(local, param->sta_addr);
24039 + sta->flags |= param->u.set_flags_sta.flags_or;
24040 + sta->flags &= param->u.set_flags_sta.flags_and;
24041 + if (local->hw->set_port_auth &&
24042 + (param->u.set_flags_sta.flags_or & WLAN_STA_AUTHORIZED) &&
24043 + local->hw->set_port_auth(local->mdev, sta->addr, 1))
24044 + printk(KERN_DEBUG "%s: failed to set low-level driver "
24045 + "PAE state (authorized) for " MACSTR "\n",
24046 + dev->name, MAC2STR(sta->addr));
24047 + if (local->hw->set_port_auth &&
24048 + !(param->u.set_flags_sta.flags_and & WLAN_STA_AUTHORIZED)
24049 + && local->hw->set_port_auth(local->mdev, sta->addr, 0))
24050 + printk(KERN_DEBUG "%s: failed to set low-level driver "
24051 + "PAE state (unauthorized) for " MACSTR "\n",
24052 + dev->name, MAC2STR(sta->addr));
24053 + sta_info_release(local, sta);
24056 + return sta ? 0 : -ENOENT;
24060 +int ieee80211_set_hw_encryption(struct net_device *dev,
24061 + struct sta_info *sta, u8 addr[ETH_ALEN],
24062 + struct ieee80211_key *key)
24064 + struct ieee80211_key_conf *keyconf = NULL;
24065 + struct ieee80211_local *local = dev->priv;
24068 + /* default to sw encryption; this will be cleared by low-level
24069 + * driver if the hw supports requested encryption */
24071 + key->force_sw_encrypt = 1;
24073 + if (key && local->hw->set_key &&
24074 + (!local->conf.sw_encrypt || !local->conf.sw_decrypt) &&
24075 + (keyconf = ieee80211_key_data2conf(local, key)) != NULL) {
24076 + if (local->hw->set_key(dev, SET_KEY, addr,
24077 + keyconf, sta ? sta->aid : 0)) {
24078 + rc = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24079 + key->force_sw_encrypt = 1;
24080 + key->hw_key_idx = HW_KEY_IDX_INVALID;
24082 + key->force_sw_encrypt =
24083 + keyconf->force_sw_encrypt;
24084 + key->hw_key_idx =
24085 + keyconf->hw_key_idx;
24095 +static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
24096 + int idx, int alg, int set_tx_key, int *err,
24097 + const u8 *_key, size_t key_len)
24099 + struct ieee80211_local *local = dev->priv;
24101 + struct sta_info *sta;
24102 + struct ieee80211_key **key;
24103 + int try_hwaccel = 1;
24104 + struct ieee80211_key_conf *keyconf;
24105 + struct ieee80211_sub_if_data *sdata;
24107 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24109 + if (sta_addr[0] == 0xff && sta_addr[1] == 0xff &&
24110 + sta_addr[2] == 0xff && sta_addr[3] == 0xff &&
24111 + sta_addr[4] == 0xff && sta_addr[5] == 0xff) {
24113 + if (idx >= NUM_DEFAULT_KEYS) {
24114 + printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
24118 + key = &sdata->keys[idx];
24120 + /* Disable hwaccel for default keys when the interface is not
24121 + * the default one.
24122 + * TODO: consider adding hwaccel support for these; at least
24123 + * Atheros key cache should be able to handle this since AP is
24124 + * only transmitting frames with default keys. */
24125 + /* FIX: hw key cache can be used when only one virtual
24126 + * STA is associated with each AP. If more than one STA
24127 + * is associated to the same AP, software encryption
24128 + * must be used. This should be done automatically
24129 + * based on configured station devices. For the time
24130 + * being, this can be only set at compile time. */
24131 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24132 + if (0 /* FIX: more than one STA per AP */)
24135 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP ||
24136 + dev != local->wdev)
24141 + printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
24142 + "individual key\n", dev->name);
24146 + sta = sta_info_get(local, sta_addr);
24147 + if (sta == NULL) {
24149 + *err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24150 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
24151 + printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
24153 + dev->name, MAC2STR(sta_addr));
24154 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
24163 + * Cannot configure default hwaccel keys with WEP algorithm, if
24164 + * any of the virtual interfaces is using static WEP
24165 + * configuration because hwaccel would otherwise try to decrypt
24168 + * For now, just disable WEP hwaccel for broadcast when there is
24169 + * possibility of conflict with default keys. This can maybe later be
24170 + * optimized by using non-default keys (at least with Atheros ar521x).
24172 + if (!sta && alg == ALG_WEP && !local->default_wep_only &&
24173 + local->conf.mode != IW_MODE_ADHOC &&
24174 + local->conf.mode != IW_MODE_INFRA) {
24178 + if (local->hw->device_hides_wep) {
24179 + /* Software encryption cannot be used with devices that hide
24180 + * encryption from the host system, so always try to use
24181 + * hardware acceleration with such devices. */
24185 + if (local->hw->no_tkip_wmm_hwaccel && alg == ALG_TKIP) {
24186 + if (sta && (sta->flags & WLAN_STA_WME)) {
24187 + /* Hardware does not support hwaccel with TKIP when using WMM.
24191 + else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24192 + sta = sta_info_get(local, sdata->u.sta.bssid);
24194 + if (sta->flags & WLAN_STA_WME) {
24197 + sta_info_release(local, sta);
24203 + if (alg == ALG_NONE) {
24205 + if (try_hwaccel && *key && local->hw->set_key &&
24206 + (keyconf = ieee80211_key_data2conf(local, *key)) != NULL &&
24207 + local->hw->set_key(dev, DISABLE_KEY, sta_addr,
24208 + keyconf, sta ? sta->aid : 0)) {
24210 + *err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24211 + printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
24212 + " failed\n", dev->name);
24217 + if (sdata->default_key == *key)
24218 + sdata->default_key = NULL;
24222 + if (*key == NULL || (*key)->keylen < key_len) {
24224 + *key = kmalloc(sizeof(struct ieee80211_key) +
24225 + key_len, GFP_ATOMIC);
24226 + if (*key == NULL) {
24231 + memset(*key, 0, sizeof(struct ieee80211_key) + key_len);
24232 + /* default to sw encryption; low-level driver sets these if the
24233 + * requested encryption is supported */
24234 + (*key)->hw_key_idx = HW_KEY_IDX_INVALID;
24235 + (*key)->force_sw_encrypt = 1;
24237 + (*key)->alg = alg;
24238 + (*key)->keyidx = idx;
24239 + (*key)->keylen = key_len;
24240 + memcpy((*key)->key, _key, key_len);
24242 + (*key)->default_tx_key = 1;
24244 + if (alg == ALG_CCMP) {
24245 + /* Initialize AES key state here as an optimization
24246 + * so that it does not need to be initialized for every
24248 + ieee80211_aes_key_setup_encrypt(
24249 + (*key)->u.ccmp.aes_state, (*key)->key);
24252 + if (try_hwaccel &&
24253 + (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP)) {
24254 + int e = ieee80211_set_hw_encryption(dev, sta, sta_addr,
24261 + if (set_tx_key || (sta == NULL && sdata->default_key == NULL)) {
24262 + sdata->default_key = *key;
24263 + if (local->hw->set_key_idx &&
24264 + local->hw->set_key_idx(dev, idx))
24265 + printk(KERN_DEBUG "%s: failed to set TX key idx for "
24266 + "low-level driver\n", dev->name);
24271 + sta_info_release(local, sta);
24277 +static int ieee80211_ioctl_set_encryption(struct net_device *dev,
24278 + struct prism2_hostapd_param *param,
24283 + param->u.crypt.err = 0;
24284 + param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
24287 + (int) ((char *) param->u.crypt.key - (char *) param) +
24288 + param->u.crypt.key_len) {
24289 + printk(KERN_DEBUG "%s: set_encrypt - invalid param_lem\n",
24294 + if (strcmp(param->u.crypt.alg, "none") == 0)
24296 + else if (strcmp(param->u.crypt.alg, "WEP") == 0)
24298 + else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
24299 + if (param->u.crypt.key_len != ALG_TKIP_KEY_LEN) {
24300 + printk(KERN_DEBUG "%s: set_encrypt - invalid TKIP key "
24301 + "length %d\n", dev->name,
24302 + param->u.crypt.key_len);
24306 + } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
24307 + if (param->u.crypt.key_len != ALG_CCMP_KEY_LEN) {
24308 + printk(KERN_DEBUG "%s: set_encrypt - invalid CCMP key "
24309 + "length %d\n", dev->name,
24310 + param->u.crypt.key_len);
24315 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
24316 + printk(KERN_DEBUG "%s: set_encrypt - unknown alg\n",
24321 + return ieee80211_set_encryption(
24322 + dev, param->sta_addr,
24323 + param->u.crypt.idx, alg,
24324 + param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY,
24325 + ¶m->u.crypt.err, param->u.crypt.key,
24326 + param->u.crypt.key_len);
24330 +static int ieee80211_ioctl_get_encryption(struct net_device *dev,
24331 + struct prism2_hostapd_param *param,
24334 + struct ieee80211_local *local = dev->priv;
24336 + struct sta_info *sta;
24337 + struct ieee80211_key **key;
24339 + struct ieee80211_sub_if_data *sdata;
24342 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24344 + param->u.crypt.err = 0;
24346 + max_key_len = param_len -
24347 + (int) ((char *) param->u.crypt.key - (char *) param);
24348 + if (max_key_len < 0)
24351 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
24352 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
24353 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
24355 + if (param->u.crypt.idx > NUM_DEFAULT_KEYS) {
24356 + param->u.crypt.idx = sdata->default_key ?
24357 + sdata->default_key->keyidx : 0;
24360 + key = &sdata->keys[param->u.crypt.idx];
24362 + sta = sta_info_get(local, param->sta_addr);
24363 + if (sta == NULL) {
24364 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24371 + memset(param->u.crypt.seq_counter, 0, HOSTAP_SEQ_COUNTER_SIZE);
24372 + if (*key == NULL) {
24373 + memcpy(param->u.crypt.alg, "none", 5);
24374 + param->u.crypt.key_len = 0;
24375 + param->u.crypt.idx = 0xff;
24377 + switch ((*key)->alg) {
24379 + memcpy(param->u.crypt.alg, "WEP", 4);
24386 + memcpy(param->u.crypt.alg, "TKIP", 5);
24387 + if (local->hw->get_sequence_counter) {
24388 + /* Get transmit counter from low level driver */
24389 + if (local->hw->get_sequence_counter(dev,
24392 + IEEE80211_SEQ_COUNTER_TX,
24395 + /* Error getting value from device */
24399 + /* Get it from our own local data */
24400 + iv32 = (*key)->u.tkip.iv32;
24401 + iv16 = (*key)->u.tkip.iv16;
24403 + pos = param->u.crypt.seq_counter;
24404 + *pos++ = iv16 & 0xff;
24405 + *pos++ = (iv16 >> 8) & 0xff;
24406 + *pos++ = iv32 & 0xff;
24407 + *pos++ = (iv32 >> 8) & 0xff;
24408 + *pos++ = (iv32 >> 16) & 0xff;
24409 + *pos++ = (iv32 >> 24) & 0xff;
24415 + memcpy(param->u.crypt.alg, "CCMP", 5);
24416 + pos = param->u.crypt.seq_counter;
24417 + pn = (*key)->u.ccmp.tx_pn;
24427 + memcpy(param->u.crypt.alg, "unknown", 8);
24431 + if (max_key_len < (*key)->keylen)
24434 + param->u.crypt.key_len = (*key)->keylen;
24435 + memcpy(param->u.crypt.key, (*key)->key,
24441 + sta_info_release(local, sta);
24447 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24448 +static int ieee80211_ioctl_wpa_trigger(struct net_device *dev,
24449 + struct prism2_hostapd_param *param)
24451 + struct ieee80211_local *local = dev->priv;
24452 + struct sta_info *sta;
24454 + if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
24455 + param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
24456 + param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
24457 + local->wpa_trigger = param->u.wpa_trigger.trigger;
24461 + sta = sta_info_get(local, param->sta_addr);
24462 + if (sta == NULL) {
24463 + printk(KERN_DEBUG "%s: wpa_trigger - unknown addr\n",
24468 + sta->wpa_trigger = param->u.wpa_trigger.trigger;
24470 + sta_info_release(local, sta);
24473 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24476 +static int ieee80211_ioctl_set_rate_sets(struct net_device *dev,
24477 + struct prism2_hostapd_param *param,
24480 + struct ieee80211_local *local = dev->priv;
24481 + u16 *pos = (u16 *) param->u.set_rate_sets.data;
24482 + int left = param_len - ((u8 *) pos - (u8 *) param);
24483 + int i, mode, num_supp, num_basic, *supp, *basic, *prev;
24485 + mode = param->u.set_rate_sets.mode;
24486 + num_supp = param->u.set_rate_sets.num_supported_rates;
24487 + num_basic = param->u.set_rate_sets.num_basic_rates;
24489 + if (left < (num_supp + num_basic) * 2) {
24490 + printk(KERN_WARNING "%s: invalid length in hostapd set rate "
24491 + "sets ioctl (%d != %d)\n", dev->name, left,
24492 + (num_supp + num_basic) * 2);
24496 + supp = (int *) kmalloc((num_supp + 1) * sizeof(int), GFP_KERNEL);
24497 + basic = (int *) kmalloc((num_basic + 1) * sizeof(int), GFP_KERNEL);
24499 + if (!supp || !basic) {
24505 + for (i = 0; i < num_supp; i++)
24506 + supp[i] = *pos++;
24509 + for (i = 0; i < num_basic; i++)
24510 + basic[i] = *pos++;
24513 + if (num_supp == 0) {
24518 + if (num_basic == 0) {
24523 + prev = local->supp_rates[mode];
24524 + local->supp_rates[mode] = supp;
24527 + prev = local->basic_rates[mode];
24528 + local->basic_rates[mode] = basic;
24531 + if (mode == local->conf.phymode) {
24532 + /* TODO: should update STA TX rates and remove STAs if they
24533 + * do not have any remaining supported rates after the change
24535 + ieee80211_prepare_rates(dev);
24542 +static int ieee80211_ioctl_add_if(struct net_device *dev,
24543 + struct prism2_hostapd_param *param,
24546 + u8 *pos = param->u.if_info.data;
24547 + int left = param_len - ((u8 *) pos - (u8 *) param);
24549 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24550 + struct ieee80211_if_wds iwds;
24551 + struct hostapd_if_wds *wds =
24552 + (struct hostapd_if_wds *) param->u.if_info.data;
24554 + if (left < sizeof(struct ieee80211_if_wds))
24557 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24559 + return ieee80211_if_add_wds(dev, param->u.if_info.name,
24561 + } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
24562 + struct hostapd_if_vlan *vlan = (struct hostapd_if_vlan *) pos;
24563 + struct ieee80211_if_vlan ivlan;
24565 + if (left < sizeof(struct hostapd_if_vlan))
24568 + ivlan.id = vlan->id;
24570 + return ieee80211_if_add_vlan(dev, param->u.if_info.name,
24572 + } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
24573 + struct hostapd_if_bss *bss =
24574 + (struct hostapd_if_bss *) param->u.if_info.data;
24576 + if (left < sizeof(struct hostapd_if_bss))
24579 + return ieee80211_if_add_ap(dev, param->u.if_info.name,
24581 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24583 + struct hostapd_if_sta *sta =
24584 + (struct hostapd_if_sta *) param->u.if_info.data;
24587 + if (left < sizeof(struct hostapd_if_sta))
24590 + return ieee80211_if_add_sta(dev, param->u.if_info.name, 1);
24598 +static int ieee80211_ioctl_remove_if(struct net_device *dev,
24599 + struct prism2_hostapd_param *param)
24601 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24602 + return ieee80211_if_remove_wds(dev, param->u.if_info.name, 1);
24603 + } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
24604 + return ieee80211_if_remove_vlan(dev, param->u.if_info.name, 1);
24605 + } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
24606 + return ieee80211_if_remove_ap(dev, param->u.if_info.name, 1);
24607 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24608 + return ieee80211_if_remove_sta(dev, param->u.if_info.name, 1);
24615 +static int ieee80211_ioctl_update_if(struct net_device *dev,
24616 + struct prism2_hostapd_param *param,
24619 + u8 *pos = param->u.if_info.data;
24620 + int left = param_len - ((u8 *) pos - (u8 *) param);
24622 + if (param->u.if_info.type == HOSTAP_IF_WDS) {
24623 + struct ieee80211_if_wds iwds;
24624 + struct hostapd_if_wds *wds =
24625 + (struct hostapd_if_wds *) param->u.if_info.data;
24627 + if (left < sizeof(struct ieee80211_if_wds))
24630 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24632 + return ieee80211_if_update_wds(dev, param->u.if_info.name,
24635 + return -EOPNOTSUPP;
24640 +static int ieee80211_ioctl_flush_ifs(struct net_device *dev,
24641 + struct prism2_hostapd_param *param)
24643 + return ieee80211_if_flush(dev, 1);
24647 +static int ieee80211_ioctl_scan_req(struct net_device *dev,
24648 + struct prism2_hostapd_param *param,
24651 + u8 *pos = param->u.scan_req.ssid;
24652 + int left = param_len - ((u8 *) pos - (u8 *) param);
24653 + int len = param->u.scan_req.ssid_len;
24655 + if (left < len || len > IEEE80211_MAX_SSID_LEN)
24658 + return ieee80211_sta_req_scan(dev, pos, len);
24662 +static int ieee80211_ioctl_sta_get_state(struct net_device *dev,
24663 + struct prism2_hostapd_param *param)
24665 + struct ieee80211_sub_if_data *sdata;
24667 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24668 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24670 + param->u.sta_get_state.state = sdata->u.sta.state;
24675 +static int ieee80211_ioctl_mlme(struct net_device *dev,
24676 + struct prism2_hostapd_param *param)
24678 + struct ieee80211_sub_if_data *sdata;
24680 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24681 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24683 + switch (param->u.mlme.cmd) {
24684 + case MLME_STA_DEAUTH:
24685 + ieee80211_sta_deauthenticate(dev, param->u.mlme.reason_code);
24687 + case MLME_STA_DISASSOC:
24688 + ieee80211_sta_disassociate(dev, param->u.mlme.reason_code);
24695 +static int ieee80211_ioctl_get_load_stats(struct net_device *dev,
24696 + struct prism2_hostapd_param *param)
24698 + struct ieee80211_local *local = dev->priv;
24700 + param->u.get_load_stats.channel_use = local->channel_use;
24701 +/* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
24702 + local->channel_use = 0; */ /* now it's not raw counter */
24708 +static int ieee80211_ioctl_set_sta_vlan(struct net_device *dev,
24709 + struct prism2_hostapd_param *param)
24711 + struct ieee80211_local *local = dev->priv;
24712 + struct sta_info *sta;
24714 + sta = sta_info_get(local, param->sta_addr);
24716 + struct net_device *new_vlan_dev;
24718 + dev_get_by_name(param->u.set_sta_vlan.vlan_name);
24719 + if (new_vlan_dev) {
24721 + printk("%s: Station " MACSTR " moved to vlan: %s\n",
24722 + dev->name, MAC2STR(param->sta_addr),
24723 + new_vlan_dev->name);
24725 + sta->dev = new_vlan_dev;
24726 + sta->vlan_id = param->u.set_sta_vlan.vlan_id;
24727 + dev_put(new_vlan_dev);
24729 + sta_info_release(local, sta);
24732 + return sta ? 0 : -ENOENT;
24736 +static int ieee80211_set_gen_ie(struct net_device *dev, u8 *ie, size_t len)
24738 + struct ieee80211_local *local = dev->priv;
24739 + struct ieee80211_sub_if_data *sdata;
24741 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24742 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
24743 + return ieee80211_sta_set_extra_ie(dev, ie, len);
24745 + kfree(local->conf.generic_elem);
24746 + local->conf.generic_elem = kmalloc(len, GFP_KERNEL);
24747 + if (local->conf.generic_elem == NULL)
24749 + memcpy(local->conf.generic_elem, ie, len);
24750 + local->conf.generic_elem_len = len;
24752 + return ieee80211_hw_config(dev);
24757 +ieee80211_ioctl_set_generic_info_elem(struct net_device *dev,
24758 + struct prism2_hostapd_param *param,
24761 + u8 *pos = param->u.set_generic_info_elem.data;
24762 + int left = param_len - ((u8 *) pos - (u8 *) param);
24763 + int len = param->u.set_generic_info_elem.len;
24768 + return ieee80211_set_gen_ie(dev, pos, len);
24772 +static int ieee80211_ioctl_set_regulatory_domain(struct net_device *dev,
24773 + struct prism2_hostapd_param *param)
24775 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24776 + conf->regulatory_domain = param->u.set_regulatory_domain.rd;
24781 +static int ieee80211_ioctl_set_adm_status(struct net_device *dev,
24784 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24785 + conf->adm_status = val;
24786 + return ieee80211_hw_config(dev);
24790 +ieee80211_ioctl_set_tx_queue_params(struct net_device *dev,
24791 + struct prism2_hostapd_param *param)
24793 + struct ieee80211_local *local = dev->priv;
24794 + struct ieee80211_tx_queue_params qparam;
24796 + if (!local->hw->conf_tx) {
24797 + printk(KERN_DEBUG "%s: low-level driver does not support TX "
24798 + "queue configuration\n", dev->name);
24799 + return -EOPNOTSUPP;
24802 + memset(&qparam, 0, sizeof(qparam));
24803 + qparam.aifs = param->u.tx_queue_params.aifs;
24804 + qparam.cw_min = param->u.tx_queue_params.cw_min;
24805 + qparam.cw_max = param->u.tx_queue_params.cw_max;
24806 + qparam.burst_time = param->u.tx_queue_params.burst_time;
24808 + return local->hw->conf_tx(dev, param->u.tx_queue_params.queue,
24813 +static int ieee80211_ioctl_get_tx_stats(struct net_device *dev,
24814 + struct prism2_hostapd_param *param)
24816 + struct ieee80211_local *local = dev->priv;
24817 + struct ieee80211_tx_queue_stats stats;
24820 + if (!local->hw->get_tx_stats)
24821 + return -EOPNOTSUPP;
24823 + memset(&stats, 0, sizeof(stats));
24824 + ret = local->hw->get_tx_stats(dev, &stats);
24828 + for (i = 0; i < 4; i++) {
24829 + param->u.get_tx_stats.data[i].len = stats.data[i].len;
24830 + param->u.get_tx_stats.data[i].limit = stats.data[i].limit;
24831 + param->u.get_tx_stats.data[i].count = stats.data[i].count;
24838 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
24841 + struct ieee80211_local *local = dev->priv;
24842 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24843 + int i, bss_count;
24844 + struct net_device **bss_devs, **prev;
24845 + struct net_device **sta_devs, **prev_sta_devs;
24848 + for (i = 0; i < conf->bss_count; i++) {
24849 + if (local->bss_devs[i])
24853 + if (new_count < bss_count) {
24854 + printk(KERN_DEBUG "%s: invalid BSS count %d (in use: %d)\n",
24855 + dev->name, new_count, bss_count);
24859 + bss_devs = kmalloc(new_count * sizeof(struct net_device *),
24861 + if (bss_devs == NULL)
24863 + sta_devs = kmalloc(new_count * sizeof(struct net_device *),
24865 + if (sta_devs == NULL) {
24870 + spin_lock_bh(&local->sub_if_lock);
24871 + memcpy(bss_devs, local->bss_devs,
24872 + bss_count * sizeof(struct net_device *));
24873 + memset(&bss_devs[bss_count], 0,
24874 + (new_count - bss_count) * sizeof(struct net_device *));
24877 + memcpy(conf->bssid_mask, bssid_mask, ETH_ALEN);
24879 + prev = local->bss_devs;
24880 + local->bss_devs = bss_devs;
24881 + conf->bss_count = new_count;
24883 + memcpy(sta_devs, local->sta_devs,
24884 + bss_count * sizeof(struct net_device *));
24885 + memset(&sta_devs[bss_count], 0,
24886 + (new_count - bss_count) * sizeof(struct net_device *));
24887 + prev_sta_devs = local->sta_devs;
24888 + local->sta_devs = sta_devs;
24890 + spin_unlock_bh(&local->sub_if_lock);
24892 + kfree(prev_sta_devs);
24894 + return ieee80211_hw_config(dev);
24897 +static int ieee80211_ioctl_set_bss(struct net_device *dev,
24898 + struct prism2_hostapd_param *param)
24900 + return ieee80211_set_bss_count(dev, param->u.set_bss.bss_count,
24901 + param->u.set_bss.bssid_mask);
24905 +static int ieee80211_ioctl_set_channel_flag(struct net_device *dev,
24906 + struct prism2_hostapd_param *param)
24908 + struct ieee80211_local *local = dev->priv;
24909 + struct ieee80211_hw_modes *mode = NULL;
24910 + struct ieee80211_channel *chan = NULL;
24913 + for (i = 0; i < local->hw->num_modes; i++) {
24914 + mode = &local->hw->modes[i];
24915 + if (mode->mode == param->u.set_channel_flag.mode)
24923 + for (i = 0; i < mode->num_channels; i++) {
24924 + chan = &mode->channels[i];
24925 + if (chan->chan == param->u.set_channel_flag.chan)
24933 + chan->flag = param->u.set_channel_flag.flag;
24934 + chan->power_level = param->u.set_channel_flag.power_level;
24935 + chan->antenna_max = param->u.set_channel_flag.antenna_max;
24941 +static int ieee80211_ioctl_set_quiet_params(struct net_device *dev,
24942 + struct prism2_hostapd_param *param)
24944 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24945 + conf->quiet_duration = param->u.quiet.duration;
24946 + conf->quiet_offset = param->u.quiet.offset;
24947 + conf->quiet_period = param->u.quiet.period;
24952 +static int ieee80211_ioctl_set_radar_params(struct net_device *dev,
24953 + struct prism2_hostapd_param *param)
24955 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24956 + conf->radar_firpwr_threshold = param->u.radar.radar_firpwr_threshold;
24957 + conf->radar_rssi_threshold = param->u.radar.radar_rssi_threshold;
24958 + conf->pulse_height_threshold = param->u.radar.pulse_height_threshold;
24959 + conf->pulse_rssi_threshold = param->u.radar.pulse_rssi_threshold;
24960 + conf->pulse_inband_threshold = param->u.radar.pulse_inband_threshold;
24965 +static int ieee80211_ioctl_priv_hostapd(struct net_device *dev,
24966 + struct iw_point *p)
24968 + struct prism2_hostapd_param *param;
24971 + if (p->length < sizeof(struct prism2_hostapd_param) ||
24972 + p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) {
24973 + printk(KERN_DEBUG "%s: hostapd ioctl: ptr=%p len=%d min=%d "
24974 + "max=%d\n", dev->name, p->pointer, p->length,
24975 + (int)sizeof(struct prism2_hostapd_param),
24976 + PRISM2_HOSTAPD_MAX_BUF_SIZE);
24980 + param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
24981 + if (param == NULL)
24984 + if (copy_from_user(param, p->pointer, p->length)) {
24989 + switch (param->cmd) {
24990 + case PRISM2_HOSTAPD_FLUSH:
24991 + ret = ieee80211_ioctl_flush(dev, param);
24993 + case PRISM2_HOSTAPD_ADD_STA:
24994 + ret = ieee80211_ioctl_add_sta(dev, param);
24996 + case PRISM2_HOSTAPD_REMOVE_STA:
24997 + ret = ieee80211_ioctl_remove_sta(dev, param);
24999 + case PRISM2_HOSTAPD_GET_INFO_STA:
25000 + ret = ieee80211_ioctl_get_info_sta(dev, param);
25002 + case PRISM2_SET_ENCRYPTION:
25003 + ret = ieee80211_ioctl_set_encryption(dev, param, p->length);
25005 + case PRISM2_GET_ENCRYPTION:
25006 + ret = ieee80211_ioctl_get_encryption(dev, param, p->length);
25008 + case PRISM2_HOSTAPD_SET_FLAGS_STA:
25009 + ret = ieee80211_ioctl_set_flags_sta(dev, param);
25011 + case PRISM2_HOSTAPD_SET_BEACON:
25012 + ret = ieee80211_ioctl_set_beacon(dev, param, p->length, 0);
25014 + case PRISM2_HOSTAPD_GET_HW_FEATURES:
25015 + ret = ieee80211_ioctl_get_hw_features(dev, param, p->length);
25017 + case PRISM2_HOSTAPD_SCAN:
25018 + ret = ieee80211_ioctl_scan(dev, param);
25020 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
25021 + case PRISM2_HOSTAPD_WPA_TRIGGER:
25022 + ret = ieee80211_ioctl_wpa_trigger(dev, param);
25024 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
25025 + case PRISM2_HOSTAPD_SET_RATE_SETS:
25026 + ret = ieee80211_ioctl_set_rate_sets(dev, param, p->length);
25028 + case PRISM2_HOSTAPD_ADD_IF:
25029 + ret = ieee80211_ioctl_add_if(dev, param, p->length);
25031 + case PRISM2_HOSTAPD_REMOVE_IF:
25032 + ret = ieee80211_ioctl_remove_if(dev, param);
25034 + case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE:
25035 + ret = ieee80211_ioctl_get_dot11counterstable(dev, param);
25037 + case PRISM2_HOSTAPD_GET_LOAD_STATS:
25038 + ret = ieee80211_ioctl_get_load_stats(dev, param);
25040 + case PRISM2_HOSTAPD_SET_STA_VLAN:
25041 + ret = ieee80211_ioctl_set_sta_vlan(dev, param);
25043 + case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM:
25044 + ret = ieee80211_ioctl_set_generic_info_elem(dev, param,
25047 + case PRISM2_HOSTAPD_SET_CHANNEL_FLAG:
25048 + ret = ieee80211_ioctl_set_channel_flag(dev, param);
25050 + case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN:
25051 + ret = ieee80211_ioctl_set_regulatory_domain(dev, param);
25053 + case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS:
25054 + ret = ieee80211_ioctl_set_tx_queue_params(dev, param);
25056 + case PRISM2_HOSTAPD_SET_BSS:
25057 + ret = ieee80211_ioctl_set_bss(dev, param);
25059 + case PRISM2_HOSTAPD_GET_TX_STATS:
25060 + ret = ieee80211_ioctl_get_tx_stats(dev, param);
25062 + case PRISM2_HOSTAPD_UPDATE_IF:
25063 + ret = ieee80211_ioctl_update_if(dev, param, p->length);
25065 + case PRISM2_HOSTAPD_SCAN_REQ:
25066 + ret = ieee80211_ioctl_scan_req(dev, param, p->length);
25068 + case PRISM2_STA_GET_STATE:
25069 + ret = ieee80211_ioctl_sta_get_state(dev, param);
25071 + case PRISM2_HOSTAPD_MLME:
25072 + ret = ieee80211_ioctl_mlme(dev, param);
25074 + case PRISM2_HOSTAPD_FLUSH_IFS:
25075 + ret = ieee80211_ioctl_flush_ifs(dev, param);
25077 + case PRISM2_HOSTAPD_SET_RADAR_PARAMS:
25078 + ret = ieee80211_ioctl_set_radar_params(dev, param);
25080 + case PRISM2_HOSTAPD_SET_QUIET_PARAMS:
25081 + ret = ieee80211_ioctl_set_quiet_params(dev, param);
25084 + ret = -EOPNOTSUPP;
25088 + if (copy_to_user(p->pointer, param, p->length))
25098 +static int ieee80211_ioctl_giwname(struct net_device *dev,
25099 + struct iw_request_info *info,
25100 + char *name, char *extra)
25102 + struct ieee80211_local *local = dev->priv;
25104 + switch (local->conf.phymode) {
25105 + case MODE_IEEE80211A:
25106 + strcpy(name, "IEEE 802.11a");
25108 + case MODE_IEEE80211B:
25109 + strcpy(name, "IEEE 802.11b");
25111 + case MODE_IEEE80211G:
25112 + strcpy(name, "IEEE 802.11g");
25114 + case MODE_ATHEROS_TURBO:
25115 + strcpy(name, "5GHz Turbo");
25118 + strcpy(name, "IEEE 802.11");
25126 +static int ieee80211_ioctl_giwrange(struct net_device *dev,
25127 + struct iw_request_info *info,
25128 + struct iw_point *data, char *extra)
25130 + struct iw_range *range = (struct iw_range *) extra;
25132 + data->length = sizeof(struct iw_range);
25133 + memset(range, 0, sizeof(struct iw_range));
25135 + range->we_version_compiled = WIRELESS_EXT;
25136 + range->we_version_source = 14;
25137 + range->retry_capa = IW_RETRY_LIMIT;
25138 + range->retry_flags = IW_RETRY_LIMIT;
25139 + range->min_retry = 0;
25140 + range->max_retry = 255;
25141 + range->min_rts = 0;
25142 + range->max_rts = 2347;
25143 + range->min_frag = 256;
25144 + range->max_frag = 2346;
25150 +struct ieee80211_channel_range {
25151 + short start_freq;
25153 + unsigned char power_level;
25154 + unsigned char antenna_max;
25157 +static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
25158 + { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
25159 + { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
25160 + { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
25161 + { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
25165 +static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
25166 + { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
25167 + { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
25168 + { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
25173 +static const struct ieee80211_channel_range *channel_range =
25174 + ieee80211_fcc_channels;
25177 +static void ieee80211_unmask_channel(struct net_device *dev, int mode,
25178 + struct ieee80211_channel *chan)
25184 + if (ieee80211_regdom == 64 &&
25185 + (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
25186 + /* Do not allow Turbo modes in Japan. */
25190 + for (i = 0; channel_range[i].start_freq; i++) {
25191 + const struct ieee80211_channel_range *r = &channel_range[i];
25192 + if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
25193 + if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
25194 + chan->freq >= 5260 && chan->freq <= 5320) {
25196 + * Skip new channels in Japan since the
25197 + * firmware was not marked having been upgraded
25203 + if (ieee80211_regdom == 0x10 &&
25204 + (chan->freq == 5190 || chan->freq == 5210 ||
25205 + chan->freq == 5230)) {
25206 + /* Skip MKK channels when in FCC domain. */
25210 + chan->flag |= IEEE80211_CHAN_W_SCAN |
25211 + IEEE80211_CHAN_W_ACTIVE_SCAN |
25212 + IEEE80211_CHAN_W_IBSS;
25213 + chan->power_level = r->power_level;
25214 + chan->antenna_max = r->antenna_max;
25216 + if (ieee80211_regdom == 64 &&
25217 + (chan->freq == 5170 || chan->freq == 5190 ||
25218 + chan->freq == 5210 || chan->freq == 5230)) {
25220 + * New regulatory rules in Japan have backwards
25221 + * compatibility with old channels in 5.15-5.25
25222 + * GHz band, but the station is not allowed to
25223 + * use active scan on these old channels.
25225 + chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
25228 + if (ieee80211_regdom == 64 &&
25229 + (chan->freq == 5260 || chan->freq == 5280 ||
25230 + chan->freq == 5300 || chan->freq == 5320)) {
25232 + * IBSS is not allowed on 5.25-5.35 GHz band
25233 + * due to radar detection requirements.
25235 + chan->flag &= ~IEEE80211_CHAN_W_IBSS;
25244 +static int ieee80211_unmask_channels(struct net_device *dev)
25246 + struct ieee80211_local *local = dev->priv;
25249 + for (m = 0; m < local->hw->num_modes; m++) {
25250 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25251 + for (c = 0; c < mode->num_channels; c++) {
25252 + ieee80211_unmask_channel(dev, mode->mode,
25253 + &mode->channels[c]);
25260 +static int ieee80211_init_client(struct net_device *dev)
25262 + if (ieee80211_regdom == 0x40)
25263 + channel_range = ieee80211_mkk_channels;
25264 + ieee80211_unmask_channels(dev);
25265 + ieee80211_ioctl_set_adm_status(dev, 1);
25270 +static int ieee80211_is_client_mode(int iw_mode)
25272 + return (iw_mode == IW_MODE_INFRA || iw_mode == IW_MODE_ADHOC);
25276 +static int ieee80211_ioctl_siwmode(struct net_device *dev,
25277 + struct iw_request_info *info,
25278 + __u32 *mode, char *extra)
25280 + struct ieee80211_local *local = dev->priv;
25282 + if (!ieee80211_is_client_mode(local->conf.mode) &&
25283 + ieee80211_is_client_mode(*mode)) {
25284 + ieee80211_init_client(dev);
25286 + if (local->conf.mode != *mode) {
25287 + struct ieee80211_sub_if_data *sdata =
25288 + IEEE80211_DEV_TO_SUB_IF(dev);
25289 + sta_info_flush(local, NULL);
25290 + if (local->conf.mode == IW_MODE_ADHOC &&
25291 + sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25292 + /* Clear drop_unencrypted when leaving adhoc mode since
25293 + * only adhoc mode is using automatic setting for this
25295 + sdata->drop_unencrypted = 0;
25297 + if (*mode == IW_MODE_MASTER) {
25298 + /* AP mode does not currently use ACM bits to limit
25299 + * TX, so clear the bitfield here. */
25300 + local->wmm_acm = 0;
25303 + local->conf.mode = *mode;
25304 + return ieee80211_hw_config(dev);
25308 +static int ieee80211_ioctl_giwmode(struct net_device *dev,
25309 + struct iw_request_info *info,
25310 + __u32 *mode, char *extra)
25312 + struct ieee80211_local *local = dev->priv;
25313 + struct ieee80211_sub_if_data *sdata;
25315 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25316 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25317 + if (local->conf.mode == IW_MODE_ADHOC)
25318 + *mode = IW_MODE_ADHOC;
25320 + *mode = IW_MODE_INFRA;
25322 + *mode = local->conf.mode;
25327 +int ieee80211_ioctl_siwfreq(struct net_device *dev,
25328 + struct iw_request_info *info,
25329 + struct iw_freq *freq, char *extra)
25331 + struct ieee80211_local *local = dev->priv;
25332 + int m, c, nfreq, set = 0;
25334 + /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
25335 + if (freq->e == 0)
25338 + int i, div = 1000000;
25339 + for (i = 0; i < freq->e; i++)
25342 + nfreq = freq->m / div;
25347 + for (m = 0; m < local->hw->num_modes; m++) {
25348 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25349 + for (c = 0; c < mode->num_channels; c++) {
25350 + struct ieee80211_channel *chan = &mode->channels[c];
25351 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
25352 + ((freq->e == 0 && chan->chan == freq->m) ||
25353 + (freq->e > 0 && nfreq == chan->freq)) &&
25354 + (local->hw_modes & (1 << mode->mode))) {
25355 + /* Use next_mode as the mode preference to
25356 + * resolve non-unique channel numbers. */
25357 + if (set && mode->mode != local->next_mode)
25360 + local->conf.channel = chan->chan;
25361 + local->conf.channel_val = chan->val;
25362 + local->conf.power_level = chan->power_level;
25363 + local->conf.freq = chan->freq;
25364 + local->conf.phymode = mode->mode;
25365 + local->conf.antenna_max = chan->antenna_max;
25372 + local->sta_scanning = 0; /* Abort possible scan */
25373 + return ieee80211_hw_config(dev);
25380 +static int ieee80211_ioctl_giwfreq(struct net_device *dev,
25381 + struct iw_request_info *info,
25382 + struct iw_freq *freq, char *extra)
25384 + struct ieee80211_local *local = dev->priv;
25386 + /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
25387 + * driver for the current channel with firmware-based management */
25389 + freq->m = local->conf.freq;
25396 +static int ieee80211_ioctl_siwessid(struct net_device *dev,
25397 + struct iw_request_info *info,
25398 + struct iw_point *data, char *ssid)
25400 + struct ieee80211_local *local = dev->priv;
25401 + struct ieee80211_sub_if_data *sdata;
25402 + size_t len = data->length;
25404 + /* iwconfig uses nul termination in SSID.. */
25405 + if (len > 0 && ssid[len - 1] == '\0')
25408 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25409 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
25410 + return ieee80211_sta_set_ssid(dev, ssid, len);
25412 + kfree(local->conf.ssid);
25413 + local->conf.ssid = kmalloc(len + 1, GFP_KERNEL);
25414 + if (local->conf.ssid == NULL)
25416 + memcpy(local->conf.ssid, ssid, len);
25417 + local->conf.ssid[len] = '\0';
25418 + local->conf.ssid_len = len;
25419 + return ieee80211_hw_config(dev);
25423 +static int ieee80211_ioctl_giwessid(struct net_device *dev,
25424 + struct iw_request_info *info,
25425 + struct iw_point *data, char *ssid)
25427 + struct ieee80211_local *local = dev->priv;
25430 + struct ieee80211_sub_if_data *sdata;
25431 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25432 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25433 + int res = ieee80211_sta_get_ssid(dev, ssid, &len);
25435 + data->length = len;
25439 + len = local->conf.ssid_len;
25440 + if (len > IW_ESSID_MAX_SIZE)
25441 + len = IW_ESSID_MAX_SIZE;
25442 + memcpy(ssid, local->conf.ssid, len);
25443 + data->length = len;
25448 +static int ieee80211_ioctl_siwap(struct net_device *dev,
25449 + struct iw_request_info *info,
25450 + struct sockaddr *ap_addr, char *extra)
25452 + struct ieee80211_local *local = dev->priv;
25453 + struct ieee80211_sub_if_data *sdata;
25455 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25456 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25457 + int changed_bssid = 0;
25458 + if (memcmp(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
25460 + changed_bssid = 1;
25461 + memcpy(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
25463 + if (changed_bssid && ieee80211_hw_config(dev)) {
25464 + printk(KERN_DEBUG "%s: Failed to config new BSSID to "
25465 + "the low-level driver\n", dev->name);
25467 + return ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
25470 + return -EOPNOTSUPP;
25474 +static int ieee80211_ioctl_giwap(struct net_device *dev,
25475 + struct iw_request_info *info,
25476 + struct sockaddr *ap_addr, char *extra)
25478 + struct ieee80211_sub_if_data *sdata;
25480 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25481 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25482 + ap_addr->sa_family = ARPHRD_ETHER;
25483 + memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
25487 + return -EOPNOTSUPP;
25491 +static int ieee80211_ioctl_siwscan(struct net_device *dev,
25492 + struct iw_request_info *info,
25493 + struct iw_point *data, char *extra)
25495 + struct ieee80211_local *local = dev->priv;
25497 + size_t ssid_len = 0;
25499 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
25500 + ssid = local->conf.ssid;
25501 + ssid_len = local->conf.ssid_len;
25503 + return ieee80211_sta_req_scan(dev, ssid, ssid_len);
25507 +static int ieee80211_ioctl_giwscan(struct net_device *dev,
25508 + struct iw_request_info *info,
25509 + struct iw_point *data, char *extra)
25512 + struct ieee80211_local *local = dev->priv;
25513 + if (local->sta_scanning)
25515 + res = ieee80211_sta_scan_results(dev, extra, IW_SCAN_MAX_DATA);
25517 + data->length = res;
25520 + data->length = 0;
25525 +static int ieee80211_ioctl_siwrts(struct net_device *dev,
25526 + struct iw_request_info *info,
25527 + struct iw_param *rts, char *extra)
25529 + struct ieee80211_local *local = dev->priv;
25531 + if (rts->disabled)
25532 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
25533 + else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
25536 + local->rts_threshold = rts->value;
25538 + /* If the wlan card performs RTS/CTS in hardware/firmware,
25539 + * configure it here */
25541 + if (local->hw->set_rts_threshold) {
25542 + local->hw->set_rts_threshold(dev, local->rts_threshold);
25548 +static int ieee80211_ioctl_giwrts(struct net_device *dev,
25549 + struct iw_request_info *info,
25550 + struct iw_param *rts, char *extra)
25552 + struct ieee80211_local *local = dev->priv;
25554 + rts->value = local->rts_threshold;
25555 + rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
25562 +static int ieee80211_ioctl_siwfrag(struct net_device *dev,
25563 + struct iw_request_info *info,
25564 + struct iw_param *frag, char *extra)
25566 + struct ieee80211_local *local = dev->priv;
25568 + if (frag->disabled)
25569 + local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
25570 + else if (frag->value < 256 ||
25571 + frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
25574 + /* Fragment length must be even, so strip LSB. */
25575 + local->fragmentation_threshold = frag->value & ~0x1;
25578 + /* If the wlan card performs fragmentation in hardware/firmware,
25579 + * configure it here */
25581 + if (local->hw->set_frag_threshold) {
25582 + local->hw->set_frag_threshold(
25583 + dev, local->fragmentation_threshold);
25589 +static int ieee80211_ioctl_giwfrag(struct net_device *dev,
25590 + struct iw_request_info *info,
25591 + struct iw_param *frag, char *extra)
25593 + struct ieee80211_local *local = dev->priv;
25595 + frag->value = local->fragmentation_threshold;
25596 + frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
25603 +static int ieee80211_ioctl_siwretry(struct net_device *dev,
25604 + struct iw_request_info *info,
25605 + struct iw_param *retry, char *extra)
25607 + struct ieee80211_local *local = dev->priv;
25609 + if (retry->disabled ||
25610 + (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25613 + if (retry->flags & IW_RETRY_MAX)
25614 + local->long_retry_limit = retry->value;
25615 + else if (retry->flags & IW_RETRY_MIN)
25616 + local->short_retry_limit = retry->value;
25618 + local->long_retry_limit = retry->value;
25619 + local->short_retry_limit = retry->value;
25622 + if (local->hw->set_retry_limit) {
25623 + return local->hw->set_retry_limit(
25624 + dev, local->short_retry_limit,
25625 + local->long_retry_limit);
25632 +static int ieee80211_ioctl_giwretry(struct net_device *dev,
25633 + struct iw_request_info *info,
25634 + struct iw_param *retry, char *extra)
25636 + struct ieee80211_local *local = dev->priv;
25638 + retry->disabled = 0;
25639 + if ((retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25641 + if (retry->flags & IW_RETRY_MAX) {
25642 + retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
25643 + retry->value = local->long_retry_limit;
25645 + retry->flags = IW_RETRY_LIMIT;
25646 + retry->value = local->short_retry_limit;
25647 + if (local->long_retry_limit != local->short_retry_limit)
25648 + retry->flags |= IW_RETRY_MIN;
25655 +static void ieee80211_ioctl_unmask_channels(struct ieee80211_local *local)
25659 + for (m = 0; m < local->hw->num_modes; m++) {
25660 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
25661 + for (c = 0; c < mode->num_channels; c++) {
25662 + struct ieee80211_channel *chan = &mode->channels[c];
25663 + chan->flag |= IEEE80211_CHAN_W_SCAN;
25669 +static int ieee80211_ioctl_test_mode(struct net_device *dev, int mode)
25671 + struct ieee80211_local *local = dev->priv;
25672 + int ret = -EOPNOTSUPP;
25674 + if (mode == IEEE80211_TEST_UNMASK_CHANNELS) {
25675 + ieee80211_ioctl_unmask_channels(local);
25679 + if (local->hw->test_mode)
25680 + ret = local->hw->test_mode(dev, mode);
25686 +static int ieee80211_ioctl_clear_keys(struct net_device *dev)
25688 + struct ieee80211_local *local = dev->priv;
25689 + struct ieee80211_key_conf key;
25690 + struct list_head *ptr;
25692 + u8 addr[ETH_ALEN];
25693 + struct ieee80211_key_conf *keyconf;
25695 + memset(addr, 0xff, ETH_ALEN);
25696 + list_for_each(ptr, &local->sub_if_list) {
25697 + struct ieee80211_sub_if_data *sdata =
25698 + list_entry(ptr, struct ieee80211_sub_if_data, list);
25699 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
25701 + if (sdata->keys[i] &&
25702 + !sdata->keys[i]->force_sw_encrypt &&
25703 + local->hw->set_key &&
25704 + (keyconf = ieee80211_key_data2conf(local,
25707 + local->hw->set_key(dev, DISABLE_KEY, addr,
25710 + kfree(sdata->keys[i]);
25711 + sdata->keys[i] = NULL;
25713 + sdata->default_key = NULL;
25716 + spin_lock_bh(&local->sta_lock);
25717 + list_for_each(ptr, &local->sta_list) {
25718 + struct sta_info *sta =
25719 + list_entry(ptr, struct sta_info, list);
25721 + if (sta->key && !sta->key->force_sw_encrypt &&
25722 + local->hw->set_key &&
25723 + (keyconf = ieee80211_key_data2conf(local, sta->key))
25725 + local->hw->set_key(dev, DISABLE_KEY, sta->addr,
25726 + keyconf, sta->aid);
25731 + spin_unlock_bh(&local->sta_lock);
25733 + memset(&key, 0, sizeof(key));
25734 + if (local->hw->set_key &&
25735 + local->hw->set_key(dev, REMOVE_ALL_KEYS, NULL,
25737 + printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
25745 +ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
25746 + struct ieee80211_sub_if_data *sdata,
25749 + struct ieee80211_local *local = dev->priv;
25752 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25756 + sdata->u.ap.force_unicast_rateidx = -1;
25760 + for (i = 0; i < local->num_curr_rates; i++) {
25761 + if (local->curr_rates[i].rate == rate) {
25762 + sdata->u.ap.force_unicast_rateidx = i;
25771 +ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
25772 + struct ieee80211_sub_if_data *sdata,
25775 + struct ieee80211_local *local = dev->priv;
25778 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25782 + sdata->u.ap.max_ratectrl_rateidx = -1;
25786 + for (i = 0; i < local->num_curr_rates; i++) {
25787 + if (local->curr_rates[i].rate == rate) {
25788 + sdata->u.ap.max_ratectrl_rateidx = i;
25796 +static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
25797 + struct ieee80211_key *key)
25799 + struct ieee80211_key_conf *keyconf;
25800 + u8 addr[ETH_ALEN];
25802 + if (key == NULL || key->alg != ALG_WEP || !key->force_sw_encrypt ||
25803 + local->hw->device_hides_wep)
25806 + memset(addr, 0xff, ETH_ALEN);
25807 + keyconf = ieee80211_key_data2conf(local, key);
25808 + if (keyconf && local->hw->set_key &&
25809 + local->hw->set_key(local->mdev, SET_KEY, addr, keyconf, 0) == 0) {
25810 + key->force_sw_encrypt = keyconf->force_sw_encrypt;
25811 + key->hw_key_idx = keyconf->hw_key_idx;
25817 +static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
25818 + struct ieee80211_key *key)
25820 + struct ieee80211_key_conf *keyconf;
25821 + u8 addr[ETH_ALEN];
25823 + if (key == NULL || key->alg != ALG_WEP || key->force_sw_encrypt ||
25824 + local->hw->device_hides_wep)
25827 + memset(addr, 0xff, ETH_ALEN);
25828 + keyconf = ieee80211_key_data2conf(local, key);
25829 + if (keyconf && local->hw->set_key)
25830 + local->hw->set_key(local->mdev, DISABLE_KEY, addr, keyconf, 0);
25832 + key->force_sw_encrypt = 1;
25836 +static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
25840 + struct list_head *ptr;
25842 + local->default_wep_only = value;
25843 + list_for_each(ptr, &local->sub_if_list) {
25844 + struct ieee80211_sub_if_data *sdata =
25845 + list_entry(ptr, struct ieee80211_sub_if_data, list);
25846 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
25848 + ieee80211_key_enable_hwaccel(local,
25851 + ieee80211_key_disable_hwaccel(local,
25861 +static int ieee80211_ioctl_prism2_param(struct net_device *dev,
25862 + struct iw_request_info *info,
25863 + void *wrqu, char *extra)
25865 + struct ieee80211_local *local = dev->priv;
25866 + struct ieee80211_sub_if_data *sdata;
25867 + int *i = (int *) extra;
25869 + int value = *(i + 1);
25872 + if (!capable(CAP_NET_ADMIN))
25875 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25878 + case PRISM2_PARAM_HOST_ENCRYPT:
25879 + case PRISM2_PARAM_HOST_DECRYPT:
25880 + /* TODO: implement these; return success now to prevent
25881 + * hostapd from aborting */
25884 + case PRISM2_PARAM_BEACON_INT:
25885 + local->conf.beacon_int = value;
25886 + if (ieee80211_hw_config(dev))
25890 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
25891 + local->bridge_packets = value;
25894 + case PRISM2_PARAM_AP_AUTH_ALGS:
25895 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25896 + sdata->u.sta.auth_algs = value;
25898 + ret = -EOPNOTSUPP;
25901 + case PRISM2_PARAM_DTIM_PERIOD:
25904 + else if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25907 + sdata->u.ap.dtim_period = value;
25910 + case PRISM2_PARAM_IEEE_802_1X:
25911 + sdata->ieee802_1x = value;
25912 + if (local->hw->set_ieee8021x &&
25913 + local->hw->set_ieee8021x(dev, value))
25914 + printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
25915 + "for low-level driver\n", dev->name, value);
25918 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
25919 + local->cts_protect_erp_frames = value;
25922 + case PRISM2_PARAM_DROP_UNENCRYPTED:
25923 + sdata->drop_unencrypted = value;
25926 + case PRISM2_PARAM_PREAMBLE:
25927 + local->short_preamble = value;
25930 + case PRISM2_PARAM_RATE_LIMIT_BURST:
25931 + local->rate_limit_burst = value;
25932 + local->rate_limit_bucket = value;
25935 + case PRISM2_PARAM_RATE_LIMIT:
25936 + /* number of packets (tokens) allowed per second */
25937 + if (!local->rate_limit && value) {
25938 + if (!local->rate_limit_burst) local->rate_limit_burst =
25940 + local->rate_limit_bucket = local->rate_limit_burst;
25941 + local->rate_limit_timer.expires = jiffies + HZ;
25942 + add_timer(&local->rate_limit_timer);
25943 + } else if (local->rate_limit && !value) {
25944 + del_timer_sync(&local->rate_limit_timer);
25946 + local->rate_limit = value;
25949 + case PRISM2_PARAM_STAT_TIME:
25950 + if (!local->stat_time && value) {
25951 + local->stat_timer.expires = jiffies + HZ * value / 100;
25952 + add_timer(&local->stat_timer);
25953 + } else if (local->stat_time && !value) {
25954 + del_timer_sync(&local->stat_timer);
25956 + local->stat_time = value;
25958 + case PRISM2_PARAM_SHORT_SLOT_TIME:
25959 + local->conf.short_slot_time = value;
25960 + if (ieee80211_hw_config(dev))
25964 + case PRISM2_PARAM_PRIVACY_INVOKED:
25965 + if (local->hw->set_privacy_invoked)
25966 + ret = local->hw->set_privacy_invoked(dev, value);
25969 + case PRISM2_PARAM_TEST_MODE:
25970 + ret = ieee80211_ioctl_test_mode(dev, value);
25973 + case PRISM2_PARAM_NEXT_MODE:
25974 + local->next_mode = value;
25977 + case PRISM2_PARAM_CLEAR_KEYS:
25978 + ret = ieee80211_ioctl_clear_keys(dev);
25981 + case PRISM2_PARAM_ADM_STATUS:
25982 + ret = ieee80211_ioctl_set_adm_status(dev, value);
25985 + case PRISM2_PARAM_ANTENNA_SEL:
25986 + local->conf.antenna_sel = value;
25987 + if (ieee80211_hw_config(dev))
25991 + case PRISM2_PARAM_CALIB_INT:
25992 + local->conf.calib_int = value;
25993 + if (ieee80211_hw_config(dev))
25997 + case PRISM2_PARAM_ANTENNA_MODE:
25998 + local->conf.antenna_mode = value;
25999 + if (ieee80211_hw_config(dev))
26003 + case PRISM2_PARAM_BROADCAST_SSID:
26004 + if ((value < 0) || (value > 1))
26007 + local->conf.ssid_hidden = value;
26010 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26011 + local->sta_antenna_sel = value;
26014 + case PRISM2_PARAM_FORCE_UNICAST_RATE:
26015 + ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
26018 + case PRISM2_PARAM_MAX_RATECTRL_RATE:
26019 + ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
26022 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26023 + local->rate_ctrl_num_up = value;
26026 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26027 + local->rate_ctrl_num_down = value;
26030 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26034 + local->conf.tx_power_reduction = value;
26037 + case PRISM2_PARAM_EAPOL:
26038 + sdata->eapol = value;
26041 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26042 + local->key_tx_rx_threshold = value;
26045 + case PRISM2_PARAM_KEY_INDEX:
26046 + if (value < 0 || value >= NUM_DEFAULT_KEYS)
26048 + else if (sdata->keys[value] == NULL)
26051 + sdata->default_key = sdata->keys[value];
26054 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26055 + ret = ieee80211_ioctl_default_wep_only(local, value);
26058 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26059 + local->wifi_wme_noack_test = value;
26062 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26063 + local->allow_broadcast_always = value;
26066 + case PRISM2_PARAM_SCAN_FLAGS:
26067 + local->scan_flags = value;
26070 + case PRISM2_PARAM_MIXED_CELL:
26071 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26074 + sdata->u.sta.mixed_cell = !!value;
26077 + case PRISM2_PARAM_KEY_MGMT:
26078 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26081 + sdata->u.sta.key_mgmt = value;
26084 + case PRISM2_PARAM_HW_MODES:
26085 + local->hw_modes = value;
26088 + case PRISM2_PARAM_CREATE_IBSS:
26089 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26092 + sdata->u.sta.create_ibss = !!value;
26094 + case PRISM2_PARAM_WMM_ENABLED:
26095 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26098 + sdata->u.sta.wmm_enabled = !!value;
26100 + case PRISM2_PARAM_RADAR_DETECT:
26101 + local->conf.radar_detect = value;
26103 + case PRISM2_PARAM_SPECTRUM_MGMT:
26104 + local->conf.spect_mgmt = value;
26107 + ret = -EOPNOTSUPP;
26115 +static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
26116 + struct iw_request_info *info,
26117 + void *wrqu, char *extra)
26119 + struct ieee80211_local *local = dev->priv;
26120 + struct ieee80211_sub_if_data *sdata;
26121 + int *param = (int *) extra;
26124 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26126 + switch (*param) {
26127 + case PRISM2_PARAM_BEACON_INT:
26128 + *param = local->conf.beacon_int;
26131 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
26132 + *param = local->bridge_packets;
26135 + case PRISM2_PARAM_AP_AUTH_ALGS:
26136 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
26137 + *param = sdata->u.sta.auth_algs;
26139 + ret = -EOPNOTSUPP;
26142 + case PRISM2_PARAM_DTIM_PERIOD:
26143 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
26146 + *param = sdata->u.ap.dtim_period;
26149 + case PRISM2_PARAM_IEEE_802_1X:
26150 + *param = sdata->ieee802_1x;
26153 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
26154 + *param = local->cts_protect_erp_frames;
26157 + case PRISM2_PARAM_DROP_UNENCRYPTED:
26158 + *param = sdata->drop_unencrypted;
26161 + case PRISM2_PARAM_PREAMBLE:
26162 + *param = local->short_preamble;
26165 + case PRISM2_PARAM_RATE_LIMIT_BURST:
26166 + *param = local->rate_limit_burst;
26169 + case PRISM2_PARAM_RATE_LIMIT:
26170 + *param = local->rate_limit;
26173 + case PRISM2_PARAM_STAT_TIME:
26174 + *param = local->stat_time;
26176 + case PRISM2_PARAM_SHORT_SLOT_TIME:
26177 + *param = local->conf.short_slot_time;
26180 + case PRISM2_PARAM_NEXT_MODE:
26181 + *param = local->next_mode;
26184 + case PRISM2_PARAM_ANTENNA_SEL:
26185 + *param = local->conf.antenna_sel;
26188 + case PRISM2_PARAM_CALIB_INT:
26189 + *param = local->conf.calib_int;
26192 + case PRISM2_PARAM_ANTENNA_MODE:
26193 + *param = local->conf.antenna_mode;
26196 + case PRISM2_PARAM_BROADCAST_SSID:
26197 + *param = local->conf.ssid_hidden;
26200 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26201 + *param = local->sta_antenna_sel;
26204 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26205 + *param = local->rate_ctrl_num_up;
26208 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26209 + *param = local->rate_ctrl_num_down;
26212 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26213 + *param = local->conf.tx_power_reduction;
26216 + case PRISM2_PARAM_EAPOL:
26217 + *param = sdata->eapol;
26220 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26221 + *param = local->key_tx_rx_threshold;
26224 + case PRISM2_PARAM_KEY_INDEX:
26225 + if (sdata->default_key == NULL)
26227 + else if (sdata->default_key == sdata->keys[0])
26229 + else if (sdata->default_key == sdata->keys[1])
26231 + else if (sdata->default_key == sdata->keys[2])
26233 + else if (sdata->default_key == sdata->keys[3])
26239 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26240 + *param = local->default_wep_only;
26243 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26244 + *param = local->wifi_wme_noack_test;
26247 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26248 + *param = local->allow_broadcast_always;
26251 + case PRISM2_PARAM_SCAN_FLAGS:
26252 + *param = local->scan_flags;
26255 + case PRISM2_PARAM_HW_MODES:
26256 + *param = local->hw_modes;
26259 + case PRISM2_PARAM_CREATE_IBSS:
26260 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26263 + *param = !!sdata->u.sta.create_ibss;
26266 + case PRISM2_PARAM_MIXED_CELL:
26267 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26270 + *param = !!sdata->u.sta.mixed_cell;
26273 + case PRISM2_PARAM_KEY_MGMT:
26274 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26277 + *param = sdata->u.sta.key_mgmt;
26279 + case PRISM2_PARAM_WMM_ENABLED:
26280 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26283 + *param = !!sdata->u.sta.wmm_enabled;
26287 + ret = -EOPNOTSUPP;
26295 +static int ieee80211_ioctl_test_param(struct net_device *dev,
26296 + struct iw_request_info *info,
26297 + void *wrqu, char *extra)
26299 + struct ieee80211_local *local = dev->priv;
26300 + int *i = (int *) extra;
26302 + int value = *(i + 1);
26304 + if (!capable(CAP_NET_ADMIN))
26307 + if (local->hw->test_param)
26308 + return local->hw->test_param(local->mdev, param, value);
26310 + return -EOPNOTSUPP;
26314 +static int ieee80211_ioctl_siwmlme(struct net_device *dev,
26315 + struct iw_request_info *info,
26316 + struct iw_point *data, char *extra)
26318 + struct ieee80211_sub_if_data *sdata;
26319 + struct iw_mlme *mlme = (struct iw_mlme *) extra;
26321 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26322 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26325 + switch (mlme->cmd) {
26326 + case IW_MLME_DEAUTH:
26327 + /* TODO: mlme->addr.sa_data */
26328 + return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
26329 + case IW_MLME_DISASSOC:
26330 + /* TODO: mlme->addr.sa_data */
26331 + return ieee80211_sta_disassociate(dev, mlme->reason_code);
26333 + return -EOPNOTSUPP;
26338 +static int ieee80211_ioctl_siwencode(struct net_device *dev,
26339 + struct iw_request_info *info,
26340 + struct iw_point *erq, char *keybuf)
26342 + struct ieee80211_sub_if_data *sdata;
26343 + int idx, i, alg = ALG_WEP;
26344 + u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
26346 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26348 + idx = erq->flags & IW_ENCODE_INDEX;
26349 + if (idx < 1 || idx > 4) {
26351 + if (sdata->default_key == NULL)
26353 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26354 + if (sdata->default_key == sdata->keys[i])
26363 + if (erq->flags & IW_ENCODE_DISABLED)
26365 + else if (erq->length == 0) {
26366 + /* No key data - just set the default TX key index */
26367 + sdata->default_key = sdata->keys[idx];
26370 + return ieee80211_set_encryption(
26372 + idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
26373 + sdata->default_key == NULL,
26374 + NULL, keybuf, erq->length);
26380 +static int ieee80211_ioctl_giwencode(struct net_device *dev,
26381 + struct iw_request_info *info,
26382 + struct iw_point *erq, char *key)
26384 + struct ieee80211_sub_if_data *sdata;
26387 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26389 + idx = erq->flags & IW_ENCODE_INDEX;
26390 + if (idx < 1 || idx > 4) {
26392 + if (sdata->default_key == NULL)
26394 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26395 + if (sdata->default_key == sdata->keys[i])
26404 + erq->flags = idx + 1;
26406 + if (sdata->keys[idx] == NULL) {
26408 + erq->flags |= IW_ENCODE_DISABLED;
26413 + erq->flags |= IW_ENCODE_ENABLED;
26419 +static int ieee80211_ioctl_siwgenie(struct net_device *dev,
26420 + struct iw_request_info *info,
26421 + struct iw_point *data, char *extra)
26423 + return ieee80211_set_gen_ie(dev, extra, data->length);
26427 +static int ieee80211_ioctl_siwauth(struct net_device *dev,
26428 + struct iw_request_info *info,
26429 + struct iw_param *data, char *extra)
26431 + struct ieee80211_local *local = dev->priv;
26432 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26435 + switch (data->flags & IW_AUTH_INDEX) {
26436 + case IW_AUTH_WPA_VERSION:
26437 + case IW_AUTH_CIPHER_PAIRWISE:
26438 + case IW_AUTH_CIPHER_GROUP:
26439 + case IW_AUTH_WPA_ENABLED:
26440 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
26442 + case IW_AUTH_KEY_MGMT:
26443 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26447 + * TODO: sdata->u.sta.key_mgmt does not match with WE18
26448 + * value completely; could consider modifying this to
26449 + * be closer to WE18. For now, this value is not really
26450 + * used for anything else than Privacy matching, so the
26451 + * current code here should be more or less OK.
26453 + if (data->value & IW_AUTH_KEY_MGMT_802_1X) {
26454 + sdata->u.sta.key_mgmt =
26455 + IEEE80211_KEY_MGMT_WPA_EAP;
26456 + } else if (data->value & IW_AUTH_KEY_MGMT_PSK) {
26457 + sdata->u.sta.key_mgmt =
26458 + IEEE80211_KEY_MGMT_WPA_PSK;
26460 + sdata->u.sta.key_mgmt =
26461 + IEEE80211_KEY_MGMT_NONE;
26465 + case IW_AUTH_80211_AUTH_ALG:
26466 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26467 + sdata->u.sta.auth_algs = data->value;
26469 + ret = -EOPNOTSUPP;
26471 + case IW_AUTH_PRIVACY_INVOKED:
26472 + if (local->hw->set_privacy_invoked)
26473 + ret = local->hw->set_privacy_invoked(dev, data->value);
26476 + ret = -EOPNOTSUPP;
26483 +static int ieee80211_ioctl_giwauth(struct net_device *dev,
26484 + struct iw_request_info *info,
26485 + struct iw_param *data, char *extra)
26487 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26490 + switch (data->flags & IW_AUTH_INDEX) {
26491 + case IW_AUTH_80211_AUTH_ALG:
26492 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26493 + data->value = sdata->u.sta.auth_algs;
26495 + ret = -EOPNOTSUPP;
26498 + ret = -EOPNOTSUPP;
26505 +static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
26506 + struct iw_request_info *info,
26507 + struct iw_point *erq, char *extra)
26509 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26510 + struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
26513 + switch (ext->alg) {
26514 + case IW_ENCODE_ALG_NONE:
26517 + case IW_ENCODE_ALG_WEP:
26520 + case IW_ENCODE_ALG_TKIP:
26523 + case IW_ENCODE_ALG_CCMP:
26527 + return -EOPNOTSUPP;
26530 + if (erq->flags & IW_ENCODE_DISABLED)
26533 + idx = erq->flags & IW_ENCODE_INDEX;
26534 + if (idx < 1 || idx > 4) {
26536 + if (sdata->default_key == NULL)
26538 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26539 + if (sdata->default_key == sdata->keys[i])
26548 + return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
26550 + IW_ENCODE_EXT_SET_TX_KEY,
26551 + NULL, ext->key, ext->key_len);
26555 +static const struct iw_priv_args ieee80211_ioctl_priv[] = {
26556 + { PRISM2_IOCTL_PRISM2_PARAM,
26557 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
26558 + { PRISM2_IOCTL_GET_PRISM2_PARAM,
26559 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
26560 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
26561 + { PRISM2_IOCTL_TEST_PARAM,
26562 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "test_param" },
26566 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
26568 + struct iwreq *wrq = (struct iwreq *) rq;
26572 + /* Private ioctls (iwpriv) that have not yet been converted
26573 + * into new wireless extensions API */
26574 + case PRISM2_IOCTL_TEST_PARAM:
26575 + ret = ieee80211_ioctl_test_param(dev, NULL, &wrq->u,
26576 + (char *) &wrq->u);
26578 + case PRISM2_IOCTL_HOSTAPD:
26579 + if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
26580 + else ret = ieee80211_ioctl_priv_hostapd(dev, &wrq->u.data);
26583 + ret = -EOPNOTSUPP;
26591 +/* Structures to export the Wireless Handlers */
26593 +static const iw_handler ieee80211_handler[] =
26595 + (iw_handler) NULL, /* SIOCSIWCOMMIT */
26596 + (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
26597 + (iw_handler) NULL, /* SIOCSIWNWID */
26598 + (iw_handler) NULL, /* SIOCGIWNWID */
26599 + (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
26600 + (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
26601 + (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
26602 + (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
26603 + (iw_handler) NULL, /* SIOCSIWSENS */
26604 + (iw_handler) NULL, /* SIOCGIWSENS */
26605 + (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
26606 + (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
26607 + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
26608 + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
26609 + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
26610 + (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
26611 + iw_handler_set_spy, /* SIOCSIWSPY */
26612 + iw_handler_get_spy, /* SIOCGIWSPY */
26613 + iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
26614 + iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
26615 + (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
26616 + (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
26617 + (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
26618 + (iw_handler) NULL, /* SIOCGIWAPLIST */
26619 + (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
26620 + (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
26621 + (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
26622 + (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
26623 + (iw_handler) NULL, /* SIOCSIWNICKN */
26624 + (iw_handler) NULL, /* SIOCGIWNICKN */
26625 + (iw_handler) NULL, /* -- hole -- */
26626 + (iw_handler) NULL, /* -- hole -- */
26627 + (iw_handler) NULL, /* SIOCSIWRATE */
26628 + (iw_handler) NULL, /* SIOCGIWRATE */
26629 + (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
26630 + (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
26631 + (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
26632 + (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
26633 + (iw_handler) NULL, /* SIOCSIWTXPOW */
26634 + (iw_handler) NULL, /* SIOCGIWTXPOW */
26635 + (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
26636 + (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
26637 + (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
26638 + (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
26639 + (iw_handler) NULL, /* SIOCSIWPOWER */
26640 + (iw_handler) NULL, /* SIOCGIWPOWER */
26641 + (iw_handler) NULL, /* -- hole -- */
26642 + (iw_handler) NULL, /* -- hole -- */
26643 + (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
26644 + (iw_handler) NULL, /* SIOCGIWGENIE */
26645 + (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
26646 + (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
26647 + (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
26648 + (iw_handler) NULL, /* SIOCGIWENCODEEXT */
26649 + (iw_handler) NULL, /* SIOCSIWPMKSA */
26650 + (iw_handler) NULL, /* -- hole -- */
26653 +static const iw_handler ieee80211_private_handler[] =
26654 +{ /* SIOCIWFIRSTPRIV + */
26655 + (iw_handler) ieee80211_ioctl_prism2_param, /* 0 */
26656 + (iw_handler) ieee80211_ioctl_get_prism2_param, /* 1 */
26659 +const struct iw_handler_def ieee80211_iw_handler_def =
26661 + .num_standard = sizeof(ieee80211_handler) / sizeof(iw_handler),
26662 + .num_private = sizeof(ieee80211_private_handler) /
26663 + sizeof(iw_handler),
26664 + .num_private_args = sizeof(ieee80211_ioctl_priv) /
26665 + sizeof(struct iw_priv_args),
26666 + .standard = (iw_handler *) ieee80211_handler,
26667 + .private = (iw_handler *) ieee80211_private_handler,
26668 + .private_args = (struct iw_priv_args *) ieee80211_ioctl_priv,
26670 diff -Nur linux-2.6.16/net/d80211/ieee80211_key.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_key.h
26671 --- linux-2.6.16/net/d80211/ieee80211_key.h 1970-01-01 01:00:00.000000000 +0100
26672 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_key.h 2006-03-28 22:16:14.000000000 +0200
26675 + * Copyright 2002-2004, Instant802 Networks, Inc.
26676 + * Copyright 2005, Devicescape Software, Inc.
26678 + * This program is free software; you can redistribute it and/or modify
26679 + * it under the terms of the GNU General Public License version 2 as
26680 + * published by the Free Software Foundation.
26683 +#ifndef IEEE80211_KEY_H
26684 +#define IEEE80211_KEY_H
26686 +#include <linux/types.h>
26687 +#include <net/d80211.h>
26690 + * struct ieee80211_key::key is encoded as a 256-bit (32 byte) data block:
26691 + * Temporal Encryption Key (128 bits)
26692 + * Temporal Authenticator Tx MIC Key (64 bits)
26693 + * Temporal Authenticator Rx MIC Key (64 bits)
26696 +#define WEP_IV_LEN 4
26697 +#define WEP_ICV_LEN 4
26699 +#define ALG_TKIP_KEY_LEN 32
26700 +/* Starting offsets for each key */
26701 +#define ALG_TKIP_TEMP_ENCR_KEY 0
26702 +#define ALG_TKIP_TEMP_AUTH_TX_MIC_KEY 16
26703 +#define ALG_TKIP_TEMP_AUTH_RX_MIC_KEY 24
26704 +#define TKIP_IV_LEN 8
26705 +#define TKIP_ICV_LEN 4
26707 +#define ALG_CCMP_KEY_LEN 16
26708 +#define CCMP_HDR_LEN 8
26709 +#define CCMP_MIC_LEN 8
26710 +#define CCMP_TK_LEN 16
26711 +#define CCMP_PN_LEN 6
26713 +#define NUM_RX_DATA_QUEUES 17
26715 +struct ieee80211_key {
26716 + int hw_key_idx; /* filled and used by low-level driver */
26717 + ieee80211_key_alg alg;
26720 + /* last used TSC */
26724 + int tx_initialized;
26726 + /* last received RSC */
26727 + u32 iv32_rx[NUM_RX_DATA_QUEUES];
26728 + u16 iv16_rx[NUM_RX_DATA_QUEUES];
26729 + u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
26730 + int rx_initialized[NUM_RX_DATA_QUEUES];
26734 + /* TODO: for WME make this replay counter per AC */
26735 + u8 rx_pn[NUM_RX_DATA_QUEUES][6];
26736 +#ifndef AES_STATE_LEN
26737 +#define AES_STATE_LEN 44
26739 + u32 aes_state[AES_STATE_LEN];
26740 + u32 replays; /* dot11RSNAStatsCCMPReplays */
26743 + int tx_rx_count; /* number of times this key has been used */
26746 + /* if the low level driver can provide hardware acceleration it should
26747 + * clear this flag */
26748 + int force_sw_encrypt:1;
26749 + int keyidx:8; /* WEP key index */
26750 + int default_tx_key:1; /* This key is the new default TX key
26751 + * (used only for broadcast keys). */
26756 +#endif /* IEEE80211_KEY_H */
26757 diff -Nur linux-2.6.16/net/d80211/ieee80211_led.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_led.c
26758 --- linux-2.6.16/net/d80211/ieee80211_led.c 1970-01-01 01:00:00.000000000 +0100
26759 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_led.c 2006-03-28 22:16:14.000000000 +0200
26762 + * Copyright 2002-2004, Instant802 Networks, Inc.
26764 + * This program is free software; you can redistribute it and/or modify
26765 + * it under the terms of the GNU General Public License version 2 as
26766 + * published by the Free Software Foundation.
26769 +#include <linux/config.h>
26770 +#include <linux/netdevice.h>
26771 +#include <linux/types.h>
26773 +#ifdef CONFIG_OAP_LEDS_WLAN
26774 +extern void leds_wlan_set(int unit, int tx, int state);
26777 +void ieee80211_rx_led(int state, struct net_device *dev) {
26778 +#ifdef CONFIG_OAP_LEDS_WLAN
26779 + static unsigned int count = 0;
26781 + if (state == 2) {
26782 + leds_wlan_set(0, 0, (++count) & 1);
26787 +void ieee80211_tx_led(int state, struct net_device *dev) {
26788 +#ifdef CONFIG_OAP_LEDS_WLAN
26789 + leds_wlan_set(0, 1, state);
26793 diff -Nur linux-2.6.16/net/d80211/ieee80211_proc.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.c
26794 --- linux-2.6.16/net/d80211/ieee80211_proc.c 1970-01-01 01:00:00.000000000 +0100
26795 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.c 2006-03-28 22:16:14.000000000 +0200
26798 + * Copyright 2003-2005, Devicescape Software, Inc.
26800 + * This program is free software; you can redistribute it and/or modify
26801 + * it under the terms of the GNU General Public License version 2 as
26802 + * published by the Free Software Foundation.
26805 +#include <linux/config.h>
26806 +#include <linux/version.h>
26807 +#include <linux/module.h>
26808 +#include <linux/netdevice.h>
26809 +#include <linux/proc_fs.h>
26810 +#include <linux/delay.h>
26812 +#ifdef CONFIG_PROC_FS
26814 +#include <net/d80211.h>
26815 +#include <net/d80211_common.h>
26816 +#include <net/d80211_mgmt.h>
26817 +#include "ieee80211_i.h"
26818 +#include "sta_info.h"
26819 +#include "ieee80211_proc.h"
26820 +#include "rate_control.h"
26823 +static struct proc_dir_entry *ieee80211_proc;
26825 +#define PROC_LIMIT (PAGE_SIZE - 80)
26828 +static char * ieee80211_proc_key(char *p, struct ieee80211_key *key,
26829 + int idx, int def_key)
26837 + p += sprintf(p, "key[%d]%s len=%d sw_encrypt=%d idx=%d hwidx=%d "
26838 + "tx_rx_count=%d",
26839 + idx, def_key ? "*" : "", key->keylen,
26840 + key->force_sw_encrypt, key->keyidx, key->hw_key_idx,
26841 + key->tx_rx_count);
26842 + switch (key->alg) {
26844 + p += sprintf(p, " alg=WEP");
26847 + p += sprintf(p, " alg=TKIP iv(tx)=%08x %04x",
26848 + key->u.tkip.iv32, key->u.tkip.iv16);
26849 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
26850 + if (key->u.tkip.iv32_rx[i] == 0 &&
26851 + key->u.tkip.iv16_rx[i] == 0)
26853 + p += sprintf(p, " iv(rx %d)=%08x %04x", i,
26854 + key->u.tkip.iv32_rx[i],
26855 + key->u.tkip.iv16_rx[i]);
26859 + tpn = key->u.ccmp.tx_pn;
26860 + p += sprintf(p, " alg=CCMP PN(tx)=%02x%02x%02x%02x%02x%02x",
26861 + tpn[0], tpn[1], tpn[2], tpn[3], tpn[4], tpn[5]);
26862 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
26863 + rpn = key->u.ccmp.rx_pn[i];
26864 + if (memcmp(rpn, "\x00\x00\x00\x00\x00\x00", 6) == 0)
26866 + p += sprintf(p, " PN(rx %d)=%02x%02x%02x%02x%02x%02x",
26867 + i, rpn[0], rpn[1], rpn[2], rpn[3], rpn[4],
26870 + p += sprintf(p, " replays=%u", key->u.ccmp.replays);
26876 + p += sprintf(p, " key=");
26877 + for (i = 0; i < key->keylen; i++)
26878 + p += sprintf(p, "%02x", key->key[i]);
26879 + p += sprintf(p, "\n");
26884 +static char * ieee80211_proc_sub_if_ap(char *p,
26885 + struct ieee80211_if_ap *ap)
26887 + p += sprintf(p, "type=ap\n");
26888 + if (ap->beacon_head)
26889 + p += sprintf(p, "beacon_head_len=%d\n", ap->beacon_head_len);
26890 + if (ap->beacon_tail)
26891 + p += sprintf(p, "beacon_tail_len=%d\n", ap->beacon_tail_len);
26894 + "num_sta_ps=%d\n"
26895 + "num_buffered_multicast=%u\n"
26896 + "dtim_period=%d\n"
26897 + "dtim_count=%d\n"
26898 + "num_beacons=%d\n"
26899 + "force_unicast_rateidx=%d\n"
26900 + "max_ratectrl_rateidx=%d\n",
26901 + ap->max_aid, atomic_read(&ap->num_sta_ps),
26902 + skb_queue_len(&ap->ps_bc_buf),
26903 + ap->dtim_period, ap->dtim_count, ap->num_beacons,
26904 + ap->force_unicast_rateidx, ap->max_ratectrl_rateidx);
26909 +static char * ieee80211_proc_sub_if_sta(char *p,
26910 + struct ieee80211_if_sta *ifsta)
26912 + p += sprintf(p, "type=sta\n");
26915 + "bssid=" MACSTR "\n"
26916 + "prev_bssid=" MACSTR "\n"
26919 + "ap_capab=0x%x\n"
26921 + "extra_ie_len=%zd\n"
26922 + "auth_tries=%d\n"
26923 + "assoc_tries=%d\n"
26924 + "flags=%s%s%s%s%s%s%s\n"
26925 + "auth_algs=0x%x\n"
26927 + "auth_transaction=%d\n",
26929 + MAC2STR(ifsta->bssid),
26930 + MAC2STR(ifsta->prev_bssid),
26935 + ifsta->extra_ie_len,
26936 + ifsta->auth_tries,
26937 + ifsta->assoc_tries,
26938 + ifsta->ssid_set ? "[SSID]" : "",
26939 + ifsta->bssid_set ? "[BSSID]" : "",
26940 + ifsta->prev_bssid_set ? "[prev BSSID" : "",
26941 + ifsta->authenticated ? "[AUTH]" : "",
26942 + ifsta->associated ? "[ASSOC]" : "",
26943 + ifsta->probereq_poll ? "[PROBEREQ POLL]" : "",
26944 + ifsta->use_protection ? "[CTS prot]" : "",
26945 + ifsta->auth_algs,
26947 + ifsta->auth_transaction);
26952 +static char * ieee80211_proc_sub_if(char *p,
26953 + struct ieee80211_sub_if_data *sdata)
26955 + if (sdata == NULL)
26959 + p += sprintf(p, "bss=%p\n", sdata->bss);
26961 + switch (sdata->type) {
26962 + case IEEE80211_SUB_IF_TYPE_AP:
26963 + p = ieee80211_proc_sub_if_ap(p, &sdata->u.ap);
26965 + case IEEE80211_SUB_IF_TYPE_WDS:
26966 + p += sprintf(p, "type=wds\n");
26967 + p += sprintf(p, "wds.peer=" MACSTR "\n",
26968 + MAC2STR(sdata->u.wds.remote_addr));
26970 + case IEEE80211_SUB_IF_TYPE_VLAN:
26971 + p += sprintf(p, "type=vlan\n");
26972 + p += sprintf(p, "vlan.id=%d\n", sdata->u.vlan.id);
26974 + case IEEE80211_SUB_IF_TYPE_STA:
26975 + p = ieee80211_proc_sub_if_sta(p, &sdata->u.sta);
26978 + p += sprintf(p, "channel_use=%d\n", sdata->channel_use);
26979 + p += sprintf(p, "drop_unencrypted=%d\n", sdata->drop_unencrypted);
26980 + p += sprintf(p, "eapol=%d\n", sdata->eapol);
26981 + p += sprintf(p, "ieee802_1x=%d\n", sdata->ieee802_1x);
26987 +static int ieee80211_proc_iface_read(char *page, char **start, off_t off,
26988 + int count, int *eof, void *data)
26991 + struct net_device *dev = (struct net_device *) data;
26992 + struct ieee80211_sub_if_data *sdata;
27000 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
27004 + p = ieee80211_proc_sub_if(p, sdata);
27006 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
27007 + if (sdata->keys[i] == NULL)
27010 + p = ieee80211_proc_key(p, sdata->keys[i], i,
27011 + sdata->keys[i] == sdata->default_key);
27014 + return (p - page);
27018 +static int ieee80211_proc_sta_read(char *page, char **start, off_t off,
27019 + int count, int *eof, void *data)
27022 + struct sta_info *sta = (struct sta_info *) data;
27023 + struct ieee80211_local *local;
27031 + if (!sta || !sta->dev)
27034 + p += sprintf(p, "users=%d\n", atomic_read(&sta->users));
27035 + p += sprintf(p, "aid=%d\n", sta->aid);
27036 + p += sprintf(p, "flags=0x%x %s%s%s%s%s%s%s%s%s%s\n", sta->flags,
27037 + sta->flags & WLAN_STA_AUTH ? "[AUTH]" : "",
27038 + sta->flags & WLAN_STA_ASSOC ? "[ASSOC]" : "",
27039 + sta->flags & WLAN_STA_PS ? "[PS]" : "",
27040 + sta->flags & WLAN_STA_TIM ? "[TIM]" : "",
27041 + sta->flags & WLAN_STA_PERM ? "[PERM]" : "",
27042 + sta->flags & WLAN_STA_AUTHORIZED ? "[AUTHORIZED]" : "",
27043 + sta->flags & WLAN_STA_SHORT_PREAMBLE ?
27044 + "[SHORT PREAMBLE]" : "",
27045 + sta->flags & WLAN_STA_WME ? "[WME]" : "",
27046 + sta->flags & WLAN_STA_WDS ? "[WDS]" : "",
27047 + sta->flags & WLAN_STA_XR ? "[XR]" : "");
27048 + p += sprintf(p, "key_idx_compression=%d\n",
27049 + sta->key_idx_compression);
27050 + p += sprintf(p, "dev=%s\n", sta->dev->name);
27051 + if (sta->vlan_id > 0)
27052 + p += sprintf(p, "vlan_id=%d\n", sta->vlan_id);
27053 + p += sprintf(p, "rx_packets=%lu\ntx_packets=%lu\nrx_bytes=%lu\n"
27054 + "tx_bytes=%lu\nrx_duplicates=%lu\nrx_fragments=%lu\n"
27055 + "rx_dropped=%lu\ntx_fragments=%lu\ntx_filtered=%lu\n",
27056 + sta->rx_packets, sta->tx_packets,
27057 + sta->rx_bytes, sta->tx_bytes,
27058 + sta->num_duplicates, sta->rx_fragments, sta->rx_dropped,
27059 + sta->tx_fragments, sta->tx_filtered_count);
27060 + p = ieee80211_proc_key(p, sta->key, 0, 1);
27062 + local = (struct ieee80211_local *) sta->dev->priv;
27063 + if (sta->txrate >= 0 && sta->txrate < local->num_curr_rates) {
27064 + p += sprintf(p, "txrate=%d\n",
27065 + local->curr_rates[sta->txrate].rate);
27067 + if (sta->last_txrate >= 0 &&
27068 + sta->last_txrate < local->num_curr_rates) {
27069 + p += sprintf(p, "last_txrate=%d\n",
27070 + local->curr_rates[sta->last_txrate].rate);
27072 + p += sprintf(p, "num_ps_buf_frames=%u\n",
27073 + skb_queue_len(&sta->ps_tx_buf));
27074 + p += sprintf(p, "tx_retry_failed=%lu\n", sta->tx_retry_failed);
27075 + p += sprintf(p, "tx_retry_count=%lu\n", sta->tx_retry_count);
27076 + p += sprintf(p, "last_rssi=%d\n", sta->last_rssi);
27077 + p += sprintf(p, "last_ack_rssi=%d %d %d\n",
27078 + sta->last_ack_rssi[0], sta->last_ack_rssi[1],
27079 + sta->last_ack_rssi[2]);
27080 + if (sta->last_ack)
27081 + p += sprintf(p, "last_ack_ms=%d\n",
27082 + jiffies_to_msecs(jiffies - sta->last_ack));
27083 + inactive = jiffies - sta->last_rx;
27084 + p += sprintf(p, "inactive_msec=%d\n", jiffies_to_msecs(inactive));
27085 + p += sprintf(p, "channel_use=%d\n", sta->channel_use);
27086 + p += sprintf(p, "wep_weak_iv_count=%d\n", sta->wep_weak_iv_count);
27087 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
27088 + p += sprintf(p, "wme_rx_queue=");
27089 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27090 + p += sprintf(p, "%u ", sta->wme_rx_queue[i]);
27091 + p += sprintf(p, "\n");
27093 + p += sprintf(p, "wme_tx_queue=");
27094 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27095 + p += sprintf(p, "%u ", sta->wme_tx_queue[i]);
27096 + p += sprintf(p, "\n");
27097 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27098 + p += sprintf(p, "last_seq_ctrl=");
27099 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
27100 + p += sprintf(p, "%x ", sta->last_seq_ctrl[i]);
27102 + p += sprintf(p, "\n");
27104 + p += rate_control_status_sta(local, sta, p);
27106 + return (p - page);
27110 +static int ieee80211_proc_counters_read(char *page, char **start, off_t off,
27111 + int count, int *eof, void *data)
27114 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27115 + struct ieee80211_low_level_stats stats;
27123 + "TransmittedFragmentCount=%u\n"
27124 + "MulticastTransmittedFrameCount=%u\n"
27125 + "FailedCount=%u\n"
27126 + "RetryCount=%u\n"
27127 + "MultipleRetryCount=%d\n"
27128 + "FrameDuplicateCount=%d\n"
27129 + "ReceivedFragmentCount=%u\n"
27130 + "MulticastReceivedFrameCount=%u\n"
27131 + "TransmittedFrameCount=%u\n"
27132 + "WEPUndecryptableCount=%u\n",
27133 + local->dot11TransmittedFragmentCount,
27134 + local->dot11MulticastTransmittedFrameCount,
27135 + local->dot11FailedCount,
27136 + local->dot11RetryCount,
27137 + local->dot11MultipleRetryCount,
27138 + local->dot11FrameDuplicateCount,
27139 + local->dot11ReceivedFragmentCount,
27140 + local->dot11MulticastReceivedFrameCount,
27141 + local->dot11TransmittedFrameCount,
27142 + local->dot11WEPUndecryptableCount);
27144 + memset(&stats, 0, sizeof(stats));
27145 + if (local->hw->get_stats &&
27146 + local->hw->get_stats(local->mdev, &stats) == 0) {
27148 + "ACKFailureCount=%u\n"
27149 + "RTSFailureCount=%u\n"
27150 + "FCSErrorCount=%u\n"
27151 + "RTSSuccessCount=%u\n",
27152 + stats.dot11ACKFailureCount,
27153 + stats.dot11RTSFailureCount,
27154 + stats.dot11FCSErrorCount,
27155 + stats.dot11RTSSuccessCount);
27158 + return (p - page);
27162 +static int ieee80211_proc_debug_read(char *page, char **start, off_t off,
27163 + int count, int *eof, void *data)
27166 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27174 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
27176 + "tx_handlers_drop=%u\n"
27177 + "tx_handlers_queued=%u\n"
27178 + "tx_handlers_drop_unencrypted=%u\n"
27179 + "tx_handlers_drop_fragment=%u\n"
27180 + "tx_handlers_drop_wep=%u\n"
27181 + "tx_handlers_drop_rate_limit=%u\n"
27182 + "tx_handlers_drop_not_assoc=%u\n"
27183 + "tx_handlers_drop_unauth_port=%u\n"
27184 + "rx_handlers_drop=%u\n"
27185 + "rx_handlers_queued=%u\n"
27186 + "rx_handlers_drop_nullfunc=%u\n"
27187 + "rx_handlers_drop_defrag=%u\n"
27188 + "rx_handlers_drop_short=%u\n"
27189 + "rx_handlers_drop_passive_scan=%u\n"
27190 + "tx_expand_skb_head=%u\n"
27191 + "tx_expand_skb_head_cloned=%u\n"
27192 + "rx_expand_skb_head=%u\n"
27193 + "rx_expand_skb_head2=%u\n"
27194 + "rx_handlers_fragments=%u\n"
27195 + "tx_status_drop=%u\n",
27196 + local->tx_handlers_drop,
27197 + local->tx_handlers_queued,
27198 + local->tx_handlers_drop_unencrypted,
27199 + local->tx_handlers_drop_fragment,
27200 + local->tx_handlers_drop_wep,
27201 + local->tx_handlers_drop_rate_limit,
27202 + local->tx_handlers_drop_not_assoc,
27203 + local->tx_handlers_drop_unauth_port,
27204 + local->rx_handlers_drop,
27205 + local->rx_handlers_queued,
27206 + local->rx_handlers_drop_nullfunc,
27207 + local->rx_handlers_drop_defrag,
27208 + local->rx_handlers_drop_short,
27209 + local->rx_handlers_drop_passive_scan,
27210 + local->tx_expand_skb_head,
27211 + local->tx_expand_skb_head_cloned,
27212 + local->rx_expand_skb_head,
27213 + local->rx_expand_skb_head2,
27214 + local->rx_handlers_fragments,
27215 + local->tx_status_drop);
27218 + p += sprintf(p, "wme_rx_queue=");
27219 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27220 + p += sprintf(p, " %u", local->wme_rx_queue[i]);
27221 + p += sprintf(p, "\n");
27223 + p += sprintf(p, "wme_tx_queue=");
27224 + for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
27225 + p += sprintf(p, " %u", local->wme_tx_queue[i]);
27226 + p += sprintf(p, "\n");
27228 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27230 + p += sprintf(p, "num_scans=%u\n", local->scan.num_scans);
27233 + "conf.bss_count=%d\n"
27234 + "bss_dev_count=%u\n",
27235 + local->conf.bss_count, local->bss_dev_count);
27236 + for (i = 0; i < local->conf.bss_count; i++) {
27237 + p += sprintf(p, "bss_dev[%d]=%p (%s)\n",
27238 + i, local->bss_devs[i],
27239 + (i < local->bss_dev_count && local->bss_devs[i]) ?
27240 + local->bss_devs[i]->name : "N/A");
27243 + return (p - page);
27247 +static const char * ieee80211_mode_str_short(int mode)
27250 + case MODE_IEEE80211A:
27251 + return "802.11a";
27252 + case MODE_IEEE80211B:
27253 + return "802.11b";
27254 + case MODE_IEEE80211G:
27255 + return "802.11g";
27256 + case MODE_ATHEROS_TURBO:
27257 + return "AtherosTurbo";
27259 + return "UNKNOWN";
27264 +static const char * ieee80211_mode_str(int mode)
27267 + case MODE_IEEE80211A:
27268 + return "IEEE 802.11a";
27269 + case MODE_IEEE80211B:
27270 + return "IEEE 802.11b";
27271 + case MODE_IEEE80211G:
27272 + return "IEEE 802.11g";
27273 + case MODE_ATHEROS_TURBO:
27274 + return "Atheros Turbo (5 GHz)";
27276 + return "UNKNOWN";
27281 +static int ieee80211_proc_info_read(char *page, char **start, off_t off,
27282 + int count, int *eof, void *data)
27285 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27287 + struct ieee80211_hw_modes *mode;
27294 + p += sprintf(p, "hw_name=%s\n", local->hw->name);
27295 + p += sprintf(p, "modes=");
27296 + for (m = 0; m < local->hw->num_modes; m++) {
27297 + mode = &local->hw->modes[m];
27298 + p += sprintf(p, "[%s]", ieee80211_mode_str_short(mode->mode));
27300 + p += sprintf(p, "\n");
27301 + if (local->rate_ctrl && local->rate_ctrl_priv)
27302 + p+= sprintf(p, "rate_ctrl_alg=%s\n", local->rate_ctrl->name);
27303 + return (p - page);
27307 +static int ieee80211_proc_config_read(char *page, char **start, off_t off,
27308 + int count, int *eof, void *data)
27311 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27319 + "low_level_driver=%s\n"
27324 + "wep_iv=0x%06x\n"
27325 + "antenna_sel=%d\n"
27327 + "tx_power_reduction=%d.%d dBm\n"
27328 + "bridge_packets=%d\n"
27329 + "key_tx_rx_threshold=%d\n"
27330 + "rts_threshold=%d\n"
27331 + "fragmentation_threshold=%d\n"
27332 + "short_retry_limit=%d\n"
27333 + "long_retry_limit=%d\n"
27334 + "total_ps_buffered=%d\n",
27335 + local->hw->name ? local->hw->name : "N/A",
27336 + local->conf.channel,
27337 + local->conf.freq,
27338 + ieee80211_mode_str(local->conf.phymode),
27339 + local->conf.radar_detect,
27340 + local->wep_iv & 0xffffff,
27341 + local->conf.antenna_sel,
27342 + local->conf.calib_int,
27343 + local->conf.tx_power_reduction / 10,
27344 + local->conf.tx_power_reduction % 10,
27345 + local->bridge_packets,
27346 + local->key_tx_rx_threshold,
27347 + local->rts_threshold,
27348 + local->fragmentation_threshold,
27349 + local->short_retry_limit,
27350 + local->long_retry_limit,
27351 + local->total_ps_buffered);
27353 + return (p - page);
27357 +static int ieee80211_proc_channels_read(char *page, char **start, off_t off,
27358 + int count, int *eof, void *data)
27361 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27363 + struct ieee80211_hw_modes *mode;
27364 + struct ieee80211_channel *chan;
27371 + p += sprintf(p, "MODE CHAN FREQ TXPOWER ANTMAX FLAGS\n");
27372 + for (m = 0; m < local->hw->num_modes; m++) {
27373 + mode = &local->hw->modes[m];
27374 + for (c = 0; c < mode->num_channels; c++) {
27375 + chan = &mode->channels[c];
27376 + p += sprintf(p, "%d %d %d %d %d %s%s%s\n",
27377 + mode->mode, chan->chan, chan->freq,
27378 + chan->power_level, chan->antenna_max,
27379 + chan->flag & IEEE80211_CHAN_W_SCAN ?
27381 + chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN
27382 + ? "[W_ACTIVE_SCAN]" : "",
27383 + chan->flag & IEEE80211_CHAN_W_IBSS ?
27384 + "[W_IBSS]" : "");
27387 + return (p - page);
27391 +static int ieee80211_proc_rates_read(char *page, char **start, off_t off,
27392 + int count, int *eof, void *data)
27395 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27397 + struct ieee80211_rate *rate;
27404 + p += sprintf(p, "RATE VAL VAL2 MIN_RSSI_ACK MIN_RSSI_ACK_DELTA "
27406 + for (r = 0; r < local->num_curr_rates; r++) {
27407 + rate = &local->curr_rates[r];
27408 + p += sprintf(p, "%d %d %d %d %d 0x%x %s%s%s%s%s%s%s%s\n",
27409 + rate->rate, rate->val, rate->val2,
27410 + rate->min_rssi_ack, rate->min_rssi_ack_delta,
27412 + rate->flags & IEEE80211_RATE_ERP ? "[ERP]" : "",
27413 + rate->flags & IEEE80211_RATE_BASIC ?
27415 + rate->flags & IEEE80211_RATE_PREAMBLE2 ?
27416 + "[PREAMBLE2]" : "",
27417 + rate->flags & IEEE80211_RATE_SUPPORTED ?
27418 + "[SUPPORTED]" : "",
27419 + rate->flags & IEEE80211_RATE_OFDM ? "[OFDM]" : "",
27420 + rate->flags & IEEE80211_RATE_CCK ? "[CCK]" : "",
27421 + rate->flags & IEEE80211_RATE_TURBO ?
27423 + rate->flags & IEEE80211_RATE_MANDATORY ?
27424 + "[MANDATORY]" : "");
27426 + return (p - page);
27430 +static int ieee80211_proc_multicast_read(char *page, char **start, off_t off,
27431 + int count, int *eof, void *data)
27434 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27441 + return rate_control_status_global(local, p);
27446 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27447 + struct sta_info *sta)
27450 + struct proc_dir_entry *entry;
27452 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27454 + if (!local->proc_sta)
27457 + entry = create_proc_read_entry(buf, 0, local->proc_sta,
27458 + ieee80211_proc_sta_read, sta);
27460 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27461 + sta->proc_entry_added = 1;
27466 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27467 + struct sta_info *sta)
27470 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27471 + if (local->proc_sta) {
27472 + remove_proc_entry(buf, local->proc_sta);
27473 + sta->proc_entry_added = 0;
27478 +void ieee80211_proc_init_virtual(struct net_device *dev)
27480 + struct proc_dir_entry *entry;
27481 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27483 + if (!local->proc_iface)
27486 + entry = create_proc_read_entry(dev->name, 0, local->proc_iface,
27487 + ieee80211_proc_iface_read, dev);
27489 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27493 +void ieee80211_proc_deinit_virtual(struct net_device *dev)
27495 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27497 + if (local->proc_iface)
27498 + remove_proc_entry(dev->name, local->proc_iface);
27502 +void ieee80211_proc_init_interface(struct ieee80211_local *local)
27504 + if (!ieee80211_proc)
27507 + local->proc = proc_mkdir(local->wdev->name, ieee80211_proc);
27508 + if (!local->proc)
27511 + local->proc_sta = proc_mkdir("sta", local->proc);
27512 + local->proc_iface = proc_mkdir("iface", local->proc);
27513 + create_proc_read_entry("counters", 0, local->proc,
27514 + ieee80211_proc_counters_read, local);
27515 + create_proc_read_entry("config", 0, local->proc,
27516 + ieee80211_proc_config_read, local);
27517 + create_proc_read_entry("channels", 0, local->proc,
27518 + ieee80211_proc_channels_read, local);
27519 + create_proc_read_entry("rates", 0, local->proc,
27520 + ieee80211_proc_rates_read, local);
27521 + create_proc_read_entry("multicast", 0, local->proc,
27522 + ieee80211_proc_multicast_read, local);
27523 + create_proc_read_entry("debug", 0, local->proc,
27524 + ieee80211_proc_debug_read, local);
27525 + create_proc_read_entry("info", 0, local->proc,
27526 + ieee80211_proc_info_read, local);
27527 + ieee80211_proc_init_virtual(local->wdev);
27531 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local)
27533 + if (!local->proc)
27536 + ieee80211_proc_deinit_virtual(local->wdev);
27537 + remove_proc_entry("iface", local->proc);
27538 + remove_proc_entry("sta", local->proc);
27539 + remove_proc_entry("counters", local->proc);
27540 + remove_proc_entry("debug", local->proc);
27541 + remove_proc_entry("config", local->proc);
27542 + remove_proc_entry("channels", local->proc);
27543 + remove_proc_entry("rates", local->proc);
27544 + remove_proc_entry("multicast", local->proc);
27545 + remove_proc_entry("info", local->proc);
27546 + local->proc = NULL;
27547 + remove_proc_entry(local->wdev->name, ieee80211_proc);
27551 +void ieee80211_proc_init(void)
27553 + if (proc_net == NULL) {
27554 + ieee80211_proc = NULL;
27558 + ieee80211_proc = proc_mkdir("ieee80211", proc_net);
27559 + if (!ieee80211_proc)
27560 + printk(KERN_WARNING "Failed to mkdir /proc/net/ieee80211\n");
27564 +void ieee80211_proc_deinit(void)
27566 + if (!ieee80211_proc)
27569 + ieee80211_proc = NULL;
27570 + remove_proc_entry("ieee80211", proc_net);
27573 +#endif /* CONFIG_PROC_FS */
27574 diff -Nur linux-2.6.16/net/d80211/ieee80211_proc.h linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.h
27575 --- linux-2.6.16/net/d80211/ieee80211_proc.h 1970-01-01 01:00:00.000000000 +0100
27576 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_proc.h 2006-03-28 22:16:14.000000000 +0200
27579 + * Copyright 2003-2004, Instant802 Networks, Inc.
27581 + * This program is free software; you can redistribute it and/or modify
27582 + * it under the terms of the GNU General Public License version 2 as
27583 + * published by the Free Software Foundation.
27586 +#ifndef IEEE80211_PROC_H
27587 +#define IEEE80211_PROC_H
27589 +#include <linux/netdevice.h>
27590 +#include "ieee80211_i.h"
27591 +#include "sta_info.h"
27593 +#ifdef CONFIG_PROC_FS
27595 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27596 + struct sta_info *sta);
27597 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27598 + struct sta_info *sta);
27599 +void ieee80211_proc_init_virtual(struct net_device *dev);
27600 +void ieee80211_proc_deinit_virtual(struct net_device *dev);
27601 +void ieee80211_proc_init_interface(struct ieee80211_local *local);
27602 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local);
27603 +void ieee80211_proc_init(void);
27604 +void ieee80211_proc_deinit(void);
27606 +#else /* CONFIG_PROC_FS */
27608 +static inline void ieee80211_proc_init_sta(struct ieee80211_local *local,
27609 + struct sta_info *sta) {}
27610 +static inline void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27611 + struct sta_info *sta) {}
27612 +static inline void ieee80211_proc_init_virtual(struct net_device *dev) {}
27613 +static inline void ieee80211_proc_deinit_virtual(struct net_device *dev) {}
27614 +static inline void
27615 +ieee80211_proc_init_interface(struct ieee80211_local *local) {}
27616 +static inline void
27617 +ieee80211_proc_deinit_interface(struct ieee80211_local *local) {}
27618 +static inline void ieee80211_proc_init(void) {}
27619 +static inline void ieee80211_proc_deinit(void) {}
27620 +#endif /* CONFIG_PROC_FS */
27622 +#endif /* IEEE80211_PROC_H */
27623 diff -Nur linux-2.6.16/net/d80211/ieee80211_scan.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_scan.c
27624 --- linux-2.6.16/net/d80211/ieee80211_scan.c 1970-01-01 01:00:00.000000000 +0100
27625 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_scan.c 2006-03-28 22:16:14.000000000 +0200
27628 + * Copyright 2002-2004, Instant802 Networks, Inc.
27630 + * This program is free software; you can redistribute it and/or modify
27631 + * it under the terms of the GNU General Public License version 2 as
27632 + * published by the Free Software Foundation.
27635 +#include <linux/config.h>
27636 +#include <linux/version.h>
27637 +#include <linux/module.h>
27638 +#include <linux/netdevice.h>
27639 +#include <linux/types.h>
27640 +#include <linux/slab.h>
27641 +#include <linux/skbuff.h>
27643 +#include <net/d80211.h>
27644 +#include "ieee80211_i.h"
27645 +#include "rate_control.h"
27648 +/* Maximum number of seconds to wait for the traffic load to get below
27649 + * threshold before forcing a passive scan. */
27650 +#define MAX_SCAN_WAIT 60
27651 +/* Threshold (pkts/sec TX or RX) for delaying passive scan */
27652 +#define SCAN_TXRX_THRESHOLD 75
27654 +static void get_channel_params(struct ieee80211_local *local, int channel,
27655 + struct ieee80211_hw_modes **mode,
27656 + struct ieee80211_channel **chan)
27660 + for (m = 0; m < local->hw->num_modes; m++) {
27661 + *mode = &local->hw->modes[m];
27662 + if ((*mode)->mode == local->conf.phymode)
27665 + local->scan.mode_idx = m;
27666 + local->scan.chan_idx = 0;
27668 + *chan = &(*mode)->channels[local->scan.chan_idx];
27669 + if ((*chan)->chan == channel) {
27672 + local->scan.chan_idx++;
27673 + } while (local->scan.chan_idx < (*mode)->num_channels);
27678 +static void next_chan_same_mode(struct ieee80211_local *local,
27679 + struct ieee80211_hw_modes **mode,
27680 + struct ieee80211_channel **chan)
27684 + for (m = 0; m < local->hw->num_modes; m++) {
27685 + *mode = &local->hw->modes[m];
27686 + if ((*mode)->mode == local->conf.phymode)
27689 + local->scan.mode_idx = m;
27691 + /* Select next channel - scan only channels marked with W_SCAN flag */
27692 + prev = local->scan.chan_idx;
27694 + local->scan.chan_idx++;
27695 + if (local->scan.chan_idx >= (*mode)->num_channels)
27696 + local->scan.chan_idx = 0;
27697 + *chan = &(*mode)->channels[local->scan.chan_idx];
27698 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27700 + } while (local->scan.chan_idx != prev);
27704 +static void next_chan_all_modes(struct ieee80211_local *local,
27705 + struct ieee80211_hw_modes **mode,
27706 + struct ieee80211_channel **chan)
27708 + int prev, prev_m;
27710 + if (local->scan.mode_idx >= local->hw->num_modes) {
27711 + local->scan.mode_idx = 0;
27712 + local->scan.chan_idx = 0;
27715 + /* Select next channel - scan only channels marked with W_SCAN flag */
27716 + prev = local->scan.chan_idx;
27717 + prev_m = local->scan.mode_idx;
27719 + *mode = &local->hw->modes[local->scan.mode_idx];
27720 + local->scan.chan_idx++;
27721 + if (local->scan.chan_idx >= (*mode)->num_channels) {
27722 + local->scan.chan_idx = 0;
27723 + local->scan.mode_idx++;
27724 + if (local->scan.mode_idx >= local->hw->num_modes)
27725 + local->scan.mode_idx = 0;
27726 + *mode = &local->hw->modes[local->scan.mode_idx];
27728 + *chan = &(*mode)->channels[local->scan.chan_idx];
27729 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27731 + } while (local->scan.chan_idx != prev ||
27732 + local->scan.mode_idx != prev_m);
27736 +static void ieee80211_scan_start(struct net_device *dev,
27737 + struct ieee80211_scan_conf *conf)
27739 + struct ieee80211_local *local = dev->priv;
27740 + int old_mode_idx = local->scan.mode_idx;
27741 + int old_chan_idx = local->scan.chan_idx;
27742 + struct ieee80211_hw_modes *mode = NULL;
27743 + struct ieee80211_channel *chan = NULL;
27746 + if (local->hw->passive_scan == 0) {
27747 + printk(KERN_DEBUG "%s: Scan handler called, yet the hardware "
27748 + "does not support passive scanning. Disabled.\n",
27753 + if ((local->scan.tries < MAX_SCAN_WAIT &&
27754 + local->scan.txrx_count > SCAN_TXRX_THRESHOLD)) {
27755 + local->scan.tries++;
27756 + /* Count TX/RX packets during one second interval and allow
27757 + * scan to start only if the number of packets is below the
27759 + local->scan.txrx_count = 0;
27760 + local->scan.timer.expires = jiffies + HZ;
27761 + add_timer(&local->scan.timer);
27765 + if (local->scan.skb == NULL) {
27766 + printk(KERN_DEBUG "%s: Scan start called even though scan.skb "
27767 + "is not set\n", dev->name);
27770 + if (local->scan.our_mode_only) {
27771 + if (local->scan.channel > 0) {
27772 + get_channel_params(local, local->scan.channel, &mode,
27775 + next_chan_same_mode(local, &mode, &chan);
27778 + next_chan_all_modes(local, &mode, &chan);
27780 + conf->scan_channel = chan->chan;
27781 + conf->scan_freq = chan->freq;
27782 + conf->scan_channel_val = chan->val;
27783 + conf->scan_phymode = mode->mode;
27784 + conf->scan_power_level = chan->power_level;
27785 + conf->scan_antenna_max = chan->antenna_max;
27786 + conf->scan_time = 2 * local->hw->channel_change_time +
27787 + local->scan.time; /* 10ms scan time+hardware changes */
27788 + conf->skb = local->scan.skb ?
27789 + skb_clone(local->scan.skb, GFP_ATOMIC) : NULL;
27790 + conf->tx_control = &local->scan.tx_control;
27792 + printk(KERN_DEBUG "%s: Doing scan on mode: %d freq: %d chan: %d "
27794 + dev->name, conf->scan_phymode, conf->scan_freq,
27795 + conf->scan_channel, conf->scan_time);
27797 + local->scan.rx_packets = 0;
27798 + local->scan.rx_beacon = 0;
27799 + local->scan.freq = chan->freq;
27800 + local->scan.in_scan = 1;
27802 + ieee80211_netif_oper(dev, NETIF_STOP);
27804 + ret = local->hw->passive_scan(dev, IEEE80211_SCAN_START, conf);
27807 + long usec = local->hw->channel_change_time +
27808 + local->scan.time;
27809 + usec += 1000000L / HZ - 1;
27810 + usec /= 1000000L / HZ;
27811 + local->scan.timer.expires = jiffies + usec;
27813 + local->scan.in_scan = 0;
27815 + dev_kfree_skb(conf->skb);
27816 + ieee80211_netif_oper(dev, NETIF_WAKE);
27817 + if (ret == -EAGAIN) {
27818 + local->scan.timer.expires = jiffies +
27819 + (local->scan.interval * HZ / 100);
27820 + local->scan.mode_idx = old_mode_idx;
27821 + local->scan.chan_idx = old_chan_idx;
27823 + printk(KERN_DEBUG "%s: Got unknown error from "
27824 + "passive_scan %d\n", dev->name, ret);
27825 + local->scan.timer.expires = jiffies +
27826 + (local->scan.interval * HZ);
27828 + local->scan.in_scan = 0;
27831 + add_timer(&local->scan.timer);
27835 +static void ieee80211_scan_stop(struct net_device *dev,
27836 + struct ieee80211_scan_conf *conf)
27838 + struct ieee80211_local *local = dev->priv;
27839 + struct ieee80211_hw_modes *mode;
27840 + struct ieee80211_channel *chan;
27843 + if (local->hw->passive_scan == NULL)
27846 + if (local->scan.mode_idx >= local->hw->num_modes) {
27847 + local->scan.mode_idx = 0;
27848 + local->scan.chan_idx = 0;
27851 + mode = &local->hw->modes[local->scan.mode_idx];
27853 + if (local->scan.chan_idx >= mode->num_channels) {
27854 + local->scan.chan_idx = 0;
27857 + chan = &mode->channels[local->scan.chan_idx];
27859 + local->hw->passive_scan(dev, IEEE80211_SCAN_END, conf);
27861 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
27862 + printk(KERN_DEBUG "%s: Did scan on mode: %d freq: %d chan: %d "
27863 + "GOT: %d Beacon: %d (%d)\n",
27865 + mode->mode, chan->freq, chan->chan,
27866 + local->scan.rx_packets, local->scan.rx_beacon,
27867 + local->scan.tries);
27868 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
27869 + local->scan.num_scans++;
27871 + local->scan.in_scan = 0;
27872 + ieee80211_netif_oper(dev, NETIF_WAKE);
27874 + local->scan.tries = 0;
27875 + /* Use random interval of scan.interval .. 2 * scan.interval */
27876 + wait = (local->scan.interval * HZ * ((net_random() & 127) + 128)) /
27878 + local->scan.timer.expires = jiffies + wait;
27880 + add_timer(&local->scan.timer);
27884 +static void ieee80211_scan_handler(unsigned long uldev)
27886 + struct net_device *dev = (struct net_device *) uldev;
27887 + struct ieee80211_local *local = dev->priv;
27888 + struct ieee80211_scan_conf conf;
27890 + if (local->scan.interval == 0 && !local->scan.in_scan) {
27891 + /* Passive scanning is disabled - keep the timer always
27892 + * running to make code cleaner. */
27893 + local->scan.timer.expires = jiffies + 10 * HZ;
27894 + add_timer(&local->scan.timer);
27898 + memset(&conf, 0, sizeof(struct ieee80211_scan_conf));
27899 + conf.running_freq = local->conf.freq;
27900 + conf.running_channel = local->conf.channel;
27901 + conf.running_phymode = local->conf.phymode;
27902 + conf.running_channel_val = local->conf.channel_val;
27903 + conf.running_power_level = local->conf.power_level;
27904 + conf.running_antenna_max = local->conf.antenna_max;
27906 + if (local->scan.in_scan == 0)
27907 + ieee80211_scan_start(dev, &conf);
27909 + ieee80211_scan_stop(dev, &conf);
27913 +void ieee80211_init_scan(struct net_device *dev)
27915 + struct ieee80211_local *local = dev->priv;
27916 + struct ieee80211_hdr hdr;
27919 + struct rate_control_extra extra;
27921 + /* Only initialize passive scanning if the hardware supports it */
27922 + if (!local->hw->passive_scan) {
27923 + local->scan.skb = NULL;
27924 + memset(&local->scan.tx_control, 0,
27925 + sizeof(local->scan.tx_control));
27926 + printk(KERN_DEBUG "%s: Does not support passive scan, "
27927 + "disabled\n", dev->name);
27931 + local->scan.interval = 0;
27932 + local->scan.our_mode_only = 1;
27933 + local->scan.time = 10000;
27934 + local->scan.timer.function = ieee80211_scan_handler;
27935 + local->scan.timer.data = (unsigned long) dev;
27936 + local->scan.timer.expires = jiffies + local->scan.interval * HZ;
27937 + add_timer(&local->scan.timer);
27939 + /* Create a CTS from for broadcasting before
27940 + * the low level changes channels */
27941 + local->scan.skb = alloc_skb(len, GFP_KERNEL);
27942 + if (local->scan.skb == NULL) {
27943 + printk(KERN_WARNING "%s: Failed to allocate CTS packet for "
27944 + "passive scan\n", dev->name);
27948 + fc = (WLAN_FC_TYPE_CTRL << 2) | (WLAN_FC_STYPE_CTS << 4);
27949 + hdr.frame_control = cpu_to_le16(fc);
27950 + hdr.duration_id =
27951 + cpu_to_le16(2 * local->hw->channel_change_time +
27952 + local->scan.time);
27953 + memcpy(hdr.addr1, dev->dev_addr, ETH_ALEN); /* DA */
27954 + hdr.seq_ctrl = 0;
27956 + memcpy(skb_put(local->scan.skb, len), &hdr, len);
27958 + memset(&local->scan.tx_control, 0, sizeof(local->scan.tx_control));
27959 + local->scan.tx_control.key_idx = HW_KEY_IDX_INVALID;
27960 + local->scan.tx_control.do_not_encrypt = 1;
27961 + memset(&extra, 0, sizeof(extra));
27962 + extra.endidx = local->num_curr_rates;
27963 + local->scan.tx_control.tx_rate =
27964 + rate_control_get_rate(dev, local->scan.skb, &extra)->val;
27965 + local->scan.tx_control.no_ack = 1;
27969 +void ieee80211_stop_scan(struct net_device *dev)
27971 + struct ieee80211_local *local = dev->priv;
27973 + if (local->hw->passive_scan != 0) {
27974 + del_timer_sync(&local->scan.timer);
27975 + dev_kfree_skb(local->scan.skb);
27976 + local->scan.skb = NULL;
27979 diff -Nur linux-2.6.16/net/d80211/ieee80211_sta.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_sta.c
27980 --- linux-2.6.16/net/d80211/ieee80211_sta.c 1970-01-01 01:00:00.000000000 +0100
27981 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_sta.c 2006-03-28 22:16:14.000000000 +0200
27984 + * BSS client mode implementation
27985 + * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
27986 + * Copyright 2004, Instant802 Networks, Inc.
27987 + * Copyright 2005, Devicescape Software, Inc.
27989 + * This program is free software; you can redistribute it and/or modify
27990 + * it under the terms of the GNU General Public License version 2 as
27991 + * published by the Free Software Foundation.
27995 + * BSS table: use <BSSID,SSID> as the key to support multi-SSID APs
27996 + * order BSS list by RSSI(?) ("quality of AP")
27997 + * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE,
28000 +#include <linux/config.h>
28001 +#include <linux/version.h>
28002 +#include <linux/if_ether.h>
28003 +#include <linux/skbuff.h>
28004 +#include <linux/netdevice.h>
28005 +#include <linux/if_arp.h>
28006 +#include <linux/wireless.h>
28007 +#include <linux/random.h>
28008 +#include <net/iw_handler.h>
28009 +#include <asm/types.h>
28010 +#include <asm/delay.h>
28012 +#include <net/d80211.h>
28013 +#include <net/d80211_mgmt.h>
28014 +#include "ieee80211_i.h"
28015 +#include "rate_control.h"
28016 +#include "hostapd_ioctl.h"
28018 +/* #define IEEE80211_IBSS_DEBUG */
28020 +#define IEEE80211_AUTH_TIMEOUT (HZ / 5)
28021 +#define IEEE80211_AUTH_MAX_TRIES 3
28022 +#define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
28023 +#define IEEE80211_ASSOC_MAX_TRIES 3
28024 +#define IEEE80211_MONITORING_INTERVAL (2 * HZ)
28025 +#define IEEE80211_PROBE_INTERVAL (60 * HZ)
28026 +#define IEEE80211_RETRY_AUTH_INTERVAL (1 * HZ)
28027 +#define IEEE80211_SCAN_INTERVAL (2 * HZ)
28028 +#define IEEE80211_SCAN_INTERVAL_SLOW (15 * HZ)
28029 +#define IEEE80211_IBSS_JOIN_TIMEOUT (20 * HZ)
28031 +#define IEEE80211_PROBE_DELAY (HZ / 33)
28032 +#define IEEE80211_CHANNEL_TIME (HZ / 33)
28033 +#define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
28034 +#define IEEE80211_SCAN_RESULT_EXPIRE (10 * HZ)
28035 +#define IEEE80211_IBSS_MERGE_INTERVAL (30 * HZ)
28036 +#define IEEE80211_IBSS_INACTIVITY_LIMIT (60 * HZ)
28038 +#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
28041 +#define IEEE80211_FC(type, stype) cpu_to_le16((type << 2) | (stype << 4))
28043 +#define ERP_INFO_USE_PROTECTION BIT(1)
28045 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
28046 + u8 *ssid, size_t ssid_len);
28047 +static struct ieee80211_sta_bss *
28048 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid);
28049 +static void ieee80211_rx_bss_put(struct net_device *dev,
28050 + struct ieee80211_sta_bss *bss);
28051 +static int ieee80211_sta_find_ibss(struct net_device *dev,
28052 + struct ieee80211_if_sta *ifsta);
28053 +static int ieee80211_sta_wep_configured(struct net_device *dev);
28056 +/* Parsed Information Elements */
28057 +struct ieee802_11_elems {
28061 + u8 supp_rates_len;
28063 + u8 fh_params_len;
28065 + u8 ds_params_len;
28067 + u8 cf_params_len;
28071 + u8 ibss_params_len;
28073 + u8 challenge_len;
28080 + u8 *ext_supp_rates;
28081 + u8 ext_supp_rates_len;
28085 + u8 wmm_param_len;
28088 +typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
28091 +static ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
28092 + struct ieee802_11_elems *elems)
28094 + size_t left = len;
28098 + memset(elems, 0, sizeof(*elems));
28100 + while (left >= 2) {
28107 + if (elen > left) {
28109 + if (net_ratelimit())
28110 + printk(KERN_DEBUG "IEEE 802.11 element parse "
28111 + "failed (id=%d elen=%d left=%d)\n",
28114 + return ParseFailed;
28118 + case WLAN_EID_SSID:
28119 + elems->ssid = pos;
28120 + elems->ssid_len = elen;
28122 + case WLAN_EID_SUPP_RATES:
28123 + elems->supp_rates = pos;
28124 + elems->supp_rates_len = elen;
28126 + case WLAN_EID_FH_PARAMS:
28127 + elems->fh_params = pos;
28128 + elems->fh_params_len = elen;
28130 + case WLAN_EID_DS_PARAMS:
28131 + elems->ds_params = pos;
28132 + elems->ds_params_len = elen;
28134 + case WLAN_EID_CF_PARAMS:
28135 + elems->cf_params = pos;
28136 + elems->cf_params_len = elen;
28138 + case WLAN_EID_TIM:
28139 + elems->tim = pos;
28140 + elems->tim_len = elen;
28142 + case WLAN_EID_IBSS_PARAMS:
28143 + elems->ibss_params = pos;
28144 + elems->ibss_params_len = elen;
28146 + case WLAN_EID_CHALLENGE:
28147 + elems->challenge = pos;
28148 + elems->challenge_len = elen;
28150 + case WLAN_EID_WPA:
28151 + if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
28152 + pos[2] == 0xf2) {
28153 + /* Microsoft OUI (00:50:F2) */
28154 + if (pos[3] == 1) {
28155 + /* OUI Type 1 - WPA IE */
28156 + elems->wpa = pos;
28157 + elems->wpa_len = elen;
28158 + } else if (elen >= 5 && pos[3] == 2) {
28159 + if (pos[4] == 0) {
28160 + elems->wmm_info = pos;
28161 + elems->wmm_info_len = elen;
28162 + } else if (pos[4] == 1) {
28163 + elems->wmm_param = pos;
28164 + elems->wmm_param_len = elen;
28169 + case WLAN_EID_RSN:
28170 + elems->rsn = pos;
28171 + elems->rsn_len = elen;
28173 + case WLAN_EID_ERP_INFO:
28174 + elems->erp_info = pos;
28175 + elems->erp_info_len = elen;
28177 + case WLAN_EID_EXT_SUPP_RATES:
28178 + elems->ext_supp_rates = pos;
28179 + elems->ext_supp_rates_len = elen;
28183 + printk(KERN_DEBUG "IEEE 802.11 element parse ignored "
28184 + "unknown element (id=%d elen=%d)\n",
28195 + /* Do not trigger error if left == 1 as Apple Airport base stations
28196 + * send AssocResps that are one spurious byte too long. */
28198 + return unknown ? ParseUnknown : ParseOK;
28204 +static int ecw2cw(int ecw)
28207 + while (ecw > 0) {
28215 +static void ieee80211_sta_wmm_params(struct net_device *dev,
28216 + struct ieee80211_if_sta *ifsta,
28217 + u8 *wmm_param, size_t wmm_param_len)
28219 + struct ieee80211_local *local = dev->priv;
28220 + struct ieee80211_tx_queue_params params;
28225 + if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
28227 + count = wmm_param[6] & 0x0f;
28228 + if (count == ifsta->wmm_last_param_set)
28230 + ifsta->wmm_last_param_set = count;
28232 + pos = wmm_param + 8;
28233 + left = wmm_param_len - 8;
28235 + memset(¶ms, 0, sizeof(params));
28237 + if (local->hw->conf_tx == NULL)
28240 + local->wmm_acm = 0;
28241 + for (; left >= 4; left -= 4, pos += 4) {
28242 + int aci = (pos[0] >> 5) & 0x03;
28243 + int acm = (pos[0] >> 4) & 0x01;
28248 + queue = IEEE80211_TX_QUEUE_DATA3;
28250 + local->wmm_acm |= BIT(1) | BIT(2);
28254 + queue = IEEE80211_TX_QUEUE_DATA1;
28256 + local->wmm_acm |= BIT(4) | BIT(5);
28260 + queue = IEEE80211_TX_QUEUE_DATA0;
28262 + local->wmm_acm |= BIT(6) | BIT(7);
28267 + queue = IEEE80211_TX_QUEUE_DATA2;
28269 + local->wmm_acm |= BIT(0) | BIT(3);
28274 + params.aifs = pos[0] & 0x0f;
28275 + params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
28276 + params.cw_min = ecw2cw(pos[1] & 0x0f);
28277 + /* TXOP is in units of 32 usec; burst_time in 0.1 ms */
28278 + params.burst_time = (pos[2] | (pos[3] << 8)) * 32 / 100;
28279 + printk(KERN_DEBUG "%s: WMM queue=%d aci=%d acm=%d aifs=%d "
28280 + "cWmin=%d cWmax=%d burst=%d\n",
28281 + dev->name, queue, aci, acm, params.aifs, params.cw_min,
28282 + params.cw_max, params.burst_time);
28283 + /* TODO: handle ACM (block TX, fallback to next lowest allowed
28285 + if (local->hw->conf_tx(local->mdev, queue, ¶ms)) {
28286 + printk(KERN_DEBUG "%s: failed to set TX queue "
28287 + "parameters for queue %d\n", dev->name, queue);
28293 +static void ieee80211_sta_send_associnfo(struct net_device *dev,
28294 + struct ieee80211_if_sta *ifsta)
28299 + union iwreq_data wrqu;
28301 + if (ifsta->assocreq_ies == NULL && ifsta->assocresp_ies == NULL)
28304 + buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
28305 + ifsta->assocresp_ies_len), GFP_ATOMIC);
28309 + len = sprintf(buf, "ASSOCINFO(");
28310 + if (ifsta->assocreq_ies) {
28311 + len += sprintf(buf + len, "ReqIEs=");
28312 + for (i = 0; i < ifsta->assocreq_ies_len; i++) {
28313 + len += sprintf(buf + len, "%02x",
28314 + ifsta->assocreq_ies[i]);
28317 + if (ifsta->assocresp_ies) {
28318 + if (ifsta->assocreq_ies)
28319 + len += sprintf(buf + len, " ");
28320 + len += sprintf(buf + len, "RespIEs=");
28321 + for (i = 0; i < ifsta->assocresp_ies_len; i++) {
28322 + len += sprintf(buf + len, "%02x",
28323 + ifsta->assocresp_ies[i]);
28326 + len += sprintf(buf + len, ")");
28328 + if (len > IW_CUSTOM_MAX) {
28329 + len = sprintf(buf, "ASSOCRESPIE=");
28330 + for (i = 0; i < ifsta->assocresp_ies_len; i++) {
28331 + len += sprintf(buf + len, "%02x",
28332 + ifsta->assocresp_ies[i]);
28336 + memset(&wrqu, 0, sizeof(wrqu));
28337 + wrqu.data.length = len;
28338 + wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
28344 +static void ieee80211_set_associated(struct net_device *dev,
28345 + struct ieee80211_if_sta *ifsta, int assoc)
28347 + union iwreq_data wrqu;
28349 + if (ifsta->associated == assoc)
28352 + ifsta->associated = assoc;
28355 + struct ieee80211_sub_if_data *sdata;
28356 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28357 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
28359 + ifsta->prev_bssid_set = 1;
28360 + memcpy(ifsta->prev_bssid, sdata->u.sta.bssid, ETH_ALEN);
28361 + memcpy(wrqu.ap_addr.sa_data, sdata->u.sta.bssid, ETH_ALEN);
28362 + ieee80211_sta_send_associnfo(dev, ifsta);
28364 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28366 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28367 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28368 + ifsta->last_probe = jiffies;
28372 +static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
28373 + int encrypt, int probe_resp)
28375 + struct ieee80211_sub_if_data *sdata;
28376 + struct ieee80211_tx_packet_data *pkt_data;
28378 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28379 + skb->dev = sdata->master;
28380 + skb->mac.raw = skb->nh.raw = skb->h.raw = skb->data;
28382 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
28383 + memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
28384 + pkt_data->sdata = sdata;
28385 + pkt_data->do_not_encrypt = !encrypt;
28387 + pkt_data->pkt_probe_resp = 1;
28389 + dev_queue_xmit(skb);
28393 +static void ieee80211_send_auth(struct net_device *dev,
28394 + struct ieee80211_if_sta *ifsta,
28395 + int transaction, u8 *extra, size_t extra_len,
28398 + struct sk_buff *skb;
28399 + struct ieee80211_mgmt *mgmt;
28401 + skb = dev_alloc_skb(sizeof(*mgmt) + 6 + extra_len);
28402 + if (skb == NULL) {
28403 + printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
28404 + "frame\n", dev->name);
28408 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
28409 + memset(mgmt, 0, 24 + 6);
28410 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28411 + WLAN_FC_STYPE_AUTH);
28413 + mgmt->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
28414 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28415 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28416 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28417 + mgmt->u.auth.auth_alg = cpu_to_le16(ifsta->auth_alg);
28418 + mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
28419 + ifsta->auth_transaction = transaction + 1;
28420 + mgmt->u.auth.status_code = cpu_to_le16(0);
28422 + memcpy(skb_put(skb, extra_len), extra, extra_len);
28424 + ieee80211_sta_tx(dev, skb, encrypt, 0);
28428 +static void ieee80211_authenticate(struct net_device *dev,
28429 + struct ieee80211_if_sta *ifsta)
28431 + ifsta->auth_tries++;
28432 + if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
28433 + printk(KERN_DEBUG "%s: authentication with AP " MACSTR
28435 + dev->name, MAC2STR(ifsta->bssid));
28439 + ifsta->state = IEEE80211_AUTHENTICATE;
28440 + printk(KERN_DEBUG "%s: authenticate with AP " MACSTR "\n",
28441 + dev->name, MAC2STR(ifsta->bssid));
28443 + ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
28445 + mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
28449 +static void ieee80211_send_assoc(struct net_device *dev,
28450 + struct ieee80211_if_sta *ifsta)
28452 + struct ieee80211_local *local = dev->priv;
28453 + struct sk_buff *skb;
28454 + struct ieee80211_mgmt *mgmt;
28458 + struct ieee80211_sta_bss *bss;
28461 + skb = dev_alloc_skb(sizeof(*mgmt) + 200 + ifsta->extra_ie_len +
28462 + ifsta->ssid_len);
28463 + if (skb == NULL) {
28464 + printk(KERN_DEBUG "%s: failed to allocate buffer for assoc "
28465 + "frame\n", dev->name);
28469 + capab = ifsta->capab;
28470 + if (local->conf.phymode == MODE_IEEE80211G) {
28471 + capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
28472 + WLAN_CAPABILITY_SHORT_PREAMBLE;
28474 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28476 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
28477 + capab |= WLAN_CAPABILITY_PRIVACY;
28478 + if (bss->wmm_ie) {
28481 + ieee80211_rx_bss_put(dev, bss);
28484 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28485 + memset(mgmt, 0, 24);
28486 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28487 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28488 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28490 + if (ifsta->prev_bssid_set) {
28491 + skb_put(skb, 10);
28492 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28493 + WLAN_FC_STYPE_REASSOC_REQ);
28494 + mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
28495 + mgmt->u.reassoc_req.listen_interval = cpu_to_le16(1);
28496 + memcpy(mgmt->u.reassoc_req.current_ap, ifsta->prev_bssid,
28500 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28501 + WLAN_FC_STYPE_ASSOC_REQ);
28502 + mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
28503 + mgmt->u.assoc_req.listen_interval = cpu_to_le16(1);
28507 + ies = pos = skb_put(skb, 2 + ifsta->ssid_len);
28508 + *pos++ = WLAN_EID_SSID;
28509 + *pos++ = ifsta->ssid_len;
28510 + memcpy(pos, ifsta->ssid, ifsta->ssid_len);
28512 + len = local->num_curr_rates;
28515 + pos = skb_put(skb, len + 2);
28516 + *pos++ = WLAN_EID_SUPP_RATES;
28518 + for (i = 0; i < len; i++) {
28519 + int rate = local->curr_rates[i].rate;
28520 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28522 + *pos++ = (u8) (rate / 5);
28525 + if (local->num_curr_rates > len) {
28526 + pos = skb_put(skb, local->num_curr_rates - len + 2);
28527 + *pos++ = WLAN_EID_EXT_SUPP_RATES;
28528 + *pos++ = local->num_curr_rates - len;
28529 + for (i = len; i < local->num_curr_rates; i++) {
28530 + int rate = local->curr_rates[i].rate;
28531 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28533 + *pos++ = (u8) (rate / 5);
28537 + if (ifsta->extra_ie) {
28538 + pos = skb_put(skb, ifsta->extra_ie_len);
28539 + memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
28542 + if (wmm && ifsta->wmm_enabled) {
28543 + pos = skb_put(skb, 9);
28544 + *pos++ = WLAN_EID_VENDOR_SPECIFIC;
28545 + *pos++ = 7; /* len */
28546 + *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */
28549 + *pos++ = 2; /* WME */
28550 + *pos++ = 0; /* WME info */
28551 + *pos++ = 1; /* WME ver */
28555 + kfree(ifsta->assocreq_ies);
28556 + ifsta->assocreq_ies_len = (skb->data + skb->len) - ies;
28557 + ifsta->assocreq_ies = kmalloc(ifsta->assocreq_ies_len, GFP_ATOMIC);
28558 + if (ifsta->assocreq_ies)
28559 + memcpy(ifsta->assocreq_ies, ies, ifsta->assocreq_ies_len);
28561 + ieee80211_sta_tx(dev, skb, 0, 0);
28565 +static void ieee80211_send_deauth(struct net_device *dev,
28566 + struct ieee80211_if_sta *ifsta, u16 reason)
28568 + struct sk_buff *skb;
28569 + struct ieee80211_mgmt *mgmt;
28571 + skb = dev_alloc_skb(sizeof(*mgmt));
28572 + if (skb == NULL) {
28573 + printk(KERN_DEBUG "%s: failed to allocate buffer for deauth "
28574 + "frame\n", dev->name);
28578 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28579 + memset(mgmt, 0, 24);
28580 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28581 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28582 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28583 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28584 + WLAN_FC_STYPE_DEAUTH);
28586 + mgmt->u.deauth.reason_code = cpu_to_le16(reason);
28588 + ieee80211_sta_tx(dev, skb, 0, 0);
28592 +static void ieee80211_send_disassoc(struct net_device *dev,
28593 + struct ieee80211_if_sta *ifsta, u16 reason)
28595 + struct sk_buff *skb;
28596 + struct ieee80211_mgmt *mgmt;
28598 + skb = dev_alloc_skb(sizeof(*mgmt));
28599 + if (skb == NULL) {
28600 + printk(KERN_DEBUG "%s: failed to allocate buffer for disassoc "
28601 + "frame\n", dev->name);
28605 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28606 + memset(mgmt, 0, 24);
28607 + memcpy(mgmt->da, ifsta->bssid, ETH_ALEN);
28608 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28609 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
28610 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28611 + WLAN_FC_STYPE_DISASSOC);
28613 + mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
28615 + ieee80211_sta_tx(dev, skb, 0, 0);
28619 +static int ieee80211_privacy_mismatch(struct net_device *dev,
28620 + struct ieee80211_if_sta *ifsta)
28622 + struct ieee80211_sta_bss *bss;
28625 + if (ifsta == NULL || ifsta->mixed_cell ||
28626 + ifsta->key_mgmt != IEEE80211_KEY_MGMT_NONE)
28629 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28633 + if (ieee80211_sta_wep_configured(dev) !=
28634 + !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
28637 + ieee80211_rx_bss_put(dev, bss);
28643 +static void ieee80211_associate(struct net_device *dev,
28644 + struct ieee80211_if_sta *ifsta)
28646 + ifsta->assoc_tries++;
28647 + if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
28648 + printk(KERN_DEBUG "%s: association with AP " MACSTR
28650 + dev->name, MAC2STR(ifsta->bssid));
28654 + ifsta->state = IEEE80211_ASSOCIATE;
28655 + printk(KERN_DEBUG "%s: associate with AP " MACSTR "\n",
28656 + dev->name, MAC2STR(ifsta->bssid));
28657 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
28658 + printk(KERN_DEBUG "%s: mismatch in privacy configuration and "
28659 + "mixed-cell disabled - abort association\n", dev->name);
28663 + ieee80211_send_assoc(dev, ifsta);
28665 + mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
28669 +static void ieee80211_associated(struct net_device *dev,
28670 + struct ieee80211_if_sta *ifsta)
28672 + struct ieee80211_local *local = dev->priv;
28673 + struct sta_info *sta;
28676 + /* TODO: start monitoring current AP signal quality and number of
28677 + * missed beacons. Scan other channels every now and then and search
28678 + * for better APs. */
28679 + /* TODO: remove expired BSSes */
28681 + ifsta->state = IEEE80211_ASSOCIATED;
28683 + sta = sta_info_get(local, ifsta->bssid);
28684 + if (sta == NULL) {
28685 + printk(KERN_DEBUG "%s: No STA entry for own AP " MACSTR "\n",
28686 + dev->name, MAC2STR(ifsta->bssid));
28690 + if (time_after(jiffies,
28691 + sta->last_rx + IEEE80211_MONITORING_INTERVAL)) {
28692 + if (ifsta->probereq_poll) {
28693 + printk(KERN_DEBUG "%s: No ProbeResp from "
28694 + "current AP " MACSTR " - assume out of "
28696 + dev->name, MAC2STR(ifsta->bssid));
28699 + ieee80211_send_probe_req(dev, ifsta->bssid,
28700 + local->scan_ssid,
28701 + local->scan_ssid_len);
28702 + ifsta->probereq_poll = 1;
28705 + ifsta->probereq_poll = 0;
28706 + if (time_after(jiffies, ifsta->last_probe +
28707 + IEEE80211_PROBE_INTERVAL)) {
28708 + ifsta->last_probe = jiffies;
28709 + ieee80211_send_probe_req(dev, ifsta->bssid,
28711 + ifsta->ssid_len);
28714 + sta_info_release(local, sta);
28717 + union iwreq_data wrqu;
28718 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28719 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28720 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28721 + mod_timer(&ifsta->timer,
28722 + jiffies + IEEE80211_MONITORING_INTERVAL + 30 * HZ);
28724 + mod_timer(&ifsta->timer,
28725 + jiffies + IEEE80211_MONITORING_INTERVAL);
28730 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
28731 + u8 *ssid, size_t ssid_len)
28733 + struct ieee80211_local *local = dev->priv;
28734 + struct sk_buff *skb;
28735 + struct ieee80211_mgmt *mgmt;
28736 + u8 *pos, *supp_rates, *esupp_rates = NULL;
28739 + skb = dev_alloc_skb(sizeof(*mgmt) + 200);
28740 + if (skb == NULL) {
28741 + printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
28742 + "request\n", dev->name);
28746 + mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
28747 + memset(mgmt, 0, 24);
28748 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
28749 + WLAN_FC_STYPE_PROBE_REQ);
28750 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
28752 + memcpy(mgmt->da, dst, ETH_ALEN);
28753 + memcpy(mgmt->bssid, dst, ETH_ALEN);
28755 + memset(mgmt->da, 0xff, ETH_ALEN);
28756 + memset(mgmt->bssid, 0xff, ETH_ALEN);
28758 + pos = skb_put(skb, 2 + ssid_len);
28759 + *pos++ = WLAN_EID_SSID;
28760 + *pos++ = ssid_len;
28761 + memcpy(pos, ssid, ssid_len);
28763 + supp_rates = skb_put(skb, 2);
28764 + supp_rates[0] = WLAN_EID_SUPP_RATES;
28765 + supp_rates[1] = 0;
28766 + for (i = 0; i < local->num_curr_rates; i++) {
28767 + struct ieee80211_rate *rate = &local->curr_rates[i];
28768 + if (!(rate->flags & IEEE80211_RATE_SUPPORTED))
28770 + if (esupp_rates) {
28771 + pos = skb_put(skb, 1);
28772 + esupp_rates[1]++;
28773 + } else if (supp_rates[1] == 8) {
28774 + esupp_rates = skb_put(skb, 3);
28775 + esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
28776 + esupp_rates[1] = 1;
28777 + pos = &esupp_rates[2];
28779 + pos = skb_put(skb, 1);
28782 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28783 + *pos = rate->rate / 10;
28785 + *pos = rate->rate / 5;
28788 + ieee80211_sta_tx(dev, skb, 0, 0);
28792 +static int ieee80211_sta_wep_configured(struct net_device *dev)
28794 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
28795 + if (sdata == NULL || sdata->default_key == NULL ||
28796 + sdata->default_key->alg != ALG_WEP)
28802 +static void ieee80211_auth_completed(struct net_device *dev,
28803 + struct ieee80211_if_sta *ifsta)
28805 + printk(KERN_DEBUG "%s: authenticated\n", dev->name);
28806 + ifsta->authenticated = 1;
28807 + ieee80211_associate(dev, ifsta);
28811 +static void ieee80211_auth_challenge(struct net_device *dev,
28812 + struct ieee80211_if_sta *ifsta,
28813 + struct ieee80211_mgmt *mgmt,
28815 + struct ieee80211_rx_status *rx_status)
28818 + struct ieee802_11_elems elems;
28820 + printk(KERN_DEBUG "%s: replying to auth challenge\n", dev->name);
28821 + pos = mgmt->u.auth.variable;
28822 + if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems)
28823 + == ParseFailed) {
28824 + printk(KERN_DEBUG "%s: failed to parse Auth(challenge)\n",
28828 + if (elems.challenge == NULL) {
28829 + printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
28830 + "frame\n", dev->name);
28833 + ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
28834 + elems.challenge_len + 2, 1);
28838 +static void ieee80211_rx_mgmt_auth(struct net_device *dev,
28839 + struct ieee80211_if_sta *ifsta,
28840 + struct ieee80211_mgmt *mgmt,
28842 + struct ieee80211_rx_status *rx_status)
28844 + struct ieee80211_local *local = dev->priv;
28845 + u16 auth_alg, auth_transaction, status_code;
28847 + if (ifsta->state != IEEE80211_AUTHENTICATE &&
28848 + local->conf.mode != IW_MODE_ADHOC) {
28849 + printk(KERN_DEBUG "%s: authentication frame received from "
28850 + MACSTR ", but not in authenticate state - ignored\n",
28851 + dev->name, MAC2STR(mgmt->sa));
28855 + if (len < 24 + 6) {
28856 + printk(KERN_DEBUG "%s: too short (%zd) authentication frame "
28857 + "received from " MACSTR " - ignored\n",
28858 + dev->name, len, MAC2STR(mgmt->sa));
28862 + if (local->conf.mode != IW_MODE_ADHOC &&
28863 + memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
28864 + printk(KERN_DEBUG "%s: authentication frame received from "
28865 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
28866 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28867 + MAC2STR(mgmt->bssid));
28871 + if (local->conf.mode == IW_MODE_ADHOC &&
28872 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0) {
28873 + printk(KERN_DEBUG "%s: authentication frame received from "
28874 + "unknown BSSID (SA=" MACSTR " BSSID=" MACSTR ") - "
28875 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28876 + MAC2STR(mgmt->bssid));
28880 + auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
28881 + auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
28882 + status_code = le16_to_cpu(mgmt->u.auth.status_code);
28884 + printk(KERN_DEBUG "%s: RX authentication from " MACSTR " (alg=%d "
28885 + "transaction=%d status=%d)\n",
28886 + dev->name, MAC2STR(mgmt->sa), auth_alg,
28887 + auth_transaction, status_code);
28889 + if (local->conf.mode == IW_MODE_ADHOC) {
28890 + /* IEEE 802.11 standard does not require authentication in IBSS
28891 + * networks and most implementations do not seem to use it.
28892 + * However, try to reply to authentication attempts if someone
28893 + * has actually implemented this.
28894 + * TODO: Could implement shared key authentication. */
28895 + if (auth_alg != WLAN_AUTH_OPEN || auth_transaction != 1) {
28896 + printk(KERN_DEBUG "%s: unexpected IBSS authentication "
28897 + "frame (alg=%d transaction=%d)\n",
28898 + dev->name, auth_alg, auth_transaction);
28901 + ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
28904 + if (auth_alg != ifsta->auth_alg ||
28905 + auth_transaction != ifsta->auth_transaction) {
28906 + printk(KERN_DEBUG "%s: unexpected authentication frame "
28907 + "(alg=%d transaction=%d)\n",
28908 + dev->name, auth_alg, auth_transaction);
28912 + if (status_code != WLAN_STATUS_SUCCESS) {
28913 + printk(KERN_DEBUG "%s: AP denied authentication (auth_alg=%d "
28914 + "code=%d)\n", dev->name, ifsta->auth_alg, status_code);
28915 + if (status_code == WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG) {
28916 + const int num_algs = 3;
28917 + u8 algs[num_algs];
28919 + algs[0] = algs[1] = algs[2] = 0xff;
28920 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
28921 + algs[0] = WLAN_AUTH_OPEN;
28922 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
28923 + algs[1] = WLAN_AUTH_SHARED_KEY;
28924 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
28925 + algs[2] = WLAN_AUTH_LEAP;
28926 + if (ifsta->auth_alg == WLAN_AUTH_OPEN)
28928 + else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
28932 + for (i = 0; i < num_algs; i++) {
28934 + if (pos >= num_algs)
28936 + if (algs[pos] == ifsta->auth_alg ||
28937 + algs[pos] == 0xff)
28939 + if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
28940 + !ieee80211_sta_wep_configured(dev))
28942 + ifsta->auth_alg = algs[pos];
28943 + printk(KERN_DEBUG "%s: set auth_alg=%d for "
28945 + dev->name, ifsta->auth_alg);
28952 + switch (ifsta->auth_alg) {
28953 + case WLAN_AUTH_OPEN:
28954 + case WLAN_AUTH_LEAP:
28955 + ieee80211_auth_completed(dev, ifsta);
28957 + case WLAN_AUTH_SHARED_KEY:
28958 + if (ifsta->auth_transaction == 4)
28959 + ieee80211_auth_completed(dev, ifsta);
28961 + ieee80211_auth_challenge(dev, ifsta, mgmt, len,
28968 +static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
28969 + struct ieee80211_if_sta *ifsta,
28970 + struct ieee80211_mgmt *mgmt,
28972 + struct ieee80211_rx_status *rx_status)
28976 + if (len < 24 + 2) {
28977 + printk(KERN_DEBUG "%s: too short (%zd) deauthentication frame "
28978 + "received from " MACSTR " - ignored\n",
28979 + dev->name, len, MAC2STR(mgmt->sa));
28983 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
28984 + printk(KERN_DEBUG "%s: deauthentication frame received from "
28985 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
28986 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
28987 + MAC2STR(mgmt->bssid));
28991 + reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
28993 + printk(KERN_DEBUG "%s: RX deauthentication from " MACSTR
28994 + " (reason=%d)\n",
28995 + dev->name, MAC2STR(mgmt->sa), reason_code);
28997 + if (ifsta->authenticated) {
28998 + printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
29001 + if (ifsta->state == IEEE80211_AUTHENTICATE ||
29002 + ifsta->state == IEEE80211_ASSOCIATE ||
29003 + ifsta->state == IEEE80211_ASSOCIATED) {
29004 + ifsta->state = IEEE80211_AUTHENTICATE;
29005 + mod_timer(&ifsta->timer,
29006 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
29009 + ieee80211_set_associated(dev, ifsta, 0);
29010 + ifsta->authenticated = 0;
29014 +static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
29015 + struct ieee80211_if_sta *ifsta,
29016 + struct ieee80211_mgmt *mgmt,
29018 + struct ieee80211_rx_status *rx_status)
29022 + if (len < 24 + 2) {
29023 + printk(KERN_DEBUG "%s: too short (%zd) disassociation frame "
29024 + "received from " MACSTR " - ignored\n",
29025 + dev->name, len, MAC2STR(mgmt->sa));
29029 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
29030 + printk(KERN_DEBUG "%s: disassociation frame received from "
29031 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
29032 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
29033 + MAC2STR(mgmt->bssid));
29037 + reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
29039 + printk(KERN_DEBUG "%s: RX disassociation from " MACSTR
29040 + " (reason=%d)\n",
29041 + dev->name, MAC2STR(mgmt->sa), reason_code);
29043 + if (ifsta->associated)
29044 + printk(KERN_DEBUG "%s: disassociated\n", dev->name);
29046 + if (ifsta->state == IEEE80211_ASSOCIATED) {
29047 + ifsta->state = IEEE80211_ASSOCIATE;
29048 + mod_timer(&ifsta->timer,
29049 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
29052 + ieee80211_set_associated(dev, ifsta, 0);
29056 +static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
29057 + struct ieee80211_if_sta *ifsta,
29058 + struct ieee80211_mgmt *mgmt,
29060 + struct ieee80211_rx_status *rx_status,
29063 + struct ieee80211_local *local = dev->priv;
29064 + struct sta_info *sta;
29066 + u16 capab_info, status_code, aid;
29067 + struct ieee802_11_elems elems;
29071 + /* AssocResp and ReassocResp have identical structure, so process both
29072 + * of them in this function. */
29074 + if (ifsta->state != IEEE80211_ASSOCIATE) {
29075 + printk(KERN_DEBUG "%s: association frame received from "
29076 + MACSTR ", but not in associate state - ignored\n",
29077 + dev->name, MAC2STR(mgmt->sa));
29081 + if (len < 24 + 6) {
29082 + printk(KERN_DEBUG "%s: too short (%zd) association frame "
29083 + "received from " MACSTR " - ignored\n",
29084 + dev->name, len, MAC2STR(mgmt->sa));
29088 + if (memcmp(ifsta->bssid, mgmt->sa, ETH_ALEN) != 0) {
29089 + printk(KERN_DEBUG "%s: association frame received from "
29090 + "unknown AP (SA=" MACSTR " BSSID=" MACSTR ") - "
29091 + "ignored\n", dev->name, MAC2STR(mgmt->sa),
29092 + MAC2STR(mgmt->bssid));
29096 + capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
29097 + status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
29098 + aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
29099 + if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
29100 + printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not "
29101 + "set\n", dev->name, aid);
29102 + aid &= ~(BIT(15) | BIT(14));
29104 + printk(KERN_DEBUG "%s: RX %sssocResp from " MACSTR " (capab=0x%x "
29105 + "status=%d aid=%d)\n",
29106 + dev->name, reassoc ? "Rea" : "A", MAC2STR(mgmt->sa),
29107 + capab_info, status_code, aid);
29109 + if (status_code != WLAN_STATUS_SUCCESS) {
29110 + printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
29111 + dev->name, status_code);
29115 + pos = mgmt->u.assoc_resp.variable;
29116 + if (ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems)
29117 + == ParseFailed) {
29118 + printk(KERN_DEBUG "%s: failed to parse AssocResp\n",
29123 + if (elems.supp_rates == NULL) {
29124 + printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
29129 + printk(KERN_DEBUG "%s: associated\n", dev->name);
29130 + ifsta->aid = aid;
29131 + ifsta->ap_capab = capab_info;
29133 + kfree(ifsta->assocresp_ies);
29134 + ifsta->assocresp_ies_len = len - (pos - (u8 *) mgmt);
29135 + ifsta->assocresp_ies = kmalloc(ifsta->assocresp_ies_len, GFP_ATOMIC);
29136 + if (ifsta->assocresp_ies)
29137 + memcpy(ifsta->assocresp_ies, pos, ifsta->assocresp_ies_len);
29139 + ieee80211_set_associated(dev, ifsta, 1);
29141 + /* Add STA entry for the AP */
29142 + sta = sta_info_get(local, ifsta->bssid);
29143 + if (sta == NULL) {
29144 + sta = sta_info_add(local, dev, ifsta->bssid);
29145 + if (sta == NULL) {
29146 + printk(KERN_DEBUG "%s: failed to add STA entry for the"
29147 + " AP\n", dev->name);
29153 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
29154 + sta->assoc_ap = 1;
29157 + for (i = 0; i < elems.supp_rates_len; i++) {
29158 + int rate = (elems.supp_rates[i] & 0x7f) * 5;
29159 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
29161 + for (j = 0; j < local->num_curr_rates; j++)
29162 + if (local->curr_rates[j].rate == rate)
29165 + for (i = 0; i < elems.ext_supp_rates_len; i++) {
29166 + int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
29167 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
29169 + for (j = 0; j < local->num_curr_rates; j++)
29170 + if (local->curr_rates[j].rate == rate)
29173 + sta->supp_rates = rates;
29175 + rate_control_rate_init(local, sta);
29177 + if (elems.wmm_param && ifsta->wmm_enabled) {
29178 + sta->flags |= WLAN_STA_WME;
29179 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29180 + elems.wmm_param_len);
29184 + sta_info_release(local, sta);
29186 + ieee80211_associated(dev, ifsta);
29190 +/* Caller must hold local->sta_bss_lock */
29191 +static void __ieee80211_rx_bss_hash_add(struct net_device *dev,
29192 + struct ieee80211_sta_bss *bss)
29194 + struct ieee80211_local *local = dev->priv;
29195 + bss->hnext = local->sta_bss_hash[STA_HASH(bss->bssid)];
29196 + local->sta_bss_hash[STA_HASH(bss->bssid)] = bss;
29200 +/* Caller must hold local->sta_bss_lock */
29201 +static void __ieee80211_rx_bss_hash_del(struct net_device *dev,
29202 + struct ieee80211_sta_bss *bss)
29204 + struct ieee80211_local *local = dev->priv;
29205 + struct ieee80211_sta_bss *b, *prev = NULL;
29206 + b = local->sta_bss_hash[STA_HASH(bss->bssid)];
29209 + if (prev == NULL) {
29210 + local->sta_bss_hash[STA_HASH(bss->bssid)] =
29213 + prev->hnext = bss->hnext;
29223 +static struct ieee80211_sta_bss *
29224 +ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid)
29226 + struct ieee80211_local *local = dev->priv;
29227 + struct ieee80211_sta_bss *bss;
29229 + bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
29232 + memset(bss, 0, sizeof(*bss));
29233 + atomic_inc(&bss->users);
29234 + atomic_inc(&bss->users);
29235 + memcpy(bss->bssid, bssid, ETH_ALEN);
29237 + spin_lock_bh(&local->sta_bss_lock);
29238 + /* TODO: order by RSSI? */
29239 + list_add_tail(&bss->list, &local->sta_bss_list);
29240 + __ieee80211_rx_bss_hash_add(dev, bss);
29241 + spin_unlock_bh(&local->sta_bss_lock);
29246 +static struct ieee80211_sta_bss *
29247 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid)
29249 + struct ieee80211_local *local = dev->priv;
29250 + struct ieee80211_sta_bss *bss;
29252 + spin_lock_bh(&local->sta_bss_lock);
29253 + bss = local->sta_bss_hash[STA_HASH(bssid)];
29255 + if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
29256 + atomic_inc(&bss->users);
29259 + bss = bss->hnext;
29261 + spin_unlock_bh(&local->sta_bss_lock);
29266 +static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
29268 + kfree(bss->wpa_ie);
29269 + kfree(bss->rsn_ie);
29270 + kfree(bss->wmm_ie);
29275 +static void ieee80211_rx_bss_put(struct net_device *dev,
29276 + struct ieee80211_sta_bss *bss)
29278 + struct ieee80211_local *local = dev->priv;
29279 + if (!atomic_dec_and_test(&bss->users))
29282 + spin_lock_bh(&local->sta_bss_lock);
29283 + __ieee80211_rx_bss_hash_del(dev, bss);
29284 + list_del(&bss->list);
29285 + spin_unlock_bh(&local->sta_bss_lock);
29286 + ieee80211_rx_bss_free(bss);
29290 +void ieee80211_rx_bss_list_init(struct net_device *dev)
29292 + struct ieee80211_local *local = dev->priv;
29293 + spin_lock_init(&local->sta_bss_lock);
29294 + INIT_LIST_HEAD(&local->sta_bss_list);
29298 +void ieee80211_rx_bss_list_deinit(struct net_device *dev)
29300 + struct ieee80211_local *local = dev->priv;
29301 + struct ieee80211_sta_bss *bss;
29302 + struct list_head *ptr;
29305 + ptr = local->sta_bss_list.next;
29306 + if (!ptr || ptr == &local->sta_bss_list)
29308 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
29309 + ieee80211_rx_bss_put(dev, bss);
29314 +static void ieee80211_rx_bss_info(struct net_device *dev,
29315 + struct ieee80211_mgmt *mgmt,
29317 + struct ieee80211_rx_status *rx_status,
29320 + struct ieee80211_local *local = dev->priv;
29321 + struct ieee802_11_elems elems;
29323 + int channel, invalid = 0, clen;
29324 + struct ieee80211_sta_bss *bss;
29325 + struct sta_info *sta;
29326 + struct ieee80211_sub_if_data *sdata;
29330 + if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
29331 + return; /* ignore ProbeResp to foreign address */
29334 + printk(KERN_DEBUG "%s: RX %s from " MACSTR " to " MACSTR "\n",
29335 + dev->name, beacon ? "Beacon" : "Probe Response",
29336 + MAC2STR(mgmt->sa), MAC2STR(mgmt->da));
29339 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29340 + if (baselen > len)
29343 + pos = mgmt->u.beacon.timestamp;
29344 + timestamp = ((u64) pos[7] << 56) | ((u64) pos[6] << 48) |
29345 + ((u64) pos[5] << 40) | ((u64) pos[4] << 32) |
29346 + ((u64) pos[3] << 24) | ((u64) pos[2] << 16) |
29347 + ((u64) pos[1] << 8) | ((u64) pos[0]);
29349 + if (local->conf.mode == IW_MODE_ADHOC && beacon &&
29350 + memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0) {
29351 +#ifdef IEEE80211_IBSS_DEBUG
29352 + static unsigned long last_tsf_debug = 0;
29354 + if (local->hw->get_tsf)
29355 + tsf = local->hw->get_tsf(local->mdev);
29358 + if (time_after(jiffies, last_tsf_debug + 5 * HZ)) {
29359 + printk(KERN_DEBUG "RX beacon SA=" MACSTR " BSSID="
29360 + MACSTR " TSF=0x%llx BCN=0x%llx diff=%lld "
29362 + MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
29363 + tsf, timestamp, tsf - timestamp, jiffies);
29364 + last_tsf_debug = jiffies;
29366 +#endif /* IEEE80211_IBSS_DEBUG */
29369 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29370 + &elems) == ParseFailed)
29373 + if (local->conf.mode == IW_MODE_ADHOC && elems.supp_rates &&
29374 + memcmp(mgmt->bssid, local->bssid, ETH_ALEN) == 0 &&
29375 + (sta = sta_info_get(local, mgmt->sa)) &&
29376 + (sdata = IEEE80211_DEV_TO_SUB_IF(dev)) &&
29377 + sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
29378 + struct ieee80211_rate *rates;
29379 + size_t num_rates;
29380 + u32 supp_rates, prev_rates;
29381 + int i, j, oper_mode;
29383 + rates = local->curr_rates;
29384 + num_rates = local->num_curr_rates;
29385 + oper_mode = local->sta_scanning ? local->scan_oper_phymode :
29386 + local->conf.phymode;
29387 + for (i = 0; i < local->hw->num_modes; i++) {
29388 + struct ieee80211_hw_modes *mode = &local->hw->modes[i];
29389 + if (oper_mode == mode->mode) {
29390 + rates = mode->rates;
29391 + num_rates = mode->num_rates;
29397 + for (i = 0; i < elems.supp_rates_len +
29398 + elems.ext_supp_rates_len; i++) {
29401 + if (i < elems.supp_rates_len)
29402 + rate = elems.supp_rates[i];
29403 + else if (elems.ext_supp_rates)
29404 + rate = elems.ext_supp_rates
29405 + [i - elems.supp_rates_len];
29406 + own_rate = 5 * (rate & 0x7f);
29407 + if (oper_mode == MODE_ATHEROS_TURBO)
29409 + for (j = 0; j < num_rates; j++)
29410 + if (rates[j].rate == own_rate)
29411 + supp_rates |= BIT(j);
29414 + prev_rates = sta->supp_rates;
29415 + sta->supp_rates &= supp_rates;
29416 + if (sta->supp_rates == 0) {
29417 + /* No matching rates - this should not really happen.
29418 + * Make sure that at least one rate is marked
29419 + * supported to avoid issues with TX rate ctrl. */
29420 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
29422 + if (sta->supp_rates != prev_rates) {
29423 + printk(KERN_DEBUG "%s: updated supp_rates set for "
29424 + MACSTR " based on beacon info (0x%x & 0x%x -> "
29426 + dev->name, MAC2STR(sta->addr), prev_rates,
29427 + supp_rates, sta->supp_rates);
29429 + sta_info_release(local, sta);
29432 + if (elems.ssid == NULL)
29435 + if (elems.ds_params && elems.ds_params_len == 1)
29436 + channel = elems.ds_params[0];
29438 + channel = rx_status->channel;
29440 + bss = ieee80211_rx_bss_get(dev, mgmt->bssid);
29441 + if (bss == NULL) {
29442 + bss = ieee80211_rx_bss_add(dev, mgmt->bssid);
29447 + /* TODO: order by RSSI? */
29448 + spin_lock_bh(&local->sta_bss_lock);
29449 + list_move_tail(&bss->list, &local->sta_bss_list);
29450 + spin_unlock_bh(&local->sta_bss_lock);
29454 + if (bss->probe_resp && beacon) {
29455 + /* Do not allow beacon to override data from Probe Response. */
29456 + ieee80211_rx_bss_put(dev, bss);
29460 + bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int);
29461 + bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info);
29462 + if (elems.ssid && elems.ssid_len <= IEEE80211_MAX_SSID_LEN) {
29463 + memcpy(bss->ssid, elems.ssid, elems.ssid_len);
29464 + bss->ssid_len = elems.ssid_len;
29467 + bss->supp_rates_len = 0;
29468 + if (elems.supp_rates) {
29469 + clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
29470 + if (clen > elems.supp_rates_len)
29471 + clen = elems.supp_rates_len;
29472 + memcpy(&bss->supp_rates[bss->supp_rates_len], elems.supp_rates,
29474 + bss->supp_rates_len += clen;
29476 + if (elems.ext_supp_rates) {
29477 + clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
29478 + if (clen > elems.ext_supp_rates_len)
29479 + clen = elems.ext_supp_rates_len;
29480 + memcpy(&bss->supp_rates[bss->supp_rates_len],
29481 + elems.ext_supp_rates, clen);
29482 + bss->supp_rates_len += clen;
29486 + (bss->wpa_ie == NULL || bss->wpa_ie_len != elems.wpa_len ||
29487 + memcmp(bss->wpa_ie, elems.wpa, elems.wpa_len))) {
29488 + kfree(bss->wpa_ie);
29489 + bss->wpa_ie = kmalloc(elems.wpa_len + 2, GFP_ATOMIC);
29490 + if (bss->wpa_ie) {
29491 + memcpy(bss->wpa_ie, elems.wpa - 2, elems.wpa_len + 2);
29492 + bss->wpa_ie_len = elems.wpa_len + 2;
29494 + bss->wpa_ie_len = 0;
29495 + } else if (!elems.wpa && bss->wpa_ie) {
29496 + kfree(bss->wpa_ie);
29497 + bss->wpa_ie = NULL;
29498 + bss->wpa_ie_len = 0;
29502 + (bss->rsn_ie == NULL || bss->rsn_ie_len != elems.rsn_len ||
29503 + memcmp(bss->rsn_ie, elems.rsn, elems.rsn_len))) {
29504 + kfree(bss->rsn_ie);
29505 + bss->rsn_ie = kmalloc(elems.rsn_len + 2, GFP_ATOMIC);
29506 + if (bss->rsn_ie) {
29507 + memcpy(bss->rsn_ie, elems.rsn - 2, elems.rsn_len + 2);
29508 + bss->rsn_ie_len = elems.rsn_len + 2;
29510 + bss->rsn_ie_len = 0;
29511 + } else if (!elems.rsn && bss->rsn_ie) {
29512 + kfree(bss->rsn_ie);
29513 + bss->rsn_ie = NULL;
29514 + bss->rsn_ie_len = 0;
29517 + if (elems.wmm_param &&
29518 + (bss->wmm_ie == NULL || bss->wmm_ie_len != elems.wmm_param_len ||
29519 + memcmp(bss->wmm_ie, elems.wmm_param, elems.wmm_param_len))) {
29520 + kfree(bss->wmm_ie);
29521 + bss->wmm_ie = kmalloc(elems.wmm_param_len + 2, GFP_ATOMIC);
29522 + if (bss->wmm_ie) {
29523 + memcpy(bss->wmm_ie, elems.wmm_param - 2,
29524 + elems.wmm_param_len + 2);
29525 + bss->wmm_ie_len = elems.wmm_param_len + 2;
29527 + bss->wmm_ie_len = 0;
29528 + } else if (!elems.wmm_param && bss->wmm_ie) {
29529 + kfree(bss->wmm_ie);
29530 + bss->wmm_ie = NULL;
29531 + bss->wmm_ie_len = 0;
29535 + bss->hw_mode = local->conf.phymode;
29536 + bss->channel = channel;
29537 + bss->freq = local->conf.freq;
29538 + if (channel != local->conf.channel &&
29539 + (local->conf.phymode == MODE_IEEE80211G ||
29540 + local->conf.phymode == MODE_IEEE80211B) &&
29541 + channel >= 1 && channel <= 14) {
29542 + static const int freq_list[] = {
29543 + 2412, 2417, 2422, 2427, 2432, 2437, 2442,
29544 + 2447, 2452, 2457, 2462, 2467, 2472, 2484
29546 + /* IEEE 802.11g/b mode can receive packets from neighboring
29547 + * channels, so map the channel into frequency. */
29548 + bss->freq = freq_list[channel - 1];
29550 + bss->timestamp = timestamp;
29551 + bss->last_update = jiffies;
29552 + bss->rssi = rx_status->ssi;
29554 + bss->probe_resp++;
29555 + ieee80211_rx_bss_put(dev, bss);
29559 +static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
29560 + struct ieee80211_mgmt *mgmt,
29562 + struct ieee80211_rx_status *rx_status)
29564 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
29568 +static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
29569 + struct ieee80211_mgmt *mgmt,
29571 + struct ieee80211_rx_status *rx_status)
29573 + struct ieee80211_local *local = dev->priv;
29574 + struct ieee80211_sub_if_data *sdata;
29575 + struct ieee80211_if_sta *ifsta;
29576 + int use_protection;
29578 + struct ieee802_11_elems elems;
29580 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
29582 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29583 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
29585 + ifsta = &sdata->u.sta;
29587 + if (!ifsta->associated ||
29588 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
29591 + /* Process beacon from the current BSS */
29592 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29593 + if (baselen > len)
29596 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29597 + &elems) == ParseFailed)
29600 + use_protection = 0;
29601 + if (elems.erp_info && elems.erp_info_len >= 1) {
29603 + (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
29606 + if (use_protection != !!ifsta->use_protection) {
29607 + if (net_ratelimit()) {
29608 + printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
29611 + use_protection ? "enabled" : "disabled",
29612 + MAC2STR(ifsta->bssid));
29614 + ifsta->use_protection = use_protection ? 1 : 0;
29615 + local->cts_protect_erp_frames = use_protection;
29618 + if (elems.wmm_param && ifsta->wmm_enabled) {
29619 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29620 + elems.wmm_param_len);
29625 +static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
29626 + struct ieee80211_if_sta *ifsta,
29627 + struct ieee80211_mgmt *mgmt,
29629 + struct ieee80211_rx_status *rx_status)
29631 + struct ieee80211_local *local = dev->priv;
29632 + int tx_last_beacon;
29633 + struct sk_buff *skb;
29634 + struct ieee80211_mgmt *resp;
29637 + if (local->conf.mode != IW_MODE_ADHOC ||
29638 + ifsta->state != IEEE80211_IBSS_JOINED ||
29639 + len < 24 + 2 || ifsta->probe_resp == NULL)
29642 + if (local->hw->tx_last_beacon)
29643 + tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
29645 + tx_last_beacon = 1;
29647 +#ifdef IEEE80211_IBSS_DEBUG
29648 + printk(KERN_DEBUG "%s: RX ProbeReq SA=" MACSTR " DA=" MACSTR " BSSID="
29649 + MACSTR " (tx_last_beacon=%d)\n",
29650 + dev->name, MAC2STR(mgmt->sa), MAC2STR(mgmt->da),
29651 + MAC2STR(mgmt->bssid), tx_last_beacon);
29652 +#endif /* IEEE80211_IBSS_DEBUG */
29654 + if (!tx_last_beacon)
29657 + if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
29658 + memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
29661 + end = ((u8 *) mgmt) + len;
29662 + pos = mgmt->u.probe_req.variable;
29663 + if (pos[0] != WLAN_EID_SSID ||
29664 + pos + 2 + pos[1] > end) {
29665 + if (net_ratelimit()) {
29666 + printk(KERN_DEBUG "%s: Invalid SSID IE in ProbeReq "
29667 + "from " MACSTR "\n",
29668 + dev->name, MAC2STR(mgmt->sa));
29672 + if (pos[1] != 0 &&
29673 + (pos[1] != ifsta->ssid_len ||
29674 + memcmp(pos + 2, ifsta->ssid, ifsta->ssid_len) != 0)) {
29675 + /* Ignore ProbeReq for foreign SSID */
29679 + /* Reply with ProbeResp */
29680 + skb = skb_copy(ifsta->probe_resp, GFP_ATOMIC);
29684 + resp = (struct ieee80211_mgmt *) skb->data;
29685 + memcpy(resp->da, mgmt->sa, ETH_ALEN);
29686 +#ifdef IEEE80211_IBSS_DEBUG
29687 + printk(KERN_DEBUG "%s: Sending ProbeResp to " MACSTR "\n",
29688 + dev->name, MAC2STR(resp->da));
29689 +#endif /* IEEE80211_IBSS_DEBUG */
29690 + ieee80211_sta_tx(dev, skb, 0, 1);
29694 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
29695 + struct ieee80211_rx_status *rx_status)
29697 + struct ieee80211_sub_if_data *sdata;
29698 + struct ieee80211_if_sta *ifsta;
29699 + struct ieee80211_mgmt *mgmt;
29702 + if (skb->len < 24)
29705 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29706 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
29707 + printk(KERN_DEBUG "%s: ieee80211_sta_rx_mgmt: non-STA "
29708 + "interface (type=%d)\n", dev->name, sdata->type);
29711 + ifsta = &sdata->u.sta;
29713 + mgmt = (struct ieee80211_mgmt *) skb->data;
29714 + fc = le16_to_cpu(mgmt->frame_control);
29716 + switch (WLAN_FC_GET_STYPE(fc)) {
29717 + case WLAN_FC_STYPE_PROBE_REQ:
29718 + ieee80211_rx_mgmt_probe_req(dev, ifsta, mgmt, skb->len,
29721 + case WLAN_FC_STYPE_PROBE_RESP:
29722 + ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
29724 + case WLAN_FC_STYPE_BEACON:
29725 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
29727 + case WLAN_FC_STYPE_AUTH:
29728 + ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len, rx_status);
29730 + case WLAN_FC_STYPE_ASSOC_RESP:
29731 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29734 + case WLAN_FC_STYPE_REASSOC_RESP:
29735 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29738 + case WLAN_FC_STYPE_DEAUTH:
29739 + ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len,
29742 + case WLAN_FC_STYPE_DISASSOC:
29743 + ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len,
29747 + printk(KERN_DEBUG "%s: received unknown management frame - "
29748 + "stype=%d\n", dev->name, WLAN_FC_GET_STYPE(fc));
29753 + dev_kfree_skb(skb);
29757 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
29758 + struct ieee80211_rx_status *rx_status)
29760 + struct ieee80211_mgmt *mgmt;
29763 + if (skb->len < 24) {
29764 + dev_kfree_skb(skb);
29768 + mgmt = (struct ieee80211_mgmt *) skb->data;
29769 + fc = le16_to_cpu(mgmt->frame_control);
29771 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT) {
29772 + if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
29773 + ieee80211_rx_mgmt_probe_resp(dev, mgmt,
29774 + skb->len, rx_status);
29775 + } else if (WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) {
29776 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len,
29781 + dev_kfree_skb(skb);
29785 +static int ieee80211_sta_active_ibss(struct net_device *dev)
29787 + struct ieee80211_local *local = dev->priv;
29788 + struct list_head *ptr;
29790 + struct sta_info *sta;
29792 + spin_lock_bh(&local->sta_lock);
29793 + list_for_each(ptr, &local->sta_list) {
29794 + sta = list_entry(ptr, struct sta_info, list);
29795 + if (sta->dev == dev &&
29796 + time_after(sta->last_rx + IEEE80211_IBSS_MERGE_INTERVAL,
29802 + spin_unlock_bh(&local->sta_lock);
29808 +static void ieee80211_sta_expire(struct net_device *dev)
29810 + struct ieee80211_local *local = dev->priv;
29811 + struct list_head *ptr, *n;
29812 + struct sta_info *sta;
29814 + spin_lock_bh(&local->sta_lock);
29815 + list_for_each_safe(ptr, n, &local->sta_list) {
29816 + sta = list_entry(ptr, struct sta_info, list);
29817 + if (time_after(jiffies, sta->last_rx +
29818 + IEEE80211_IBSS_INACTIVITY_LIMIT)) {
29819 + printk(KERN_DEBUG "%s: expiring inactive STA " MACSTR
29820 + "\n", dev->name, MAC2STR(sta->addr));
29821 + sta_info_free(local, sta, 1);
29824 + spin_unlock_bh(&local->sta_lock);
29828 +static void ieee80211_sta_merge_ibss(struct net_device *dev,
29829 + struct ieee80211_if_sta *ifsta)
29831 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
29833 + ieee80211_sta_expire(dev);
29834 + if (ieee80211_sta_active_ibss(dev))
29837 + printk(KERN_DEBUG "%s: No active IBSS STAs - trying to scan for other "
29838 + "IBSS networks with same SSID (merge)\n", dev->name);
29839 + ieee80211_sta_req_scan(dev, ifsta->ssid, ifsta->ssid_len);
29843 +void ieee80211_sta_timer(unsigned long ptr)
29845 + struct net_device *dev;
29846 + struct ieee80211_sub_if_data *sdata;
29847 + struct ieee80211_if_sta *ifsta;
29849 + dev = (struct net_device *) ptr;
29850 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29851 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA) {
29852 + printk(KERN_DEBUG "%s: ieee80211_sta_timer: non-STA interface "
29853 + "(type=%d)\n", dev->name, sdata->type);
29856 + ifsta = &sdata->u.sta;
29858 + switch (ifsta->state) {
29859 + case IEEE80211_DISABLED:
29861 + case IEEE80211_AUTHENTICATE:
29862 + ieee80211_authenticate(dev, ifsta);
29864 + case IEEE80211_ASSOCIATE:
29865 + ieee80211_associate(dev, ifsta);
29867 + case IEEE80211_ASSOCIATED:
29868 + ieee80211_associated(dev, ifsta);
29870 + case IEEE80211_IBSS_SEARCH:
29871 + ieee80211_sta_find_ibss(dev, ifsta);
29873 + case IEEE80211_IBSS_JOINED:
29874 + ieee80211_sta_merge_ibss(dev, ifsta);
29877 + printk(KERN_DEBUG "ieee80211_sta_timer: Unknown state %d\n",
29882 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
29883 + printk(KERN_DEBUG "%s: privacy configuration mismatch and "
29884 + "mixed-cell disabled - disassociate\n", dev->name);
29886 + ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
29887 + ieee80211_set_associated(dev, ifsta, 0);
29892 +static void ieee80211_sta_new_auth(struct net_device *dev,
29893 + struct ieee80211_if_sta *ifsta)
29895 + struct ieee80211_local *local = dev->priv;
29897 + if (local->conf.mode != IW_MODE_INFRA)
29900 + if (local->hw->reset_tsf) {
29901 + /* Reset own TSF to allow time synchronization work. */
29902 + local->hw->reset_tsf(local->mdev);
29905 + ifsta->wmm_last_param_set = -1; /* allow any WMM update */
29908 + if (ifsta->auth_algs & IEEE80211_AUTH_ALG_OPEN)
29909 + ifsta->auth_alg = WLAN_AUTH_OPEN;
29910 + else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_SHARED_KEY)
29911 + ifsta->auth_alg = WLAN_AUTH_SHARED_KEY;
29912 + else if (ifsta->auth_algs & IEEE80211_AUTH_ALG_LEAP)
29913 + ifsta->auth_alg = WLAN_AUTH_LEAP;
29915 + ifsta->auth_alg = WLAN_AUTH_OPEN;
29916 + printk(KERN_DEBUG "%s: Initial auth_alg=%d\n", dev->name,
29917 + ifsta->auth_alg);
29918 + ifsta->auth_transaction = -1;
29919 + ifsta->auth_tries = ifsta->assoc_tries = 0;
29920 + ieee80211_authenticate(dev, ifsta);
29924 +static int ieee80211_ibss_allowed(struct ieee80211_local *local)
29928 + for (m = 0; m < local->hw->num_modes; m++) {
29929 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
29930 + if (mode->mode != local->conf.phymode)
29932 + for (c = 0; c < mode->num_channels; c++) {
29933 + struct ieee80211_channel *chan = &mode->channels[c];
29934 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
29935 + chan->chan == local->conf.channel) {
29936 + if (chan->flag & IEEE80211_CHAN_W_IBSS)
29947 +extern int ieee80211_ioctl_siwfreq(struct net_device *dev,
29948 + struct iw_request_info *info,
29949 + struct iw_freq *freq, char *extra);
29951 +static int ieee80211_sta_join_ibss(struct net_device *dev,
29952 + struct ieee80211_if_sta *ifsta,
29953 + struct ieee80211_sta_bss *bss)
29955 + struct ieee80211_local *local = dev->priv;
29956 + struct iw_freq rq;
29957 + int res, rates, i, j;
29958 + struct sk_buff *skb;
29959 + struct ieee80211_mgmt *mgmt;
29960 + struct ieee80211_tx_control control;
29961 + struct ieee80211_rate *rate;
29962 + struct rate_control_extra extra;
29964 + struct ieee80211_sub_if_data *sdata;
29966 + /* Remove possible STA entries from other IBSS networks. */
29967 + sta_info_flush(local, NULL);
29969 + if (local->hw->reset_tsf) {
29970 + /* Reset own TSF to allow time synchronization work. */
29971 + local->hw->reset_tsf(local->mdev);
29973 + memcpy(ifsta->bssid, bss->bssid, ETH_ALEN);
29974 + memcpy(local->bssid, bss->bssid, ETH_ALEN);
29975 + memcpy(local->conf.client_bssid, bss->bssid, ETH_ALEN);
29977 + local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
29979 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29980 + sdata->drop_unencrypted = bss->capability &
29981 + cpu_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
29983 + memset(&rq, 0, sizeof(rq));
29984 + rq.m = bss->freq * 100000;
29986 + res = ieee80211_ioctl_siwfreq(dev, NULL, &rq, NULL);
29988 + if (!ieee80211_ibss_allowed(local)) {
29989 + printk(KERN_DEBUG "%s: IBSS not allowed on channel %d "
29990 + "(%d MHz)\n", dev->name, local->conf.channel,
29991 + local->conf.freq);
29995 + /* Set beacon template based on scan results */
29996 + skb = dev_alloc_skb(400);
30001 + mgmt = (struct ieee80211_mgmt *)
30002 + skb_put(skb, 24 + sizeof(mgmt->u.beacon));
30003 + memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
30004 + mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
30005 + WLAN_FC_STYPE_BEACON);
30006 + memset(mgmt->da, 0xff, ETH_ALEN);
30007 + memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
30008 + memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
30009 + mgmt->u.beacon.beacon_int =
30010 + cpu_to_le16(local->conf.beacon_int);
30011 + mgmt->u.beacon.capab_info = cpu_to_le16(bss->capability);
30013 + pos = skb_put(skb, 2 + ifsta->ssid_len);
30014 + *pos++ = WLAN_EID_SSID;
30015 + *pos++ = ifsta->ssid_len;
30016 + memcpy(pos, ifsta->ssid, ifsta->ssid_len);
30018 + rates = bss->supp_rates_len;
30021 + pos = skb_put(skb, 2 + rates);
30022 + *pos++ = WLAN_EID_SUPP_RATES;
30024 + memcpy(pos, bss->supp_rates, rates);
30026 + pos = skb_put(skb, 2 + 1);
30027 + *pos++ = WLAN_EID_DS_PARAMS;
30029 + *pos++ = bss->channel;
30031 + pos = skb_put(skb, 2 + 2);
30032 + *pos++ = WLAN_EID_IBSS_PARAMS;
30034 + /* FIX: set ATIM window based on scan results */
30038 + if (bss->supp_rates_len > 8) {
30039 + rates = bss->supp_rates_len - 8;
30040 + pos = skb_put(skb, 2 + rates);
30041 + *pos++ = WLAN_EID_EXT_SUPP_RATES;
30043 + memcpy(pos, &bss->supp_rates[8], rates);
30046 + memset(&control, 0, sizeof(control));
30047 + control.pkt_type = PKT_PROBE_RESP;
30048 + memset(&extra, 0, sizeof(extra));
30049 + extra.endidx = local->num_curr_rates;
30050 + rate = rate_control_get_rate(dev, skb, &extra);
30051 + if (rate == NULL) {
30052 + printk(KERN_DEBUG "%s: Failed to determine TX rate "
30053 + "for IBSS beacon\n", dev->name);
30056 + control.tx_rate = (local->short_preamble &&
30057 + (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
30058 + rate->val2 : rate->val;
30059 + control.antenna_sel = local->conf.antenna_sel;
30060 + control.power_level = local->conf.power_level;
30061 + control.no_ack = 1;
30062 + control.retry_limit = 1;
30063 + control.rts_cts_duration = 0;
30065 + ifsta->probe_resp = skb_copy(skb, GFP_ATOMIC);
30066 + if (ifsta->probe_resp) {
30067 + mgmt = (struct ieee80211_mgmt *)
30068 + ifsta->probe_resp->data;
30069 + mgmt->frame_control =
30070 + IEEE80211_FC(WLAN_FC_TYPE_MGMT,
30071 + WLAN_FC_STYPE_PROBE_RESP);
30073 + printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
30074 + "template for IBSS\n", dev->name);
30077 + if (local->hw->beacon_update &&
30078 + local->hw->beacon_update(dev, skb, &control) == 0) {
30079 + printk(KERN_DEBUG "%s: Configured IBSS beacon "
30080 + "template based on scan results\n", dev->name);
30085 + for (i = 0; i < bss->supp_rates_len; i++) {
30086 + int rate = (bss->supp_rates[i] & 0x7f) * 5;
30087 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
30089 + for (j = 0; j < local->num_curr_rates; j++)
30090 + if (local->curr_rates[j].rate == rate)
30093 + ifsta->supp_rates_bits = rates;
30097 + printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
30098 + "template\n", dev->name);
30099 + dev_kfree_skb(skb);
30102 + ifsta->state = IEEE80211_IBSS_JOINED;
30103 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30105 + ieee80211_rx_bss_put(dev, bss);
30111 +static int ieee80211_sta_create_ibss(struct net_device *dev,
30112 + struct ieee80211_if_sta *ifsta)
30114 + struct ieee80211_local *local = dev->priv;
30115 + struct ieee80211_sta_bss *bss;
30116 + struct ieee80211_sub_if_data *sdata;
30117 + u8 bssid[ETH_ALEN], *pos;
30121 + /* Easier testing, use fixed BSSID. */
30122 + memset(bssid, 0xfe, ETH_ALEN);
30124 + /* Generate random, not broadcast, locally administered BSSID. Mix in
30125 + * own MAC address to make sure that devices that do not have proper
30126 + * random number generator get different BSSID. */
30127 + get_random_bytes(bssid, ETH_ALEN);
30128 + for (i = 0; i < ETH_ALEN; i++)
30129 + bssid[i] ^= dev->dev_addr[i];
30130 + bssid[0] &= ~0x01;
30131 + bssid[0] |= 0x02;
30134 + printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID " MACSTR "\n",
30135 + dev->name, MAC2STR(bssid));
30137 + bss = ieee80211_rx_bss_add(dev, bssid);
30141 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30143 + if (local->conf.beacon_int == 0)
30144 + local->conf.beacon_int = 100;
30145 + bss->beacon_int = local->conf.beacon_int;
30146 + bss->hw_mode = local->conf.phymode;
30147 + bss->channel = local->conf.channel;
30148 + bss->freq = local->conf.freq;
30149 + bss->last_update = jiffies;
30150 + bss->capability = cpu_to_le16(WLAN_CAPABILITY_IBSS);
30151 + if (sdata->default_key) {
30152 + bss->capability |= cpu_to_le16(WLAN_CAPABILITY_PRIVACY);
30154 + sdata->drop_unencrypted = 0;
30155 + bss->supp_rates_len = local->num_curr_rates;
30156 + pos = bss->supp_rates;
30157 + for (i = 0; i < local->num_curr_rates; i++) {
30158 + int rate = local->curr_rates[i].rate;
30159 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
30161 + *pos++ = (u8) (rate / 5);
30164 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30168 +static int ieee80211_sta_find_ibss(struct net_device *dev,
30169 + struct ieee80211_if_sta *ifsta)
30171 + struct ieee80211_local *local = dev->priv;
30172 + struct ieee80211_sta_bss *bss;
30174 + u8 bssid[ETH_ALEN];
30175 + struct list_head *ptr;
30178 + if (ifsta->ssid_len == 0)
30181 + active_ibss = ieee80211_sta_active_ibss(dev);
30182 +#ifdef IEEE80211_IBSS_DEBUG
30183 + printk(KERN_DEBUG "%s: sta_find_ibss (active_ibss=%d)\n",
30184 + dev->name, active_ibss);
30185 +#endif /* IEEE80211_IBSS_DEBUG */
30186 + spin_lock_bh(&local->sta_bss_lock);
30187 + list_for_each(ptr, &local->sta_bss_list) {
30188 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
30189 + if (ifsta->ssid_len != bss->ssid_len ||
30190 + memcmp(ifsta->ssid, bss->ssid, bss->ssid_len) != 0
30191 + || !(bss->capability & WLAN_CAPABILITY_IBSS))
30193 +#ifdef IEEE80211_IBSS_DEBUG
30194 + printk(KERN_DEBUG " bssid=" MACSTR " found\n",
30195 + MAC2STR(bss->bssid));
30196 +#endif /* IEEE80211_IBSS_DEBUG */
30197 + memcpy(bssid, bss->bssid, ETH_ALEN);
30199 + if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
30202 + spin_unlock_bh(&local->sta_bss_lock);
30204 +#ifdef IEEE80211_IBSS_DEBUG
30205 + printk(KERN_DEBUG " sta_find_ibss: selected " MACSTR " current "
30206 + MACSTR "\n", MAC2STR(bssid), MAC2STR(ifsta->bssid));
30207 +#endif /* IEEE80211_IBSS_DEBUG */
30208 + if (found && memcmp(ifsta->bssid, bssid, ETH_ALEN) != 0 &&
30209 + (bss = ieee80211_rx_bss_get(dev, bssid))) {
30210 + printk(KERN_DEBUG "%s: Selected IBSS BSSID " MACSTR
30211 + " based on configured SSID\n",
30212 + dev->name, MAC2STR(bssid));
30213 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30215 +#ifdef IEEE80211_IBSS_DEBUG
30216 + printk(KERN_DEBUG " did not try to join ibss\n");
30217 +#endif /* IEEE80211_IBSS_DEBUG */
30219 + /* Selected IBSS not found in current scan results - try to scan */
30220 + if (ifsta->state == IEEE80211_IBSS_JOINED &&
30221 + !ieee80211_sta_active_ibss(dev)) {
30222 + mod_timer(&ifsta->timer,
30223 + jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30224 + } else if (time_after(jiffies, local->last_scan_completed +
30225 + IEEE80211_SCAN_INTERVAL)) {
30226 + printk(KERN_DEBUG "%s: Trigger new scan to find an IBSS to "
30227 + "join\n", dev->name);
30228 + return ieee80211_sta_req_scan(dev, ifsta->ssid,
30229 + ifsta->ssid_len);
30230 + } else if (ifsta->state != IEEE80211_IBSS_JOINED) {
30231 + int interval = IEEE80211_SCAN_INTERVAL;
30233 + if (time_after(jiffies, ifsta->ibss_join_req +
30234 + IEEE80211_IBSS_JOIN_TIMEOUT)) {
30235 + if (ifsta->create_ibss &&
30236 + ieee80211_ibss_allowed(local))
30237 + return ieee80211_sta_create_ibss(dev, ifsta);
30238 + if (ifsta->create_ibss) {
30239 + printk(KERN_DEBUG "%s: IBSS not allowed on the"
30240 + " configured channel %d (%d MHz)\n",
30241 + dev->name, local->conf.channel,
30242 + local->conf.freq);
30245 + /* No IBSS found - decrease scan interval and continue
30247 + interval = IEEE80211_SCAN_INTERVAL_SLOW;
30250 + ifsta->state = IEEE80211_IBSS_SEARCH;
30251 + mod_timer(&ifsta->timer, jiffies + interval);
30259 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
30261 + struct ieee80211_sub_if_data *sdata;
30262 + struct ieee80211_if_sta *ifsta;
30263 + struct ieee80211_local *local = dev->priv;
30265 + if (len > IEEE80211_MAX_SSID_LEN)
30268 + /* TODO: This should always be done for IBSS, even if IEEE80211_QOS is
30269 + * not defined. */
30270 + if (local->hw->conf_tx) {
30271 + struct ieee80211_tx_queue_params qparam;
30274 + memset(&qparam, 0, sizeof(qparam));
30275 + /* TODO: are these ok defaults for all hw_modes? */
30278 + local->conf.phymode == MODE_IEEE80211B ? 31 : 15;
30279 + qparam.cw_max = 1023;
30280 + qparam.burst_time = 0;
30281 + for (i = IEEE80211_TX_QUEUE_DATA0; i < NUM_TX_DATA_QUEUES; i++)
30283 + local->hw->conf_tx(dev, i + IEEE80211_TX_QUEUE_DATA0,
30286 + /* IBSS uses different parameters for Beacon sending */
30288 + qparam.cw_min *= 2;
30290 + local->hw->conf_tx(dev, IEEE80211_TX_QUEUE_BEACON, &qparam);
30293 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30294 + ifsta = &sdata->u.sta;
30296 + if (ifsta->ssid_len != len || memcmp(ifsta->ssid, ssid, len) != 0)
30297 + ifsta->prev_bssid_set = 0;
30298 + memcpy(ifsta->ssid, ssid, len);
30299 + memset(ifsta->ssid + len, 0, IEEE80211_MAX_SSID_LEN - len);
30300 + ifsta->ssid_len = len;
30302 + ifsta->ssid_set = 1;
30303 + if (local->conf.mode == IW_MODE_ADHOC && !ifsta->bssid_set) {
30304 + ifsta->ibss_join_req = jiffies;
30305 + ifsta->state = IEEE80211_IBSS_SEARCH;
30306 + return ieee80211_sta_find_ibss(dev, ifsta);
30309 + if (ifsta->bssid_set && ifsta->state != IEEE80211_AUTHENTICATE)
30310 + ieee80211_sta_new_auth(dev, ifsta);
30316 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
30318 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30319 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30320 + memcpy(ssid, ifsta->ssid, ifsta->ssid_len);
30321 + *len = ifsta->ssid_len;
30326 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
30328 + struct ieee80211_local *local = dev->priv;
30329 + struct ieee80211_sub_if_data *sdata;
30330 + struct ieee80211_if_sta *ifsta;
30332 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30333 + ifsta = &sdata->u.sta;
30335 + memcpy(ifsta->bssid, bssid, ETH_ALEN);
30336 + if (local->conf.mode == IW_MODE_ADHOC)
30337 + memcpy(local->bssid, bssid, ETH_ALEN);
30339 + if (memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
30340 + ifsta->bssid_set = 0;
30342 + ifsta->bssid_set = 1;
30343 + if (ifsta->ssid_set)
30344 + ieee80211_sta_new_auth(dev, ifsta);
30350 +static void ieee80211_sta_save_oper_chan(struct net_device *dev)
30352 + struct ieee80211_local *local = dev->priv;
30353 + local->scan_oper_channel = local->conf.channel;
30354 + local->scan_oper_channel_val = local->conf.channel_val;
30355 + local->scan_oper_power_level = local->conf.power_level;
30356 + local->scan_oper_freq = local->conf.freq;
30357 + local->scan_oper_phymode = local->conf.phymode;
30358 + local->scan_oper_antenna_max = local->conf.antenna_max;
30362 +static int ieee80211_sta_restore_oper_chan(struct net_device *dev)
30364 + struct ieee80211_local *local = dev->priv;
30365 + local->conf.channel = local->scan_oper_channel;
30366 + local->conf.channel_val = local->scan_oper_channel_val;
30367 + local->conf.power_level = local->scan_oper_power_level;
30368 + local->conf.freq = local->scan_oper_freq;
30369 + local->conf.phymode = local->scan_oper_phymode;
30370 + local->conf.antenna_max = local->scan_oper_antenna_max;
30371 + return ieee80211_hw_config(dev);
30375 +static int ieee80211_active_scan(struct ieee80211_local *local)
30379 + for (m = 0; m < local->hw->num_modes; m++) {
30380 + struct ieee80211_hw_modes *mode = &local->hw->modes[m];
30381 + if (mode->mode != local->conf.phymode)
30383 + for (c = 0; c < mode->num_channels; c++) {
30384 + struct ieee80211_channel *chan = &mode->channels[c];
30385 + if (chan->flag & IEEE80211_CHAN_W_SCAN &&
30386 + chan->chan == local->conf.channel) {
30387 + if (chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN)
30398 +static void ieee80211_sta_scan_timer(unsigned long ptr)
30400 + struct net_device *dev = (struct net_device *) ptr;
30401 + struct ieee80211_local *local = dev->priv;
30402 + struct ieee80211_hw_modes *mode;
30403 + struct ieee80211_channel *chan;
30405 + union iwreq_data wrqu;
30407 + if (!local->sta_scanning)
30410 + switch (local->scan_state) {
30411 + case SCAN_SET_CHANNEL:
30412 + mode = &local->hw->modes[local->scan_hw_mode_idx];
30413 + if (local->scan_hw_mode_idx >= local->hw->num_modes ||
30414 + (local->scan_hw_mode_idx + 1 == local->hw->num_modes &&
30415 + local->scan_channel_idx >= mode->num_channels)) {
30416 + if (ieee80211_sta_restore_oper_chan(dev)) {
30417 + printk(KERN_DEBUG "%s: failed to restore "
30418 + "operational channel after scan\n",
30421 + printk(KERN_DEBUG "%s: scan completed\n", dev->name);
30422 + local->sta_scanning = 0;
30423 + local->last_scan_completed = jiffies;
30424 + memset(&wrqu, 0, sizeof(wrqu));
30425 + wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
30426 + if (local->conf.mode == IW_MODE_ADHOC) {
30427 + struct ieee80211_sub_if_data *sdata =
30428 + IEEE80211_DEV_TO_SUB_IF(dev);
30429 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30430 + if (!ifsta->bssid_set ||
30431 + (ifsta->state == IEEE80211_IBSS_JOINED &&
30432 + !ieee80211_sta_active_ibss(dev)))
30433 + ieee80211_sta_find_ibss(dev, ifsta);
30437 + skip = !(local->hw_modes & (1 << mode->mode));
30438 + chan = &mode->channels[local->scan_channel_idx];
30439 + if (!(chan->flag & IEEE80211_CHAN_W_SCAN) ||
30440 + (local->conf.mode == IW_MODE_ADHOC &&
30441 + !(chan->flag & IEEE80211_CHAN_W_IBSS)) ||
30442 + (local->hw_modes & (1 << MODE_IEEE80211G) &&
30443 + mode->mode == MODE_IEEE80211B && local->scan_skip_11b))
30448 + printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
30449 + dev->name, chan->chan, chan->freq);
30452 + local->conf.channel = chan->chan;
30453 + local->conf.channel_val = chan->val;
30454 + local->conf.power_level = chan->power_level;
30455 + local->conf.freq = chan->freq;
30456 + local->conf.phymode = mode->mode;
30457 + local->conf.antenna_max = chan->antenna_max;
30458 + if (ieee80211_hw_config(dev)) {
30459 + printk(KERN_DEBUG "%s: failed to set channel "
30460 + "%d (%d MHz) for scan\n", dev->name,
30461 + chan->chan, chan->freq);
30466 + local->scan_channel_idx++;
30467 + if (local->scan_channel_idx >=
30468 + local->hw->modes[local->scan_hw_mode_idx].num_channels) {
30469 + local->scan_hw_mode_idx++;
30470 + local->scan_channel_idx = 0;
30474 + local->scan_timer.expires = jiffies;
30478 + local->scan_timer.expires = jiffies + IEEE80211_PROBE_DELAY;
30479 + local->scan_state = SCAN_SEND_PROBE;
30481 + case SCAN_SEND_PROBE:
30482 + if (ieee80211_active_scan(local)) {
30483 + ieee80211_send_probe_req(dev, NULL, local->scan_ssid,
30484 + local->scan_ssid_len);
30485 + local->scan_timer.expires =
30486 + jiffies + IEEE80211_CHANNEL_TIME;
30488 + local->scan_timer.expires =
30489 + jiffies + IEEE80211_PASSIVE_CHANNEL_TIME;
30491 + local->scan_state = SCAN_SET_CHANNEL;
30495 + add_timer(&local->scan_timer);
30499 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
30501 + struct ieee80211_local *local = dev->priv;
30503 + if (ssid_len > IEEE80211_MAX_SSID_LEN)
30506 + /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
30507 + * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
30508 + * BSSID: MACAddress
30510 + * ScanType: ACTIVE, PASSIVE
30511 + * ProbeDelay: delay (in microseconds) to be used prior to transmitting
30512 + * a Probe frame during active scanning
30514 + * MinChannelTime (>= ProbeDelay), in TU
30515 + * MaxChannelTime: (>= MinChannelTime), in TU
30518 + /* MLME-SCAN.confirm
30519 + * BSSDescriptionSet
30520 + * ResultCode: SUCCESS, INVALID_PARAMETERS
30523 + /* TODO: if assoc, move to power save mode for the duration of the
30526 + if (local->sta_scanning)
30529 + printk(KERN_DEBUG "%s: starting scan\n", dev->name);
30531 + ieee80211_sta_save_oper_chan(dev);
30533 + local->sta_scanning = 1;
30534 + /* TODO: stop TX queue? */
30537 + local->scan_ssid_len = ssid_len;
30538 + memcpy(local->scan_ssid, ssid, ssid_len);
30540 + local->scan_ssid_len = 0;
30541 + local->scan_skip_11b = 1; /* FIX: clear this is 11g is not supported */
30542 + local->scan_state = SCAN_SET_CHANNEL;
30543 + local->scan_hw_mode_idx = 0;
30544 + local->scan_channel_idx = 0;
30545 + init_timer(&local->scan_timer);
30546 + local->scan_timer.data = (unsigned long) dev;
30547 + local->scan_timer.function = ieee80211_sta_scan_timer;
30548 + local->scan_timer.expires = jiffies + 1;
30549 + add_timer(&local->scan_timer);
30556 +ieee80211_sta_scan_result(struct net_device *dev,
30557 + struct ieee80211_sta_bss *bss,
30558 + char *current_ev, char *end_buf)
30560 + struct ieee80211_local *local = dev->priv;
30561 + struct iw_event iwe;
30563 + if (time_after(jiffies,
30564 + bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
30565 + return current_ev;
30567 + if (!(local->hw_modes & (1 << bss->hw_mode)))
30568 + return current_ev;
30570 + if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY &&
30571 + bss->wpa_ie == NULL && bss->rsn_ie == NULL)
30572 + return current_ev;
30574 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID &&
30575 + (local->scan_ssid_len != bss->ssid_len ||
30576 + memcmp(local->scan_ssid, bss->ssid, bss->ssid_len) != 0))
30577 + return current_ev;
30579 + memset(&iwe, 0, sizeof(iwe));
30580 + iwe.cmd = SIOCGIWAP;
30581 + iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
30582 + memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
30583 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30586 + memset(&iwe, 0, sizeof(iwe));
30587 + iwe.cmd = SIOCGIWESSID;
30588 + iwe.u.data.length = bss->ssid_len;
30589 + iwe.u.data.flags = 1;
30590 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30593 + if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
30594 + memset(&iwe, 0, sizeof(iwe));
30595 + iwe.cmd = SIOCGIWMODE;
30596 + if (bss->capability & WLAN_CAPABILITY_ESS)
30597 + iwe.u.mode = IW_MODE_MASTER;
30599 + iwe.u.mode = IW_MODE_ADHOC;
30600 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30604 + memset(&iwe, 0, sizeof(iwe));
30605 + iwe.cmd = SIOCGIWFREQ;
30606 + iwe.u.freq.m = bss->freq * 100000;
30607 + iwe.u.freq.e = 1;
30608 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30611 + memset(&iwe, 0, sizeof(iwe));
30612 + iwe.cmd = SIOCGIWENCODE;
30613 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
30614 + iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
30616 + iwe.u.data.flags = IW_ENCODE_DISABLED;
30617 + iwe.u.data.length = 0;
30618 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
30620 + if (bss && bss->wpa_ie) {
30623 + buf = kmalloc(30 + bss->wpa_ie_len * 2, GFP_ATOMIC);
30626 + p += sprintf(p, "wpa_ie=");
30627 + for (i = 0; i < bss->wpa_ie_len; i++)
30628 + p+= sprintf(p, "%02x", bss->wpa_ie[i]);
30629 + memset(&iwe, 0, sizeof(iwe));
30630 + iwe.cmd = IWEVCUSTOM;
30631 + iwe.u.data.length = strlen(buf);
30632 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30638 + if (bss && bss->rsn_ie) {
30641 + buf = kmalloc(30 + bss->rsn_ie_len * 2, GFP_ATOMIC);
30644 + p += sprintf(p, "rsn_ie=");
30645 + for (i = 0; i < bss->rsn_ie_len; i++)
30646 + p+= sprintf(p, "%02x", bss->rsn_ie[i]);
30647 + memset(&iwe, 0, sizeof(iwe));
30648 + iwe.cmd = IWEVCUSTOM;
30649 + iwe.u.data.length = strlen(buf);
30650 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30658 + buf = kmalloc(30, GFP_ATOMIC);
30660 + memset(&iwe, 0, sizeof(iwe));
30661 + iwe.cmd = IWEVCUSTOM;
30662 + sprintf(buf, "tsf=%016llx", bss->timestamp);
30663 + iwe.u.data.length = strlen(buf);
30664 + current_ev = iwe_stream_add_point(current_ev, end_buf,
30674 + if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO))
30677 + buf = kmalloc(100, GFP_ATOMIC);
30681 + memset(&iwe, 0, sizeof(iwe));
30682 + iwe.cmd = IWEVCUSTOM;
30683 + sprintf(buf, "bcn_int=%d", bss->beacon_int);
30684 + iwe.u.data.length = strlen(buf);
30685 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30688 + memset(&iwe, 0, sizeof(iwe));
30689 + iwe.cmd = IWEVCUSTOM;
30690 + sprintf(buf, "rssi=%d", bss->rssi);
30691 + iwe.u.data.length = strlen(buf);
30692 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30695 + memset(&iwe, 0, sizeof(iwe));
30696 + iwe.cmd = IWEVCUSTOM;
30697 + sprintf(buf, "capab=0x%04x", bss->capability);
30698 + iwe.u.data.length = strlen(buf);
30699 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30703 + p += sprintf(p, "supp_rates=");
30704 + for (i = 0; i < bss->supp_rates_len; i++)
30705 + p+= sprintf(p, "%02x", bss->supp_rates[i]);
30706 + memset(&iwe, 0, sizeof(iwe));
30707 + iwe.cmd = IWEVCUSTOM;
30708 + iwe.u.data.length = strlen(buf);
30709 + current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
30716 + return current_ev;
30720 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
30722 + struct ieee80211_local *local = dev->priv;
30723 + struct list_head *ptr;
30724 + char *current_ev = buf;
30725 + char *end_buf = buf + len;
30726 + struct ieee80211_sta_bss *bss;
30728 + spin_lock_bh(&local->sta_bss_lock);
30729 + list_for_each(ptr, &local->sta_bss_list) {
30730 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
30731 + current_ev = ieee80211_sta_scan_result(dev, bss, current_ev,
30734 + spin_unlock_bh(&local->sta_bss_lock);
30735 + return current_ev - buf;
30739 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
30741 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30742 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30743 + kfree(ifsta->extra_ie);
30745 + ifsta->extra_ie = NULL;
30746 + ifsta->extra_ie_len = 0;
30749 + ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
30750 + if (ifsta->extra_ie == NULL) {
30751 + ifsta->extra_ie_len = 0;
30754 + memcpy(ifsta->extra_ie, ie, len);
30755 + ifsta->extra_ie_len = len;
30756 + if (ifsta->bssid_set && ifsta->ssid_set &&
30757 + ifsta->state != IEEE80211_AUTHENTICATE)
30758 + ieee80211_sta_new_auth(dev, ifsta);
30763 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
30764 + struct sk_buff *skb, u8 *bssid,
30767 + struct ieee80211_local *local = dev->priv;
30768 + struct list_head *ptr;
30769 + struct sta_info *sta;
30770 + struct ieee80211_sub_if_data *sdata = NULL;
30771 + struct net_device *sta_dev = NULL;
30773 + /* TODO: Could consider removing the least recently used entry and
30774 + * allow new one to be added. */
30775 + if (local->num_sta >= IEEE80211_IBSS_MAX_STA_ENTRIES) {
30776 + if (net_ratelimit()) {
30777 + printk(KERN_DEBUG "%s: No room for a new IBSS STA "
30778 + "entry " MACSTR "\n", dev->name, MAC2STR(addr));
30783 + spin_lock_bh(&local->sub_if_lock);
30784 + list_for_each(ptr, &local->sub_if_list) {
30785 + sdata = list_entry(ptr, struct ieee80211_sub_if_data, list);
30786 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA &&
30787 + memcmp(bssid, sdata->u.sta.bssid, ETH_ALEN) == 0) {
30788 + sta_dev = sdata->dev;
30792 + spin_unlock_bh(&local->sub_if_lock);
30794 + if (sta_dev == NULL)
30797 + printk(KERN_DEBUG "%s: Adding new IBSS station " MACSTR " (dev=%s)\n",
30798 + dev->name, MAC2STR(addr), sta_dev->name);
30800 + sta = sta_info_add(local, dev, addr);
30801 + if (sta == NULL) {
30805 + sta->dev = sta_dev;
30806 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
30808 + rate_control_rate_init(local, sta);
30810 + return sta; /* caller will call sta_info_release() */
30814 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
30816 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30817 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30819 + printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
30820 + dev->name, reason);
30822 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30825 + ieee80211_send_deauth(dev, ifsta, reason);
30826 + ieee80211_set_associated(dev, ifsta, 0);
30831 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
30833 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30834 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30836 + printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
30837 + dev->name, reason);
30839 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30842 + if (!ifsta->associated)
30845 + ieee80211_send_disassoc(dev, ifsta, reason);
30846 + ieee80211_set_associated(dev, ifsta, 0);
30849 diff -Nur linux-2.6.16/net/d80211/ieee80211_sysfs.c linux-2.6.16-bcm43xx/net/d80211/ieee80211_sysfs.c
30850 --- linux-2.6.16/net/d80211/ieee80211_sysfs.c 1970-01-01 01:00:00.000000000 +0100
30851 +++ linux-2.6.16-bcm43xx/net/d80211/ieee80211_sysfs.c 2006-03-28 22:16:14.000000000 +0200
30854 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
30856 + * This program is free software; you can redistribute it and/or modify
30857 + * it under the terms of the GNU General Public License version 2 as
30858 + * published by the Free Software Foundation.
30861 +#include <linux/kernel.h>
30862 +#include <linux/device.h>
30863 +#include <linux/if.h>
30864 +#include <linux/interrupt.h>
30865 +#include <linux/rtnetlink.h>
30866 +#include <net/d80211.h>
30867 +#include "ieee80211_i.h"
30869 +#define to_ieee80211_local(class) container_of(class, struct ieee80211_local, class_dev)
30872 +static ssize_t store_add_iface(struct class_device *dev,
30873 + const char *buf, size_t len)
30875 + struct ieee80211_local *local = to_ieee80211_local(dev);
30878 + if (!capable(CAP_NET_ADMIN))
30880 + if (len > IFNAMSIZ)
30882 + /* Cannot call ieee80211_if_add_sta() with 'locked' parameter equal
30883 + * to zero as it would lead to call to register_netdev() and
30884 + * interpreting '%d' character in an interface name. */
30886 + res = ieee80211_if_add_sta(local->mdev, buf, 1);
30888 + return res < 0 ? res : len;
30891 +static ssize_t store_remove_iface(struct class_device *dev,
30892 + const char *buf, size_t len)
30894 + struct ieee80211_local *local = to_ieee80211_local(dev);
30897 + if (!capable(CAP_NET_ADMIN))
30899 + if (len > IFNAMSIZ)
30901 + res = ieee80211_if_remove_sta(local->mdev, buf, 0);
30902 + return res < 0 ? res : len;
30905 +static ssize_t show_max_iface_count(struct class_device *dev,
30908 + struct ieee80211_local *local = to_ieee80211_local(dev);
30910 + return sprintf(buf, "%d\n", local->conf.bss_count);
30913 +static ssize_t store_max_iface_count(struct class_device *dev,
30914 + const char *buf, size_t len)
30916 + struct ieee80211_local *local = to_ieee80211_local(dev);
30917 + unsigned long new_count;
30921 + if (!capable(CAP_NET_ADMIN))
30923 + new_count = simple_strtoul(buf, &endp, 0);
30927 + res = ieee80211_set_bss_count(local->mdev, new_count, NULL);
30929 + return res < 0 ? res : len;
30932 +#ifdef CONFIG_HOTPLUG
30933 +static int ieee80211_uevent(struct class_device *cd, char **envp,
30934 + int num_envp, char *buf, int size)
30936 + struct ieee80211_local *local = to_ieee80211_local(cd);
30938 + if (num_envp < 2)
30941 + if (snprintf(buf, size, "IEEE80211_DEV=phy%d",
30942 + local->dev_index) + 1 >= size)
30949 +static struct class_device_attribute ieee80211_class_dev_attrs[] = {
30950 + __ATTR(add_iface, S_IWUSR, NULL, store_add_iface),
30951 + __ATTR(remove_iface, S_IWUSR, NULL, store_remove_iface),
30952 + __ATTR(max_iface_count, S_IRUGO | S_IWUSR,
30953 + show_max_iface_count, store_max_iface_count),
30957 +static struct class ieee80211_class = {
30958 + .name = "ieee80211",
30959 + .class_dev_attrs = ieee80211_class_dev_attrs,
30960 +#ifdef CONFIG_HOTPLUG
30961 + .uevent = ieee80211_uevent,
30965 +int ieee80211_register_sysfs(struct ieee80211_local *local)
30967 + local->class_dev.class = &ieee80211_class;
30968 + local->class_dev.class_data = local;
30969 + snprintf(local->class_dev.class_id, BUS_ID_SIZE,
30970 + "phy%d", local->dev_index);
30971 + return class_device_register(&local->class_dev);
30974 +void ieee80211_unregister_sysfs(struct ieee80211_local *local)
30976 + class_device_del(&local->class_dev);
30979 +int ieee80211_sysfs_init(void)
30981 + return class_register(&ieee80211_class);
30984 +void ieee80211_sysfs_deinit(void)
30986 + class_unregister(&ieee80211_class);
30988 diff -Nur linux-2.6.16/net/d80211/Kconfig linux-2.6.16-bcm43xx/net/d80211/Kconfig
30989 --- linux-2.6.16/net/d80211/Kconfig 1970-01-01 01:00:00.000000000 +0100
30990 +++ linux-2.6.16-bcm43xx/net/d80211/Kconfig 2006-03-28 22:16:14.000000000 +0200
30993 + tristate "Generic IEEE 802.11 Networking Stack (dscape)"
30995 + This option enables the hardware independent IEEE 802.11
30996 + networking stack.
30998 +config D80211_DEBUG
30999 + bool "Enable debugging output"
31000 + depends on D80211
31002 + This option will enable debug tracing output for the
31003 + ieee80211 network stack.
31005 + If you are not trying to debug or develop the ieee80211
31006 + subsystem, you most likely want to say N here.
31008 +config D80211_VERBOSE_DEBUG
31009 + bool "Verbose debugging output"
31010 + depends on D80211_DEBUG
31013 + bool "TKIP debugging"
31014 + depends on D80211_DEBUG
31016 +config D80211_DEBUG_COUNTERS
31017 + bool "Extra statistics for TX/RX debugging"
31018 + depends on D80211_DEBUG
31020 +config HOSTAPD_WPA_TESTING
31021 + bool "Support for TKIP countermeasures testing"
31022 + depends on D80211_DEBUG
31023 diff -Nur linux-2.6.16/net/d80211/Makefile linux-2.6.16-bcm43xx/net/d80211/Makefile
31024 --- linux-2.6.16/net/d80211/Makefile 1970-01-01 01:00:00.000000000 +0100
31025 +++ linux-2.6.16-bcm43xx/net/d80211/Makefile 2006-03-28 22:16:14.000000000 +0200
31027 +obj-$(CONFIG_D80211) += 80211.o rate_control.o
31031 + ieee80211_ioctl.o \
31035 + ieee80211_proc.o \
31036 + ieee80211_scan.o \
31037 + ieee80211_sta.o \
31038 + ieee80211_dev.o \
31039 + ieee80211_sysfs.o \
31045 +ifeq ($(CONFIG_NET_SCHED),)
31046 + 80211-objs += fifo_qdisc.o
31049 +ifeq ($(CONFIG_D80211_LEDS),y)
31050 + 80211-objs += ieee80211_led.o
31053 diff -Nur linux-2.6.16/net/d80211/michael.c linux-2.6.16-bcm43xx/net/d80211/michael.c
31054 --- linux-2.6.16/net/d80211/michael.c 1970-01-01 01:00:00.000000000 +0100
31055 +++ linux-2.6.16-bcm43xx/net/d80211/michael.c 2006-03-28 22:16:14.000000000 +0200
31058 + * Michael MIC implementation - optimized for TKIP MIC operations
31059 + * Copyright 2002-2003, Instant802 Networks, Inc.
31061 + * This program is free software; you can redistribute it and/or modify
31062 + * it under the terms of the GNU General Public License version 2 as
31063 + * published by the Free Software Foundation.
31066 +#include <linux/types.h>
31068 +#include "michael.h"
31070 +static inline u32 rotr(u32 val, int bits)
31072 + return (val >> bits) | (val << (32 - bits));
31076 +static inline u32 rotl(u32 val, int bits)
31078 + return (val << bits) | (val >> (32 - bits));
31082 +static inline u32 xswap(u32 val)
31084 + return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
31088 +#define michael_block(l, r) \
31090 + r ^= rotl(l, 17); \
31094 + r ^= rotl(l, 3); \
31096 + r ^= rotr(l, 2); \
31101 +static inline u32 michael_get32(u8 *data)
31103 + return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
31107 +static inline void michael_put32(u32 val, u8 *data)
31109 + data[0] = val & 0xff;
31110 + data[1] = (val >> 8) & 0xff;
31111 + data[2] = (val >> 16) & 0xff;
31112 + data[3] = (val >> 24) & 0xff;
31116 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31117 + u8 *data, size_t data_len, u8 *mic)
31120 + size_t block, blocks, left;
31122 + l = michael_get32(key);
31123 + r = michael_get32(key + 4);
31125 + /* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC
31126 + * calculation, but it is _not_ transmitted */
31127 + l ^= michael_get32(da);
31128 + michael_block(l, r);
31129 + l ^= da[4] | (da[5] << 8) | (sa[0] << 16) | (sa[1] << 24);
31130 + michael_block(l, r);
31131 + l ^= michael_get32(&sa[2]);
31132 + michael_block(l, r);
31134 + michael_block(l, r);
31137 + blocks = data_len / 4;
31138 + left = data_len % 4;
31140 + for (block = 0; block < blocks; block++) {
31141 + l ^= michael_get32(&data[block * 4]);
31142 + michael_block(l, r);
31145 + /* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
31146 + * total length a multiple of 4. */
31148 + while (left > 0) {
31151 + val |= data[blocks * 4 + left];
31154 + michael_block(l, r);
31155 + /* last block is zero, so l ^ 0 = l */
31156 + michael_block(l, r);
31158 + michael_put32(l, mic);
31159 + michael_put32(r, mic + 4);
31161 diff -Nur linux-2.6.16/net/d80211/michael.h linux-2.6.16-bcm43xx/net/d80211/michael.h
31162 --- linux-2.6.16/net/d80211/michael.h 1970-01-01 01:00:00.000000000 +0100
31163 +++ linux-2.6.16-bcm43xx/net/d80211/michael.h 2006-03-28 22:16:14.000000000 +0200
31166 + * Michael MIC implementation - optimized for TKIP MIC operations
31167 + * Copyright 2002-2003, Instant802 Networks, Inc.
31169 + * This program is free software; you can redistribute it and/or modify
31170 + * it under the terms of the GNU General Public License version 2 as
31171 + * published by the Free Software Foundation.
31177 +#include <linux/types.h>
31179 +#define MICHAEL_MIC_LEN 8
31181 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31182 + u8 *data, size_t data_len, u8 *mic);
31184 +#endif /* MICHAEL_H */
31185 diff -Nur linux-2.6.16/net/d80211/rate_control.c linux-2.6.16-bcm43xx/net/d80211/rate_control.c
31186 --- linux-2.6.16/net/d80211/rate_control.c 1970-01-01 01:00:00.000000000 +0100
31187 +++ linux-2.6.16-bcm43xx/net/d80211/rate_control.c 2006-03-28 22:16:14.000000000 +0200
31190 + * Copyright 2002-2005, Instant802 Networks, Inc.
31191 + * Copyright 2005, Devicescape Software, Inc.
31193 + * This program is free software; you can redistribute it and/or modify
31194 + * it under the terms of the GNU General Public License version 2 as
31195 + * published by the Free Software Foundation.
31198 +#include <linux/config.h>
31199 +#include <linux/version.h>
31200 +#include <linux/module.h>
31201 +#include <linux/init.h>
31202 +#include <linux/netdevice.h>
31203 +#include <linux/types.h>
31204 +#include <linux/slab.h>
31205 +#include <linux/skbuff.h>
31206 +#include <linux/compiler.h>
31208 +#include <net/d80211.h>
31209 +#include "ieee80211_i.h"
31210 +#include "rate_control.h"
31213 +/* This is a minimal implementation of TX rate controlling that can be used
31214 + * as the default when no improved mechanisms are available. */
31217 +#define RATE_CONTROL_EMERG_DEC 2
31218 +#define RATE_CONTROL_INTERVAL (HZ / 20)
31219 +#define RATE_CONTROL_MIN_TX 10
31221 +MODULE_ALIAS("ieee80211_rate_control");
31223 +static void rate_control_rate_inc(struct ieee80211_local *local,
31224 + struct sta_info *sta)
31226 + struct ieee80211_sub_if_data *sdata;
31227 + int i = sta->txrate;
31230 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31231 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
31232 + /* forced unicast rate - do not change STA rate */
31236 + maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
31238 + if (i > local->num_curr_rates)
31239 + i = local->num_curr_rates - 2;
31241 + while (i + 1 < local->num_curr_rates) {
31243 + if (sta->supp_rates & BIT(i) &&
31244 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED &&
31245 + (maxrate < 0 || i <= maxrate)) {
31253 +static void rate_control_rate_dec(struct ieee80211_local *local,
31254 + struct sta_info *sta)
31256 + struct ieee80211_sub_if_data *sdata;
31257 + int i = sta->txrate;
31259 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31260 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
31261 + /* forced unicast rate - do not change STA rate */
31265 + if (i > local->num_curr_rates)
31266 + i = local->num_curr_rates;
31270 + if (sta->supp_rates & BIT(i) &&
31271 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED) {
31279 +static struct ieee80211_rate *
31280 +rate_control_lowest_rate(struct ieee80211_local *local)
31284 + for (i = 0; i < local->num_curr_rates; i++) {
31285 + struct ieee80211_rate *rate = &local->curr_rates[i];
31287 + if (rate->flags & IEEE80211_RATE_SUPPORTED
31292 + printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
31294 + return &local->curr_rates[0];
31298 +struct global_rate_control {
31302 +struct sta_rate_control {
31303 + unsigned long last_rate_change;
31304 + u32 tx_num_failures;
31307 + unsigned long avg_rate_update;
31308 + u32 tx_avg_rate_sum;
31309 + u32 tx_avg_rate_num;
31313 +static void rate_control_simple_tx_status(struct net_device *dev,
31314 + struct sk_buff *skb,
31315 + struct ieee80211_tx_status *status)
31317 + struct ieee80211_local *local = dev->priv;
31318 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
31319 + struct sta_info *sta;
31320 + struct sta_rate_control *srctrl;
31322 + sta = sta_info_get(local, hdr->addr1);
31327 + srctrl = sta->rate_ctrl_priv;
31328 + srctrl->tx_num_xmit++;
31329 + if (status->excessive_retries) {
31330 + sta->antenna_sel = sta->antenna_sel == 1 ? 2 : 1;
31331 + if (local->sta_antenna_sel == STA_ANTENNA_SEL_SW_CTRL_DEBUG) {
31332 + printk(KERN_DEBUG "%s: " MACSTR " TX antenna --> %d "
31334 + dev->name, MAC2STR(hdr->addr1),
31335 + sta->antenna_sel, jiffies);
31337 + srctrl->tx_num_failures++;
31338 + sta->tx_retry_failed++;
31339 + sta->tx_num_consecutive_failures++;
31340 + sta->tx_num_mpdu_fail++;
31342 + sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
31343 + sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
31344 + sta->last_ack_rssi[2] = status->ack_signal;
31345 + sta->tx_num_consecutive_failures = 0;
31346 + sta->tx_num_mpdu_ok++;
31348 + sta->tx_retry_count += status->retry_count;
31349 + sta->tx_num_mpdu_fail += status->retry_count;
31351 + if (time_after(jiffies,
31352 + srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
31353 + srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
31355 + srctrl->last_rate_change = jiffies;
31357 + per_failed = (100 * sta->tx_num_mpdu_fail) /
31358 + (sta->tx_num_mpdu_fail + sta->tx_num_mpdu_ok);
31359 + /* TODO: calculate average per_failed to make adjusting
31360 + * parameters easier */
31362 + if (net_ratelimit()) {
31363 + printk(KERN_DEBUG "MPDU fail=%d ok=%d per_failed=%d\n",
31364 + sta->tx_num_mpdu_fail, sta->tx_num_mpdu_ok,
31369 + if (per_failed > local->rate_ctrl_num_down) {
31370 + rate_control_rate_dec(local, sta);
31371 + } else if (per_failed < local->rate_ctrl_num_up) {
31372 + rate_control_rate_inc(local, sta);
31374 + srctrl->tx_avg_rate_sum += local->curr_rates[sta->txrate].rate;
31375 + srctrl->tx_avg_rate_num++;
31376 + srctrl->tx_num_failures = 0;
31377 + srctrl->tx_num_xmit = 0;
31378 + } else if (sta->tx_num_consecutive_failures >=
31379 + RATE_CONTROL_EMERG_DEC) {
31380 + rate_control_rate_dec(local, sta);
31383 + if (srctrl->avg_rate_update + 60 * HZ < jiffies) {
31384 + srctrl->avg_rate_update = jiffies;
31385 + if (srctrl->tx_avg_rate_num > 0) {
31386 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31387 + printk(KERN_DEBUG "%s: STA " MACSTR " Average rate: "
31389 + dev->name, MAC2STR(sta->addr),
31390 + srctrl->tx_avg_rate_sum /
31391 + srctrl->tx_avg_rate_num,
31392 + srctrl->tx_avg_rate_sum,
31393 + srctrl->tx_avg_rate_num);
31394 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31395 + srctrl->tx_avg_rate_sum = 0;
31396 + srctrl->tx_avg_rate_num = 0;
31400 + sta_info_release(local, sta);
31404 +static struct ieee80211_rate *
31405 +rate_control_simple_get_rate(struct net_device *dev, struct sk_buff *skb,
31406 + struct rate_control_extra *extra)
31408 + struct ieee80211_local *local = dev->priv;
31409 + struct ieee80211_sub_if_data *sdata;
31410 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
31411 + struct sta_info *sta;
31412 + int rateidx, nonerp_idx;
31415 + memset(extra, 0, sizeof(*extra));
31417 + fc = le16_to_cpu(hdr->frame_control);
31418 + if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA ||
31419 + (hdr->addr1[0] & 0x01)) {
31420 + /* Send management frames and broadcast/multicast data using
31421 + * lowest rate. */
31422 + /* TODO: this could probably be improved.. */
31423 + return rate_control_lowest_rate(local);
31426 + sta = sta_info_get(local, hdr->addr1);
31429 + return rate_control_lowest_rate(local);
31431 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
31432 + if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
31433 + sta->txrate = sdata->bss->force_unicast_rateidx;
31435 + rateidx = sta->txrate;
31437 + if (rateidx >= local->num_curr_rates)
31438 + rateidx = local->num_curr_rates - 1;
31440 + sta->last_txrate = rateidx;
31441 + nonerp_idx = rateidx;
31442 + while (nonerp_idx > 0 &&
31443 + ((local->curr_rates[nonerp_idx].flags & IEEE80211_RATE_ERP) ||
31444 + !(local->curr_rates[nonerp_idx].flags &
31445 + IEEE80211_RATE_SUPPORTED) ||
31446 + !(sta->supp_rates & BIT(nonerp_idx))))
31448 + extra->nonerp_idx = nonerp_idx;
31449 + extra->nonerp = &local->curr_rates[extra->nonerp_idx];
31451 + sta_info_release(local, sta);
31453 + return &local->curr_rates[rateidx];
31457 +static void rate_control_simple_rate_init(struct ieee80211_local *local,
31458 + struct sta_info *sta)
31462 + /* TODO: what is a good starting rate for STA? About middle? Maybe not
31463 + * the lowest or the highest rate.. Could consider using RSSI from
31464 + * previous packets? Need to have IEEE 802.1X auth succeed immediately
31465 + * after assoc.. */
31466 + for (i = 0; i < local->num_curr_rates; i++) {
31467 + if ((sta->supp_rates & BIT(i)) &&
31468 + (local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED))
31474 +static void * rate_control_simple_alloc(struct ieee80211_local *local)
31476 + struct global_rate_control *rctrl;
31478 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31479 + if (rctrl == NULL) {
31482 + memset(rctrl, 0, sizeof(*rctrl));
31487 +static void rate_control_simple_free(void *priv)
31489 + struct global_rate_control *rctrl = priv;
31494 +static void rate_control_simple_clear(void *priv)
31499 +static void * rate_control_simple_alloc_sta(void)
31501 + struct sta_rate_control *rctrl;
31503 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31504 + if (rctrl == NULL) {
31507 + memset(rctrl, 0, sizeof(*rctrl));
31512 +static void rate_control_simple_free_sta(void *priv)
31514 + struct sta_rate_control *rctrl = priv;
31519 +static int rate_control_simple_status_sta(struct ieee80211_local *local,
31520 + struct sta_info *sta, char *buf)
31523 + struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
31525 + p += sprintf(p, "tx_avg_rate_sum=%d\n", srctrl->tx_avg_rate_sum);
31526 + p += sprintf(p, "tx_avg_rate_num=%d\n", srctrl->tx_avg_rate_num);
31527 + if (srctrl->tx_avg_rate_num)
31528 + p += sprintf(p, "tx_avg_rate_avg=%d\n",
31529 + srctrl->tx_avg_rate_sum /
31530 + srctrl->tx_avg_rate_num);
31535 +static int rate_control_simple_status_global(struct ieee80211_local *local,
31542 +static struct rate_control_ops rate_control_simple = {
31543 + .name = "simple",
31544 + .tx_status = rate_control_simple_tx_status,
31545 + .get_rate = rate_control_simple_get_rate,
31546 + .rate_init = rate_control_simple_rate_init,
31547 + .clear = rate_control_simple_clear,
31548 + .status_sta = rate_control_simple_status_sta,
31549 + .status_global = rate_control_simple_status_global,
31550 + .alloc = rate_control_simple_alloc,
31551 + .free = rate_control_simple_free,
31552 + .alloc_sta = rate_control_simple_alloc_sta,
31553 + .free_sta = rate_control_simple_free_sta,
31557 +int __init rate_control_simple_init(void)
31559 + return ieee80211_rate_control_register(&rate_control_simple);
31563 +static void __exit rate_control_simple_exit(void)
31565 + ieee80211_rate_control_unregister(&rate_control_simple);
31569 +module_init(rate_control_simple_init);
31570 +module_exit(rate_control_simple_exit);
31572 +MODULE_DESCRIPTION("Simple rate control algorithm for ieee80211");
31573 +MODULE_LICENSE("GPL");
31574 diff -Nur linux-2.6.16/net/d80211/rate_control.h linux-2.6.16-bcm43xx/net/d80211/rate_control.h
31575 --- linux-2.6.16/net/d80211/rate_control.h 1970-01-01 01:00:00.000000000 +0100
31576 +++ linux-2.6.16-bcm43xx/net/d80211/rate_control.h 2006-03-28 22:16:14.000000000 +0200
31579 + * Copyright 2002-2005, Instant802 Networks, Inc.
31580 + * Copyright 2005, Devicescape Software, Inc.
31582 + * This program is free software; you can redistribute it and/or modify
31583 + * it under the terms of the GNU General Public License version 2 as
31584 + * published by the Free Software Foundation.
31587 +#ifndef RATE_CONTROL
31588 +#define RATE_CONTROL
31590 +#include <linux/netdevice.h>
31591 +#include <linux/skbuff.h>
31592 +#include <linux/types.h>
31593 +#include <net/d80211.h>
31594 +#include "ieee80211_i.h"
31595 +#include "sta_info.h"
31597 +#define RATE_CONTROL_NUM_DOWN 20
31598 +#define RATE_CONTROL_NUM_UP 15
31601 +struct rate_control_extra {
31602 + /* values from rate_control_get_rate() to the caller: */
31603 + struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
31605 + int startidx, endidx, rateidx;
31606 + struct ieee80211_rate *nonerp;
31609 + /* parameters from the caller to rate_control_get_rate(): */
31610 + int mgmt_data; /* this is data frame that is used for management
31611 + * (e.g., IEEE 802.1X EAPOL) */
31616 +struct rate_control_ops {
31617 + const char *name;
31618 + void (*tx_status)(struct net_device *dev, struct sk_buff *skb,
31619 + struct ieee80211_tx_status *status);
31620 + struct ieee80211_rate *
31621 + (*get_rate)(struct net_device *dev, struct sk_buff *skb,
31622 + struct rate_control_extra *extra);
31623 + void (*rate_init)(struct ieee80211_local *local, struct sta_info *sta);
31624 + void (*clear)(void *priv);
31625 + int (*status_sta)(struct ieee80211_local *local,
31626 + struct sta_info *sta, char *buf);
31627 + int (*status_global)(struct ieee80211_local *local, char *buf);
31629 + void * (*alloc)(struct ieee80211_local *local);
31630 + void (*free)(void *priv);
31631 + void * (*alloc_sta)(void);
31632 + void (*free_sta)(void *priv);
31636 +int ieee80211_rate_control_register(struct rate_control_ops *ops);
31637 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
31640 +static inline void rate_control_tx_status(struct net_device *dev,
31641 + struct sk_buff *skb,
31642 + struct ieee80211_tx_status *status)
31644 + struct ieee80211_local *local = dev->priv;
31645 + local->rate_ctrl->tx_status(dev, skb, status);
31649 +static inline struct ieee80211_rate *
31650 +rate_control_get_rate(struct net_device *dev, struct sk_buff *skb,
31651 + struct rate_control_extra *extra)
31653 + struct ieee80211_local *local = dev->priv;
31654 + return local->rate_ctrl->get_rate(dev, skb, extra);
31658 +static inline void rate_control_rate_init(struct ieee80211_local *local,
31659 + struct sta_info *sta)
31661 + local->rate_ctrl->rate_init(local, sta);
31665 +static inline void rate_control_clear(struct ieee80211_local *local)
31667 + local->rate_ctrl->clear(local->rate_ctrl_priv);
31671 +static inline int rate_control_status_sta(struct ieee80211_local *local,
31672 + struct sta_info *sta, char *buf)
31674 + return local->rate_ctrl->status_sta(local, sta, buf);
31678 +static inline int rate_control_status_global(struct ieee80211_local *local,
31681 + return local->rate_ctrl->status_global(local, buf);
31685 +static inline void * rate_control_alloc(struct ieee80211_local *local)
31687 + return local->rate_ctrl->alloc(local);
31691 +static inline void rate_control_free(struct ieee80211_local *local)
31693 + if (local->rate_ctrl == NULL || local->rate_ctrl_priv == NULL)
31695 + local->rate_ctrl->free(local->rate_ctrl_priv);
31696 + local->rate_ctrl_priv = NULL;
31700 +static inline void * rate_control_alloc_sta(struct ieee80211_local *local)
31702 + return local->rate_ctrl->alloc_sta();
31706 +static inline void rate_control_free_sta(struct ieee80211_local *local,
31709 + local->rate_ctrl->free_sta(priv);
31712 +#endif /* RATE_CONTROL */
31713 diff -Nur linux-2.6.16/net/d80211/sta_info.c linux-2.6.16-bcm43xx/net/d80211/sta_info.c
31714 --- linux-2.6.16/net/d80211/sta_info.c 1970-01-01 01:00:00.000000000 +0100
31715 +++ linux-2.6.16-bcm43xx/net/d80211/sta_info.c 2006-03-28 22:16:14.000000000 +0200
31718 + * Copyright 2002-2005, Instant802 Networks, Inc.
31720 + * This program is free software; you can redistribute it and/or modify
31721 + * it under the terms of the GNU General Public License version 2 as
31722 + * published by the Free Software Foundation.
31725 +#include <linux/config.h>
31726 +#include <linux/version.h>
31727 +#include <linux/module.h>
31728 +#include <linux/init.h>
31729 +#include <linux/netdevice.h>
31730 +#include <linux/types.h>
31731 +#include <linux/slab.h>
31732 +#include <linux/skbuff.h>
31733 +#include <linux/if_arp.h>
31735 +#include <net/d80211.h>
31736 +#include "ieee80211_i.h"
31737 +#include "ieee80211_proc.h"
31738 +#include "rate_control.h"
31741 +/* Caller must hold local->sta_lock */
31742 +static void sta_info_hash_add(struct ieee80211_local *local,
31743 + struct sta_info *sta)
31745 + sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
31746 + local->sta_hash[STA_HASH(sta->addr)] = sta;
31750 +/* Caller must hold local->sta_lock */
31751 +static void sta_info_hash_del(struct ieee80211_local *local,
31752 + struct sta_info *sta)
31754 + struct sta_info *s;
31756 + s = local->sta_hash[STA_HASH(sta->addr)];
31759 + if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
31760 + local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
31764 + while (s->hnext != NULL &&
31765 + memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
31767 + if (s->hnext != NULL)
31768 + s->hnext = s->hnext->hnext;
31770 + printk(KERN_ERR "%s: could not remove STA " MACSTR " from "
31771 + "hash table\n", local->mdev->name, MAC2STR(sta->addr));
31775 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr)
31777 + struct sta_info *sta;
31779 + spin_lock_bh(&local->sta_lock);
31780 + sta = local->sta_hash[STA_HASH(addr)];
31782 + if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
31783 + atomic_inc(&sta->users);
31786 + sta = sta->hnext;
31788 + spin_unlock_bh(&local->sta_lock);
31794 +int sta_info_min_txrate_get(struct ieee80211_local *local)
31796 + struct sta_info *sta;
31797 + int min_txrate = 9999999;
31800 + spin_lock_bh(&local->sta_lock);
31801 + for (i = 0; i < STA_HASH_SIZE; i++) {
31802 + sta = local->sta_hash[i];
31804 + if (sta->txrate < min_txrate)
31805 + min_txrate = sta->txrate;
31806 + sta = sta->hnext;
31809 + spin_unlock_bh(&local->sta_lock);
31810 + if (min_txrate == 9999999)
31813 + return min_txrate;
31817 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta)
31819 + struct sk_buff *skb;
31821 + if (!atomic_dec_and_test(&sta->users))
31824 + /* free sta structure; it has already been removed from
31825 + * hash table etc. external structures. Make sure that all
31826 + * buffered frames are release (one might have been added
31827 + * after sta_info_free() was called). */
31828 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31829 + local->total_ps_buffered--;
31830 + dev_kfree_skb_any(skb);
31832 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31833 + dev_kfree_skb_any(skb);
31835 + rate_control_free_sta(local, sta->rate_ctrl_priv);
31840 +struct sta_info * sta_info_add(struct ieee80211_local *local,
31841 + struct net_device *dev, u8 *addr)
31843 + struct sta_info *sta;
31845 + sta = kmalloc(sizeof(*sta), GFP_ATOMIC);
31849 + memset(sta, 0, sizeof(*sta));
31851 + sta->rate_ctrl_priv = rate_control_alloc_sta(local);
31852 + if (sta->rate_ctrl_priv == NULL) {
31857 + memcpy(sta->addr, addr, ETH_ALEN);
31859 + skb_queue_head_init(&sta->ps_tx_buf);
31860 + skb_queue_head_init(&sta->tx_filtered);
31861 + atomic_inc(&sta->users); /* sta in hashlist etc, decremented by
31862 + * sta_info_free() */
31863 + atomic_inc(&sta->users); /* sta used by caller, decremented by
31864 + * sta_info_release() */
31865 + spin_lock_bh(&local->sta_lock);
31866 + list_add(&sta->list, &local->sta_list);
31867 + local->num_sta++;
31868 + sta_info_hash_add(local, sta);
31869 + spin_unlock_bh(&local->sta_lock);
31870 + if (local->hw->sta_table_notification)
31871 + local->hw->sta_table_notification(local->mdev, local->num_sta);
31872 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
31874 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31875 + printk(KERN_DEBUG "%s: Added STA " MACSTR "\n",
31876 + local->mdev->name, MAC2STR(addr));
31877 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31879 + if (!in_interrupt()) {
31880 + ieee80211_proc_init_sta(local, sta);
31882 + /* procfs entry adding might sleep, so schedule process context
31883 + * task for adding proc entry for STAs that do not yet have
31885 + schedule_work(&local->sta_proc_add);
31892 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
31895 + struct sk_buff *skb;
31896 + struct ieee80211_sub_if_data *sdata;
31899 + spin_lock_bh(&local->sta_lock);
31900 + sta_info_hash_del(local, sta);
31901 + list_del(&sta->list);
31902 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
31903 + if (sta->flags & WLAN_STA_PS) {
31904 + sta->flags &= ~WLAN_STA_PS;
31906 + atomic_dec(&sdata->bss->num_sta_ps);
31908 + local->num_sta--;
31909 + sta_info_remove_aid_ptr(sta);
31911 + spin_unlock_bh(&local->sta_lock);
31912 + if (local->hw->sta_table_notification)
31913 + local->hw->sta_table_notification(local->mdev, local->num_sta);
31915 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31916 + local->total_ps_buffered--;
31917 + dev_kfree_skb_any(skb);
31919 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31920 + dev_kfree_skb_any(skb);
31924 + if (local->hw->set_key) {
31925 + struct ieee80211_key_conf *key;
31926 + key = ieee80211_key_data2conf(local, sta->key);
31928 + local->hw->set_key(local->mdev, DISABLE_KEY,
31929 + sta->addr, key, sta->aid);
31935 + } else if (sta->key_idx_compression != HW_KEY_IDX_INVALID) {
31936 + struct ieee80211_key_conf conf;
31937 + memset(&conf, 0, sizeof(conf));
31938 + conf.hw_key_idx = sta->key_idx_compression;
31939 + conf.alg = ALG_NULL;
31940 + conf.force_sw_encrypt = 1;
31941 + local->hw->set_key(local->mdev, DISABLE_KEY, sta->addr, &conf,
31943 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
31946 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
31947 + printk(KERN_DEBUG "%s: Removed STA " MACSTR "\n",
31948 + local->mdev->name, MAC2STR(sta->addr));
31949 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
31951 + ieee80211_proc_deinit_sta(local, sta);
31953 + if (atomic_read(&sta->users) != 1) {
31954 + /* This is OK, but printed for debugging. The station structure
31955 + * will be removed when the other user of the data calls
31956 + * sta_info_release(). */
31957 + printk(KERN_DEBUG "%s: STA " MACSTR " users count %d when "
31958 + "removing it\n", local->mdev->name, MAC2STR(sta->addr),
31959 + atomic_read(&sta->users));
31962 + sta_info_release(local, sta);
31966 +static inline int sta_info_buffer_expired(struct sk_buff *skb)
31968 + struct ieee80211_tx_packet_data *pkt_data;
31972 + /* TODO: this could be improved by passing STA listen interval into
31973 + * the kernel driver and expiring frames after 2 x listen_interval x
31974 + * beacon interval */
31976 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
31977 + return time_after(jiffies, pkt_data->jiffies + STA_TX_BUFFER_EXPIRE);
31981 +static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
31982 + struct sta_info *sta)
31984 + unsigned long flags;
31985 + struct sk_buff *skb;
31987 + if (skb_queue_empty(&sta->ps_tx_buf))
31991 + spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
31992 + skb = skb_peek(&sta->ps_tx_buf);
31993 + if (sta_info_buffer_expired(skb))
31994 + skb = __skb_dequeue(&sta->ps_tx_buf);
31997 + spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
32000 + local->total_ps_buffered--;
32001 + printk(KERN_DEBUG "Buffered frame expired (STA "
32002 + MACSTR ")\n", MAC2STR(sta->addr));
32003 + dev_kfree_skb(skb);
32010 +static void sta_info_cleanup(unsigned long data)
32012 + struct ieee80211_local *local = (struct ieee80211_local *) data;
32013 + struct list_head *ptr;
32015 + spin_lock_bh(&local->sta_lock);
32016 + ptr = local->sta_list.next;
32017 + while (ptr && ptr != &local->sta_list) {
32018 + struct sta_info *sta = (struct sta_info *) ptr;
32019 + atomic_inc(&sta->users);
32020 + sta_info_cleanup_expire_buffered(local, sta);
32021 + sta_info_release(local, sta);
32024 + spin_unlock_bh(&local->sta_lock);
32026 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
32027 + add_timer(&local->sta_cleanup);
32031 +static void sta_info_proc_add_task(void *data)
32033 + struct ieee80211_local *local = data;
32034 + struct list_head *ptr;
32035 + struct sta_info *sta;
32036 + int max_adds = 100;
32038 + while (max_adds > 0) {
32040 + spin_lock_bh(&local->sta_lock);
32041 + list_for_each(ptr, &local->sta_list) {
32042 + sta = list_entry(ptr, struct sta_info, list);
32043 + if (!sta->proc_entry_added) {
32044 + atomic_inc(&sta->users);
32049 + spin_unlock_bh(&local->sta_lock);
32054 + ieee80211_proc_init_sta(local, sta);
32055 + atomic_dec(&sta->users);
32062 +void sta_info_init(struct ieee80211_local *local)
32064 + spin_lock_init(&local->sta_lock);
32065 + INIT_LIST_HEAD(&local->sta_list);
32067 + init_timer(&local->sta_cleanup);
32068 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
32069 + local->sta_cleanup.data = (unsigned long) local;
32070 + local->sta_cleanup.function = sta_info_cleanup;
32072 + INIT_WORK(&local->sta_proc_add, sta_info_proc_add_task, local);
32075 +void sta_info_start(struct ieee80211_local *local)
32077 + add_timer(&local->sta_cleanup);
32080 +void sta_info_stop(struct ieee80211_local *local)
32082 + struct list_head *ptr;
32084 + del_timer(&local->sta_cleanup);
32086 + ptr = local->sta_list.next;
32087 + while (ptr && ptr != &local->sta_list) {
32088 + struct sta_info *sta = (struct sta_info *) ptr;
32090 + sta_info_free(local, sta, 0);
32095 +void sta_info_remove_aid_ptr(struct sta_info *sta)
32097 + struct ieee80211_sub_if_data *sdata;
32099 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
32100 + if (sta->aid <= 0 || !sdata->bss)
32103 + sdata->bss->sta_aid[sta->aid - 1] = NULL;
32104 + if (sta->aid == sdata->bss->max_aid) {
32105 + while (sdata->bss->max_aid > 0 &&
32106 + sdata->bss->sta_aid[sdata->bss->max_aid - 1] == NULL)
32107 + sdata->bss->max_aid--;
32113 + * sta_info_flush - flush matching STA entries from the STA table
32114 + * @local: local interface data
32115 + * @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
32117 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
32119 + struct list_head *ptr, *n;
32121 + spin_lock_bh(&local->sta_lock);
32123 + list_for_each_safe(ptr, n, &local->sta_list) {
32124 + struct sta_info *sta = list_entry(ptr, struct sta_info, list);
32125 + if (dev == NULL || dev == sta->dev)
32126 + sta_info_free(local, sta, 1);
32128 + spin_unlock_bh(&local->sta_lock);
32130 diff -Nur linux-2.6.16/net/d80211/sta_info.h linux-2.6.16-bcm43xx/net/d80211/sta_info.h
32131 --- linux-2.6.16/net/d80211/sta_info.h 1970-01-01 01:00:00.000000000 +0100
32132 +++ linux-2.6.16-bcm43xx/net/d80211/sta_info.h 2006-03-28 22:16:14.000000000 +0200
32135 + * Copyright 2002-2005, Devicescape Software, Inc.
32137 + * This program is free software; you can redistribute it and/or modify
32138 + * it under the terms of the GNU General Public License version 2 as
32139 + * published by the Free Software Foundation.
32142 +#ifndef STA_INFO_H
32143 +#define STA_INFO_H
32145 +#include <linux/if_ether.h>
32146 +#include <linux/types.h>
32147 +#include "ieee80211_i.h"
32148 +#include "ieee80211_key.h"
32150 +/* Stations flags (struct sta_info::flags) */
32151 +#define WLAN_STA_AUTH BIT(0)
32152 +#define WLAN_STA_ASSOC BIT(1)
32153 +#define WLAN_STA_PS BIT(2)
32154 +#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
32155 +#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
32156 +#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
32157 + * controlling whether STA is authorized to
32158 + * send and receive non-IEEE 802.1X frames
32160 +#define WLAN_STA_SHORT_PREAMBLE BIT(7)
32161 +#define WLAN_STA_WME BIT(9)
32162 +#define WLAN_STA_XR BIT(26)
32163 +#define WLAN_STA_WDS BIT(27)
32167 + struct list_head list;
32168 + struct sta_info *hnext; /* next entry in hash table list */
32169 + atomic_t users; /* number of users (do not remove if > 0) */
32171 + u8 addr[ETH_ALEN];
32172 + u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
32173 + u32 flags; /* WLAN_STA_ */
32175 + struct sk_buff_head ps_tx_buf; /* buffer of TX frames for station in
32176 + * power saving state */
32177 + int pspoll; /* whether STA has send a PS Poll frame */
32178 + struct sk_buff_head tx_filtered; /* buffer of TX frames that were
32179 + * already given to low-level driver,
32180 + * but were filtered */
32181 + int clear_dst_mask;
32183 + unsigned long rx_packets, tx_packets; /* number of RX/TX MSDUs */
32184 + unsigned long rx_bytes, tx_bytes;
32185 + unsigned long tx_retry_failed, tx_retry_count;
32186 + unsigned long tx_filtered_count;
32188 + unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
32190 + unsigned long last_rx;
32191 + u32 supp_rates; /* bitmap of supported rates in local->curr_rates */
32192 + int txrate; /* index in local->curr_rates */
32193 + int last_txrate; /* last rate used to send a frame to this STA */
32194 + int last_nonerp_idx;
32196 + struct net_device *dev; /* which net device is this station associated
32199 + struct ieee80211_key *key;
32201 + u32 tx_num_consecutive_failures;
32202 + u32 tx_num_mpdu_ok;
32203 + u32 tx_num_mpdu_fail;
32205 + void *rate_ctrl_priv;
32207 + /* last received seq/frag number from this STA (per RX queue) */
32208 + u16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
32209 + unsigned long num_duplicates; /* number of duplicate frames received
32210 + * from this STA */
32211 + unsigned long tx_fragments; /* number of transmitted MPDUs */
32212 + unsigned long rx_fragments; /* number of received MPDUs */
32213 + unsigned long rx_dropped; /* number of dropped MPDUs from this STA */
32215 + int last_rssi; /* RSSI of last received frame from this STA */
32216 + int last_ack_rssi[3]; /* RSSI of last received ACKs from this STA */
32217 + unsigned long last_ack;
32219 + int channel_use_raw;
32224 + int key_idx_compression; /* key table index for compression and TX
32225 + * filtering; used only if sta->key is not
32228 + int proc_entry_added:1;
32229 + int assoc_ap:1; /* whether this is an AP that we are associated with
32232 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
32234 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
32236 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
32237 + unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
32238 + unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
32239 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
32245 +/* Maximum number of concurrently registered stations */
32246 +#define MAX_STA_COUNT 2007
32248 +/* Maximum number of AIDs to use for STAs; must be 2007 or lower
32249 + * (IEEE 802.11 beacon format limitation) */
32250 +#define MAX_AID_TABLE_SIZE 2007
32252 +#define STA_HASH_SIZE 256
32253 +#define STA_HASH(sta) (sta[5])
32256 +/* Maximum number of frames to buffer per power saving station */
32257 +#define STA_MAX_TX_BUFFER 128
32259 +/* Buffered frame expiry time */
32260 +#define STA_TX_BUFFER_EXPIRE (10 * HZ)
32262 +/* How often station data is cleaned up (e.g., expiration of buffered frames)
32264 +#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
32266 +struct ieee80211_local;
32268 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
32269 +int sta_info_min_txrate_get(struct ieee80211_local *local);
32270 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta);
32271 +struct sta_info * sta_info_add(struct ieee80211_local *local,
32272 + struct net_device *dev, u8 *addr);
32273 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
32275 +void sta_info_init(struct ieee80211_local *local);
32276 +void sta_info_start(struct ieee80211_local *local);
32277 +void sta_info_stop(struct ieee80211_local *local);
32278 +void sta_info_remove_aid_ptr(struct sta_info *sta);
32279 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev);
32281 +#endif /* STA_INFO_H */
32282 diff -Nur linux-2.6.16/net/d80211/tkip.c linux-2.6.16-bcm43xx/net/d80211/tkip.c
32283 --- linux-2.6.16/net/d80211/tkip.c 1970-01-01 01:00:00.000000000 +0100
32284 +++ linux-2.6.16-bcm43xx/net/d80211/tkip.c 2006-03-28 22:16:14.000000000 +0200
32287 + * Copyright 2002-2004, Instant802 Networks, Inc.
32288 + * Copyright 2005, Devicescape Software, Inc.
32290 + * This program is free software; you can redistribute it and/or modify
32291 + * it under the terms of the GNU General Public License version 2 as
32292 + * published by the Free Software Foundation.
32295 +#ifdef CONFIG_TKIP_DEBUG
32296 +#include <linux/config.h>
32297 +#include <linux/version.h>
32298 +#include <linux/module.h>
32299 +#include <linux/kernel.h>
32300 +#include <linux/skbuff.h>
32301 +#endif /* CONFIG_TKIP_DEBUG */
32303 +#include <linux/types.h>
32304 +#include <linux/netdevice.h>
32306 +#include <net/d80211.h>
32307 +#include "ieee80211_key.h"
32308 +#ifdef CONFIG_TKIP_DEBUG
32309 +#include "ieee80211_i.h"
32310 +#endif /* CONFIG_TKIP_DEBUG */
32313 +/* Dummy prototypes for structures used in wep.h, but not really needed for
32315 +struct ieee80211_local;
32320 +/* TKIP key mixing functions */
32323 +#define PHASE1_LOOP_COUNT 8
32326 +/* 2-byte by 2-byte subset of the full AES S-box table; second part of this
32327 + * table is identical to first part but byte-swapped */
32328 +static const u16 tkip_sbox[256] =
32330 + 0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
32331 + 0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
32332 + 0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
32333 + 0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
32334 + 0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
32335 + 0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
32336 + 0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
32337 + 0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
32338 + 0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
32339 + 0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
32340 + 0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
32341 + 0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
32342 + 0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
32343 + 0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
32344 + 0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
32345 + 0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
32346 + 0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
32347 + 0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
32348 + 0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
32349 + 0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
32350 + 0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
32351 + 0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
32352 + 0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
32353 + 0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
32354 + 0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
32355 + 0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
32356 + 0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
32357 + 0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
32358 + 0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
32359 + 0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
32360 + 0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
32361 + 0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
32365 +static inline u16 Mk16(u8 x, u8 y)
32367 + return ((u16) x << 8) | (u16) y;
32371 +static inline u8 Hi8(u16 v)
32377 +static inline u8 Lo8(u16 v)
32383 +static inline u16 Hi16(u32 v)
32389 +static inline u16 Lo16(u32 v)
32391 + return v & 0xffff;
32395 +static inline u16 RotR1(u16 v)
32397 + return (v >> 1) | ((v & 0x0001) << 15);
32401 +static inline u16 tkip_S(u16 val)
32403 + u16 a = tkip_sbox[Hi8(val)];
32405 + return tkip_sbox[Lo8(val)] ^ Hi8(a) ^ (Lo8(a) << 8);
32410 +/* P1K := Phase1(TA, TK, TSC)
32411 + * TA = transmitter address (48 bits)
32412 + * TK = dot11DefaultKeyValue or dot11KeyMappingValue (128 bits)
32413 + * TSC = TKIP sequence counter (48 bits, only 32 msb bits used)
32416 +static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
32421 + p1k[0] = Lo16(tsc_IV32);
32422 + p1k[1] = Hi16(tsc_IV32);
32423 + p1k[2] = Mk16(ta[1], ta[0]);
32424 + p1k[3] = Mk16(ta[3], ta[2]);
32425 + p1k[4] = Mk16(ta[5], ta[4]);
32427 + for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
32429 + p1k[0] += tkip_S(p1k[4] ^ Mk16(tk[ 1 + j], tk[ 0 + j]));
32430 + p1k[1] += tkip_S(p1k[0] ^ Mk16(tk[ 5 + j], tk[ 4 + j]));
32431 + p1k[2] += tkip_S(p1k[1] ^ Mk16(tk[ 9 + j], tk[ 8 + j]));
32432 + p1k[3] += tkip_S(p1k[2] ^ Mk16(tk[13 + j], tk[12 + j]));
32433 + p1k[4] += tkip_S(p1k[3] ^ Mk16(tk[ 1 + j], tk[ 0 + j])) + i;
32438 +static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
32449 + ppk[5] = p1k[4] + tsc_IV16;
32451 + ppk[0] += tkip_S(ppk[5] ^ Mk16(tk[ 1], tk[ 0]));
32452 + ppk[1] += tkip_S(ppk[0] ^ Mk16(tk[ 3], tk[ 2]));
32453 + ppk[2] += tkip_S(ppk[1] ^ Mk16(tk[ 5], tk[ 4]));
32454 + ppk[3] += tkip_S(ppk[2] ^ Mk16(tk[ 7], tk[ 6]));
32455 + ppk[4] += tkip_S(ppk[3] ^ Mk16(tk[ 9], tk[ 8]));
32456 + ppk[5] += tkip_S(ppk[4] ^ Mk16(tk[11], tk[10]));
32457 + ppk[0] += RotR1(ppk[5] ^ Mk16(tk[13], tk[12]));
32458 + ppk[1] += RotR1(ppk[0] ^ Mk16(tk[15], tk[14]));
32459 + ppk[2] += RotR1(ppk[1]);
32460 + ppk[3] += RotR1(ppk[2]);
32461 + ppk[4] += RotR1(ppk[3]);
32462 + ppk[5] += RotR1(ppk[4]);
32464 + rc4key[0] = Hi8(tsc_IV16);
32465 + rc4key[1] = (Hi8(tsc_IV16) | 0x20) & 0x7f;
32466 + rc4key[2] = Lo8(tsc_IV16);
32467 + rc4key[3] = Lo8((ppk[5] ^ Mk16(tk[1], tk[0])) >> 1);
32469 + for (i = 0; i < 6; i++) {
32470 + rc4key[4 + 2 * i] = Lo8(ppk[i]);
32471 + rc4key[5 + 2 * i] = Hi8(ppk[i]);
32476 +/* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets
32477 + * of the IV. Returns pointer to the octet following IVs (i.e., beginning of
32478 + * the packet payload). */
32479 +u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
32480 + u8 iv0, u8 iv1, u8 iv2)
32485 + *pos++ = (key->keyidx << 6) | (1 << 5) /* Ext IV */;
32486 + *pos++ = key->u.tkip.iv32 & 0xff;
32487 + *pos++ = (key->u.tkip.iv32 >> 8) & 0xff;
32488 + *pos++ = (key->u.tkip.iv32 >> 16) & 0xff;
32489 + *pos++ = (key->u.tkip.iv32 >> 24) & 0xff;
32494 +/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the
32495 + * beginning of the buffer containing payload. This payload must include
32496 + * headroom of eight octets for IV and Ext. IV and taildroom of four octets
32497 + * for ICV. @payload_len is the length of payload (_not_ including extra
32498 + * headroom and tailroom). @ta is the transmitter addresses. */
32499 +void ieee80211_tkip_encrypt_data(struct ieee80211_key *key, u8 *pos,
32500 + size_t payload_len, u8 *ta)
32504 + /* Calculate per-packet key */
32505 + if (key->u.tkip.iv16 == 0 || !key->u.tkip.tx_initialized) {
32506 + /* IV16 wrapped around - perform TKIP phase 1 */
32507 + tkip_mixing_phase1(ta, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32508 + key->u.tkip.iv32, key->u.tkip.p1k);
32509 + key->u.tkip.tx_initialized = 1;
32512 + tkip_mixing_phase2(key->u.tkip.p1k, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32513 + key->u.tkip.iv16, rc4key);
32515 + pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]);
32516 + ieee80211_wep_encrypt_data(rc4key, 16, pos, payload_len);
32520 +/* Decrypt packet payload with TKIP using @key. @pos is a pointer to the
32521 + * beginning of the buffer containing IEEE 802.11 header payload, i.e.,
32522 + * including IV, Ext. IV, real data, Michael MIC, ICV. @payload_len is the
32523 + * length of payload, including IV, Ext. IV, MIC, ICV. */
32524 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32525 + size_t payload_len, u8 *ta, int only_iv,
32530 + u8 rc4key[16], keyid, *pos = payload;
32533 + if (payload_len < 12)
32536 + iv16 = (pos[0] << 8) | pos[2];
32538 + iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
32540 +#ifdef CONFIG_TKIP_DEBUG
32543 + printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len);
32544 + for (i = 0; i < payload_len; i++)
32545 + printk(" %02x", payload[i]);
32547 + printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n",
32550 +#endif /* CONFIG_TKIP_DEBUG */
32552 + if (!(keyid & (1 << 5)))
32553 + return TKIP_DECRYPT_NO_EXT_IV;
32555 + if ((keyid >> 6) != key->keyidx)
32556 + return TKIP_DECRYPT_INVALID_KEYIDX;
32558 + if (key->u.tkip.rx_initialized[queue] &&
32559 + (iv32 < key->u.tkip.iv32_rx[queue] ||
32560 + (iv32 == key->u.tkip.iv32_rx[queue] &&
32561 + iv16 <= key->u.tkip.iv16_rx[queue]))) {
32562 +#ifdef CONFIG_TKIP_DEBUG
32563 + printk(KERN_DEBUG "TKIP replay detected for RX frame from "
32564 + MACSTR " (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
32566 + iv32, iv16, key->u.tkip.iv32_rx[queue],
32567 + key->u.tkip.iv16_rx[queue]);
32568 +#endif /* CONFIG_TKIP_DEBUG */
32569 + return TKIP_DECRYPT_REPLAY;
32573 + res = TKIP_DECRYPT_OK;
32577 + if (!key->u.tkip.rx_initialized[queue] ||
32578 + key->u.tkip.iv32_rx[queue] != iv32) {
32579 + key->u.tkip.rx_initialized[queue] = 1;
32580 + /* IV16 wrapped around - perform TKIP phase 1 */
32581 + tkip_mixing_phase1(ta, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32582 + iv32, key->u.tkip.p1k_rx[queue]);
32583 +#ifdef CONFIG_TKIP_DEBUG
32586 + printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=" MACSTR
32587 + " TK=", MAC2STR(ta));
32588 + for (i = 0; i < 16; i++)
32590 + key->key[ALG_TKIP_TEMP_ENCR_KEY + i]);
32592 + printk(KERN_DEBUG "TKIP decrypt: P1K=");
32593 + for (i = 0; i < 5; i++)
32594 + printk("%04x ", key->u.tkip.p1k_rx[queue][i]);
32597 +#endif /* CONFIG_TKIP_DEBUG */
32600 + tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
32601 + &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32603 +#ifdef CONFIG_TKIP_DEBUG
32606 + printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key=");
32607 + for (i = 0; i < 16; i++)
32608 + printk("%02x ", rc4key[i]);
32611 +#endif /* CONFIG_TKIP_DEBUG */
32613 + res = ieee80211_wep_decrypt_data(rc4key, 16, pos, payload_len - 12);
32615 + if (res == TKIP_DECRYPT_OK) {
32616 + /* FIX: these should be updated only after Michael MIC has been
32618 + /* Record previously received IV */
32619 + key->u.tkip.iv32_rx[queue] = iv32;
32620 + key->u.tkip.iv16_rx[queue] = iv16;
32627 diff -Nur linux-2.6.16/net/d80211/tkip.h linux-2.6.16-bcm43xx/net/d80211/tkip.h
32628 --- linux-2.6.16/net/d80211/tkip.h 1970-01-01 01:00:00.000000000 +0100
32629 +++ linux-2.6.16-bcm43xx/net/d80211/tkip.h 2006-03-28 22:16:14.000000000 +0200
32632 + * Copyright 2002-2004, Instant802 Networks, Inc.
32634 + * This program is free software; you can redistribute it and/or modify
32635 + * it under the terms of the GNU General Public License version 2 as
32636 + * published by the Free Software Foundation.
32642 +#include <linux/types.h>
32643 +#include "ieee80211_key.h"
32645 +u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
32646 + u8 iv0, u8 iv1, u8 iv2);
32647 +void ieee80211_tkip_encrypt_data(struct ieee80211_key *key, u8 *pos,
32648 + size_t payload_len, u8 *ta);
32650 + TKIP_DECRYPT_OK = 0,
32651 + TKIP_DECRYPT_NO_EXT_IV = -1,
32652 + TKIP_DECRYPT_INVALID_KEYIDX = -2,
32653 + TKIP_DECRYPT_REPLAY = -3,
32655 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32656 + size_t payload_len, u8 *ta, int only_iv,
32659 +#endif /* TKIP_H */
32660 diff -Nur linux-2.6.16/net/d80211/wep.c linux-2.6.16-bcm43xx/net/d80211/wep.c
32661 --- linux-2.6.16/net/d80211/wep.c 1970-01-01 01:00:00.000000000 +0100
32662 +++ linux-2.6.16-bcm43xx/net/d80211/wep.c 2006-03-28 22:16:14.000000000 +0200
32665 + * Software WEP encryption implementation
32666 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
32667 + * Copyright 2003, Instant802 Networks, Inc.
32669 + * This program is free software; you can redistribute it and/or modify
32670 + * it under the terms of the GNU General Public License version 2 as
32671 + * published by the Free Software Foundation.
32674 +#include <linux/config.h>
32675 +#include <linux/version.h>
32676 +#include <linux/netdevice.h>
32677 +#include <linux/types.h>
32678 +#include <linux/random.h>
32679 +#include <linux/compiler.h>
32681 +#include <net/d80211.h>
32682 +#include "ieee80211_i.h"
32686 +static const __u32 crc32_table[256] = {
32687 + 0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
32688 + 0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
32689 + 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
32690 + 0x90bf1d91L, 0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL,
32691 + 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L, 0x136c9856L,
32692 + 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L,
32693 + 0xfa0f3d63L, 0x8d080df5L, 0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L,
32694 + 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
32695 + 0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L,
32696 + 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L, 0x26d930acL, 0x51de003aL,
32697 + 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L,
32698 + 0xb8bda50fL, 0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L,
32699 + 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL, 0x76dc4190L,
32700 + 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL,
32701 + 0x9fbfe4a5L, 0xe8b8d433L, 0x7807c9a2L, 0x0f00f934L, 0x9609a88eL,
32702 + 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
32703 + 0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL,
32704 + 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L, 0x65b0d9c6L, 0x12b7e950L,
32705 + 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L,
32706 + 0xfbd44c65L, 0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L,
32707 + 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL, 0x4369e96aL,
32708 + 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L,
32709 + 0xaa0a4c5fL, 0xdd0d7cc9L, 0x5005713cL, 0x270241aaL, 0xbe0b1010L,
32710 + 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
32711 + 0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L,
32712 + 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL, 0xedb88320L, 0x9abfb3b6L,
32713 + 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L,
32714 + 0x73dc1683L, 0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L,
32715 + 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L, 0xf00f9344L,
32716 + 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL,
32717 + 0x196c3671L, 0x6e6b06e7L, 0xfed41b76L, 0x89d32be0L, 0x10da7a5aL,
32718 + 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
32719 + 0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L,
32720 + 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL, 0xd80d2bdaL, 0xaf0a1b4cL,
32721 + 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL,
32722 + 0x4669be79L, 0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L,
32723 + 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL, 0xc5ba3bbeL,
32724 + 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L,
32725 + 0x2cd99e8bL, 0x5bdeae1dL, 0x9b64c2b0L, 0xec63f226L, 0x756aa39cL,
32726 + 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
32727 + 0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL,
32728 + 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L, 0x86d3d2d4L, 0xf1d4e242L,
32729 + 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L,
32730 + 0x18b74777L, 0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL,
32731 + 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L, 0xa00ae278L,
32732 + 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L,
32733 + 0x4969474dL, 0x3e6e77dbL, 0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L,
32734 + 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
32735 + 0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L,
32736 + 0xcdd70693L, 0x54de5729L, 0x23d967bfL, 0xb3667a2eL, 0xc4614ab8L,
32737 + 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL,
32742 +void ieee80211_wep_init(struct ieee80211_local *local)
32744 + /* start WEP IV from a random value */
32745 + get_random_bytes(&local->wep_iv, WEP_IV_LEN);
32749 +static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
32751 + /* Fluhrer, Mantin, and Shamir have reported weaknesses in the
32752 + * key scheduling algorithm of RC4. At least IVs (KeyByte + 3,
32753 + * 0xff, N) can be used to speedup attacks, so avoid using them. */
32754 + if ((iv & 0xff00) == 0xff00) {
32755 + u8 B = (iv >> 16) & 0xff;
32756 + if (B >= 3 && B < 3 + keylen)
32763 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
32764 + struct ieee80211_key *key, u8 *iv)
32767 + if (ieee80211_wep_weak_iv(local->wep_iv, key->keylen))
32768 + local->wep_iv += 0x0100;
32773 + *iv++ = (local->wep_iv >> 16) & 0xff;
32774 + *iv++ = (local->wep_iv >> 8) & 0xff;
32775 + *iv++ = local->wep_iv & 0xff;
32776 + *iv++ = key->keyidx << 6;
32780 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
32781 + struct sk_buff *skb,
32782 + struct ieee80211_key *key)
32784 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32789 + fc = le16_to_cpu(hdr->frame_control);
32790 + fc |= WLAN_FC_ISWEP;
32791 + hdr->frame_control = cpu_to_le16(fc);
32793 + if ((skb_headroom(skb) < WEP_IV_LEN ||
32794 + skb_tailroom(skb) < WEP_ICV_LEN)) {
32795 + I802_DEBUG_INC(local->tx_expand_skb_head);
32796 + if (unlikely(pskb_expand_head(skb, WEP_IV_LEN, WEP_ICV_LEN,
32801 + hdrlen = ieee80211_get_hdrlen(fc);
32802 + newhdr = skb_push(skb, WEP_IV_LEN);
32803 + memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen);
32804 + ieee80211_wep_get_iv(local, key, newhdr + hdrlen);
32805 + return newhdr + hdrlen;
32809 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
32810 + struct sk_buff *skb,
32811 + struct ieee80211_key *key)
32813 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32817 + fc = le16_to_cpu(hdr->frame_control);
32818 + hdrlen = ieee80211_get_hdrlen(fc);
32819 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
32820 + skb_pull(skb, WEP_IV_LEN);
32824 +/* Perform WEP encryption using given key. data buffer must have tailroom
32825 + * for 4-byte ICV. data_len must not include this ICV. Note: this function
32826 + * does _not_ add IV. data = RC4(data | CRC32(data)) */
32827 +void ieee80211_wep_encrypt_data(u8 *rc4key, size_t klen, u8 *data,
32830 + u32 i, j, k, crc;
32833 +#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
32835 + /* Setup RC4 state */
32836 + for (i = 0; i < 256; i++)
32840 + for (i = 0; i < 256; i++) {
32841 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32843 + if (kpos >= klen)
32848 + /* Compute CRC32 over unencrypted data and apply RC4 to data */
32852 + for (k = 0; k < data_len; k++) {
32853 + crc = crc32_table[(crc ^ *pos) & 0xff] ^ (crc >> 8);
32854 + i = (i + 1) & 0xff;
32855 + j = (j + S[i]) & 0xff;
32857 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32861 + /* Append little-endian CRC32 and encrypt it to produce ICV */
32863 + pos[1] = crc >> 8;
32864 + pos[2] = crc >> 16;
32865 + pos[3] = crc >> 24;
32866 + for (k = 0; k < 4; k++) {
32867 + i = (i + 1) & 0xff;
32868 + j = (j + S[i]) & 0xff;
32870 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32875 +/* Perform WEP encryption on given skb. 4 bytes of extra space (IV) in the
32876 + * beginning of the buffer 4 bytes of extra space (ICV) in the end of the
32877 + * buffer will be added. Both IV and ICV will be transmitted, so the
32878 + * payload length increases with 8 bytes.
32880 + * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
32882 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
32883 + struct ieee80211_key *key)
32889 + if (key == NULL || key->alg != ALG_WEP)
32892 + klen = 3 + key->keylen;
32893 + rc4key = kmalloc(klen, GFP_ATOMIC);
32894 + if (rc4key == NULL)
32897 + iv = ieee80211_wep_add_iv(local, skb, key);
32898 + if (iv == NULL) {
32903 + len = skb->len - (iv + WEP_IV_LEN - skb->data);
32905 + /* Prepend 24-bit IV to RC4 key */
32906 + memcpy(rc4key, iv, 3);
32908 + /* Copy rest of the WEP key (the secret part) */
32909 + memcpy(rc4key + 3, key->key, key->keylen);
32911 + /* Add room for ICV */
32912 + skb_put(skb, WEP_ICV_LEN);
32914 + ieee80211_wep_encrypt_data(rc4key, klen, iv + WEP_IV_LEN, len);
32922 +/* Perform WEP decryption using given key. data buffer includes encrypted
32923 + * payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
32924 + * Return 0 on success and -1 on ICV mismatch. */
32925 +int ieee80211_wep_decrypt_data(u8 *rc4key, size_t klen, u8 *data,
32928 + u32 i, j, k, crc;
32930 + u8 kpos, *pos, crcbuf[WEP_ICV_LEN], *cpos;
32932 + /* Setup RC4 state */
32933 + for (i = 0; i < 256; i++)
32937 + for (i = 0; i < 256; i++) {
32938 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32940 + if (kpos >= klen)
32945 + /* Apply RC4 to data and compute CRC32 over decrypted data */
32949 + for (k = 0; k < data_len; k++) {
32950 + i = (i + 1) & 0xff;
32951 + j = (j + S[i]) & 0xff;
32953 + *pos ^= S[(S[i] + S[j]) & 0xff];
32954 + crc = crc32_table[(crc ^ *pos++) & 0xff] ^ (crc >> 8);
32958 + /* Decrypt little-endian CRC32 and verify that it matches with the
32959 + * received ICV */
32962 + crcbuf[1] = crc >> 8;
32963 + crcbuf[2] = crc >> 16;
32964 + crcbuf[3] = crc >> 24;
32965 + for (k = 0; k < WEP_ICV_LEN; k++) {
32966 + i = (i + 1) & 0xff;
32967 + j = (j + S[i]) & 0xff;
32969 + if (*cpos++ != (*pos++ ^ S[(S[i] + S[j]) & 0xff])) {
32970 + /* ICV mismatch */
32979 +/* Perform WEP decryption on given skb. Buffer includes whole WEP part of
32980 + * the frame: IV (4 bytes), encrypted payload (including SNAP header),
32981 + * ICV (4 bytes). skb->len includes both IV and ICV.
32983 + * Returns 0 if frame was decrypted successfully and ICV was correct and -1 on
32984 + * failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload
32985 + * is moved to the beginning of the skb and skb length will be reduced.
32987 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
32988 + struct ieee80211_key *key)
32993 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32999 + fc = le16_to_cpu(hdr->frame_control);
33000 + if (!(fc & WLAN_FC_ISWEP))
33003 + hdrlen = ieee80211_get_hdrlen(fc);
33005 + if (skb->len < 8 + hdrlen)
33008 + len = skb->len - hdrlen - 8;
33010 + keyidx = skb->data[hdrlen + 3] >> 6;
33012 + if (key == NULL || keyidx != key->keyidx || key->alg != ALG_WEP)
33015 + klen = 3 + key->keylen;
33017 + rc4key = kmalloc(klen, GFP_ATOMIC);
33018 + if (rc4key == NULL)
33021 + /* Prepend 24-bit IV to RC4 key */
33022 + memcpy(rc4key, skb->data + hdrlen, 3);
33024 + /* Copy rest of the WEP key (the secret part) */
33025 + memcpy(rc4key + 3, key->key, key->keylen);
33027 + if (ieee80211_wep_decrypt_data(rc4key, klen,
33028 + skb->data + hdrlen + WEP_IV_LEN,
33030 + printk(KERN_DEBUG "WEP decrypt failed (ICV)\n");
33037 + skb_trim(skb, skb->len - WEP_ICV_LEN);
33040 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
33041 + skb_pull(skb, WEP_IV_LEN);
33047 +int ieee80211_wep_get_keyidx(struct sk_buff *skb)
33049 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33053 + fc = le16_to_cpu(hdr->frame_control);
33054 + if (!(fc & WLAN_FC_ISWEP))
33057 + hdrlen = ieee80211_get_hdrlen(fc);
33059 + if (skb->len < 8 + hdrlen)
33062 + return skb->data[hdrlen + 3] >> 6;
33066 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
33068 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33074 + fc = le16_to_cpu(hdr->frame_control);
33075 + if (!(fc & WLAN_FC_ISWEP))
33078 + hdrlen = ieee80211_get_hdrlen(fc);
33079 + ivpos = skb->data + hdrlen;
33080 + iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
33082 + if (ieee80211_wep_weak_iv(iv, key->keylen))
33087 diff -Nur linux-2.6.16/net/d80211/wep.h linux-2.6.16-bcm43xx/net/d80211/wep.h
33088 --- linux-2.6.16/net/d80211/wep.h 1970-01-01 01:00:00.000000000 +0100
33089 +++ linux-2.6.16-bcm43xx/net/d80211/wep.h 2006-03-28 22:16:14.000000000 +0200
33092 + * Software WEP encryption implementation
33093 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
33094 + * Copyright 2003, Instant802 Networks, Inc.
33096 + * This program is free software; you can redistribute it and/or modify
33097 + * it under the terms of the GNU General Public License version 2 as
33098 + * published by the Free Software Foundation.
33104 +#include <linux/skbuff.h>
33105 +#include <linux/types.h>
33106 +#include "ieee80211_i.h"
33107 +#include "ieee80211_key.h"
33109 +void ieee80211_wep_init(struct ieee80211_local *local);
33110 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
33111 + struct ieee80211_key *key, u8 *iv);
33112 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
33113 + struct sk_buff *skb,
33114 + struct ieee80211_key *key);
33115 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
33116 + struct sk_buff *skb,
33117 + struct ieee80211_key *key);
33118 +void ieee80211_wep_encrypt_data(u8 *rc4key, size_t klen, u8 *data,
33119 + size_t data_len);
33120 +int ieee80211_wep_decrypt_data(u8 *rc4key, size_t klen, u8 *data,
33121 + size_t data_len);
33122 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
33123 + struct ieee80211_key *key);
33124 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
33125 + struct ieee80211_key *key);
33126 +int ieee80211_wep_get_keyidx(struct sk_buff *skb);
33127 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
33129 +#endif /* WEP_H */
33130 diff -Nur linux-2.6.16/net/d80211/wme.c linux-2.6.16-bcm43xx/net/d80211/wme.c
33131 --- linux-2.6.16/net/d80211/wme.c 1970-01-01 01:00:00.000000000 +0100
33132 +++ linux-2.6.16-bcm43xx/net/d80211/wme.c 2006-03-28 22:16:14.000000000 +0200
33135 + * Copyright 2004, Instant802 Networks, Inc.
33137 + * This program is free software; you can redistribute it and/or modify
33138 + * it under the terms of the GNU General Public License version 2 as
33139 + * published by the Free Software Foundation.
33142 +#include <linux/config.h>
33143 +#include <linux/version.h>
33144 +#include <linux/netdevice.h>
33145 +#include <linux/skbuff.h>
33146 +#include <linux/module.h>
33147 +#include <linux/if_arp.h>
33148 +#include <net/ip.h>
33150 +#include <net/d80211.h>
33151 +#include "ieee80211_i.h"
33154 +#define CHILD_QDISC_OPS pfifo_qdisc_ops
33156 +static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
33158 + return (fc & 0x8C) == 0x88;
33162 +ieee80211_txrx_result
33163 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
33165 + u8 *data = rx->skb->data;
33168 + /* does the frame have a qos control field? */
33169 + if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
33170 + u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
33171 + /* frame has qos control */
33172 + tid = qc[0] & QOS_CONTROL_TID_MASK;
33174 + if (unlikely(WLAN_FC_GET_TYPE(rx->fc) == WLAN_FC_TYPE_MGMT)) {
33175 + /* Separate TID for management frames */
33176 + tid = NUM_RX_DATA_QUEUES - 1;
33178 + /* no qos control present */
33179 + tid = 0; /* 802.1d - Best Effort */
33182 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
33183 + I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
33185 + I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
33187 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
33189 + rx->u.rx.queue = tid;
33190 + /* Set skb->priority to 1d tag if highest order bit of TID is not set.
33191 + * For now, set skb->priority to 0 for other cases. */
33192 + rx->skb->priority = (tid > 7) ? 0 : tid;
33194 + return TXRX_CONTINUE;
33198 +ieee80211_txrx_result
33199 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
33202 + u8 *data = rx->skb->data;
33203 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
33205 + if (!WLAN_FC_IS_QOS_DATA(fc))
33206 + return TXRX_CONTINUE;
33208 + /* remove the qos control field, update frame type and meta-data */
33209 + memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
33210 + hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
33211 + /* change frame type to non QOS */
33212 + rx->fc = fc &= ~(WLAN_FC_STYPE_QOS_DATA << 4);
33213 + hdr->frame_control = cpu_to_le16(fc);
33215 + return TXRX_CONTINUE;
33219 +/* maximum number of hardware queues we support. */
33220 +#define TC_80211_MAX_QUEUES 8
33222 +struct ieee80211_sched_data
33224 + struct tcf_proto *filter_list;
33225 + struct Qdisc *queues[TC_80211_MAX_QUEUES];
33226 + struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
33230 +/* given a data frame determine the 802.1p/1d tag to use */
33231 +static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
33233 + struct iphdr *ip;
33237 +#ifdef CONFIG_NET_SCHED
33238 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33239 + struct tcf_result res = { -1, 0 };
33241 + /* if there is a user set filter list, call out to that */
33242 + if (q->filter_list) {
33243 + tc_classify(skb, q->filter_list, &res);
33244 + if (res.class != -1)
33245 + return res.class;
33247 +#endif /* CONFIG_NET_SCHED */
33249 + /* skb->priority values from 256->263 are magic values to
33250 + * directly indicate a specific 802.1d priority.
33251 + * This is used to allow 802.1d priority to be passed directly in
33252 + * from VLAN tags, etc. */
33253 + if (skb->priority >= 256 && skb->priority <= 263)
33254 + return skb->priority - 256;
33256 + /* check there is a valid IP header present */
33257 + offset = ieee80211_get_hdrlen_from_skb(skb) + 8 /* LLC + proto */;
33258 + if (skb->protocol != __constant_htons(ETH_P_IP) ||
33259 + skb->len < offset + sizeof(*ip))
33262 + ip = (struct iphdr *) (skb->data + offset);
33264 + dscp = ip->tos & 0xfc;
33286 +static inline int wme_downgrade_ac(struct sk_buff *skb)
33288 + switch (skb->priority) {
33291 + skb->priority = 5; /* VO -> VI */
33295 + skb->priority = 3; /* VI -> BE */
33299 + skb->priority = 2; /* BE -> BK */
33307 +/* positive return value indicates which queue to use
33308 + * negative return value indicates to drop the frame */
33309 +static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
33311 + struct ieee80211_local *local = qd->dev->priv;
33312 + struct ieee80211_tx_packet_data *pkt_data =
33313 + (struct ieee80211_tx_packet_data *) skb->cb;
33314 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33315 + unsigned short fc = le16_to_cpu(hdr->frame_control);
33317 + const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
33319 + /* see if frame is data or non data frame */
33320 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA)) {
33321 + /* management frames go on AC_VO queue, but are sent
33322 + * without QoS control fields */
33323 + return IEEE80211_TX_QUEUE_DATA0;
33326 + if (unlikely(pkt_data->sdata->type == IEEE80211_SUB_IF_TYPE_MGMT)) {
33327 + /* Data frames from hostapd (mainly, EAPOL) use AC_VO
33328 + * and they will include QoS control fields if
33329 + * the target STA is using WME. */
33330 + skb->priority = 7;
33331 + return ieee802_1d_to_ac[skb->priority];
33334 + /* is this a QoS frame? */
33335 + qos = fc & (WLAN_FC_STYPE_QOS_DATA << 4);
33338 + skb->priority = 0; /* required for correct WPA/11i MIC */
33339 + return ieee802_1d_to_ac[skb->priority];
33342 + /* use the data classifier to determine what 802.1d tag the
33343 + * data frame has */
33344 + skb->priority = classify_1d(skb, qd);
33346 + /* incase we are a client verify acm is not set for this ac */
33347 + for (; unlikely(local->wmm_acm & BIT(skb->priority)); )
33349 + if (wme_downgrade_ac(skb)) {
33350 + /* No AC with lower priority has acm=0,
33351 + * drop packet. */
33356 + /* look up which queue to use for frames with this 1d tag */
33357 + return ieee802_1d_to_ac[skb->priority];
33361 +static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
33363 + struct ieee80211_local *local = qd->dev->priv;
33364 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33365 + struct ieee80211_tx_packet_data *pkt_data =
33366 + (struct ieee80211_tx_packet_data *) skb->cb;
33367 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33368 + unsigned short fc = le16_to_cpu(hdr->frame_control);
33369 + struct Qdisc *qdisc;
33372 + if (pkt_data->requeue) {
33373 + skb_queue_tail(&q->requeued[pkt_data->queue], skb);
33377 + queue = classify80211(skb, qd);
33379 + /* now we know the 1d priority, fill in the QoS header if there is one
33381 + if (WLAN_FC_IS_QOS_DATA(fc)) {
33382 + struct qos_control *qc = (struct qos_control *)
33383 + (skb->data + ieee80211_get_hdrlen(fc) - 2);
33384 + u8 *p = (u8 *) qc;
33385 + *p++ = 0; /* do this due to gcc's lack of optimization on
33386 + * bitfield ops */
33388 + qc->tag1d = skb->priority;
33389 + if (local->wifi_wme_noack_test)
33390 + qc->ack_policy = 1;
33393 + if (unlikely(queue >= local->hw->queues)) {
33395 + if (net_ratelimit()) {
33396 + printk(KERN_DEBUG "%s - queue=%d (hw does not "
33397 + "support) -> %d\n",
33398 + __func__, queue, local->hw->queues - 1);
33401 + queue = local->hw->queues - 1;
33404 + if (unlikely(queue < 0)) {
33406 + err = NET_XMIT_DROP;
33408 + pkt_data->queue = (unsigned int) queue;
33409 + qdisc = q->queues[queue];
33410 + err = qdisc->enqueue(skb, qdisc);
33411 + if (err == NET_XMIT_SUCCESS) {
33413 + qd->bstats.bytes += skb->len;
33414 + qd->bstats.packets++;
33415 + return NET_XMIT_SUCCESS;
33418 + qd->qstats.drops++;
33423 +/* TODO: clean up the cases where master_hard_start_xmit
33424 + * returns non 0 - it shouldn't ever do that. Once done we
33425 + * can remove this function */
33426 +static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
33428 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33429 + struct ieee80211_tx_packet_data *pkt_data =
33430 + (struct ieee80211_tx_packet_data *) skb->cb;
33431 + struct Qdisc *qdisc;
33434 + /* we recorded which queue to use earlier! */
33435 + qdisc = q->queues[pkt_data->queue];
33437 + if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
33441 + qd->qstats.drops++;
33446 +static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
33448 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33449 + struct net_device *dev = qd->dev;
33450 + struct ieee80211_local *local = dev->priv;
33451 + struct ieee80211_hw *hw = local->hw;
33452 + struct ieee80211_tx_queue_stats stats;
33453 + struct sk_buff *skb;
33454 + struct Qdisc *qdisc;
33457 + /* find which hardware queues have space in them */
33458 + hw->get_tx_stats(dev, &stats);
33460 + /* check all the h/w queues in numeric/priority order */
33461 + for (queue = 0; queue < hw->queues; queue++) {
33462 + /* see if there is room in this hardware queue */
33463 + if (stats.data[queue].len >= stats.data[queue].limit)
33466 + /* there is space - try and get a frame */
33467 + skb = skb_dequeue(&q->requeued[queue]);
33471 + qdisc = q->queues[queue];
33472 + skb = qdisc->dequeue(qdisc);
33478 + /* returning a NULL here when all the h/w queues are full means we
33479 + * never need to call netif_stop_queue in the driver */
33484 +static void wme_qdiscop_reset(struct Qdisc* qd)
33486 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33487 + struct ieee80211_local *local = qd->dev->priv;
33488 + struct ieee80211_hw *hw = local->hw;
33491 + /* QUESTION: should we have some hardware flush functionality here? */
33493 + for (queue = 0; queue < hw->queues; queue++) {
33494 + skb_queue_purge(&q->requeued[queue]);
33495 + qdisc_reset(q->queues[queue]);
33501 +static void wme_qdiscop_destroy(struct Qdisc* qd)
33503 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33504 + struct ieee80211_local *local = qd->dev->priv;
33505 + struct ieee80211_hw *hw = local->hw;
33506 + struct tcf_proto *tp;
33509 + while ((tp = q->filter_list) != NULL) {
33510 + q->filter_list = tp->next;
33511 + tp->ops->destroy(tp);
33514 + for (queue=0; queue < hw->queues; queue++) {
33515 + skb_queue_purge(&q->requeued[queue]);
33516 + qdisc_destroy(q->queues[queue]);
33517 + q->queues[queue] = &noop_qdisc;
33522 +/* called whenever parameters are updated on existing qdisc */
33523 +static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
33525 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33527 + /* check our options block is the right size */
33528 + /* copy any options to our local structure */
33529 +/* Ignore options block for now - always use static mapping
33530 + struct tc_ieee80211_qopt *qopt = RTA_DATA(opt);
33532 + if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
33534 + memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
33540 +/* called during initial creation of qdisc on device */
33541 +static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
33543 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33544 + struct net_device *dev = qd->dev;
33545 + struct ieee80211_local *local = dev->priv;
33546 + int queues = local->hw->queues;
33549 + /* check this device is an ieee80211 master type device */
33550 + if (dev->type != ARPHRD_IEEE80211)
33553 + /* check that there is no qdisc currently attached to device
33554 + * this ensures that we will be the root qdisc. (I can't find a better
33555 + * way to test this explicitly) */
33556 + if (dev->qdisc_sleeping != &noop_qdisc)
33559 + if (qd->flags & TCQ_F_INGRESS)
33562 + /* if options were passed in, set them */
33564 + err = wme_qdiscop_tune(qd, opt);
33567 + /* create child queues */
33568 + for (i = 0; i < queues; i++) {
33569 + skb_queue_head_init(&q->requeued[i]);
33570 + q->queues[i] = qdisc_create_dflt(qd->dev, &CHILD_QDISC_OPS);
33571 + if (q->queues[i] == 0) {
33572 + q->queues[i] = &noop_qdisc;
33573 + printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
33580 +static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
33582 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33583 + unsigned char *p = skb->tail;
33584 + struct tc_ieee80211_qopt opt;
33586 + memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
33587 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
33588 +*/ return skb->len;
33591 + skb_trim(skb, p - skb->data);*/
33596 +static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
33597 + struct Qdisc *new, struct Qdisc **old)
33599 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33600 + struct ieee80211_local *local = qd->dev->priv;
33601 + struct ieee80211_hw *hw = local->hw;
33602 + unsigned long queue = arg - 1;
33604 + if (queue >= hw->queues)
33608 + new = &noop_qdisc;
33610 + sch_tree_lock(qd);
33611 + *old = q->queues[queue];
33612 + q->queues[queue] = new;
33613 + qdisc_reset(*old);
33614 + sch_tree_unlock(qd);
33620 +static struct Qdisc *
33621 +wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
33623 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33624 + struct ieee80211_local *local = qd->dev->priv;
33625 + struct ieee80211_hw *hw = local->hw;
33626 + unsigned long queue = arg - 1;
33628 + if (queue >= hw->queues)
33631 + return q->queues[queue];
33635 +static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
33637 + struct ieee80211_local *local = qd->dev->priv;
33638 + struct ieee80211_hw *hw = local->hw;
33639 + unsigned long queue = TC_H_MIN(classid);
33641 + if (queue - 1 >= hw->queues)
33648 +static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
33651 + return wme_classop_get(qd, classid);
33655 +static void wme_classop_put(struct Qdisc *q, unsigned long cl)
33657 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33661 +static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
33662 + struct rtattr **tca, unsigned long *arg)
33664 + unsigned long cl = *arg;
33665 + struct ieee80211_local *local = qd->dev->priv;
33666 + struct ieee80211_hw *hw = local->hw;
33667 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33669 + if (cl - 1 > hw->queues)
33672 + /* TODO: put code to program hardware queue parameters here,
33673 + * to allow programming from tc command line */
33679 +/* we don't support deleting hardware queues
33680 + * when we add WMM-SA support - TSPECs may be deleted here */
33681 +static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
33683 + struct ieee80211_local *local = qd->dev->priv;
33684 + struct ieee80211_hw *hw = local->hw;
33685 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33687 + if (cl - 1 > hw->queues)
33693 +static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
33694 + struct sk_buff *skb, struct tcmsg *tcm)
33696 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33697 + struct ieee80211_local *local = qd->dev->priv;
33698 + struct ieee80211_hw *hw = local->hw;
33699 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33701 + if (cl - 1 > hw->queues)
33703 + tcm->tcm_handle = TC_H_MIN(cl);
33704 + tcm->tcm_parent = qd->handle;
33705 + tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
33710 +static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
33712 + struct ieee80211_local *local = qd->dev->priv;
33713 + struct ieee80211_hw *hw = local->hw;
33715 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33720 + for (queue = 0; queue < hw->queues; queue++) {
33721 + if (arg->count < arg->skip) {
33725 + /* we should return classids for our internal queues here
33726 + * as well as the external ones */
33727 + if (arg->fn(qd, queue+1, arg) < 0) {
33736 +static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
33737 + unsigned long cl)
33739 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33740 + /* printk("entering %s\n", __func__); */
33745 + return &q->filter_list;
33749 +/* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
33750 + * - these are the operations on the classes */
33751 +static struct Qdisc_class_ops class_ops =
33753 + .graft = wme_classop_graft,
33754 + .leaf = wme_classop_leaf,
33756 + .get = wme_classop_get,
33757 + .put = wme_classop_put,
33758 + .change = wme_classop_change,
33759 + .delete = wme_classop_delete,
33760 + .walk = wme_classop_walk,
33762 + .tcf_chain = wme_classop_find_tcf,
33763 + .bind_tcf = wme_classop_bind,
33764 + .unbind_tcf = wme_classop_put,
33766 + .dump = wme_classop_dump_class,
33770 +/* queueing discipline operations */
33771 +static struct Qdisc_ops wme_qdisc_ops =
33774 + .cl_ops = &class_ops,
33775 + .id = "ieee80211",
33776 + .priv_size = sizeof(struct ieee80211_sched_data),
33778 + .enqueue = wme_qdiscop_enqueue,
33779 + .dequeue = wme_qdiscop_dequeue,
33780 + .requeue = wme_qdiscop_requeue,
33781 + .drop = NULL, /* drop not needed since we are always the root qdisc */
33783 + .init = wme_qdiscop_init,
33784 + .reset = wme_qdiscop_reset,
33785 + .destroy = wme_qdiscop_destroy,
33786 + .change = wme_qdiscop_tune,
33788 + .dump = wme_qdiscop_dump,
33792 +void ieee80211_install_qdisc(struct net_device *dev)
33794 + struct Qdisc *qdisc;
33796 + qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops);
33797 + if (qdisc == NULL) {
33798 + printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
33802 + /* same handle as would be allocated by qdisc_alloc_handle() */
33803 + qdisc->handle = 0x80010000;
33805 + qdisc_lock_tree(dev);
33806 + list_add_tail(&qdisc->list, &dev->qdisc_list);
33807 + dev->qdisc_sleeping = qdisc;
33808 + qdisc_unlock_tree(dev);
33812 +int ieee80211_wme_register(void)
33816 +#ifdef CONFIG_NET_SCHED
33817 + err = register_qdisc(&wme_qdisc_ops);
33823 +void ieee80211_wme_unregister(void)
33825 +#ifdef CONFIG_NET_SCHED
33826 + unregister_qdisc(&wme_qdisc_ops);
33829 diff -Nur linux-2.6.16/net/d80211/wme.h linux-2.6.16-bcm43xx/net/d80211/wme.h
33830 --- linux-2.6.16/net/d80211/wme.h 1970-01-01 01:00:00.000000000 +0100
33831 +++ linux-2.6.16-bcm43xx/net/d80211/wme.h 2006-03-28 22:16:14.000000000 +0200
33834 + * IEEE 802.11 driver (80211.o) - QoS datatypes
33835 + * Copyright 2004, Instant802 Networks, Inc.
33836 + * Copyright 2005, Devicescape Software, Inc.
33838 + * This program is free software; you can redistribute it and/or modify
33839 + * it under the terms of the GNU General Public License version 2 as
33840 + * published by the Free Software Foundation.
33846 +#include <asm/byteorder.h>
33847 +#include <linux/netdevice.h>
33848 +#include <linux/types.h>
33849 +#include <net/pkt_sched.h>
33851 +#define QOS_CONTROL_LEN 2
33853 +#define QOS_CONTROL_ACK_POLICY_NORMAL 0
33854 +#define QOS_CONTROL_ACK_POLICY_NOACK 1
33856 +#define QOS_CONTROL_TID_MASK 0x0f
33857 +#define QOS_CONTROL_ACK_POLICY_SHIFT 5
33859 +/* This bit field structure should not be used; it can cause compiler to
33860 + * generate unaligned accesses and inefficient code. */
33861 +struct qos_control {
33862 +#if defined(__LITTLE_ENDIAN_BITFIELD)
33863 + u8 tag1d:3, /* bits 0-2 */
33868 +#elif defined (__BIG_ENDIAN_BITFIELD)
33873 + tag1d:3; /* bits 0-2 */
33875 +#error "Please fix <asm/byteorder.h>"
33878 +} __attribute__ ((packed));
33880 +ieee80211_txrx_result
33881 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx);
33883 +ieee80211_txrx_result
33884 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx);
33886 +void ieee80211_install_qdisc(struct net_device *dev);
33888 +int ieee80211_wme_register(void);
33889 +void ieee80211_wme_unregister(void);
33892 diff -Nur linux-2.6.16/net/d80211/wpa.c linux-2.6.16-bcm43xx/net/d80211/wpa.c
33893 --- linux-2.6.16/net/d80211/wpa.c 1970-01-01 01:00:00.000000000 +0100
33894 +++ linux-2.6.16-bcm43xx/net/d80211/wpa.c 2006-03-28 22:16:14.000000000 +0200
33897 + * Copyright 2002-2004, Instant802 Networks, Inc.
33899 + * This program is free software; you can redistribute it and/or modify
33900 + * it under the terms of the GNU General Public License version 2 as
33901 + * published by the Free Software Foundation.
33904 +#include <linux/config.h>
33905 +#include <linux/version.h>
33906 +#include <linux/module.h>
33907 +#include <linux/netdevice.h>
33908 +#include <linux/types.h>
33909 +#include <linux/slab.h>
33910 +#include <linux/skbuff.h>
33911 +#include <linux/compiler.h>
33912 +#include <linux/wireless.h>
33913 +#include <net/iw_handler.h>
33915 +#include <net/d80211.h>
33916 +#include <net/d80211_common.h>
33917 +#include "ieee80211_i.h"
33918 +#include "michael.h"
33920 +#include "aes_ccm.h"
33922 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33923 +#include "hostapd_ioctl.h"
33924 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33927 +#define MICHAEL_MIC_HWACCEL
33930 +int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
33931 + u8 *qos_tid, u8 **data, size_t *data_len)
33933 + struct ieee80211_hdr *hdr;
33939 + hdr = (struct ieee80211_hdr *) skb->data;
33940 + fc = le16_to_cpu(hdr->frame_control);
33943 + if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) ==
33944 + (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
33945 + hdrlen += ETH_ALEN;
33946 + *sa = hdr->addr4;
33947 + *da = hdr->addr3;
33948 + } else if (fc & WLAN_FC_FROMDS) {
33949 + *sa = hdr->addr3;
33950 + *da = hdr->addr1;
33951 + } else if (fc & WLAN_FC_TODS) {
33952 + *sa = hdr->addr2;
33953 + *da = hdr->addr3;
33955 + *sa = hdr->addr2;
33956 + *da = hdr->addr1;
33962 + *data = skb->data + hdrlen;
33963 + *data_len = skb->len - hdrlen;
33965 + a4_included = (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
33966 + (WLAN_FC_TODS | WLAN_FC_FROMDS);
33967 + if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
33968 + WLAN_FC_GET_STYPE(fc) & 0x08) {
33969 + pos = (u8 *) &hdr->addr4;
33972 + *qos_tid = pos[0] & 0x0f;
33973 + *qos_tid |= 0x80; /* qos_included flag */
33977 + return skb->len < hdrlen ? -1 : 0;
33981 +ieee80211_txrx_result
33982 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
33984 + u8 *data, *sa, *da, *key, *mic, qos_tid;
33987 + struct sk_buff *skb = tx->skb;
33988 + int authenticator;
33989 +#if defined(CONFIG_HOSTAPD_WPA_TESTING) || defined(MICHAEL_MIC_HWACCEL)
33990 + int wpa_test = 0;
33995 + if (!tx->key || tx->key->alg != ALG_TKIP || skb->len < 24 ||
33996 + !WLAN_FC_DATA_PRESENT(fc))
33997 + return TXRX_CONTINUE;
33999 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
34000 + return TXRX_DROP;
34002 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34003 + if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) ||
34004 + (!tx->u.tx.unicast &&
34005 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC)) {
34008 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34010 +#ifdef MICHAEL_MIC_HWACCEL
34011 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
34012 + !tx->fragmented && !wpa_test) {
34013 + /* hwaccel - with no need for preallocated room for Michael MIC
34015 + return TXRX_CONTINUE;
34017 +#endif /* MICHAEL_MIC_HWACCEL */
34019 + if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
34020 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
34021 + if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN,
34022 + MICHAEL_MIC_LEN + TKIP_ICV_LEN,
34024 + printk(KERN_DEBUG "%s: failed to allocate more memory "
34025 + "for Michael MIC\n", tx->dev->name);
34026 + return TXRX_DROP;
34031 + authenticator = fc & WLAN_FC_FROMDS; /* FIX */
34033 + authenticator = 1;
34035 + key = &tx->key->key[authenticator ? ALG_TKIP_TEMP_AUTH_TX_MIC_KEY :
34036 + ALG_TKIP_TEMP_AUTH_RX_MIC_KEY];
34037 + mic = skb_put(skb, MICHAEL_MIC_LEN);
34038 + michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
34040 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34041 + if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
34042 + printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
34043 + "for STA " MACSTR "\n",
34044 + tx->dev->name, MAC2STR(tx->sta->addr));
34045 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34046 + tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
34047 + tx->wpa_test = 1;
34049 + } else if (!tx->u.tx.unicast &&
34050 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
34051 + printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
34052 + "for Group Key\n", tx->dev->name);
34053 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34054 + tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
34055 + tx->wpa_test = 1;
34058 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34060 + return TXRX_CONTINUE;
34064 +ieee80211_txrx_result
34065 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
34067 + u8 *data, *sa, *da, *key = NULL, qos_tid;
34070 + u8 mic[MICHAEL_MIC_LEN];
34071 + struct sk_buff *skb = rx->skb;
34072 + int authenticator = 1, wpa_test = 0;
34076 + /* If device handles decryption totally, skip this check */
34077 + if (rx->local->hw->device_hides_wep ||
34078 + rx->local->hw->device_strips_mic)
34079 + return TXRX_CONTINUE;
34081 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34082 + !(rx->fc & WLAN_FC_ISWEP) || !WLAN_FC_DATA_PRESENT(fc))
34083 + return TXRX_CONTINUE;
34085 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34086 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34089 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34091 +#ifdef MICHAEL_MIC_HWACCEL
34092 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34093 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34094 + if (rx->local->hw->wep_include_iv) {
34095 + if (skb->len < MICHAEL_MIC_LEN)
34096 + return TXRX_DROP;
34098 + /* Need to verify Michael MIC sometimes in software even when
34099 + * hwaccel is used. Atheros ar5212: fragmented frames and QoS
34101 + if (!rx->fragmented && !wpa_test)
34104 +#endif /* MICHAEL_MIC_HWACCEL */
34106 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
34107 + || data_len < MICHAEL_MIC_LEN)
34108 + return TXRX_DROP;
34110 + data_len -= MICHAEL_MIC_LEN;
34113 + authenticator = fc & WLAN_FC_TODS; /* FIX */
34115 + authenticator = 1;
34117 + key = &rx->key->key[authenticator ? ALG_TKIP_TEMP_AUTH_RX_MIC_KEY :
34118 + ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
34119 + michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
34120 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34121 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34122 + printk(KERN_INFO "%s: WPA testing - corrupting RX Michael MIC "
34123 + "for STA " MACSTR "\n",
34124 + rx->dev->name, MAC2STR(rx->sta->addr));
34125 + rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_MIC;
34128 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34129 + if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
34130 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34132 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34133 + printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
34134 + MACSTR "\n", rx->dev->name, MAC2STR(sa));
34135 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34136 + printk(KERN_DEBUG " received");
34137 + for (i = 0; i < MICHAEL_MIC_LEN; i++)
34138 + printk(" %02x", data[data_len + i]);
34139 + printk(" expected");
34140 + for (i = 0; i < MICHAEL_MIC_LEN; i++)
34141 + printk(" %02x", mic[i]);
34143 + printk(KERN_DEBUG " SA=" MACSTR " DA=" MACSTR " key",
34144 + MAC2STR(sa), MAC2STR(da));
34145 + for (i = 0; i < 8; i++)
34146 + printk(" %02x", key[i]);
34147 + printk(" (%d)\n", authenticator);
34148 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34151 + struct ieee80211_hdr *hdr;
34152 + union iwreq_data wrqu;
34153 + char *buf = kmalloc(128, GFP_ATOMIC);
34157 + /* TODO: needed parameters: count, key type, TSC */
34158 + hdr = (struct ieee80211_hdr *) skb->data;
34159 + sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
34160 + "keyid=%d %scast addr=" MACSTR ")",
34162 + hdr->addr1[0] & 0x01 ? "broad" : "uni",
34163 + MAC2STR(hdr->addr2));
34164 + memset(&wrqu, 0, sizeof(wrqu));
34165 + wrqu.data.length = strlen(buf);
34166 + wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
34170 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
34171 + ieee80211_msg_michael_mic_failure);
34173 + return TXRX_QUEUED;
34176 +#ifdef MICHAEL_MIC_HWACCEL
34178 +#endif /* MICHAEL_MIC_HWACCEL */
34179 + /* remove Michael MIC from payload */
34180 + skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
34182 + return TXRX_CONTINUE;
34186 +static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
34187 + struct sk_buff *skb, int test)
34189 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34190 + struct ieee80211_key *key = tx->key;
34191 + int hdrlen, len, tailneed;
34195 + fc = le16_to_cpu(hdr->frame_control);
34196 + hdrlen = ieee80211_get_hdrlen(fc);
34197 + len = skb->len - hdrlen;
34199 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34200 + ? 0 : TKIP_ICV_LEN;
34201 + if ((skb_headroom(skb) < TKIP_IV_LEN ||
34202 + skb_tailroom(skb) < tailneed)) {
34203 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
34204 + if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN, tailneed,
34209 + pos = skb_push(skb, TKIP_IV_LEN);
34210 + memmove(pos, pos + TKIP_IV_LEN, hdrlen);
34213 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34214 + if (test & WPA_TRIGGER_TX_REPLAY)
34215 + goto skip_iv_inc;
34217 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34219 + /* Increase IV for the frame */
34220 + key->u.tkip.iv16++;
34221 + if (key->u.tkip.iv16 == 0)
34222 + key->u.tkip.iv32++;
34224 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34225 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34230 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34232 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt
34233 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34235 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34237 + /* hwaccel - with preallocated room for IV */
34239 + ieee80211_tkip_add_iv(pos, key,
34240 + (u8) (key->u.tkip.iv16 >> 8),
34241 + (u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
34243 + (u8) key->u.tkip.iv16);
34245 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34249 + /* Add room for ICV */
34250 + skb_put(skb, TKIP_ICV_LEN);
34252 + hdr = (struct ieee80211_hdr *) skb->data;
34253 + ieee80211_tkip_encrypt_data(key, pos, len, hdr->addr2);
34258 +ieee80211_txrx_result
34259 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx)
34261 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34263 + struct ieee80211_key *key = tx->key;
34264 + struct sk_buff *skb = tx->skb;
34265 + int wpa_test = 0, test = 0;
34267 + fc = le16_to_cpu(hdr->frame_control);
34269 + if (!key || key->alg != ALG_TKIP || !WLAN_FC_DATA_PRESENT(fc))
34270 + return TXRX_CONTINUE;
34272 + tx->u.tx.control->icv_len = TKIP_ICV_LEN;
34273 + tx->u.tx.control->iv_len = TKIP_IV_LEN;
34274 + ieee80211_tx_set_iswep(tx);
34276 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34277 + if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) ||
34278 + (!tx->u.tx.unicast &&
34279 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV)) {
34284 + test = tx->sta->wpa_trigger;
34285 + tx->sta->wpa_trigger &=
34286 + ~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34287 + WPA_TRIGGER_TX_SKIP_SEQ);
34289 + test = tx->local->wpa_trigger;
34290 + tx->local->wpa_trigger &=
34291 + ~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34292 + WPA_TRIGGER_TX_SKIP_SEQ);
34295 + (WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34296 + WPA_TRIGGER_TX_SKIP_SEQ)) {
34297 + printk(KERN_INFO "%s: WPA testing - TKIP TX packet number "
34298 + "%s%s%s%s\n", tx->dev->name,
34299 + tx->sta ? "[UNICAST]" : "[MULTICAST]",
34300 + test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
34301 + test & WPA_TRIGGER_TX_REPLAY_FRAG ?
34302 + "[REPLAY FRAG]" : "",
34303 + test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
34305 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34307 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
34308 + !tx->local->hw->wep_include_iv && !wpa_test) {
34309 + /* hwaccel - with no need for preallocated room for IV/ICV */
34310 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34311 + return TXRX_CONTINUE;
34314 + if (tkip_encrypt_skb(tx, skb, test) < 0)
34315 + return TXRX_DROP;
34317 + if (tx->u.tx.extra_frag) {
34319 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34320 + if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
34321 + test |= WPA_TRIGGER_TX_REPLAY;
34322 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34323 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
34324 + if (tkip_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
34326 + return TXRX_DROP;
34330 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34331 + if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
34332 + printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
34333 + "for STA " MACSTR "\n",
34334 + tx->dev->name, MAC2STR(tx->sta->addr));
34335 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34336 + tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
34337 + skb->data[skb->len - 1]++;
34338 + } else if (!tx->u.tx.unicast &&
34339 + tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
34340 + printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
34341 + "for Group Key\n",
34343 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
34344 + tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
34345 + skb->data[skb->len - 1]++;
34347 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34349 + return TXRX_CONTINUE;
34353 +ieee80211_txrx_result
34354 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx)
34356 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34358 + int hdrlen, res, hwaccel = 0, wpa_test = 0;
34359 + struct ieee80211_key *key = rx->key;
34360 + struct sk_buff *skb = rx->skb;
34362 + fc = le16_to_cpu(hdr->frame_control);
34363 + hdrlen = ieee80211_get_hdrlen(fc);
34365 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34366 + !(rx->fc & WLAN_FC_ISWEP) ||
34367 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA)
34368 + return TXRX_CONTINUE;
34370 + if (!rx->sta || skb->len - hdrlen < 12)
34371 + return TXRX_DROP;
34373 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34374 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_ICV) {
34375 + printk(KERN_INFO "%s: WPA testing - corrupting RX TKIP ICV "
34376 + "for STA " MACSTR "\n",
34377 + rx->dev->name, MAC2STR(rx->sta->addr));
34378 + rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_ICV;
34379 + skb->data[skb->len - 1]++;
34382 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34384 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34385 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34386 + if (!rx->local->hw->wep_include_iv) {
34387 + /* Hardware takes care of all processing, including
34388 + * replay protection, so no need to continue here. */
34389 + return TXRX_CONTINUE;
34392 + /* let TKIP code verify IV, but skip decryption */
34396 + res = ieee80211_tkip_decrypt_data(key, skb->data + hdrlen,
34397 + skb->len - hdrlen, rx->sta->addr,
34398 + hwaccel, rx->u.rx.queue);
34399 + if (res != TKIP_DECRYPT_OK || wpa_test) {
34400 + printk(KERN_DEBUG "%s: TKIP decrypt failed for RX frame from "
34401 + MACSTR " (res=%d)\n",
34402 + rx->dev->name, MAC2STR(rx->sta->addr), res);
34403 + return TXRX_DROP;
34407 + skb_trim(skb, skb->len - TKIP_ICV_LEN);
34410 + memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
34411 + skb_pull(skb, TKIP_IV_LEN);
34413 + return TXRX_CONTINUE;
34417 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
34421 + int a4_included, qos_included;
34422 + u8 qos_tid, *fc_pos, *data, *sa, *da;
34425 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34427 + fc_pos = (u8 *) &hdr->frame_control;
34428 + fc = fc_pos[0] ^ (fc_pos[1] << 8);
34429 + a4_included = (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) ==
34430 + (WLAN_FC_TODS | WLAN_FC_FROMDS);
34432 + ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len);
34433 + data_len -= CCMP_HDR_LEN + (encrypted ? CCMP_MIC_LEN : 0);
34434 + if (qos_tid & 0x80) {
34435 + qos_included = 1;
34438 + qos_included = 0;
34439 + /* First block, b_0 */
34441 + b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
34442 + /* Nonce: QoS Priority | A2 | PN */
34443 + b_0[1] = qos_tid;
34444 + memcpy(&b_0[2], hdr->addr2, 6);
34445 + memcpy(&b_0[8], pn, CCMP_PN_LEN);
34447 + b_0[14] = (data_len >> 8) & 0xff;
34448 + b_0[15] = data_len & 0xff;
34451 + /* AAD (extra authenticate-only data) / masked 802.11 header
34452 + * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
34454 + len_a = a4_included ? 28 : 22;
34455 + if (qos_included)
34458 + aad[0] = 0; /* (len_a >> 8) & 0xff; */
34459 + aad[1] = len_a & 0xff;
34460 + /* Mask FC: zero subtype b4 b5 b6 */
34461 + aad[2] = fc_pos[0] & ~(BIT(4) | BIT(5) | BIT(6));
34462 + /* Retry, PwrMgt, MoreData; set Protected */
34463 + aad[3] = (fc_pos[1] & ~(BIT(3) | BIT(4) | BIT(5))) | BIT(6);
34464 + memcpy(&aad[4], &hdr->addr1, 18);
34466 + /* Mask Seq#, leave Frag# */
34467 + aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
34469 + if (a4_included) {
34470 + memcpy(&aad[24], hdr->addr4, 6);
34474 + memset(&aad[24], 0, 8);
34475 + if (qos_included) {
34476 + u8 *dpos = &aad[a4_included ? 30 : 24];
34478 + /* Mask QoS Control field */
34479 + dpos[0] = qos_tid;
34485 +static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
34490 + hdr[3] = 0x20 | (key_id << 6);
34498 +static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
34506 + return (hdr[3] >> 6) & 0x03;
34510 +static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
34511 + struct sk_buff *skb, int test)
34513 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34514 + struct ieee80211_key *key = tx->key;
34515 + int hdrlen, len, tailneed;
34518 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34521 + fc = le16_to_cpu(hdr->frame_control);
34522 + hdrlen = ieee80211_get_hdrlen(fc);
34523 + len = skb->len - hdrlen;
34525 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34526 + ? 0 : CCMP_MIC_LEN;
34528 + if ((skb_headroom(skb) < CCMP_HDR_LEN ||
34529 + skb_tailroom(skb) < tailneed)) {
34530 + I802_DEBUG_INC(tx->local->tx_expand_skb_head);
34531 + if (unlikely(pskb_expand_head(skb, CCMP_HDR_LEN, tailneed,
34536 + pos = skb_push(skb, CCMP_HDR_LEN);
34537 + memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
34538 + hdr = (struct ieee80211_hdr *) pos;
34541 + /* PN = PN + 1 */
34542 + pn = key->u.ccmp.tx_pn;
34544 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34545 + if (test & WPA_TRIGGER_TX_REPLAY)
34546 + goto skip_pn_inc;
34548 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34550 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
34556 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34557 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34562 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34564 + ccmp_pn2hdr(pos, pn, key->keyidx);
34566 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt) {
34567 + /* hwaccel - with preallocated room for CCMP header */
34568 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34572 + pos += CCMP_HDR_LEN;
34573 + ccmp_special_blocks(skb, pn, b_0, aad, 0);
34574 + ieee80211_aes_ccm_encrypt(key->u.ccmp.aes_state, b_0, aad, pos, len,
34575 + pos, skb_put(skb, CCMP_MIC_LEN));
34581 +ieee80211_txrx_result
34582 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx)
34584 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34585 + struct ieee80211_key *key = tx->key;
34587 + struct sk_buff *skb = tx->skb;
34590 + fc = le16_to_cpu(hdr->frame_control);
34592 + if (!key || key->alg != ALG_CCMP || !WLAN_FC_DATA_PRESENT(fc))
34593 + return TXRX_CONTINUE;
34595 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34597 + test = tx->sta->wpa_trigger;
34598 + tx->sta->wpa_trigger = 0;
34600 + test = tx->local->wpa_trigger;
34601 + tx->local->wpa_trigger = 0;
34604 + (WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
34605 + WPA_TRIGGER_TX_SKIP_SEQ)) {
34606 + printk(KERN_INFO "%s: WPA testing - CCMP TX packet number "
34607 + "%s%s%s%s\n", tx->dev->name,
34608 + tx->sta ? "[UNICAST]" : "[MULTICAST]",
34609 + test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
34610 + test & WPA_TRIGGER_TX_REPLAY_FRAG ?
34611 + "[REPLAY FRAG]" : "",
34612 + test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
34614 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34616 + tx->u.tx.control->icv_len = CCMP_MIC_LEN;
34617 + tx->u.tx.control->iv_len = CCMP_HDR_LEN;
34618 + ieee80211_tx_set_iswep(tx);
34620 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt &&
34621 + !tx->local->hw->wep_include_iv) {
34622 + /* hwaccel - with no need for preallocated room for CCMP "
34623 + * header or MIC fields */
34624 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34625 + return TXRX_CONTINUE;
34628 + if (ccmp_encrypt_skb(tx, skb, test) < 0)
34629 + return TXRX_DROP;
34631 + if (tx->u.tx.extra_frag) {
34633 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34634 + if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
34635 + test |= WPA_TRIGGER_TX_REPLAY;
34636 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34637 + for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
34638 + if (ccmp_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
34640 + return TXRX_DROP;
34644 + return TXRX_CONTINUE;
34648 +ieee80211_txrx_result
34649 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx)
34651 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34654 + struct ieee80211_key *key = rx->key;
34655 + struct sk_buff *skb = rx->skb;
34656 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34657 + u8 pn[CCMP_PN_LEN];
34660 + fc = le16_to_cpu(hdr->frame_control);
34661 + hdrlen = ieee80211_get_hdrlen(fc);
34663 + if (!rx->key || rx->key->alg != ALG_CCMP ||
34664 + !(rx->fc & WLAN_FC_ISWEP) ||
34665 + WLAN_FC_GET_TYPE(rx->fc) != WLAN_FC_TYPE_DATA)
34666 + return TXRX_CONTINUE;
34668 + data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
34669 + if (!rx->sta || data_len < 0)
34670 + return TXRX_DROP;
34672 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34673 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt &&
34674 + !rx->local->hw->wep_include_iv)
34675 + return TXRX_CONTINUE;
34677 + (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
34679 + if (memcmp(pn, key->u.ccmp.rx_pn[rx->u.rx.queue], CCMP_PN_LEN) <= 0) {
34680 +#ifdef CONFIG_D80211_DEBUG
34681 + u8 *ppn = key->u.ccmp.rx_pn[rx->u.rx.queue];
34682 + printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
34683 + MACSTR " (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
34684 + "%02x%02x%02x%02x%02x%02x)\n", rx->dev->name,
34685 + MAC2STR(rx->sta->addr),
34686 + pn[0], pn[1], pn[2], pn[3], pn[4], pn[5],
34687 + ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
34688 +#endif /* CONFIG_D80211_DEBUG */
34689 + key->u.ccmp.replays++;
34690 + return TXRX_DROP;
34693 + if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
34694 + !rx->key->force_sw_encrypt && !rx->local->conf.sw_decrypt) {
34695 + /* hwaccel has already decrypted frame and verified MIC */
34697 + ccmp_special_blocks(skb, pn, b_0, aad, 1);
34699 + if (ieee80211_aes_ccm_decrypt(
34700 + key->u.ccmp.aes_state, b_0, aad,
34701 + skb->data + hdrlen + CCMP_HDR_LEN, data_len,
34702 + skb->data + skb->len - CCMP_MIC_LEN,
34703 + skb->data + hdrlen + CCMP_HDR_LEN)) {
34704 + printk(KERN_DEBUG "%s: CCMP decrypt failed for RX "
34705 + "frame from " MACSTR "\n", rx->dev->name,
34706 + MAC2STR(rx->sta->addr));
34707 + return TXRX_DROP;
34711 + memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
34713 + /* Remove CCMP header and MIC */
34714 + skb_trim(skb, skb->len - CCMP_MIC_LEN);
34715 + memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
34716 + skb_pull(skb, CCMP_HDR_LEN);
34718 + return TXRX_CONTINUE;
34721 diff -Nur linux-2.6.16/net/d80211/wpa.h linux-2.6.16-bcm43xx/net/d80211/wpa.h
34722 --- linux-2.6.16/net/d80211/wpa.h 1970-01-01 01:00:00.000000000 +0100
34723 +++ linux-2.6.16-bcm43xx/net/d80211/wpa.h 2006-03-28 22:16:14.000000000 +0200
34726 + * Copyright 2002-2004, Instant802 Networks, Inc.
34728 + * This program is free software; you can redistribute it and/or modify
34729 + * it under the terms of the GNU General Public License version 2 as
34730 + * published by the Free Software Foundation.
34736 +#include <linux/skbuff.h>
34737 +#include <linux/types.h>
34738 +#include "ieee80211_i.h"
34740 +ieee80211_txrx_result
34741 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx);
34742 +ieee80211_txrx_result
34743 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx);
34745 +ieee80211_txrx_result
34746 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx);
34747 +ieee80211_txrx_result
34748 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx);
34750 +ieee80211_txrx_result
34751 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx);
34752 +ieee80211_txrx_result
34753 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx);
34755 +int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
34756 + u8 *qos_tid, u8 **data, size_t *data_len);
34758 +#endif /* WPA_H */
34759 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt.c
34760 --- linux-2.6.16/net/ieee80211/ieee80211_crypt.c 2006-03-20 06:53:29.000000000 +0100
34761 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt.c 2006-03-28 22:16:14.000000000 +0200
34763 #include <linux/string.h>
34764 #include <net/ieee80211.h>
34767 MODULE_AUTHOR("Jouni Malinen");
34768 MODULE_DESCRIPTION("HostAP crypto");
34769 MODULE_LICENSE("GPL");
34770 @@ -33,11 +32,11 @@
34772 void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
34774 - struct ieee80211_crypt_data *entry, *next;
34775 + struct ieee80211_crypt_data *entry, *next;
34776 unsigned long flags;
34778 spin_lock_irqsave(&ieee->lock, flags);
34779 - list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
34780 + list_for_each_entry_safe(entry, next, &ieee->crypt_deinit_list, list) {
34781 if (atomic_read(&entry->refcnt) != 0 && !force)
34784 @@ -141,9 +140,9 @@
34785 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34790 printk(KERN_DEBUG "ieee80211_crypt: unregistered algorithm "
34791 - "'%s'\n", ops->name);
34792 + "'%s'\n", ops->name);
34793 list_del(&alg->list);
34794 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34796 @@ -163,7 +162,7 @@
34797 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34802 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34805 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_ccmp.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_ccmp.c
34806 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_ccmp.c 2006-03-20 06:53:29.000000000 +0100
34807 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_ccmp.c 2006-03-28 22:16:14.000000000 +0200
34808 @@ -190,7 +190,8 @@
34809 ieee80211_ccmp_aes_encrypt(tfm, b0, s0);
34812 -static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len, void *priv)
34813 +static int ieee80211_ccmp_hdr(struct sk_buff *skb, int hdr_len,
34814 + u8 *aeskey, int keylen, void *priv)
34816 struct ieee80211_ccmp_data *key = priv;
34818 @@ -199,6 +200,9 @@
34819 if (skb_headroom(skb) < CCMP_HDR_LEN || skb->len < hdr_len)
34822 + if (aeskey != NULL && keylen >= CCMP_TK_LEN)
34823 + memcpy(aeskey, key->key, CCMP_TK_LEN);
34825 pos = skb_push(skb, CCMP_HDR_LEN);
34826 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
34828 @@ -238,7 +242,7 @@
34831 data_len = skb->len - hdr_len;
34832 - len = ieee80211_ccmp_hdr(skb, hdr_len, priv);
34833 + len = ieee80211_ccmp_hdr(skb, hdr_len, NULL, 0, priv);
34837 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_tkip.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_tkip.c
34838 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_tkip.c 2006-03-20 06:53:29.000000000 +0100
34839 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_tkip.c 2006-03-28 22:16:14.000000000 +0200
34842 struct ieee80211_tkip_data *priv;
34844 - priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
34845 + priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
34848 - memset(priv, 0, sizeof(*priv));
34850 priv->key_idx = key_idx;
34852 @@ -271,34 +270,33 @@
34856 -static u8 *ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len, void *priv)
34857 +static int ieee80211_tkip_hdr(struct sk_buff *skb, int hdr_len,
34858 + u8 * rc4key, int keylen, void *priv)
34860 struct ieee80211_tkip_data *tkey = priv;
34862 - u8 *rc4key, *pos, *icv;
34864 struct ieee80211_hdr_4addr *hdr;
34867 hdr = (struct ieee80211_hdr_4addr *)skb->data;
34869 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
34873 + if (rc4key == NULL || keylen < 16)
34876 if (!tkey->tx_phase1_done) {
34877 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
34879 tkey->tx_phase1_done = 1;
34881 - rc4key = kmalloc(16, GFP_ATOMIC);
34884 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
34886 len = skb->len - hdr_len;
34887 pos = skb_push(skb, 8);
34888 memmove(pos, pos + 8, hdr_len);
34890 - icv = skb_put(skb, 4);
34893 *pos++ = *(rc4key + 1);
34894 @@ -309,28 +307,28 @@
34895 *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
34896 *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
34898 - crc = ~crc32_le(~0, pos, len);
34900 - icv[1] = crc >> 8;
34901 - icv[2] = crc >> 16;
34902 - icv[3] = crc >> 24;
34904 + if (tkey->tx_iv16 == 0) {
34905 + tkey->tx_phase1_done = 0;
34913 static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
34915 struct ieee80211_tkip_data *tkey = priv;
34917 - const u8 *rc4key;
34919 + u8 rc4key[16], *pos, *icv;
34921 struct scatterlist sg;
34923 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
34924 if (net_ratelimit()) {
34925 struct ieee80211_hdr_4addr *hdr =
34926 (struct ieee80211_hdr_4addr *)skb->data;
34927 - printk(KERN_DEBUG "TKIP countermeasures: dropped "
34928 + printk(KERN_DEBUG ": TKIP countermeasures: dropped "
34929 "TX packet to " MAC_FMT "\n",
34930 MAC_ARG(hdr->addr1));
34932 @@ -343,22 +341,23 @@
34933 len = skb->len - hdr_len;
34934 pos = skb->data + hdr_len;
34936 - rc4key = ieee80211_tkip_hdr(skb, hdr_len, priv);
34938 + if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
34941 + icv = skb_put(skb, 4);
34943 + crc = ~crc32_le(~0, pos, len);
34945 + icv[1] = crc >> 8;
34946 + icv[2] = crc >> 16;
34947 + icv[3] = crc >> 24;
34949 crypto_cipher_setkey(tkey->tfm_arc4, rc4key, 16);
34950 sg.page = virt_to_page(pos);
34951 sg.offset = offset_in_page(pos);
34952 sg.length = len + 4;
34953 crypto_cipher_encrypt(tkey->tfm_arc4, &sg, &sg, len + 4);
34956 - if (tkey->tx_iv16 == 0) {
34957 - tkey->tx_phase1_done = 0;
34964 @@ -379,7 +378,7 @@
34966 if (tkey->flags & IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) {
34967 if (net_ratelimit()) {
34968 - printk(KERN_DEBUG "TKIP countermeasures: dropped "
34969 + printk(KERN_DEBUG ": TKIP countermeasures: dropped "
34970 "received packet from " MAC_FMT "\n",
34971 MAC_ARG(hdr->addr2));
34973 @@ -695,6 +694,7 @@
34975 .init = ieee80211_tkip_init,
34976 .deinit = ieee80211_tkip_deinit,
34977 + .build_iv = ieee80211_tkip_hdr,
34978 .encrypt_mpdu = ieee80211_tkip_encrypt,
34979 .decrypt_mpdu = ieee80211_tkip_decrypt,
34980 .encrypt_msdu = ieee80211_michael_mic_add,
34981 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_crypt_wep.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_wep.c
34982 --- linux-2.6.16/net/ieee80211/ieee80211_crypt_wep.c 2006-03-20 06:53:29.000000000 +0100
34983 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_crypt_wep.c 2006-03-28 22:16:14.000000000 +0200
34987 /* Add WEP IV/key info to a frame that has at least 4 bytes of headroom */
34988 -static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len, void *priv)
34989 +static int prism2_wep_build_iv(struct sk_buff *skb, int hdr_len,
34990 + u8 *key, int keylen, void *priv)
34992 struct prism2_wep_data *wep = priv;
34994 @@ -131,7 +132,7 @@
34997 /* add the IV to the frame */
34998 - if (prism2_wep_build_iv(skb, hdr_len, priv))
34999 + if (prism2_wep_build_iv(skb, hdr_len, NULL, 0, priv))
35002 /* Copy the IV into the first 3 bytes of the key */
35003 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_geo.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_geo.c
35004 --- linux-2.6.16/net/ieee80211/ieee80211_geo.c 2006-03-20 06:53:29.000000000 +0100
35005 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_geo.c 2006-03-28 22:16:14.000000000 +0200
35008 /* Driver needs to initialize the geography map before using
35009 * these helper functions */
35010 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
35011 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
35014 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
35015 for (i = 0; i < ieee->geo.bg_channels; i++)
35016 @@ -58,13 +59,15 @@
35017 * this is a B only channel, we don't see it
35019 if ((ieee->geo.bg[i].channel == channel) &&
35020 + !(ieee->geo.bg[i].flags & IEEE80211_CH_INVALID) &&
35021 (!(ieee->mode & IEEE_G) ||
35022 !(ieee->geo.bg[i].flags & IEEE80211_CH_B_ONLY)))
35023 return IEEE80211_24GHZ_BAND;
35025 if (ieee->freq_band & IEEE80211_52GHZ_BAND)
35026 for (i = 0; i < ieee->geo.a_channels; i++)
35027 - if (ieee->geo.a[i].channel == channel)
35028 + if ((ieee->geo.a[i].channel == channel) &&
35029 + !(ieee->geo.a[i].flags & IEEE80211_CH_INVALID))
35030 return IEEE80211_52GHZ_BAND;
35035 /* Driver needs to initialize the geography map before using
35036 * these helper functions */
35037 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
35038 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
35041 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
35042 for (i = 0; i < ieee->geo.bg_channels; i++)
35045 /* Driver needs to initialize the geography map before using
35046 * these helper functions */
35047 - BUG_ON(ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0);
35048 + if (ieee->geo.bg_channels == 0 && ieee->geo.a_channels == 0)
35053 @@ -133,6 +138,41 @@
35057 +u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
35059 + int index = ieee80211_channel_to_index(ieee, channel);
35062 + return IEEE80211_CH_INVALID;
35064 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35065 + return ieee->geo.bg[index].flags;
35067 + return ieee->geo.a[index].flags;
35070 +static const struct ieee80211_channel bad_channel = {
35072 + .flags = IEEE80211_CH_INVALID,
35076 +const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
35077 + *ieee, u8 channel)
35079 + int index = ieee80211_channel_to_index(ieee, channel);
35082 + return &bad_channel;
35084 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35085 + return &ieee->geo.bg[index];
35087 + return &ieee->geo.a[index];
35090 +EXPORT_SYMBOL(ieee80211_get_channel);
35091 +EXPORT_SYMBOL(ieee80211_get_channel_flags);
35092 EXPORT_SYMBOL(ieee80211_is_valid_channel);
35093 EXPORT_SYMBOL(ieee80211_freq_to_channel);
35094 EXPORT_SYMBOL(ieee80211_channel_to_index);
35095 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_module.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_module.c
35096 --- linux-2.6.16/net/ieee80211/ieee80211_module.c 2006-03-20 06:53:29.000000000 +0100
35097 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_module.c 2006-03-28 22:16:14.000000000 +0200
35098 @@ -82,10 +82,28 @@
35102 +void ieee80211_network_reset(struct ieee80211_network *network)
35107 + if (network->ibss_dfs) {
35108 + kfree(network->ibss_dfs);
35109 + network->ibss_dfs = NULL;
35113 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
35117 if (!ieee->networks)
35120 + for (i = 0; i < MAX_NETWORK_COUNT; i++)
35121 + if (ieee->networks[i].ibss_dfs)
35122 + kfree(ieee->networks[i].ibss_dfs);
35124 kfree(ieee->networks);
35125 ieee->networks = NULL;
35127 @@ -195,7 +213,7 @@
35129 static int debug = 0;
35130 u32 ieee80211_debug_level = 0;
35131 -struct proc_dir_entry *ieee80211_proc = NULL;
35132 +static struct proc_dir_entry *ieee80211_proc = NULL;
35134 static int show_debug_level(char *page, char **start, off_t offset,
35135 int count, int *eof, void *data)
35136 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_rx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_rx.c
35137 --- linux-2.6.16/net/ieee80211/ieee80211_rx.c 2006-03-20 06:53:29.000000000 +0100
35138 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_rx.c 2006-03-28 22:16:14.000000000 +0200
35139 @@ -369,8 +369,8 @@
35141 /* Put this code here so that we avoid duplicating it in all
35142 * Rx paths. - Jean II */
35143 +#ifdef CONFIG_WIRELESS_EXT
35144 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
35145 -#ifdef CONFIG_NET_RADIO
35146 /* If spy monitoring on */
35147 if (ieee->spy_data.spy_number > 0) {
35148 struct iw_quality wstats;
35149 @@ -397,8 +397,8 @@
35150 /* Update spy records */
35151 wireless_spy_update(ieee->dev, hdr->addr2, &wstats);
35153 -#endif /* CONFIG_NET_RADIO */
35154 #endif /* IW_WIRELESS_SPY */
35155 +#endif /* CONFIG_WIRELESS_EXT */
35158 hostap_update_rx_stats(local->ap, hdr, rx_stats);
35159 @@ -574,7 +574,7 @@
35160 /* skb: hdr + (possibly fragmented) plaintext payload */
35161 // PR: FIXME: hostap has additional conditions in the "if" below:
35162 // ieee->host_decrypt && (fc & IEEE80211_FCTL_PROTECTED) &&
35163 - if ((frag != 0 || (fc & IEEE80211_FCTL_MOREFRAGS))) {
35164 + if ((frag != 0) || (fc & IEEE80211_FCTL_MOREFRAGS)) {
35166 struct sk_buff *frag_skb = ieee80211_frag_cache_get(ieee, hdr);
35167 IEEE80211_DEBUG_FRAG("Rx Fragment received (%u)\n", frag);
35168 @@ -754,7 +754,14 @@
35169 memset(skb->cb, 0, sizeof(skb->cb));
35171 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
35173 + if (netif_rx(skb) == NET_RX_DROP) {
35174 + /* netif_rx always succeeds, but it might drop
35175 + * the packet. If it drops the packet, we log that
35176 + * in our stats. */
35177 + IEEE80211_DEBUG_DROP
35178 + ("RX: netif_rx dropped the packet\n");
35179 + stats->rx_dropped++;
35184 @@ -930,6 +937,45 @@
35188 +#ifdef CONFIG_IEEE80211_DEBUG
35189 +#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
35191 +static const char *get_info_element_string(u16 id)
35194 + MFIE_STRING(SSID);
35195 + MFIE_STRING(RATES);
35196 + MFIE_STRING(FH_SET);
35197 + MFIE_STRING(DS_SET);
35198 + MFIE_STRING(CF_SET);
35199 + MFIE_STRING(TIM);
35200 + MFIE_STRING(IBSS_SET);
35201 + MFIE_STRING(COUNTRY);
35202 + MFIE_STRING(HOP_PARAMS);
35203 + MFIE_STRING(HOP_TABLE);
35204 + MFIE_STRING(REQUEST);
35205 + MFIE_STRING(CHALLENGE);
35206 + MFIE_STRING(POWER_CONSTRAINT);
35207 + MFIE_STRING(POWER_CAPABILITY);
35208 + MFIE_STRING(TPC_REQUEST);
35209 + MFIE_STRING(TPC_REPORT);
35210 + MFIE_STRING(SUPP_CHANNELS);
35211 + MFIE_STRING(CSA);
35212 + MFIE_STRING(MEASURE_REQUEST);
35213 + MFIE_STRING(MEASURE_REPORT);
35214 + MFIE_STRING(QUIET);
35215 + MFIE_STRING(IBSS_DFS);
35216 + MFIE_STRING(ERP_INFO);
35217 + MFIE_STRING(RSN);
35218 + MFIE_STRING(RATES_EX);
35219 + MFIE_STRING(GENERIC);
35220 + MFIE_STRING(QOS_PARAMETER);
35222 + return "UNKNOWN";
35227 static int ieee80211_parse_info_param(struct ieee80211_info_element
35228 *info_element, u16 length,
35229 struct ieee80211_network *network)
35230 @@ -1040,7 +1086,9 @@
35233 case MFIE_TYPE_TIM:
35234 - IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: ignored\n");
35235 + network->tim.tim_count = info_element->data[0];
35236 + network->tim.tim_period = info_element->data[1];
35237 + IEEE80211_DEBUG_MGMT("MFIE_TYPE_TIM: partially ignored\n");
35240 case MFIE_TYPE_ERP_INFO:
35241 @@ -1091,10 +1139,49 @@
35243 "QoS Error need to parse QOS_PARAMETER IE\n");
35246 + case MFIE_TYPE_POWER_CONSTRAINT:
35247 + network->power_constraint = info_element->data[0];
35248 + network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
35251 + case MFIE_TYPE_CSA:
35252 + network->power_constraint = info_element->data[0];
35253 + network->flags |= NETWORK_HAS_CSA;
35256 + case MFIE_TYPE_QUIET:
35257 + network->quiet.count = info_element->data[0];
35258 + network->quiet.period = info_element->data[1];
35259 + network->quiet.duration = info_element->data[2];
35260 + network->quiet.offset = info_element->data[3];
35261 + network->flags |= NETWORK_HAS_QUIET;
35264 + case MFIE_TYPE_IBSS_DFS:
35265 + if (network->ibss_dfs)
35267 + network->ibss_dfs =
35268 + kmalloc(info_element->len, GFP_ATOMIC);
35269 + if (!network->ibss_dfs)
35271 + memcpy(network->ibss_dfs, info_element->data,
35272 + info_element->len);
35273 + network->flags |= NETWORK_HAS_IBSS_DFS;
35276 + case MFIE_TYPE_TPC_REPORT:
35277 + network->tpc_report.transmit_power =
35278 + info_element->data[0];
35279 + network->tpc_report.link_margin = info_element->data[1];
35280 + network->flags |= NETWORK_HAS_TPC_REPORT;
35284 - IEEE80211_DEBUG_MGMT("unsupported IE %d\n",
35285 - info_element->id);
35286 + IEEE80211_DEBUG_MGMT
35287 + ("Unsupported info element: %s (%d)\n",
35288 + get_info_element_string(info_element->id),
35289 + info_element->id);
35293 @@ -1110,7 +1197,9 @@
35294 static int ieee80211_handle_assoc_resp(struct ieee80211_device *ieee, struct ieee80211_assoc_response
35295 *frame, struct ieee80211_rx_stats *stats)
35297 - struct ieee80211_network network_resp;
35298 + struct ieee80211_network network_resp = {
35299 + .ibss_dfs = NULL,
35301 struct ieee80211_network *network = &network_resp;
35302 struct net_device *dev = ieee->dev;
35304 @@ -1253,7 +1342,22 @@
35308 - memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
35309 + ieee80211_network_reset(dst);
35310 + dst->ibss_dfs = src->ibss_dfs;
35312 + /* We only update the statistics if they were created by receiving
35313 + * the network information on the actual channel the network is on.
35315 + * This keeps beacons received on neighbor channels from bringing
35316 + * down the signal level of an AP. */
35317 + if (dst->channel == src->stats.received_channel)
35318 + memcpy(&dst->stats, &src->stats,
35319 + sizeof(struct ieee80211_rx_stats));
35321 + IEEE80211_DEBUG_SCAN("Network " MAC_FMT " info received "
35322 + "off channel (%d vs. %d)\n", MAC_ARG(src->bssid),
35323 + dst->channel, src->stats.received_channel);
35325 dst->capability = src->capability;
35326 memcpy(dst->rates, src->rates, src->rates_len);
35327 dst->rates_len = src->rates_len;
35328 @@ -1269,6 +1373,7 @@
35329 dst->listen_interval = src->listen_interval;
35330 dst->atim_window = src->atim_window;
35331 dst->erp_value = src->erp_value;
35332 + dst->tim = src->tim;
35334 memcpy(dst->wpa_ie, src->wpa_ie, src->wpa_ie_len);
35335 dst->wpa_ie_len = src->wpa_ie_len;
35336 @@ -1313,7 +1418,9 @@
35339 struct net_device *dev = ieee->dev;
35340 - struct ieee80211_network network;
35341 + struct ieee80211_network network = {
35342 + .ibss_dfs = NULL,
35344 struct ieee80211_network *target;
35345 struct ieee80211_network *oldest = NULL;
35346 #ifdef CONFIG_IEEE80211_DEBUG
35347 @@ -1386,6 +1493,7 @@
35348 escape_essid(target->ssid,
35350 MAC_ARG(target->bssid));
35351 + ieee80211_network_reset(target);
35353 /* Otherwise just pull from the free list */
35354 target = list_entry(ieee->network_free_list.next,
35355 @@ -1402,6 +1510,7 @@
35356 "BEACON" : "PROBE RESPONSE");
35358 memcpy(target, &network, sizeof(*target));
35359 + network.ibss_dfs = NULL;
35360 list_add_tail(&target->list, &ieee->network_list);
35362 IEEE80211_DEBUG_SCAN("Updating '%s' (" MAC_FMT ") via %s.\n",
35363 @@ -1411,6 +1520,7 @@
35364 is_beacon(beacon->header.frame_ctl) ?
35365 "BEACON" : "PROBE RESPONSE");
35366 update_network(target, &network);
35367 + network.ibss_dfs = NULL;
35370 spin_unlock_irqrestore(&ieee->lock, flags);
35371 @@ -1495,10 +1605,43 @@
35375 + case IEEE80211_STYPE_ACTION:
35376 + IEEE80211_DEBUG_MGMT("ACTION\n");
35377 + if (ieee->handle_action)
35378 + ieee->handle_action(ieee->dev,
35379 + (struct ieee80211_action *)
35383 + case IEEE80211_STYPE_REASSOC_REQ:
35384 + IEEE80211_DEBUG_MGMT("received reassoc (%d)\n",
35385 + WLAN_FC_GET_STYPE(le16_to_cpu
35386 + (header->frame_ctl)));
35388 + IEEE80211_WARNING("%s: IEEE80211_REASSOC_REQ received\n",
35389 + ieee->dev->name);
35390 + if (ieee->handle_reassoc_request != NULL)
35391 + ieee->handle_reassoc_request(ieee->dev,
35392 + (struct ieee80211_reassoc_request *)
35396 + case IEEE80211_STYPE_ASSOC_REQ:
35397 + IEEE80211_DEBUG_MGMT("received assoc (%d)\n",
35398 + WLAN_FC_GET_STYPE(le16_to_cpu
35399 + (header->frame_ctl)));
35401 + IEEE80211_WARNING("%s: IEEE80211_ASSOC_REQ received\n",
35402 + ieee->dev->name);
35403 + if (ieee->handle_assoc_request != NULL)
35404 + ieee->handle_assoc_request(ieee->dev);
35407 case IEEE80211_STYPE_DEAUTH:
35408 - printk("DEAUTH from AP\n");
35409 + IEEE80211_DEBUG_MGMT("DEAUTH\n");
35410 if (ieee->handle_deauth != NULL)
35411 - ieee->handle_deauth(ieee->dev, (struct ieee80211_auth *)
35412 + ieee->handle_deauth(ieee->dev,
35413 + (struct ieee80211_deauth *)
35417 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_tx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_tx.c
35418 --- linux-2.6.16/net/ieee80211/ieee80211_tx.c 2006-03-20 06:53:29.000000000 +0100
35419 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_tx.c 2006-03-28 22:16:14.000000000 +0200
35421 `--------------------------------------------------| |------'
35422 Total: 28 non-data bytes `----.----'
35424 - .- 'Frame data' expands to <---------------------------'
35425 + .- 'Frame data' expands, if WEP enabled, to <----------'
35428 + ,-----------------------.
35429 +Bytes | 4 | 0-2296 | 4 |
35430 + |-----|-----------|-----|
35431 +Desc. | IV | Encrypted | ICV |
35436 + .- 'Encrypted Packet' expands to
35439 ,---------------------------------------------------.
35441 Desc. | SNAP | SNAP | Control |Eth Tunnel| Type | IP |
35442 | DSAP | SSAP | | | | Packet |
35443 | 0xAA | 0xAA |0x03 (UI)|0x00-00-F8| | |
35444 - `-----------------------------------------| |
35445 -Total: 8 non-data bytes `----.----'
35447 - .- 'IP Packet' expands, if WEP enabled, to <--'
35450 - ,-----------------------.
35451 -Bytes | 4 | 0-2296 | 4 |
35452 - |-----|-----------|-----|
35453 -Desc. | IV | Encrypted | ICV |
35454 - | | IP Packet | |
35455 - `-----------------------'
35456 + `----------------------------------------------------
35457 Total: 8 non-data bytes
35459 802.3 Ethernet Data Frame
35460 @@ -470,7 +470,9 @@
35461 atomic_inc(&crypt->refcnt);
35462 if (crypt->ops->build_iv)
35463 crypt->ops->build_iv(skb_frag, hdr_len,
35465 + ieee->sec.keys[ieee->sec.active_key],
35466 + ieee->sec.key_sizes[ieee->sec.active_key],
35468 atomic_dec(&crypt->refcnt);
35471 diff -Nur linux-2.6.16/net/ieee80211/ieee80211_wx.c linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_wx.c
35472 --- linux-2.6.16/net/ieee80211/ieee80211_wx.c 2006-03-20 06:53:29.000000000 +0100
35473 +++ linux-2.6.16-bcm43xx/net/ieee80211/ieee80211_wx.c 2006-03-28 22:16:14.000000000 +0200
35474 @@ -149,9 +149,7 @@
35475 iwe.u.qual.updated |= IW_QUAL_QUAL_INVALID |
35476 IW_QUAL_LEVEL_INVALID;
35477 iwe.u.qual.qual = 0;
35478 - iwe.u.qual.level = 0;
35480 - iwe.u.qual.level = network->stats.rssi;
35481 if (ieee->perfect_rssi == ieee->worst_rssi)
35482 iwe.u.qual.qual = 100;
35484 @@ -179,6 +177,13 @@
35485 iwe.u.qual.noise = network->stats.noise;
35488 + if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) {
35489 + iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
35490 + iwe.u.qual.level = 0;
35492 + iwe.u.qual.level = network->stats.signal;
35495 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
35497 iwe.cmd = IWEVCUSTOM;
35498 @@ -188,33 +193,21 @@
35499 if (iwe.u.data.length)
35500 start = iwe_stream_add_point(start, stop, &iwe, custom);
35502 + memset(&iwe, 0, sizeof(iwe));
35503 if (network->wpa_ie_len) {
35504 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35507 - p += sprintf(p, "wpa_ie=");
35508 - for (i = 0; i < network->wpa_ie_len; i++) {
35509 - p += sprintf(p, "%02x", network->wpa_ie[i]);
35512 - memset(&iwe, 0, sizeof(iwe));
35513 - iwe.cmd = IWEVCUSTOM;
35514 - iwe.u.data.length = strlen(buf);
35515 + char buf[MAX_WPA_IE_LEN];
35516 + memcpy(buf, network->wpa_ie, network->wpa_ie_len);
35517 + iwe.cmd = IWEVGENIE;
35518 + iwe.u.data.length = network->wpa_ie_len;
35519 start = iwe_stream_add_point(start, stop, &iwe, buf);
35522 + memset(&iwe, 0, sizeof(iwe));
35523 if (network->rsn_ie_len) {
35524 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35527 - p += sprintf(p, "rsn_ie=");
35528 - for (i = 0; i < network->rsn_ie_len; i++) {
35529 - p += sprintf(p, "%02x", network->rsn_ie[i]);
35532 - memset(&iwe, 0, sizeof(iwe));
35533 - iwe.cmd = IWEVCUSTOM;
35534 - iwe.u.data.length = strlen(buf);
35535 + char buf[MAX_WPA_IE_LEN];
35536 + memcpy(buf, network->rsn_ie, network->rsn_ie_len);
35537 + iwe.cmd = IWEVGENIE;
35538 + iwe.u.data.length = network->rsn_ie_len;
35539 start = iwe_stream_add_point(start, stop, &iwe, buf);
35542 @@ -229,6 +222,28 @@
35543 if (iwe.u.data.length)
35544 start = iwe_stream_add_point(start, stop, &iwe, custom);
35546 + /* Add spectrum management information */
35549 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Channel flags: ");
35551 + if (ieee80211_get_channel_flags(ieee, network->channel) &
35552 + IEEE80211_CH_INVALID) {
35553 + iwe.cmd = IWEVCUSTOM;
35554 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "INVALID ");
35557 + if (ieee80211_get_channel_flags(ieee, network->channel) &
35558 + IEEE80211_CH_RADAR_DETECT) {
35559 + iwe.cmd = IWEVCUSTOM;
35560 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), "DFS ");
35563 + if (iwe.cmd == IWEVCUSTOM) {
35564 + iwe.u.data.length = p - custom;
35565 + start = iwe_stream_add_point(start, stop, &iwe, custom);
35571 @@ -734,9 +749,98 @@
35575 +int ieee80211_wx_set_auth(struct net_device *dev,
35576 + struct iw_request_info *info,
35577 + union iwreq_data *wrqu,
35580 + struct ieee80211_device *ieee = netdev_priv(dev);
35581 + unsigned long flags;
35584 + spin_lock_irqsave(&ieee->lock, flags);
35586 + switch (wrqu->param.flags & IW_AUTH_INDEX) {
35587 + case IW_AUTH_WPA_VERSION:
35588 + case IW_AUTH_CIPHER_PAIRWISE:
35589 + case IW_AUTH_CIPHER_GROUP:
35590 + case IW_AUTH_KEY_MGMT:
35592 + * Host AP driver does not use these parameters and allows
35593 + * wpa_supplicant to control them internally.
35596 + case IW_AUTH_TKIP_COUNTERMEASURES:
35597 + break; /* FIXME */
35598 + case IW_AUTH_DROP_UNENCRYPTED:
35599 + ieee->drop_unencrypted = !!wrqu->param.value;
35601 + case IW_AUTH_80211_AUTH_ALG:
35602 + break; /* FIXME */
35603 + case IW_AUTH_WPA_ENABLED:
35604 + ieee->privacy_invoked = ieee->wpa_enabled = !!wrqu->param.value;
35606 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35607 + ieee->ieee802_1x = !!wrqu->param.value;
35609 + case IW_AUTH_PRIVACY_INVOKED:
35610 + ieee->privacy_invoked = !!wrqu->param.value;
35613 + err = -EOPNOTSUPP;
35616 + spin_unlock_irqrestore(&ieee->lock, flags);
35620 +int ieee80211_wx_get_auth(struct net_device *dev,
35621 + struct iw_request_info *info,
35622 + union iwreq_data *wrqu,
35625 + struct ieee80211_device *ieee = netdev_priv(dev);
35626 + unsigned long flags;
35629 + spin_lock_irqsave(&ieee->lock, flags);
35631 + switch (wrqu->param.flags & IW_AUTH_INDEX) {
35632 + case IW_AUTH_WPA_VERSION:
35633 + case IW_AUTH_CIPHER_PAIRWISE:
35634 + case IW_AUTH_CIPHER_GROUP:
35635 + case IW_AUTH_KEY_MGMT:
35636 + case IW_AUTH_TKIP_COUNTERMEASURES: /* FIXME */
35637 + case IW_AUTH_80211_AUTH_ALG: /* FIXME */
35639 + * Host AP driver does not use these parameters and allows
35640 + * wpa_supplicant to control them internally.
35642 + err = -EOPNOTSUPP;
35644 + case IW_AUTH_DROP_UNENCRYPTED:
35645 + wrqu->param.value = ieee->drop_unencrypted;
35647 + case IW_AUTH_WPA_ENABLED:
35648 + wrqu->param.value = ieee->wpa_enabled;
35650 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35651 + wrqu->param.value = ieee->ieee802_1x;
35654 + err = -EOPNOTSUPP;
35657 + spin_unlock_irqrestore(&ieee->lock, flags);
35661 EXPORT_SYMBOL(ieee80211_wx_set_encodeext);
35662 EXPORT_SYMBOL(ieee80211_wx_get_encodeext);
35664 EXPORT_SYMBOL(ieee80211_wx_get_scan);
35665 EXPORT_SYMBOL(ieee80211_wx_set_encode);
35666 EXPORT_SYMBOL(ieee80211_wx_get_encode);
35668 +EXPORT_SYMBOL_GPL(ieee80211_wx_set_auth);
35669 +EXPORT_SYMBOL_GPL(ieee80211_wx_get_auth);
35670 diff -Nur linux-2.6.16/net/Kconfig linux-2.6.16-bcm43xx/net/Kconfig
35671 --- linux-2.6.16/net/Kconfig 2006-03-20 06:53:29.000000000 +0100
35672 +++ linux-2.6.16-bcm43xx/net/Kconfig 2006-03-28 22:16:14.000000000 +0200
35673 @@ -222,8 +222,12 @@
35674 source "net/ax25/Kconfig"
35675 source "net/irda/Kconfig"
35676 source "net/bluetooth/Kconfig"
35677 +source "net/d80211/Kconfig"
35678 source "net/ieee80211/Kconfig"
35680 +config WIRELESS_EXT
35684 endmenu # Networking
35686 diff -Nur linux-2.6.16/net/Makefile linux-2.6.16-bcm43xx/net/Makefile
35687 --- linux-2.6.16/net/Makefile 2006-03-20 06:53:29.000000000 +0100
35688 +++ linux-2.6.16-bcm43xx/net/Makefile 2006-03-28 22:16:14.000000000 +0200
35690 obj-$(CONFIG_VLAN_8021Q) += 8021q/
35691 obj-$(CONFIG_IP_DCCP) += dccp/
35692 obj-$(CONFIG_IP_SCTP) += sctp/
35693 +obj-$(CONFIG_D80211) += d80211/
35694 obj-$(CONFIG_IEEE80211) += ieee80211/
35695 obj-$(CONFIG_TIPC) += tipc/
35697 diff -Nur linux-2.6.16/net/socket.c linux-2.6.16-bcm43xx/net/socket.c
35698 --- linux-2.6.16/net/socket.c 2006-03-20 06:53:29.000000000 +0100
35699 +++ linux-2.6.16-bcm43xx/net/socket.c 2006-03-28 22:16:14.000000000 +0200
35701 #include <linux/compat.h>
35702 #include <linux/kmod.h>
35703 #include <linux/audit.h>
35705 -#ifdef CONFIG_NET_RADIO
35706 -#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
35707 -#endif /* CONFIG_NET_RADIO */
35708 +#include <linux/wireless.h>
35710 #include <asm/uaccess.h>
35711 #include <asm/unistd.h>
35712 @@ -840,11 +837,11 @@
35713 if (cmd >= SIOCDEVPRIVATE && cmd <= (SIOCDEVPRIVATE + 15)) {
35714 err = dev_ioctl(cmd, argp);
35716 -#ifdef WIRELESS_EXT
35717 +#ifdef CONFIG_WIRELESS_EXT
35718 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
35719 err = dev_ioctl(cmd, argp);
35721 -#endif /* WIRELESS_EXT */
35722 +#endif /* CONFIG_WIRELESS_EXT */
35726 diff -Nur linux-2.6.16/scripts/bcm43xx-d80211-sta_up.sh linux-2.6.16-bcm43xx/scripts/bcm43xx-d80211-sta_up.sh
35727 --- linux-2.6.16/scripts/bcm43xx-d80211-sta_up.sh 1970-01-01 01:00:00.000000000 +0100
35728 +++ linux-2.6.16-bcm43xx/scripts/bcm43xx-d80211-sta_up.sh 2006-03-28 22:16:14.000000000 +0200
35732 +if [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
35733 + echo "$0, an ugly script to configure and bring up a STA (802.11 station)"
35734 + echo "device for the linux devicescape 802.11 stack."
35737 + echo "$0 [ wlan_device local_ip wpasupplicant_config ]"
35740 + echo "Run with default parameters: $0"
35741 + echo "Manually define parameters: $0 wlan0 192.168.1.1 ./wpasupp.conf"
35743 + echo "Default parameters are: $0 wlan0 192.168.1.101 /etc/wpa_supplicant.conf"
35751 +if [ -z "$wlan_dev" ]; then
35754 +if [ -z "$sta_dev" ]; then
35757 +if [ -z "$ip_addr" ]; then
35758 + ip_addr="192.168.1.101"
35760 +if [ -z "$wpasupp_conf" ]; then
35761 + wpasupp_conf="/etc/wpa_supplicant.conf"
35764 +idx=$(echo $wlan_dev | awk '{ gsub("[^0-9]", "", $0); printf($0); }')
35765 +if [ -z "$idx" ]; then
35766 + echo "Invalid wlan_device parameter \"$wlan_dev\". Example: wlan0"
35777 + if [ $res -ne 0 ]; then
35778 + echo "FAILED ($res)"
35783 +if [ -z "$(grep -e bcm43xx /proc/modules)" ]; then
35784 + echo "ERROR: bcm43xx module not loaded."
35788 +killall wpa_supplicant 2>/dev/null
35789 +echo -n "$sta_dev" > /sys/class/ieee80211/${phy_dev}/add_iface
35790 +if [ $? -ne 0 ]; then
35791 + echo "ERROR: Could not add STA device."
35794 +run iwconfig $wlan_dev.11 mode managed
35795 +run ifconfig $wlan_dev.11 up
35797 +hwaddr="$(ifconfig | grep $wlan_dev.11 | awk '{print $NF}')"
35798 +run ifconfig $sta_dev hw ether $hwaddr
35799 +run ifconfig $sta_dev $ip_addr
35800 +run ifconfig $sta_dev up
35801 +run iwconfig $sta_dev mode managed
35803 +run wpa_supplicant -B -Dwext -i$sta_dev -c$wpasupp_conf
35806 +echo "You may want to set the default route, now:"
35807 +echo " route add default gw GATEWAY_IP_ADDRESS"