ee88128ae597802494aadb6e482ebe69d76a8bd6
[openwrt/svn-archive/archive.git] / openwrt / target / linux / brcm-2.6 / patches / 005-bcm43xx-dscape-060328.patch
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
4 @@ -0,0 +1,67 @@
5 +**** ****
6 +**** HOWTO get bcm43xx-dscape running ****
7 +**** ****
8 +
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
13 +following text.
14 +
15 +
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...
19 +
20 +
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
26 + this patch.
27 +
28 + Patch the kernel, compile and install it.
29 + When configuring, enable
30 + "Networking/Generic IEEE 802.11 Networking Stack (dscape)"
31 + and
32 + "Device Drivers/Network device support/Wireless LAN (non-hamradio)/Broadcom BCM43xx wireless support (DeviceScape stack)"
33 + Reboot.
34 +
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:
37 +
38 + # WPA AES encryption
39 + ctrl_interface=/var/run/wpa_supplicant
40 + network={
41 + ssid="ACCESSPOINT_SSID"
42 + key_mgmt=WPA-PSK
43 + proto=WPA
44 + pairwise=CCMP TKIP
45 + group=CCMP TKIP
46 + psk="MY PASSPHRASE"
47 + priority=3
48 + }
49 +
50 +3) Take a bottle of your favourite beer, open it and take a swallow.
51 +
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.
61 +
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
65 +
66 +6) Take another swallow from your bottle of beer and test if it works:
67 + ping www.kernel.org
68 +
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
71 + does not work.
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
75 @@ -0,0 +1,31 @@
76 +
77 + BCM43xx Linux Driver Project
78 + ============================
79 +
80 +About this software
81 +-------------------
82 +
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/
86 +
87 +The project page is http://bcm43xx.berlios.de/
88 +
89 +This is a port of the bcm43xx driver for the devicescape ieee802.11
90 +stack.
91 +
92 +Requirements
93 +------------
94 +
95 +1) Linux Kernel 2.6.16 or later
96 + http://www.kernel.org/
97 +
98 + See Documentation/networking/bcm43xx-d80211-HOWTO.txt for further
99 + instructions.
100 +
101 +2) Firmware Files
102 +
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
110 @@ -0,0 +1,499 @@
111 +/*
112 +
113 + Broadcom BCM43xx wireless driver
114 +
115 + debugfs driver debugging code
116 +
117 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
118 +
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.
123 +
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.
128 +
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.
133 +
134 +*/
135 +
136 +
137 +
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>
143 +#include <asm/io.h>
144 +
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"
151 +
152 +#define REALLY_BIG_BUFFER_SIZE (1024*256)
153 +
154 +static struct bcm43xx_debugfs fs;
155 +static char really_big_buffer[REALLY_BIG_BUFFER_SIZE];
156 +static DECLARE_MUTEX(big_buffer_sem);
157 +
158 +
159 +static ssize_t write_file_dummy(struct file *file, const char __user *buf,
160 + size_t count, loff_t *ppos)
161 +{
162 + return count;
163 +}
164 +
165 +static int open_file_generic(struct inode *inode, struct file *file)
166 +{
167 + file->private_data = inode->u.generic_ip;
168 + return 0;
169 +}
170 +
171 +#define fappend(fmt, x...) pos += snprintf(buf + pos, len - pos, fmt , ##x)
172 +
173 +static ssize_t devinfo_read_file(struct file *file, char __user *userbuf,
174 + size_t count, loff_t *ppos)
175 +{
176 + const size_t len = REALLY_BIG_BUFFER_SIZE;
177 +
178 + struct bcm43xx_private *bcm = file->private_data;
179 + char *buf = really_big_buffer;
180 + size_t pos = 0;
181 + ssize_t res;
182 + struct net_device *net_dev;
183 + struct pci_dev *pci_dev;
184 + unsigned long flags;
185 + u16 tmp16;
186 + int i;
187 +
188 + down(&big_buffer_sem);
189 +
190 + bcm43xx_lock_mmio(bcm, flags);
191 + if (!bcm->initialized) {
192 + fappend("Board not initialized.\n");
193 + goto out;
194 + }
195 + net_dev = bcm->net_dev;
196 + pci_dev = bcm->pci_dev;
197 +
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,
212 + bcm->board_type);
213 +
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", \
217 + (info).available \
218 + ? "available" : "nonavailable", \
219 + (info).enabled \
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]);
226 +#undef fappend_core
227 + tmp16 = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
228 + fappend("LEDs: ");
229 + for (i = 0; i < BCM43xx_NR_LEDS; i++)
230 + fappend("%d ", !!(tmp16 & (1 << i)));
231 + fappend("\n");
232 +
233 +out:
234 + bcm43xx_unlock_mmio(bcm, flags);
235 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
236 + up(&big_buffer_sem);
237 + return res;
238 +}
239 +
240 +static ssize_t drvinfo_read_file(struct file *file, char __user *userbuf,
241 + size_t count, loff_t *ppos)
242 +{
243 + const size_t len = REALLY_BIG_BUFFER_SIZE;
244 +
245 + char *buf = really_big_buffer;
246 + size_t pos = 0;
247 + ssize_t res;
248 +
249 + down(&big_buffer_sem);
250 +
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__);
254 +
255 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
256 + up(&big_buffer_sem);
257 + return res;
258 +}
259 +
260 +static ssize_t spromdump_read_file(struct file *file, char __user *userbuf,
261 + size_t count, loff_t *ppos)
262 +{
263 + const size_t len = REALLY_BIG_BUFFER_SIZE;
264 +
265 + struct bcm43xx_private *bcm = file->private_data;
266 + char *buf = really_big_buffer;
267 + size_t pos = 0;
268 + ssize_t res;
269 + unsigned long flags;
270 +
271 + down(&big_buffer_sem);
272 + bcm43xx_lock_mmio(bcm, flags);
273 + if (!bcm->initialized) {
274 + fappend("Board not initialized.\n");
275 + goto out;
276 + }
277 +
278 + /* This is where the information is written to the "sprom_dump" file */
279 + fappend("boardflags: 0x%04x\n", bcm->sprom.boardflags);
280 +
281 +out:
282 + bcm43xx_unlock_mmio(bcm, flags);
283 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
284 + up(&big_buffer_sem);
285 + return res;
286 +}
287 +
288 +static ssize_t tsf_read_file(struct file *file, char __user *userbuf,
289 + size_t count, loff_t *ppos)
290 +{
291 + const size_t len = REALLY_BIG_BUFFER_SIZE;
292 +
293 + struct bcm43xx_private *bcm = file->private_data;
294 + char *buf = really_big_buffer;
295 + size_t pos = 0;
296 + ssize_t res;
297 + unsigned long flags;
298 + u64 tsf;
299 +
300 + down(&big_buffer_sem);
301 + bcm43xx_lock_mmio(bcm, flags);
302 + if (!bcm->initialized) {
303 + fappend("Board not initialized.\n");
304 + goto out;
305 + }
306 + bcm43xx_tsf_read(bcm, &tsf);
307 + fappend("0x%08x%08x\n",
308 + (unsigned int)((tsf & 0xFFFFFFFF00000000ULL) >> 32),
309 + (unsigned int)(tsf & 0xFFFFFFFFULL));
310 +
311 +out:
312 + bcm43xx_unlock_mmio(bcm, flags);
313 + res = simple_read_from_buffer(userbuf, count, ppos, buf, pos);
314 + up(&big_buffer_sem);
315 + return res;
316 +}
317 +
318 +static ssize_t tsf_write_file(struct file *file, const char __user *user_buf,
319 + size_t count, loff_t *ppos)
320 +{
321 + struct bcm43xx_private *bcm = file->private_data;
322 + char *buf = really_big_buffer;
323 + ssize_t buf_size;
324 + ssize_t res;
325 + unsigned long flags;
326 + u64 tsf;
327 +
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)) {
331 + res = -EFAULT;
332 + goto out_up;
333 + }
334 + bcm43xx_lock_mmio(bcm, flags);
335 + if (!bcm->initialized) {
336 + printk(KERN_INFO PFX "debugfs: Board not initialized.\n");
337 + res = -EFAULT;
338 + goto out_unlock;
339 + }
340 + if (sscanf(buf, "%lli", &tsf) != 1) {
341 + printk(KERN_INFO PFX "debugfs: invalid values for \"tsf\"\n");
342 + res = -EINVAL;
343 + goto out_unlock;
344 + }
345 + bcm43xx_tsf_write(bcm, tsf);
346 + res = buf_size;
347 +
348 +out_unlock:
349 + bcm43xx_unlock_mmio(bcm, flags);
350 +out_up:
351 + up(&big_buffer_sem);
352 + return res;
353 +}
354 +
355 +static ssize_t txstat_read_file(struct file *file, char __user *userbuf,
356 + size_t count, loff_t *ppos)
357 +{
358 + const size_t len = REALLY_BIG_BUFFER_SIZE;
359 +
360 + struct bcm43xx_private *bcm = file->private_data;
361 + char *buf = really_big_buffer;
362 + size_t pos = 0;
363 + ssize_t res;
364 + unsigned long flags;
365 + struct bcm43xx_dfsentry *e;
366 + struct bcm43xx_xmitstatus *status;
367 + int i, cnt, j = 0;
368 +
369 + down(&big_buffer_sem);
370 + bcm43xx_lock(bcm, flags);
371 +
372 + fappend("Last %d logged xmitstatus blobs (Latest first):\n\n",
373 + BCM43xx_NR_LOGGED_XMITSTATUS);
374 + e = bcm->dfsentry;
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.
380 + */
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)));
386 + }
387 + i = e->saved_xmitstatus_ptr - 1;
388 + if (i < 0)
389 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
390 + cnt = e->saved_xmitstatus_cnt;
391 + while (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,
398 + status->unknown);
399 + j++;
400 + cnt--;
401 + i--;
402 + if (i < 0)
403 + i = BCM43xx_NR_LOGGED_XMITSTATUS - 1;
404 + }
405 +
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;
412 + }
413 + bcm43xx_unlock(bcm, flags);
414 + up(&big_buffer_sem);
415 + return res;
416 +}
417 +
418 +#undef fappend
419 +
420 +
421 +static struct file_operations devinfo_fops = {
422 + .read = devinfo_read_file,
423 + .write = write_file_dummy,
424 + .open = open_file_generic,
425 +};
426 +
427 +static struct file_operations spromdump_fops = {
428 + .read = spromdump_read_file,
429 + .write = write_file_dummy,
430 + .open = open_file_generic,
431 +};
432 +
433 +static struct file_operations drvinfo_fops = {
434 + .read = drvinfo_read_file,
435 + .write = write_file_dummy,
436 + .open = open_file_generic,
437 +};
438 +
439 +static struct file_operations tsf_fops = {
440 + .read = tsf_read_file,
441 + .write = tsf_write_file,
442 + .open = open_file_generic,
443 +};
444 +
445 +static struct file_operations txstat_fops = {
446 + .read = txstat_read_file,
447 + .write = write_file_dummy,
448 + .open = open_file_generic,
449 +};
450 +
451 +
452 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm)
453 +{
454 + struct bcm43xx_dfsentry *e;
455 + char devdir[IFNAMSIZ];
456 +
457 + assert(bcm);
458 + e = kzalloc(sizeof(*e), GFP_KERNEL);
459 + if (!e) {
460 + printk(KERN_ERR PFX "out of memory\n");
461 + return;
462 + }
463 + e->bcm = bcm;
464 + e->xmitstatus_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
465 + * sizeof(*(e->xmitstatus_buffer)),
466 + GFP_KERNEL);
467 + if (!e->xmitstatus_buffer) {
468 + printk(KERN_ERR PFX "out of memory\n");
469 + kfree(e);
470 + return;
471 + }
472 + e->xmitstatus_print_buffer = kzalloc(BCM43xx_NR_LOGGED_XMITSTATUS
473 + * sizeof(*(e->xmitstatus_buffer)),
474 + GFP_KERNEL);
475 + if (!e->xmitstatus_print_buffer) {
476 + printk(KERN_ERR PFX "out of memory\n");
477 + kfree(e);
478 + return;
479 + }
480 +
481 +
482 + bcm->dfsentry = e;
483 +
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,
495 + bcm, &tsf_fops);
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);
502 +}
503 +
504 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm)
505 +{
506 + struct bcm43xx_dfsentry *e;
507 +
508 + if (!bcm)
509 + return;
510 +
511 + e = bcm->dfsentry;
512 + assert(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);
520 + kfree(e);
521 +}
522 +
523 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
524 + struct bcm43xx_xmitstatus *status)
525 +{
526 + struct bcm43xx_dfsentry *e;
527 + struct bcm43xx_xmitstatus *savedstatus;
528 +
529 + /* This is protected by bcm->_lock */
530 + e = bcm->dfsentry;
531 + assert(e);
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++;
539 +}
540 +
541 +void bcm43xx_debugfs_init(void)
542 +{
543 + memset(&fs, 0, sizeof(fs));
544 + fs.root = debugfs_create_dir(KBUILD_MODNAME, NULL);
545 + if (!fs.root)
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");
550 +}
551 +
552 +void bcm43xx_debugfs_exit(void)
553 +{
554 + debugfs_remove(fs.dentry_driverinfo);
555 + debugfs_remove(fs.root);
556 +}
557 +
558 +void bcm43xx_printk_dump(const char *data,
559 + size_t size,
560 + const char *description)
561 +{
562 + size_t i;
563 + char c;
564 +
565 + printk(KERN_INFO PFX "Data dump (%s, %u bytes):",
566 + description, size);
567 + for (i = 0; i < size; i++) {
568 + c = data[i];
569 + if (i % 8 == 0)
570 + printk("\n" KERN_INFO PFX "0x%08x: 0x%02x, ", i, c & 0xff);
571 + else
572 + printk("0x%02x, ", c & 0xff);
573 + }
574 + printk("\n");
575 +}
576 +
577 +void bcm43xx_printk_bitdump(const unsigned char *data,
578 + size_t bytes, int msb_to_lsb,
579 + const char *description)
580 +{
581 + size_t i;
582 + int j;
583 + const unsigned char *d;
584 +
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++) {
588 + d = data + i;
589 + if (i % 8 == 0)
590 + printk("\n" KERN_INFO PFX "0x%08x: ", i);
591 + if (msb_to_lsb) {
592 + for (j = 7; j >= 0; j--) {
593 + if (*d & (1 << j))
594 + printk("1");
595 + else
596 + printk("0");
597 + }
598 + } else {
599 + for (j = 0; j < 8; j++) {
600 + if (*d & (1 << j))
601 + printk("1");
602 + else
603 + printk("0");
604 + }
605 + }
606 + printk(" ");
607 + }
608 + printk("\n");
609 +}
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
613 @@ -0,0 +1,117 @@
614 +#ifndef BCM43xx_DEBUGFS_H_
615 +#define BCM43xx_DEBUGFS_H_
616 +
617 +struct bcm43xx_private;
618 +struct bcm43xx_xmitstatus;
619 +
620 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
621 +
622 +#include <linux/list.h>
623 +#include <asm/semaphore.h>
624 +
625 +struct dentry;
626 +
627 +/* limited by the size of the "really_big_buffer" */
628 +#define BCM43xx_NR_LOGGED_XMITSTATUS 100
629 +
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;
636 +
637 + struct bcm43xx_private *bcm;
638 +
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).
646 + */
647 + struct bcm43xx_xmitstatus *xmitstatus_print_buffer;
648 + int saved_xmitstatus_ptr;
649 + int saved_xmitstatus_cnt;
650 + int xmitstatus_printing;
651 +};
652 +
653 +struct bcm43xx_debugfs {
654 + struct dentry *root;
655 + struct dentry *dentry_driverinfo;
656 +};
657 +
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);
664 +
665 +/* Debug helper: Dump binary data through printk. */
666 +void bcm43xx_printk_dump(const char *data,
667 + size_t size,
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) \
674 + do { \
675 + bcm43xx_printk_bitdump((const unsigned char *)(pointer), \
676 + sizeof(*(pointer)), \
677 + (msb_to_lsb), \
678 + (description)); \
679 + } while (0)
680 +
681 +#else /* CONFIG_BCM43XX_D80211_DEBUG*/
682 +
683 +static inline
684 +void bcm43xx_debugfs_init(void) { }
685 +static inline
686 +void bcm43xx_debugfs_exit(void) { }
687 +static inline
688 +void bcm43xx_debugfs_add_device(struct bcm43xx_private *bcm) { }
689 +static inline
690 +void bcm43xx_debugfs_remove_device(struct bcm43xx_private *bcm) { }
691 +static inline
692 +void bcm43xx_debugfs_log_txstat(struct bcm43xx_private *bcm,
693 + struct bcm43xx_xmitstatus *status) { }
694 +
695 +static inline
696 +void bcm43xx_printk_dump(const char *data,
697 + size_t size,
698 + const char *description)
699 +{
700 +}
701 +static inline
702 +void bcm43xx_printk_bitdump(const unsigned char *data,
703 + size_t bytes, int msb_to_lsb,
704 + const char *description)
705 +{
706 +}
707 +#define bcm43xx_printk_bitdumpt(pointer, msb_to_lsb, description) do { /* nothing */ } while (0)
708 +
709 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
710 +
711 +/* Ugly helper macros to make incomplete code more verbose on runtime */
712 +#ifdef TODO
713 +# undef TODO
714 +#endif
715 +#define TODO() \
716 + do { \
717 + printk(KERN_INFO PFX "TODO: Incomplete code in %s() at %s:%d\n", \
718 + __FUNCTION__, __FILE__, __LINE__); \
719 + } while (0)
720 +
721 +#ifdef FIXME
722 +# undef FIXME
723 +#endif
724 +#define FIXME() \
725 + do { \
726 + printk(KERN_INFO PFX "FIXME: Possibly broken code in %s() at %s:%d\n", \
727 + __FUNCTION__, __FILE__, __LINE__); \
728 + } while (0)
729 +
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
734 @@ -0,0 +1,991 @@
735 +/*
736 +
737 + Broadcom BCM43xx wireless driver
738 +
739 + DMA ringbuffer and descriptor allocation/management
740 +
741 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
742 +
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
746 +
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.
751 +
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.
756 +
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.
761 +
762 +*/
763 +
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"
770 +
771 +#include <linux/dma-mapping.h>
772 +#include <linux/pci.h>
773 +#include <linux/delay.h>
774 +#include <linux/skbuff.h>
775 +
776 +
777 +static inline int free_slots(struct bcm43xx_dmaring *ring)
778 +{
779 + return (ring->nr_slots - ring->used_slots);
780 +}
781 +
782 +static inline int next_slot(struct bcm43xx_dmaring *ring, int slot)
783 +{
784 + assert(slot >= -1 && slot <= ring->nr_slots - 1);
785 + if (slot == ring->nr_slots - 1)
786 + return 0;
787 + return slot + 1;
788 +}
789 +
790 +static inline int prev_slot(struct bcm43xx_dmaring *ring, int slot)
791 +{
792 + assert(slot >= 0 && slot <= ring->nr_slots - 1);
793 + if (slot == 0)
794 + return ring->nr_slots - 1;
795 + return slot - 1;
796 +}
797 +
798 +/* Request a slot for usage. */
799 +static inline
800 +int request_slot(struct bcm43xx_dmaring *ring)
801 +{
802 + int slot;
803 +
804 + assert(ring->tx);
805 + assert(!ring->suspended);
806 + assert(free_slots(ring) != 0);
807 +
808 + slot = next_slot(ring, ring->current_slot);
809 + ring->current_slot = slot;
810 + ring->used_slots++;
811 +
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*/
816 +
817 + return slot;
818 +}
819 +
820 +/* Return a slot to the free slots. */
821 +static inline
822 +void return_slot(struct bcm43xx_dmaring *ring, int slot)
823 +{
824 + assert(ring->tx);
825 +
826 + ring->used_slots--;
827 +}
828 +
829 +static inline
830 +dma_addr_t map_descbuffer(struct bcm43xx_dmaring *ring,
831 + unsigned char *buf,
832 + size_t len,
833 + int tx)
834 +{
835 + dma_addr_t dmaaddr;
836 +
837 + if (tx) {
838 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
839 + buf, len,
840 + DMA_TO_DEVICE);
841 + } else {
842 + dmaaddr = dma_map_single(&ring->bcm->pci_dev->dev,
843 + buf, len,
844 + DMA_FROM_DEVICE);
845 + }
846 +
847 + return dmaaddr;
848 +}
849 +
850 +static inline
851 +void unmap_descbuffer(struct bcm43xx_dmaring *ring,
852 + dma_addr_t addr,
853 + size_t len,
854 + int tx)
855 +{
856 + if (tx) {
857 + dma_unmap_single(&ring->bcm->pci_dev->dev,
858 + addr, len,
859 + DMA_TO_DEVICE);
860 + } else {
861 + dma_unmap_single(&ring->bcm->pci_dev->dev,
862 + addr, len,
863 + DMA_FROM_DEVICE);
864 + }
865 +}
866 +
867 +static inline
868 +void sync_descbuffer_for_cpu(struct bcm43xx_dmaring *ring,
869 + dma_addr_t addr,
870 + size_t len)
871 +{
872 + assert(!ring->tx);
873 +
874 + dma_sync_single_for_cpu(&ring->bcm->pci_dev->dev,
875 + addr, len, DMA_FROM_DEVICE);
876 +}
877 +
878 +static inline
879 +void sync_descbuffer_for_device(struct bcm43xx_dmaring *ring,
880 + dma_addr_t addr,
881 + size_t len)
882 +{
883 + assert(!ring->tx);
884 +
885 + dma_sync_single_for_device(&ring->bcm->pci_dev->dev,
886 + addr, len, DMA_FROM_DEVICE);
887 +}
888 +
889 +/* Unmap and free a descriptor buffer. */
890 +static inline
891 +void free_descriptor_buffer(struct bcm43xx_dmaring *ring,
892 + struct bcm43xx_dmadesc *desc,
893 + struct bcm43xx_dmadesc_meta *meta,
894 + int irq_context)
895 +{
896 + assert(meta->skb);
897 + if (irq_context)
898 + dev_kfree_skb_irq(meta->skb);
899 + else
900 + dev_kfree_skb(meta->skb);
901 + meta->skb = NULL;
902 +}
903 +
904 +static int alloc_ringmemory(struct bcm43xx_dmaring *ring)
905 +{
906 + struct device *dev = &(ring->bcm->pci_dev->dev);
907 +
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");
912 + return -ENOMEM;
913 + }
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);
920 + return -ENOMEM;
921 + }
922 + assert(!(ring->dmabase & 0x000003FF));
923 + memset(ring->vbase, 0, BCM43xx_DMA_RINGMEMSIZE);
924 +
925 + return 0;
926 +}
927 +
928 +static void free_ringmemory(struct bcm43xx_dmaring *ring)
929 +{
930 + struct device *dev = &(ring->bcm->pci_dev->dev);
931 +
932 + dma_free_coherent(dev, BCM43xx_DMA_RINGMEMSIZE,
933 + ring->vbase, ring->dmabase);
934 +}
935 +
936 +/* Reset the RX DMA channel */
937 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
938 + u16 mmio_base)
939 +{
940 + int i;
941 + u32 value;
942 +
943 + bcm43xx_write32(bcm,
944 + mmio_base + BCM43xx_DMA_RX_CONTROL,
945 + 0x00000000);
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) {
951 + i = -1;
952 + break;
953 + }
954 + udelay(10);
955 + }
956 + if (i != -1) {
957 + printk(KERN_ERR PFX "Error: Wait on DMA RX status timed out.\n");
958 + return -ENODEV;
959 + }
960 +
961 + return 0;
962 +}
963 +
964 +/* Reset the RX DMA channel */
965 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
966 + u16 mmio_base)
967 +{
968 + int i;
969 + u32 value;
970 +
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)
978 + break;
979 + udelay(10);
980 + }
981 + bcm43xx_write32(bcm,
982 + mmio_base + BCM43xx_DMA_TX_CONTROL,
983 + 0x00000000);
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) {
989 + i = -1;
990 + break;
991 + }
992 + udelay(10);
993 + }
994 + if (i != -1) {
995 + printk(KERN_ERR PFX "Error: Wait on DMA TX status timed out.\n");
996 + return -ENODEV;
997 + }
998 + /* ensure the reset is completed. */
999 + udelay(300);
1000 +
1001 + return 0;
1002 +}
1003 +
1004 +static int setup_rx_descbuffer(struct bcm43xx_dmaring *ring,
1005 + struct bcm43xx_dmadesc *desc,
1006 + struct bcm43xx_dmadesc_meta *meta,
1007 + gfp_t gfp_flags)
1008 +{
1009 + struct bcm43xx_rxhdr *rxhdr;
1010 + dma_addr_t dmaaddr;
1011 + u32 desc_addr;
1012 + u32 desc_ctl;
1013 + const int slot = (int)(desc - ring->vbase);
1014 + struct sk_buff *skb;
1015 +
1016 + assert(slot >= 0 && slot < ring->nr_slots);
1017 + assert(!ring->tx);
1018 +
1019 + skb = __dev_alloc_skb(ring->rx_buffersize, gfp_flags);
1020 + if (unlikely(!skb))
1021 + return -ENOMEM;
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);
1030 + return -ENOMEM;
1031 + }
1032 + meta->skb = skb;
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);
1042 +
1043 + rxhdr = (struct bcm43xx_rxhdr *)(skb->data);
1044 + rxhdr->frame_length = 0;
1045 + rxhdr->flags1 = 0;
1046 +
1047 + return 0;
1048 +}
1049 +
1050 +/* Allocate the initial descbuffers.
1051 + * This is used for an RX ring only.
1052 + */
1053 +static int alloc_initial_descbuffers(struct bcm43xx_dmaring *ring)
1054 +{
1055 + int i, err = -ENOMEM;
1056 + struct bcm43xx_dmadesc *desc;
1057 + struct bcm43xx_dmadesc_meta *meta;
1058 +
1059 + for (i = 0; i < ring->nr_slots; i++) {
1060 + desc = ring->vbase + i;
1061 + meta = ring->meta + i;
1062 +
1063 + err = setup_rx_descbuffer(ring, desc, meta, GFP_KERNEL);
1064 + if (err)
1065 + goto err_unwind;
1066 + }
1067 + ring->used_slots = ring->nr_slots;
1068 + err = 0;
1069 +out:
1070 + return err;
1071 +
1072 +err_unwind:
1073 + for (i--; i >= 0; i--) {
1074 + desc = ring->vbase + i;
1075 + meta = ring->meta + i;
1076 +
1077 + unmap_descbuffer(ring, meta->dmaaddr, ring->rx_buffersize, 0);
1078 + dev_kfree_skb(meta->skb);
1079 + }
1080 + goto out;
1081 +}
1082 +
1083 +/* Do initial setup of the DMA controller.
1084 + * Reset the controller, write the ring busaddress
1085 + * and switch the "enable" bit on.
1086 + */
1087 +static int dmacontroller_setup(struct bcm43xx_dmaring *ring)
1088 +{
1089 + int err = 0;
1090 + u32 value;
1091 +
1092 + if (ring->tx) {
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);
1099 + } else {
1100 + err = alloc_initial_descbuffers(ring);
1101 + if (err)
1102 + goto out;
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);
1112 + }
1113 +
1114 +out:
1115 + return err;
1116 +}
1117 +
1118 +/* Shutdown the DMA controller. */
1119 +static void dmacontroller_cleanup(struct bcm43xx_dmaring *ring)
1120 +{
1121 + if (ring->tx) {
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);
1125 + } else {
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);
1129 + }
1130 +}
1131 +
1132 +static void free_all_descbuffers(struct bcm43xx_dmaring *ring)
1133 +{
1134 + struct bcm43xx_dmadesc *desc;
1135 + struct bcm43xx_dmadesc_meta *meta;
1136 + int i;
1137 +
1138 + if (!ring->used_slots)
1139 + return;
1140 + for (i = 0; i < ring->nr_slots; i++) {
1141 + desc = ring->vbase + i;
1142 + meta = ring->meta + i;
1143 +
1144 + if (!meta->skb) {
1145 + assert(ring->tx);
1146 + continue;
1147 + }
1148 + if (ring->tx) {
1149 + unmap_descbuffer(ring, meta->dmaaddr,
1150 + meta->skb->len, 1);
1151 + } else {
1152 + unmap_descbuffer(ring, meta->dmaaddr,
1153 + ring->rx_buffersize, 0);
1154 + }
1155 + free_descriptor_buffer(ring, desc, meta, 0);
1156 + }
1157 +}
1158 +
1159 +/* Main initialization function. */
1160 +static
1161 +struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
1162 + u16 dma_controller_base,
1163 + int nr_descriptor_slots,
1164 + int tx)
1165 +{
1166 + struct bcm43xx_dmaring *ring;
1167 + int err;
1168 +
1169 + ring = kzalloc(sizeof(*ring), GFP_KERNEL);
1170 + if (!ring)
1171 + goto out;
1172 +
1173 + ring->meta = kzalloc(sizeof(*ring->meta) * nr_descriptor_slots,
1174 + GFP_KERNEL);
1175 + if (!ring->meta)
1176 + goto err_kfree_ring;
1177 +
1178 + ring->memoffset = BCM43xx_DMA_DMABUSADDROFFSET;
1179 +#ifdef CONFIG_BCM947XX
1180 + if (bcm->pci_dev->bus->number == 0)
1181 + ring->memoffset = 0;
1182 +#endif
1183 +
1184 + ring->bcm = bcm;
1185 + ring->nr_slots = nr_descriptor_slots;
1186 + ring->mmio_base = dma_controller_base;
1187 + if (tx) {
1188 + ring->tx = 1;
1189 + ring->current_slot = -1;
1190 + } else {
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;
1195 + break;
1196 + case BCM43xx_MMIO_DMA4_BASE:
1197 + ring->rx_buffersize = BCM43xx_DMA4_RXBUFFERSIZE;
1198 + ring->frameoffset = BCM43xx_DMA4_RX_FRAMEOFFSET;
1199 + break;
1200 + default:
1201 + assert(0);
1202 + }
1203 + }
1204 +
1205 + err = alloc_ringmemory(ring);
1206 + if (err)
1207 + goto err_kfree_meta;
1208 + err = dmacontroller_setup(ring);
1209 + if (err)
1210 + goto err_free_ringmemory;
1211 +
1212 +out:
1213 + return ring;
1214 +
1215 +err_free_ringmemory:
1216 + free_ringmemory(ring);
1217 +err_kfree_meta:
1218 + kfree(ring->meta);
1219 +err_kfree_ring:
1220 + kfree(ring);
1221 + ring = NULL;
1222 + goto out;
1223 +}
1224 +
1225 +/* Main cleanup function. */
1226 +static void bcm43xx_destroy_dmaring(struct bcm43xx_dmaring *ring)
1227 +{
1228 + if (!ring)
1229 + return;
1230 +
1231 + dprintk(KERN_INFO PFX "DMA 0x%04x (%s) max used slots: %d/%d\n",
1232 + ring->mmio_base,
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.
1237 + */
1238 + dmacontroller_cleanup(ring);
1239 + free_all_descbuffers(ring);
1240 + free_ringmemory(ring);
1241 +
1242 + kfree(ring->meta);
1243 + kfree(ring);
1244 +}
1245 +
1246 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1247 +{
1248 + struct bcm43xx_dma *dma;
1249 +
1250 + if (bcm43xx_using_pio(bcm))
1251 + return;
1252 + dma = bcm43xx_current_dma(bcm);
1253 +
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;
1266 +}
1267 +
1268 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1269 +{
1270 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1271 + struct bcm43xx_dmaring *ring;
1272 + int err = -ENOMEM;
1273 +
1274 + /* setup TX DMA channels. */
1275 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1276 + BCM43xx_TXRING_SLOTS, 1);
1277 + if (!ring)
1278 + goto out;
1279 + dma->tx_ring0 = ring;
1280 +
1281 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA2_BASE,
1282 + BCM43xx_TXRING_SLOTS, 1);
1283 + if (!ring)
1284 + goto err_destroy_tx0;
1285 + dma->tx_ring1 = ring;
1286 +
1287 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA3_BASE,
1288 + BCM43xx_TXRING_SLOTS, 1);
1289 + if (!ring)
1290 + goto err_destroy_tx1;
1291 + dma->tx_ring2 = ring;
1292 +
1293 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1294 + BCM43xx_TXRING_SLOTS, 1);
1295 + if (!ring)
1296 + goto err_destroy_tx2;
1297 + dma->tx_ring3 = ring;
1298 +
1299 + /* setup RX DMA channels. */
1300 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA1_BASE,
1301 + BCM43xx_RXRING_SLOTS, 0);
1302 + if (!ring)
1303 + goto err_destroy_tx3;
1304 + dma->rx_ring0 = ring;
1305 +
1306 + if (bcm->current_core->rev < 5) {
1307 + ring = bcm43xx_setup_dmaring(bcm, BCM43xx_MMIO_DMA4_BASE,
1308 + BCM43xx_RXRING_SLOTS, 0);
1309 + if (!ring)
1310 + goto err_destroy_rx0;
1311 + dma->rx_ring1 = ring;
1312 + }
1313 +
1314 + dprintk(KERN_INFO PFX "DMA initialized\n");
1315 + err = 0;
1316 +out:
1317 + return err;
1318 +
1319 +err_destroy_rx0:
1320 + bcm43xx_destroy_dmaring(dma->rx_ring0);
1321 + dma->rx_ring0 = NULL;
1322 +err_destroy_tx3:
1323 + bcm43xx_destroy_dmaring(dma->tx_ring3);
1324 + dma->tx_ring3 = NULL;
1325 +err_destroy_tx2:
1326 + bcm43xx_destroy_dmaring(dma->tx_ring2);
1327 + dma->tx_ring2 = NULL;
1328 +err_destroy_tx1:
1329 + bcm43xx_destroy_dmaring(dma->tx_ring1);
1330 + dma->tx_ring1 = NULL;
1331 +err_destroy_tx0:
1332 + bcm43xx_destroy_dmaring(dma->tx_ring0);
1333 + dma->tx_ring0 = NULL;
1334 + goto out;
1335 +}
1336 +
1337 +/* Generate a cookie for the TX header. */
1338 +static u16 generate_cookie(struct bcm43xx_dmaring *ring,
1339 + int slot)
1340 +{
1341 + u16 cookie = 0x0000;
1342 +
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
1346 + */
1347 + switch (ring->mmio_base) {
1348 + default:
1349 + assert(0);
1350 + case BCM43xx_MMIO_DMA1_BASE:
1351 + break;
1352 + case BCM43xx_MMIO_DMA2_BASE:
1353 + cookie = 0x1000;
1354 + break;
1355 + case BCM43xx_MMIO_DMA3_BASE:
1356 + cookie = 0x2000;
1357 + break;
1358 + case BCM43xx_MMIO_DMA4_BASE:
1359 + cookie = 0x3000;
1360 + break;
1361 + }
1362 + assert(((u16)slot & 0xF000) == 0x0000);
1363 + cookie |= (u16)slot;
1364 +
1365 + return cookie;
1366 +}
1367 +
1368 +/* Inspect a cookie and find out to which controller/slot it belongs. */
1369 +static
1370 +struct bcm43xx_dmaring * parse_cookie(struct bcm43xx_private *bcm,
1371 + u16 cookie, int *slot)
1372 +{
1373 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1374 + struct bcm43xx_dmaring *ring = NULL;
1375 +
1376 + switch (cookie & 0xF000) {
1377 + case 0x0000:
1378 + ring = dma->tx_ring0;
1379 + break;
1380 + case 0x1000:
1381 + ring = dma->tx_ring1;
1382 + break;
1383 + case 0x2000:
1384 + ring = dma->tx_ring2;
1385 + break;
1386 + case 0x3000:
1387 + ring = dma->tx_ring3;
1388 + break;
1389 + default:
1390 + assert(0);
1391 + }
1392 + *slot = (cookie & 0x0FFF);
1393 + assert(*slot >= 0 && *slot < ring->nr_slots);
1394 +
1395 + return ring;
1396 +}
1397 +
1398 +static void dmacontroller_poke_tx(struct bcm43xx_dmaring *ring,
1399 + int slot)
1400 +{
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.
1405 + */
1406 + wmb();
1407 + slot = next_slot(ring, slot);
1408 + bcm43xx_dma_write(ring, BCM43xx_DMA_TX_DESC_INDEX,
1409 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1410 +}
1411 +
1412 +static int dma_tx_fragment(struct bcm43xx_dmaring *ring,
1413 + struct sk_buff *skb,
1414 + struct ieee80211_tx_control *ctl)
1415 +{
1416 + struct sk_buff *hdr_skb;
1417 + int slot;
1418 + struct bcm43xx_dmadesc *desc;
1419 + struct bcm43xx_dmadesc_meta *meta;
1420 + u32 desc_ctl;
1421 + u32 desc_addr;
1422 +
1423 + assert(skb_shinfo(skb)->nr_frags == 0);
1424 +
1425 + hdr_skb = dev_alloc_skb(sizeof(struct bcm43xx_txhdr));
1426 + if (unlikely(!hdr_skb))
1427 + return -ENOMEM;
1428 + skb_put(hdr_skb, sizeof(struct bcm43xx_txhdr));
1429 +
1430 + slot = request_slot(ring);
1431 + desc = ring->vbase + slot;
1432 + meta = ring->meta + slot;
1433 +
1434 + bcm43xx_generate_txhdr(ring->bcm,
1435 + (struct bcm43xx_txhdr *)hdr_skb->data,
1436 + skb->data, skb->len,
1437 + 1,//FIXME
1438 + generate_cookie(ring, slot),
1439 + ctl);
1440 +
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);
1449 + return -ENOMEM;
1450 + }
1451 +
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);
1459 +
1460 + slot = request_slot(ring);
1461 + desc = ring->vbase + slot;
1462 + meta = ring->meta + slot;
1463 +
1464 + /* We inspect the txstatus on the FRAMESTART descriptor later
1465 + * on xmit-status IRQ.
1466 + */
1467 + meta->must_xmit_txstat = 1;
1468 + memset(&meta->txstat, 0, sizeof(meta->txstat));
1469 + memcpy(&meta->txstat.control, ctl, sizeof(*ctl));
1470 +
1471 + meta->skb = skb;
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);
1480 + return -ENOMEM;
1481 + }
1482 +
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;
1487 +
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);
1493 +
1494 + return 0;
1495 +}
1496 +
1497 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1498 + struct sk_buff *skb,
1499 + struct ieee80211_tx_control *ctl)
1500 +{
1501 + struct bcm43xx_dmaring *ring = bcm43xx_current_dma(bcm)->tx_ring1;
1502 + int err;
1503 +
1504 + assert(ring->tx);
1505 +
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.
1511 + */
1512 + printk(KERN_ERR PFX "DMA queue overflow\n");
1513 + return -ENOMEM;
1514 + }
1515 +
1516 + err = dma_tx_fragment(ring, skb, ctl);
1517 + if (likely(!err))
1518 + ring->nr_tx_packets++;
1519 +
1520 + return err;
1521 +}
1522 +
1523 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1524 + struct bcm43xx_xmitstatus *status)
1525 +{
1526 + struct bcm43xx_dmaring *ring;
1527 + struct bcm43xx_dmadesc *desc;
1528 + struct bcm43xx_dmadesc_meta *meta;
1529 + int is_last_fragment;
1530 + int slot;
1531 +
1532 + ring = parse_cookie(bcm, status->cookie, &slot);
1533 + assert(ring);
1534 + assert(ring->tx);
1535 + assert(get_desc_ctl(ring->vbase + slot) & BCM43xx_DMADTOR_FRAMESTART);
1536 + while (1) {
1537 + assert(slot >= 0 && slot < ring->nr_slots);
1538 + desc = ring->vbase + slot;
1539 + meta = ring->meta + slot;
1540 +
1541 + is_last_fragment = !!(get_desc_ctl(desc) & BCM43xx_DMADTOR_FRAMEEND);
1542 + unmap_descbuffer(ring, meta->dmaaddr, meta->skb->len, 1);
1543 +
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().
1549 + */
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));
1554 + meta->skb = NULL;
1555 + } else
1556 + free_descriptor_buffer(ring, desc, meta, 1);
1557 + /* Everything belonging to the slot is unmapped
1558 + * and freed, so we can return it.
1559 + */
1560 + return_slot(ring, slot);
1561 +
1562 + if (is_last_fragment)
1563 + break;
1564 + slot = next_slot(ring, slot);
1565 + }
1566 + bcm->stats.last_tx = jiffies;
1567 +}
1568 +
1569 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1570 + struct ieee80211_tx_queue_stats *stats)
1571 +{
1572 + struct bcm43xx_dma *dma = bcm43xx_current_dma(bcm);
1573 + struct bcm43xx_dmaring *ring;
1574 + struct ieee80211_tx_queue_stats_data *data;
1575 +
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;
1581 +}
1582 +
1583 +static void dma_rx(struct bcm43xx_dmaring *ring,
1584 + int *slot)
1585 +{
1586 + struct bcm43xx_dmadesc *desc;
1587 + struct bcm43xx_dmadesc_meta *meta;
1588 + struct bcm43xx_rxhdr *rxhdr;
1589 + struct sk_buff *skb;
1590 + u16 len;
1591 + int err;
1592 + dma_addr_t dmaaddr;
1593 +
1594 + desc = ring->vbase + *slot;
1595 + meta = ring->meta + *slot;
1596 +
1597 + sync_descbuffer_for_cpu(ring, meta->dmaaddr, ring->rx_buffersize);
1598 + skb = meta->skb;
1599 +
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;
1604 +
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);
1611 +
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);
1616 +
1617 + return;
1618 + }
1619 + rxhdr = (struct bcm43xx_rxhdr *)skb->data;
1620 + len = le16_to_cpu(rxhdr->frame_length);
1621 + if (len == 0) {
1622 + int i = 0;
1623 +
1624 + do {
1625 + udelay(2);
1626 + barrier();
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);
1633 + goto drop;
1634 + }
1635 + }
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.
1641 + */
1642 + int cnt = 0;
1643 + s32 tmp = len;
1644 +
1645 + while (1) {
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);
1652 + cnt++;
1653 + tmp -= ring->rx_buffersize;
1654 + if (tmp <= 0)
1655 + break;
1656 + }
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);
1660 + goto drop;
1661 + }
1662 +
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);
1669 + goto drop;
1670 + }
1671 +
1672 + unmap_descbuffer(ring, dmaaddr, ring->rx_buffersize, 0);
1673 + skb_put(skb, len + ring->frameoffset);
1674 + skb_pull(skb, ring->frameoffset);
1675 +
1676 + bcm43xx_rx(ring->bcm, skb, rxhdr);
1677 +drop:
1678 + return;
1679 +}
1680 +
1681 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1682 +{
1683 + u32 status;
1684 + u16 descptr;
1685 + int slot, current_slot;
1686 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
1687 + int used_slots = 0;
1688 +#endif
1689 +
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);
1695 +
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;
1702 +#endif
1703 + }
1704 + bcm43xx_dma_write(ring, BCM43xx_DMA_RX_DESC_INDEX,
1705 + (u32)(slot * sizeof(struct bcm43xx_dmadesc)));
1706 + ring->current_slot = slot;
1707 +}
1708 +
1709 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring)
1710 +{
1711 + assert(ring->tx);
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);
1716 +}
1717 +
1718 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring)
1719 +{
1720 + assert(ring->tx);
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);
1725 +}
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
1729 @@ -0,0 +1,228 @@
1730 +#ifndef BCM43xx_DMA_H_
1731 +#define BCM43xx_DMA_H_
1732 +
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>
1738 +
1739 +#include "bcm43xx.h"
1740 +
1741 +
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)
1747 +
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
1757 +
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
1785 +
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)
1792 +
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
1799 +
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
1805 +
1806 +
1807 +
1808 +#ifdef CONFIG_BCM43XX_D80211_DMA
1809 +
1810 +
1811 +struct sk_buff;
1812 +struct bcm43xx_private;
1813 +struct bcm43xx_xmitstatus;
1814 +
1815 +
1816 +struct bcm43xx_dmadesc {
1817 + __le32 _control;
1818 + __le32 _address;
1819 +} __attribute__((__packed__));
1820 +
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)
1826 +
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;
1835 +};
1836 +
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. */
1848 + int nr_slots;
1849 + /* Number of used descriptor slots. */
1850 + int used_slots;
1851 + /* Currently used slot in the ring. */
1852 + int current_slot;
1853 + /* Total number of packets sent. Statistics only. */
1854 + unsigned int nr_tx_packets;
1855 + /* Frameoffset in octets. */
1856 + u32 frameoffset;
1857 + /* Descriptor buffer size. */
1858 + u16 rx_buffersize;
1859 + /* The MMIO base register of the DMA controller, this
1860 + * ring is posted to.
1861 + */
1862 + u16 mmio_base;
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*/
1869 +};
1870 +
1871 +
1872 +static inline
1873 +u32 bcm43xx_dma_read(struct bcm43xx_dmaring *ring,
1874 + u16 offset)
1875 +{
1876 + return bcm43xx_read32(ring->bcm, ring->mmio_base + offset);
1877 +}
1878 +
1879 +static inline
1880 +void bcm43xx_dma_write(struct bcm43xx_dmaring *ring,
1881 + u16 offset, u32 value)
1882 +{
1883 + bcm43xx_write32(ring->bcm, ring->mmio_base + offset, value);
1884 +}
1885 +
1886 +
1887 +int bcm43xx_dma_init(struct bcm43xx_private *bcm);
1888 +void bcm43xx_dma_free(struct bcm43xx_private *bcm);
1889 +
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);
1894 +
1895 +void bcm43xx_dma_tx_suspend(struct bcm43xx_dmaring *ring);
1896 +void bcm43xx_dma_tx_resume(struct bcm43xx_dmaring *ring);
1897 +
1898 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1899 + struct ieee80211_tx_queue_stats *stats);
1900 +
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);
1906 +
1907 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring);
1908 +
1909 +
1910 +#else /* CONFIG_BCM43XX_D80211_DMA */
1911 +
1912 +
1913 +static inline
1914 +int bcm43xx_dma_init(struct bcm43xx_private *bcm)
1915 +{
1916 + return 0;
1917 +}
1918 +static inline
1919 +void bcm43xx_dma_free(struct bcm43xx_private *bcm)
1920 +{
1921 +}
1922 +static inline
1923 +int bcm43xx_dmacontroller_rx_reset(struct bcm43xx_private *bcm,
1924 + u16 dmacontroller_mmio_base)
1925 +{
1926 + return 0;
1927 +}
1928 +static inline
1929 +int bcm43xx_dmacontroller_tx_reset(struct bcm43xx_private *bcm,
1930 + u16 dmacontroller_mmio_base)
1931 +{
1932 + return 0;
1933 +}
1934 +static inline
1935 +void bcm43xx_dma_get_tx_stats(struct bcm43xx_private *bcm,
1936 + struct ieee80211_tx_queue_stats *stats)
1937 +{
1938 +}
1939 +static inline
1940 +int bcm43xx_dma_tx(struct bcm43xx_private *bcm,
1941 + struct sk_buff *skb,
1942 + struct ieee80211_tx_control *ctl)
1943 +{
1944 + return 0;
1945 +}
1946 +static inline
1947 +void bcm43xx_dma_handle_xmitstatus(struct bcm43xx_private *bcm,
1948 + struct bcm43xx_xmitstatus *status)
1949 +{
1950 +}
1951 +static inline
1952 +void bcm43xx_dma_rx(struct bcm43xx_dmaring *ring)
1953 +{
1954 +}
1955 +
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
1961 @@ -0,0 +1,50 @@
1962 +/*
1963 +
1964 + Broadcom BCM43xx wireless driver
1965 +
1966 + ethtool support
1967 +
1968 + Copyright (c) 2006 Jason Lunz <lunz@falooley.org>
1969 +
1970 + Some code in this file is derived from the 8139too.c driver
1971 + Copyright (C) 2002 Jeff Garzik
1972 +
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.
1977 +
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.
1982 +
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.
1987 +
1988 +*/
1989 +
1990 +#include "bcm43xx.h"
1991 +#include "bcm43xx_ethtool.h"
1992 +
1993 +#include <linux/netdevice.h>
1994 +#include <linux/pci.h>
1995 +#include <linux/string.h>
1996 +#include <linux/version.h>
1997 +
1998 +
1999 +static void bcm43xx_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
2000 +{
2001 + struct bcm43xx_private *bcm = bcm43xx_priv(dev);
2002 +
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);
2006 +}
2007 +
2008 +struct ethtool_ops bcm43xx_ethtool_ops = {
2009 + .get_drvinfo = bcm43xx_get_drvinfo,
2010 + .get_link = ethtool_op_get_link,
2011 +};
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
2015 @@ -0,0 +1,8 @@
2016 +#ifndef BCM43xx_ETHTOOL_H_
2017 +#define BCM43xx_ETHTOOL_H_
2018 +
2019 +#include <linux/ethtool.h>
2020 +
2021 +extern struct ethtool_ops bcm43xx_ethtool_ops;
2022 +
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
2027 @@ -0,0 +1,917 @@
2028 +#ifndef BCM43xx_H_
2029 +#define BCM43xx_H_
2030 +
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>
2040 +
2041 +#include <linux/wireless.h>
2042 +#include <net/d80211.h>
2043 +#include <net/d80211_mgmt.h>
2044 +#include <net/d80211_common.h>
2045 +
2046 +#include "bcm43xx_debugfs.h"
2047 +#include "bcm43xx_leds.h"
2048 +#include "bcm43xx_sysfs.h"
2049 +
2050 +
2051 +#define PFX KBUILD_MODNAME ": "
2052 +
2053 +#define BCM43xx_SWITCH_CORE_MAX_RETRIES 50
2054 +#define BCM43xx_IRQWAIT_MAX_RETRIES 50
2055 +
2056 +#define BCM43xx_IO_SIZE 8192
2057 +
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
2064 +
2065 +/* MMIO offsets */
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
2117 +
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
2139 +
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 */
2157 +
2158 +/* GPIO register offset, in both ChipCommon and PCI core. */
2159 +#define BCM43xx_GPIO_CONTROL 0x6c
2160 +
2161 +/* SHM Routing */
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
2167 +
2168 +/* MacFilter offsets. */
2169 +#define BCM43xx_MACFILTER_SELF 0x0000
2170 +#define BCM43xx_MACFILTER_ASSOC 0x0003
2171 +
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
2178 +
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
2183 +
2184 +/* SBTOPCI2 values. */
2185 +#define BCM43xx_SBTOPCI2_PREFETCH 0x4
2186 +#define BCM43xx_SBTOPCI2_BURST 0x8
2187 +
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
2200 +
2201 +/* PowerControl */
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
2207 +
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
2212 +
2213 +#define BCM43xx_PCTL_FORCE_SLOW 0x0800
2214 +#define BCM43xx_PCTL_FORCE_PLL 0x1000
2215 +#define BCM43xx_PCTL_DYN_XTAL 0x2000
2216 +
2217 +/* COREIDs */
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
2236 +
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)
2246 +
2247 +/* Mask to get the Backplane Flag Number from SBTPSFLAG. */
2248 +#define BCM43xx_BACKPLANE_FLAG_NR_MASK 0x3f
2249 +
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
2257 +
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
2263 +
2264 +/* sbtmstatehigh state flags */
2265 +#define BCM43xx_SBTMSTATEHIGH_SERROR 0x1
2266 +#define BCM43xx_SBTMSTATEHIGH_BUSY 0x4
2267 +
2268 +/* sbimstate flags */
2269 +#define BCM43xx_SBIMSTATE_IB_ERROR 0x20000
2270 +#define BCM43xx_SBIMSTATE_TIMEOUT 0x40000
2271 +
2272 +/* PHYVersioning */
2273 +#define BCM43xx_PHYTYPE_A 0x00
2274 +#define BCM43xx_PHYTYPE_B 0x01
2275 +#define BCM43xx_PHYTYPE_G 0x02
2276 +
2277 +/* PHYRegisters */
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
2292 +
2293 +/* RadioRegisters */
2294 +#define BCM43xx_RADIOCTL_ID 0x01
2295 +
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*/
2314 +
2315 +/* MicrocodeFlagsBitfield (addr + lo-word values?)*/
2316 +#define BCM43xx_UCODEFLAGS_OFFSET 0x005E
2317 +
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
2324 +
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)
2337 +
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)
2347 +
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
2354 +
2355 +/* Rate values. */
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
2368 +
2369 +#define BCM43xx_DEFAULT_SHORT_RETRY_LIMIT 7
2370 +#define BCM43xx_DEFAULT_LONG_RETRY_LIMIT 4
2371 +
2372 +/* Max size of a security key */
2373 +#define BCM43xx_SEC_KEYSIZE 16
2374 +/* Security algorithms. */
2375 +enum {
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,
2382 +};
2383 +
2384 +
2385 +#ifdef assert
2386 +# undef assert
2387 +#endif
2388 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2389 +#define assert(expr) \
2390 + do { \
2391 + if (unlikely(!(expr))) { \
2392 + printk(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", \
2393 + #expr, __FILE__, __LINE__, __FUNCTION__); \
2394 + } \
2395 + } while (0)
2396 +#else
2397 +#define assert(expr) do { /* nothing */ } while (0)
2398 +#endif
2399 +
2400 +/* rate limited printk(). */
2401 +#ifdef printkl
2402 +# undef printkl
2403 +#endif
2404 +#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
2405 +/* rate limited printk() for debugging */
2406 +#ifdef dprintkl
2407 +# undef dprintkl
2408 +#endif
2409 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2410 +# define dprintkl printkl
2411 +#else
2412 +# define dprintkl(f, x...) do { /* nothing */ } while (0)
2413 +#endif
2414 +
2415 +/* debugging printk() */
2416 +#ifdef dprintk
2417 +# undef dprintk
2418 +#endif
2419 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2420 +# define dprintk(f, x...) do { printk(f ,##x); } while (0)
2421 +#else
2422 +# define dprintk(f, x...) do { /* nothing */ } while (0)
2423 +#endif
2424 +
2425 +
2426 +struct net_device;
2427 +struct pci_dev;
2428 +struct bcm43xx_dmaring;
2429 +struct bcm43xx_pioqueue;
2430 +
2431 +struct bcm43xx_initval {
2432 + u16 offset;
2433 + u16 size;
2434 + u32 value;
2435 +} __attribute__((__packed__));
2436 +
2437 +/* Values for bcm430x_sprominfo.locale */
2438 +enum {
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,
2451 +};
2452 +
2453 +#define BCM43xx_SPROM_SIZE 64 /* in 16-bit words. */
2454 +struct bcm43xx_sprominfo {
2455 + u16 boardflags2;
2456 + u8 il0macaddr[6];
2457 + u8 et0macaddr[6];
2458 + u8 et1macaddr[6];
2459 + u8 et0phyaddr:5;
2460 + u8 et1phyaddr:5;
2461 + u8 et0mdcport:1;
2462 + u8 et1mdcport:1;
2463 + u8 boardrev;
2464 + u8 locale:4;
2465 + u8 antennas_aphy:2;
2466 + u8 antennas_bgphy:2;
2467 + u16 pa0b0;
2468 + u16 pa0b1;
2469 + u16 pa0b2;
2470 + u8 wl0gpio0;
2471 + u8 wl0gpio1;
2472 + u8 wl0gpio2;
2473 + u8 wl0gpio3;
2474 + u8 maxpower_aphy;
2475 + u8 maxpower_bgphy;
2476 + u16 pa1b0;
2477 + u16 pa1b1;
2478 + u16 pa1b2;
2479 + u8 idle_tssi_tgt_aphy;
2480 + u8 idle_tssi_tgt_bgphy;
2481 + u16 boardflags;
2482 + u16 antennagain_aphy;
2483 + u16 antennagain_bgphy;
2484 +};
2485 +
2486 +/* Value pair to measure the LocalOscillator. */
2487 +struct bcm43xx_lopair {
2488 + s8 low;
2489 + s8 high;
2490 + u8 used:1;
2491 +};
2492 +#define BCM43xx_LO_COUNT (14*4)
2493 +
2494 +struct bcm43xx_phyinfo {
2495 + /* Hardware Data */
2496 + u8 version;
2497 + u8 type;
2498 + u8 rev;
2499 + u16 antenna_diversity;
2500 + u16 savedpctlreg;
2501 + u16 minlowsig[2];
2502 + u16 minlowsigpos[2];
2503 + u8 connected:1,
2504 + calibrated:1,
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.
2509 + */
2510 + struct bcm43xx_lopair *_lo_pairs;
2511 +
2512 + /* TSSI to dBm table in use */
2513 + const s8 *tssi2dbm;
2514 + /* idle TSSI value */
2515 + s8 idle_tssi;
2516 +
2517 + /* Values from bcm43xx_calc_loopback_gain() */
2518 + u16 loopback_gain[2];
2519 +
2520 + /* PHY lock for core.rev < 3
2521 + * This lock is only used by bcm43xx_phy_{un}lock()
2522 + */
2523 + spinlock_t lock;
2524 +};
2525 +
2526 +
2527 +struct bcm43xx_radioinfo {
2528 + u16 manufact;
2529 + u16 version;
2530 + u8 revision;
2531 +
2532 + /* Desired TX power level (in dBm).
2533 + * This is set by the user and adjusted in bcm43xx_phy_xmitpower(). */
2534 + u8 power_level;
2535 + /* TX Power control values. */
2536 + union {
2537 + /* B/G PHY */
2538 + struct {
2539 + u16 baseband_atten;
2540 + u16 radio_atten;
2541 + u16 txctl1;
2542 + u16 txctl2;
2543 + };
2544 + /* A PHY */
2545 + struct {
2546 + u16 txpwr_offset;
2547 + };
2548 + };
2549 +
2550 + /* Current Interference Mitigation mode */
2551 + int interfmode;
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
2558 + */
2559 +#define BCM43xx_INTERFSTACK_SIZE 26
2560 + u32 interfstack[BCM43xx_INTERFSTACK_SIZE];
2561 +
2562 + /* Saved values from the NRSSI Slope calculation */
2563 + s16 nrssi[2];
2564 + s32 nrssislope;
2565 + /* In memory nrssi lookup table. */
2566 + s8 nrssi_lt[64];
2567 +
2568 + /* current channel */
2569 + u8 channel;
2570 + u8 initial_channel;
2571 +
2572 + u16 lofcal;
2573 +
2574 + u16 initval;
2575 +
2576 + u8 enabled:1;
2577 + /* ACI (adjacent channel interference) flags. */
2578 + u8 aci_enable:1,
2579 + aci_wlan_automatic:1,
2580 + aci_hw_rssi:1;
2581 +};
2582 +
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 */
2591 +};
2592 +
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;
2599 +};
2600 +
2601 +#define BCM43xx_MAX_80211_CORES 2
2602 +
2603 +#ifdef CONFIG_BCM947XX
2604 +#define core_offset(bcm) (bcm)->current_core_offset
2605 +#else
2606 +#define core_offset(bcm) 0
2607 +#endif
2608 +
2609 +/* Generic information about a core. */
2610 +struct bcm43xx_coreinfo {
2611 + u8 available:1,
2612 + enabled:1,
2613 + initialized:1;
2614 + /** core_id ID number */
2615 + u16 id;
2616 + /** core_rev revision number */
2617 + u8 rev;
2618 + /** Index number for _switch_core() */
2619 + u8 index;
2620 +};
2621 +
2622 +/* Additional information for each 80211 core. */
2623 +struct bcm43xx_coreinfo_80211 {
2624 + /* PHY device. */
2625 + struct bcm43xx_phyinfo phy;
2626 + /* Radio device. */
2627 + struct bcm43xx_radioinfo radio;
2628 + union {
2629 + /* DMA context. */
2630 + struct bcm43xx_dma dma;
2631 + /* PIO context. */
2632 + struct bcm43xx_pio pio;
2633 + };
2634 +};
2635 +
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;
2641 + u8 nr_samples;
2642 + s8 samples[8][4];
2643 +};
2644 +
2645 +struct bcm43xx_stats {
2646 + u8 link_quality;
2647 + /* Store the last TX/RX times here for updating the leds. */
2648 + unsigned long last_tx;
2649 + unsigned long last_rx;
2650 +};
2651 +
2652 +struct bcm43xx_key {
2653 + u8 enabled:1;
2654 + u8 algorithm;
2655 +};
2656 +
2657 +struct bcm43xx_private {
2658 + struct bcm43xx_sysfs sysfs;
2659 +
2660 + struct ieee80211_hw *ieee;
2661 + struct ieee80211_low_level_stats ieee_stats;
2662 + int iw_mode;
2663 +
2664 + struct net_device *net_dev;
2665 + struct pci_dev *pci_dev;
2666 + unsigned int irq;
2667 +
2668 + void __iomem *mmio_addr;
2669 + unsigned int mmio_len;
2670 +
2671 + /* Do not use the lock directly. Use the bcm43xx_lock* helper
2672 + * functions, to be MMIO-safe. */
2673 + spinlock_t _lock;
2674 +
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. */
2686 +
2687 + struct bcm43xx_stats stats;
2688 +
2689 + /* Bus type we are connected to.
2690 + * This is currently always BCM43xx_BUSTYPE_PCI
2691 + */
2692 + u8 bustype;
2693 +
2694 + u16 board_vendor;
2695 + u16 board_type;
2696 + u16 board_revision;
2697 +
2698 + u16 chip_id;
2699 + u8 chip_rev;
2700 + u8 chip_package;
2701 +
2702 + struct bcm43xx_sprominfo sprom;
2703 +#define BCM43xx_NR_LEDS 4
2704 + struct bcm43xx_led leds[BCM43xx_NR_LEDS];
2705 +
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;
2711 +#endif
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.
2716 + */
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.
2724 + */
2725 + int current_80211_core_idx;
2726 + /* Number of available 80211 cores. */
2727 + int nr_80211_available;
2728 +
2729 + u32 chipcommon_capabilities;
2730 +
2731 + /* Reason code of the last interrupt. */
2732 + u32 irq_reason;
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;
2738 +
2739 + /* Interrupt Service Routine tasklet (bottom-half) */
2740 + struct tasklet_struct isr_tasklet;
2741 +
2742 + /* Periodic tasks */
2743 + struct timer_list periodic_tasks;
2744 + unsigned int periodic_state;
2745 +
2746 + struct work_struct restart_work;
2747 +
2748 + /* Informational stuff. */
2749 + char nick[IW_ESSID_MAX_SIZE + 1];
2750 + u8 bssid[ETH_ALEN];
2751 +
2752 + /* encryption/decryption */
2753 + u16 security_offset;
2754 + struct bcm43xx_key key[54];
2755 + u8 default_key_idx;
2756 +
2757 + /* Firmware. */
2758 + const struct firmware *ucode;
2759 + const struct firmware *pcm;
2760 + const struct firmware *initvals0;
2761 + const struct firmware *initvals1;
2762 +
2763 + /* Cached beacon template while uploading the template. */
2764 + struct sk_buff *cached_beacon;
2765 +
2766 + /* Debugging stuff follows. */
2767 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
2768 + struct bcm43xx_dfsentry *dfsentry;
2769 +#endif
2770 +};
2771 +
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.
2777 + */
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.
2784 + */
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)
2787 +
2788 +static inline
2789 +struct bcm43xx_private * bcm43xx_priv(struct net_device *dev)
2790 +{
2791 + return ieee80211_dev_hw_data(dev);
2792 +}
2793 +
2794 +/* Helper function, which returns a boolean.
2795 + * TRUE, if PIO is used; FALSE, if DMA is used.
2796 + */
2797 +#if defined(CONFIG_BCM43XX_D80211_DMA) && defined(CONFIG_BCM43XX_D80211_PIO)
2798 +static inline
2799 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2800 +{
2801 + return bcm->__using_pio;
2802 +}
2803 +#elif defined(CONFIG_BCM43XX_D80211_DMA)
2804 +static inline
2805 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2806 +{
2807 + return 0;
2808 +}
2809 +#elif defined(CONFIG_BCM43XX_D80211_PIO)
2810 +static inline
2811 +int bcm43xx_using_pio(struct bcm43xx_private *bcm)
2812 +{
2813 + return 1;
2814 +}
2815 +#else
2816 +# error "Using neither DMA nor PIO? Confused..."
2817 +#endif
2818 +
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.
2822 + */
2823 +static inline
2824 +struct bcm43xx_pio * bcm43xx_current_pio(struct bcm43xx_private *bcm)
2825 +{
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);
2830 +}
2831 +static inline
2832 +struct bcm43xx_dma * bcm43xx_current_dma(struct bcm43xx_private *bcm)
2833 +{
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);
2838 +}
2839 +static inline
2840 +struct bcm43xx_phyinfo * bcm43xx_current_phy(struct bcm43xx_private *bcm)
2841 +{
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);
2845 +}
2846 +static inline
2847 +struct bcm43xx_radioinfo * bcm43xx_current_radio(struct bcm43xx_private *bcm)
2848 +{
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);
2852 +}
2853 +
2854 +/* Are we running in init_board() context? */
2855 +static inline
2856 +int bcm43xx_is_initializing(struct bcm43xx_private *bcm)
2857 +{
2858 + if (bcm->initialized)
2859 + return 0;
2860 + if (bcm->shutting_down)
2861 + return 0;
2862 + return 1;
2863 +}
2864 +
2865 +static inline
2866 +struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
2867 + u16 radio_attenuation,
2868 + u16 baseband_attenuation)
2869 +{
2870 + return phy->_lo_pairs + (radio_attenuation + 14 * (baseband_attenuation / 2));
2871 +}
2872 +
2873 +
2874 +static inline
2875 +u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
2876 +{
2877 + return ioread16(bcm->mmio_addr + core_offset(bcm) + offset);
2878 +}
2879 +
2880 +static inline
2881 +void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
2882 +{
2883 + iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset);
2884 +}
2885 +
2886 +static inline
2887 +u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
2888 +{
2889 + return ioread32(bcm->mmio_addr + core_offset(bcm) + offset);
2890 +}
2891 +
2892 +static inline
2893 +void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
2894 +{
2895 + iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset);
2896 +}
2897 +
2898 +static inline
2899 +int bcm43xx_pci_read_config16(struct bcm43xx_private *bcm, int offset, u16 *value)
2900 +{
2901 + return pci_read_config_word(bcm->pci_dev, offset, value);
2902 +}
2903 +
2904 +static inline
2905 +int bcm43xx_pci_read_config32(struct bcm43xx_private *bcm, int offset, u32 *value)
2906 +{
2907 + return pci_read_config_dword(bcm->pci_dev, offset, value);
2908 +}
2909 +
2910 +static inline
2911 +int bcm43xx_pci_write_config16(struct bcm43xx_private *bcm, int offset, u16 value)
2912 +{
2913 + return pci_write_config_word(bcm->pci_dev, offset, value);
2914 +}
2915 +
2916 +static inline
2917 +int bcm43xx_pci_write_config32(struct bcm43xx_private *bcm, int offset, u32 value)
2918 +{
2919 + return pci_write_config_dword(bcm->pci_dev, offset, value);
2920 +}
2921 +
2922 +/** Limit a value between two limits */
2923 +#ifdef limit_value
2924 +# undef limit_value
2925 +#endif
2926 +#define limit_value(value, min, max) \
2927 + ({ \
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; \
2935 + __value; \
2936 + })
2937 +
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]
2943 +
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
2948 @@ -0,0 +1,337 @@
2949 +/*
2950 +
2951 + Broadcom BCM43xx wireless driver
2952 +
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>
2958 +
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.
2963 +
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.
2968 +
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.
2973 +
2974 +*/
2975 +
2976 +#include "bcm43xx.h"
2977 +#include "bcm43xx_ilt.h"
2978 +#include "bcm43xx_phy.h"
2979 +
2980 +
2981 +/**** Initial Internal Lookup Tables ****/
2982 +
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,
3010 + 0x01473FFD,
3011 +};
3012 +
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,
3040 + 0x246DCB87,
3041 +};
3042 +
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,
3108 +};
3109 +
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,
3175 +};
3176 +
3177 +const u16 bcm43xx_ilt_noisea2[BCM43xx_ILT_NOISEA2_SIZE] = {
3178 + 0x0001, 0x0001, 0x0001, 0xFFFE,
3179 + 0xFFFE, 0x3FFF, 0x1000, 0x0393,
3180 +};
3181 +
3182 +const u16 bcm43xx_ilt_noisea3[BCM43xx_ILT_NOISEA3_SIZE] = {
3183 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3184 + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36,
3185 +};
3186 +
3187 +const u16 bcm43xx_ilt_noiseg1[BCM43xx_ILT_NOISEG1_SIZE] = {
3188 + 0x013C, 0x01F5, 0x031A, 0x0631,
3189 + 0x0001, 0x0001, 0x0001, 0x0001,
3190 +};
3191 +
3192 +const u16 bcm43xx_ilt_noiseg2[BCM43xx_ILT_NOISEG2_SIZE] = {
3193 + 0x5484, 0x3C40, 0x0000, 0x0000,
3194 + 0x0000, 0x0000, 0x0000, 0x0000,
3195 +};
3196 +
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,
3205 +};
3206 +
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,
3215 +};
3216 +
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,
3225 +};
3226 +
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 */
3241 + 0x007A,
3242 +};
3243 +
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 */
3258 + 0x00DE,
3259 +};
3260 +
3261 +/**** Helper functions to access the device Internal Lookup Tables ****/
3262 +
3263 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
3264 +{
3265 + if (bcm43xx_current_phy(bcm)->type == BCM43xx_PHYTYPE_A) {
3266 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_CTRL, offset);
3267 + mmiowb();
3268 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, val);
3269 + } else {
3270 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3271 + mmiowb();
3272 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_DATA1, val);
3273 + }
3274 +}
3275 +
3276 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset)
3277 +{
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);
3281 + } else {
3282 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_G_CTRL, offset);
3283 + return bcm43xx_phy_read(bcm, BCM43xx_PHY_ILT_G_DATA1);
3284 + }
3285 +}
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
3289 @@ -0,0 +1,32 @@
3290 +#ifndef BCM43xx_ILT_H_
3291 +#define BCM43xx_ILT_H_
3292 +
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];
3316 +
3317 +
3318 +void bcm43xx_ilt_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
3319 +u16 bcm43xx_ilt_read(struct bcm43xx_private *bcm, u16 offset);
3320 +
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
3325 @@ -0,0 +1,293 @@
3326 +/*
3327 +
3328 + Broadcom BCM43xx wireless driver
3329 +
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>
3335 +
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.
3340 +
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.
3345 +
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.
3350 +
3351 +*/
3352 +
3353 +#include "bcm43xx_leds.h"
3354 +#include "bcm43xx.h"
3355 +
3356 +#include <asm/bitops.h>
3357 +
3358 +
3359 +static void bcm43xx_led_changestate(struct bcm43xx_led *led)
3360 +{
3361 + struct bcm43xx_private *bcm = led->bcm;
3362 + const int index = bcm43xx_led_index(led);
3363 + const u16 mask = (1 << index);
3364 + u16 ledctl;
3365 +
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);
3371 +}
3372 +
3373 +static void bcm43xx_led_blink(unsigned long d)
3374 +{
3375 + struct bcm43xx_led *led = (struct bcm43xx_led *)d;
3376 + struct bcm43xx_private *bcm = led->bcm;
3377 + unsigned long flags;
3378 +
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);
3383 + }
3384 + bcm43xx_unlock_mmio(bcm, flags);
3385 +}
3386 +
3387 +static void bcm43xx_led_blink_start(struct bcm43xx_led *led,
3388 + unsigned long interval)
3389 +{
3390 + if (led->blink_interval)
3391 + return;
3392 + led->blink_interval = interval;
3393 + bcm43xx_led_changestate(led);
3394 + led->blink_timer.expires = jiffies + interval;
3395 + add_timer(&led->blink_timer);
3396 +}
3397 +
3398 +static void bcm43xx_led_blink_stop(struct bcm43xx_led *led, int sync)
3399 +{
3400 + struct bcm43xx_private *bcm = led->bcm;
3401 + const int index = bcm43xx_led_index(led);
3402 + u16 ledctl;
3403 +
3404 + if (!led->blink_interval)
3405 + return;
3406 + if (unlikely(sync))
3407 + del_timer_sync(&led->blink_timer);
3408 + else
3409 + del_timer(&led->blink_timer);
3410 + led->blink_interval = 0;
3411 +
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);
3417 + else
3418 + ledctl &= ~(1 << index);
3419 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3420 +}
3421 +
3422 +static void bcm43xx_led_init_hardcoded(struct bcm43xx_private *bcm,
3423 + struct bcm43xx_led *led,
3424 + int led_index)
3425 +{
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.
3431 + */
3432 +
3433 + switch (led_index) {
3434 + case 0:
3435 + led->behaviour = BCM43xx_LED_ACTIVITY;
3436 + if (bcm->board_vendor == PCI_VENDOR_ID_COMPAQ)
3437 + led->behaviour = BCM43xx_LED_RADIO_ALL;
3438 + break;
3439 + case 1:
3440 + led->behaviour = BCM43xx_LED_RADIO_B;
3441 + if (bcm->board_vendor == PCI_VENDOR_ID_ASUSTEK)
3442 + led->behaviour = BCM43xx_LED_ASSOC;
3443 + break;
3444 + case 2:
3445 + led->behaviour = BCM43xx_LED_RADIO_A;
3446 + break;
3447 + case 3:
3448 + led->behaviour = BCM43xx_LED_OFF;
3449 + break;
3450 + default:
3451 + assert(0);
3452 + }
3453 +}
3454 +
3455 +int bcm43xx_leds_init(struct bcm43xx_private *bcm)
3456 +{
3457 + struct bcm43xx_led *led;
3458 + u8 sprom[4];
3459 + int i;
3460 +
3461 + sprom[0] = bcm->sprom.wl0gpio0;
3462 + sprom[1] = bcm->sprom.wl0gpio1;
3463 + sprom[2] = bcm->sprom.wl0gpio2;
3464 + sprom[3] = bcm->sprom.wl0gpio3;
3465 +
3466 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3467 + led = &(bcm->leds[i]);
3468 + led->bcm = bcm;
3469 + setup_timer(&led->blink_timer,
3470 + bcm43xx_led_blink,
3471 + (unsigned long)led);
3472 +
3473 + if (sprom[i] == 0xFF) {
3474 + bcm43xx_led_init_hardcoded(bcm, led, i);
3475 + } else {
3476 + led->behaviour = sprom[i] & BCM43xx_LED_BEHAVIOUR;
3477 + led->activelow = !!(sprom[i] & BCM43xx_LED_ACTIVELOW);
3478 + }
3479 + }
3480 +
3481 + return 0;
3482 +}
3483 +
3484 +void bcm43xx_leds_exit(struct bcm43xx_private *bcm)
3485 +{
3486 + struct bcm43xx_led *led;
3487 + int i;
3488 +
3489 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3490 + led = &(bcm->leds[i]);
3491 + bcm43xx_led_blink_stop(led, 1);
3492 + }
3493 + bcm43xx_leds_switch_all(bcm, 0);
3494 +}
3495 +
3496 +void bcm43xx_leds_update(struct bcm43xx_private *bcm, int activity)
3497 +{
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;
3502 + int i, turn_on;
3503 + unsigned long interval = 0;
3504 + u16 ledctl;
3505 +
3506 + ledctl = bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_CONTROL);
3507 + for (i = 0; i < BCM43xx_NR_LEDS; i++) {
3508 + led = &(bcm->leds[i]);
3509 +
3510 + turn_on = 0;
3511 + switch (led->behaviour) {
3512 + case BCM43xx_LED_INACTIVE:
3513 + continue;
3514 + case BCM43xx_LED_OFF:
3515 + break;
3516 + case BCM43xx_LED_ON:
3517 + turn_on = 1;
3518 + break;
3519 + case BCM43xx_LED_ACTIVITY:
3520 + turn_on = activity;
3521 + break;
3522 + case BCM43xx_LED_RADIO_ALL:
3523 + turn_on = radio->enabled;
3524 + break;
3525 + case BCM43xx_LED_RADIO_A:
3526 + turn_on = (radio->enabled && phy->type == BCM43xx_PHYTYPE_A);
3527 + break;
3528 + case BCM43xx_LED_RADIO_B:
3529 + turn_on = (radio->enabled &&
3530 + (phy->type == BCM43xx_PHYTYPE_B ||
3531 + phy->type == BCM43xx_PHYTYPE_G));
3532 + break;
3533 + case BCM43xx_LED_MODE_BG:
3534 + if (phy->type == BCM43xx_PHYTYPE_G &&
3535 + 1/*FIXME: using G rates.*/)
3536 + turn_on = 1;
3537 + break;
3538 + case BCM43xx_LED_TRANSFER:
3539 + if (transferring)
3540 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3541 + else
3542 + bcm43xx_led_blink_stop(led, 0);
3543 + continue;
3544 + case BCM43xx_LED_APTRANSFER:
3545 + if (bcm->iw_mode == IW_MODE_MASTER) {
3546 + if (transferring) {
3547 + interval = BCM43xx_LEDBLINK_FAST;
3548 + turn_on = 1;
3549 + }
3550 + } else {
3551 + turn_on = 1;
3552 + if (0/*TODO: not assoc*/)
3553 + interval = BCM43xx_LEDBLINK_SLOW;
3554 + else if (transferring)
3555 + interval = BCM43xx_LEDBLINK_FAST;
3556 + else
3557 + turn_on = 0;
3558 + }
3559 + if (turn_on)
3560 + bcm43xx_led_blink_start(led, interval);
3561 + else
3562 + bcm43xx_led_blink_stop(led, 0);
3563 + continue;
3564 + case BCM43xx_LED_WEIRD:
3565 + //TODO
3566 + break;
3567 + case BCM43xx_LED_ASSOC:
3568 + if (1/*bcm->softmac->associated*/)
3569 + turn_on = 1;
3570 + break;
3571 +#ifdef CONFIG_BCM43XX_DEBUG
3572 + case BCM43xx_LED_TEST_BLINKSLOW:
3573 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_SLOW);
3574 + continue;
3575 + case BCM43xx_LED_TEST_BLINKMEDIUM:
3576 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_MEDIUM);
3577 + continue;
3578 + case BCM43xx_LED_TEST_BLINKFAST:
3579 + bcm43xx_led_blink_start(led, BCM43xx_LEDBLINK_FAST);
3580 + continue;
3581 +#endif /* CONFIG_BCM43XX_DEBUG */
3582 + default:
3583 + assert(0);
3584 + };
3585 +
3586 + if (led->activelow)
3587 + turn_on = !turn_on;
3588 + if (turn_on)
3589 + ledctl |= (1 << i);
3590 + else
3591 + ledctl &= ~(1 << i);
3592 + }
3593 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3594 +}
3595 +
3596 +void bcm43xx_leds_switch_all(struct bcm43xx_private *bcm, int on)
3597 +{
3598 + struct bcm43xx_led *led;
3599 + u16 ledctl;
3600 + int i;
3601 + int bit_on;
3602 +
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)
3607 + continue;
3608 + if (on)
3609 + bit_on = led->activelow ? 0 : 1;
3610 + else
3611 + bit_on = led->activelow ? 1 : 0;
3612 + if (bit_on)
3613 + ledctl |= (1 << i);
3614 + else
3615 + ledctl &= ~(1 << i);
3616 + }
3617 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_CONTROL, ledctl);
3618 +}
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
3622 @@ -0,0 +1,56 @@
3623 +#ifndef BCM43xx_LEDS_H_
3624 +#define BCM43xx_LEDS_H_
3625 +
3626 +#include <linux/types.h>
3627 +#include <linux/timer.h>
3628 +
3629 +
3630 +struct bcm43xx_led {
3631 + u8 behaviour:7;
3632 + u8 activelow:1;
3633 +
3634 + struct bcm43xx_private *bcm;
3635 + struct timer_list blink_timer;
3636 + unsigned long blink_interval;
3637 +};
3638 +#define bcm43xx_led_index(led) ((int)((led) - (led)->bcm->leds))
3639 +
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)
3644 +
3645 +#define BCM43xx_LED_XFER_THRES (HZ / 100)
3646 +
3647 +#define BCM43xx_LED_BEHAVIOUR 0x7F
3648 +#define BCM43xx_LED_ACTIVELOW 0x80
3649 +enum { /* LED behaviour values */
3650 + BCM43xx_LED_OFF,
3651 + BCM43xx_LED_ON,
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,
3662 +
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.
3667 + */
3668 + BCM43xx_LED_TEST_BLINKSLOW,
3669 + BCM43xx_LED_TEST_BLINKMEDIUM,
3670 + BCM43xx_LED_TEST_BLINKFAST,
3671 +};
3672 +
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);
3677 +
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
3682 @@ -0,0 +1,4491 @@
3683 +/*
3684 +
3685 + Broadcom BCM43xx wireless driver
3686 +
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>
3692 +
3693 + Some parts of the code in this file are derived from the ipw2200
3694 + driver Copyright(c) 2003 - 2004 Intel Corporation.
3695 +
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.
3700 +
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.
3705 +
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.
3710 +
3711 +*/
3712 +
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>
3725 +
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"
3737 +
3738 +
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");
3744 +
3745 +#ifdef CONFIG_BCM947XX
3746 +extern char *nvram_get(char *name);
3747 +#endif
3748 +
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
3757 +#endif
3758 +
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");
3762 +
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)");
3766 +
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)");
3770 +
3771 +static int modparam_noleds;
3772 +module_param_named(noleds, modparam_noleds, int, 0444);
3773 +MODULE_PARM_DESC(noleds, "Turn off all LED activity");
3774 +
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.");
3779 +#else
3780 +# define modparam_fwpostfix ""
3781 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
3782 +
3783 +
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.
3787 + */
3788 +//#define DEBUG_SINGLE_DEVICE_ONLY "0001:11:00.0"
3789 +
3790 +/* If you want to enable printing of each MMIO access, enable this. */
3791 +//#define DEBUG_ENABLE_MMIO_PRINT
3792 +
3793 +/* If you want to enable printing of MMIO access within
3794 + * ucode/pcm upload, initvals write, enable this.
3795 + */
3796 +//#define DEBUG_ENABLE_UCODE_MMIO_PRINT
3797 +
3798 +/* If you want to enable printing of PCI Config Space access, enable this */
3799 +//#define DEBUG_ENABLE_PCILOG
3800 +
3801 +
3802 +/* Detailed list maintained at:
3803 + * http://openfacts.berlios.de/index-en.phtml?title=Bcm43xxDevices
3804 + */
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 },
3823 +#endif
3824 + { 0 },
3825 +};
3826 +MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
3827 +
3828 +
3829 +static void bcm43xx_ram_write(struct bcm43xx_private *bcm, u16 offset, u32 val)
3830 +{
3831 + u32 status;
3832 +
3833 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3834 + if (!(status & BCM43xx_SBF_XFER_REG_BYTESWAP))
3835 + val = swab32(val);
3836 +
3837 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_CONTROL, offset);
3838 + mmiowb();
3839 + bcm43xx_write32(bcm, BCM43xx_MMIO_RAM_DATA, val);
3840 +}
3841 +
3842 +static inline
3843 +void bcm43xx_shm_control_word(struct bcm43xx_private *bcm,
3844 + u16 routing, u16 offset)
3845 +{
3846 + u32 control;
3847 +
3848 + /* "offset" is the WORD offset. */
3849 +
3850 + control = routing;
3851 + control <<= 16;
3852 + control |= offset;
3853 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_CONTROL, control);
3854 +}
3855 +
3856 +u32 bcm43xx_shm_read32(struct bcm43xx_private *bcm,
3857 + u16 routing, u16 offset)
3858 +{
3859 + u32 ret;
3860 +
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);
3866 + ret <<= 16;
3867 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3868 + ret |= bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3869 +
3870 + return ret;
3871 + }
3872 + offset >>= 2;
3873 + }
3874 + bcm43xx_shm_control_word(bcm, routing, offset);
3875 + ret = bcm43xx_read32(bcm, BCM43xx_MMIO_SHM_DATA);
3876 +
3877 + return ret;
3878 +}
3879 +
3880 +u16 bcm43xx_shm_read16(struct bcm43xx_private *bcm,
3881 + u16 routing, u16 offset)
3882 +{
3883 + u16 ret;
3884 +
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);
3890 +
3891 + return ret;
3892 + }
3893 + offset >>= 2;
3894 + }
3895 + bcm43xx_shm_control_word(bcm, routing, offset);
3896 + ret = bcm43xx_read16(bcm, BCM43xx_MMIO_SHM_DATA);
3897 +
3898 + return ret;
3899 +}
3900 +
3901 +void bcm43xx_shm_write32(struct bcm43xx_private *bcm,
3902 + u16 routing, u16 offset,
3903 + u32 value)
3904 +{
3905 + if (routing == BCM43xx_SHM_SHARED) {
3906 + if (offset & 0x0003) {
3907 + /* Unaligned access */
3908 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3909 + mmiowb();
3910 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3911 + (value >> 16) & 0xffff);
3912 + mmiowb();
3913 + bcm43xx_shm_control_word(bcm, routing, (offset >> 2) + 1);
3914 + mmiowb();
3915 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA,
3916 + value & 0xffff);
3917 + return;
3918 + }
3919 + offset >>= 2;
3920 + }
3921 + bcm43xx_shm_control_word(bcm, routing, offset);
3922 + mmiowb();
3923 + bcm43xx_write32(bcm, BCM43xx_MMIO_SHM_DATA, value);
3924 +}
3925 +
3926 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
3927 + u16 routing, u16 offset,
3928 + u16 value)
3929 +{
3930 + if (routing == BCM43xx_SHM_SHARED) {
3931 + if (offset & 0x0003) {
3932 + /* Unaligned access */
3933 + bcm43xx_shm_control_word(bcm, routing, offset >> 2);
3934 + mmiowb();
3935 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA_UNALIGNED,
3936 + value);
3937 + return;
3938 + }
3939 + offset >>= 2;
3940 + }
3941 + bcm43xx_shm_control_word(bcm, routing, offset);
3942 + mmiowb();
3943 + bcm43xx_write16(bcm, BCM43xx_MMIO_SHM_DATA, value);
3944 +}
3945 +
3946 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf)
3947 +{
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).
3953 + */
3954 + if (bcm->current_core->rev >= 3) {
3955 + u32 low, high, high2;
3956 +
3957 + do {
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));
3962 +
3963 + *tsf = high;
3964 + *tsf <<= 32;
3965 + *tsf |= low;
3966 + } else {
3967 + u64 tmp;
3968 + u16 v0, v1, v2, v3;
3969 + u16 test1, test2, test3;
3970 +
3971 + do {
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);
3976 +
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);
3981 +
3982 + *tsf = v3;
3983 + *tsf <<= 48;
3984 + tmp = v2;
3985 + tmp <<= 32;
3986 + *tsf |= tmp;
3987 + tmp = v1;
3988 + tmp <<= 16;
3989 + *tsf |= tmp;
3990 + *tsf |= v0;
3991 + }
3992 +}
3993 +
3994 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf)
3995 +{
3996 + u32 status;
3997 +
3998 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
3999 + status |= BCM43xx_SBF_TIME_UPDATE;
4000 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
4001 + mmiowb();
4002 +
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.
4006 + */
4007 + if (bcm->current_core->rev >= 3) {
4008 + u32 lo = (tsf & 0x00000000FFFFFFFFULL);
4009 + u32 hi = (tsf & 0xFFFFFFFF00000000ULL) >> 32;
4010 +
4011 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, 0);
4012 + mmiowb();
4013 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_HIGH, hi);
4014 + mmiowb();
4015 + bcm43xx_write32(bcm, BCM43xx_MMIO_REV3PLUS_TSF_LOW, lo);
4016 + } else {
4017 + u16 v0 = (tsf & 0x000000000000FFFFULL);
4018 + u16 v1 = (tsf & 0x00000000FFFF0000ULL) >> 16;
4019 + u16 v2 = (tsf & 0x0000FFFF00000000ULL) >> 32;
4020 + u16 v3 = (tsf & 0xFFFF000000000000ULL) >> 48;
4021 +
4022 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, 0);
4023 + mmiowb();
4024 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_3, v3);
4025 + mmiowb();
4026 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_2, v2);
4027 + mmiowb();
4028 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_1, v1);
4029 + mmiowb();
4030 + bcm43xx_write16(bcm, BCM43xx_MMIO_TSF_0, v0);
4031 + }
4032 +
4033 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
4034 + status &= ~BCM43xx_SBF_TIME_UPDATE;
4035 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
4036 +}
4037 +
4038 +static
4039 +void bcm43xx_macfilter_set(struct bcm43xx_private *bcm,
4040 + u16 offset,
4041 + const u8 *mac)
4042 +{
4043 + u16 data;
4044 +
4045 + offset |= 0x0020;
4046 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_CONTROL, offset);
4047 +
4048 + data = mac[0];
4049 + data |= mac[1] << 8;
4050 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4051 + data = mac[2];
4052 + data |= mac[3] << 8;
4053 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4054 + data = mac[4];
4055 + data |= mac[5] << 8;
4056 + bcm43xx_write16(bcm, BCM43xx_MMIO_MACFILTER_DATA, data);
4057 +}
4058 +
4059 +static void bcm43xx_macfilter_clear(struct bcm43xx_private *bcm,
4060 + u16 offset)
4061 +{
4062 + const u8 zero_addr[ETH_ALEN] = { 0 };
4063 +
4064 + bcm43xx_macfilter_set(bcm, offset, zero_addr);
4065 +}
4066 +
4067 +static void bcm43xx_write_mac_bssid_templates(struct bcm43xx_private *bcm)
4068 +{
4069 + const u8 *mac = (const u8 *)(bcm->net_dev->dev_addr);
4070 + const u8 *bssid = bcm->bssid;
4071 + u8 mac_bssid[ETH_ALEN * 2];
4072 + int i;
4073 +
4074 + memcpy(mac_bssid, mac, ETH_ALEN);
4075 + memcpy(mac_bssid + ETH_ALEN, bssid, ETH_ALEN);
4076 +
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)));
4084 +}
4085 +
4086 +static void bcm43xx_set_slot_time(struct bcm43xx_private *bcm, u16 slot_time)
4087 +{
4088 + /* slot_time is in usec. */
4089 + if (bcm43xx_current_phy(bcm)->type != BCM43xx_PHYTYPE_G)
4090 + return;
4091 + bcm43xx_write16(bcm, 0x684, 510 + slot_time);
4092 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0010, slot_time);
4093 +}
4094 +
4095 +static void bcm43xx_short_slot_timing_enable(struct bcm43xx_private *bcm)
4096 +{
4097 + bcm43xx_set_slot_time(bcm, 9);
4098 + bcm->short_slot = 1;
4099 +}
4100 +
4101 +static void bcm43xx_short_slot_timing_disable(struct bcm43xx_private *bcm)
4102 +{
4103 + bcm43xx_set_slot_time(bcm, 20);
4104 + bcm->short_slot = 0;
4105 +}
4106 +
4107 +/* FIXME: To get the MAC-filter working, we need to implement the
4108 + * following functions (and rename them :)
4109 + */
4110 +#if 0
4111 +static void bcm43xx_disassociate(struct bcm43xx_private *bcm)
4112 +{
4113 + bcm43xx_mac_suspend(bcm);
4114 + bcm43xx_macfilter_clear(bcm, BCM43xx_MACFILTER_ASSOC);
4115 +
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);
4122 +
4123 + if (bcm->current_core->rev < 3) {
4124 + bcm43xx_write16(bcm, 0x0610, 0x8000);
4125 + bcm43xx_write16(bcm, 0x060E, 0x0000);
4126 + } else
4127 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
4128 +
4129 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
4130 +
4131 +#if 0
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);
4135 +#endif
4136 +
4137 + bcm43xx_mac_enable(bcm);
4138 +}
4139 +
4140 +static void bcm43xx_associate(struct bcm43xx_private *bcm,
4141 + const u8 *mac)
4142 +{
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);
4147 +}
4148 +#endif
4149 +
4150 +/* Enable a Generic IRQ. "mask" is the mask of which IRQs to enable.
4151 + * Returns the _previously_ enabled IRQ mask.
4152 + */
4153 +static inline u32 bcm43xx_interrupt_enable(struct bcm43xx_private *bcm, u32 mask)
4154 +{
4155 + u32 old_mask;
4156 +
4157 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4158 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask | mask);
4159 +
4160 + return old_mask;
4161 +}
4162 +
4163 +/* Disable a Generic IRQ. "mask" is the mask of which IRQs to disable.
4164 + * Returns the _previously_ enabled IRQ mask.
4165 + */
4166 +static inline u32 bcm43xx_interrupt_disable(struct bcm43xx_private *bcm, u32 mask)
4167 +{
4168 + u32 old_mask;
4169 +
4170 + old_mask = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
4171 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK, old_mask & ~mask);
4172 +
4173 + return old_mask;
4174 +}
4175 +
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)
4178 +{
4179 + u32 old;
4180 + unsigned long flags;
4181 +
4182 + bcm43xx_lock_mmio(bcm, flags);
4183 + if (bcm43xx_is_initializing(bcm) || bcm->shutting_down) {
4184 + bcm43xx_unlock_mmio(bcm, flags);
4185 + return -EBUSY;
4186 + }
4187 + old = bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
4188 + tasklet_disable(&bcm->isr_tasklet);
4189 + bcm43xx_unlock_mmio(bcm, flags);
4190 + if (oldstate)
4191 + *oldstate = old;
4192 +
4193 + return 0;
4194 +}
4195 +
4196 +static int bcm43xx_read_radioinfo(struct bcm43xx_private *bcm)
4197 +{
4198 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4199 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4200 + u32 radio_id;
4201 + u16 manufact;
4202 + u16 version;
4203 + u8 revision;
4204 + s8 i;
4205 +
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;
4211 + else
4212 + radio_id = 0x5205017F;
4213 + } else {
4214 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4215 + radio_id = bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_HIGH);
4216 + radio_id <<= 16;
4217 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, BCM43xx_RADIOCTL_ID);
4218 + radio_id |= bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
4219 + }
4220 +
4221 + manufact = (radio_id & 0x00000FFF);
4222 + version = (radio_id & 0x0FFFF000) >> 12;
4223 + revision = (radio_id & 0xF0000000) >> 28;
4224 +
4225 + dprintk(KERN_INFO PFX "Detected Radio: ID: %x (Manuf: %x Ver: %x Rev: %x)\n",
4226 + radio_id, manufact, version, revision);
4227 +
4228 + switch (phy->type) {
4229 + case BCM43xx_PHYTYPE_A:
4230 + if ((version != 0x2060) || (revision != 1) || (manufact != 0x17f))
4231 + goto err_unsupported_radio;
4232 + break;
4233 + case BCM43xx_PHYTYPE_B:
4234 + if ((version & 0xFFF0) != 0x2050)
4235 + goto err_unsupported_radio;
4236 + break;
4237 + case BCM43xx_PHYTYPE_G:
4238 + if (version != 0x2050)
4239 + goto err_unsupported_radio;
4240 + break;
4241 + }
4242 +
4243 + radio->manufact = manufact;
4244 + radio->version = version;
4245 + radio->revision = revision;
4246 +
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;
4253 +
4254 + /* Initialize the in-memory nrssi Lookup Table. */
4255 + for (i = 0; i < 64; i++)
4256 + radio->nrssi_lt[i] = i;
4257 +
4258 + return 0;
4259 +
4260 +err_unsupported_radio:
4261 + printk(KERN_ERR PFX "Unsupported Radio connected to the PHY!\n");
4262 + return -ENODEV;
4263 +}
4264 +
4265 +static inline u8 bcm43xx_crc8(u8 crc, u8 data)
4266 +{
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,
4300 + };
4301 + return t[crc ^ data];
4302 +}
4303 +
4304 +static u8 bcm43xx_sprom_crc(const u16 *sprom)
4305 +{
4306 + int word;
4307 + u8 crc = 0xFF;
4308 +
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);
4312 + }
4313 + crc = bcm43xx_crc8(crc, sprom[BCM43xx_SPROM_VERSION] & 0x00FF);
4314 + crc ^= 0xFF;
4315 +
4316 + return crc;
4317 +}
4318 +
4319 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom)
4320 +{
4321 + int i;
4322 + u8 crc, expected_crc;
4323 +
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);
4333 + return -EINVAL;
4334 + }
4335 +
4336 + return 0;
4337 +}
4338 +
4339 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom)
4340 +{
4341 + int i, err;
4342 + u8 crc, expected_crc;
4343 + u32 spromctl;
4344 +
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");
4350 + return -EINVAL;
4351 + }
4352 +
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);
4355 + if (err)
4356 + goto err_ctlreg;
4357 + spromctl |= 0x10; /* SPROM WRITE enable. */
4358 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4359 + if (err)
4360 + goto err_ctlreg;
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...
4363 + */
4364 + printk(KERN_INFO PFX "[ 0%%");
4365 + mdelay(500);
4366 + for (i = 0; i < BCM43xx_SPROM_SIZE; i++) {
4367 + if (i == 16)
4368 + printk("25%%");
4369 + else if (i == 32)
4370 + printk("50%%");
4371 + else if (i == 48)
4372 + printk("75%%");
4373 + else if (i % 2)
4374 + printk(".");
4375 + bcm43xx_write16(bcm, BCM43xx_SPROM_BASE + (i * 2), sprom[i]);
4376 + mmiowb();
4377 + mdelay(20);
4378 + }
4379 + spromctl &= ~0x10; /* SPROM WRITE enable. */
4380 + bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_SPROMCTL, spromctl);
4381 + if (err)
4382 + goto err_ctlreg;
4383 + mdelay(500);
4384 + printk("100%% ]\n");
4385 + printk(KERN_INFO PFX "SPROM written.\n");
4386 + bcm43xx_controller_restart(bcm, "SPROM update");
4387 +
4388 + return 0;
4389 +err_ctlreg:
4390 + printk(KERN_ERR PFX "Could not access SPROM control register.\n");
4391 + return -ENODEV;
4392 +}
4393 +
4394 +static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
4395 +{
4396 + u16 value;
4397 + u16 *sprom;
4398 +#ifdef CONFIG_BCM947XX
4399 + char *c;
4400 +#endif
4401 +
4402 + sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
4403 + GFP_KERNEL);
4404 + if (!sprom) {
4405 + printk(KERN_ERR PFX "sprom_extract OOM\n");
4406 + return -ENOMEM;
4407 + }
4408 +#ifdef CONFIG_BCM947XX
4409 + sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
4410 + sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
4411 +
4412 + if ((c = nvram_get("il0macaddr")) != NULL)
4413 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
4414 +
4415 + if ((c = nvram_get("et1macaddr")) != NULL)
4416 + e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
4417 +
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"));
4421 +
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"));
4425 +
4426 + sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
4427 +#else
4428 + bcm43xx_sprom_read(bcm, sprom);
4429 +#endif
4430 +
4431 + /* boardflags2 */
4432 + value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
4433 + bcm->sprom.boardflags2 = value;
4434 +
4435 + /* il0macaddr */
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);
4442 +
4443 + /* et0macaddr */
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);
4450 +
4451 + /* et1macaddr */
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);
4458 +
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;
4465 +
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;
4472 +
4473 + /* pa0b* */
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;
4480 +
4481 + /* wl0gpio* */
4482 + value = sprom[BCM43xx_SPROM_WL0GPIO0];
4483 + if (value == 0x0000)
4484 + value = 0xFFFF;
4485 + bcm->sprom.wl0gpio0 = value & 0x00FF;
4486 + bcm->sprom.wl0gpio1 = (value & 0xFF00) >> 8;
4487 + value = sprom[BCM43xx_SPROM_WL0GPIO2];
4488 + if (value == 0x0000)
4489 + value = 0xFFFF;
4490 + bcm->sprom.wl0gpio2 = value & 0x00FF;
4491 + bcm->sprom.wl0gpio3 = (value & 0xFF00) >> 8;
4492 +
4493 + /* maxpower */
4494 + value = sprom[BCM43xx_SPROM_MAXPWR];
4495 + bcm->sprom.maxpower_aphy = (value & 0xFF00) >> 8;
4496 + bcm->sprom.maxpower_bgphy = value & 0x00FF;
4497 +
4498 + /* pa1b* */
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;
4505 +
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;
4510 +
4511 + /* boardflags */
4512 + value = sprom[BCM43xx_SPROM_BOARDFLAGS];
4513 + if (value == 0xFFFF)
4514 + value = 0x0000;
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;
4525 +
4526 + /* antenna gain */
4527 + value = sprom[BCM43xx_SPROM_ANTENNA_GAIN];
4528 + if (value == 0x0000 || value == 0xFFFF)
4529 + value = 0x0202;
4530 + /* convert values to Q5.2 */
4531 + bcm->sprom.antennagain_aphy = ((value & 0xFF00) >> 8) * 4;
4532 + bcm->sprom.antennagain_bgphy = (value & 0x00FF) * 4;
4533 +
4534 + kfree(sprom);
4535 +
4536 + return 0;
4537 +}
4538 +
4539 +/* DummyTransmission function, as documented on
4540 + * http://bcm-specs.sipsolutions.net/DummyTransmission
4541 + */
4542 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm)
4543 +{
4544 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
4545 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
4546 + unsigned int i, max_loop;
4547 + u16 value = 0;
4548 + u32 buffer[5] = {
4549 + 0x00000000,
4550 + 0x0000D400,
4551 + 0x00000000,
4552 + 0x00000001,
4553 + 0x00000000,
4554 + };
4555 +
4556 + switch (phy->type) {
4557 + case BCM43xx_PHYTYPE_A:
4558 + max_loop = 0x1E;
4559 + buffer[0] = 0xCC010200;
4560 + break;
4561 + case BCM43xx_PHYTYPE_B:
4562 + case BCM43xx_PHYTYPE_G:
4563 + max_loop = 0xFA;
4564 + buffer[0] = 0x6E840B00;
4565 + break;
4566 + default:
4567 + assert(0);
4568 + return;
4569 + }
4570 +
4571 + for (i = 0; i < 5; i++)
4572 + bcm43xx_ram_write(bcm, i * 4, buffer[i]);
4573 +
4574 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* dummy read */
4575 +
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);
4586 +
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)
4592 + break;
4593 + udelay(10);
4594 + }
4595 + for (i = 0x00; i < 0x0A; i++) {
4596 + value = bcm43xx_read16(bcm, 0x050E);
4597 + if (value & 0x0400)
4598 + break;
4599 + udelay(10);
4600 + }
4601 + for (i = 0x00; i < 0x0A; i++) {
4602 + value = bcm43xx_read16(bcm, 0x0690);
4603 + if (!(value & 0x0100))
4604 + break;
4605 + udelay(10);
4606 + }
4607 + if (radio->version == 0x2050 && radio->revision <= 0x5)
4608 + bcm43xx_radio_write16(bcm, 0x0051, 0x0037);
4609 +}
4610 +
4611 +static void key_write(struct bcm43xx_private *bcm,
4612 + u8 index, u8 algorithm, const u16 *key)
4613 +{
4614 + unsigned int i, basic_wep = 0;
4615 + u32 offset;
4616 + u16 value;
4617 +
4618 + /* Write associated key information */
4619 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x100 + (index * 2),
4620 + ((index << 4) | (algorithm & 0x0F)));
4621 +
4622 + /* The first 4 WEP keys need extra love */
4623 + if (((algorithm == BCM43xx_SEC_ALGO_WEP) ||
4624 + (algorithm == BCM43xx_SEC_ALGO_WEP104)) && (index < 4))
4625 + basic_wep = 1;
4626 +
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);
4633 +
4634 + if (!basic_wep)
4635 + continue;
4636 +
4637 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED,
4638 + offset + (i * 2) + 4 * BCM43xx_SEC_KEYSIZE,
4639 + value);
4640 + }
4641 +}
4642 +
4643 +static void keymac_write(struct bcm43xx_private *bcm,
4644 + u8 index, const u32 *addr)
4645 +{
4646 + /* for keys 0-3 there is no associated mac address */
4647 + if (index < 4)
4648 + return;
4649 +
4650 + index -= 4;
4651 + if (bcm->current_core->rev >= 5) {
4652 + bcm43xx_shm_write32(bcm,
4653 + BCM43xx_SHM_HWMAC,
4654 + index * 2,
4655 + cpu_to_be32(*addr));
4656 + bcm43xx_shm_write16(bcm,
4657 + BCM43xx_SHM_HWMAC,
4658 + (index * 2) + 1,
4659 + cpu_to_be16(*((u16 *)(addr + 1))));
4660 + } else {
4661 + if (index < 8) {
4662 + TODO(); /* Put them in the macaddress filter */
4663 + } else {
4664 + TODO();
4665 + /* Put them BCM43xx_SHM_SHARED, stating index 0x0120.
4666 + Keep in mind to update the count of keymacs in 0x003E as well! */
4667 + }
4668 + }
4669 +}
4670 +
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)
4675 +{
4676 + u8 key[BCM43xx_SEC_KEYSIZE] = { 0 };
4677 +
4678 + if (index >= ARRAY_SIZE(bcm->key))
4679 + return -EINVAL;
4680 + if (key_len > ARRAY_SIZE(key))
4681 + return -EINVAL;
4682 + if (algorithm < 1 || algorithm > 5)
4683 + return -EINVAL;
4684 +
4685 + memcpy(key, _key, key_len);
4686 + key_write(bcm, index, algorithm, (const u16 *)key);
4687 + keymac_write(bcm, index, (const u32 *)mac_addr);
4688 +
4689 + bcm->key[index].algorithm = algorithm;
4690 +
4691 + return 0;
4692 +}
4693 +
4694 +static void bcm43xx_clear_keys(struct bcm43xx_private *bcm)
4695 +{
4696 + static const u32 zero_mac[2] = { 0 };
4697 + unsigned int i,j, nr_keys = 54;
4698 + u16 offset;
4699 +
4700 + if (bcm->current_core->rev < 5)
4701 + nr_keys = 16;
4702 + assert(nr_keys <= ARRAY_SIZE(bcm->key));
4703 +
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,
4713 + offset, 0x0000);
4714 + }
4715 + }
4716 + dprintk(KERN_INFO PFX "Keys cleared\n");
4717 +}
4718 +
4719 +/* Lowlevel core-switch function. This is only to be used in
4720 + * bcm43xx_switch_core() and bcm43xx_probe_cores()
4721 + */
4722 +static int _switch_core(struct bcm43xx_private *bcm, int core)
4723 +{
4724 + int err;
4725 + int attempts = 0;
4726 + u32 current_core;
4727 +
4728 + assert(core >= 0);
4729 + while (1) {
4730 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4731 + (core * 0x1000) + 0x18000000);
4732 + if (unlikely(err))
4733 + goto error;
4734 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ACTIVE_CORE,
4735 + &current_core);
4736 + if (unlikely(err))
4737 + goto error;
4738 + current_core = (current_core - 0x18000000) / 0x1000;
4739 + if (current_core == core)
4740 + break;
4741 +
4742 + if (unlikely(attempts++ > BCM43xx_SWITCH_CORE_MAX_RETRIES))
4743 + goto error;
4744 + udelay(10);
4745 + }
4746 +#ifdef CONFIG_BCM947XX
4747 + if (bcm->pci_dev->bus->number == 0)
4748 + bcm->current_core_offset = 0x1000 * core;
4749 + else
4750 + bcm->current_core_offset = 0;
4751 +#endif
4752 +
4753 + return 0;
4754 +error:
4755 + printk(KERN_ERR PFX "Failed to switch to core %d\n", core);
4756 + return -ENODEV;
4757 +}
4758 +
4759 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core)
4760 +{
4761 + int err;
4762 +
4763 + if (unlikely(!new_core))
4764 + return 0;
4765 + if (!new_core->available)
4766 + return -ENODEV;
4767 + if (bcm->current_core == new_core)
4768 + return 0;
4769 + err = _switch_core(bcm, new_core->index);
4770 + if (unlikely(err))
4771 + goto out;
4772 +
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]));
4777 +
4778 +out:
4779 + return err;
4780 +}
4781 +
4782 +static int bcm43xx_core_enabled(struct bcm43xx_private *bcm)
4783 +{
4784 + u32 value;
4785 +
4786 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4787 + value &= BCM43xx_SBTMSTATELOW_CLOCK | BCM43xx_SBTMSTATELOW_RESET
4788 + | BCM43xx_SBTMSTATELOW_REJECT;
4789 +
4790 + return (value == BCM43xx_SBTMSTATELOW_CLOCK);
4791 +}
4792 +
4793 +/* disable current core */
4794 +static int bcm43xx_core_disable(struct bcm43xx_private *bcm, u32 core_flags)
4795 +{
4796 + u32 sbtmstatelow;
4797 + u32 sbtmstatehigh;
4798 + int i;
4799 +
4800 + /* fetch sbtmstatelow from core information registers */
4801 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4802 +
4803 + /* core is already in reset */
4804 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_RESET)
4805 + goto out;
4806 +
4807 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_CLOCK) {
4808 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4809 + BCM43xx_SBTMSTATELOW_REJECT;
4810 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4811 +
4812 + for (i = 0; i < 1000; i++) {
4813 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4814 + if (sbtmstatelow & BCM43xx_SBTMSTATELOW_REJECT) {
4815 + i = -1;
4816 + break;
4817 + }
4818 + udelay(10);
4819 + }
4820 + if (i != -1) {
4821 + printk(KERN_ERR PFX "Error: core_disable() REJECT timeout!\n");
4822 + return -EBUSY;
4823 + }
4824 +
4825 + for (i = 0; i < 1000; i++) {
4826 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
4827 + if (!(sbtmstatehigh & BCM43xx_SBTMSTATEHIGH_BUSY)) {
4828 + i = -1;
4829 + break;
4830 + }
4831 + udelay(10);
4832 + }
4833 + if (i != -1) {
4834 + printk(KERN_ERR PFX "Error: core_disable() BUSY timeout!\n");
4835 + return -EBUSY;
4836 + }
4837 +
4838 + sbtmstatelow = BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4839 + BCM43xx_SBTMSTATELOW_REJECT |
4840 + BCM43xx_SBTMSTATELOW_RESET |
4841 + BCM43xx_SBTMSTATELOW_CLOCK |
4842 + core_flags;
4843 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4844 + udelay(10);
4845 + }
4846 +
4847 + sbtmstatelow = BCM43xx_SBTMSTATELOW_RESET |
4848 + BCM43xx_SBTMSTATELOW_REJECT |
4849 + core_flags;
4850 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4851 +
4852 +out:
4853 + bcm->current_core->enabled = 0;
4854 +
4855 + return 0;
4856 +}
4857 +
4858 +/* enable (reset) current core */
4859 +static int bcm43xx_core_enable(struct bcm43xx_private *bcm, u32 core_flags)
4860 +{
4861 + u32 sbtmstatelow;
4862 + u32 sbtmstatehigh;
4863 + u32 sbimstate;
4864 + int err;
4865 +
4866 + err = bcm43xx_core_disable(bcm, core_flags);
4867 + if (err)
4868 + goto out;
4869 +
4870 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4871 + BCM43xx_SBTMSTATELOW_RESET |
4872 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4873 + core_flags;
4874 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4875 + udelay(1);
4876 +
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);
4881 + }
4882 +
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);
4887 + }
4888 +
4889 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK |
4890 + BCM43xx_SBTMSTATELOW_FORCE_GATE_CLOCK |
4891 + core_flags;
4892 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4893 + udelay(1);
4894 +
4895 + sbtmstatelow = BCM43xx_SBTMSTATELOW_CLOCK | core_flags;
4896 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4897 + udelay(1);
4898 +
4899 + bcm->current_core->enabled = 1;
4900 + assert(err == 0);
4901 +out:
4902 + return err;
4903 +}
4904 +
4905 +/* http://bcm-specs.sipsolutions.net/80211CoreReset */
4906 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
4907 +{
4908 + u32 flags = 0x00040000;
4909 +
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);
4922 +#endif
4923 + }
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));
4928 + } else {
4929 + if (connect_phy)
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);
4937 + }
4938 +}
4939 +
4940 +static void bcm43xx_wireless_core_disable(struct bcm43xx_private *bcm)
4941 +{
4942 + bcm43xx_radio_turn_off(bcm);
4943 + bcm43xx_write16(bcm, 0x03E6, 0x00F4);
4944 + bcm43xx_core_disable(bcm, 0);
4945 +}
4946 +
4947 +/* Mark the current 80211 core inactive.
4948 + * "active_80211_core" is the other 80211 core, which is used.
4949 + */
4950 +static int bcm43xx_wireless_core_mark_inactive(struct bcm43xx_private *bcm,
4951 + struct bcm43xx_coreinfo *active_80211_core)
4952 +{
4953 + u32 sbtmstatelow;
4954 + struct bcm43xx_coreinfo *old_core;
4955 + int err = 0;
4956 +
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);
4963 + udelay(1);
4964 + sbtmstatelow = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
4965 + sbtmstatelow &= ~0xa0000;
4966 + sbtmstatelow |= 0x80000;
4967 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, sbtmstatelow);
4968 + udelay(1);
4969 +
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);
4973 + if (err)
4974 + goto out;
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);
4980 + }
4981 +
4982 +out:
4983 + return err;
4984 +}
4985 +
4986 +static void handle_irq_transmit_status(struct bcm43xx_private *bcm)
4987 +{
4988 + u32 v0, v1;
4989 + u16 tmp;
4990 + struct bcm43xx_xmitstatus stat;
4991 +
4992 + while (1) {
4993 + v0 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_0);
4994 + if (!v0)
4995 + break;
4996 + v1 = bcm43xx_read32(bcm, BCM43xx_MMIO_XMITSTAT_1);
4997 +
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);
5005 +
5006 + bcm43xx_debugfs_log_txstat(bcm, &stat);
5007 +
5008 + if (stat.flags & BCM43xx_TXSTAT_FLAG_IGNORE)
5009 + continue;
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
5013 +
5014 + if (bcm43xx_using_pio(bcm))
5015 + bcm43xx_pio_handle_xmitstatus(bcm, &stat);
5016 + else
5017 + bcm43xx_dma_handle_xmitstatus(bcm, &stat);
5018 + }
5019 +}
5020 +
5021 +static void bcm43xx_generate_noise_sample(struct bcm43xx_private *bcm)
5022 +{
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);
5029 +}
5030 +
5031 +static void bcm43xx_calculate_link_quality(struct bcm43xx_private *bcm)
5032 +{
5033 + /* Top half of Link Quality calculation. */
5034 +
5035 + if (bcm->noisecalc.calculation_running)
5036 + return;
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;
5041 +
5042 + bcm43xx_generate_noise_sample(bcm);
5043 +}
5044 +
5045 +static void handle_irq_noise(struct bcm43xx_private *bcm)
5046 +{
5047 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5048 + u16 tmp;
5049 + u8 noise[4];
5050 + u8 i, j;
5051 + s32 average;
5052 +
5053 + /* Bottom half of Link Quality calculation. */
5054 +
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;
5068 +
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. */
5083 + average = 0;
5084 + for (i = 0; i < 8; i++) {
5085 + for (j = 0; j < 4; j++)
5086 + average += bcm->noisecalc.samples[i][j];
5087 + }
5088 + average /= (8 * 4);
5089 + average *= 125;
5090 + average += 64;
5091 + average /= 128;
5092 + tmp = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x40C);
5093 + tmp = (tmp / 128) & 0x1F;
5094 + if (tmp >= 8)
5095 + average += 2;
5096 + else
5097 + average -= 25;
5098 + if (tmp == 8)
5099 + average -= 72;
5100 + else
5101 + average -= 48;
5102 +
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;
5109 + else
5110 + bcm->stats.link_quality = 3;
5111 +// dprintk(KERN_INFO PFX "Link Quality: %u (avg was %d)\n", bcm->stats.link_quality, average);
5112 +drop_calculation:
5113 + bcm->noisecalc.calculation_running = 0;
5114 + return;
5115 + }
5116 +generate_new:
5117 + bcm43xx_generate_noise_sample(bcm);
5118 +}
5119 +
5120 +static void handle_irq_ps(struct bcm43xx_private *bcm)
5121 +{
5122 + if (bcm->iw_mode == IW_MODE_MASTER) {
5123 + ///TODO: PS TBTT
5124 + } else {
5125 + if (1/*FIXME: the last PSpoll frame was sent successfully */)
5126 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
5127 + }
5128 + if (bcm->iw_mode == IW_MODE_ADHOC)
5129 + bcm->reg124_set_0x4 = 1;
5130 + //FIXME else set to false?
5131 +}
5132 +
5133 +static void handle_irq_reg124(struct bcm43xx_private *bcm)
5134 +{
5135 + if (!bcm->reg124_set_0x4)
5136 + return;
5137 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD,
5138 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD)
5139 + | 0x4);
5140 + //FIXME: reset reg124_set_0x4 to false?
5141 +}
5142 +
5143 +static void handle_irq_pmq(struct bcm43xx_private *bcm)
5144 +{
5145 + u32 tmp;
5146 +
5147 + //TODO: AP mode.
5148 +
5149 + while (1) {
5150 + tmp = bcm43xx_read32(bcm, BCM43xx_MMIO_PS_STATUS);
5151 + if (!(tmp & 0x00000008))
5152 + break;
5153 + }
5154 + /* 16bit write is odd, but correct. */
5155 + bcm43xx_write16(bcm, BCM43xx_MMIO_PS_STATUS, 0x0002);
5156 +}
5157 +
5158 +static void bcm43xx_write_beacon_template(struct bcm43xx_private *bcm,
5159 + u16 ram_offset,
5160 + u16 shm_size_offset)
5161 +{
5162 + u32 tmp;
5163 + u16 i, size;
5164 + const u8 *data;
5165 +
5166 + data = (const u8 *)(bcm->cached_beacon->data);
5167 + size = min(bcm->cached_beacon->len, (unsigned int)17);
5168 +
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);
5175 + }
5176 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, shm_size_offset, size);
5177 +}
5178 +
5179 +static void handle_irq_beacon(struct bcm43xx_private *bcm)
5180 +{
5181 + u32 status;
5182 +
5183 + bcm->irq_savedstate &= ~BCM43xx_IRQ_BEACON;
5184 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD);
5185 +
5186 + if (!bcm->cached_beacon) {
5187 + struct ieee80211_tx_control control;
5188 +
5189 + /* No cached template available, yet.
5190 + * Request the 80211 subsystem to generate a new beacon
5191 + * frame and use it as template.
5192 + */
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");
5196 + goto ack;
5197 + }
5198 + }
5199 +
5200 + if ((status & 0x1) && (status & 0x2)) {
5201 +ack:
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;
5209 + return;
5210 + }
5211 + if (!(status & 0x1)) {
5212 + bcm43xx_write_beacon_template(bcm, 0x68, 0x18);
5213 + status |= 0x1;
5214 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5215 + }
5216 + if (!(status & 0x2)) {
5217 + bcm43xx_write_beacon_template(bcm, 0x468, 0x1A);
5218 + status |= 0x2;
5219 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS2_BITFIELD, status);
5220 + }
5221 +}
5222 +
5223 +/* Interrupt handler bottom-half */
5224 +static void bcm43xx_interrupt_tasklet(struct bcm43xx_private *bcm)
5225 +{
5226 + u32 reason;
5227 + u32 dma_reason[4];
5228 + int activity = 0;
5229 + unsigned long flags;
5230 +
5231 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
5232 + u32 _handled = 0x00000000;
5233 +# define bcmirq_handled(irq) do { _handled |= (irq); } while (0)
5234 +#else
5235 +# define bcmirq_handled(irq) do { /* nothing */ } while (0)
5236 +#endif /* CONFIG_BCM43XX_D80211_DEBUG*/
5237 +
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];
5244 +
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.
5250 + */
5251 + printkl(KERN_ERR PFX "FATAL ERROR: BCM43xx_IRQ_XMIT_ERROR\n");
5252 + bcmirq_handled(BCM43xx_IRQ_XMIT_ERROR);
5253 + }
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);
5264 + return;
5265 + }
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]);
5274 + }
5275 +
5276 + if (reason & BCM43xx_IRQ_PS) {
5277 + handle_irq_ps(bcm);
5278 + bcmirq_handled(BCM43xx_IRQ_PS);
5279 + }
5280 +
5281 + if (reason & BCM43xx_IRQ_REG124) {
5282 + handle_irq_reg124(bcm);
5283 + bcmirq_handled(BCM43xx_IRQ_REG124);
5284 + }
5285 +
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);
5290 + }
5291 +
5292 + if (reason & BCM43xx_IRQ_PMQ) {
5293 + handle_irq_pmq(bcm);
5294 + bcmirq_handled(BCM43xx_IRQ_PMQ);
5295 + }
5296 +
5297 + if (reason & BCM43xx_IRQ_SCAN) {
5298 + /*TODO*/
5299 + //bcmirq_handled(BCM43xx_IRQ_SCAN);
5300 + }
5301 +
5302 + if (reason & BCM43xx_IRQ_NOISE) {
5303 + handle_irq_noise(bcm);
5304 + bcmirq_handled(BCM43xx_IRQ_NOISE);
5305 + }
5306 +
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);
5313 + else
5314 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring0);
5315 + /* We intentionally don't set "activity" to 1, here. */
5316 + }
5317 + if (dma_reason[3] & BCM43xx_DMAIRQ_RX_DONE) {
5318 + if (bcm43xx_using_pio(bcm))
5319 + bcm43xx_pio_rx(bcm43xx_current_pio(bcm)->queue3);
5320 + else
5321 + bcm43xx_dma_rx(bcm43xx_current_dma(bcm)->rx_ring1);
5322 + activity = 1;
5323 + }
5324 + bcmirq_handled(BCM43xx_IRQ_RX);
5325 +
5326 + if (reason & BCM43xx_IRQ_XMIT_STATUS) {
5327 + handle_irq_transmit_status(bcm);
5328 + activity = 1;
5329 + //TODO: In AP mode, this also causes sending of powersave responses.
5330 + bcmirq_handled(BCM43xx_IRQ_XMIT_STATUS);
5331 + }
5332 +
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]);
5343 + }
5344 +#endif
5345 +#undef bcmirq_handled
5346 +
5347 + if (!modparam_noleds)
5348 + bcm43xx_leds_update(bcm, activity);
5349 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
5350 + bcm43xx_unlock_mmio(bcm, flags);
5351 +}
5352 +
5353 +static void pio_irq_workaround(struct bcm43xx_private *bcm,
5354 + u16 base, int queueidx)
5355 +{
5356 + u16 rxctl;
5357 +
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;
5361 + else
5362 + bcm->dma_reason[queueidx] &= ~BCM43xx_DMAIRQ_RX_DONE;
5363 +}
5364 +
5365 +static void bcm43xx_interrupt_ack(struct bcm43xx_private *bcm, u32 reason)
5366 +{
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);
5375 + }
5376 +
5377 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, reason);
5378 +
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]);
5387 +}
5388 +
5389 +/* Interrupt handler top-half */
5390 +static irqreturn_t bcm43xx_interrupt_handler(int irq, void *dev_id, struct pt_regs *regs)
5391 +{
5392 + irqreturn_t ret = IRQ_HANDLED;
5393 + struct bcm43xx_private *bcm = dev_id;
5394 + u32 reason;
5395 +
5396 + if (!bcm)
5397 + return IRQ_NONE;
5398 +
5399 + spin_lock(&bcm->_lock);
5400 +
5401 + reason = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5402 + if (reason == 0xffffffff) {
5403 + /* irq not for us (shared irq) */
5404 + ret = IRQ_NONE;
5405 + goto out;
5406 + }
5407 + reason &= bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_MASK);
5408 + if (!reason)
5409 + goto out;
5410 +
5411 + bcm->dma_reason[0] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA1_REASON)
5412 + & 0x0001dc00;
5413 + bcm->dma_reason[1] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA2_REASON)
5414 + & 0x0000dc00;
5415 + bcm->dma_reason[2] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA3_REASON)
5416 + & 0x0000dc00;
5417 + bcm->dma_reason[3] = bcm43xx_read32(bcm, BCM43xx_MMIO_DMA4_REASON)
5418 + & 0x0001dc00;
5419 +
5420 + bcm43xx_interrupt_ack(bcm, reason);
5421 +
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... .
5427 + */
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);
5434 + }
5435 +
5436 +out:
5437 + mmiowb();
5438 + spin_unlock(&bcm->_lock);
5439 +
5440 + return ret;
5441 +}
5442 +
5443 +static void bcm43xx_release_firmware(struct bcm43xx_private *bcm, int force)
5444 +{
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);
5450 + bcm->pcm = NULL;
5451 + release_firmware(bcm->initvals0);
5452 + bcm->initvals0 = NULL;
5453 + release_firmware(bcm->initvals1);
5454 + bcm->initvals1 = NULL;
5455 +}
5456 +
5457 +static int bcm43xx_request_firmware(struct bcm43xx_private *bcm)
5458 +{
5459 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5460 + u8 rev = bcm->current_core->rev;
5461 + int err = 0;
5462 + int nr;
5463 + char buf[22 + sizeof(modparam_fwpostfix) - 1] = { 0 };
5464 +
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);
5470 + if (err) {
5471 + printk(KERN_ERR PFX
5472 + "Error: Microcode \"%s\" not available or load failed.\n",
5473 + buf);
5474 + goto error;
5475 + }
5476 + }
5477 +
5478 + if (!bcm->pcm) {
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);
5484 + if (err) {
5485 + printk(KERN_ERR PFX
5486 + "Error: PCM \"%s\" not available or load failed.\n",
5487 + buf);
5488 + goto error;
5489 + }
5490 + }
5491 +
5492 + if (!bcm->initvals0) {
5493 + if (rev == 2 || rev == 4) {
5494 + switch (phy->type) {
5495 + case BCM43xx_PHYTYPE_A:
5496 + nr = 3;
5497 + break;
5498 + case BCM43xx_PHYTYPE_B:
5499 + case BCM43xx_PHYTYPE_G:
5500 + nr = 1;
5501 + break;
5502 + default:
5503 + goto err_noinitval;
5504 + }
5505 +
5506 + } else if (rev >= 5) {
5507 + switch (phy->type) {
5508 + case BCM43xx_PHYTYPE_A:
5509 + nr = 7;
5510 + break;
5511 + case BCM43xx_PHYTYPE_B:
5512 + case BCM43xx_PHYTYPE_G:
5513 + nr = 5;
5514 + break;
5515 + default:
5516 + goto err_noinitval;
5517 + }
5518 + } else
5519 + goto err_noinitval;
5520 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5521 + nr, modparam_fwpostfix);
5522 +
5523 + err = request_firmware(&bcm->initvals0, buf, &bcm->pci_dev->dev);
5524 + if (err) {
5525 + printk(KERN_ERR PFX
5526 + "Error: InitVals \"%s\" not available or load failed.\n",
5527 + buf);
5528 + goto error;
5529 + }
5530 + if (bcm->initvals0->size % sizeof(struct bcm43xx_initval)) {
5531 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5532 + goto error;
5533 + }
5534 + }
5535 +
5536 + if (!bcm->initvals1) {
5537 + if (rev >= 5) {
5538 + u32 sbtmstatehigh;
5539 +
5540 + switch (phy->type) {
5541 + case BCM43xx_PHYTYPE_A:
5542 + sbtmstatehigh = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
5543 + if (sbtmstatehigh & 0x00010000)
5544 + nr = 9;
5545 + else
5546 + nr = 10;
5547 + break;
5548 + case BCM43xx_PHYTYPE_B:
5549 + case BCM43xx_PHYTYPE_G:
5550 + nr = 6;
5551 + break;
5552 + default:
5553 + goto err_noinitval;
5554 + }
5555 + snprintf(buf, ARRAY_SIZE(buf), "bcm43xx_initval%02d%s.fw",
5556 + nr, modparam_fwpostfix);
5557 +
5558 + err = request_firmware(&bcm->initvals1, buf, &bcm->pci_dev->dev);
5559 + if (err) {
5560 + printk(KERN_ERR PFX
5561 + "Error: InitVals \"%s\" not available or load failed.\n",
5562 + buf);
5563 + goto error;
5564 + }
5565 + if (bcm->initvals1->size % sizeof(struct bcm43xx_initval)) {
5566 + printk(KERN_ERR PFX "InitVals fileformat error.\n");
5567 + goto error;
5568 + }
5569 + }
5570 + }
5571 +
5572 +out:
5573 + return err;
5574 +error:
5575 + bcm43xx_release_firmware(bcm, 1);
5576 + goto out;
5577 +err_noinitval:
5578 + printk(KERN_ERR PFX "Error: No InitVals available!\n");
5579 + err = -ENOENT;
5580 + goto error;
5581 +}
5582 +
5583 +static void bcm43xx_upload_microcode(struct bcm43xx_private *bcm)
5584 +{
5585 + const u32 *data;
5586 + unsigned int i, len;
5587 +
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]));
5595 + udelay(10);
5596 + }
5597 +
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]));
5607 + udelay(10);
5608 + }
5609 +}
5610 +
5611 +static int bcm43xx_write_initvals(struct bcm43xx_private *bcm,
5612 + const struct bcm43xx_initval *data,
5613 + const unsigned int len)
5614 +{
5615 + u16 offset, size;
5616 + u32 value;
5617 + unsigned int i;
5618 +
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);
5623 +
5624 + if (unlikely(offset >= 0x1000))
5625 + goto err_format;
5626 + if (size == 2) {
5627 + if (unlikely(value & 0xFFFF0000))
5628 + goto err_format;
5629 + bcm43xx_write16(bcm, offset, (u16)value);
5630 + } else if (size == 4) {
5631 + bcm43xx_write32(bcm, offset, value);
5632 + } else
5633 + goto err_format;
5634 + }
5635 +
5636 + return 0;
5637 +
5638 +err_format:
5639 + printk(KERN_ERR PFX "InitVals (bcm43xx_initvalXX.fw) file-format error. "
5640 + "Please fix your bcm43xx firmware files.\n");
5641 + return -EPROTO;
5642 +}
5643 +
5644 +static int bcm43xx_upload_initvals(struct bcm43xx_private *bcm)
5645 +{
5646 + int err;
5647 +
5648 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals0->data,
5649 + bcm->initvals0->size / sizeof(struct bcm43xx_initval));
5650 + if (err)
5651 + goto out;
5652 + if (bcm->initvals1) {
5653 + err = bcm43xx_write_initvals(bcm, (struct bcm43xx_initval *)bcm->initvals1->data,
5654 + bcm->initvals1->size / sizeof(struct bcm43xx_initval));
5655 + if (err)
5656 + goto out;
5657 + }
5658 +out:
5659 + return err;
5660 +}
5661 +
5662 +static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
5663 +{
5664 + int res;
5665 + unsigned int i;
5666 + u32 data;
5667 +
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);
5674 + if (d != NULL) {
5675 + bcm->irq = d->irq;
5676 + }
5677 + }
5678 +#endif
5679 + res = request_irq(bcm->irq, bcm43xx_interrupt_handler,
5680 + SA_SHIRQ, KBUILD_MODNAME, bcm);
5681 + if (res) {
5682 + printk(KERN_ERR PFX "Cannot register IRQ%d\n", bcm->irq);
5683 + return -ENODEV;
5684 + }
5685 + bcm43xx_write32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON, 0xffffffff);
5686 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 0x00020402);
5687 + i = 0;
5688 + while (1) {
5689 + data = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5690 + if (data == BCM43xx_IRQ_READY)
5691 + break;
5692 + i++;
5693 + if (i >= BCM43xx_IRQWAIT_MAX_RETRIES) {
5694 + printk(KERN_ERR PFX "Card IRQ register not responding. "
5695 + "Giving up.\n");
5696 + free_irq(bcm->irq, bcm);
5697 + return -ENODEV;
5698 + }
5699 + udelay(10);
5700 + }
5701 + // dummy read
5702 + bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
5703 +
5704 + return 0;
5705 +}
5706 +
5707 +/* Switch to the core used to write the GPIO register.
5708 + * This is either the ChipCommon, or the PCI core.
5709 + */
5710 +static int switch_to_gpio_core(struct bcm43xx_private *bcm)
5711 +{
5712 + int err;
5713 +
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.
5718 + */
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");
5725 + }
5726 + }
5727 +
5728 + return err;
5729 +}
5730 +
5731 +/* Initialize the GPIOs
5732 + * http://bcm-specs.sipsolutions.net/GPIO
5733 + */
5734 +static int bcm43xx_gpio_init(struct bcm43xx_private *bcm)
5735 +{
5736 + struct bcm43xx_coreinfo *old_core;
5737 + int err;
5738 + u32 mask, set;
5739 +
5740 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5741 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD)
5742 + & 0xFFFF3FFF);
5743 +
5744 + bcm43xx_leds_switch_all(bcm, 0);
5745 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5746 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK) | 0x000F);
5747 +
5748 + mask = 0x0000001F;
5749 + set = 0x0000000F;
5750 + if (bcm->chip_id == 0x4301) {
5751 + mask |= 0x0060;
5752 + set |= 0x0060;
5753 + }
5754 + if (0 /* FIXME: conditional unknown */) {
5755 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5756 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5757 + | 0x0100);
5758 + mask |= 0x0180;
5759 + set |= 0x0180;
5760 + }
5761 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) {
5762 + bcm43xx_write16(bcm, BCM43xx_MMIO_GPIO_MASK,
5763 + bcm43xx_read16(bcm, BCM43xx_MMIO_GPIO_MASK)
5764 + | 0x0200);
5765 + mask |= 0x0200;
5766 + set |= 0x0200;
5767 + }
5768 + if (bcm->current_core->rev >= 2)
5769 + mask |= 0x0010; /* FIXME: This is redundant. */
5770 +
5771 + old_core = bcm->current_core;
5772 + err = switch_to_gpio_core(bcm);
5773 + if (err)
5774 + goto out;
5775 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL,
5776 + (bcm43xx_read32(bcm, BCM43xx_GPIO_CONTROL) & mask) | set);
5777 + err = bcm43xx_switch_core(bcm, old_core);
5778 +out:
5779 + return err;
5780 +}
5781 +
5782 +/* Turn off all GPIO stuff. Call this on module unload, for example. */
5783 +static int bcm43xx_gpio_cleanup(struct bcm43xx_private *bcm)
5784 +{
5785 + struct bcm43xx_coreinfo *old_core;
5786 + int err;
5787 +
5788 + old_core = bcm->current_core;
5789 + err = switch_to_gpio_core(bcm);
5790 + if (err)
5791 + return err;
5792 + bcm43xx_write32(bcm, BCM43xx_GPIO_CONTROL, 0x00000000);
5793 + err = bcm43xx_switch_core(bcm, old_core);
5794 + assert(err == 0);
5795 +
5796 + return 0;
5797 +}
5798 +
5799 +/* http://bcm-specs.sipsolutions.net/EnableMac */
5800 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm)
5801 +{
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);
5809 +}
5810 +
5811 +/* http://bcm-specs.sipsolutions.net/SuspendMAC */
5812 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm)
5813 +{
5814 + int i;
5815 + u32 tmp;
5816 +
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)
5825 + return;
5826 + udelay(10);
5827 + }
5828 + printkl(KERN_ERR PFX "MAC suspend failed\n");
5829 +}
5830 +
5831 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
5832 + int iw_mode)
5833 +{
5834 + struct net_device *net_dev = bcm->net_dev;
5835 + u32 status;
5836 + u16 value;
5837 +
5838 + bcm->iw_mode = iw_mode;
5839 + if (iw_mode == IW_MODE_MONITOR)
5840 + net_dev->type = ARPHRD_IEEE80211;
5841 + else
5842 + net_dev->type = ARPHRD_ETHER;
5843 +
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;
5849 +
5850 +/* FIXME: Always enable promisc mode, until we get the MAC filters working correctly. */
5851 +status |= BCM43xx_SBF_MODE_PROMISC;
5852 +
5853 + switch (iw_mode) {
5854 + case IW_MODE_MONITOR:
5855 + status |= BCM43xx_SBF_MODE_MONITOR;
5856 + status |= BCM43xx_SBF_MODE_PROMISC;
5857 + break;
5858 + case IW_MODE_ADHOC:
5859 + status &= ~BCM43xx_SBF_MODE_NOTADHOC;
5860 + break;
5861 + case IW_MODE_MASTER:
5862 + status |= BCM43xx_SBF_MODE_AP;
5863 + break;
5864 + case IW_MODE_SECOND:
5865 + case IW_MODE_REPEAT:
5866 + TODO(); /* TODO */
5867 + break;
5868 + case IW_MODE_INFRA:
5869 + /* nothing to be done here... */
5870 + break;
5871 + default:
5872 + dprintk(KERN_ERR PFX "Unknown mode in set_iwmode: %d\n", iw_mode);
5873 + }
5874 + if (net_dev->flags & IFF_PROMISC)
5875 + status |= BCM43xx_SBF_MODE_PROMISC;
5876 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
5877 +
5878 + value = 0x0002;
5879 + if (iw_mode != IW_MODE_ADHOC && iw_mode != IW_MODE_MASTER) {
5880 + if (bcm->chip_id == 0x4306 && bcm->chip_rev == 3)
5881 + value = 0x0064;
5882 + else
5883 + value = 0x0032;
5884 + }
5885 + bcm43xx_write16(bcm, 0x0612, value);
5886 +}
5887 +
5888 +/* This is the opposite of bcm43xx_chip_init() */
5889 +static void bcm43xx_chip_cleanup(struct bcm43xx_private *bcm)
5890 +{
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);
5897 +}
5898 +
5899 +/* Initialize the chip
5900 + * http://bcm-specs.sipsolutions.net/ChipInit
5901 + */
5902 +static int bcm43xx_chip_init(struct bcm43xx_private *bcm)
5903 +{
5904 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
5905 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
5906 + int err;
5907 + int tmp;
5908 + u32 value32;
5909 + u16 value16;
5910 +
5911 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
5912 + BCM43xx_SBF_CORE_READY
5913 + | BCM43xx_SBF_400);
5914 +
5915 + err = bcm43xx_request_firmware(bcm);
5916 + if (err)
5917 + goto out;
5918 + bcm43xx_upload_microcode(bcm);
5919 + err = bcm43xx_initialize_irq(bcm);
5920 + if (err)
5921 + goto err_release_fw;
5922 + err = bcm43xx_gpio_init(bcm);
5923 + if (err)
5924 + goto err_free_irq;
5925 + err = bcm43xx_upload_initvals(bcm);
5926 + if (err)
5927 + goto err_gpio_cleanup;
5928 + bcm43xx_radio_turn_on(bcm);
5929 +
5930 + bcm43xx_write16(bcm, 0x03E6, 0x0000);
5931 + err = bcm43xx_phy_init(bcm);
5932 + if (err)
5933 + goto err_radio_off;
5934 +
5935 + /* Select initial Interference Mitigation. */
5936 + tmp = radio->interfmode;
5937 + radio->interfmode = BCM43xx_RADIO_INTERFMODE_NONE;
5938 + bcm43xx_radio_set_interference_mitigation(bcm, tmp);
5939 +
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);
5946 + }
5947 + bcm43xx_write32(bcm, 0x0100, 0x01000000);
5948 + if (bcm->current_core->rev < 5)
5949 + bcm43xx_write32(bcm, 0x010C, 0x01000000);
5950 +
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);
5957 +
5958 + value32 = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
5959 + value32 |= 0x100000;
5960 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, value32);
5961 +
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);
5968 + }
5969 +
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);
5973 +
5974 + /* Initially set the wireless operation mode. */
5975 + bcm43xx_set_iwmode(bcm, bcm->iw_mode);
5976 +
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);
5982 + } else {
5983 + bcm43xx_write32(bcm, 0x0188, 0x80000000);
5984 + bcm43xx_write32(bcm, 0x018C, 0x02000000);
5985 + }
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);
5991 +
5992 + value32 = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
5993 + value32 |= 0x00100000;
5994 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, value32);
5995 +
5996 + bcm43xx_write16(bcm, BCM43xx_MMIO_POWERUP_DELAY, bcm43xx_pctl_powerup_delay(bcm));
5997 +
5998 + assert(err == 0);
5999 + dprintk(KERN_INFO PFX "Chip initialized\n");
6000 +out:
6001 + return err;
6002 +
6003 +err_radio_off:
6004 + bcm43xx_radio_turn_off(bcm);
6005 +err_gpio_cleanup:
6006 + bcm43xx_gpio_cleanup(bcm);
6007 +err_free_irq:
6008 + free_irq(bcm->irq, bcm);
6009 +err_release_fw:
6010 + bcm43xx_release_firmware(bcm, 1);
6011 + goto out;
6012 +}
6013 +
6014 +/* Validate chip access
6015 + * http://bcm-specs.sipsolutions.net/ValidateChipAccess */
6016 +static int bcm43xx_validate_chip(struct bcm43xx_private *bcm)
6017 +{
6018 + u32 value;
6019 + u32 shm_backup;
6020 +
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)
6024 + goto error;
6025 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, 0x55AAAA55);
6026 + if (bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED, 0x0000) != 0x55AAAA55)
6027 + goto error;
6028 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED, 0x0000, shm_backup);
6029 +
6030 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
6031 + if ((value | 0x80000000) != 0x80000400)
6032 + goto error;
6033 +
6034 + value = bcm43xx_read32(bcm, BCM43xx_MMIO_GEN_IRQ_REASON);
6035 + if (value != 0x00000000)
6036 + goto error;
6037 +
6038 + return 0;
6039 +error:
6040 + printk(KERN_ERR PFX "Failed to validate the chipaccess\n");
6041 + return -ENODEV;
6042 +}
6043 +
6044 +static void bcm43xx_init_struct_phyinfo(struct bcm43xx_phyinfo *phy)
6045 +{
6046 + /* Initialize a "phyinfo" structure. The structure is already
6047 + * zeroed out.
6048 + */
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);
6054 +}
6055 +
6056 +static void bcm43xx_init_struct_radioinfo(struct bcm43xx_radioinfo *radio)
6057 +{
6058 + /* Initialize a "radioinfo" structure. The structure is already
6059 + * zeroed out.
6060 + */
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;
6068 +}
6069 +
6070 +static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
6071 +{
6072 + int err, i;
6073 + int current_core;
6074 + u32 core_vendor, core_id, core_rev;
6075 + u32 sb_id_hi, chip_id_32 = 0;
6076 + u16 pci_device, chip_id_16;
6077 + u8 core_count;
6078 +
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;
6089 +
6090 + /* map core 0 */
6091 + err = _switch_core(bcm, 0);
6092 + if (err)
6093 + goto out;
6094 +
6095 + /* fetch sb_id_hi from core information registers */
6096 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
6097 +
6098 + core_id = (sb_id_hi & 0xFFF0) >> 4;
6099 + core_rev = (sb_id_hi & 0xF);
6100 + core_vendor = (sb_id_hi & 0xFFFF0000) >> 16;
6101 +
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);
6112 + } else {
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;
6128 +#endif
6129 + else {
6130 + printk(KERN_ERR PFX "Could not determine Chip ID\n");
6131 + return -ENODEV;
6132 + }
6133 + }
6134 +
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;
6139 + } else {
6140 + switch (chip_id_16) {
6141 + case 0x4610:
6142 + case 0x4704:
6143 + case 0x4710:
6144 + core_count = 9;
6145 + break;
6146 + case 0x4310:
6147 + core_count = 8;
6148 + break;
6149 + case 0x5365:
6150 + core_count = 7;
6151 + break;
6152 + case 0x4306:
6153 + core_count = 6;
6154 + break;
6155 + case 0x4301:
6156 + case 0x4307:
6157 + core_count = 5;
6158 + break;
6159 + case 0x4402:
6160 + core_count = 3;
6161 + break;
6162 + default:
6163 + /* SOL if we get here */
6164 + assert(0);
6165 + core_count = 1;
6166 + }
6167 + }
6168 +
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;
6172 +
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");
6180 + }
6181 +
6182 + if (bcm->core_chipcommon.available)
6183 + current_core = 1;
6184 + else
6185 + current_core = 0;
6186 + for ( ; current_core < core_count; current_core++) {
6187 + struct bcm43xx_coreinfo *core;
6188 + struct bcm43xx_coreinfo_80211 *ext_80211;
6189 +
6190 + err = _switch_core(bcm, current_core);
6191 + if (err)
6192 + goto out;
6193 + /* Gather information */
6194 + /* fetch sb_id_hi from core information registers */
6195 + sb_id_hi = bcm43xx_read32(bcm, BCM43xx_CIR_SB_ID_HI);
6196 +
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;
6201 +
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" );
6205 +
6206 + core = NULL;
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");
6212 + continue;
6213 + }
6214 + break;
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)
6220 + break;
6221 + core = NULL;
6222 + }
6223 + if (!core) {
6224 + printk(KERN_WARNING PFX "More than %d cores of type 802.11 found.\n",
6225 + BCM43xx_MAX_80211_CORES);
6226 + continue;
6227 + }
6228 + if (i != 0) {
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.
6234 + */
6235 + if (bcm->pci_dev->device != 0x4324) {
6236 + dprintk(KERN_INFO PFX "Ignoring additional 802.11 core.\n");
6237 + continue;
6238 + }
6239 + }
6240 + switch (core_rev) {
6241 + case 2:
6242 + case 4:
6243 + case 5:
6244 + case 6:
6245 + case 7:
6246 + case 9:
6247 + break;
6248 + default:
6249 + printk(KERN_ERR PFX "Error: Unsupported 80211 core revision %u\n",
6250 + core_rev);
6251 + err = -ENODEV;
6252 + goto out;
6253 + }
6254 + bcm->nr_80211_available++;
6255 + bcm43xx_init_struct_phyinfo(&ext_80211->phy);
6256 + bcm43xx_init_struct_radioinfo(&ext_80211->radio);
6257 + break;
6258 + case BCM43xx_COREID_CHIPCOMMON:
6259 + printk(KERN_WARNING PFX "Multiple CHIPCOMMON cores found.\n");
6260 + break;
6261 + }
6262 + if (core) {
6263 + core->available = 1;
6264 + core->id = core_id;
6265 + core->rev = core_rev;
6266 + core->index = current_core;
6267 + }
6268 + }
6269 +
6270 + if (!bcm->core_80211[0].available) {
6271 + printk(KERN_ERR PFX "Error: No 80211 core found!\n");
6272 + err = -ENODEV;
6273 + goto out;
6274 + }
6275 +
6276 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[0]);
6277 +
6278 + assert(err == 0);
6279 +out:
6280 + return err;
6281 +}
6282 +
6283 +static void bcm43xx_gen_bssid(struct bcm43xx_private *bcm)
6284 +{
6285 + const u8 *mac = (const u8*)(bcm->net_dev->dev_addr);
6286 + u8 *bssid = bcm->bssid;
6287 +
6288 + switch (bcm->iw_mode) {
6289 + case IW_MODE_ADHOC:
6290 + random_ether_addr(bssid);
6291 + break;
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);
6298 + break;
6299 + default:
6300 + assert(0);
6301 + }
6302 +}
6303 +
6304 +static void bcm43xx_rate_memory_write(struct bcm43xx_private *bcm,
6305 + u16 rate,
6306 + int is_ofdm)
6307 +{
6308 + u16 offset;
6309 +
6310 + if (is_ofdm) {
6311 + offset = 0x480;
6312 + offset += (bcm43xx_plcp_get_ratecode_ofdm(rate) & 0x000F) * 2;
6313 + } else {
6314 + offset = 0x4C0;
6315 + offset += (bcm43xx_plcp_get_ratecode_cck(rate) & 0x000F) * 2;
6316 + }
6317 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, offset + 0x20,
6318 + bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, offset));
6319 +}
6320 +
6321 +static void bcm43xx_rate_memory_init(struct bcm43xx_private *bcm)
6322 +{
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);
6338 + break;
6339 + default:
6340 + assert(0);
6341 + }
6342 +}
6343 +
6344 +static void bcm43xx_wireless_core_cleanup(struct bcm43xx_private *bcm)
6345 +{
6346 + bcm43xx_chip_cleanup(bcm);
6347 + bcm43xx_pio_free(bcm);
6348 + bcm43xx_dma_free(bcm);
6349 +
6350 + bcm->current_core->initialized = 0;
6351 +}
6352 +
6353 +/* http://bcm-specs.sipsolutions.net/80211Init */
6354 +static int bcm43xx_wireless_core_init(struct bcm43xx_private *bcm)
6355 +{
6356 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6357 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6358 + u32 ucodeflags;
6359 + int err;
6360 + u32 sbimconfiglow;
6361 + u8 limit;
6362 +
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;
6371 + else
6372 + assert(0);
6373 + bcm43xx_write32(bcm, BCM43xx_CIR_SBIMCONFIGLOW, sbimconfiglow);
6374 + }
6375 +
6376 + bcm43xx_phy_calibrate(bcm);
6377 + err = bcm43xx_chip_init(bcm);
6378 + if (err)
6379 + goto out;
6380 +
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);
6383 +
6384 + if (0 /*FIXME: which condition has to be used here? */)
6385 + ucodeflags |= 0x00000010;
6386 +
6387 + /* HW decryption needs to be set now. */
6388 + ucodeflags |= 0x40000000;
6389 +
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;
6400 + }
6401 +
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);
6406 + }
6407 +
6408 + /* Short/Long Retry Limit.
6409 + * The retry-limit is a 4-bit counter. Enforce this to avoid overflowing
6410 + * the chip-internal counter.
6411 + */
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);
6416 +
6417 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0044, 3);
6418 + bcm43xx_shm_write16(bcm, BCM43xx_SHM_SHARED, 0x0046, 2);
6419 +
6420 + bcm43xx_rate_memory_init(bcm);
6421 +
6422 + /* Minimum Contention Window */
6423 + if (phy->type == BCM43xx_PHYTYPE_B)
6424 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000001f);
6425 + else
6426 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0003, 0x0000000f);
6427 + /* Maximum Contention Window */
6428 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_WIRELESS, 0x0004, 0x000003ff);
6429 +
6430 + bcm43xx_gen_bssid(bcm);
6431 + bcm43xx_write_mac_bssid_templates(bcm);
6432 +
6433 + if (bcm->current_core->rev >= 5)
6434 + bcm43xx_write16(bcm, 0x043C, 0x000C);
6435 +
6436 + if (bcm43xx_using_pio(bcm))
6437 + err = bcm43xx_pio_init(bcm);
6438 + else
6439 + err = bcm43xx_dma_init(bcm);
6440 + if (err)
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);
6445 +
6446 + bcm43xx_mac_enable(bcm);
6447 + bcm43xx_interrupt_enable(bcm, bcm->irq_savedstate);
6448 +
6449 + bcm->current_core->initialized = 1;
6450 +out:
6451 + return err;
6452 +
6453 +err_chip_cleanup:
6454 + bcm43xx_chip_cleanup(bcm);
6455 + goto out;
6456 +}
6457 +
6458 +static int bcm43xx_chipset_attach(struct bcm43xx_private *bcm)
6459 +{
6460 + int err;
6461 + u16 pci_status;
6462 +
6463 + err = bcm43xx_pctl_set_crystal(bcm, 1);
6464 + if (err)
6465 + goto out;
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);
6468 +
6469 +out:
6470 + return err;
6471 +}
6472 +
6473 +static void bcm43xx_chipset_detach(struct bcm43xx_private *bcm)
6474 +{
6475 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
6476 + bcm43xx_pctl_set_crystal(bcm, 0);
6477 +}
6478 +
6479 +static void bcm43xx_pcicore_broadcast_value(struct bcm43xx_private *bcm,
6480 + u32 address,
6481 + u32 data)
6482 +{
6483 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_ADDR, address);
6484 + bcm43xx_write32(bcm, BCM43xx_PCICORE_BCAST_DATA, data);
6485 +}
6486 +
6487 +static int bcm43xx_pcicore_commit_settings(struct bcm43xx_private *bcm)
6488 +{
6489 + int err;
6490 + struct bcm43xx_coreinfo *old_core;
6491 +
6492 + old_core = bcm->current_core;
6493 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6494 + if (err)
6495 + goto out;
6496 +
6497 + bcm43xx_pcicore_broadcast_value(bcm, 0xfd8, 0x00000000);
6498 +
6499 + bcm43xx_switch_core(bcm, old_core);
6500 + assert(err == 0);
6501 +out:
6502 + return err;
6503 +}
6504 +
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
6507 + */
6508 +static int bcm43xx_setup_backplane_pci_connection(struct bcm43xx_private *bcm,
6509 + u32 core_mask)
6510 +{
6511 + u32 backplane_flag_nr;
6512 + u32 value;
6513 + struct bcm43xx_coreinfo *old_core;
6514 + int err = 0;
6515 +
6516 + value = bcm43xx_read32(bcm, BCM43xx_CIR_SBTPSFLAG);
6517 + backplane_flag_nr = value & BCM43xx_BACKPLANE_FLAG_NR_MASK;
6518 +
6519 + old_core = bcm->current_core;
6520 + err = bcm43xx_switch_core(bcm, &bcm->core_pci);
6521 + if (err)
6522 + goto out;
6523 +
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);
6528 + } else {
6529 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCICFG_ICR, &value);
6530 + if (err) {
6531 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6532 + goto out_switch_back;
6533 + }
6534 + value |= core_mask << 8;
6535 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCICFG_ICR, value);
6536 + if (err) {
6537 + printk(KERN_ERR PFX "Error: ICR setup failure!\n");
6538 + goto out_switch_back;
6539 + }
6540 + }
6541 +
6542 + value = bcm43xx_read32(bcm, BCM43xx_PCICORE_SBTOPCI2);
6543 + value |= BCM43xx_SBTOPCI2_PREFETCH | BCM43xx_SBTOPCI2_BURST;
6544 + bcm43xx_write32(bcm, BCM43xx_PCICORE_SBTOPCI2, value);
6545 +
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);
6554 + assert(err == 0);
6555 + }
6556 +
6557 +out_switch_back:
6558 + err = bcm43xx_switch_core(bcm, old_core);
6559 +out:
6560 + return err;
6561 +}
6562 +
6563 +static void bcm43xx_periodic_every120sec(struct bcm43xx_private *bcm)
6564 +{
6565 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6566 +
6567 + if (phy->type != BCM43xx_PHYTYPE_G || phy->rev < 2)
6568 + return;
6569 +
6570 + bcm43xx_mac_suspend(bcm);
6571 + bcm43xx_phy_lo_g_measure(bcm);
6572 + bcm43xx_mac_enable(bcm);
6573 +}
6574 +
6575 +static void bcm43xx_periodic_every60sec(struct bcm43xx_private *bcm)
6576 +{
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);
6582 + }
6583 +}
6584 +
6585 +static void bcm43xx_periodic_every30sec(struct bcm43xx_private *bcm)
6586 +{
6587 + /* Update device statistics. */
6588 + bcm43xx_calculate_link_quality(bcm);
6589 +}
6590 +
6591 +static void bcm43xx_periodic_every15sec(struct bcm43xx_private *bcm)
6592 +{
6593 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
6594 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
6595 +
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);
6604 + }
6605 + } else if (1/*TODO*/) {
6606 + /*
6607 + if ((aci_average > 1000) && !(bcm43xx_radio_aci_scan(bcm))) {
6608 + bcm43xx_radio_set_interference_mitigation(bcm,
6609 + BCM43xx_RADIO_INTERFMODE_NONE);
6610 + }
6611 + */
6612 + }
6613 + bcm43xx_mac_enable(bcm);
6614 + } else if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN &&
6615 + phy->rev == 1) {
6616 + //TODO: implement rev1 workaround
6617 + }
6618 + }
6619 + bcm43xx_phy_xmitpower(bcm); //FIXME: unless scanning?
6620 + //TODO for APHY (temperature?)
6621 +}
6622 +
6623 +static void bcm43xx_periodic_task_handler(unsigned long d)
6624 +{
6625 + struct bcm43xx_private *bcm = (struct bcm43xx_private *)d;
6626 + unsigned long flags;
6627 + unsigned int state;
6628 +
6629 + bcm43xx_lock_mmio(bcm, flags);
6630 +
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;
6641 +
6642 + mod_timer(&bcm->periodic_tasks, jiffies + (HZ * 15));
6643 +
6644 + bcm43xx_unlock_mmio(bcm, flags);
6645 +}
6646 +
6647 +static void bcm43xx_periodic_tasks_delete(struct bcm43xx_private *bcm)
6648 +{
6649 + del_timer_sync(&bcm->periodic_tasks);
6650 +}
6651 +
6652 +static void bcm43xx_periodic_tasks_setup(struct bcm43xx_private *bcm)
6653 +{
6654 + struct timer_list *timer = &(bcm->periodic_tasks);
6655 +
6656 + assert(bcm->initialized);
6657 + setup_timer(timer,
6658 + bcm43xx_periodic_task_handler,
6659 + (unsigned long)bcm);
6660 + timer->expires = jiffies;
6661 + add_timer(timer);
6662 +}
6663 +
6664 +static void bcm43xx_free_modes(struct bcm43xx_private *bcm)
6665 +{
6666 + struct ieee80211_hw *ieee = bcm->ieee;
6667 + int i;
6668 +
6669 + for (i = 0; i < ieee->num_modes; i++) {
6670 + kfree(ieee->modes[i].channels);
6671 + kfree(ieee->modes[i].rates);
6672 + }
6673 + kfree(ieee->modes);
6674 + ieee->modes = NULL;
6675 + ieee->num_modes = 0;
6676 +}
6677 +
6678 +static int bcm43xx_append_mode(struct ieee80211_hw *ieee,
6679 + int mode_id,
6680 + int nr_channels,
6681 + const struct ieee80211_channel *channels,
6682 + int nr_rates,
6683 + const struct ieee80211_rate *rates)
6684 +{
6685 + struct ieee80211_hw_modes *mode;
6686 + int err = -ENOMEM;
6687 +
6688 + mode = &(ieee->modes[ieee->num_modes]);
6689 +
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)
6694 + goto out;
6695 + memcpy(mode->channels, channels, sizeof(*channels) * nr_channels);
6696 +
6697 + mode->num_rates = nr_rates;
6698 + mode->rates = kzalloc(sizeof(*rates) * nr_rates, GFP_KERNEL);
6699 + if (!mode->rates)
6700 + goto err_free_channels;
6701 + memcpy(mode->rates, rates, sizeof(*rates) * nr_rates);
6702 +
6703 + ieee->num_modes++;
6704 + err = 0;
6705 +out:
6706 + return err;
6707 +
6708 +err_free_channels:
6709 + kfree(mode->channels);
6710 + goto out;
6711 +}
6712 +
6713 +static int bcm43xx_setup_modes_aphy(struct bcm43xx_private *bcm)
6714 +{
6715 + int err = 0;
6716 +
6717 + static const struct ieee80211_rate rates[] = {
6718 + {
6719 + .rate = 60,
6720 + .val = BCM43xx_OFDM_RATE_6MB,
6721 + .flags = IEEE80211_RATE_OFDM,
6722 + .val2 = BCM43xx_OFDM_RATE_6MB,
6723 + }, {
6724 + .rate = 90,
6725 + .val = BCM43xx_OFDM_RATE_9MB,
6726 + .flags = IEEE80211_RATE_OFDM,
6727 + .val2 = BCM43xx_OFDM_RATE_9MB,
6728 + }, {
6729 + .rate = 120,
6730 + .val = BCM43xx_OFDM_RATE_12MB,
6731 + .flags = IEEE80211_RATE_OFDM,
6732 + .val2 = BCM43xx_OFDM_RATE_12MB,
6733 + }, {
6734 + .rate = 180,
6735 + .val = BCM43xx_OFDM_RATE_18MB,
6736 + .flags = IEEE80211_RATE_OFDM,
6737 + .val2 = BCM43xx_OFDM_RATE_18MB,
6738 + }, {
6739 + .rate = 240,
6740 + .val = BCM43xx_OFDM_RATE_24MB,
6741 + .flags = IEEE80211_RATE_OFDM,
6742 + .val2 = BCM43xx_OFDM_RATE_24MB,
6743 + }, {
6744 + .rate = 360,
6745 + .val = BCM43xx_OFDM_RATE_36MB,
6746 + .flags = IEEE80211_RATE_OFDM,
6747 + .val2 = BCM43xx_OFDM_RATE_36MB,
6748 + }, {
6749 + .rate = 480,
6750 + .val = BCM43xx_OFDM_RATE_48MB,
6751 + .flags = IEEE80211_RATE_OFDM,
6752 + .val2 = BCM43xx_OFDM_RATE_48MB,
6753 + }, {
6754 + .rate = 540,
6755 + .val = BCM43xx_OFDM_RATE_54MB,
6756 + .flags = IEEE80211_RATE_OFDM,
6757 + .val2 = BCM43xx_OFDM_RATE_54MB,
6758 + },
6759 + };
6760 + static const struct ieee80211_channel channels[] = {
6761 + {
6762 + .chan = 36,
6763 + .freq = 5180,
6764 + .val = 36,
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,
6770 + }, {
6771 + .chan = 40,
6772 + .freq = 5200,
6773 + .val = 40,
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,
6779 + }, {
6780 + .chan = 44,
6781 + .freq = 5220,
6782 + .val = 44,
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,
6788 + }, {
6789 + .chan = 48,
6790 + .freq = 5240,
6791 + .val = 48,
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,
6797 + }, {
6798 + .chan = 52,
6799 + .freq = 5260,
6800 + .val = 52,
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,
6806 + }, {
6807 + .chan = 56,
6808 + .freq = 5280,
6809 + .val = 56,
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,
6815 + }, {
6816 + .chan = 60,
6817 + .freq = 5300,
6818 + .val = 60,
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,
6824 + }, {
6825 + .chan = 64,
6826 + .freq = 5320,
6827 + .val = 64,
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,
6833 + }, {
6834 + .chan = 149,
6835 + .freq = 5745,
6836 + .val = 149,
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,
6842 + }, {
6843 + .chan = 153,
6844 + .freq = 5765,
6845 + .val = 153,
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,
6851 + }, {
6852 + .chan = 157,
6853 + .freq = 5785,
6854 + .val = 157,
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,
6860 + }, {
6861 + .chan = 161,
6862 + .freq = 5805,
6863 + .val = 161,
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,
6869 + }, {
6870 + .chan = 165,
6871 + .freq = 5825,
6872 + .val = 165,
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,
6878 + },
6879 + };
6880 +
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);
6885 + }
6886 +
6887 + return err;
6888 +}
6889 +
6890 +static int bcm43xx_setup_modes_bphy(struct bcm43xx_private *bcm)
6891 +{
6892 + int err = 0;
6893 +
6894 + static const struct ieee80211_rate rates[] = {
6895 + {
6896 + .rate = 10,
6897 + .val = BCM43xx_CCK_RATE_1MB,
6898 + .flags = IEEE80211_RATE_CCK,
6899 + .val2 = BCM43xx_CCK_RATE_1MB,
6900 + }, {
6901 + .rate = 20,
6902 + .val = BCM43xx_CCK_RATE_2MB,
6903 + .flags = IEEE80211_RATE_CCK_2,
6904 + .val2 = BCM43xx_CCK_RATE_2MB,
6905 + }, {
6906 + .rate = 55,
6907 + .val = BCM43xx_CCK_RATE_5MB,
6908 + .flags = IEEE80211_RATE_CCK_2,
6909 + .val2 = BCM43xx_CCK_RATE_5MB,
6910 + }, {
6911 + .rate = 110,
6912 + .val = BCM43xx_CCK_RATE_11MB,
6913 + .flags = IEEE80211_RATE_CCK_2,
6914 + .val2 = BCM43xx_CCK_RATE_11MB,
6915 + },
6916 + };
6917 + static const struct ieee80211_channel channels[] = {
6918 + {
6919 + .chan = 1,
6920 + .freq = 2412,
6921 + .val = 1,
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,
6927 + }, {
6928 + .chan = 2,
6929 + .freq = 2417,
6930 + .val = 2,
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,
6936 + }, {
6937 + .chan = 3,
6938 + .freq = 2422,
6939 + .val = 3,
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,
6945 + }, {
6946 + .chan = 4,
6947 + .freq = 2427,
6948 + .val = 4,
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,
6954 + }, {
6955 + .chan = 5,
6956 + .freq = 2432,
6957 + .val = 5,
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,
6963 + }, {
6964 + .chan = 6,
6965 + .freq = 2437,
6966 + .val = 6,
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,
6972 + }, {
6973 + .chan = 7,
6974 + .freq = 2442,
6975 + .val = 7,
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,
6981 + }, {
6982 + .chan = 8,
6983 + .freq = 2447,
6984 + .val = 8,
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,
6990 + }, {
6991 + .chan = 9,
6992 + .freq = 2452,
6993 + .val = 9,
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,
6999 + }, {
7000 + .chan = 10,
7001 + .freq = 2457,
7002 + .val = 10,
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,
7008 + }, {
7009 + .chan = 11,
7010 + .freq = 2462,
7011 + .val = 11,
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,
7017 + }, {
7018 + .chan = 12,
7019 + .freq = 2467,
7020 + .val = 12,
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,
7026 + }, {
7027 + .chan = 13,
7028 + .freq = 2472,
7029 + .val = 13,
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,
7035 + }, /*{
7036 + .chan = 14,
7037 + .freq = 2484,
7038 + .val = 14,
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,
7044 + },*/
7045 + };
7046 +
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);
7052 + }
7053 +
7054 + return err;
7055 +}
7056 +
7057 +static int bcm43xx_setup_modes_gphy(struct bcm43xx_private *bcm)
7058 +{
7059 + int err = 0;
7060 +
7061 + static const struct ieee80211_rate rates[] = {
7062 + {
7063 + .rate = 10,
7064 + .val = BCM43xx_CCK_RATE_1MB,
7065 + .flags = IEEE80211_RATE_CCK,
7066 + .val2 = BCM43xx_CCK_RATE_1MB,
7067 + }, {
7068 + .rate = 20,
7069 + .val = BCM43xx_CCK_RATE_2MB,
7070 + .flags = IEEE80211_RATE_CCK_2,
7071 + .val2 = BCM43xx_CCK_RATE_2MB,
7072 + }, {
7073 + .rate = 55,
7074 + .val = BCM43xx_CCK_RATE_5MB,
7075 + .flags = IEEE80211_RATE_CCK_2,
7076 + .val2 = BCM43xx_CCK_RATE_5MB,
7077 + }, {
7078 + .rate = 60,
7079 + .val = BCM43xx_OFDM_RATE_6MB,
7080 + .flags = IEEE80211_RATE_OFDM,
7081 + .val2 = BCM43xx_OFDM_RATE_6MB,
7082 + }, {
7083 + .rate = 90,
7084 + .val = BCM43xx_OFDM_RATE_9MB,
7085 + .flags = IEEE80211_RATE_OFDM,
7086 + .val2 = BCM43xx_OFDM_RATE_9MB,
7087 + }, {
7088 + .rate = 110,
7089 + .val = BCM43xx_CCK_RATE_11MB,
7090 + .flags = IEEE80211_RATE_CCK_2,
7091 + .val2 = BCM43xx_CCK_RATE_11MB,
7092 + }, {
7093 + .rate = 120,
7094 + .val = BCM43xx_OFDM_RATE_12MB,
7095 + .flags = IEEE80211_RATE_OFDM,
7096 + .val2 = BCM43xx_OFDM_RATE_12MB,
7097 + }, {
7098 + .rate = 180,
7099 + .val = BCM43xx_OFDM_RATE_18MB,
7100 + .flags = IEEE80211_RATE_OFDM,
7101 + .val2 = BCM43xx_OFDM_RATE_18MB,
7102 + }, {
7103 + .rate = 240,
7104 + .val = BCM43xx_OFDM_RATE_24MB,
7105 + .flags = IEEE80211_RATE_OFDM,
7106 + .val2 = BCM43xx_OFDM_RATE_24MB,
7107 + }, {
7108 + .rate = 360,
7109 + .val = BCM43xx_OFDM_RATE_36MB,
7110 + .flags = IEEE80211_RATE_OFDM,
7111 + .val2 = BCM43xx_OFDM_RATE_36MB,
7112 + }, {
7113 + .rate = 480,
7114 + .val = BCM43xx_OFDM_RATE_48MB,
7115 + .flags = IEEE80211_RATE_OFDM,
7116 + .val2 = BCM43xx_OFDM_RATE_48MB,
7117 + }, {
7118 + .rate = 540,
7119 + .val = BCM43xx_OFDM_RATE_54MB,
7120 + .flags = IEEE80211_RATE_OFDM,
7121 + .val2 = BCM43xx_OFDM_RATE_54MB,
7122 + },
7123 + };
7124 + static const struct ieee80211_channel channels[] = {
7125 + {
7126 + .chan = 1,
7127 + .freq = 2412,
7128 + .val = 1,
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,
7134 + }, {
7135 + .chan = 2,
7136 + .freq = 2417,
7137 + .val = 2,
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,
7143 + }, {
7144 + .chan = 3,
7145 + .freq = 2422,
7146 + .val = 3,
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,
7152 + }, {
7153 + .chan = 4,
7154 + .freq = 2427,
7155 + .val = 4,
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,
7161 + }, {
7162 + .chan = 5,
7163 + .freq = 2432,
7164 + .val = 5,
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,
7170 + }, {
7171 + .chan = 6,
7172 + .freq = 2437,
7173 + .val = 6,
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,
7179 + }, {
7180 + .chan = 7,
7181 + .freq = 2442,
7182 + .val = 7,
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,
7188 + }, {
7189 + .chan = 8,
7190 + .freq = 2447,
7191 + .val = 8,
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,
7197 + }, {
7198 + .chan = 9,
7199 + .freq = 2452,
7200 + .val = 9,
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,
7206 + }, {
7207 + .chan = 10,
7208 + .freq = 2457,
7209 + .val = 10,
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,
7215 + }, {
7216 + .chan = 11,
7217 + .freq = 2462,
7218 + .val = 11,
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,
7224 + }, {
7225 + .chan = 12,
7226 + .freq = 2467,
7227 + .val = 12,
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,
7233 + }, {
7234 + .chan = 13,
7235 + .freq = 2472,
7236 + .val = 13,
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,
7242 + }, /*{
7243 + .chan = 14,
7244 + .freq = 2484,
7245 + .val = 14,
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,
7251 + },*/
7252 + };
7253 +
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);
7258 + }
7259 +
7260 + return err;
7261 +}
7262 +
7263 +static int bcm43xx_setup_modes(struct bcm43xx_private *bcm)
7264 +{
7265 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7266 + int err = -ENOMEM;
7267 + int nr;
7268 + struct ieee80211_hw *ieee = bcm->ieee;
7269 +
7270 + if (phy->type == BCM43xx_PHYTYPE_A)
7271 + nr = 1;
7272 + else if (phy->type == BCM43xx_PHYTYPE_B)
7273 + nr = 1;
7274 + else
7275 + nr = 2;
7276 + ieee->modes = kzalloc(sizeof(*(ieee->modes)) * nr, GFP_KERNEL);
7277 + if (!ieee->modes)
7278 + goto out;
7279 + ieee->num_modes = 0;
7280 +
7281 + err = bcm43xx_setup_modes_aphy(bcm);
7282 + if (err)
7283 + goto error;
7284 + err = bcm43xx_setup_modes_gphy(bcm);
7285 + if (err)
7286 + goto error;
7287 + err = bcm43xx_setup_modes_bphy(bcm);
7288 + if (err)
7289 + goto error;
7290 +
7291 + assert(ieee->num_modes == nr && nr > 0);
7292 +out:
7293 + return err;
7294 +
7295 +error:
7296 + bcm43xx_free_modes(bcm);
7297 + goto out;
7298 +}
7299 +
7300 +static void bcm43xx_security_init(struct bcm43xx_private *bcm)
7301 +{
7302 + bcm->security_offset = bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED,
7303 + 0x0056) * 2;
7304 + bcm43xx_clear_keys(bcm);
7305 +}
7306 +
7307 +/* This is the opposite of bcm43xx_init_board() */
7308 +static void bcm43xx_free_board(struct bcm43xx_private *bcm)
7309 +{
7310 + int i, err;
7311 + unsigned long flags;
7312 +
7313 + bcm43xx_sysfs_unregister(bcm);
7314 +
7315 + bcm43xx_periodic_tasks_delete(bcm);
7316 +
7317 + bcm43xx_lock(bcm, flags);
7318 + bcm->initialized = 0;
7319 + bcm->shutting_down = 1;
7320 + bcm43xx_unlock(bcm, flags);
7321 +
7322 + for (i = 0; i < BCM43xx_MAX_80211_CORES; i++) {
7323 + if (!bcm->core_80211[i].available)
7324 + continue;
7325 + if (!bcm->core_80211[i].initialized)
7326 + continue;
7327 +
7328 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7329 + assert(err == 0);
7330 + bcm43xx_wireless_core_cleanup(bcm);
7331 + }
7332 +
7333 + bcm43xx_pctl_set_crystal(bcm, 0);
7334 + bcm43xx_free_modes(bcm);
7335 +
7336 + bcm43xx_lock(bcm, flags);
7337 + bcm->shutting_down = 0;
7338 + bcm43xx_unlock(bcm, flags);
7339 +}
7340 +
7341 +static int bcm43xx_init_board(struct bcm43xx_private *bcm)
7342 +{
7343 + int i, err;
7344 + int connect_phy;
7345 + unsigned long flags;
7346 +
7347 + might_sleep();
7348 +
7349 + bcm43xx_lock(bcm, flags);
7350 + bcm->initialized = 0;
7351 + bcm->shutting_down = 0;
7352 + bcm43xx_unlock(bcm, flags);
7353 +
7354 + err = bcm43xx_pctl_set_crystal(bcm, 1);
7355 + if (err)
7356 + goto out;
7357 + err = bcm43xx_pctl_init(bcm);
7358 + if (err)
7359 + goto err_crystal_off;
7360 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_FAST);
7361 + if (err)
7362 + goto err_crystal_off;
7363 +
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);
7368 + if (err)
7369 + goto err_80211_unwind;
7370 +
7371 + /* Enable the selected wireless core.
7372 + * Connect PHY only on the first core.
7373 + */
7374 + if (!bcm43xx_core_enabled(bcm)) {
7375 + if (bcm->nr_80211_available == 1) {
7376 + connect_phy = bcm43xx_current_phy(bcm)->connected;
7377 + } else {
7378 + if (i == 0)
7379 + connect_phy = 1;
7380 + else
7381 + connect_phy = 0;
7382 + }
7383 + bcm43xx_wireless_core_reset(bcm, connect_phy);
7384 + }
7385 +
7386 + if (i != 0)
7387 + bcm43xx_wireless_core_mark_inactive(bcm, &bcm->core_80211[0]);
7388 +
7389 + err = bcm43xx_wireless_core_init(bcm);
7390 + if (err)
7391 + goto err_80211_unwind;
7392 +
7393 + if (i != 0) {
7394 + bcm43xx_mac_suspend(bcm);
7395 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7396 + bcm43xx_radio_turn_off(bcm);
7397 + }
7398 + }
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);
7403 + }
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);
7413 +
7414 + bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_DYNAMIC);
7415 +
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);
7420 + }
7421 +
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);
7426 +
7427 + bcm43xx_periodic_tasks_setup(bcm);
7428 + bcm43xx_sysfs_register(bcm);
7429 +
7430 + assert(err == 0);
7431 +out:
7432 + return err;
7433 +
7434 +err_80211_unwind:
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)
7439 + continue;
7440 + bcm43xx_interrupt_disable(bcm, BCM43xx_IRQ_ALL);
7441 + bcm43xx_wireless_core_cleanup(bcm);
7442 + }
7443 +err_crystal_off:
7444 + bcm43xx_pctl_set_crystal(bcm, 0);
7445 + goto out;
7446 +}
7447 +
7448 +static void bcm43xx_detach_board(struct bcm43xx_private *bcm)
7449 +{
7450 + struct pci_dev *pci_dev = bcm->pci_dev;
7451 + int i;
7452 +
7453 + bcm43xx_chipset_detach(bcm);
7454 + /* Do _not_ access the chip, after it is detached. */
7455 + iounmap(bcm->mmio_addr);
7456 +
7457 + pci_release_regions(pci_dev);
7458 + pci_disable_device(pci_dev);
7459 +
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);
7465 + }
7466 +}
7467 +
7468 +static int bcm43xx_read_phyinfo(struct bcm43xx_private *bcm)
7469 +{
7470 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
7471 + u16 value;
7472 + u8 phy_version;
7473 + u8 phy_type;
7474 + u8 phy_rev;
7475 + int phy_rev_ok = 1;
7476 + void *p;
7477 +
7478 + value = bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_VER);
7479 +
7480 + phy_version = (value & 0xF000) >> 12;
7481 + phy_type = (value & 0x0F00) >> 8;
7482 + phy_rev = (value & 0x000F);
7483 +
7484 + dprintk(KERN_INFO PFX "Detected PHY: Version: %x, Type %x, Revision %x\n",
7485 + phy_version, phy_type, phy_rev);
7486 +
7487 + switch (phy_type) {
7488 + case BCM43xx_PHYTYPE_A:
7489 + if (phy_rev >= 4)
7490 + phy_rev_ok = 0;
7491 + break;
7492 + case BCM43xx_PHYTYPE_B:
7493 + if (phy_rev != 2 && phy_rev != 4 && phy_rev != 6 && phy_rev != 7)
7494 + phy_rev_ok = 0;
7495 + break;
7496 + case BCM43xx_PHYTYPE_G:
7497 + if (phy_rev > 7)
7498 + phy_rev_ok = 0;
7499 + break;
7500 + default:
7501 + printk(KERN_ERR PFX "Error: Unknown PHY Type %x\n",
7502 + phy_type);
7503 + return -ENODEV;
7504 + };
7505 + if (!phy_rev_ok) {
7506 + printk(KERN_WARNING PFX "Invalid PHY Revision %x\n",
7507 + phy_rev);
7508 + }
7509 +
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,
7515 + GFP_KERNEL);
7516 + if (!p)
7517 + return -ENOMEM;
7518 + phy->_lo_pairs = p;
7519 + }
7520 +
7521 + return 0;
7522 +}
7523 +
7524 +static int bcm43xx_attach_board(struct bcm43xx_private *bcm)
7525 +{
7526 + struct pci_dev *pci_dev = bcm->pci_dev;
7527 + struct net_device *net_dev = bcm->net_dev;
7528 + int err;
7529 + int i;
7530 + unsigned long mmio_start, mmio_flags, mmio_len;
7531 + u32 coremask;
7532 +
7533 + err = pci_enable_device(pci_dev);
7534 + if (err) {
7535 + printk(KERN_ERR PFX "unable to wake up pci device (%i)\n", err);
7536 + goto out;
7537 + }
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));
7545 + err = -ENODEV;
7546 + goto err_pci_disable;
7547 + }
7548 + err = pci_request_regions(pci_dev, KBUILD_MODNAME);
7549 + if (err) {
7550 + printk(KERN_ERR PFX
7551 + "could not access PCI resources (%i)\n", err);
7552 + goto err_pci_disable;
7553 + }
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));
7560 + err = -EIO;
7561 + goto err_pci_release;
7562 + }
7563 + bcm->mmio_len = mmio_len;
7564 + net_dev->base_addr = (unsigned long)bcm->mmio_addr;
7565 +
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);
7572 +
7573 + err = bcm43xx_chipset_attach(bcm);
7574 + if (err)
7575 + goto err_iounmap;
7576 + err = bcm43xx_pctl_init(bcm);
7577 + if (err)
7578 + goto err_chipset_detach;
7579 + err = bcm43xx_probe_cores(bcm);
7580 + if (err)
7581 + goto err_chipset_detach;
7582 +
7583 + /* Attach all IO cores to the backplane. */
7584 + coremask = 0;
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);
7589 + if (err) {
7590 + printk(KERN_ERR PFX "Backplane->PCI connection failed!\n");
7591 + goto err_chipset_detach;
7592 + }
7593 +
7594 + err = bcm43xx_sprom_extract(bcm);
7595 + if (err)
7596 + goto err_chipset_detach;
7597 + err = bcm43xx_leds_init(bcm);
7598 + if (err)
7599 + goto err_chipset_detach;
7600 +
7601 + for (i = 0; i < bcm->nr_80211_available; i++) {
7602 + err = bcm43xx_switch_core(bcm, &bcm->core_80211[i]);
7603 + assert(err != -ENODEV);
7604 + if (err)
7605 + goto err_80211_unwind;
7606 +
7607 + /* Enable the selected wireless core.
7608 + * Connect PHY only on the first core.
7609 + */
7610 + bcm43xx_wireless_core_reset(bcm, (i == 0));
7611 +
7612 + err = bcm43xx_read_phyinfo(bcm);
7613 + if (err && (i == 0))
7614 + goto err_80211_unwind;
7615 +
7616 + err = bcm43xx_read_radioinfo(bcm);
7617 + if (err && (i == 0))
7618 + goto err_80211_unwind;
7619 +
7620 + err = bcm43xx_validate_chip(bcm);
7621 + if (err && (i == 0))
7622 + goto err_80211_unwind;
7623 +
7624 + bcm43xx_radio_turn_off(bcm);
7625 + err = bcm43xx_phy_init_tssi2dbm_table(bcm);
7626 + if (err)
7627 + goto err_80211_unwind;
7628 + bcm43xx_wireless_core_disable(bcm);
7629 + }
7630 + bcm43xx_pctl_set_crystal(bcm, 0);
7631 +
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);
7635 + else
7636 + memcpy(bcm->net_dev->dev_addr, bcm->sprom.il0macaddr, 6);
7637 +
7638 + snprintf(bcm->nick, IW_ESSID_MAX_SIZE,
7639 + "Broadcom %04X", bcm->chip_id);
7640 +
7641 + assert(err == 0);
7642 +out:
7643 + return err;
7644 +
7645 +err_80211_unwind:
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);
7650 + }
7651 +err_chipset_detach:
7652 + bcm43xx_chipset_detach(bcm);
7653 +err_iounmap:
7654 + iounmap(bcm->mmio_addr);
7655 +err_pci_release:
7656 + pci_release_regions(pci_dev);
7657 +err_pci_disable:
7658 + pci_disable_device(pci_dev);
7659 + goto out;
7660 +}
7661 +
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)
7666 +{
7667 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7668 + int err = -ENODEV;
7669 + unsigned long flags;
7670 +
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);
7675 + else
7676 + err = bcm43xx_dma_tx(bcm, skb, ctl);
7677 + }
7678 + bcm43xx_unlock_mmio(bcm, flags);
7679 +
7680 + return err;
7681 +}
7682 +
7683 +static int bcm43xx_net_reset(struct net_device *net_dev)
7684 +{
7685 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7686 + unsigned long flags;
7687 +
7688 + bcm43xx_lock_mmio(bcm, flags);
7689 + bcm43xx_controller_restart(bcm, "IEEE reset");
7690 + bcm43xx_unlock_mmio(bcm, flags);
7691 +
7692 + return 0;
7693 +}
7694 +
7695 +static int bcm43xx_net_config(struct net_device *net_dev,
7696 + struct ieee80211_conf *conf)
7697 +{
7698 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7699 + struct bcm43xx_radioinfo *radio;
7700 + struct bcm43xx_phyinfo *phy;
7701 + unsigned long flags;
7702 +
7703 + bcm43xx_lock_mmio(bcm, flags);
7704 + if (!bcm->initialized) {
7705 + bcm43xx_unlock_mmio(bcm, flags);
7706 + return 0;
7707 + }
7708 + radio = bcm43xx_current_radio(bcm);
7709 + phy = bcm43xx_current_phy(bcm);
7710 +
7711 + if (conf->channel != radio->channel)
7712 + bcm43xx_radio_selectchannel(bcm, conf->channel, 0);
7713 +
7714 + if (conf->mode != bcm->iw_mode)
7715 + bcm43xx_set_iwmode(bcm, conf->mode);
7716 +
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);
7721 + else
7722 + bcm43xx_short_slot_timing_disable(bcm);
7723 + }
7724 +
7725 + if (conf->power_level != 0) {
7726 + radio->power_level = conf->power_level;
7727 + bcm43xx_phy_xmitpower(bcm);
7728 + }
7729 +//FIXME: This does not seem to wake up:
7730 +#if 0
7731 + if (conf->power_level == 0) {
7732 + if (radio->enabled)
7733 + bcm43xx_radio_turn_off(bcm);
7734 + } else {
7735 + if (!radio->enabled)
7736 + bcm43xx_radio_turn_on(bcm);
7737 + }
7738 +#endif
7739 +
7740 + //TODO: phymode
7741 + //TODO: antennas
7742 +
7743 + bcm43xx_unlock_mmio(bcm, flags);
7744 +
7745 + return 0;
7746 +}
7747 +
7748 +static int bcm43xx_net_set_key(struct net_device *net_dev,
7749 + set_key_cmd cmd,
7750 + u8 *addr,
7751 + struct ieee80211_key_conf *key,
7752 + int aid)
7753 +{
7754 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7755 + unsigned long flags;
7756 + u8 algorithm;
7757 + u8 index;
7758 + int err = -EINVAL;
7759 +
7760 + switch (key->alg) {
7761 + default:
7762 + case ALG_NONE:
7763 + case ALG_NULL:
7764 + algorithm = BCM43xx_SEC_ALGO_NONE;
7765 + break;
7766 + case ALG_WEP:
7767 + if (key->keylen == 5)
7768 + algorithm = BCM43xx_SEC_ALGO_WEP;
7769 + else
7770 + algorithm = BCM43xx_SEC_ALGO_WEP104;
7771 + break;
7772 + case ALG_TKIP:
7773 + algorithm = BCM43xx_SEC_ALGO_TKIP;
7774 + break;
7775 + case ALG_CCMP:
7776 + algorithm = BCM43xx_SEC_ALGO_AES;
7777 + break;
7778 + }
7779 +
7780 + index = (u8)(key->keyidx);
7781 + if (index >= ARRAY_SIZE(bcm->key))
7782 + goto out;
7783 + bcm43xx_lock_mmio(bcm, flags);
7784 + switch (cmd) {
7785 + case SET_KEY:
7786 + err = bcm43xx_key_write(bcm, index, algorithm,
7787 + key->key, key->keylen,
7788 + addr);
7789 + if (err)
7790 + goto out_unlock;
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;
7796 + break;
7797 + case DISABLE_KEY:
7798 + bcm->key[index].enabled = 0;
7799 + err = 0;
7800 + break;
7801 + case REMOVE_ALL_KEYS:
7802 + bcm43xx_clear_keys(bcm);
7803 + err = 0;
7804 + break;
7805 + case ENABLE_COMPRESSION:
7806 + case DISABLE_COMPRESSION:
7807 + err = 0;
7808 + break;
7809 + }
7810 +out_unlock:
7811 + bcm43xx_unlock_mmio(bcm, flags);
7812 +out:
7813 + return err;
7814 +}
7815 +
7816 +static int bcm43xx_net_conf_tx(struct net_device *net_dev,
7817 + int queue,
7818 + const struct ieee80211_tx_queue_params *params)
7819 +{
7820 + return 0;
7821 +}
7822 +
7823 +static int bcm43xx_net_get_tx_stats(struct net_device *net_dev,
7824 + struct ieee80211_tx_queue_stats *stats)
7825 +{
7826 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7827 + unsigned long flags;
7828 +
7829 + bcm43xx_lock(bcm, flags);
7830 + if (bcm43xx_using_pio(bcm))
7831 + bcm43xx_pio_get_tx_stats(bcm, stats);
7832 + else
7833 + bcm43xx_dma_get_tx_stats(bcm, stats);
7834 + bcm43xx_unlock(bcm, flags);
7835 +
7836 + return 0;
7837 +}
7838 +
7839 +static int bcm43xx_net_get_stats(struct net_device *net_dev,
7840 + struct ieee80211_low_level_stats *stats)
7841 +{
7842 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7843 + unsigned long flags;
7844 +
7845 + bcm43xx_lock(bcm, flags);
7846 + memcpy(stats, &bcm->ieee_stats, sizeof(*stats));
7847 + bcm43xx_unlock(bcm, flags);
7848 +
7849 + return 0;
7850 +}
7851 +
7852 +#ifdef CONFIG_NET_POLL_CONTROLLER
7853 +static void bcm43xx_net_poll_controller(struct net_device *net_dev)
7854 +{
7855 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7856 + unsigned long flags;
7857 +
7858 + local_irq_save(flags);
7859 + bcm43xx_interrupt_handler(bcm->irq, bcm, NULL);
7860 + local_irq_restore(flags);
7861 +}
7862 +#endif /* CONFIG_NET_POLL_CONTROLLER */
7863 +
7864 +static int bcm43xx_net_open(struct net_device *net_dev)
7865 +{
7866 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7867 +
7868 + return bcm43xx_init_board(bcm);
7869 +}
7870 +
7871 +static int bcm43xx_net_stop(struct net_device *net_dev)
7872 +{
7873 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
7874 +
7875 + if (bcm->initialized) {
7876 + bcm43xx_disable_interrupts_sync(bcm, NULL);
7877 + bcm43xx_free_board(bcm);
7878 + }
7879 +
7880 + return 0;
7881 +}
7882 +
7883 +/* Initialization of struct net_device, just after allocation. */
7884 +static void bcm43xx_netdev_setup(struct net_device *net_dev)
7885 +{
7886 +#ifdef CONFIG_NET_POLL_CONTROLLER
7887 + net_dev->poll_controller = bcm43xx_net_poll_controller;
7888 +#endif
7889 + SET_ETHTOOL_OPS(net_dev, &bcm43xx_ethtool_ops);
7890 +}
7891 +
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)
7896 +{
7897 + int err;
7898 +
7899 + bcm->ieee = 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;
7911 + } else {
7912 + err = pci_set_dma_mask(pci_dev, DMA_30BIT_MASK);
7913 + err |= pci_set_consistent_dma_mask(pci_dev, DMA_30BIT_MASK);
7914 + if (err) {
7915 +#ifdef CONFIG_BCM43XX_D80211_PIO
7916 + printk(KERN_WARNING PFX "DMA not supported. Falling back to PIO.\n");
7917 + bcm->__using_pio = 1;
7918 +#else
7919 + printk(KERN_ERR PFX "FATAL: DMA not supported and PIO not configured. "
7920 + "Recompile the driver with PIO support, please.\n");
7921 + return -ENODEV;
7922 +#endif /* CONFIG_BCM43XX_D80211_PIO */
7923 + }
7924 + }
7925 +
7926 + return 0;
7927 +}
7928 +
7929 +static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
7930 + const struct pci_device_id *ent)
7931 +{
7932 + struct net_device *net_dev;
7933 + struct bcm43xx_private *bcm;
7934 + struct ieee80211_hw *ieee;
7935 + int err = -ENOMEM;
7936 +
7937 +#ifdef CONFIG_BCM947XX
7938 + if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
7939 + return -ENODEV;
7940 +#endif
7941 +
7942 +#ifdef DEBUG_SINGLE_DEVICE_ONLY
7943 + if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
7944 + return -ENODEV;
7945 +#endif
7946 +
7947 + ieee = kzalloc(sizeof(*ieee), GFP_KERNEL);
7948 + if (!ieee)
7949 + goto out;
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;
7961 + ieee->queues = 1;
7962 + ieee->get_tx_stats = bcm43xx_net_get_tx_stats;
7963 + ieee->conf_tx = bcm43xx_net_conf_tx;
7964 + ieee->wep_include_iv = 1;
7965 +
7966 + net_dev = ieee80211_alloc_hw(sizeof(*bcm), bcm43xx_netdev_setup);
7967 + if (!net_dev) {
7968 + printk(KERN_ERR PFX
7969 + "could not allocate ieee80211 device %s\n",
7970 + pci_name(pdev));
7971 + goto err_free_ieee;
7972 + }
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);
7977 + if (err)
7978 + goto err_free_netdev;
7979 +
7980 + pci_set_drvdata(pdev, net_dev);
7981 +
7982 + err = bcm43xx_attach_board(bcm);
7983 + if (err)
7984 + goto err_free_netdev;
7985 + err = ieee80211_register_hw(net_dev, ieee);
7986 + if (err)
7987 + goto err_detach_board;
7988 +
7989 + bcm43xx_debugfs_add_device(bcm);
7990 +
7991 + assert(err == 0);
7992 +out:
7993 + return err;
7994 +
7995 +err_detach_board:
7996 + bcm43xx_detach_board(bcm);
7997 +err_free_netdev:
7998 + ieee80211_free_hw(net_dev);
7999 +err_free_ieee:
8000 + kfree(ieee);
8001 + goto out;
8002 +}
8003 +
8004 +static void __devexit bcm43xx_remove_one(struct pci_dev *pdev)
8005 +{
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;
8009 +
8010 + bcm43xx_debugfs_remove_device(bcm);
8011 +
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);
8015 +
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);
8023 + kfree(ieee);
8024 +}
8025 +
8026 +/* Hard-reset the chip. Do not call this directly.
8027 + * Use bcm43xx_controller_restart()
8028 + */
8029 +static void bcm43xx_chip_reset(void *_bcm)
8030 +{
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;
8035 + int err;
8036 + int was_initialized = bcm->initialized;
8037 +
8038 + ieee80211_netif_oper(bcm->net_dev, NETIF_DETACH);
8039 + tasklet_disable(&bcm->isr_tasklet);
8040 +
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);
8047 + if (err)
8048 + goto failure;
8049 + err = bcm43xx_attach_board(bcm);
8050 + if (err)
8051 + goto failure;
8052 + if (was_initialized) {
8053 + err = bcm43xx_init_board(bcm);
8054 + if (err)
8055 + goto failure;
8056 + }
8057 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8058 + printk(KERN_INFO PFX "Controller restarted\n");
8059 +
8060 + return;
8061 +failure:
8062 + printk(KERN_ERR PFX "Controller restart failed\n");
8063 +}
8064 +
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.
8068 + */
8069 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason)
8070 +{
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);
8076 +}
8077 +
8078 +#ifdef CONFIG_PM
8079 +
8080 +static int bcm43xx_suspend(struct pci_dev *pdev, pm_message_t state)
8081 +{
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;
8086 +
8087 + dprintk(KERN_INFO PFX "Suspending...\n");
8088 +
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);
8094 +
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");
8100 + return -EAGAIN;
8101 + }
8102 + bcm->firmware_norelease = 1;
8103 + bcm43xx_free_board(bcm);
8104 + bcm->firmware_norelease = 0;
8105 + }
8106 + bcm43xx_chipset_detach(bcm);
8107 +
8108 + pci_save_state(pdev);
8109 + pci_disable_device(pdev);
8110 + pci_set_power_state(pdev, pci_choose_state(pdev, state));
8111 +
8112 + dprintk(KERN_INFO PFX "Device suspended.\n");
8113 +
8114 + return 0;
8115 +}
8116 +
8117 +static int bcm43xx_resume(struct pci_dev *pdev)
8118 +{
8119 + struct net_device *net_dev = pci_get_drvdata(pdev);
8120 + struct bcm43xx_private *bcm = bcm43xx_priv(net_dev);
8121 + int err = 0;
8122 +
8123 + dprintk(KERN_INFO PFX "Resuming...\n");
8124 +
8125 + pci_set_power_state(pdev, 0);
8126 + pci_enable_device(pdev);
8127 + pci_restore_state(pdev);
8128 +
8129 + bcm43xx_chipset_attach(bcm);
8130 + if (bcm->was_initialized) {
8131 + bcm->irq_savedstate = BCM43xx_IRQ_INITIAL;
8132 + err = bcm43xx_init_board(bcm);
8133 + }
8134 + if (err) {
8135 + printk(KERN_ERR PFX "Resume failed!\n");
8136 + return err;
8137 + }
8138 +
8139 + ieee80211_netif_oper(bcm->net_dev, NETIF_ATTACH);
8140 +
8141 + dprintk(KERN_INFO PFX "Device resumed.\n");
8142 +
8143 + return 0;
8144 +}
8145 +
8146 +#endif /* CONFIG_PM */
8147 +
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),
8153 +#ifdef CONFIG_PM
8154 + .suspend = bcm43xx_suspend,
8155 + .resume = bcm43xx_resume,
8156 +#endif /* CONFIG_PM */
8157 +};
8158 +
8159 +static int __init bcm43xx_init(void)
8160 +{
8161 + printk(KERN_INFO KBUILD_MODNAME " driver\n");
8162 + bcm43xx_debugfs_init();
8163 + return pci_register_driver(&bcm43xx_pci_driver);
8164 +}
8165 +
8166 +static void __exit bcm43xx_exit(void)
8167 +{
8168 + pci_unregister_driver(&bcm43xx_pci_driver);
8169 + bcm43xx_debugfs_exit();
8170 +}
8171 +
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
8177 @@ -0,0 +1,177 @@
8178 +/*
8179 +
8180 + Broadcom BCM43xx wireless driver
8181 +
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>
8187 +
8188 + Some parts of the code in this file are derived from the ipw2200
8189 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8190 +
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.
8195 +
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.
8200 +
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.
8205 +
8206 +*/
8207 +
8208 +#ifndef BCM43xx_MAIN_H_
8209 +#define BCM43xx_MAIN_H_
8210 +
8211 +#include "bcm43xx.h"
8212 +
8213 +#ifdef CONFIG_BCM947XX
8214 +#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
8215 +
8216 +static inline void e_aton(char *str, char *dest)
8217 +{
8218 + int i = 0;
8219 + u16 *d = (u16 *) dest;
8220 +
8221 + for (;;) {
8222 + dest[i++] = (char) simple_strtoul(str, NULL, 16);
8223 + str += 2;
8224 + if (!*str++ || i == 6)
8225 + break;
8226 + }
8227 + for (i = 0; i < 3; i++)
8228 + d[i] = cpu_to_be16(d[i]);
8229 +}
8230 +#endif
8231 +
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))
8236 +
8237 +
8238 +/* Lightweight function to convert a frequency (in Mhz) to a channel number. */
8239 +static inline
8240 +u8 bcm43xx_freq_to_channel_a(int freq)
8241 +{
8242 + return ((freq - 5000) / 5);
8243 +}
8244 +static inline
8245 +u8 bcm43xx_freq_to_channel_bg(int freq)
8246 +{
8247 + u8 channel;
8248 +
8249 + if (freq == 2484)
8250 + channel = 14;
8251 + else
8252 + channel = (freq - 2407) / 5;
8253 +
8254 + return channel;
8255 +}
8256 +static inline
8257 +u8 bcm43xx_freq_to_channel(struct bcm43xx_private *bcm,
8258 + int freq)
8259 +{
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);
8263 +}
8264 +
8265 +/* Lightweight function to convert a channel number to a frequency (in Mhz). */
8266 +static inline
8267 +int bcm43xx_channel_to_freq_a(u8 channel)
8268 +{
8269 + return (5000 + (5 * channel));
8270 +}
8271 +static inline
8272 +int bcm43xx_channel_to_freq_bg(u8 channel)
8273 +{
8274 + int freq;
8275 +
8276 + if (channel == 14)
8277 + freq = 2484;
8278 + else
8279 + freq = 2407 + (5 * channel);
8280 +
8281 + return freq;
8282 +}
8283 +static inline
8284 +int bcm43xx_channel_to_freq(struct bcm43xx_private *bcm,
8285 + u8 channel)
8286 +{
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);
8290 +}
8291 +
8292 +/* Lightweight function to check if a channel number is valid.
8293 + * Note that this does _NOT_ check for geographical restrictions!
8294 + */
8295 +static inline
8296 +int bcm43xx_is_valid_channel_a(u8 channel)
8297 +{
8298 + return (channel <= 200);
8299 +}
8300 +static inline
8301 +int bcm43xx_is_valid_channel_bg(u8 channel)
8302 +{
8303 + return (channel >= 1 && channel <= 14);
8304 +}
8305 +static inline
8306 +int bcm43xx_is_valid_channel(struct bcm43xx_private *bcm,
8307 + u8 channel)
8308 +{
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);
8312 +}
8313 +
8314 +static inline
8315 +int bcm43xx_is_cck_rate(int rate)
8316 +{
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);
8321 +}
8322 +
8323 +void bcm43xx_tsf_read(struct bcm43xx_private *bcm, u64 *tsf);
8324 +void bcm43xx_tsf_write(struct bcm43xx_private *bcm, u64 tsf);
8325 +
8326 +void bcm43xx_set_iwmode(struct bcm43xx_private *bcm,
8327 + int iw_mode);
8328 +
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,
8335 + u32 value);
8336 +void bcm43xx_shm_write16(struct bcm43xx_private *bcm,
8337 + u16 routing, u16 offset,
8338 + u16 value);
8339 +
8340 +void bcm43xx_dummy_transmission(struct bcm43xx_private *bcm);
8341 +
8342 +int bcm43xx_switch_core(struct bcm43xx_private *bcm, struct bcm43xx_coreinfo *new_core);
8343 +
8344 +void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy);
8345 +
8346 +void bcm43xx_mac_suspend(struct bcm43xx_private *bcm);
8347 +void bcm43xx_mac_enable(struct bcm43xx_private *bcm);
8348 +
8349 +void bcm43xx_controller_restart(struct bcm43xx_private *bcm, const char *reason);
8350 +
8351 +int bcm43xx_sprom_read(struct bcm43xx_private *bcm, u16 *sprom);
8352 +int bcm43xx_sprom_write(struct bcm43xx_private *bcm, const u16 *sprom);
8353 +
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
8358 @@ -0,0 +1,2347 @@
8359 +/*
8360 +
8361 + Broadcom BCM43xx wireless driver
8362 +
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>
8368 +
8369 + Some parts of the code in this file are derived from the ipw2200
8370 + driver Copyright(c) 2003 - 2004 Intel Corporation.
8371 +
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.
8376 +
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.
8381 +
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.
8386 +
8387 +*/
8388 +
8389 +#include <linux/delay.h>
8390 +#include <linux/pci.h>
8391 +#include <linux/types.h>
8392 +
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"
8399 +
8400 +
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,
8415 + -7, -7, -7, -7,
8416 + -7, -7, -7, -7,
8417 + -7, -7, -7, -7,
8418 +};
8419 +
8420 +static const s8 bcm43xx_tssi2dbm_g_table[] = {
8421 + 77, 77, 77, 76,
8422 + 76, 76, 75, 75,
8423 + 74, 74, 73, 73,
8424 + 73, 72, 72, 71,
8425 + 71, 70, 70, 69,
8426 + 68, 68, 67, 67,
8427 + 66, 65, 65, 64,
8428 + 63, 63, 62, 61,
8429 + 60, 59, 58, 57,
8430 + 56, 55, 54, 53,
8431 + 52, 50, 49, 47,
8432 + 45, 43, 40, 37,
8433 + 33, 28, 22, 14,
8434 + 5, -7, -20, -20,
8435 + -20, -20, -20, -20,
8436 + -20, -20, -20, -20,
8437 +};
8438 +
8439 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm);
8440 +
8441 +
8442 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm)
8443 +{
8444 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8445 +
8446 + assert(irqs_disabled());
8447 + if (bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD) == 0x00000000) {
8448 + phy->is_locked = 0;
8449 + return;
8450 + }
8451 + if (bcm->current_core->rev < 3) {
8452 + bcm43xx_mac_suspend(bcm);
8453 + spin_lock(&phy->lock);
8454 + } else {
8455 + if (bcm->iw_mode != IW_MODE_MASTER)
8456 + bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
8457 + }
8458 + phy->is_locked = 1;
8459 +}
8460 +
8461 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm)
8462 +{
8463 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8464 +
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);
8470 + }
8471 + } else {
8472 + if (bcm->iw_mode != IW_MODE_MASTER)
8473 + bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
8474 + }
8475 + phy->is_locked = 0;
8476 +}
8477 +
8478 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset)
8479 +{
8480 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8481 + return bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_DATA);
8482 +}
8483 +
8484 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val)
8485 +{
8486 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_CONTROL, offset);
8487 + mmiowb();
8488 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_DATA, val);
8489 +}
8490 +
8491 +void bcm43xx_phy_calibrate(struct bcm43xx_private *bcm)
8492 +{
8493 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8494 + unsigned long flags;
8495 +
8496 + bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD); /* Dummy read. */
8497 + if (phy->calibrated)
8498 + return;
8499 + if (phy->type == BCM43xx_PHYTYPE_G && phy->rev == 1) {
8500 + /* We do not want to be preempted while calibrating
8501 + * the hardware.
8502 + */
8503 + local_irq_save(flags);
8504 +
8505 + bcm43xx_wireless_core_reset(bcm, 0);
8506 + bcm43xx_phy_initg(bcm);
8507 + bcm43xx_wireless_core_reset(bcm, 1);
8508 +
8509 + local_irq_restore(flags);
8510 + }
8511 + phy->calibrated = 1;
8512 +}
8513 +
8514 +/* Connect the PHY
8515 + * http://bcm-specs.sipsolutions.net/SetPHY
8516 + */
8517 +int bcm43xx_phy_connect(struct bcm43xx_private *bcm, int connect)
8518 +{
8519 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8520 + u32 flags;
8521 +
8522 + if (bcm->current_core->rev < 5)
8523 + goto out;
8524 +
8525 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATEHIGH);
8526 + if (connect) {
8527 + if (!(flags & 0x00010000))
8528 + return -ENODEV;
8529 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8530 + flags |= (0x800 << 18);
8531 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8532 + } else {
8533 + if (!(flags & 0x00020000))
8534 + return -ENODEV;
8535 + flags = bcm43xx_read32(bcm, BCM43xx_CIR_SBTMSTATELOW);
8536 + flags &= ~(0x800 << 18);
8537 + bcm43xx_write32(bcm, BCM43xx_CIR_SBTMSTATELOW, flags);
8538 + }
8539 +out:
8540 + phy->connected = connect;
8541 + if (connect)
8542 + dprintk(KERN_INFO PFX "PHY connected\n");
8543 + else
8544 + dprintk(KERN_INFO PFX "PHY disconnected\n");
8545 +
8546 + return 0;
8547 +}
8548 +
8549 +/* intialize B PHY power control
8550 + * as described in http://bcm-specs.sipsolutions.net/InitPowerControl
8551 + */
8552 +static void bcm43xx_phy_init_pctl(struct bcm43xx_private *bcm)
8553 +{
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;
8558 +
8559 + assert(phy->type != BCM43xx_PHYTYPE_A);
8560 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8561 + (bcm->board_type == 0x0416))
8562 + return;
8563 +
8564 + bcm43xx_write16(bcm, 0x03E6, bcm43xx_read16(bcm, 0x03E6) & 0xFFDF);
8565 + bcm43xx_phy_write(bcm, 0x0028, 0x8018);
8566 +
8567 + if (phy->type == BCM43xx_PHYTYPE_G) {
8568 + if (!phy->connected)
8569 + return;
8570 + bcm43xx_phy_write(bcm, 0x047A, 0xC111);
8571 + }
8572 + if (phy->savedpctlreg != 0xFFFF)
8573 + return;
8574 +
8575 + if (phy->type == BCM43xx_PHYTYPE_B &&
8576 + phy->rev >= 2 &&
8577 + radio->version == 0x2050) {
8578 + bcm43xx_radio_write16(bcm, 0x0076,
8579 + bcm43xx_radio_read16(bcm, 0x0076) | 0x0084);
8580 + } else {
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);
8587 + else
8588 + bcm43xx_radio_set_txpower_bg(bcm, 0xB, 9, 0);
8589 + must_reset_txpower = 1;
8590 + }
8591 + bcm43xx_dummy_transmission(bcm);
8592 +
8593 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_PCTL);
8594 +
8595 + if (must_reset_txpower)
8596 + bcm43xx_radio_set_txpower_bg(bcm, saved_batt, saved_ratt, saved_txctl1);
8597 + else
8598 + bcm43xx_radio_write16(bcm, 0x0076, bcm43xx_radio_read16(bcm, 0x0076) & 0xFF7B);
8599 + bcm43xx_radio_clear_tssi(bcm);
8600 +}
8601 +
8602 +static void bcm43xx_phy_agcsetup(struct bcm43xx_private *bcm)
8603 +{
8604 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8605 + u16 offset = 0x0000;
8606 +
8607 + if (phy->rev == 1)
8608 + offset = 0x4C00;
8609 +
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);
8614 +
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);
8621 + }
8622 +
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);
8627 +
8628 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0008);
8629 +
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);
8634 +
8635 + if (phy->rev == 1)
8636 + bcm43xx_phy_write(bcm, 0x04A2, (bcm43xx_phy_read(bcm, 0x04A2) & 0xFFF0) | 0x0007);
8637 +
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);
8647 +
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);
8651 + } else {
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);
8655 + }
8656 +
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);
8660 + }
8661 +
8662 + bcm43xx_phy_write(bcm, 0x04A8, (bcm43xx_phy_read(bcm, 0x04A8) & 0x8080) | 0x7874);
8663 + bcm43xx_phy_write(bcm, 0x048E, 0x1C00);
8664 +
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);
8670 + }
8671 +
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);
8676 +}
8677 +
8678 +static void bcm43xx_phy_setupg(struct bcm43xx_private *bcm)
8679 +{
8680 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8681 + u16 i;
8682 +
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);
8690 +
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]);
8697 + } else {
8698 + /* nrssi values are signed 6-bit values. Not sure why we write 0x7654 here... */
8699 + bcm43xx_nrssi_hw_write(bcm, 0xBA98, (s16)0x7654);
8700 +
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);
8708 + }
8709 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x800);
8710 +
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]);
8715 + }
8716 +
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]);
8723 + else
8724 + for (i = 0; i < BCM43xx_ILT_NOISESCALEG_SIZE; i++)
8725 + bcm43xx_ilt_write(bcm, 0x1400 + i, bcm43xx_ilt_noisescaleg2[i]);
8726 +
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]);
8733 +
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);
8742 + }
8743 + bcm43xx_phy_agcsetup(bcm);
8744 +
8745 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8746 + (bcm->board_type == 0x0416) &&
8747 + (bcm->board_revision == 0x0017))
8748 + return;
8749 +
8750 + bcm43xx_ilt_write(bcm, 0x5001, 0x0002);
8751 + bcm43xx_ilt_write(bcm, 0x5002, 0x0001);
8752 + } else {
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);
8760 +
8761 + if ((bcm->board_vendor == PCI_VENDOR_ID_BROADCOM) &&
8762 + (bcm->board_type == 0x0416) &&
8763 + (bcm->board_revision == 0x0017))
8764 + return;
8765 +
8766 + bcm43xx_ilt_write(bcm, 0x0401, 0x0002);
8767 + bcm43xx_ilt_write(bcm, 0x0402, 0x0001);
8768 + }
8769 +}
8770 +
8771 +/* Initialize the noisescaletable for APHY */
8772 +static void bcm43xx_phy_init_noisescaletbl(struct bcm43xx_private *bcm)
8773 +{
8774 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8775 + int i;
8776 +
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);
8781 + else
8782 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8783 + }
8784 + if (phy->rev == 2)
8785 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x6700);
8786 + else
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);
8791 + else
8792 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x2323);
8793 + }
8794 + if (phy->rev == 2)
8795 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0067);
8796 + else
8797 + bcm43xx_phy_write(bcm, BCM43xx_PHY_ILT_A_DATA1, 0x0023);
8798 +}
8799 +
8800 +static void bcm43xx_phy_setupa(struct bcm43xx_private *bcm)
8801 +{
8802 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8803 + u16 i;
8804 +
8805 + assert(phy->type == BCM43xx_PHYTYPE_A);
8806 + switch (phy->rev) {
8807 + case 2:
8808 + bcm43xx_phy_write(bcm, 0x008E, 0x3800);
8809 + bcm43xx_phy_write(bcm, 0x0035, 0x03FF);
8810 + bcm43xx_phy_write(bcm, 0x0036, 0x0400);
8811 +
8812 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8813 +
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);
8818 +
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);
8823 +
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);
8827 +
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);
8833 +
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);
8841 +
8842 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8843 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8844 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8845 +
8846 + for (i = 0; i < 16; i++)
8847 + bcm43xx_ilt_write(bcm, 0x4000 + i, (0x8 + i) & 0x000F);
8848 +
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);
8853 +
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]);
8863 + break;
8864 + case 3:
8865 + for (i = 0; i < 64; i++)
8866 + bcm43xx_ilt_write(bcm, 0x4000 + i, i);
8867 +
8868 + bcm43xx_ilt_write(bcm, 0x3807, 0x0051);
8869 +
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);
8873 +
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);
8879 +
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]);
8886 +
8887 + bcm43xx_phy_write(bcm, 0x0003, 0x1808);
8888 +
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);
8894 +
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);
8902 +
8903 + bcm43xx_ilt_write(bcm, 0x0404, 0x0003);
8904 + bcm43xx_ilt_write(bcm, 0x0405, 0x0003);
8905 + bcm43xx_ilt_write(bcm, 0x0406, 0x0007);
8906 +
8907 + bcm43xx_ilt_write(bcm, 0x3C02, 0x000F);
8908 + bcm43xx_ilt_write(bcm, 0x3C03, 0x0014);
8909 + break;
8910 + default:
8911 + assert(0);
8912 + }
8913 +}
8914 +
8915 +/* Initialize APHY. This is also called for the GPHY in some cases. */
8916 +static void bcm43xx_phy_inita(struct bcm43xx_private *bcm)
8917 +{
8918 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
8919 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8920 + u16 tval;
8921 +
8922 + if (phy->type == BCM43xx_PHYTYPE_A) {
8923 + bcm43xx_phy_setupa(bcm);
8924 + } else {
8925 + bcm43xx_phy_setupg(bcm);
8926 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
8927 + bcm43xx_phy_write(bcm, 0x046E, 0x03CF);
8928 + return;
8929 + }
8930 +
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);
8934 +
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);
8939 +
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);
8945 + } else
8946 + bcm43xx_radio_write16(bcm, 0x001E, radio->lofcal);
8947 + }
8948 +
8949 + bcm43xx_phy_write(bcm, 0x007A, 0xF111);
8950 +
8951 + if (phy->savedpctlreg == 0xFFFF) {
8952 + bcm43xx_radio_write16(bcm, 0x0019, 0x0000);
8953 + bcm43xx_radio_write16(bcm, 0x0017, 0x0020);
8954 +
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)
8959 + | 0x0058);
8960 + } else {
8961 + bcm43xx_ilt_write(bcm, 0x3001,
8962 + (bcm43xx_ilt_read(bcm, 0x3001) & 0xFFC3)
8963 + | 0x002C);
8964 + }
8965 + bcm43xx_dummy_transmission(bcm);
8966 + phy->savedpctlreg = bcm43xx_phy_read(bcm, BCM43xx_PHY_A_PCTL);
8967 + bcm43xx_ilt_write(bcm, 0x3001, tval);
8968 +
8969 + bcm43xx_radio_set_txpower_a(bcm, 0x0018);
8970 + }
8971 + bcm43xx_radio_clear_tssi(bcm);
8972 +}
8973 +
8974 +static void bcm43xx_phy_initb2(struct bcm43xx_private *bcm)
8975 +{
8976 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
8977 + u16 offset, val;
8978 +
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);
8984 + val = 0x3C3D;
8985 + for (offset = 0x0089; offset < 0x00A7; offset++) {
8986 + bcm43xx_phy_write(bcm, offset, val);
8987 + val -= 0x0202;
8988 + }
8989 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
8990 + if (radio->channel == 0xFF)
8991 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
8992 + else
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);
8997 + }
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);
9008 + }
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);
9023 +}
9024 +
9025 +static void bcm43xx_phy_initb4(struct bcm43xx_private *bcm)
9026 +{
9027 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9028 + u16 offset, val;
9029 +
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);
9035 + val = 0x3C3D;
9036 + for (offset = 0x0089; offset < 0x00A7; offset++) {
9037 + bcm43xx_phy_write(bcm, offset, val);
9038 + val -= 0x0202;
9039 + }
9040 + bcm43xx_phy_write(bcm, 0x03E4, 0x3000);
9041 + if (radio->channel == 0xFF)
9042 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9043 + else
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);
9048 + }
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);
9059 + }
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);
9065 +
9066 + bcm43xx_phy_lo_b_measure(bcm);
9067 +
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);
9079 + }
9080 + bcm43xx_phy_init_pctl(bcm);
9081 +}
9082 +
9083 +static void bcm43xx_phy_initb5(struct bcm43xx_private *bcm)
9084 +{
9085 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9086 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9087 + u16 offset;
9088 +
9089 + if (phy->version == 1 &&
9090 + radio->version == 0x2050) {
9091 + bcm43xx_radio_write16(bcm, 0x007A,
9092 + bcm43xx_radio_read16(bcm, 0x007A)
9093 + | 0x0050);
9094 + }
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)
9100 + & 0x3F3F);
9101 + }
9102 + }
9103 + bcm43xx_phy_write(bcm, 0x0035,
9104 + (bcm43xx_phy_read(bcm, 0x0035) & 0xF0FF)
9105 + | 0x0700);
9106 + if (radio->version == 0x2050)
9107 + bcm43xx_phy_write(bcm, 0x0038, 0x0667);
9108 +
9109 + if (phy->connected) {
9110 + if (radio->version == 0x2050) {
9111 + bcm43xx_radio_write16(bcm, 0x007A,
9112 + bcm43xx_radio_read16(bcm, 0x007A)
9113 + | 0x0020);
9114 + bcm43xx_radio_write16(bcm, 0x0051,
9115 + bcm43xx_radio_read16(bcm, 0x0051)
9116 + | 0x0004);
9117 + }
9118 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO, 0x0000);
9119 +
9120 + bcm43xx_phy_write(bcm, 0x0802, bcm43xx_phy_read(bcm, 0x0802) | 0x0100);
9121 + bcm43xx_phy_write(bcm, 0x042B, bcm43xx_phy_read(bcm, 0x042B) | 0x2000);
9122 +
9123 + bcm43xx_phy_write(bcm, 0x001C, 0x186A);
9124 +
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);
9128 + }
9129 +
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));
9133 + }
9134 +
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);
9141 + } else
9142 + bcm43xx_phy_write(bcm, 0x0026, 0xCC00);
9143 + bcm43xx_phy_write(bcm, 0x0030, 0x00C6);
9144 + bcm43xx_write16(bcm, 0x03EC, 0x3F22);
9145 +
9146 + if (phy->version == 1 && radio->version == 0x2050)
9147 + bcm43xx_phy_write(bcm, 0x0020, 0x3E1C);
9148 + else
9149 + bcm43xx_phy_write(bcm, 0x0020, 0x301C);
9150 +
9151 + if (phy->version == 0)
9152 + bcm43xx_write16(bcm, 0x03E4, 0x3000);
9153 +
9154 + /* Force to channel 7, even if not supported. */
9155 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9156 +
9157 + if (radio->version != 0x2050) {
9158 + bcm43xx_radio_write16(bcm, 0x0075, 0x0080);
9159 + bcm43xx_radio_write16(bcm, 0x0079, 0x0081);
9160 + }
9161 +
9162 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9163 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9164 +
9165 + if (radio->version == 0x2050) {
9166 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9167 + bcm43xx_radio_write16(bcm, 0x005A, 0x0070);
9168 + }
9169 +
9170 + bcm43xx_radio_write16(bcm, 0x005B, 0x007B);
9171 + bcm43xx_radio_write16(bcm, 0x005C, 0x00B0);
9172 +
9173 + bcm43xx_radio_write16(bcm, 0x007A, bcm43xx_radio_read16(bcm, 0x007A) | 0x0007);
9174 +
9175 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9176 +
9177 + bcm43xx_phy_write(bcm, 0x0014, 0x0080);
9178 + bcm43xx_phy_write(bcm, 0x0032, 0x00CA);
9179 + bcm43xx_phy_write(bcm, 0x88A3, 0x002A);
9180 +
9181 + bcm43xx_radio_set_txpower_bg(bcm, 0xFFFF, 0xFFFF, 0xFFFF);
9182 +
9183 + if (radio->version == 0x2050)
9184 + bcm43xx_radio_write16(bcm, 0x005D, 0x000D);
9185 +
9186 + bcm43xx_write16(bcm, 0x03E4, (bcm43xx_read16(bcm, 0x03E4) & 0xFFC0) | 0x0004);
9187 +}
9188 +
9189 +static void bcm43xx_phy_initb6(struct bcm43xx_private *bcm)
9190 +{
9191 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9192 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9193 + u16 offset, val;
9194 +
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);
9212 + }
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);
9228 + }
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);
9245 + }
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);
9259 + } else {
9260 + bcm43xx_radio_write16(bcm, 0x005D, 0x00F5);
9261 + bcm43xx_radio_write16(bcm, 0x005E, 0x00B8);
9262 + }
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);
9267 + }
9268 + val = 0x1E1F;
9269 + for (offset = 0x0088; offset < 0x0098; offset++) {
9270 + bcm43xx_phy_write(bcm, offset, val);
9271 + val -= 0x0202;
9272 + }
9273 + val = 0x3E3F;
9274 + for (offset = 0x0098; offset < 0x00A8; offset++) {
9275 + bcm43xx_phy_write(bcm, offset, val);
9276 + val -= 0x0202;
9277 + }
9278 + val = 0x2120;
9279 + for (offset = 0x00A8; offset < 0x00C8; offset++) {
9280 + bcm43xx_phy_write(bcm, offset, (val & 0x3F3F));
9281 + val += 0x0202;
9282 + }
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);
9292 + }
9293 +
9294 + /* Force to channel 7, even if not supported. */
9295 + bcm43xx_radio_selectchannel(bcm, 7, 0);
9296 +
9297 + bcm43xx_radio_write16(bcm, 0x0050, 0x0020);
9298 + bcm43xx_radio_write16(bcm, 0x0050, 0x0023);
9299 + udelay(40);
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);
9309 + }
9310 + bcm43xx_radio_write16(bcm, 0x007A,
9311 + (bcm43xx_radio_read16(bcm, 0x007A) & 0x00F8) | 0x0007);
9312 +
9313 + bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_BG, 0);
9314 +
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);
9321 + else
9322 + bcm43xx_phy_write(bcm, 0x002A, 0x88C2);
9323 + }
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);
9333 + }
9334 +
9335 + if (phy->rev == 4)
9336 + bcm43xx_phy_write(bcm, 0x0002, (bcm43xx_phy_read(bcm, 0x0002) & 0xFFC0) | 0x0004);
9337 + else
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);
9349 + }
9350 + bcm43xx_phy_init_pctl(bcm);
9351 + } else
9352 + bcm43xx_write16(bcm, 0x03E6, 0x0);
9353 +}
9354 +
9355 +static void bcm43xx_calc_loopback_gain(struct bcm43xx_private *bcm)
9356 +{
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];
9361 + u16 backup_bband;
9362 + u16 i;
9363 + u16 loop1_cnt, loop1_done, loop1_omitted;
9364 + u16 loop2_done;
9365 +
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);
9386 +
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);
9411 +
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);
9418 +
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);
9424 + } else {
9425 + bcm43xx_phy_write(bcm, 0x000A,
9426 + bcm43xx_phy_read(bcm, 0x000A)
9427 + | 0x2000);
9428 + }
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);
9441 + loop1_cnt = 9;
9442 + } else if (radio->revision == 8) {
9443 + bcm43xx_radio_write16(bcm, 0x0043, 0x000F);
9444 + loop1_cnt = 15;
9445 + } else
9446 + loop1_cnt = 0;
9447 +
9448 + bcm43xx_phy_set_baseband_attenuation(bcm, 11);
9449 +
9450 + if (phy->rev >= 3)
9451 + bcm43xx_phy_write(bcm, 0x080F, 0xC020);
9452 + else
9453 + bcm43xx_phy_write(bcm, 0x080F, 0x8020);
9454 + bcm43xx_phy_write(bcm, 0x0810, 0x0000);
9455 +
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)
9470 + | 0x0800);
9471 + bcm43xx_phy_write(bcm, 0x0812,
9472 + bcm43xx_phy_read(bcm, 0x0812)
9473 + | 0x8000);
9474 + }
9475 + }
9476 + bcm43xx_radio_write16(bcm, 0x007A,
9477 + bcm43xx_radio_read16(bcm, 0x007A)
9478 + & 0x00F7);
9479 +
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);
9491 + udelay(20);
9492 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9493 + break;
9494 + }
9495 + loop1_done = i;
9496 + loop1_omitted = loop1_cnt - loop1_done;
9497 +
9498 + loop2_done = 0;
9499 + if (loop1_done >= 8) {
9500 + bcm43xx_phy_write(bcm, 0x0812,
9501 + bcm43xx_phy_read(bcm, 0x0812)
9502 + | 0x0030);
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);
9513 + udelay(20);
9514 + if (bcm43xx_phy_read(bcm, 0x002D) >= 0x0DFC)
9515 + break;
9516 + }
9517 + }
9518 +
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]);
9530 +
9531 + bcm43xx_phy_set_baseband_attenuation(bcm, backup_bband);
9532 +
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]);
9536 +
9537 + bcm43xx_phy_write(bcm, 0x0811, backup_phy[2] | 0x0003);
9538 + udelay(10);
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]);
9543 +
9544 + phy->loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) - 11;
9545 + phy->loopback_gain[1] = (24 - (3 * loop2_done)) * 2;
9546 +}
9547 +
9548 +static void bcm43xx_phy_initg(struct bcm43xx_private *bcm)
9549 +{
9550 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9551 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9552 + u16 tmp;
9553 +
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);
9560 +
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;
9571 + if (tmp < 6) {
9572 + bcm43xx_phy_write(bcm, 0x04C2, 0x1816);
9573 + bcm43xx_phy_write(bcm, 0x04C3, 0x8006);
9574 + if (tmp != 3) {
9575 + bcm43xx_phy_write(bcm, 0x04CC,
9576 + (bcm43xx_phy_read(bcm, 0x04CC)
9577 + & 0x00FF) | 0x1F00);
9578 + }
9579 + }
9580 + }
9581 + }
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);
9587 + }
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);
9593 + else
9594 + bcm43xx_radio_write16(bcm, 0x0078, radio->initval);
9595 + }
9596 + if (radio->txctl2 == 0xFFFF) {
9597 + bcm43xx_phy_lo_g_measure(bcm);
9598 + } else {
9599 + if (radio->version == 0x2050 && radio->revision == 8) {
9600 + //FIXME
9601 + } else {
9602 + bcm43xx_radio_write16(bcm, 0x0052,
9603 + (bcm43xx_radio_read16(bcm, 0x0052)
9604 + & 0xFFF0) | radio->txctl1);
9605 + }
9606 + if (phy->rev >= 6) {
9607 + /*
9608 + bcm43xx_phy_write(bcm, 0x0036,
9609 + (bcm43xx_phy_read(bcm, 0x0036)
9610 + & 0xF000) | (FIXME << 12));
9611 + */
9612 + }
9613 + if (bcm->sprom.boardflags & BCM43xx_BFL_PACTRL)
9614 + bcm43xx_phy_write(bcm, 0x002E, 0x8075);
9615 + else
9616 + bcm43xx_phy_write(bcm, 0x003E, 0x807F);
9617 + if (phy->rev < 2)
9618 + bcm43xx_phy_write(bcm, 0x002F, 0x0101);
9619 + else
9620 + bcm43xx_phy_write(bcm, 0x002F, 0x0202);
9621 + }
9622 + if (phy->connected) {
9623 + bcm43xx_phy_lo_adjust(bcm, 0);
9624 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
9625 + }
9626 +
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())
9633 + */
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);
9640 + } else {
9641 + assert(radio->nrssi[1] != -1000);
9642 + bcm43xx_calc_nrssi_threshold(bcm);
9643 + }
9644 + }
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);
9653 + }
9654 +}
9655 +
9656 +static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm)
9657 +{
9658 + int i;
9659 + u16 ret = 0;
9660 +
9661 + for (i = 0; i < 10; i++){
9662 + bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);
9663 + udelay(1);
9664 + bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);
9665 + udelay(10);
9666 + bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);
9667 + udelay(40);
9668 + ret += bcm43xx_phy_read(bcm, 0x002C);
9669 + }
9670 +
9671 + return ret;
9672 +}
9673 +
9674 +void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm)
9675 +{
9676 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9677 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9678 + u16 regstack[12] = { 0 };
9679 + u16 mls;
9680 + u16 fval;
9681 + int i, j;
9682 +
9683 + regstack[0] = bcm43xx_phy_read(bcm, 0x0015);
9684 + regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;
9685 +
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);
9693 +
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;
9698 +
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);
9703 + }
9704 + bcm43xx_phy_write(bcm, 0x0015, 0xB000);
9705 + bcm43xx_phy_write(bcm, 0x002B, 0x0004);
9706 +
9707 + if (radio->version == 0x2053) {
9708 + bcm43xx_phy_write(bcm, 0x002B, 0x0203);
9709 + bcm43xx_phy_write(bcm, 0x002A, 0x08A3);
9710 + }
9711 +
9712 + phy->minlowsig[0] = 0xFFFF;
9713 +
9714 + for (i = 0; i < 4; i++) {
9715 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);
9716 + bcm43xx_phy_lo_b_r15_loop(bcm);
9717 + }
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;
9724 + }
9725 + }
9726 + bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);
9727 +
9728 + phy->minlowsig[1] = 0xFFFF;
9729 +
9730 + for (i = -4; i < 5; i += 2) {
9731 + for (j = -4; j < 5; j += 2) {
9732 + if (j < 0)
9733 + fval = (0x0100 * i) + j + 0x0100;
9734 + else
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;
9741 + }
9742 + }
9743 + }
9744 + phy->minlowsigpos[1] += 0x0101;
9745 +
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]);
9754 +
9755 + bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);
9756 + bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);
9757 +
9758 + bcm43xx_radio_write16(bcm, 0x0052,
9759 + (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)
9760 + | regstack[11]);
9761 +
9762 + bcm43xx_write16(bcm, 0x03EC, regstack[10]);
9763 + }
9764 + bcm43xx_phy_write(bcm, 0x0015, regstack[0]);
9765 +}
9766 +
9767 +static inline
9768 +u16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control)
9769 +{
9770 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9771 +
9772 + if (phy->connected) {
9773 + bcm43xx_phy_write(bcm, 0x15, 0xE300);
9774 + control <<= 8;
9775 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);
9776 + udelay(5);
9777 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);
9778 + udelay(2);
9779 + bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);
9780 + udelay(4);
9781 + bcm43xx_phy_write(bcm, 0x0015, 0xF300);
9782 + udelay(8);
9783 + } else {
9784 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);
9785 + udelay(2);
9786 + bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);
9787 + udelay(4);
9788 + bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);
9789 + udelay(8);
9790 + }
9791 +
9792 + return bcm43xx_phy_read(bcm, 0x002D);
9793 +}
9794 +
9795 +static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control)
9796 +{
9797 + int i;
9798 + u32 ret = 0;
9799 +
9800 + for (i = 0; i < 8; i++)
9801 + ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);
9802 +
9803 + return ret;
9804 +}
9805 +
9806 +/* Write the LocalOscillator CONTROL */
9807 +static inline
9808 +void bcm43xx_lo_write(struct bcm43xx_private *bcm,
9809 + struct bcm43xx_lopair *pair)
9810 +{
9811 + u16 value;
9812 +
9813 + value = (u8)(pair->low);
9814 + value |= ((u8)(pair->high)) << 8;
9815 +
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));
9825 + dump_stack();
9826 + }
9827 +#endif
9828 +
9829 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);
9830 +}
9831 +
9832 +static inline
9833 +struct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,
9834 + u16 baseband_attenuation,
9835 + u16 radio_attenuation,
9836 + u16 tx)
9837 +{
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);
9840 +
9841 + if (baseband_attenuation > 6)
9842 + baseband_attenuation = 6;
9843 + assert(radio_attenuation < 10);
9844 +
9845 + if (tx == 3) {
9846 + return bcm43xx_get_lopair(phy,
9847 + radio_attenuation,
9848 + baseband_attenuation);
9849 + }
9850 + return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);
9851 +}
9852 +
9853 +static inline
9854 +struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm)
9855 +{
9856 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9857 +
9858 + return bcm43xx_find_lopair(bcm,
9859 + radio->baseband_atten,
9860 + radio->radio_atten,
9861 + radio->txctl1);
9862 +}
9863 +
9864 +/* Adjust B/G LO */
9865 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed)
9866 +{
9867 + struct bcm43xx_lopair *pair;
9868 +
9869 + if (fixed) {
9870 + /* Use fixed values. Only for initialization. */
9871 + pair = bcm43xx_find_lopair(bcm, 2, 3, 0);
9872 + } else
9873 + pair = bcm43xx_current_lopair(bcm);
9874 + bcm43xx_lo_write(bcm, pair);
9875 +}
9876 +
9877 +static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm)
9878 +{
9879 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
9880 + u16 txctl2 = 0, i;
9881 + u32 smallest, tmp;
9882 +
9883 + bcm43xx_radio_write16(bcm, 0x0052, 0x0000);
9884 + udelay(10);
9885 + smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9886 + for (i = 0; i < 16; i++) {
9887 + bcm43xx_radio_write16(bcm, 0x0052, i);
9888 + udelay(10);
9889 + tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);
9890 + if (tmp < smallest) {
9891 + smallest = tmp;
9892 + txctl2 = i;
9893 + }
9894 + }
9895 + radio->txctl2 = txctl2;
9896 +}
9897 +
9898 +static
9899 +void bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,
9900 + const struct bcm43xx_lopair *in_pair,
9901 + struct bcm43xx_lopair *out_pair,
9902 + u16 r27)
9903 +{
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, },
9913 + };
9914 + struct bcm43xx_lopair lowest_transition = {
9915 + .high = in_pair->high,
9916 + .low = in_pair->low,
9917 + };
9918 + struct bcm43xx_lopair tmp_pair;
9919 + struct bcm43xx_lopair transition;
9920 + int i = 12;
9921 + int state = 0;
9922 + int found_lower;
9923 + int j, begin, end;
9924 + u32 lowest_deviation;
9925 + u32 tmp;
9926 +
9927 + /* Note that in_pair and out_pair can point to the same pair. Be careful. */
9928 +
9929 + bcm43xx_lo_write(bcm, &lowest_transition);
9930 + lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);
9931 + do {
9932 + found_lower = 0;
9933 + assert(state >= 0 && state <= 8);
9934 + if (state == 0) {
9935 + begin = 1;
9936 + end = 8;
9937 + } else if (state % 2 == 0) {
9938 + begin = state - 1;
9939 + end = state + 1;
9940 + } else {
9941 + begin = state - 2;
9942 + end = state + 2;
9943 + }
9944 + if (begin < 1)
9945 + begin += 8;
9946 + if (end > 8)
9947 + end -= 8;
9948 +
9949 + j = begin;
9950 + tmp_pair.high = lowest_transition.high;
9951 + tmp_pair.low = lowest_transition.low;
9952 + while (1) {
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;
9961 + state = j;
9962 + found_lower = 1;
9963 +
9964 + lowest_transition.high = transition.high;
9965 + lowest_transition.low = transition.low;
9966 + }
9967 + }
9968 + if (j == end)
9969 + break;
9970 + if (j == 8)
9971 + j = 1;
9972 + else
9973 + j++;
9974 + }
9975 + } while (i-- && found_lower);
9976 +
9977 + out_pair->high = lowest_transition.high;
9978 + out_pair->low = lowest_transition.low;
9979 +}
9980 +
9981 +/* Set the baseband attenuation value on chip. */
9982 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
9983 + u16 baseband_attenuation)
9984 +{
9985 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
9986 + u16 value;
9987 +
9988 + if (phy->version == 0) {
9989 + value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);
9990 + value |= (baseband_attenuation & 0x000F);
9991 + bcm43xx_write16(bcm, 0x03E6, value);
9992 + return;
9993 + }
9994 +
9995 + if (phy->version > 1) {
9996 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;
9997 + value |= (baseband_attenuation << 2) & 0x003C;
9998 + } else {
9999 + value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;
10000 + value |= (baseband_attenuation << 3) & 0x0078;
10001 + }
10002 + bcm43xx_phy_write(bcm, 0x0060, value);
10003 +}
10004 +
10005 +/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */
10006 +void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm)
10007 +{
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;
10015 + u16 tmp;
10016 + u16 regstack[16] = { 0 };
10017 + u8 oldchannel;
10018 +
10019 + //XXX: What are these?
10020 + u8 r27 = 0, r31;
10021 +
10022 + oldchannel = radio->channel;
10023 + /* Setup */
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);
10029 + }
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);
10045 + }
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);
10051 + }
10052 + bcm43xx_radio_write16(bcm, 0x0043, 0x0006);
10053 +
10054 + bcm43xx_phy_set_baseband_attenuation(bcm, 2);
10055 +
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);
10068 + }
10069 + if (is_initializing)
10070 + bcm43xx_phy_lo_g_measure_txctl2(bcm);
10071 + bcm43xx_phy_write(bcm, 0x080F, 0x8078);
10072 +
10073 + /* Measure */
10074 + control.low = 0;
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) {
10080 + if (i == 3) {
10081 + control.low = 0;
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));
10087 + } else {
10088 + tmp_control = bcm43xx_get_lopair(phy, 3, 0);
10089 + memcpy(&control, tmp_control, sizeof(control));
10090 + }
10091 + }
10092 + /* Loop over each possible BasebandAttenuation/2 */
10093 + for (j = 0; j < 4; j++) {
10094 + if (is_initializing) {
10095 + tmp = i * 2 + j;
10096 + r27 = 0;
10097 + r31 = 0;
10098 + if (tmp > 14) {
10099 + r31 = 1;
10100 + if (tmp > 17)
10101 + r27 = 1;
10102 + if (tmp > 19)
10103 + r27 = 2;
10104 + }
10105 + } else {
10106 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10107 + if (!tmp_control->used)
10108 + continue;
10109 + memcpy(&control, tmp_control, sizeof(control));
10110 + r27 = 3;
10111 + r31 = 0;
10112 + }
10113 + bcm43xx_radio_write16(bcm, 0x43, i);
10114 + bcm43xx_radio_write16(bcm, 0x52, radio->txctl2);
10115 + udelay(10);
10116 +
10117 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10118 +
10119 + tmp = (regstack[10] & 0xFFF0);
10120 + if (r31)
10121 + tmp |= 0x0008;
10122 + bcm43xx_radio_write16(bcm, 0x007A, tmp);
10123 +
10124 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10125 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10126 + }
10127 + oldi = i;
10128 + }
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.
10137 + r27 = 0;
10138 + r31 = 0;
10139 + if (tmp > 14) {
10140 + r31 = 1;
10141 + if (tmp > 17)
10142 + r27 = 1;
10143 + if (tmp > 19)
10144 + r27 = 2;
10145 + }
10146 + } else {
10147 + tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);
10148 + if (!tmp_control->used)
10149 + continue;
10150 + memcpy(&control, tmp_control, sizeof(control));
10151 + r27 = 3;
10152 + r31 = 0;
10153 + }
10154 + bcm43xx_radio_write16(bcm, 0x43, i - 9);
10155 + bcm43xx_radio_write16(bcm, 0x52,
10156 + radio->txctl2
10157 + | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?
10158 + udelay(10);
10159 +
10160 + bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);
10161 +
10162 + tmp = (regstack[10] & 0xFFF0);
10163 + if (r31)
10164 + tmp |= 0x0008;
10165 + bcm43xx_radio_write16(bcm, 0x7A, tmp);
10166 +
10167 + tmp_control = bcm43xx_get_lopair(phy, i, j * 2);
10168 + bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);
10169 + }
10170 + }
10171 +
10172 + /* Restoration */
10173 + if (phy->connected) {
10174 + bcm43xx_phy_write(bcm, 0x0015, 0xE300);
10175 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);
10176 + udelay(5);
10177 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);
10178 + udelay(2);
10179 + bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);
10180 + } else
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);
10186 + else
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]);
10206 + }
10207 + bcm43xx_radio_selectchannel(bcm, oldchannel, 1);
10208 +
10209 +#ifdef CONFIG_BCM43XX_D80211_DEBUG
10210 + {
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);
10219 + }
10220 + }
10221 + }
10222 +#endif /* CONFIG_BCM43XX_D80211_DEBUG */
10223 +}
10224 +
10225 +static
10226 +void bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm)
10227 +{
10228 + struct bcm43xx_lopair *pair;
10229 +
10230 + pair = bcm43xx_current_lopair(bcm);
10231 + pair->used = 1;
10232 +}
10233 +
10234 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm)
10235 +{
10236 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10237 + struct bcm43xx_lopair *pair;
10238 + int i;
10239 +
10240 + for (i = 0; i < BCM43xx_LO_COUNT; i++) {
10241 + pair = phy->_lo_pairs + i;
10242 + pair->used = 0;
10243 + }
10244 +}
10245 +
10246 +/* http://bcm-specs.sipsolutions.net/EstimatePowerOut
10247 + * This function converts a TSSI value to dBm in Q5.2
10248 + */
10249 +static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi)
10250 +{
10251 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10252 + s8 dbm = 0;
10253 + s32 tmp;
10254 +
10255 + tmp = phy->idle_tssi;
10256 + tmp += tssi;
10257 + tmp -= phy->savedpctlreg;
10258 +
10259 + switch (phy->type) {
10260 + case BCM43xx_PHYTYPE_A:
10261 + tmp += 0x80;
10262 + tmp = limit_value(tmp, 0x00, 0xFF);
10263 + dbm = phy->tssi2dbm[tmp];
10264 + TODO(); //TODO: There's a FIXME on the specs
10265 + break;
10266 + case BCM43xx_PHYTYPE_B:
10267 + case BCM43xx_PHYTYPE_G:
10268 + tmp = limit_value(tmp, 0x00, 0x3F);
10269 + dbm = phy->tssi2dbm[tmp];
10270 + break;
10271 + default:
10272 + assert(0);
10273 + }
10274 +
10275 + return dbm;
10276 +}
10277 +
10278 +/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */
10279 +void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm)
10280 +{
10281 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10282 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10283 +
10284 + if (phy->savedpctlreg == 0xFFFF)
10285 + return;
10286 + if ((bcm->board_type == 0x0416) &&
10287 + (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM))
10288 + return;
10289 +
10290 + switch (phy->type) {
10291 + case BCM43xx_PHYTYPE_A: {
10292 +
10293 + TODO(); //TODO: Nothing for A PHYs yet :-/
10294 +
10295 + break;
10296 + }
10297 + case BCM43xx_PHYTYPE_B:
10298 + case BCM43xx_PHYTYPE_G: {
10299 + u16 tmp;
10300 + u16 txpower;
10301 + s8 v0, v1, v2, v3;
10302 + s8 average;
10303 + u8 max_pwr;
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;
10308 +
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);
10315 + tmp = 0;
10316 +
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)
10325 + return;
10326 + v0 = (v0 + 0x20) & 0x3F;
10327 + v1 = (v1 + 0x20) & 0x3F;
10328 + v2 = (v2 + 0x20) & 0x3F;
10329 + v3 = (v3 + 0x20) & 0x3F;
10330 + tmp = 1;
10331 + }
10332 + bcm43xx_radio_clear_tssi(bcm);
10333 +
10334 + average = (v0 + v1 + v2 + v3 + 2) / 4;
10335 +
10336 + if (tmp && (bcm43xx_shm_read16(bcm, BCM43xx_SHM_SHARED, 0x005E) & 0x8))
10337 + average -= 13;
10338 +
10339 + estimated_pwr = bcm43xx_phy_estimate_power_out(bcm, average);
10340 +
10341 + max_pwr = bcm->sprom.maxpower_bgphy;
10342 +
10343 + if ((bcm->sprom.boardflags & BCM43xx_BFL_PACTRL) &&
10344 + (phy->type == BCM43xx_PHYTYPE_G))
10345 + max_pwr -= 0x3;
10346 +
10347 + /*TODO:
10348 + max_pwr = min(REG - bcm->sprom.antennagain_bgphy - 0x6, max_pwr)
10349 + where REG is the max power as per the regulatory domain
10350 + */
10351 +
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);
10355 +
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);
10361 + return;
10362 + }
10363 +
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;
10369 +
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.
10373 + */
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;
10380 + } else {
10381 + while (baseband_attenuation < 0 && radio_attenuation > 0) {
10382 + baseband_attenuation += 4;
10383 + radio_attenuation--;
10384 + }
10385 + while (baseband_attenuation > 11 && radio_attenuation < 9) {
10386 + baseband_attenuation -= 4;
10387 + radio_attenuation++;
10388 + }
10389 + }
10390 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10391 +
10392 + txpower = radio->txctl1;
10393 + if ((radio->version == 0x2050) && (radio->revision == 2)) {
10394 + if (radio_attenuation <= 1) {
10395 + if (txpower == 0) {
10396 + txpower = 3;
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;
10402 + }
10403 + } else if (radio_attenuation > 4 && txpower != 0) {
10404 + txpower = 0;
10405 + if (baseband_attenuation < 3) {
10406 + radio_attenuation -= 3;
10407 + baseband_attenuation += 2;
10408 + } else {
10409 + radio_attenuation -= 2;
10410 + baseband_attenuation -= 2;
10411 + }
10412 + }
10413 + }
10414 + radio->txctl1 = txpower;
10415 + baseband_attenuation = limit_value(baseband_attenuation, 0, 11);
10416 + radio_attenuation = limit_value(radio_attenuation, 0, 9);
10417 +
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);
10425 + break;
10426 + }
10427 + default:
10428 + assert(0);
10429 + }
10430 +}
10431 +
10432 +static inline
10433 +s32 bcm43xx_tssi2dbm_ad(s32 num, s32 den)
10434 +{
10435 + if (num < 0)
10436 + return num/den;
10437 + else
10438 + return (num+den/2)/den;
10439 +}
10440 +
10441 +static inline
10442 +s8 bcm43xx_tssi2dbm_entry(s8 entry [], u8 index, s16 pab0, s16 pab1, s16 pab2)
10443 +{
10444 + s32 m1, m2, f = 256, q, delta;
10445 + s8 i = 0;
10446 +
10447 + m1 = bcm43xx_tssi2dbm_ad(16 * pab0 + index * pab1, 32);
10448 + m2 = max(bcm43xx_tssi2dbm_ad(32768 + index * pab2, 256), 1);
10449 + do {
10450 + if (i > 15)
10451 + return -EINVAL;
10452 + q = bcm43xx_tssi2dbm_ad(f * 4096 -
10453 + bcm43xx_tssi2dbm_ad(m2 * f, 16) * f, 2048);
10454 + delta = abs(q - f);
10455 + f = q;
10456 + i++;
10457 + } while (delta >= 2);
10458 + entry[index] = limit_value(bcm43xx_tssi2dbm_ad(m1 * f, 8192), -127, 128);
10459 + return 0;
10460 +}
10461 +
10462 +/* http://bcm-specs.sipsolutions.net/TSSI_to_DBM_Table */
10463 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm)
10464 +{
10465 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10466 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
10467 + s16 pab0, pab1, pab2;
10468 + u8 idx;
10469 + s8 *dyn_tssi2dbm;
10470 +
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);
10475 + } else {
10476 + pab0 = (s16)(bcm->sprom.pa0b0);
10477 + pab1 = (s16)(bcm->sprom.pa0b1);
10478 + pab2 = (s16)(bcm->sprom.pa0b2);
10479 + }
10480 +
10481 + if ((bcm->chip_id == 0x4301) && (radio->version != 0x2050)) {
10482 + phy->idle_tssi = 0x34;
10483 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10484 + return 0;
10485 + }
10486 +
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);
10494 + else
10495 + phy->idle_tssi = 62;
10496 + } else {
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);
10500 + else
10501 + phy->idle_tssi = 62;
10502 + }
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");
10507 + return -ENOMEM;
10508 + }
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");
10514 + return -ENODEV;
10515 + }
10516 + phy->tssi2dbm = dyn_tssi2dbm;
10517 + phy->dyn_tssi_tbl = 1;
10518 + } else {
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");
10526 + return -ENODEV;
10527 + case BCM43xx_PHYTYPE_B:
10528 + phy->idle_tssi = 0x34;
10529 + phy->tssi2dbm = bcm43xx_tssi2dbm_b_table;
10530 + break;
10531 + case BCM43xx_PHYTYPE_G:
10532 + phy->idle_tssi = 0x34;
10533 + phy->tssi2dbm = bcm43xx_tssi2dbm_g_table;
10534 + break;
10535 + }
10536 + }
10537 +
10538 + return 0;
10539 +}
10540 +
10541 +int bcm43xx_phy_init(struct bcm43xx_private *bcm)
10542 +{
10543 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10544 + int err = -ENODEV;
10545 + unsigned long flags;
10546 +
10547 + /* We do not want to be preempted while calibrating
10548 + * the hardware.
10549 + */
10550 + local_irq_save(flags);
10551 +
10552 + switch (phy->type) {
10553 + case BCM43xx_PHYTYPE_A:
10554 + if (phy->rev == 2 || phy->rev == 3) {
10555 + bcm43xx_phy_inita(bcm);
10556 + err = 0;
10557 + }
10558 + break;
10559 + case BCM43xx_PHYTYPE_B:
10560 + switch (phy->rev) {
10561 + case 2:
10562 + bcm43xx_phy_initb2(bcm);
10563 + err = 0;
10564 + break;
10565 + case 4:
10566 + bcm43xx_phy_initb4(bcm);
10567 + err = 0;
10568 + break;
10569 + case 5:
10570 + bcm43xx_phy_initb5(bcm);
10571 + err = 0;
10572 + break;
10573 + case 6:
10574 + bcm43xx_phy_initb6(bcm);
10575 + err = 0;
10576 + break;
10577 + }
10578 + break;
10579 + case BCM43xx_PHYTYPE_G:
10580 + bcm43xx_phy_initg(bcm);
10581 + err = 0;
10582 + break;
10583 + }
10584 + local_irq_restore(flags);
10585 + if (err)
10586 + printk(KERN_WARNING PFX "Unknown PHYTYPE found!\n");
10587 +
10588 + return err;
10589 +}
10590 +
10591 +void bcm43xx_phy_set_antenna_diversity(struct bcm43xx_private *bcm)
10592 +{
10593 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
10594 + u16 antennadiv;
10595 + u16 offset;
10596 + u16 value;
10597 + u32 ucodeflags;
10598 +
10599 + antennadiv = phy->antenna_diversity;
10600 +
10601 + if (antennadiv == 0xFFFF)
10602 + antennadiv = 3;
10603 + assert(antennadiv <= 3);
10604 +
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);
10610 +
10611 + switch (phy->type) {
10612 + case BCM43xx_PHYTYPE_A:
10613 + case BCM43xx_PHYTYPE_G:
10614 + if (phy->type == BCM43xx_PHYTYPE_A)
10615 + offset = 0x0000;
10616 + else
10617 + offset = 0x0400;
10618 +
10619 + if (antennadiv == 2)
10620 + value = (3/*automatic*/ << 7);
10621 + else
10622 + value = (antennadiv << 7);
10623 + bcm43xx_phy_write(bcm, offset + 1,
10624 + (bcm43xx_phy_read(bcm, offset + 1)
10625 + & 0x7E7F) | value);
10626 +
10627 + if (antennadiv >= 2) {
10628 + if (antennadiv == 2)
10629 + value = (antennadiv << 7);
10630 + else
10631 + value = (0/*force0*/ << 7);
10632 + bcm43xx_phy_write(bcm, offset + 0x2B,
10633 + (bcm43xx_phy_read(bcm, offset + 0x2B)
10634 + & 0xFEFF) | value);
10635 + }
10636 +
10637 + if (phy->type == BCM43xx_PHYTYPE_G) {
10638 + if (antennadiv >= 2)
10639 + bcm43xx_phy_write(bcm, 0x048C,
10640 + bcm43xx_phy_read(bcm, 0x048C)
10641 + | 0x2000);
10642 + else
10643 + bcm43xx_phy_write(bcm, 0x048C,
10644 + bcm43xx_phy_read(bcm, 0x048C)
10645 + & ~0x2000);
10646 + if (phy->rev >= 2) {
10647 + bcm43xx_phy_write(bcm, 0x0461,
10648 + bcm43xx_phy_read(bcm, 0x0461)
10649 + | 0x0010);
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);
10655 + else
10656 + bcm43xx_phy_write(bcm, 0x0427,
10657 + (bcm43xx_phy_read(bcm, 0x0427)
10658 + & 0x00FF) | 0x0008);
10659 + }
10660 + else if (phy->rev >= 6)
10661 + bcm43xx_phy_write(bcm, 0x049B, 0x00DC);
10662 + } else {
10663 + if (phy->rev < 3)
10664 + bcm43xx_phy_write(bcm, 0x002B,
10665 + (bcm43xx_phy_read(bcm, 0x002B)
10666 + & 0x00FF) | 0x0024);
10667 + else {
10668 + bcm43xx_phy_write(bcm, 0x0061,
10669 + bcm43xx_phy_read(bcm, 0x0061)
10670 + | 0x0010);
10671 + if (phy->rev == 3) {
10672 + bcm43xx_phy_write(bcm, 0x0093, 0x001D);
10673 + bcm43xx_phy_write(bcm, 0x0027, 0x0008);
10674 + } else {
10675 + bcm43xx_phy_write(bcm, 0x0093, 0x003A);
10676 + bcm43xx_phy_write(bcm, 0x0027,
10677 + (bcm43xx_phy_read(bcm, 0x0027)
10678 + & 0x00FF) | 0x0008);
10679 + }
10680 + }
10681 + }
10682 + break;
10683 + case BCM43xx_PHYTYPE_B:
10684 + if (bcm->current_core->rev == 2)
10685 + value = (3/*automatic*/ << 7);
10686 + else
10687 + value = (antennadiv << 7);
10688 + bcm43xx_phy_write(bcm, 0x03E2,
10689 + (bcm43xx_phy_read(bcm, 0x03E2)
10690 + & 0xFE7F) | value);
10691 + break;
10692 + default:
10693 + assert(0);
10694 + }
10695 +
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);
10702 + }
10703 +
10704 + phy->antenna_diversity = antennadiv;
10705 +}
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
10709 @@ -0,0 +1,74 @@
10710 +/*
10711 +
10712 + Broadcom BCM43xx wireless driver
10713 +
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>
10719 +
10720 + Some parts of the code in this file are derived from the ipw2200
10721 + driver Copyright(c) 2003 - 2004 Intel Corporation.
10722 +
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.
10727 +
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.
10732 +
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.
10737 +
10738 +*/
10739 +
10740 +#ifndef BCM43xx_PHY_H_
10741 +#define BCM43xx_PHY_H_
10742 +
10743 +#include <linux/types.h>
10744 +
10745 +struct bcm43xx_private;
10746 +
10747 +void bcm43xx_raw_phy_lock(struct bcm43xx_private *bcm);
10748 +#define bcm43xx_phy_lock(bcm, flags) \
10749 + do { \
10750 + local_irq_save(flags); \
10751 + bcm43xx_raw_phy_lock(bcm); \
10752 + } while (0)
10753 +void bcm43xx_raw_phy_unlock(struct bcm43xx_private *bcm);
10754 +#define bcm43xx_phy_unlock(bcm, flags) \
10755 + do { \
10756 + bcm43xx_raw_phy_unlock(bcm); \
10757 + local_irq_restore(flags); \
10758 + } while (0)
10759 +
10760 +u16 bcm43xx_phy_read(struct bcm43xx_private *bcm, u16 offset);
10761 +void bcm43xx_phy_write(struct bcm43xx_private *bcm, u16 offset, u16 val);
10762 +
10763 +int bcm43xx_phy_init_tssi2dbm_table(struct bcm43xx_private *bcm);
10764 +int bcm43xx_phy_init(struct bcm43xx_private *bcm);
10765 +
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);
10769 +
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);
10773 +
10774 +/* Adjust the LocalOscillator to the saved values.
10775 + * "fixed" is only set to 1 once in initialization. Set to 0 otherwise.
10776 + */
10777 +void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed);
10778 +void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm);
10779 +
10780 +void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,
10781 + u16 baseband_attenuation);
10782 +
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
10787 @@ -0,0 +1,592 @@
10788 +/*
10789 +
10790 + Broadcom BCM43xx wireless driver
10791 +
10792 + PIO Transmission
10793 +
10794 + Copyright (c) 2005 Michael Buesch <mbuesch@freenet.de>
10795 +
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.
10800 +
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.
10805 +
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.
10810 +
10811 +*/
10812 +
10813 +#include "bcm43xx.h"
10814 +#include "bcm43xx_pio.h"
10815 +#include "bcm43xx_main.h"
10816 +#include "bcm43xx_xmit.h"
10817 +
10818 +#include <linux/delay.h>
10819 +
10820 +
10821 +static void tx_start(struct bcm43xx_pioqueue *queue)
10822 +{
10823 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10824 + BCM43xx_PIO_TXCTL_INIT);
10825 +}
10826 +
10827 +static void tx_octet(struct bcm43xx_pioqueue *queue,
10828 + u8 octet)
10829 +{
10830 + if (queue->need_workarounds) {
10831 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10832 + octet);
10833 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10834 + BCM43xx_PIO_TXCTL_WRITEHI);
10835 + } else {
10836 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10837 + BCM43xx_PIO_TXCTL_WRITEHI);
10838 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA,
10839 + octet);
10840 + }
10841 +}
10842 +
10843 +static u16 tx_get_next_word(struct bcm43xx_txhdr *txhdr,
10844 + const u8 *packet,
10845 + unsigned int *pos)
10846 +{
10847 + const u8 *source;
10848 + unsigned int i = *pos;
10849 + u16 ret;
10850 +
10851 + if (i < sizeof(*txhdr)) {
10852 + source = (const u8 *)txhdr;
10853 + } else {
10854 + source = packet;
10855 + i -= sizeof(*txhdr);
10856 + }
10857 + ret = le16_to_cpu( *((u16 *)(source + i)) );
10858 + *pos += 2;
10859 +
10860 + return ret;
10861 +}
10862 +
10863 +static void tx_data(struct bcm43xx_pioqueue *queue,
10864 + struct bcm43xx_txhdr *txhdr,
10865 + const u8 *packet,
10866 + unsigned int octets)
10867 +{
10868 + u16 data;
10869 + unsigned int i = 0;
10870 +
10871 + if (queue->need_workarounds) {
10872 + data = tx_get_next_word(txhdr, packet, &i);
10873 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXDATA, data);
10874 + }
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);
10881 + }
10882 + if (octets % 2)
10883 + tx_octet(queue, packet[octets - sizeof(*txhdr) - 1]);
10884 +}
10885 +
10886 +static void tx_complete(struct bcm43xx_pioqueue *queue,
10887 + struct sk_buff *skb)
10888 +{
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);
10895 + } else {
10896 + bcm43xx_pio_write(queue, BCM43xx_PIO_TXCTL,
10897 + BCM43xx_PIO_TXCTL_COMPLETE);
10898 + }
10899 +}
10900 +
10901 +static u16 generate_cookie(struct bcm43xx_pioqueue *queue,
10902 + int packetindex)
10903 +{
10904 + u16 cookie = 0x0000;
10905 +
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).
10909 + */
10910 + switch (queue->mmio_base) {
10911 + case BCM43xx_MMIO_PIO1_BASE:
10912 + break;
10913 + case BCM43xx_MMIO_PIO2_BASE:
10914 + cookie = 0x1000;
10915 + break;
10916 + case BCM43xx_MMIO_PIO3_BASE:
10917 + cookie = 0x2000;
10918 + break;
10919 + case BCM43xx_MMIO_PIO4_BASE:
10920 + cookie = 0x3000;
10921 + break;
10922 + default:
10923 + assert(0);
10924 + }
10925 + assert(((u16)packetindex & 0xF000) == 0x0000);
10926 + cookie |= (u16)packetindex;
10927 +
10928 + return cookie;
10929 +}
10930 +
10931 +static
10932 +struct bcm43xx_pioqueue * parse_cookie(struct bcm43xx_private *bcm,
10933 + u16 cookie,
10934 + struct bcm43xx_pio_txpacket **packet)
10935 +{
10936 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
10937 + struct bcm43xx_pioqueue *queue = NULL;
10938 + int packetindex;
10939 +
10940 + switch (cookie & 0xF000) {
10941 + case 0x0000:
10942 + queue = pio->queue0;
10943 + break;
10944 + case 0x1000:
10945 + queue = pio->queue1;
10946 + break;
10947 + case 0x2000:
10948 + queue = pio->queue2;
10949 + break;
10950 + case 0x3000:
10951 + queue = pio->queue3;
10952 + break;
10953 + default:
10954 + assert(0);
10955 + }
10956 + packetindex = (cookie & 0x0FFF);
10957 + assert(packetindex >= 0 && packetindex < BCM43xx_PIO_MAXTXPACKETS);
10958 + *packet = &(queue->tx_packets_cache[packetindex]);
10959 +
10960 + return queue;
10961 +}
10962 +
10963 +static void pio_tx_write_fragment(struct bcm43xx_pioqueue *queue,
10964 + struct sk_buff *skb,
10965 + struct bcm43xx_pio_txpacket *packet)
10966 +{
10967 + struct bcm43xx_txhdr txhdr;
10968 + unsigned int octets;
10969 +
10970 + assert(skb_shinfo(skb)->nr_frags == 0);
10971 + bcm43xx_generate_txhdr(queue->bcm,
10972 + &txhdr, skb->data, skb->len,
10973 + 1,//FIXME
10974 + generate_cookie(queue, pio_txpacket_getindex(packet)),
10975 + packet->ctl);
10976 +
10977 + tx_start(queue);
10978 + octets = skb->len + sizeof(txhdr);
10979 + if (queue->need_workarounds)
10980 + octets--;
10981 + tx_data(queue, &txhdr, (u8 *)skb->data, octets);
10982 + tx_complete(queue, skb);
10983 +}
10984 +
10985 +static void free_txpacket(struct bcm43xx_pio_txpacket *packet,
10986 + int irq_context)
10987 +{
10988 + struct bcm43xx_pioqueue *queue = packet->queue;
10989 +
10990 + if (irq_context)
10991 + dev_kfree_skb_irq(packet->skb);
10992 + else
10993 + dev_kfree_skb(packet->skb);
10994 + list_move(&packet->list, &queue->txfree);
10995 + queue->nr_txfree++;
10996 +}
10997 +
10998 +static int pio_tx_packet(struct bcm43xx_pio_txpacket *packet)
10999 +{
11000 + struct bcm43xx_pioqueue *queue = packet->queue;
11001 + struct sk_buff *skb = packet->skb;
11002 + u16 octets;
11003 +
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);
11010 + return 0;
11011 + }
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
11016 + * retry later.
11017 + */
11018 + if (queue->tx_devq_packets == BCM43xx_PIO_MAXTXDEVQPACKETS)
11019 + return -EBUSY;
11020 + if (queue->tx_devq_used + octets > queue->tx_devq_size)
11021 + return -EBUSY;
11022 + /* Now poke the device. */
11023 + pio_tx_write_fragment(queue, skb, packet);
11024 +
11025 + /* Account for the packet size.
11026 + * (We must not overflow the device TX queue)
11027 + */
11028 + queue->tx_devq_packets++;
11029 + queue->tx_devq_used += octets;
11030 +
11031 + /* Transmission started, everything ok, move the
11032 + * packet to the txrunning list.
11033 + */
11034 + list_move_tail(&packet->list, &queue->txrunning);
11035 +
11036 + return 0;
11037 +}
11038 +
11039 +static void tx_tasklet(unsigned long d)
11040 +{
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;
11045 + int err;
11046 +
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
11054 + * is dropped.
11055 + */
11056 + err = pio_tx_packet(packet);
11057 + if (err)
11058 + break;
11059 + }
11060 + bcm43xx_unlock_mmio(bcm, flags);
11061 +}
11062 +
11063 +static void setup_txqueues(struct bcm43xx_pioqueue *queue)
11064 +{
11065 + struct bcm43xx_pio_txpacket *packet;
11066 + int i;
11067 +
11068 + queue->nr_txfree = BCM43xx_PIO_MAXTXPACKETS;
11069 + for (i = 0; i < BCM43xx_PIO_MAXTXPACKETS; i++) {
11070 + packet = &(queue->tx_packets_cache[i]);
11071 +
11072 + packet->queue = queue;
11073 + INIT_LIST_HEAD(&packet->list);
11074 +
11075 + list_add(&packet->list, &queue->txfree);
11076 + }
11077 +}
11078 +
11079 +static
11080 +struct bcm43xx_pioqueue * bcm43xx_setup_pioqueue(struct bcm43xx_private *bcm,
11081 + u16 pio_mmio_base)
11082 +{
11083 + struct bcm43xx_pioqueue *queue;
11084 + u32 value;
11085 + u16 qsize;
11086 +
11087 + queue = kzalloc(sizeof(*queue), GFP_KERNEL);
11088 + if (!queue)
11089 + goto out;
11090 +
11091 + queue->bcm = bcm;
11092 + queue->mmio_base = pio_mmio_base;
11093 + queue->need_workarounds = (bcm->current_core->rev < 3);
11094 +
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);
11100 +
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);
11104 +
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;
11109 + }
11110 + qsize -= BCM43xx_PIO_TXQADJUST;
11111 + queue->tx_devq_size = qsize;
11112 +
11113 + setup_txqueues(queue);
11114 +
11115 +out:
11116 + return queue;
11117 +
11118 +err_freequeue:
11119 + kfree(queue);
11120 + queue = NULL;
11121 + goto out;
11122 +}
11123 +
11124 +static void cancel_transfers(struct bcm43xx_pioqueue *queue)
11125 +{
11126 + struct bcm43xx_pio_txpacket *packet, *tmp_packet;
11127 +
11128 + ieee80211_netif_oper(queue->bcm->net_dev, NETIF_DETACH);
11129 + assert(queue->bcm->shutting_down);
11130 + tasklet_disable(&queue->txtask);
11131 +
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);
11136 +}
11137 +
11138 +static void bcm43xx_destroy_pioqueue(struct bcm43xx_pioqueue *queue)
11139 +{
11140 + if (!queue)
11141 + return;
11142 +
11143 + cancel_transfers(queue);
11144 + kfree(queue);
11145 +}
11146 +
11147 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11148 +{
11149 + struct bcm43xx_pio *pio;
11150 +
11151 + if (!bcm43xx_using_pio(bcm))
11152 + return;
11153 + pio = bcm43xx_current_pio(bcm);
11154 +
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;
11163 +}
11164 +
11165 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11166 +{
11167 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11168 + struct bcm43xx_pioqueue *queue;
11169 + int err = -ENOMEM;
11170 +
11171 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO1_BASE);
11172 + if (!queue)
11173 + goto out;
11174 + pio->queue0 = queue;
11175 +
11176 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO2_BASE);
11177 + if (!queue)
11178 + goto err_destroy0;
11179 + pio->queue1 = queue;
11180 +
11181 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO3_BASE);
11182 + if (!queue)
11183 + goto err_destroy1;
11184 + pio->queue2 = queue;
11185 +
11186 + queue = bcm43xx_setup_pioqueue(bcm, BCM43xx_MMIO_PIO4_BASE);
11187 + if (!queue)
11188 + goto err_destroy2;
11189 + pio->queue3 = queue;
11190 +
11191 + if (bcm->current_core->rev < 3)
11192 + bcm->irq_savedstate |= BCM43xx_IRQ_PIO_WORKAROUND;
11193 +
11194 + dprintk(KERN_INFO PFX "PIO initialized\n");
11195 + err = 0;
11196 +out:
11197 + return err;
11198 +
11199 +err_destroy2:
11200 + bcm43xx_destroy_pioqueue(pio->queue2);
11201 + pio->queue2 = NULL;
11202 +err_destroy1:
11203 + bcm43xx_destroy_pioqueue(pio->queue1);
11204 + pio->queue1 = NULL;
11205 +err_destroy0:
11206 + bcm43xx_destroy_pioqueue(pio->queue0);
11207 + pio->queue0 = NULL;
11208 + goto out;
11209 +}
11210 +
11211 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11212 + struct sk_buff *skb,
11213 + struct ieee80211_tx_control *ctl)
11214 +{
11215 + struct bcm43xx_pioqueue *queue = bcm43xx_current_pio(bcm)->queue1;
11216 + struct bcm43xx_pio_txpacket *packet;
11217 + u16 tmp;
11218 +
11219 + assert(!queue->tx_suspended);
11220 + assert(!list_empty(&queue->txfree));
11221 +
11222 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_TXCTL);
11223 + if (tmp & BCM43xx_PIO_TXCTL_SUSPEND)
11224 + return -EBUSY;
11225 +
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);
11232 +
11233 + tasklet_schedule(&queue->txtask);
11234 +
11235 + return 0;
11236 +}
11237 +
11238 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11239 + struct bcm43xx_xmitstatus *status)
11240 +{
11241 + struct bcm43xx_pioqueue *queue;
11242 + struct bcm43xx_pio_txpacket *packet;
11243 +
11244 + queue = parse_cookie(bcm, status->cookie, &packet);
11245 + assert(queue);
11246 +//TODO
11247 +if (!queue)
11248 +return;
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);
11253 +}
11254 +
11255 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11256 + struct ieee80211_tx_queue_stats *stats)
11257 +{
11258 + struct bcm43xx_pio *pio = bcm43xx_current_pio(bcm);
11259 + struct bcm43xx_pioqueue *queue;
11260 + struct ieee80211_tx_queue_stats_data *data;
11261 +
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;
11267 +}
11268 +
11269 +static void pio_rx_error(struct bcm43xx_pioqueue *queue,
11270 + int clear_buffers,
11271 + const char *error)
11272 +{
11273 + int i;
11274 +
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);
11283 + }
11284 + }
11285 +}
11286 +
11287 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11288 +{
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;
11294 +
11295 +return;
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.
11299 + return;
11300 + }
11301 + bcm43xx_pio_write(queue, BCM43xx_PIO_RXCTL,
11302 + BCM43xx_PIO_RXCTL_DATAAVAILABLE);
11303 +
11304 + for (i = 0; i < 10; i++) {
11305 + tmp = bcm43xx_pio_read(queue, BCM43xx_PIO_RXCTL);
11306 + if (tmp & BCM43xx_PIO_RXCTL_READY)
11307 + goto data_ready;
11308 + udelay(10);
11309 + }
11310 + dprintkl(KERN_ERR PFX "PIO RX timed out\n");
11311 + return;
11312 +data_ready:
11313 +
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");
11318 + return;
11319 + }
11320 + if (unlikely(len == 0 && queue->mmio_base != BCM43xx_MMIO_PIO4_BASE)) {
11321 + pio_rx_error(queue, 0, "len == 0");
11322 + return;
11323 + }
11324 + preamble[0] = cpu_to_le16(len);
11325 + if (queue->mmio_base == BCM43xx_MMIO_PIO4_BASE)
11326 + preamble_readwords = 14 / sizeof(u16);
11327 + else
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?
11332 + }
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");
11339 + return;
11340 + }
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;
11345 +
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);
11353 +
11354 + bcm43xx_debugfs_log_txstat(queue->bcm, &stat);
11355 + bcm43xx_pio_handle_xmitstatus(queue->bcm, &stat);
11356 +
11357 + return;
11358 + }
11359 +
11360 + skb = dev_alloc_skb(len);
11361 + if (unlikely(!skb)) {
11362 + pio_rx_error(queue, 1, "OOM");
11363 + return;
11364 + }
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;
11369 + }
11370 + if (len % 2) {
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;
11375 + else
11376 + skb->data[0x1E] = (tmp & 0xFF00) >> 8;
11377 + }
11378 + bcm43xx_rx(queue->bcm, skb, rxhdr);
11379 +}
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
11383 @@ -0,0 +1,146 @@
11384 +#ifndef BCM43xx_PIO_H_
11385 +#define BCM43xx_PIO_H_
11386 +
11387 +#include "bcm43xx.h"
11388 +
11389 +#include <linux/interrupt.h>
11390 +#include <linux/list.h>
11391 +#include <linux/skbuff.h>
11392 +
11393 +
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
11399 +
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)
11405 +
11406 +#define BCM43xx_PIO_RXCTL_DATAAVAILABLE (1 << 0)
11407 +#define BCM43xx_PIO_RXCTL_READY (1 << 1)
11408 +
11409 +/* PIO constants */
11410 +#define BCM43xx_PIO_MAXTXDEVQPACKETS 31
11411 +#define BCM43xx_PIO_TXQADJUST 80
11412 +
11413 +/* PIO tuning knobs */
11414 +#define BCM43xx_PIO_MAXTXPACKETS 256
11415 +
11416 +
11417 +
11418 +#ifdef CONFIG_BCM43XX_D80211_PIO
11419 +
11420 +
11421 +struct bcm43xx_pioqueue;
11422 +struct bcm43xx_xmitstatus;
11423 +
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;
11429 +};
11430 +
11431 +#define pio_txpacket_getindex(packet) ((int)((packet) - (packet)->queue->tx_packets_cache))
11432 +
11433 +struct bcm43xx_pioqueue {
11434 + struct bcm43xx_private *bcm;
11435 + u16 mmio_base;
11436 +
11437 + u8 tx_suspended:1,
11438 + need_workarounds:1; /* Workarounds needed for core.rev < 3 */
11439 +
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.
11448 + */
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.
11453 + */
11454 + struct list_head txqueue;
11455 + /* Packets on the txrunning queue are completely
11456 + * posted to the device. We are waiting for the txstatus.
11457 + */
11458 + struct list_head txrunning;
11459 + /* Total number or packets sent.
11460 + * (This counter can obviously wrap).
11461 + */
11462 + unsigned int nr_tx_packets;
11463 + struct tasklet_struct txtask;
11464 + struct bcm43xx_pio_txpacket tx_packets_cache[BCM43xx_PIO_MAXTXPACKETS];
11465 +};
11466 +
11467 +static inline
11468 +u16 bcm43xx_pio_read(struct bcm43xx_pioqueue *queue,
11469 + u16 offset)
11470 +{
11471 + return bcm43xx_read16(queue->bcm, queue->mmio_base + offset);
11472 +}
11473 +
11474 +static inline
11475 +void bcm43xx_pio_write(struct bcm43xx_pioqueue *queue,
11476 + u16 offset, u16 value)
11477 +{
11478 + bcm43xx_write16(queue->bcm, queue->mmio_base + offset, value);
11479 +}
11480 +
11481 +
11482 +int bcm43xx_pio_init(struct bcm43xx_private *bcm);
11483 +void bcm43xx_pio_free(struct bcm43xx_private *bcm);
11484 +
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);
11492 +
11493 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue);
11494 +
11495 +#else /* CONFIG_BCM43XX_D80211_PIO */
11496 +
11497 +static inline
11498 +int bcm43xx_pio_init(struct bcm43xx_private *bcm)
11499 +{
11500 + return 0;
11501 +}
11502 +static inline
11503 +void bcm43xx_pio_free(struct bcm43xx_private *bcm)
11504 +{
11505 +}
11506 +static inline
11507 +int bcm43xx_pio_tx(struct bcm43xx_private *bcm,
11508 + struct sk_buff *skb,
11509 + struct ieee80211_tx_control *ctl)
11510 +{
11511 + return 0;
11512 +}
11513 +static inline
11514 +void bcm43xx_pio_handle_xmitstatus(struct bcm43xx_private *bcm,
11515 + struct bcm43xx_xmitstatus *status)
11516 +{
11517 +}
11518 +static inline
11519 +void bcm43xx_pio_get_tx_stats(struct bcm43xx_private *bcm,
11520 + struct ieee80211_tx_queue_stats *stats)
11521 +{
11522 +}
11523 +static inline
11524 +void bcm43xx_pio_rx(struct bcm43xx_pioqueue *queue)
11525 +{
11526 +}
11527 +
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
11533 @@ -0,0 +1,358 @@
11534 +/*
11535 +
11536 + Broadcom BCM43xx wireless driver
11537 +
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>
11543 +
11544 + Some parts of the code in this file are derived from the ipw2200
11545 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11546 +
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.
11551 +
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.
11556 +
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.
11561 +
11562 +*/
11563 +
11564 +#include <linux/delay.h>
11565 +
11566 +#include "bcm43xx.h"
11567 +#include "bcm43xx_power.h"
11568 +#include "bcm43xx_main.h"
11569 +
11570 +
11571 +/* Get max/min slowclock frequency
11572 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11573 + */
11574 +static int bcm43xx_pctl_clockfreqlimit(struct bcm43xx_private *bcm,
11575 + int get_max)
11576 +{
11577 + int limit = 0;
11578 + int divisor;
11579 + int selection;
11580 + int err;
11581 + u32 tmp;
11582 + struct bcm43xx_coreinfo *old_core;
11583 +
11584 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11585 + goto out;
11586 + old_core = bcm->current_core;
11587 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11588 + if (err)
11589 + goto out;
11590 +
11591 + if (bcm->current_core->rev < 6) {
11592 + if ((bcm->bustype == BCM43xx_BUSTYPE_PCMCIA) ||
11593 + (bcm->bustype == BCM43xx_BUSTYPE_SB)) {
11594 + selection = 1;
11595 + divisor = 32;
11596 + } else {
11597 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &tmp);
11598 + if (err) {
11599 + printk(KERN_ERR PFX "clockfreqlimit pcicfg read failure\n");
11600 + goto out_switchback;
11601 + }
11602 + if (tmp & 0x10) {
11603 + /* PCI */
11604 + selection = 2;
11605 + divisor = 64;
11606 + } else {
11607 + /* XTAL */
11608 + selection = 1;
11609 + divisor = 32;
11610 + }
11611 + }
11612 + } else if (bcm->current_core->rev < 10) {
11613 + selection = (tmp & 0x07);
11614 + if (selection) {
11615 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SLOWCLKCTL);
11616 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11617 + } else
11618 + divisor = 1;
11619 + } else {
11620 + tmp = bcm43xx_read32(bcm, BCM43xx_CHIPCOMMON_SYSCLKCTL);
11621 + divisor = 4 * (1 + ((tmp & 0xFFFF0000) >> 16));
11622 + selection = 1;
11623 + }
11624 +
11625 + switch (selection) {
11626 + case 0:
11627 + /* LPO */
11628 + if (get_max)
11629 + limit = 43000;
11630 + else
11631 + limit = 25000;
11632 + break;
11633 + case 1:
11634 + /* XTAL */
11635 + if (get_max)
11636 + limit = 20200000;
11637 + else
11638 + limit = 19800000;
11639 + break;
11640 + case 2:
11641 + /* PCI */
11642 + if (get_max)
11643 + limit = 34000000;
11644 + else
11645 + limit = 25000000;
11646 + break;
11647 + default:
11648 + assert(0);
11649 + }
11650 + limit /= divisor;
11651 +
11652 +out_switchback:
11653 + err = bcm43xx_switch_core(bcm, old_core);
11654 + assert(err == 0);
11655 +
11656 +out:
11657 + return limit;
11658 +}
11659 +
11660 +/* init power control
11661 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11662 + */
11663 +int bcm43xx_pctl_init(struct bcm43xx_private *bcm)
11664 +{
11665 + int err, maxfreq;
11666 + struct bcm43xx_coreinfo *old_core;
11667 +
11668 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11669 + return 0;
11670 + old_core = bcm->current_core;
11671 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11672 + if (err == -ENODEV)
11673 + return 0;
11674 + if (err)
11675 + goto out;
11676 +
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);
11682 +
11683 + err = bcm43xx_switch_core(bcm, old_core);
11684 + assert(err == 0);
11685 +
11686 +out:
11687 + return err;
11688 +}
11689 +
11690 +u16 bcm43xx_pctl_powerup_delay(struct bcm43xx_private *bcm)
11691 +{
11692 + u16 delay = 0;
11693 + int err;
11694 + u32 pll_on_delay;
11695 + struct bcm43xx_coreinfo *old_core;
11696 + int minfreq;
11697 +
11698 + if (bcm->bustype != BCM43xx_BUSTYPE_PCI)
11699 + goto out;
11700 + if (!(bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL))
11701 + goto out;
11702 + old_core = bcm->current_core;
11703 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11704 + if (err == -ENODEV)
11705 + goto out;
11706 +
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;
11710 +
11711 + err = bcm43xx_switch_core(bcm, old_core);
11712 + assert(err == 0);
11713 +
11714 +out:
11715 + return delay;
11716 +}
11717 +
11718 +/* set the powercontrol clock
11719 + * as described in http://bcm-specs.sipsolutions.net/PowerControl
11720 + */
11721 +int bcm43xx_pctl_set_clock(struct bcm43xx_private *bcm, u16 mode)
11722 +{
11723 + int err;
11724 + struct bcm43xx_coreinfo *old_core;
11725 + u32 tmp;
11726 +
11727 + old_core = bcm->current_core;
11728 + err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11729 + if (err == -ENODEV)
11730 + return 0;
11731 + if (err)
11732 + goto out;
11733 +
11734 + if (bcm->core_chipcommon.rev < 6) {
11735 + if (mode == BCM43xx_PCTL_CLK_FAST) {
11736 + err = bcm43xx_pctl_set_crystal(bcm, 1);
11737 + if (err)
11738 + goto out;
11739 + }
11740 + } else {
11741 + if ((bcm->chipcommon_capabilities & BCM43xx_CAPABILITIES_PCTL) &&
11742 + (bcm->core_chipcommon.rev < 10)) {
11743 + switch (mode) {
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);
11748 + break;
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);
11753 + break;
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);
11760 + }
11761 + }
11762 + }
11763 +
11764 + err = bcm43xx_switch_core(bcm, old_core);
11765 + assert(err == 0);
11766 +
11767 +out:
11768 + return err;
11769 +}
11770 +
11771 +int bcm43xx_pctl_set_crystal(struct bcm43xx_private *bcm, int on)
11772 +{
11773 + int err;
11774 + u32 in, out, outenable;
11775 +
11776 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_IN, &in);
11777 + if (err)
11778 + goto err_pci;
11779 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUT, &out);
11780 + if (err)
11781 + goto err_pci;
11782 + err = bcm43xx_pci_read_config32(bcm, BCM43xx_PCTL_OUTENABLE, &outenable);
11783 + if (err)
11784 + goto err_pci;
11785 +
11786 + outenable |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11787 +
11788 + if (on) {
11789 + if (in & 0x40)
11790 + return 0;
11791 +
11792 + out |= (BCM43xx_PCTL_XTAL_POWERUP | BCM43xx_PCTL_PLL_POWERDOWN);
11793 +
11794 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11795 + if (err)
11796 + goto err_pci;
11797 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11798 + if (err)
11799 + goto err_pci;
11800 + udelay(1000);
11801 +
11802 + out &= ~BCM43xx_PCTL_PLL_POWERDOWN;
11803 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11804 + if (err)
11805 + goto err_pci;
11806 + udelay(5000);
11807 + } else {
11808 + if (bcm->current_core->rev < 5)
11809 + return 0;
11810 + if (bcm->sprom.boardflags & BCM43xx_BFL_XTAL_NOSLOW)
11811 + return 0;
11812 +
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);
11815 + * if (err)
11816 + * return err;
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))))
11821 + * return 0;
11822 + * err = bcm43xx_switch_core(bcm, &bcm->core_chipcommon);
11823 + * if (err)
11824 + * return err;
11825 + */
11826 +
11827 + err = bcm43xx_pctl_set_clock(bcm, BCM43xx_PCTL_CLK_SLOW);
11828 + if (err)
11829 + goto out;
11830 + out &= ~BCM43xx_PCTL_XTAL_POWERUP;
11831 + out |= BCM43xx_PCTL_PLL_POWERDOWN;
11832 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUT, out);
11833 + if (err)
11834 + goto err_pci;
11835 + err = bcm43xx_pci_write_config32(bcm, BCM43xx_PCTL_OUTENABLE, outenable);
11836 + if (err)
11837 + goto err_pci;
11838 + }
11839 +
11840 +out:
11841 + return err;
11842 +
11843 +err_pci:
11844 + printk(KERN_ERR PFX "Error: pctl_set_clock() could not access PCI config space!\n");
11845 + err = -EBUSY;
11846 + goto out;
11847 +}
11848 +
11849 +/* Set the PowerSavingControlBits.
11850 + * Bitvalues:
11851 + * 0 => unset the bit
11852 + * 1 => set the bit
11853 + * -1 => calculate the bit
11854 + */
11855 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11856 + int bit25, int bit26)
11857 +{
11858 + int i;
11859 + u32 status;
11860 +
11861 +//FIXME: Force 25 to off and 26 to on for now:
11862 +bit25 = 0;
11863 +bit26 = 1;
11864 +
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
11868 + }
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
11873 + }
11874 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
11875 + if (bit25)
11876 + status |= BCM43xx_SBF_PS1;
11877 + else
11878 + status &= ~BCM43xx_SBF_PS1;
11879 + if (bit26)
11880 + status |= BCM43xx_SBF_PS2;
11881 + else
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)
11887 + break;
11888 + udelay(10);
11889 + }
11890 + }
11891 +}
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
11895 @@ -0,0 +1,47 @@
11896 +/*
11897 +
11898 + Broadcom BCM43xx wireless driver
11899 +
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>
11905 +
11906 + Some parts of the code in this file are derived from the ipw2200
11907 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11908 +
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.
11913 +
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.
11918 +
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.
11923 +
11924 +*/
11925 +
11926 +#ifndef BCM43xx_POWER_H_
11927 +#define BCM43xx_POWER_H_
11928 +
11929 +#include <linux/types.h>
11930 +
11931 +
11932 +struct bcm43xx_private;
11933 +
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);
11938 +
11939 +void bcm43xx_power_saving_ctl_bits(struct bcm43xx_private *bcm,
11940 + int bit25, int bit26);
11941 +
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
11946 @@ -0,0 +1,2026 @@
11947 +/*
11948 +
11949 + Broadcom BCM43xx wireless driver
11950 +
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>
11956 +
11957 + Some parts of the code in this file are derived from the ipw2200
11958 + driver Copyright(c) 2003 - 2004 Intel Corporation.
11959 +
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.
11964 +
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.
11969 +
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.
11974 +
11975 +*/
11976 +
11977 +#include <linux/delay.h>
11978 +
11979 +#include "bcm43xx.h"
11980 +#include "bcm43xx_main.h"
11981 +#include "bcm43xx_phy.h"
11982 +#include "bcm43xx_radio.h"
11983 +#include "bcm43xx_ilt.h"
11984 +
11985 +
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,
11992 +};
11993 +
11994 +/* Reverse the bits of a 4bit value.
11995 + * Example: 1101 is flipped 1011
11996 + */
11997 +static u16 flip_4bit(u16 value)
11998 +{
11999 + u16 flipped = 0x0000;
12000 +
12001 + assert((value & ~0x000F) == 0x0000);
12002 +
12003 + flipped |= (value & 0x0001) << 3;
12004 + flipped |= (value & 0x0002) << 1;
12005 + flipped |= (value & 0x0004) >> 1;
12006 + flipped |= (value & 0x0008) >> 3;
12007 +
12008 + return flipped;
12009 +}
12010 +
12011 +/* Get the freq, as it has to be written to the device. */
12012 +static inline
12013 +u16 channel2freq_bg(u8 channel)
12014 +{
12015 + /* Frequencies are given as frequencies_bg[index] + 2.4GHz
12016 + * Starting with channel 1
12017 + */
12018 + static const u16 frequencies_bg[14] = {
12019 + 12, 17, 22, 27,
12020 + 32, 37, 42, 47,
12021 + 52, 57, 62, 67,
12022 + 72, 84,
12023 + };
12024 +
12025 + assert(channel >= 1 && channel <= 14);
12026 +
12027 + return frequencies_bg[channel - 1];
12028 +}
12029 +
12030 +/* Get the freq, as it has to be written to the device. */
12031 +static inline
12032 +u16 channel2freq_a(u8 channel)
12033 +{
12034 + assert(channel <= 200);
12035 +
12036 + return (5000 + 5 * channel);
12037 +}
12038 +
12039 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm)
12040 +{
12041 + u32 status;
12042 +
12043 + status = bcm43xx_read32(bcm, BCM43xx_MMIO_STATUS_BITFIELD);
12044 + status |= BCM43xx_SBF_RADIOREG_LOCK;
12045 + bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, status);
12046 + mmiowb();
12047 + udelay(10);
12048 +}
12049 +
12050 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm)
12051 +{
12052 + u32 status;
12053 +
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);
12058 + mmiowb();
12059 +}
12060 +
12061 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset)
12062 +{
12063 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12064 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12065 +
12066 + switch (phy->type) {
12067 + case BCM43xx_PHYTYPE_A:
12068 + offset |= 0x0040;
12069 + break;
12070 + case BCM43xx_PHYTYPE_B:
12071 + if (radio->version == 0x2053) {
12072 + if (offset < 0x70)
12073 + offset += 0x80;
12074 + else if (offset < 0x80)
12075 + offset += 0x70;
12076 + } else if (radio->version == 0x2050) {
12077 + offset |= 0x80;
12078 + } else
12079 + assert(0);
12080 + break;
12081 + case BCM43xx_PHYTYPE_G:
12082 + offset |= 0x80;
12083 + break;
12084 + }
12085 +
12086 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
12087 + return bcm43xx_read16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW);
12088 +}
12089 +
12090 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val)
12091 +{
12092 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_CONTROL, offset);
12093 + mmiowb();
12094 + bcm43xx_write16(bcm, BCM43xx_MMIO_RADIO_DATA_LOW, val);
12095 +}
12096 +
12097 +static void bcm43xx_set_all_gains(struct bcm43xx_private *bcm,
12098 + s16 first, s16 second, s16 third)
12099 +{
12100 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12101 + u16 i;
12102 + u16 start = 0x08, end = 0x18;
12103 + u16 offset = 0x0400;
12104 + u16 tmp;
12105 +
12106 + if (phy->rev <= 1) {
12107 + offset = 0x5000;
12108 + start = 0x10;
12109 + end = 0x20;
12110 + }
12111 +
12112 + for (i = 0; i < 4; i++)
12113 + bcm43xx_ilt_write(bcm, offset + i, first);
12114 +
12115 + for (i = start; i < end; i++)
12116 + bcm43xx_ilt_write(bcm, offset + i, second);
12117 +
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);
12126 + }
12127 + bcm43xx_dummy_transmission(bcm);
12128 +}
12129 +
12130 +static void bcm43xx_set_original_gains(struct bcm43xx_private *bcm)
12131 +{
12132 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12133 + u16 i, tmp;
12134 + u16 offset = 0x0400;
12135 + u16 start = 0x0008, end = 0x0018;
12136 +
12137 + if (phy->rev <= 1) {
12138 + offset = 0x5000;
12139 + start = 0x0010;
12140 + end = 0x0020;
12141 + }
12142 +
12143 + for (i = 0; i < 4; i++) {
12144 + tmp = (i & 0xFFFC);
12145 + tmp |= (i & 0x0001) << 1;
12146 + tmp |= (i & 0x0002) >> 1;
12147 +
12148 + bcm43xx_ilt_write(bcm, offset + i, tmp);
12149 + }
12150 +
12151 + for (i = start; i < end; i++)
12152 + bcm43xx_ilt_write(bcm, offset + i, i - start);
12153 +
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);
12161 +}
12162 +
12163 +/* Synthetic PU workaround */
12164 +static void bcm43xx_synth_pu_workaround(struct bcm43xx_private *bcm, u8 channel)
12165 +{
12166 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12167 +
12168 + if (radio->version != 0x2050 || radio->revision >= 6) {
12169 + /* We do not need the workaround. */
12170 + return;
12171 + }
12172 +
12173 + if (channel <= 10) {
12174 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12175 + channel2freq_bg(channel + 4));
12176 + } else {
12177 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12178 + channel2freq_bg(1));
12179 + }
12180 + udelay(100);
12181 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
12182 + channel2freq_bg(channel));
12183 +}
12184 +
12185 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel)
12186 +{
12187 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12188 + u8 ret = 0;
12189 + u16 saved, rssi, temp;
12190 + int i, j = 0;
12191 +
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;
12197 + else
12198 + rssi = saved & 0x3F;
12199 + /* clamp temp to signed 5bit */
12200 + if (rssi > 32)
12201 + rssi -= 64;
12202 + for (i = 0;i < 100; i++) {
12203 + temp = (bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x3F;
12204 + if (temp > 32)
12205 + temp -= 64;
12206 + if (temp < rssi)
12207 + j++;
12208 + if (j >= 20)
12209 + ret = 1;
12210 + }
12211 + bcm43xx_phy_write(bcm, 0x0403, saved);
12212 +
12213 + return ret;
12214 +}
12215 +
12216 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm)
12217 +{
12218 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12219 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12220 + u8 ret[13];
12221 + unsigned int channel = radio->channel;
12222 + unsigned int i, j, start, end;
12223 + unsigned long phylock_flags;
12224 +
12225 + if (!((phy->type == BCM43xx_PHYTYPE_G) && (phy->rev > 0)))
12226 + return 0;
12227 +
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);
12235 +
12236 + start = (channel - 5 > 0) ? channel - 5 : 1;
12237 + end = (channel + 5 < 14) ? channel + 5 : 13;
12238 +
12239 + for (i = start; i <= end; i++) {
12240 + if (abs(channel - i) > 2)
12241 + ret[i-1] = bcm43xx_radio_aci_detect(bcm, i);
12242 + }
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++) {
12252 + if (!ret[i])
12253 + continue;
12254 + end = (i + 5 < 13) ? i + 5 : 13;
12255 + for (j = i; j < end; j++)
12256 + ret[j] = 1;
12257 + }
12258 + bcm43xx_radio_unlock(bcm);
12259 + bcm43xx_phy_unlock(bcm, phylock_flags);
12260 +
12261 + return ret[channel - 1];
12262 +}
12263 +
12264 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12265 +void bcm43xx_nrssi_hw_write(struct bcm43xx_private *bcm, u16 offset, s16 val)
12266 +{
12267 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12268 + mmiowb();
12269 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_DATA, (u16)val);
12270 +}
12271 +
12272 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12273 +s16 bcm43xx_nrssi_hw_read(struct bcm43xx_private *bcm, u16 offset)
12274 +{
12275 + u16 val;
12276 +
12277 + bcm43xx_phy_write(bcm, BCM43xx_PHY_NRSSILT_CTRL, offset);
12278 + val = bcm43xx_phy_read(bcm, BCM43xx_PHY_NRSSILT_DATA);
12279 +
12280 + return (s16)val;
12281 +}
12282 +
12283 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12284 +void bcm43xx_nrssi_hw_update(struct bcm43xx_private *bcm, u16 val)
12285 +{
12286 + u16 i;
12287 + s16 tmp;
12288 +
12289 + for (i = 0; i < 64; i++) {
12290 + tmp = bcm43xx_nrssi_hw_read(bcm, i);
12291 + tmp -= val;
12292 + tmp = limit_value(tmp, -32, 31);
12293 + bcm43xx_nrssi_hw_write(bcm, i, tmp);
12294 + }
12295 +}
12296 +
12297 +/* http://bcm-specs.sipsolutions.net/NRSSILookupTable */
12298 +void bcm43xx_nrssi_mem_update(struct bcm43xx_private *bcm)
12299 +{
12300 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12301 + s16 i, delta;
12302 + s32 tmp;
12303 +
12304 + delta = 0x1F - radio->nrssi[0];
12305 + for (i = 0; i < 64; i++) {
12306 + tmp = (i - delta) * radio->nrssislope;
12307 + tmp /= 0x10000;
12308 + tmp += 0x3A;
12309 + tmp = limit_value(tmp, 0, 0x3F);
12310 + radio->nrssi_lt[i] = tmp;
12311 + }
12312 +}
12313 +
12314 +static void bcm43xx_calc_nrssi_offset(struct bcm43xx_private *bcm)
12315 +{
12316 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12317 + u16 backup[20] = { 0 };
12318 + s16 v47F;
12319 + u16 i;
12320 + u16 saved = 0xFFFF;
12321 +
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);
12334 +
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);
12354 +
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);
12367 + }
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);
12372 + udelay(30);
12373 +
12374 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12375 + if (v47F >= 0x20)
12376 + v47F -= 0x40;
12377 + if (v47F == 31) {
12378 + for (i = 7; i >= 4; i--) {
12379 + bcm43xx_radio_write16(bcm, 0x007B, i);
12380 + udelay(20);
12381 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12382 + if (v47F >= 0x20)
12383 + v47F -= 0x40;
12384 + if (v47F < 31 && saved == 0xFFFF)
12385 + saved = i;
12386 + }
12387 + if (saved == 0xFFFF)
12388 + saved = 4;
12389 + } else {
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);
12409 + } else {
12410 + bcm43xx_phy_write(bcm, 0x000A,
12411 + bcm43xx_phy_read(bcm, 0x000A)
12412 + | 0x2000);
12413 + }
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)
12420 + | 0x0040);
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);
12427 + udelay(30);
12428 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12429 + if (v47F >= 0x20)
12430 + v47F -= 0x40;
12431 + if (v47F == -32) {
12432 + for (i = 0; i < 4; i++) {
12433 + bcm43xx_radio_write16(bcm, 0x007B, i);
12434 + udelay(20);
12435 + v47F = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12436 + if (v47F >= 0x20)
12437 + v47F -= 0x40;
12438 + if (v47F > -31 && saved == 0xFFFF)
12439 + saved = i;
12440 + }
12441 + if (saved == 0xFFFF)
12442 + saved = 3;
12443 + } else
12444 + saved = 0;
12445 + }
12446 + bcm43xx_radio_write16(bcm, 0x007B, saved);
12447 +
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]);
12453 + }
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]);
12473 + }
12474 + bcm43xx_phy_write(bcm, 0x0001, backup[0]);
12475 + bcm43xx_phy_write(bcm, 0x0812, backup[2]);
12476 + bcm43xx_phy_write(bcm, 0x0811, backup[1]);
12477 +}
12478 +
12479 +void bcm43xx_calc_nrssi_slope(struct bcm43xx_private *bcm)
12480 +{
12481 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12482 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12483 + u16 backup[18] = { 0 };
12484 + u16 tmp;
12485 + s16 nrssi0, nrssi1;
12486 +
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);
12503 +
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);
12515 +
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);
12523 + } else {
12524 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12525 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT) & 0x2000);
12526 + }
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);
12535 + udelay(20);
12536 +
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]);
12547 +
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]);
12554 +
12555 + if (nrssi0 == nrssi1)
12556 + radio->nrssislope = 0x00010000;
12557 + else
12558 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12559 +
12560 + if (nrssi0 <= -4) {
12561 + radio->nrssi[0] = nrssi0;
12562 + radio->nrssi[1] = nrssi1;
12563 + }
12564 + break;
12565 + case BCM43xx_PHYTYPE_G:
12566 + if (radio->revision >= 9)
12567 + return;
12568 + if (radio->revision == 8)
12569 + bcm43xx_calc_nrssi_offset(bcm);
12570 +
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)
12602 + | 0x0100);
12603 + bcm43xx_phy_write(bcm, 0x0801,
12604 + bcm43xx_phy_read(bcm, 0x0801)
12605 + | 0x0040);
12606 + break;
12607 + case 3: case 5:
12608 + bcm43xx_phy_write(bcm, 0x0801,
12609 + bcm43xx_phy_read(bcm, 0x0801)
12610 + & 0xFFBF);
12611 + break;
12612 + }
12613 + bcm43xx_phy_write(bcm, 0x0060,
12614 + bcm43xx_phy_read(bcm, 0x0060)
12615 + | 0x0040);
12616 + bcm43xx_phy_write(bcm, 0x0014,
12617 + bcm43xx_phy_read(bcm, 0x0014)
12618 + | 0x0200);
12619 + }
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);
12630 + }
12631 + bcm43xx_radio_write16(bcm, 0x007A,
12632 + bcm43xx_radio_read16(bcm, 0x007A) | 0x0080);
12633 + udelay(20);
12634 +
12635 + nrssi0 = (s16)((bcm43xx_phy_read(bcm, 0x047F) >> 8) & 0x003F);
12636 + if (nrssi0 >= 0x0020)
12637 + nrssi0 -= 0x0040;
12638 +
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);
12645 + }
12646 +
12647 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
12648 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
12649 + | 0x2000);
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);
12658 + }
12659 +
12660 + bcm43xx_set_all_gains(bcm, 3, 0, 1);
12661 + if (radio->revision == 8) {
12662 + bcm43xx_radio_write16(bcm, 0x0043, 0x001F);
12663 + } else {
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);
12668 + }
12669 + bcm43xx_phy_write(bcm, 0x005A, 0x0480);
12670 + bcm43xx_phy_write(bcm, 0x0059, 0x0810);
12671 + bcm43xx_phy_write(bcm, 0x0058, 0x000D);
12672 + udelay(20);
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;
12678 + else
12679 + radio->nrssislope = 0x00400000 / (nrssi0 - nrssi1);
12680 + if (nrssi0 >= -4) {
12681 + radio->nrssi[0] = nrssi1;
12682 + radio->nrssi[1] = nrssi0;
12683 + }
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]);
12689 + }
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);
12695 + }
12696 +
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]);
12718 + }
12719 + bcm43xx_nrssi_mem_update(bcm);
12720 + bcm43xx_calc_nrssi_threshold(bcm);
12721 + break;
12722 + default:
12723 + assert(0);
12724 + }
12725 +}
12726 +
12727 +void bcm43xx_calc_nrssi_threshold(struct bcm43xx_private *bcm)
12728 +{
12729 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12730 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12731 + s32 threshold;
12732 + s32 a, b;
12733 + s16 tmp16;
12734 + u16 tmp_u16;
12735 +
12736 + switch (phy->type) {
12737 + case BCM43xx_PHYTYPE_B: {
12738 + if (radio->version != 0x2050)
12739 + return;
12740 + if (!(bcm->sprom.boardflags & BCM43xx_BFL_RSSI))
12741 + return;
12742 +
12743 + if (radio->revision >= 6) {
12744 + threshold = (radio->nrssi[1] - radio->nrssi[0]) * 32;
12745 + threshold += 20 * (radio->nrssi[0] + 1);
12746 + threshold /= 40;
12747 + } else
12748 + threshold = radio->nrssi[1] - 5;
12749 +
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);
12753 +
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);
12763 + }
12764 + break;
12765 + }
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)
12771 + tmp16 -= 0x40;
12772 + if (tmp16 < 3) {
12773 + bcm43xx_phy_write(bcm, 0x048A,
12774 + (bcm43xx_phy_read(bcm, 0x048A)
12775 + & 0xF000) | 0x09EB);
12776 + } else {
12777 + bcm43xx_phy_write(bcm, 0x048A,
12778 + (bcm43xx_phy_read(bcm, 0x048A)
12779 + & 0xF000) | 0x0AED);
12780 + }
12781 + } else {
12782 + if (radio->interfmode == BCM43xx_RADIO_INTERFMODE_NONWLAN) {
12783 + a = 0xE;
12784 + b = 0xA;
12785 + } else if (!radio->aci_wlan_automatic && radio->aci_enable) {
12786 + a = 0x13;
12787 + b = 0x12;
12788 + } else {
12789 + a = 0xE;
12790 + b = 0x11;
12791 + }
12792 +
12793 + a = a * (radio->nrssi[1] - radio->nrssi[0]);
12794 + a += (radio->nrssi[0] << 6);
12795 + if (a < 32)
12796 + a += 31;
12797 + else
12798 + a += 32;
12799 + a = a >> 6;
12800 + a = limit_value(a, -31, 31);
12801 +
12802 + b = b * (radio->nrssi[1] - radio->nrssi[0]);
12803 + b += (radio->nrssi[0] << 6);
12804 + if (b < 32)
12805 + b += 31;
12806 + else
12807 + b += 32;
12808 + b = b >> 6;
12809 + b = limit_value(b, -31, 31);
12810 +
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);
12815 + }
12816 + break;
12817 + default:
12818 + assert(0);
12819 + }
12820 +}
12821 +
12822 +/* Stack implementation to save/restore values from the
12823 + * interference mitigation code.
12824 + * It is save to restore values in random order.
12825 + */
12826 +static void _stack_save(u32 *_stackptr, size_t *stackidx,
12827 + u8 id, u16 offset, u16 value)
12828 +{
12829 + u32 *stackptr = &(_stackptr[*stackidx]);
12830 +
12831 + assert((offset & 0xF000) == 0x0000);
12832 + assert((id & 0xF0) == 0x00);
12833 + *stackptr = offset;
12834 + *stackptr |= ((u32)id) << 12;
12835 + *stackptr |= ((u32)value) << 16;
12836 + (*stackidx)++;
12837 + assert(*stackidx < BCM43xx_INTERFSTACK_SIZE);
12838 +}
12839 +
12840 +static u16 _stack_restore(u32 *stackptr,
12841 + u8 id, u16 offset)
12842 +{
12843 + size_t i;
12844 +
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)
12849 + continue;
12850 + if (((*stackptr & 0x0000F000) >> 12) != id)
12851 + continue;
12852 + return ((*stackptr & 0xFFFF0000) >> 16);
12853 + }
12854 + assert(0);
12855 +
12856 + return 0;
12857 +}
12858 +
12859 +#define phy_stacksave(offset) \
12860 + do { \
12861 + _stack_save(stack, &stackidx, 0x1, (offset), \
12862 + bcm43xx_phy_read(bcm, (offset))); \
12863 + } while (0)
12864 +#define phy_stackrestore(offset) \
12865 + do { \
12866 + bcm43xx_phy_write(bcm, (offset), \
12867 + _stack_restore(stack, 0x1, \
12868 + (offset))); \
12869 + } while (0)
12870 +#define radio_stacksave(offset) \
12871 + do { \
12872 + _stack_save(stack, &stackidx, 0x2, (offset), \
12873 + bcm43xx_radio_read16(bcm, (offset))); \
12874 + } while (0)
12875 +#define radio_stackrestore(offset) \
12876 + do { \
12877 + bcm43xx_radio_write16(bcm, (offset), \
12878 + _stack_restore(stack, 0x2, \
12879 + (offset))); \
12880 + } while (0)
12881 +#define ilt_stacksave(offset) \
12882 + do { \
12883 + _stack_save(stack, &stackidx, 0x3, (offset), \
12884 + bcm43xx_ilt_read(bcm, (offset))); \
12885 + } while (0)
12886 +#define ilt_stackrestore(offset) \
12887 + do { \
12888 + bcm43xx_ilt_write(bcm, (offset), \
12889 + _stack_restore(stack, 0x3, \
12890 + (offset))); \
12891 + } while (0)
12892 +
12893 +static void
12894 +bcm43xx_radio_interference_mitigation_enable(struct bcm43xx_private *bcm,
12895 + int mode)
12896 +{
12897 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
12898 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
12899 + u16 tmp, flipped;
12900 + u32 tmp32;
12901 + size_t stackidx = 0;
12902 + u32 *stack = radio->interfstack;
12903 +
12904 + switch (mode) {
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);
12911 + break;
12912 + }
12913 + radio_stacksave(0x0078);
12914 + tmp = (bcm43xx_radio_read16(bcm, 0x0078) & 0x001E);
12915 + flipped = flip_4bit(tmp);
12916 + if (flipped < 10 && flipped >= 8)
12917 + flipped = 7;
12918 + else if (flipped >= 10)
12919 + flipped -= 3;
12920 + flipped = flip_4bit(flipped);
12921 + flipped = (flipped << 1) | 0x0020;
12922 + bcm43xx_radio_write16(bcm, 0x0078, flipped);
12923 +
12924 + bcm43xx_calc_nrssi_threshold(bcm);
12925 +
12926 + phy_stacksave(0x0406);
12927 + bcm43xx_phy_write(bcm, 0x0406, 0x7E28);
12928 +
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);
12933 +
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);
12949 +
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);
12962 + break;
12963 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
12964 + if (bcm43xx_phy_read(bcm, 0x0033) & 0x0800)
12965 + break;
12966 +
12967 + radio->aci_enable = 1;
12968 +
12969 + phy_stacksave(BCM43xx_PHY_RADIO_BITFIELD);
12970 + phy_stacksave(BCM43xx_PHY_G_CRS);
12971 + if (phy->rev < 2) {
12972 + phy_stacksave(0x0406);
12973 + } else {
12974 + phy_stacksave(0x04C0);
12975 + phy_stacksave(0x04C1);
12976 + }
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);
13000 + }
13001 + phy_stacksave(0x042B);
13002 + phy_stacksave(0x048C);
13003 +
13004 + bcm43xx_phy_write(bcm, BCM43xx_PHY_RADIO_BITFIELD,
13005 + bcm43xx_phy_read(bcm, BCM43xx_PHY_RADIO_BITFIELD)
13006 + & ~0x1000);
13007 + bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS,
13008 + (bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS)
13009 + & 0xFFFC) | 0x0002);
13010 +
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);
13017 +
13018 + bcm43xx_phy_write(bcm, 0x04A0,
13019 + (bcm43xx_phy_read(bcm, 0x04A0)
13020 + & 0xFFC0) | 0x001A);
13021 + bcm43xx_phy_write(bcm, 0x04A7, 0x000D);
13022 +
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);
13028 + } else {
13029 + bcm43xx_phy_write(bcm, 0x04C0, 0x00C1);
13030 + bcm43xx_phy_write(bcm, 0x04C1, 0x0059);
13031 + }
13032 +
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);
13072 +
13073 + if (phy->rev >= 3) {
13074 + bcm43xx_phy_write(bcm, 0x048A,
13075 + bcm43xx_phy_read(bcm, 0x048A)
13076 + & ~0x8000);
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);
13086 + } else {
13087 + bcm43xx_phy_write(bcm, 0x048A,
13088 + bcm43xx_phy_read(bcm, 0x048A)
13089 + | 0x1000);
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)) {
13096 + tmp32 |= 0x800;
13097 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13098 + BCM43xx_UCODEFLAGS_OFFSET,
13099 + tmp32);
13100 + }
13101 + }
13102 + if (phy->rev >= 2) {
13103 + bcm43xx_phy_write(bcm, 0x042B,
13104 + bcm43xx_phy_read(bcm, 0x042B)
13105 + | 0x0800);
13106 + }
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)
13122 + & 0x00FF);
13123 + }
13124 + bcm43xx_calc_nrssi_slope(bcm);
13125 + break;
13126 + default:
13127 + assert(0);
13128 + }
13129 +}
13130 +
13131 +static void
13132 +bcm43xx_radio_interference_mitigation_disable(struct bcm43xx_private *bcm,
13133 + int mode)
13134 +{
13135 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13136 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13137 + u32 tmp32;
13138 + u32 *stack = radio->interfstack;
13139 +
13140 + switch (mode) {
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);
13147 + break;
13148 + }
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)
13157 + & ~(1 << 11));
13158 + }
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);
13172 + break;
13173 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13174 + if (!(bcm43xx_phy_read(bcm, 0x0033) & 0x0800))
13175 + break;
13176 +
13177 + radio->aci_enable = 0;
13178 +
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);
13192 + } else
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);
13207 + }
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) {
13215 + tmp32 &= ~0x800;
13216 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13217 + BCM43xx_UCODEFLAGS_OFFSET,
13218 + tmp32);
13219 + }
13220 + bcm43xx_calc_nrssi_slope(bcm);
13221 + break;
13222 + default:
13223 + assert(0);
13224 + }
13225 +}
13226 +
13227 +#undef phy_stacksave
13228 +#undef phy_stackrestore
13229 +#undef radio_stacksave
13230 +#undef radio_stackrestore
13231 +#undef ilt_stacksave
13232 +#undef ilt_stackrestore
13233 +
13234 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm,
13235 + int mode)
13236 +{
13237 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13238 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13239 + int currentmode;
13240 +
13241 + if ((phy->type != BCM43xx_PHYTYPE_G) ||
13242 + (phy->rev == 0) ||
13243 + (!phy->connected))
13244 + return -ENODEV;
13245 +
13246 + radio->aci_wlan_automatic = 0;
13247 + switch (mode) {
13248 + case BCM43xx_RADIO_INTERFMODE_AUTOWLAN:
13249 + radio->aci_wlan_automatic = 1;
13250 + if (radio->aci_enable)
13251 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
13252 + else
13253 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
13254 + break;
13255 + case BCM43xx_RADIO_INTERFMODE_NONE:
13256 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
13257 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
13258 + break;
13259 + default:
13260 + return -EINVAL;
13261 + }
13262 +
13263 + currentmode = radio->interfmode;
13264 + if (currentmode == mode)
13265 + return 0;
13266 + if (currentmode != BCM43xx_RADIO_INTERFMODE_NONE)
13267 + bcm43xx_radio_interference_mitigation_disable(bcm, currentmode);
13268 +
13269 + if (mode == BCM43xx_RADIO_INTERFMODE_NONE) {
13270 + radio->aci_enable = 0;
13271 + radio->aci_hw_rssi = 0;
13272 + } else
13273 + bcm43xx_radio_interference_mitigation_enable(bcm, mode);
13274 + radio->interfmode = mode;
13275 +
13276 + return 0;
13277 +}
13278 +
13279 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm)
13280 +{
13281 + u16 reg, index, ret;
13282 +
13283 + reg = bcm43xx_radio_read16(bcm, 0x0060);
13284 + index = (reg & 0x001E) >> 1;
13285 + ret = rcc_table[index] << 1;
13286 + ret |= (reg & 0x0001);
13287 + ret |= 0x0020;
13288 +
13289 + return ret;
13290 +}
13291 +
13292 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm)
13293 +{
13294 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13295 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13296 + u16 backup[19] = { 0 };
13297 + u16 ret;
13298 + u16 i, j;
13299 + u32 tmp1 = 0, tmp2 = 0;
13300 +
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);
13313 + } else {
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);
13331 + }
13332 + bcm43xx_write16(bcm, BCM43xx_MMIO_PHY_RADIO,
13333 + (bcm43xx_read16(bcm, BCM43xx_MMIO_PHY_RADIO) | 0x8000));
13334 + }
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);
13340 +
13341 + // Initialization
13342 + if (phy->version == 0) {
13343 + bcm43xx_write16(bcm, 0x03E6, 0x0122);
13344 + } else {
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));
13349 + }
13350 +
13351 + ret = bcm43xx_radio_calibrationvalue(bcm);
13352 +
13353 + if (phy->type == BCM43xx_PHYTYPE_B)
13354 + bcm43xx_radio_write16(bcm, 0x0078, 0x0003);
13355 +
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);
13367 +
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);
13375 + udelay(10);
13376 + if (phy->connected)
13377 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13378 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13379 + udelay(10);
13380 + if (phy->connected)
13381 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13382 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13383 + udelay(10);
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);
13389 + }
13390 +
13391 + tmp1++;
13392 + tmp1 >>= 9;
13393 + udelay(10);
13394 + bcm43xx_phy_write(bcm, 0x0058, 0x0000);
13395 +
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);
13399 + udelay(10);
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);
13407 + udelay(10);
13408 + if (phy->connected)
13409 + bcm43xx_phy_write(bcm, 0x0812, 0x30B2);
13410 + bcm43xx_phy_write(bcm, 0x0015, 0xEFB0);
13411 + udelay(10);
13412 + if (phy->connected)
13413 + bcm43xx_phy_write(bcm, 0x0812, 0x30B3); /* 0x30B3 is not a typo */
13414 + bcm43xx_phy_write(bcm, 0x0015, 0xFFF0);
13415 + udelay(10);
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);
13421 + }
13422 + tmp2++;
13423 + tmp2 >>= 8;
13424 + if (tmp1 < tmp2)
13425 + break;
13426 + }
13427 +
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]);
13444 + } else {
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]);
13454 + }
13455 + }
13456 + if (i >= 15)
13457 + ret = backup[13];
13458 +
13459 + return ret;
13460 +}
13461 +
13462 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm)
13463 +{
13464 + int err;
13465 +
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);
13481 + udelay(400);
13482 +
13483 + bcm43xx_radio_write16(bcm, 0x0081, (bcm43xx_radio_read16(bcm, 0x0081) & ~0x0020) | 0x0010);
13484 + udelay(400);
13485 +
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);
13495 +
13496 + err = bcm43xx_radio_selectchannel(bcm, BCM43xx_RADIO_DEFAULT_CHANNEL_A, 0);
13497 + assert(err == 0);
13498 + udelay(1000);
13499 +}
13500 +
13501 +static inline
13502 +u16 freq_r3A_value(u16 frequency)
13503 +{
13504 + u16 value;
13505 +
13506 + if (frequency < 5091)
13507 + value = 0x0040;
13508 + else if (frequency < 5321)
13509 + value = 0x0000;
13510 + else if (frequency < 5806)
13511 + value = 0x0080;
13512 + else
13513 + value = 0x0040;
13514 +
13515 + return value;
13516 +}
13517 +
13518 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm)
13519 +{
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);
13523 + int i, j;
13524 +
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);
13529 + return;
13530 + }
13531 + }
13532 + }
13533 +}
13534 +
13535 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm,
13536 + u8 channel,
13537 + int synthetic_pu_workaround)
13538 +{
13539 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13540 + u16 r8, tmp;
13541 + u16 freq;
13542 +
13543 + if ((radio->manufact == 0x17F) &&
13544 + (radio->version == 0x2060) &&
13545 + (radio->revision == 1)) {
13546 + if (channel > 200)
13547 + return -EINVAL;
13548 + freq = channel2freq_a(channel);
13549 +
13550 + r8 = bcm43xx_radio_read16(bcm, 0x0008);
13551 + bcm43xx_write16(bcm, 0x03F0, freq);
13552 + bcm43xx_radio_write16(bcm, 0x0008, r8);
13553 +
13554 + TODO();//TODO: write max channel TX power? to Radio 0x2D
13555 + tmp = bcm43xx_radio_read16(bcm, 0x002E);
13556 + tmp &= 0x0080;
13557 + TODO();//TODO: OR tmp with the Power out estimation for this channel?
13558 + bcm43xx_radio_write16(bcm, 0x002E, tmp);
13559 +
13560 + if (freq >= 4920 && freq <= 5500) {
13561 + /*
13562 + * r8 = (((freq * 15 * 0xE1FC780F) >> 32) / 29) & 0x0F;
13563 + * = (freq * 0.025862069
13564 + */
13565 + r8 = 3 * freq / 116; /* is equal to r8 = freq * 0.025862 */
13566 + }
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?
13599 + } else {
13600 + if ((channel < 1) || (channel > 14))
13601 + return -EINVAL;
13602 +
13603 + if (synthetic_pu_workaround)
13604 + bcm43xx_synth_pu_workaround(bcm, channel);
13605 +
13606 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL,
13607 + channel2freq_bg(channel));
13608 +
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)
13615 + & ~(1 << 7));
13616 + } else {
13617 + bcm43xx_shm_write32(bcm, BCM43xx_SHM_SHARED,
13618 + BCM43xx_UCODEFLAGS_OFFSET,
13619 + bcm43xx_shm_read32(bcm, BCM43xx_SHM_SHARED,
13620 + BCM43xx_UCODEFLAGS_OFFSET)
13621 + | (1 << 7));
13622 + }
13623 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13624 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13625 + | (1 << 11));
13626 + } else {
13627 + bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT,
13628 + bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT)
13629 + & 0xF7BF);
13630 + }
13631 + }
13632 +
13633 + radio->channel = channel;
13634 + //XXX: Using the longer of 2 timeouts (8000 vs 2000 usecs). Specs states
13635 + // that 2000 usecs might suffice.
13636 + udelay(8000);
13637 +
13638 + return 0;
13639 +}
13640 +
13641 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val)
13642 +{
13643 + u16 tmp;
13644 +
13645 + val <<= 8;
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);
13652 +}
13653 +
13654 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Base_Band */
13655 +static u16 bcm43xx_get_txgain_base_band(u16 txpower)
13656 +{
13657 + u16 ret;
13658 +
13659 + assert(txpower <= 63);
13660 +
13661 + if (txpower >= 54)
13662 + ret = 2;
13663 + else if (txpower >= 49)
13664 + ret = 4;
13665 + else if (txpower >= 44)
13666 + ret = 5;
13667 + else
13668 + ret = 6;
13669 +
13670 + return ret;
13671 +}
13672 +
13673 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Radio_Frequency_Power_Amplifier */
13674 +static u16 bcm43xx_get_txgain_freq_power_amp(u16 txpower)
13675 +{
13676 + u16 ret;
13677 +
13678 + assert(txpower <= 63);
13679 +
13680 + if (txpower >= 32)
13681 + ret = 0;
13682 + else if (txpower >= 25)
13683 + ret = 1;
13684 + else if (txpower >= 20)
13685 + ret = 2;
13686 + else if (txpower >= 12)
13687 + ret = 3;
13688 + else
13689 + ret = 4;
13690 +
13691 + return ret;
13692 +}
13693 +
13694 +/* http://bcm-specs.sipsolutions.net/TX_Gain_Digital_Analog_Converter */
13695 +static u16 bcm43xx_get_txgain_dac(u16 txpower)
13696 +{
13697 + u16 ret;
13698 +
13699 + assert(txpower <= 63);
13700 +
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;
13715 + else
13716 + ret = txpower;
13717 +
13718 + return ret;
13719 +}
13720 +
13721 +void bcm43xx_radio_set_txpower_a(struct bcm43xx_private *bcm, u16 txpower)
13722 +{
13723 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13724 + u16 pamp, base, dac, ilt;
13725 +
13726 + txpower = limit_value(txpower, 0, 63);
13727 +
13728 + pamp = bcm43xx_get_txgain_freq_power_amp(txpower);
13729 + pamp <<= 5;
13730 + pamp &= 0x00E0;
13731 + bcm43xx_phy_write(bcm, 0x0019, pamp);
13732 +
13733 + base = bcm43xx_get_txgain_base_band(txpower);
13734 + base &= 0x000F;
13735 + bcm43xx_phy_write(bcm, 0x0017, base | 0x0020);
13736 +
13737 + ilt = bcm43xx_ilt_read(bcm, 0x3001);
13738 + ilt &= 0x0007;
13739 +
13740 + dac = bcm43xx_get_txgain_dac(txpower);
13741 + dac <<= 3;
13742 + dac |= ilt;
13743 +
13744 + bcm43xx_ilt_write(bcm, 0x3001, dac);
13745 +
13746 + radio->txpwr_offset = txpower;
13747 +
13748 + TODO();
13749 + //TODO: FuncPlaceholder (Adjust BB loft cancel)
13750 +}
13751 +
13752 +void bcm43xx_radio_set_txpower_bg(struct bcm43xx_private *bcm,
13753 + u16 baseband_attenuation, u16 radio_attenuation,
13754 + u16 txpower)
13755 +{
13756 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13757 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13758 +
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;
13768 +
13769 + assert(/*baseband_attenuation >= 0 &&*/ baseband_attenuation <= 11);
13770 + if (radio->revision < 6)
13771 + assert(/*radio_attenuation >= 0 &&*/ radio_attenuation <= 9);
13772 + else
13773 + assert(/* radio_attenuation >= 0 &&*/ radio_attenuation <= 31);
13774 + assert(/*txpower >= 0 &&*/ txpower <= 7);
13775 +
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));
13783 + }
13784 + //FIXME: The spec is very weird and unclear here.
13785 + if (phy->type == BCM43xx_PHYTYPE_G)
13786 + bcm43xx_phy_lo_adjust(bcm, 0);
13787 +}
13788 +
13789 +u16 bcm43xx_default_baseband_attenuation(struct bcm43xx_private *bcm)
13790 +{
13791 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13792 +
13793 + if (radio->version == 0x2050 && radio->revision < 6)
13794 + return 0;
13795 + return 2;
13796 +}
13797 +
13798 +u16 bcm43xx_default_radio_attenuation(struct bcm43xx_private *bcm)
13799 +{
13800 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13801 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13802 + u16 att = 0xFFFF;
13803 +
13804 + if (phy->type == BCM43xx_PHYTYPE_A)
13805 + return 0x60;
13806 +
13807 + switch (radio->version) {
13808 + case 0x2053:
13809 + switch (radio->revision) {
13810 + case 1:
13811 + att = 6;
13812 + break;
13813 + }
13814 + break;
13815 + case 0x2050:
13816 + switch (radio->revision) {
13817 + case 0:
13818 + att = 5;
13819 + break;
13820 + case 1:
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)
13825 + att = 3;
13826 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13827 + bcm->board_type == 0x416)
13828 + att = 3;
13829 + else
13830 + att = 1;
13831 + } else {
13832 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13833 + bcm->board_type == 0x421 &&
13834 + bcm->board_revision >= 30)
13835 + att = 7;
13836 + else
13837 + att = 6;
13838 + }
13839 + break;
13840 + case 2:
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)
13845 + att = 3;
13846 + else if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13847 + bcm->board_type == 0x416)
13848 + att = 5;
13849 + else if (bcm->chip_id == 0x4320)
13850 + att = 4;
13851 + else
13852 + att = 3;
13853 + } else
13854 + att = 6;
13855 + break;
13856 + case 3:
13857 + att = 5;
13858 + break;
13859 + case 4:
13860 + case 5:
13861 + att = 1;
13862 + break;
13863 + case 6:
13864 + case 7:
13865 + att = 5;
13866 + break;
13867 + case 8:
13868 + att = 0x1A;
13869 + break;
13870 + case 9:
13871 + default:
13872 + att = 5;
13873 + }
13874 + }
13875 + if (bcm->board_vendor == PCI_VENDOR_ID_BROADCOM &&
13876 + bcm->board_type == 0x421) {
13877 + if (bcm->board_revision < 0x43)
13878 + att = 2;
13879 + else if (bcm->board_revision < 0x51)
13880 + att = 3;
13881 + }
13882 + if (att == 0xFFFF)
13883 + att = 5;
13884 +
13885 + return att;
13886 +}
13887 +
13888 +u16 bcm43xx_default_txctl1(struct bcm43xx_private *bcm)
13889 +{
13890 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13891 +
13892 + if (radio->version != 0x2050)
13893 + return 0;
13894 + if (radio->revision == 1)
13895 + return 3;
13896 + if (radio->revision < 6)
13897 + return 2;
13898 + if (radio->revision == 8)
13899 + return 1;
13900 + return 0;
13901 +}
13902 +
13903 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm)
13904 +{
13905 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13906 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13907 + int err;
13908 +
13909 + if (radio->enabled)
13910 + return;
13911 +
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);
13919 + break;
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);
13927 + break;
13928 + default:
13929 + assert(0);
13930 + }
13931 + radio->enabled = 1;
13932 + dprintk(KERN_INFO PFX "Radio turned on\n");
13933 +}
13934 +
13935 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm)
13936 +{
13937 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13938 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
13939 +
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);
13945 + }
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);
13949 + } else
13950 + bcm43xx_phy_write(bcm, 0x0015, 0xAA00);
13951 + radio->enabled = 0;
13952 + dprintk(KERN_INFO PFX "Radio turned off\n");
13953 +}
13954 +
13955 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm)
13956 +{
13957 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
13958 +
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);
13963 + break;
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);
13970 + break;
13971 + }
13972 +}
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
13976 @@ -0,0 +1,99 @@
13977 +/*
13978 +
13979 + Broadcom BCM43xx wireless driver
13980 +
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>
13986 +
13987 + Some parts of the code in this file are derived from the ipw2200
13988 + driver Copyright(c) 2003 - 2004 Intel Corporation.
13989 +
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.
13994 +
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.
13999 +
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.
14004 +
14005 +*/
14006 +
14007 +#ifndef BCM43xx_RADIO_H_
14008 +#define BCM43xx_RADIO_H_
14009 +
14010 +#include "bcm43xx.h"
14011 +
14012 +
14013 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_A 36
14014 +#define BCM43xx_RADIO_DEFAULT_CHANNEL_BG 6
14015 +
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.
14022 + */
14023 +#define BCM43xx_RADIO_TXANTENNA_LASTPLCP 3
14024 +#define BCM43xx_RADIO_TXANTENNA_DEFAULT BCM43xx_RADIO_TXANTENNA_LASTPLCP
14025 +
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
14030 +
14031 +
14032 +void bcm43xx_radio_lock(struct bcm43xx_private *bcm);
14033 +void bcm43xx_radio_unlock(struct bcm43xx_private *bcm);
14034 +
14035 +u16 bcm43xx_radio_read16(struct bcm43xx_private *bcm, u16 offset);
14036 +void bcm43xx_radio_write16(struct bcm43xx_private *bcm, u16 offset, u16 val);
14037 +
14038 +u16 bcm43xx_radio_init2050(struct bcm43xx_private *bcm);
14039 +void bcm43xx_radio_init2060(struct bcm43xx_private *bcm);
14040 +
14041 +void bcm43xx_radio_turn_on(struct bcm43xx_private *bcm);
14042 +void bcm43xx_radio_turn_off(struct bcm43xx_private *bcm);
14043 +
14044 +int bcm43xx_radio_selectchannel(struct bcm43xx_private *bcm, u8 channel,
14045 + int synthetic_pu_workaround);
14046 +
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,
14050 + u16 txpower);
14051 +
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);
14055 +
14056 +void bcm43xx_radio_set_txantenna(struct bcm43xx_private *bcm, u32 val);
14057 +
14058 +void bcm43xx_radio_clear_tssi(struct bcm43xx_private *bcm);
14059 +
14060 +u8 bcm43xx_radio_aci_detect(struct bcm43xx_private *bcm, u8 channel);
14061 +u8 bcm43xx_radio_aci_scan(struct bcm43xx_private *bcm);
14062 +
14063 +int bcm43xx_radio_set_interference_mitigation(struct bcm43xx_private *bcm, int mode);
14064 +
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);
14071 +
14072 +void bcm43xx_radio_set_tx_iq(struct bcm43xx_private *bcm);
14073 +u16 bcm43xx_radio_calibrationvalue(struct bcm43xx_private *bcm);
14074 +
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
14079 @@ -0,0 +1,322 @@
14080 +/*
14081 +
14082 + Broadcom BCM43xx wireless driver
14083 +
14084 + SYSFS support routines
14085 +
14086 + Copyright (c) 2006 Michael Buesch <mbuesch@freenet.de>
14087 +
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.
14092 +
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.
14097 +
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.
14102 +
14103 +*/
14104 +
14105 +#include "bcm43xx_sysfs.h"
14106 +#include "bcm43xx.h"
14107 +#include "bcm43xx_main.h"
14108 +#include "bcm43xx_radio.h"
14109 +
14110 +#include <linux/capability.h>
14111 +
14112 +
14113 +#define GENERIC_FILESIZE 64
14114 +
14115 +
14116 +static int get_integer(const char *buf, size_t count)
14117 +{
14118 + char tmp[10 + 1] = { 0 };
14119 + int ret = -EINVAL;
14120 +
14121 + if (count == 0)
14122 + goto out;
14123 + count = min(count, (size_t)10);
14124 + memcpy(tmp, buf, count);
14125 + ret = simple_strtol(tmp, NULL, 10);
14126 +out:
14127 + return ret;
14128 +}
14129 +
14130 +static int get_boolean(const char *buf, size_t count)
14131 +{
14132 + if (count != 0) {
14133 + if (buf[0] == '1')
14134 + return 1;
14135 + if (buf[0] == '0')
14136 + return 0;
14137 + if (count >= 4 && memcmp(buf, "true", 4) == 0)
14138 + return 1;
14139 + if (count >= 5 && memcmp(buf, "false", 5) == 0)
14140 + return 0;
14141 + if (count >= 3 && memcmp(buf, "yes", 3) == 0)
14142 + return 1;
14143 + if (count >= 2 && memcmp(buf, "no", 2) == 0)
14144 + return 0;
14145 + if (count >= 2 && memcmp(buf, "on", 2) == 0)
14146 + return 1;
14147 + if (count >= 3 && memcmp(buf, "off", 3) == 0)
14148 + return 0;
14149 + }
14150 + return -EINVAL;
14151 +}
14152 +
14153 +static ssize_t bcm43xx_attr_sprom_show(struct device *dev,
14154 + struct device_attribute *attr,
14155 + char *buf)
14156 +{
14157 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14158 + u16 *sprom;
14159 + unsigned long flags;
14160 + int i, err;
14161 +
14162 + if (!capable(CAP_NET_ADMIN))
14163 + return -EPERM;
14164 +
14165 + assert(BCM43xx_SPROM_SIZE * sizeof(u16) <= PAGE_SIZE);
14166 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14167 + GFP_KERNEL);
14168 + if (!sprom)
14169 + return -ENOMEM;
14170 + bcm43xx_lock_mmio(bcm, flags);
14171 + assert(bcm->initialized);
14172 + err = bcm43xx_sprom_read(bcm, sprom);
14173 + if (!err) {
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;
14177 + }
14178 + }
14179 + bcm43xx_unlock_mmio(bcm, flags);
14180 + kfree(sprom);
14181 +
14182 + return err ? err : BCM43xx_SPROM_SIZE * sizeof(u16);
14183 +}
14184 +
14185 +static ssize_t bcm43xx_attr_sprom_store(struct device *dev,
14186 + struct device_attribute *attr,
14187 + const char *buf, size_t count)
14188 +{
14189 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_sprom);
14190 + u16 *sprom;
14191 + unsigned long flags;
14192 + int i, err;
14193 +
14194 + if (!capable(CAP_NET_ADMIN))
14195 + return -EPERM;
14196 +
14197 + if (count != BCM43xx_SPROM_SIZE * sizeof(u16))
14198 + return -EINVAL;
14199 + sprom = kmalloc(BCM43xx_SPROM_SIZE * sizeof(*sprom),
14200 + GFP_KERNEL);
14201 + if (!sprom)
14202 + return -ENOMEM;
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;
14206 + }
14207 + bcm43xx_lock_mmio(bcm, flags);
14208 + assert(bcm->initialized);
14209 + err = bcm43xx_sprom_write(bcm, sprom);
14210 + bcm43xx_unlock_mmio(bcm, flags);
14211 + kfree(sprom);
14212 +
14213 + return err ? err : count;
14214 +
14215 +}
14216 +
14217 +static ssize_t bcm43xx_attr_interfmode_show(struct device *dev,
14218 + struct device_attribute *attr,
14219 + char *buf)
14220 +{
14221 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14222 + unsigned long flags;
14223 + int err;
14224 + ssize_t count = 0;
14225 +
14226 + if (!capable(CAP_NET_ADMIN))
14227 + return -EPERM;
14228 +
14229 + bcm43xx_lock(bcm, flags);
14230 + assert(bcm->initialized);
14231 +
14232 + switch (bcm43xx_current_radio(bcm)->interfmode) {
14233 + case BCM43xx_RADIO_INTERFMODE_NONE:
14234 + count = snprintf(buf, PAGE_SIZE, "0 (No Interference Mitigation)\n");
14235 + break;
14236 + case BCM43xx_RADIO_INTERFMODE_NONWLAN:
14237 + count = snprintf(buf, PAGE_SIZE, "1 (Non-WLAN Interference Mitigation)\n");
14238 + break;
14239 + case BCM43xx_RADIO_INTERFMODE_MANUALWLAN:
14240 + count = snprintf(buf, PAGE_SIZE, "2 (WLAN Interference Mitigation)\n");
14241 + break;
14242 + default:
14243 + assert(0);
14244 + }
14245 + err = 0;
14246 +
14247 + bcm43xx_unlock(bcm, flags);
14248 +
14249 + return err ? err : count;
14250 +
14251 +}
14252 +
14253 +static ssize_t bcm43xx_attr_interfmode_store(struct device *dev,
14254 + struct device_attribute *attr,
14255 + const char *buf, size_t count)
14256 +{
14257 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_interfmode);
14258 + unsigned long flags;
14259 + int err;
14260 + int mode;
14261 +
14262 + if (!capable(CAP_NET_ADMIN))
14263 + return -EPERM;
14264 +
14265 + mode = get_integer(buf, count);
14266 + switch (mode) {
14267 + case 0:
14268 + mode = BCM43xx_RADIO_INTERFMODE_NONE;
14269 + break;
14270 + case 1:
14271 + mode = BCM43xx_RADIO_INTERFMODE_NONWLAN;
14272 + break;
14273 + case 2:
14274 + mode = BCM43xx_RADIO_INTERFMODE_MANUALWLAN;
14275 + break;
14276 + case 3:
14277 + mode = BCM43xx_RADIO_INTERFMODE_AUTOWLAN;
14278 + break;
14279 + default:
14280 + return -EINVAL;
14281 + }
14282 +
14283 + bcm43xx_lock_mmio(bcm, flags);
14284 + assert(bcm->initialized);
14285 +
14286 + err = bcm43xx_radio_set_interference_mitigation(bcm, mode);
14287 + if (err) {
14288 + printk(KERN_ERR PFX "Interference Mitigation not "
14289 + "supported by device\n");
14290 + }
14291 +
14292 + bcm43xx_unlock_mmio(bcm, flags);
14293 +
14294 + return err ? err : count;
14295 +}
14296 +
14297 +static ssize_t bcm43xx_attr_preamble_show(struct device *dev,
14298 + struct device_attribute *attr,
14299 + char *buf)
14300 +{
14301 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14302 + unsigned long flags;
14303 + int err;
14304 + ssize_t count;
14305 +
14306 + if (!capable(CAP_NET_ADMIN))
14307 + return -EPERM;
14308 +
14309 + bcm43xx_lock(bcm, flags);
14310 + assert(bcm->initialized);
14311 +
14312 + if (bcm->short_preamble)
14313 + count = snprintf(buf, PAGE_SIZE, "1 (Short Preamble enabled)\n");
14314 + else
14315 + count = snprintf(buf, PAGE_SIZE, "0 (Short Preamble disabled)\n");
14316 +
14317 + err = 0;
14318 + bcm43xx_unlock(bcm, flags);
14319 +
14320 + return err ? err : count;
14321 +}
14322 +
14323 +static ssize_t bcm43xx_attr_preamble_store(struct device *dev,
14324 + struct device_attribute *attr,
14325 + const char *buf, size_t count)
14326 +{
14327 + struct bcm43xx_private *bcm = devattr_to_bcm(attr, attr_preamble);
14328 + unsigned long flags;
14329 + int err;
14330 + int value;
14331 +
14332 + if (!capable(CAP_NET_ADMIN))
14333 + return -EPERM;
14334 +
14335 + value = get_boolean(buf, count);
14336 + if (value < 0)
14337 + return value;
14338 + bcm43xx_lock(bcm, flags);
14339 + assert(bcm->initialized);
14340 +
14341 + bcm->short_preamble = !!value;
14342 +
14343 + err = 0;
14344 + bcm43xx_unlock(bcm, flags);
14345 +
14346 + return err ? err : count;
14347 +}
14348 +
14349 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm)
14350 +{
14351 + struct device *dev = &bcm->pci_dev->dev;
14352 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14353 + int err;
14354 +
14355 + assert(bcm->initialized);
14356 +
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);
14363 + if (err)
14364 + goto out;
14365 +
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);
14372 + if (err)
14373 + goto err_remove_sprom;
14374 +
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);
14381 + if (err)
14382 + goto err_remove_interfmode;
14383 +
14384 +out:
14385 + return err;
14386 +err_remove_interfmode:
14387 + device_remove_file(dev, &sysfs->attr_interfmode);
14388 +err_remove_sprom:
14389 + device_remove_file(dev, &sysfs->attr_sprom);
14390 + goto out;
14391 +}
14392 +
14393 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm)
14394 +{
14395 + struct device *dev = &bcm->pci_dev->dev;
14396 + struct bcm43xx_sysfs *sysfs = &bcm->sysfs;
14397 +
14398 + device_remove_file(dev, &sysfs->attr_preamble);
14399 + device_remove_file(dev, &sysfs->attr_interfmode);
14400 + device_remove_file(dev, &sysfs->attr_sprom);
14401 +}
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
14405 @@ -0,0 +1,25 @@
14406 +#ifndef BCM43xx_SYSFS_H_
14407 +#define BCM43xx_SYSFS_H_
14408 +
14409 +#include <linux/device.h>
14410 +
14411 +
14412 +struct bcm43xx_sysfs {
14413 + struct device_attribute attr_sprom;
14414 + struct device_attribute attr_interfmode;
14415 + struct device_attribute attr_preamble;
14416 +};
14417 +
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); \
14422 + __p; \
14423 + })
14424 +
14425 +struct bcm43xx_private;
14426 +
14427 +int bcm43xx_sysfs_register(struct bcm43xx_private *bcm);
14428 +void bcm43xx_sysfs_unregister(struct bcm43xx_private *bcm);
14429 +
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
14434 @@ -0,0 +1,494 @@
14435 +/*
14436 +
14437 + Broadcom BCM43xx wireless driver
14438 +
14439 + Transmission (TX/RX) related functions.
14440 +
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>
14446 +
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.
14451 +
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.
14456 +
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.
14461 +
14462 +*/
14463 +
14464 +#include "bcm43xx_xmit.h"
14465 +
14466 +
14467 +/* Extract the bitrate out of a CCK PLCP header. */
14468 +static u8 bcm43xx_plcp_get_bitrate_cck(struct bcm43xx_plcp_hdr4 *plcp)
14469 +{
14470 + switch (plcp->raw[0]) {
14471 + case 0x0A:
14472 + return BCM43xx_CCK_RATE_1MB;
14473 + case 0x14:
14474 + return BCM43xx_CCK_RATE_2MB;
14475 + case 0x37:
14476 + return BCM43xx_CCK_RATE_5MB;
14477 + case 0x6E:
14478 + return BCM43xx_CCK_RATE_11MB;
14479 + }
14480 + assert(0);
14481 + return 0;
14482 +}
14483 +
14484 +/* Extract the bitrate out of an OFDM PLCP header. */
14485 +static u8 bcm43xx_plcp_get_bitrate_ofdm(struct bcm43xx_plcp_hdr4 *plcp)
14486 +{
14487 + switch (plcp->raw[0] & 0xF) {
14488 + case 0xB:
14489 + return BCM43xx_OFDM_RATE_6MB;
14490 + case 0xF:
14491 + return BCM43xx_OFDM_RATE_9MB;
14492 + case 0xA:
14493 + return BCM43xx_OFDM_RATE_12MB;
14494 + case 0xE:
14495 + return BCM43xx_OFDM_RATE_18MB;
14496 + case 0x9:
14497 + return BCM43xx_OFDM_RATE_24MB;
14498 + case 0xD:
14499 + return BCM43xx_OFDM_RATE_36MB;
14500 + case 0x8:
14501 + return BCM43xx_OFDM_RATE_48MB;
14502 + case 0xC:
14503 + return BCM43xx_OFDM_RATE_54MB;
14504 + }
14505 + assert(0);
14506 + return 0;
14507 +}
14508 +
14509 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate)
14510 +{
14511 + switch (bitrate) {
14512 + case BCM43xx_CCK_RATE_1MB:
14513 + return 0x0A;
14514 + case BCM43xx_CCK_RATE_2MB:
14515 + return 0x14;
14516 + case BCM43xx_CCK_RATE_5MB:
14517 + return 0x37;
14518 + case BCM43xx_CCK_RATE_11MB:
14519 + return 0x6E;
14520 + }
14521 + assert(0);
14522 + return 0;
14523 +}
14524 +
14525 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate)
14526 +{
14527 + switch (bitrate) {
14528 + case BCM43xx_OFDM_RATE_6MB:
14529 + return 0xB;
14530 + case BCM43xx_OFDM_RATE_9MB:
14531 + return 0xF;
14532 + case BCM43xx_OFDM_RATE_12MB:
14533 + return 0xA;
14534 + case BCM43xx_OFDM_RATE_18MB:
14535 + return 0xE;
14536 + case BCM43xx_OFDM_RATE_24MB:
14537 + return 0x9;
14538 + case BCM43xx_OFDM_RATE_36MB:
14539 + return 0xD;
14540 + case BCM43xx_OFDM_RATE_48MB:
14541 + return 0x8;
14542 + case BCM43xx_OFDM_RATE_54MB:
14543 + return 0xC;
14544 + }
14545 + assert(0);
14546 + return 0;
14547 +}
14548 +
14549 +static void bcm43xx_generate_plcp_hdr(struct bcm43xx_plcp_hdr4 *plcp,
14550 + const u16 octets, const u8 bitrate,
14551 + const int ofdm_modulation)
14552 +{
14553 + __le32 *data = &(plcp->data);
14554 + __u8 *raw = plcp->raw;
14555 +
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);
14561 + } else {
14562 + u32 plen;
14563 +
14564 + plen = octets * 16 / bitrate;
14565 + if ((octets * 16 % bitrate) > 0) {
14566 + plen++;
14567 + if ((bitrate == BCM43xx_CCK_RATE_11MB)
14568 + && ((octets * 8 % 11) < 4)) {
14569 + raw[1] = 0x84;
14570 + } else
14571 + raw[1] = 0x04;
14572 + } else
14573 + raw[1] = 0x04;
14574 + *data |= cpu_to_le32(plen << 16);
14575 + raw[0] = bcm43xx_plcp_get_ratecode_cck(bitrate);
14576 + }
14577 +}
14578 +
14579 +static u8 bcm43xx_calc_fallback_rate(u8 bitrate)
14580 +{
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;
14606 + }
14607 + assert(0);
14608 + return 0;
14609 +}
14610 +
14611 +static
14612 +__le16 bcm43xx_calc_duration_id(const struct ieee80211_hdr *wireless_header,
14613 + u8 bitrate)
14614 +{
14615 + const u16 frame_ctl = le16_to_cpu(wireless_header->frame_control);
14616 + __le16 duration_id = wireless_header->duration_id;
14617 +
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.
14622 + break;
14623 + case WLAN_FC_TYPE_CTRL:
14624 + /* Use the original duration/id. */
14625 + break;
14626 + default:
14627 + assert(0);
14628 + }
14629 +
14630 + return duration_id;
14631 +}
14632 +
14633 +static inline
14634 +u16 ceiling_div(u16 dividend, u16 divisor)
14635 +{
14636 + return ((dividend + divisor - 1) / divisor);
14637 +}
14638 +
14639 +static void bcm43xx_generate_rts(const struct bcm43xx_phyinfo *phy,
14640 + struct bcm43xx_txhdr *txhdr,
14641 + u16 *flags,
14642 + u8 bitrate,
14643 + const struct ieee80211_hdr *wlhdr)
14644 +{
14645 + u16 fctl;
14646 + u16 dur;
14647 + u8 fallback_bitrate;
14648 + int ofdm_modulation;
14649 + int fallback_ofdm_modulation;
14650 + u8 *sa, *da;
14651 + u16 flen;
14652 +
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));
14658 +
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),
14661 + flen, bitrate,
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...
14671 + */
14672 +assert(dur);
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.
14676 + */
14677 + if (phy->type == BCM43xx_PHYTYPE_A) {
14678 + /* Three times SIFS */
14679 + dur += 16 * 3;
14680 + /* Add ACK duration. */
14681 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14682 + bitrate * 4);
14683 + /* Add CTS duration. */
14684 + dur += ceiling_div((16 + 8 * (14 /*bytes*/) + 6) * 10,
14685 + bitrate * 4);
14686 + } else {
14687 + /* Three times SIFS */
14688 + dur += 10 * 3;
14689 + /* Add ACK duration. */
14690 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14691 + bitrate);
14692 + /* Add CTS duration. */
14693 + dur += ceiling_div(8 * (14 /*bytes*/) * 10,
14694 + bitrate);
14695 + }
14696 +
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);
14703 +
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;
14710 +}
14711 +
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)
14719 +{
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);
14723 + u8 bitrate;
14724 + u8 fallback_bitrate;
14725 + int ofdm_modulation;
14726 + int fallback_ofdm_modulation;
14727 + u16 plcp_fragment_len = fragment_len;
14728 + u16 flags = 0;
14729 + u16 control = 0;
14730 + u16 wsec_rate = 0;
14731 +
14732 + /* Now construct the TX header. */
14733 + memset(txhdr, 0, sizeof(*txhdr));
14734 +
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));
14739 +
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);
14749 +
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]);
14755 + int wlhdr_len;
14756 +
14757 + if (key->enabled) {
14758 + /* Hardware appends ICV. */
14759 + plcp_fragment_len += txctl->icv_len;
14760 +
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);
14765 + }
14766 + }
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);
14773 +
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;
14781 +
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;
14791 +
14792 + /* Set WSEC/RATE field */
14793 + wsec_rate |= (txhdr->plcp.raw[0] << BCM43xx_TXHDR_RATE_SHIFT)
14794 + & BCM43xx_TXHDR_RATE_MASK;
14795 +
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.
14800 + */
14801 + if (txctl->use_rts_cts) {
14802 + bcm43xx_generate_rts(phy, txhdr, &flags,
14803 + txctl->rts_cts_rate,
14804 + wireless_header);
14805 + }
14806 +
14807 + txhdr->flags = cpu_to_le16(flags);
14808 + txhdr->control = cpu_to_le16(control);
14809 + txhdr->wsec_rate = cpu_to_le16(wsec_rate);
14810 +}
14811 +
14812 +static s8 bcm43xx_rssi_postprocess(struct bcm43xx_private *bcm,
14813 + u8 in_rssi, int ofdm,
14814 + int adjust_2053, int adjust_2050)
14815 +{
14816 + struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);
14817 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14818 + s32 tmp;
14819 +
14820 + switch (radio->version) {
14821 + case 0x2050:
14822 + if (ofdm) {
14823 + tmp = in_rssi;
14824 + if (tmp > 127)
14825 + tmp -= 256;
14826 + tmp *= 73;
14827 + tmp /= 64;
14828 + if (adjust_2050)
14829 + tmp += 25;
14830 + else
14831 + tmp -= 3;
14832 + } else {
14833 + if (bcm->sprom.boardflags & BCM43xx_BFL_RSSI) {
14834 + if (in_rssi > 63)
14835 + in_rssi = 63;
14836 + tmp = radio->nrssi_lt[in_rssi];
14837 + tmp = 31 - tmp;
14838 + tmp *= -131;
14839 + tmp /= 128;
14840 + tmp -= 57;
14841 + } else {
14842 + tmp = in_rssi;
14843 + tmp = 31 - tmp;
14844 + tmp *= -149;
14845 + tmp /= 128;
14846 + tmp -= 68;
14847 + }
14848 + if (phy->type == BCM43xx_PHYTYPE_G &&
14849 + adjust_2050)
14850 + tmp += 25;
14851 + }
14852 + break;
14853 + case 0x2060:
14854 + if (in_rssi > 127)
14855 + tmp = in_rssi - 256;
14856 + else
14857 + tmp = in_rssi;
14858 + break;
14859 + default:
14860 + tmp = in_rssi;
14861 + tmp -= 11;
14862 + tmp *= 103;
14863 + tmp /= 64;
14864 + if (adjust_2053)
14865 + tmp -= 109;
14866 + else
14867 + tmp -= 83;
14868 + }
14869 +
14870 + return (s8)tmp;
14871 +}
14872 +
14873 +//TODO
14874 +#if 0
14875 +static s8 bcm43xx_rssinoise_postprocess(struct bcm43xx_private *bcm,
14876 + u8 in_rssi)
14877 +{
14878 + struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);
14879 + s8 ret;
14880 +
14881 + if (phy->type == BCM43xx_PHYTYPE_A) {
14882 + //TODO: Incomplete specs.
14883 + ret = 0;
14884 + } else
14885 + ret = bcm43xx_rssi_postprocess(bcm, in_rssi, 0, 1, 1);
14886 +
14887 + return ret;
14888 +}
14889 +#endif
14890 +
14891 +void bcm43xx_rx(struct bcm43xx_private *bcm,
14892 + struct sk_buff *skb,
14893 + struct bcm43xx_rxhdr *rxhdr)
14894 +{
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);
14902 +
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));
14907 + } else {
14908 + plcp = (struct bcm43xx_plcp_hdr4 *)(skb->data);
14909 + /* Skip the PLCP header. */
14910 + skb_pull(skb, sizeof(struct bcm43xx_plcp_hdr6));
14911 + }
14912 + /* The SKB contains the PAYLOAD (wireless header + data)
14913 + * at this point.
14914 + */
14915 +
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));
14920 + if (is_ofdm)
14921 + status.rate = bcm43xx_plcp_get_bitrate_ofdm(plcp);
14922 + else
14923 + status.rate = bcm43xx_plcp_get_bitrate_cck(plcp);
14924 + status.channel = radio->channel;
14925 +
14926 + bcm->stats.last_rx = jiffies;
14927 + ieee80211_rx_irqsafe(bcm->net_dev, skb, &status);
14928 +}
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
14932 @@ -0,0 +1,157 @@
14933 +#ifndef BCM43xx_XMIT_H_
14934 +#define BCM43xx_XMIT_H_
14935 +
14936 +#include "bcm43xx_main.h"
14937 +
14938 +
14939 +#define _bcm43xx_declare_plcp_hdr(size) \
14940 + struct bcm43xx_plcp_hdr##size { \
14941 + union { \
14942 + __le32 data; \
14943 + __u8 raw[size]; \
14944 + } __attribute__((__packed__)); \
14945 + } __attribute__((__packed__))
14946 +
14947 +/* struct bcm43xx_plcp_hdr4 */
14948 +_bcm43xx_declare_plcp_hdr(4);
14949 +/* struct bcm43xx_plcp_hdr6 */
14950 +_bcm43xx_declare_plcp_hdr(6);
14951 +
14952 +#undef _bcm43xx_declare_plcp_hdr
14953 +
14954 +/* Device specific TX header. To be prepended to TX frames. */
14955 +struct bcm43xx_txhdr {
14956 + union {
14957 + struct {
14958 + __le16 flags;
14959 + __le16 wsec_rate;
14960 + __le16 frame_control;
14961 + u16 unknown_zeroed_0;
14962 + __le16 control;
14963 + u8 wep_iv[10];
14964 + u8 unknown_wsec_tkip_data[3]; //FIXME
14965 + PAD_BYTES(3);
14966 + u8 mac1[6];
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;
14972 + PAD_BYTES(2);
14973 + __le16 cookie;
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];
14980 + PAD_BYTES(2);
14981 + struct bcm43xx_plcp_hdr6 plcp;
14982 + } __attribute__((__packed__));
14983 + u8 raw[82];
14984 + } __attribute__((__packed__));
14985 +} __attribute__((__packed__));
14986 +
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
14998 +
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
15003 +
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
15012 +
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);
15020 +
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;
15025 + PAD_BYTES(2);
15026 + /* Flags field 1 */
15027 + __le16 flags1;
15028 + u8 rssi;
15029 + u8 signal_quality;
15030 + PAD_BYTES(2);
15031 + /* Flags field 3 */
15032 + __le16 flags3;
15033 + /* Flags field 2 */
15034 + __le16 flags2;
15035 + /* Lower 16bits of the TSF at the time the frame started. */
15036 + __le16 mactime;
15037 + PAD_BYTES(14);
15038 +} __attribute__((__packed__));
15039 +
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)
15044 +
15045 +#define BCM43xx_RXHDR_FLAGS2_INVALIDFRAME (1 << 0)
15046 +#define BCM43xx_RXHDR_FLAGS2_TYPE2FRAME (1 << 2)
15047 +/*FIXME: WEP related flags */
15048 +
15049 +#define BCM43xx_RXHDR_FLAGS3_2050RSSIADJ (1 << 10)
15050 +
15051 +/* Transmit Status as received from the hardware. */
15052 +struct bcm43xx_hwxmitstatus {
15053 + PAD_BYTES(4);
15054 + __le16 cookie;
15055 + u8 flags;
15056 + u8 cnt1:4,
15057 + cnt2:4;
15058 + PAD_BYTES(2);
15059 + __le16 seq;
15060 + __le16 unknown; //FIXME
15061 +} __attribute__((__packed__));
15062 +
15063 +/* Transmit Status in CPU byteorder. */
15064 +struct bcm43xx_xmitstatus {
15065 + u16 cookie;
15066 + u8 flags;
15067 + u8 cnt1:4,
15068 + cnt2:4;
15069 + u16 seq;
15070 + u16 unknown; //FIXME
15071 +};
15072 +
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
15081 +
15082 +u8 bcm43xx_plcp_get_ratecode_cck(const u8 bitrate);
15083 +u8 bcm43xx_plcp_get_ratecode_ofdm(const u8 bitrate);
15084 +
15085 +void bcm43xx_rx(struct bcm43xx_private *bcm,
15086 + struct sk_buff *skb,
15087 + struct bcm43xx_rxhdr *rxhdr);
15088 +
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
15093 @@ -0,0 +1,62 @@
15094 +config BCM43XX_D80211
15095 + tristate "Broadcom BCM43xx wireless support (DeviceScape stack)"
15096 + depends on PCI && D80211 && NET_RADIO && EXPERIMENTAL
15097 + select FW_LOADER
15098 + ---help---
15099 + This is an experimental driver for the Broadcom 43xx wireless chip,
15100 + found in the Apple Airport Extreme and various other devices.
15101 +
15102 +config BCM43XX_D80211_DEBUG
15103 + bool "Broadcom BCM43xx debugging (RECOMMENDED)"
15104 + depends on BCM43XX_D80211
15105 + default y
15106 + ---help---
15107 + Broadcom 43xx debugging messages.
15108 + Say Y, because the driver is still very experimental and
15109 + this will help you get it running.
15110 +
15111 +config BCM43XX_D80211_DMA
15112 + bool
15113 +config BCM43XX_D80211_PIO
15114 + bool
15115 +
15116 +choice
15117 + prompt "BCM43xx data transfer mode"
15118 + depends on BCM43XX_D80211
15119 + default BCM43XX_D80211_DMA_AND_PIO_MODE
15120 +
15121 +config BCM43XX_D80211_DMA_AND_PIO_MODE
15122 + bool "DMA + PIO"
15123 + select BCM43XX_D80211_DMA
15124 + select BCM43XX_D80211_PIO
15125 + ---help---
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.
15131 +
15132 + If unsure, choose this option.
15133 +
15134 +config BCM43XX_D80211_DMA_MODE
15135 + bool "DMA (Direct Memory Access) only"
15136 + select BCM43XX_D80211_DMA
15137 + ---help---
15138 + Only include Direct Memory Access (DMA).
15139 + This reduces the size of the driver module, by omitting the PIO code.
15140 +
15141 +config BCM43XX_D80211_PIO_MODE
15142 + bool "PIO (Programmed I/O) only"
15143 + select BCM43XX_D80211_PIO
15144 + ---help---
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).
15148 +
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.
15152 +
15153 + Only use PIO, if DMA does not work for you.
15154 +
15155 +endchoice
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
15159 @@ -0,0 +1,12 @@
15160 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211.o
15161 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DEBUG) += bcm43xx_debugfs.o
15162 +
15163 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_DMA) += bcm43xx_dma.o
15164 +bcm43xx-d80211-obj-$(CONFIG_BCM43XX_D80211_PIO) += bcm43xx_pio.o
15165 +
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 \
15170 + bcm43xx_xmit.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.
15177
15178 source "drivers/net/wireless/hostap/Kconfig"
15179 +source "drivers/net/wireless/bcm43xx-d80211/Kconfig"
15180
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
15186 @@ -35,6 +35,7 @@
15187 obj-$(CONFIG_PRISM54) += prism54/
15188
15189 obj-$(CONFIG_HOSTAP) += hostap/
15190 +obj-$(CONFIG_BCM43XX_D80211) += bcm43xx-d80211/
15191
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
15197 @@ -0,0 +1,98 @@
15198 +/*
15199 + * IEEE 802.11 driver (80211.o) -- hostapd interface
15200 + * Copyright 2002-2004, Instant802 Networks, Inc.
15201 + *
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.
15205 + */
15206 +
15207 +#ifndef D80211_COMMON_H
15208 +#define D80211_COMMON_H
15209 +
15210 +#include <linux/types.h>
15211 +
15212 +/*
15213 + * This is common header information with user space. It is used on all
15214 + * frames sent to wlan#ap interface.
15215 + */
15216 +
15217 +#define IEEE80211_FI_VERSION 0x80211001
15218 +
15219 +struct ieee80211_frame_info {
15220 + u32 version;
15221 + u32 length;
15222 + u64 mactime;
15223 + u64 hosttime;
15224 + u32 phytype;
15225 + u32 channel;
15226 + u32 datarate;
15227 + u32 antenna;
15228 + u32 priority;
15229 + u32 ssi_type;
15230 + u32 ssi_signal;
15231 + u32 ssi_noise;
15232 + u32 preamble;
15233 + u32 encoding;
15234 +
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. */
15239 + u32 msg_type;
15240 +} __attribute__ ((packed));
15241 +
15242 +
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,
15255 +};
15256 +
15257 +struct ieee80211_msg_set_aid_for_sta {
15258 + char sta_address[ETH_ALEN];
15259 + u16 aid;
15260 +};
15261 +
15262 +struct ieee80211_msg_key_notification {
15263 + int tx_rx_count;
15264 + char ifname[IFNAMSIZ];
15265 + u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
15266 +};
15267 +
15268 +
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,
15280 +};
15281 +
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 */
15287 +};
15288 +
15289 +struct ieee80211_radar_info {
15290 + int channel;
15291 + int radar;
15292 + int radar_type;
15293 +};
15294 +
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
15299 @@ -0,0 +1,870 @@
15300 +/*
15301 + * Low-level hardware driver -- IEEE 802.11 driver (80211.o) interface
15302 + * Copyright 2002-2005, Devicescape Software, Inc.
15303 + *
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.
15307 + */
15308 +
15309 +#ifndef D80211_H
15310 +#define D80211_H
15311 +
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"
15318 +
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).
15325 + */
15326 +
15327 +/*
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.
15332 + *
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
15335 + * support this.
15336 + *
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.
15342 + */
15343 +
15344 +/* Interface version (used for compatibility verification) */
15345 +#define IEEE80211_VERSION 2
15346 +
15347 +
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;
15360 +};
15361 +
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;
15371 +
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 */
15376 +};
15377 +
15378 +struct ieee80211_hw_modes {
15379 + int mode;
15380 + int num_channels;
15381 + struct ieee80211_channel *channels;
15382 + int num_rates;
15383 + struct ieee80211_rate *rates;
15384 + int xr_end; /* only used with Atheros XR */
15385 +};
15386 +
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 */
15393 +};
15394 +
15395 +#define NUM_TX_DATA_QUEUES 6
15396 +
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 */
15401 +};
15402 +
15403 +struct ieee80211_tx_queue_stats {
15404 + struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES];
15405 +};
15406 +
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
15411 + * hostapd */
15412 +enum {
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
15421 +};
15422 +#endif /* IEEE80211_TX_QUEUE_NUMS */
15423 +
15424 +
15425 +struct ieee80211_low_level_stats {
15426 + unsigned int dot11ACKFailureCount;
15427 + unsigned int dot11RTSFailureCount;
15428 + unsigned int dot11FCSErrorCount;
15429 + unsigned int dot11RTSSuccessCount;
15430 +};
15431 +
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
15436 +
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
15449 + * frame */
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;
15465 +
15466 + unsigned int atheros_xr:1; /* only used with Atheros XR */
15467 +
15468 + unsigned int power_level:8; /* per-packet transmit power level, in dBm
15469 + */
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()
15473 + */
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) */
15480 +
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 */
15488 +};
15489 +
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;
15499 +};
15500 +
15501 +#define RX_FLAG_MMIC_ERROR 0x1
15502 +#define RX_FLAG_DECRYPTED 0x2
15503 +#define RX_FLAG_XR_DOUBLE_CHIRP 0x4
15504 +
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
15507 + * frame. */
15508 +struct ieee80211_rx_status {
15509 + u64 hosttime;
15510 + u64 mactime;
15511 + int freq; /* receive frequency in Mhz */
15512 + int channel;
15513 + int phymode;
15514 + int ssi;
15515 + int antenna;
15516 + int rate;
15517 + int flag;
15518 +};
15519 +
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
15522 + * frame. */
15523 +struct ieee80211_tx_status {
15524 + /* copied ieee80211_tx_control structure */
15525 + struct ieee80211_tx_control control;
15526 +
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;
15531 + int retry_count;
15532 +
15533 + /* following two fields are only used with Atheros Super A/G */
15534 + int queue_length; /* information about TX queue */
15535 + int queue_number;
15536 +};
15537 +
15538 +
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 */
15543 +
15544 + int mode; /* IW_MODE_ */
15545 +
15546 + int phymode; /* MODE_IEEE80211A, .. */
15547 + unsigned int regulatory_domain;
15548 + int adm_status;
15549 +
15550 + int beacon_int;
15551 +
15552 + /* Bitfields, grouped together */
15553 +
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 */
15558 +
15559 + /* these fields are used by low level drivers for hardware
15560 + * that generate beacons independently */
15561 + u8 *ssid;
15562 + size_t ssid_len;
15563 + u8 *generic_elem;
15564 + size_t generic_elem_len;
15565 +
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 */
15570 +
15571 + int antenna_sel; /* default antenna conf:
15572 + * 0 = default/diversity,
15573 + * 1 = Ant0,
15574 + * 2 = Ant1 */
15575 +
15576 + int calib_int; /* hw/radio calibration interval in
15577 + * seconds */
15578 + int antenna_def;
15579 + int antenna_mode;
15580 +
15581 + u8 bssid_mask[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff = 1 BSSID */
15582 + int bss_count;
15583 +
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;
15590 +
15591 + int atheros_xr;
15592 +
15593 + u8 client_bssid[ETH_ALEN];
15594 +
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
15600 + * period */
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;
15607 +};
15608 +
15609 +
15610 +typedef enum { ALG_NONE, ALG_WEP, ALG_TKIP, ALG_CCMP, ALG_NULL }
15611 +ieee80211_key_alg;
15612 +
15613 +
15614 +struct ieee80211_key_conf {
15615 +
15616 + int hw_key_idx; /* filled + used by low-level driver */
15617 + ieee80211_key_alg alg;
15618 + int keylen;
15619 +
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 */
15627 + u8 key[0];
15628 +};
15629 +
15630 +#define IEEE80211_SCAN_START 1
15631 +#define IEEE80211_SCAN_END 2
15632 +
15633 +struct ieee80211_scan_conf {
15634 + int scan_channel; /* IEEE 802.11 channel number to do passive scan
15635 + * on */
15636 + int scan_freq; /* new freq in MHz to switch to for passive scan
15637 + */
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;
15642 +
15643 +
15644 + int running_channel; /* IEEE 802.11 channel number we operate on
15645 + * normally */
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;
15651 +
15652 + int scan_time; /* time a scan will take in us */
15653 + int tries;
15654 +
15655 + struct sk_buff *skb; /* skb to transmit before changing channels, maybe
15656 + * NULL for none */
15657 + struct ieee80211_tx_control *tx_control;
15658 +
15659 +};
15660 +
15661 +#ifndef IW_MODE_ADHOC
15662 +#define IW_MODE_ADHOC 1
15663 +#endif
15664 +
15665 +#ifndef IW_MODE_INFRA
15666 +#define IW_MODE_INFRA 2
15667 +#endif
15668 +
15669 +#ifndef IW_MODE_MASTER
15670 +#define IW_MODE_MASTER 3
15671 +#endif
15672 +
15673 +#ifndef IW_MODE_MONITOR
15674 +#define IW_MODE_MONITOR 6
15675 +#endif
15676 +
15677 +#define IEEE80211_SEQ_COUNTER_RX 0
15678 +#define IEEE80211_SEQ_COUNTER_TX 1
15679 +
15680 +typedef enum {
15681 + SET_KEY, DISABLE_KEY, REMOVE_ALL_KEYS,
15682 + ENABLE_COMPRESSION, DISABLE_COMPRESSION
15683 +} set_key_cmd;
15684 +
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
15687 + * functions. */
15688 +struct ieee80211_hw {
15689 + int version; /* IEEE80211_VERSION */
15690 +
15691 + /* Driver name */
15692 + char *name;
15693 +
15694 + /* TODO: frame_type 802.11/802.3, sw_encryption requirements */
15695 +
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;
15702 +
15703 +
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
15707 + * through) */
15708 + int device_hides_wep:1;
15709 +
15710 + /* Whether RX frames passed to ieee80211_rx() include FCS in the end
15711 + */
15712 + int rx_includes_fcs:1;
15713 +
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;
15721 +
15722 + int wep_include_iv:1;
15723 + int data_nullfunc_ack:1; /* will data nullfunc frames get proper
15724 + * TX status callback */
15725 +
15726 + /* Force sw version of encryption for TKIP packets if WMM is enabled.
15727 + */
15728 + int no_tkip_wmm_hwaccel:1;
15729 +
15730 + /* 1 if the payload needs to be padded at even boundaries after the
15731 + * header */
15732 + unsigned int extra_hdr_room:1;
15733 +
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.
15738 + */
15739 + unsigned int device_strips_mic:1;
15740 +
15741 + /* 1 = low-level driver supports skb fraglist (NETIF_F_FRAGLIST), i.e.,
15742 + * more than one skb per frame */
15743 + unsigned int fraglist;
15744 +
15745 + /* This is the time in us to change channels
15746 + */
15747 + int channel_change_time;
15748 +
15749 + int num_modes;
15750 + struct ieee80211_hw_modes *modes;
15751 +
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);
15758 +
15759 + /* Handler for performing hardware reset. */
15760 + int (*reset)(struct net_device *dev);
15761 +
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);
15766 +
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);
15771 +
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);
15775 +
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);
15782 +
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);
15791 +
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
15796 + * TX frame. */
15797 + int (*set_key_idx)(struct net_device *dev, int idx);
15798 +
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);
15804 +
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);
15812 +
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);
15818 +
15819 + /* return low-level statistics */
15820 + int (*get_stats)(struct net_device *dev,
15821 + struct ieee80211_low_level_stats *stats);
15822 +
15823 + /* Enable/disable test modes; mode = IEEE80211_TEST_* */
15824 + int (*test_mode)(struct net_device *dev, int mode);
15825 +
15826 + /* Configuration of test parameters */
15827 + int (*test_param)(struct net_device *dev, int param, int value);
15828 +
15829 + /* Change MAC address. addr is pointer to struct sockaddr. */
15830 + int (*set_mac_address)(struct net_device *dev, void *addr);
15831 +
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 */
15835 +
15836 + int (*set_privacy_invoked)(struct net_device *dev,
15837 + int privacy_invoked);
15838 +
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);
15844 +
15845 + /* Configuration of RTS threshold (if device needs it) */
15846 + int (*set_rts_threshold)(struct net_device *dev, u32 value);
15847 +
15848 + /* Configuration of fragmentation threshold (if device needs it) */
15849 + int (*set_frag_threshold)(struct net_device *dev, u32 value);
15850 +
15851 + /* Configuration of retry limits (if device needs it) */
15852 + int (*set_retry_limit)(struct net_device *dev, u32 short_retry,
15853 + u32 long_retr);
15854 +
15855 + /* Number of STAs in STA table notification (NULL = disabled) */
15856 + void (*sta_table_notification)(struct net_device *dev, int num_sta);
15857 +
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);
15863 +
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);
15872 +
15873 + /* Number of available hardware TX queues for data packets.
15874 + * WMM requires at least four queues. */
15875 + int queues;
15876 +
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);
15881 +
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);
15887 +
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);
15893 +
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);
15898 +
15899 + /* Optional handler for XR-in-use notification. */
15900 + int (*atheros_xr_in_use)(struct net_device *dev, int in_use);
15901 +};
15902 +
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.
15909 + *
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 *));
15916 +
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
15919 + * function. */
15920 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw);
15921 +
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);
15925 +
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);
15929 +
15930 +/* Free allocated net_device including private data of a driver. */
15931 +void ieee80211_free_hw(struct net_device *dev);
15932 +
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);
15940 +
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
15947 + * sent. */
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);
15952 +
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);
15961 +
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.
15969 + *
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. */
15976 +struct sk_buff *
15977 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
15978 + struct ieee80211_tx_control *control);
15979 +
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,
15983 + u16 aid);
15984 +
15985 +
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.
15990 + */
15991 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb);
15992 +
15993 +/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */
15994 +int ieee80211_get_hdrlen(u16 fc);
15995 +
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. */
16000 +typedef enum {
16001 + NETIF_ATTACH, NETIF_DETACH, NETIF_START, NETIF_STOP, NETIF_WAKE,
16002 + NETIF_IS_STOPPED, NETIF_UPDATE_TX_START
16003 +} Netif_Oper;
16004 +int ieee80211_netif_oper(struct net_device *dev, Netif_Oper op);
16005 +
16006 +
16007 +/*
16008 + * Function to get hardware configuration information
16009 + * by the low level driver should it need it.
16010 + */
16011 +struct ieee80211_conf *
16012 +ieee80211_get_hw_conf(struct net_device *dev);
16013 +
16014 +
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);
16019 +
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,
16024 + int radar_type);
16025 +
16026 +/* Test modes */
16027 +enum {
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,
16031 +};
16032 +
16033 +/* Test parameters */
16034 +enum {
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,
16046 +};
16047 +
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
16050 + */
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
16053 + * (== 2)
16054 + */
16055 +void ieee80211_rx_led(int state, struct net_device *dev);
16056 +
16057 +
16058 +/* IEEE 802.11 defines */
16059 +
16060 +#define FCS_LEN 4
16061 +
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
16071 +
16072 +#define WLAN_FC_GET_TYPE(fc) (((fc) & 0x000c) >> 2)
16073 +#define WLAN_FC_GET_STYPE(fc) (((fc) & 0x00f0) >> 4)
16074 +
16075 +#define WLAN_GET_SEQ_FRAG(seq) ((seq) & 0x000f)
16076 +#define WLAN_GET_SEQ_SEQ(seq) ((seq) >> 4)
16077 +
16078 +#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
16079 +
16080 +#define WLAN_FC_TYPE_MGMT 0
16081 +#define WLAN_FC_TYPE_CTRL 1
16082 +#define WLAN_FC_TYPE_DATA 2
16083 +
16084 +/* management */
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
16097 +
16098 +/* control */
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
16105 +
16106 +/* data */
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
16123 +
16124 +
16125 +#define IEEE80211_MAX_FRAG_THRESHOLD 2346
16126 +#define IEEE80211_MAX_RTS_THRESHOLD 2347
16127 +
16128 +struct ieee80211_hdr {
16129 + u16 frame_control;
16130 + u16 duration_id;
16131 + u8 addr1[6];
16132 + u8 addr2[6];
16133 + u8 addr3[6];
16134 + u16 seq_ctrl;
16135 + u8 addr4[6];
16136 +} __attribute__ ((packed));
16137 +
16138 +/* return a pointer to the source address (SA) */
16139 +static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
16140 +{
16141 + u8 *raw = (u8 *) hdr;
16142 + u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
16143 +
16144 + switch (tofrom) {
16145 + case 2:
16146 + return hdr->addr3;
16147 + case 3:
16148 + return hdr->addr4;
16149 + }
16150 + return hdr->addr2;
16151 +}
16152 +
16153 +/* return a pointer to the destination address (DA) */
16154 +static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
16155 +{
16156 + u8 *raw = (u8 *) hdr;
16157 + u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
16158 +
16159 + if (to_ds)
16160 + return hdr->addr3;
16161 + return hdr->addr1;
16162 +}
16163 +
16164 +static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
16165 +{
16166 + return (le16_to_cpu(hdr->frame_control) & WLAN_FC_MOREFRAG) != 0;
16167 +}
16168 +
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
16173 @@ -0,0 +1,197 @@
16174 +/*
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.
16179 + *
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.
16183 + */
16184 +
16185 +#ifndef D802_11_MGMT_H
16186 +#define D802_11_MGMT_H
16187 +
16188 +#include <linux/types.h>
16189 +
16190 +struct ieee80211_mgmt {
16191 + u16 frame_control;
16192 + u16 duration;
16193 + u8 da[6];
16194 + u8 sa[6];
16195 + u8 bssid[6];
16196 + u16 seq_ctrl;
16197 + union {
16198 + struct {
16199 + u16 auth_alg;
16200 + u16 auth_transaction;
16201 + u16 status_code;
16202 + /* possibly followed by Challenge text */
16203 + u8 variable[0];
16204 + } __attribute__ ((packed)) auth;
16205 + struct {
16206 + u16 reason_code;
16207 + } __attribute__ ((packed)) deauth;
16208 + struct {
16209 + u16 capab_info;
16210 + u16 listen_interval;
16211 + /* followed by SSID and Supported rates */
16212 + u8 variable[0];
16213 + } __attribute__ ((packed)) assoc_req;
16214 + struct {
16215 + u16 capab_info;
16216 + u16 status_code;
16217 + u16 aid;
16218 + /* followed by Supported rates */
16219 + u8 variable[0];
16220 + } __attribute__ ((packed)) assoc_resp, reassoc_resp;
16221 + struct {
16222 + u16 capab_info;
16223 + u16 listen_interval;
16224 + u8 current_ap[6];
16225 + /* followed by SSID and Supported rates */
16226 + u8 variable[0];
16227 + } __attribute__ ((packed)) reassoc_req;
16228 + struct {
16229 + u16 reason_code;
16230 + } __attribute__ ((packed)) disassoc;
16231 + struct {
16232 + u8 timestamp[8];
16233 + u16 beacon_int;
16234 + u16 capab_info;
16235 + /* followed by some of SSID, Supported rates,
16236 + * FH Params, DS Params, CF Params, IBSS Params, TIM */
16237 + u8 variable[0];
16238 + } __attribute__ ((packed)) beacon;
16239 + struct {
16240 + /* only variable items: SSID, Supported rates */
16241 + u8 variable[0];
16242 + } __attribute__ ((packed)) probe_req;
16243 + struct {
16244 + u8 timestamp[8];
16245 + u16 beacon_int;
16246 + u16 capab_info;
16247 + /* followed by some of SSID, Supported rates,
16248 + * FH Params, DS Params, CF Params, IBSS Params */
16249 + u8 variable[0];
16250 + } __attribute__ ((packed)) probe_resp;
16251 + struct {
16252 + u8 category;
16253 + union {
16254 + struct {
16255 + u8 action_code;
16256 + u8 dialog_token;
16257 + u8 status_code;
16258 + u8 variable[0];
16259 + } __attribute__ ((packed)) wme_action;
16260 + struct{
16261 + u8 action_code;
16262 + u8 element_id;
16263 + u8 length;
16264 + u8 switch_mode;
16265 + u8 new_chan;
16266 + u8 switch_count;
16267 + } __attribute__((packed)) chan_switch;
16268 + } u;
16269 + } __attribute__ ((packed)) action;
16270 + } u;
16271 +} __attribute__ ((packed));
16272 +
16273 +
16274 +/* Authentication algorithms */
16275 +#define WLAN_AUTH_OPEN 0
16276 +#define WLAN_AUTH_SHARED_KEY 1
16277 +#define WLAN_AUTH_LEAP 128
16278 +
16279 +#define WLAN_AUTH_CHALLENGE_LEN 128
16280 +
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)
16289 +/* 802.11h */
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)
16293 +
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
16306 +/* 802.11b */
16307 +#define WLAN_STATUS_ASSOC_DENIED_NOSHORT 19
16308 +#define WLAN_STATUS_ASSOC_DENIED_NOPBCC 20
16309 +#define WLAN_STATUS_ASSOC_DENIED_NOAGILITY 21
16310 +/* 802.11h */
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
16314 +/* 802.11g */
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
16318 +
16319 +
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
16330 +/* 802.11h */
16331 +#define WLAN_REASON_PWR_CAPABILITY_NOT_VALID 10
16332 +#define WLAN_REASON_SUPPORTED_CHANNEL_NOT_VALID 11
16333 +
16334 +#define WLAN_REASON_MIC_FAILURE 14
16335 +
16336 +
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
16365 +
16366 +
16367 +
16368 +#define ATHEROS_INFO_USEXR BIT(3)
16369 +
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
16374 @@ -0,0 +1,50 @@
16375 +/*
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.
16379 + *
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.
16383 + */
16384 +
16385 +#ifndef D80211_SHARED_H
16386 +#define D80211_SHARED_H
16387 +
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. */
16390 +enum {
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
16400 +};
16401 +
16402 +#define IEEE80211_CHAN_W_SCAN 0x00000001
16403 +#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
16404 +#define IEEE80211_CHAN_W_IBSS 0x00000004
16405 +
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
16418 +
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))
16422 +
16423 +
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
16428 @@ -47,7 +47,8 @@
16429 /* deinitialize crypto context and free allocated private data */
16430 void (*deinit) (void *priv);
16431
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);
16435
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
16446
16447 #define WLAN_AUTH_CHALLENGE_LEN 128
16448
16449 @@ -299,6 +300,23 @@
16450 WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
16451 };
16452
16453 +/* Action categories - 802.11h */
16454 +enum ieee80211_actioncategories {
16455 + WLAN_ACTION_SPECTRUM_MGMT = 0,
16456 + /* Reserved 1-127 */
16457 + /* Error 128-255 */
16458 +};
16459 +
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 */
16468 +};
16469 +
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 @@
16474 u8 mask;
16475 u8 freq;
16476 u16 len;
16477 + u64 tsf;
16478 + u32 beacon_time;
16479 };
16480
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));
16485
16486 +struct ieee80211_channel_switch {
16487 + u8 id;
16488 + u8 len;
16489 + u8 mode;
16490 + u8 channel;
16491 + u8 count;
16492 +} __attribute__ ((packed));
16493 +
16494 +struct ieee80211_action {
16495 + struct ieee80211_hdr_3addr header;
16496 + u8 category;
16497 + u8 action;
16498 + union {
16499 + struct ieee80211_action_exchange {
16500 + u8 token;
16501 + struct ieee80211_info_element info_element[0];
16502 + } exchange;
16503 + struct ieee80211_channel_switch channel_switch;
16504 +
16505 + } format;
16506 +} __attribute__ ((packed));
16507 +
16508 struct ieee80211_disassoc {
16509 struct ieee80211_hdr_3addr header;
16510 __le16 reason;
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)
16518 +
16519 +/* 802.11h */
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)
16525
16526 #define QOS_QUEUE_NUM 4
16527 #define QOS_OUI_LEN 3
16528 @@ -748,6 +798,91 @@
16529
16530 /*******************************************************/
16531
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 */
16539 +
16540 +};
16541 +struct ieee80211_basic_report {
16542 + u8 channel;
16543 + __le64 start_time;
16544 + __le16 duration;
16545 + u8 map;
16546 +} __attribute__ ((packed));
16547 +
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 */
16554 +};
16555 +
16556 +enum {
16557 + IEEE80211_REPORT_BASIC = 0, /* required */
16558 + IEEE80211_REPORT_CCA = 1, /* optional */
16559 + IEEE80211_REPORT_RPI = 2, /* optional */
16560 + /* 3-255 reserved */
16561 +};
16562 +
16563 +struct ieee80211_measurement_params {
16564 + u8 channel;
16565 + __le64 start_time;
16566 + __le16 duration;
16567 +} __attribute__ ((packed));
16568 +
16569 +struct ieee80211_measurement_request {
16570 + struct ieee80211_info_element ie;
16571 + u8 token;
16572 + u8 mode;
16573 + u8 type;
16574 + struct ieee80211_measurement_params params[0];
16575 +} __attribute__ ((packed));
16576 +
16577 +struct ieee80211_measurement_report {
16578 + struct ieee80211_info_element ie;
16579 + u8 token;
16580 + u8 mode;
16581 + u8 type;
16582 + union {
16583 + struct ieee80211_basic_report basic[0];
16584 + } u;
16585 +} __attribute__ ((packed));
16586 +
16587 +struct ieee80211_tpc_report {
16588 + u8 transmit_power;
16589 + u8 link_margin;
16590 +} __attribute__ ((packed));
16591 +
16592 +struct ieee80211_channel_map {
16593 + u8 channel;
16594 + u8 map;
16595 +} __attribute__ ((packed));
16596 +
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];
16602 +};
16603 +
16604 +struct ieee80211_csa {
16605 + u8 mode;
16606 + u8 channel;
16607 + u8 count;
16608 +} __attribute__ ((packed));
16609 +
16610 +struct ieee80211_quiet {
16611 + u8 count;
16612 + u8 period;
16613 + u8 duration;
16614 + u8 offset;
16615 +} __attribute__ ((packed));
16616 +
16617 struct ieee80211_network {
16618 /* These entries are used to identify a unique network */
16619 u8 bssid[ETH_ALEN];
16620 @@ -767,7 +902,7 @@
16621 u8 rates_ex_len;
16622 unsigned long last_scanned;
16623 u8 mode;
16624 - u8 flags;
16625 + u32 flags;
16626 u32 last_associate;
16627 u32 time_stamp[2];
16628 u16 beacon_interval;
16629 @@ -779,6 +914,25 @@
16630 u8 rsn_ie[MAX_WPA_IE_LEN];
16631 size_t rsn_ie_len;
16632 struct ieee80211_tim_parameters tim;
16633 +
16634 + /* 802.11h info */
16635 +
16636 + /* Power Constraint - mandatory if spctrm mgmt required */
16637 + u8 power_constraint;
16638 +
16639 + /* TPC Report - mandatory if spctrm mgmt required */
16640 + struct ieee80211_tpc_report tpc_report;
16641 +
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;
16645 +
16646 + /* Channel Switch Announcement - optional if spctrm mgmt required */
16647 + struct ieee80211_csa csa;
16648 +
16649 + /* Quiet - optional if spctrm mgmt required */
16650 + struct ieee80211_quiet quiet;
16651 +
16652 struct list_head list;
16653 };
16654
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);
16672
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,
16677 u8 channel);
16678 extern u8 ieee80211_freq_to_channel(struct ieee80211_device *ieee, u32 freq);
16679 +extern u8 ieee80211_get_channel_flags(struct ieee80211_device *ieee,
16680 + u8 channel);
16681 +extern const struct ieee80211_channel *ieee80211_get_channel(struct
16682 + ieee80211_device
16683 + *ieee, u8 channel);
16684
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,
16694 + char *extra);
16695 +extern int ieee80211_wx_get_auth(struct net_device *dev,
16696 + struct iw_request_info *info,
16697 + union iwreq_data *wrqu,
16698 + char *extra);
16699
16700 static inline void ieee80211_increment_scans(struct ieee80211_device *ieee)
16701 {
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; \
16707 if (!rc) { \
16708 *(__timeo) = schedule_timeout(*(__timeo)); \
16709 + rc = __condition; \
16710 } \
16711 lock_sock(__sk); \
16712 - rc = __condition; \
16713 rc; \
16714 })
16715
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>
16729
16730 /*
16731 @@ -2028,7 +2026,7 @@
16732 .release = seq_release,
16733 };
16734
16735 -#ifdef WIRELESS_EXT
16736 +#ifdef CONFIG_WIRELESS_EXT
16737 extern int wireless_proc_init(void);
16738 #else
16739 #define wireless_proc_init() 0
16740 @@ -2582,7 +2580,7 @@
16741 ret = -EFAULT;
16742 return ret;
16743 }
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 @@
16750 ret = -EFAULT;
16751 return ret;
16752 }
16753 -#endif /* WIRELESS_EXT */
16754 +#endif /* CONFIG_WIRELESS_EXT */
16755 return -EINVAL;
16756 }
16757 }
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
16761 @@ -14,5 +14,5 @@
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
16771 @@ -0,0 +1,564 @@
16772 +/* Based on Rijndael implementation that has been placed in the public domain,
16773 + * although heavily modified.
16774 + *
16775 + * Modifications Copyright 2003, Instant802 Networks, Inc.
16776 + *
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.
16780 + *
16781 + * Optimized both speed and size by removing not used key lengths (only
16782 + * 128-bit is used in IEEE 802.11i).
16783 + */
16784 +
16785 +/* Use 256-byte Te4 table instead of larger 1024-byte */
16786 +#define SMALL_TE4
16787 +
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 */
16793 +
16794 +
16795 +/* --- start of code that is based on public domain AES implementation --- */
16796 +
16797 +/**
16798 + * rijndael-alg-fst.c
16799 + *
16800 + * @version 3.0 (December 2000)
16801 + *
16802 + * Optimised ANSI C code for the Rijndael cipher (now AES)
16803 + *
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>
16807 + *
16808 + * This code is hereby placed in the public domain.
16809 + *
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.
16821 + */
16822 +
16823 +/*
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];
16829 +*/
16830 +
16831 +static const u32 Te0[256] =
16832 +{
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,
16897 +};
16898 +
16899 +#ifndef ONLY_ONE_TABLE
16900 +static const u32 Te1[256] =
16901 +{
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,
16966 +};
16967 +
16968 +static const u32 Te2[256] =
16969 +{
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,
17034 +};
17035 +
17036 +static const u32 Te3[256] =
17037 +{
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,
17102 +};
17103 +
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])
17108 +
17109 +#else /* ONLY_ONE_TABLE */
17110 +
17111 +
17112 +static inline u32 ROR8(u32 v)
17113 +{
17114 + return (v >> 8) | (v << 24);
17115 +}
17116 +
17117 +static inline u32 ROR16(u32 v)
17118 +{
17119 + return (v >> 16) | (v << 16);
17120 +}
17121 +
17122 +static inline u32 ROR24(u32 v)
17123 +{
17124 + return (v >> 24) | (v << 8);
17125 +}
17126 +
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]))
17131 +
17132 +#endif /* ONLY_ONE_TABLE */
17133 +
17134 +
17135 +
17136 +#ifdef SMALL_TE4
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,
17170 +};
17171 +
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])
17176 +
17177 +#else /* SMALL_TE4 */
17178 +
17179 +static const u32 Te4[256] =
17180 +{
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,
17245 +};
17246 +
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)
17251 +
17252 +#endif /* SMALL_TE4 */
17253 +
17254 +
17255 +static const u32 rcon[] = {
17256 + 0x01000000, 0x02000000, 0x04000000, 0x08000000, 0x10000000,
17257 + 0x20000000, 0x40000000, 0x80000000, 0x1B000000, 0x36000000,
17258 +};
17259 +
17260 +#define GETU32(pt) \
17261 +(((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] << 8) ^ \
17262 +((u32)(pt)[3]))
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); }
17266 +
17267 +
17268 +/* Expand the cipher key into the encryption key schedule. */
17269 +void ieee80211_aes_key_setup_encrypt(u32 rk[/*44*/], const u8 key[])
17270 +{
17271 + int i;
17272 + u32 temp;
17273 +
17274 + rk[0] = GETU32(key );
17275 + rk[1] = GETU32(key + 4);
17276 + rk[2] = GETU32(key + 8);
17277 + rk[3] = GETU32(key + 12);
17278 +
17279 + for (i = 0; i < 10; i++) {
17280 + temp = rk[3];
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];
17286 + rk += 4;
17287 + }
17288 +}
17289 +
17290 +
17291 +void ieee80211_aes_encrypt(const u32 rk[/*44*/], const u8 pt[16], u8 ct[16])
17292 +{
17293 + const int Nr = 10;
17294 + u32 s0, s1, s2, s3, t0, t1, t2, t3;
17295 +
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];
17301 +
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]
17307 + ROUND(1,t,s,4);
17308 + ROUND(2,s,t,8);
17309 + ROUND(3,t,s,12);
17310 + ROUND(4,s,t,16);
17311 + ROUND(5,t,s,20);
17312 + ROUND(6,s,t,24);
17313 + ROUND(7,t,s,28);
17314 + ROUND(8,s,t,32);
17315 + ROUND(9,t,s,36);
17316 +#undef ROUND
17317 +
17318 + rk += Nr << 2;
17319 +
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) ^
17322 + rk[0];
17323 + PUTU32(ct, s0);
17324 + s0 = TE4_1(t1 >> 24) ^ TE4_2(t2 >> 16) ^ TE4_3(t3 >> 8) ^ TE4_4(t0) ^
17325 + rk[1];
17326 + PUTU32(ct + 4, s0);
17327 + s0 = TE4_1(t2 >> 24) ^ TE4_2(t3 >> 16) ^ TE4_3(t0 >> 8) ^ TE4_4(t1) ^
17328 + rk[2];
17329 + PUTU32(ct + 8, s0);
17330 + s0 = TE4_1(t3 >> 24) ^ TE4_2(t0 >> 16) ^ TE4_3(t1 >> 8) ^ TE4_4(t2) ^
17331 + rk[3];
17332 + PUTU32(ct + 12, s0);
17333 +}
17334 +
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
17339 @@ -0,0 +1,119 @@
17340 +/*
17341 + * Copyright 2003-2004, Instant802 Networks, Inc.
17342 + * Copyright 2005, Devicescape Software, Inc.
17343 + *
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.
17347 + */
17348 +
17349 +#include <linux/types.h>
17350 +#include <linux/netdevice.h>
17351 +
17352 +#include <net/d80211.h>
17353 +#include "ieee80211_key.h"
17354 +#include "aes_ccm.h"
17355 +
17356 +#include "aes.c"
17357 +
17358 +static inline void aes_ccm_prepare(u32 *rk, u8 *b_0, u8 *aad, u8 *b,
17359 + u8 *s_0, u8 *a)
17360 +{
17361 + int i;
17362 +
17363 + ieee80211_aes_encrypt(rk, b_0, b);
17364 +
17365 + /* Extra Authenticate-only data (always two AES blocks) */
17366 + for (i = 0; i < AES_BLOCK_LEN; i++)
17367 + aad[i] ^= b[i];
17368 + ieee80211_aes_encrypt(rk, aad, b);
17369 +
17370 + aad += AES_BLOCK_LEN;
17371 +
17372 + for (i = 0; i < AES_BLOCK_LEN; i++)
17373 + aad[i] ^= b[i];
17374 + ieee80211_aes_encrypt(rk, aad, a);
17375 +
17376 + /* Mask out bits from auth-only-b_0 */
17377 + b_0[0] &= 0x07;
17378 +
17379 + /* S_0 is used to encrypt T (= MIC) */
17380 + b_0[14] = 0;
17381 + b_0[15] = 0;
17382 + ieee80211_aes_encrypt(rk, b_0, s_0);
17383 +}
17384 +
17385 +
17386 +void ieee80211_aes_ccm_encrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *data,
17387 + size_t data_len, u8 *cdata, u8 *mic)
17388 +{
17389 + int i, j, last_len, num_blocks;
17390 + u8 *pos, *cpos;
17391 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], e[AES_BLOCK_LEN];
17392 +
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);
17396 +
17397 + /* Process payload blocks */
17398 + pos = data;
17399 + cpos = cdata;
17400 + for (j = 1; j <= num_blocks; j++) {
17401 + int blen = (j == num_blocks && last_len) ?
17402 + last_len : AES_BLOCK_LEN;
17403 +
17404 + /* Authentication followed by encryption */
17405 + for (i = 0; i < blen; i++)
17406 + b[i] ^= pos[i];
17407 + ieee80211_aes_encrypt(rk, b, b);
17408 +
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];
17414 + }
17415 +
17416 + for (i = 0; i < CCMP_MIC_LEN; i++)
17417 + mic[i] = b[i] ^ s_0[i];
17418 +}
17419 +
17420 +
17421 +int ieee80211_aes_ccm_decrypt(u32 *rk, u8 *b_0, u8 *aad, u8 *cdata,
17422 + size_t data_len, u8 *mic, u8 *data)
17423 +{
17424 + int i, j, last_len, num_blocks;
17425 + u8 *pos, *cpos;
17426 + u8 b[AES_BLOCK_LEN], s_0[AES_BLOCK_LEN], a[AES_BLOCK_LEN];
17427 +
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);
17431 +
17432 + /* Process payload blocks */
17433 + cpos = cdata;
17434 + pos = data;
17435 + for (j = 1; j <= num_blocks; j++) {
17436 + int blen = (j == num_blocks && last_len) ?
17437 + last_len : AES_BLOCK_LEN;
17438 +
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];
17445 + a[i] ^= *pos++;
17446 + }
17447 +
17448 + ieee80211_aes_encrypt(rk, a, a);
17449 + }
17450 +
17451 + for (i = 0; i < CCMP_MIC_LEN; i++) {
17452 + if ((mic[i] ^ s_0[i]) != a[i])
17453 + return -1;
17454 + }
17455 +
17456 + return 0;
17457 +}
17458 +
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
17462 @@ -0,0 +1,24 @@
17463 +/*
17464 + * Copyright 2003-2004, Instant802 Networks, Inc.
17465 + *
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.
17469 + */
17470 +
17471 +#ifndef AES_CCM_H
17472 +#define AES_CCM_H
17473 +
17474 +#include <linux/types.h>
17475 +
17476 +#define AES_BLOCK_LEN 16
17477 +#define AES_STATE_LEN 44
17478 +
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);
17485 +
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
17490 @@ -0,0 +1,103 @@
17491 +/*
17492 + * Copyright 2005, Devicescape Software, Inc.
17493 + *
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.
17497 + *
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.
17501 + */
17502 +
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"
17508 +#include "wme.h"
17509 +
17510 +static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* qd)
17511 +{
17512 + struct sk_buff_head *q = qdisc_priv(qd);
17513 +
17514 + if (skb_queue_len(q) > qd->dev->tx_queue_len) {
17515 + qd->qstats.drops++;
17516 + kfree_skb(skb);
17517 + return NET_XMIT_DROP;
17518 + }
17519 +
17520 + skb_queue_tail(q, skb);
17521 + qd->q.qlen++;
17522 + qd->bstats.bytes += skb->len;
17523 + qd->bstats.packets++;
17524 +
17525 + return NET_XMIT_SUCCESS;
17526 +}
17527 +
17528 +
17529 +static int pfifo_requeue(struct sk_buff *skb, struct Qdisc* qd)
17530 +{
17531 + struct sk_buff_head *q = qdisc_priv(qd);
17532 +
17533 + skb_queue_head(q, skb);
17534 + qd->q.qlen++;
17535 + qd->bstats.bytes += skb->len;
17536 + qd->bstats.packets++;
17537 +
17538 + return NET_XMIT_SUCCESS;
17539 +}
17540 +
17541 +
17542 +static struct sk_buff *pfifo_dequeue(struct Qdisc* qd)
17543 +{
17544 + struct sk_buff_head *q = qdisc_priv(qd);
17545 +
17546 + return skb_dequeue(q);
17547 +}
17548 +
17549 +
17550 +static int pfifo_init(struct Qdisc* qd, struct rtattr *opt)
17551 +{
17552 + struct sk_buff_head *q = qdisc_priv(qd);
17553 +
17554 + skb_queue_head_init(q);
17555 + return 0;
17556 +}
17557 +
17558 +
17559 +static void pfifo_reset(struct Qdisc* qd)
17560 +{
17561 + struct sk_buff_head *q = qdisc_priv(qd);
17562 +
17563 + skb_queue_purge(q);
17564 + qd->q.qlen = 0;
17565 +}
17566 +
17567 +
17568 +static int pfifo_dump(struct Qdisc *qd, struct sk_buff *skb)
17569 +{
17570 + return skb->len;
17571 +}
17572 +
17573 +
17574 +struct Qdisc_ops pfifo_qdisc_ops =
17575 +{
17576 + .next = NULL,
17577 + .cl_ops = NULL,
17578 + .id = "ieee80211_pfifo",
17579 + .priv_size = sizeof(struct sk_buff_head),
17580 +
17581 + .enqueue = pfifo_enqueue,
17582 + .dequeue = pfifo_dequeue,
17583 + .requeue = pfifo_requeue,
17584 + .drop = NULL,
17585 +
17586 + .init = pfifo_init,
17587 + .reset = pfifo_reset,
17588 + .destroy = NULL,
17589 + .change = NULL,
17590 +
17591 + .dump = pfifo_dump,
17592 +};
17593 +
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
17597 @@ -0,0 +1,439 @@
17598 +/*
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.
17604 + *
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.
17608 + */
17609 +
17610 +#ifndef HOSTAPD_IOCTL_H
17611 +#define HOSTAPD_IOCTL_H
17612 +
17613 +#include <linux/types.h>
17614 +
17615 +#ifndef __KERNEL__
17616 +#include "ieee80211_shared.h"
17617 +#endif /* __KERNEL__ */
17618 +
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)
17623 +
17624 +/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
17625 +enum {
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,
17655 +
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. */
17699 +};
17700 +
17701 +/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
17702 +enum {
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,
17715 +
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. */
17746 +};
17747 +
17748 + /* these definitions mirror the ieee80211_i.h
17749 + * IEEE80211_DISABLED, ... IEEE80211_ASSOCIATED enumeration */
17750 +enum {
17751 + PRISM2_PARAM_STA_DISABLED,
17752 + PRISM2_PARAM_STA_AUTHENTICATE,
17753 + PRISM2_PARAM_STA_ASSOCIATE,
17754 + PRISM2_PARAM_STA_ASSOCIATED,
17755 +};
17756 +
17757 +#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
17758 +#define HOSTAP_CRYPT_ALG_NAME_LEN 16
17759 +
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.
17763 + */
17764 +#ifdef __GNUC__
17765 +#undef ALIGNED
17766 +#define ALIGNED __attribute__ ((aligned))
17767 +#else
17768 +/* Check if it has been defined elsewhere */
17769 +#ifndef ALIGNED
17770 +#error "Must define ALIGNED to generate aligned structure elements"
17771 +#endif
17772 +#endif
17773 +
17774 +struct prism2_hostapd_param {
17775 + u32 cmd;
17776 + u8 sta_addr[ETH_ALEN];
17777 + u8 pad[2];
17778 + union {
17779 + struct {
17780 + u16 aid;
17781 + u16 capability;
17782 + u8 supp_rates[32];
17783 + /* atheros_super_ag and enc_flags are only used with
17784 + * IEEE80211_ATHEROS_SUPER_AG
17785 + */
17786 + u8 atheros_super_ag;
17787 + u8 atheros_xr_mode;
17788 + u8 wds_flags;
17789 +#define IEEE80211_STA_DYNAMIC_ENC BIT(0)
17790 + u8 enc_flags;
17791 + } add_sta;
17792 + struct {
17793 + u32 inactive_msec;
17794 + u32 rx_packets;
17795 + u32 tx_packets;
17796 + u32 rx_bytes;
17797 + u32 tx_bytes;
17798 + u32 current_tx_rate; /* in 100 kbps */
17799 + u32 channel_use;
17800 + u32 flags;
17801 + u32 num_ps_buf_frames;
17802 + u32 tx_retry_failed;
17803 + u32 tx_retry_count;
17804 + u32 last_rssi;
17805 + u32 last_ack_rssi;
17806 + } get_info_sta;
17807 + struct {
17808 + u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
17809 + u32 flags;
17810 + u32 err;
17811 + u8 idx;
17812 +#define HOSTAP_SEQ_COUNTER_SIZE 8
17813 + u8 seq_counter[HOSTAP_SEQ_COUNTER_SIZE];
17814 + u16 key_len;
17815 + u8 key[0] ALIGNED;
17816 + } crypt;
17817 + struct {
17818 + u32 flags_and;
17819 + u32 flags_or;
17820 + } set_flags_sta;
17821 + struct {
17822 + u16 rid;
17823 + u16 len;
17824 + u8 data[0] ALIGNED;
17825 + } rid;
17826 + struct {
17827 + u16 head_len;
17828 + u16 tail_len;
17829 + u8 data[0] ALIGNED; /* head_len + tail_len bytes */
17830 + } beacon;
17831 + struct {
17832 + u16 num_modes;
17833 + u16 flags;
17834 + u8 data[0] ALIGNED; /* num_modes * feature data */
17835 + } hw_features;
17836 + struct {
17837 + u8 now;
17838 + s8 our_mode_only;
17839 + s16 last_rx;
17840 + u16 channel;
17841 + s16 interval; /* seconds */
17842 + s32 listen; /* microseconds */
17843 + } scan;
17844 + struct {
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)
17852 + u32 trigger;
17853 + } wpa_trigger;
17854 + struct {
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 */
17860 + } set_rate_sets;
17861 + struct {
17862 + u8 type; /* WDS, VLAN, etc */
17863 + u8 name[IFNAMSIZ];
17864 + u8 data[0] ALIGNED;
17865 + } if_info;
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;
17879 + struct {
17880 +#define LOAD_STATS_CLEAR BIT(1)
17881 + u32 flags;
17882 + u32 channel_use;
17883 + } get_load_stats;
17884 + struct {
17885 + char vlan_name[IFNAMSIZ];
17886 + int vlan_id;
17887 + } set_sta_vlan;
17888 + struct {
17889 + u8 len;
17890 + u8 data[0] ALIGNED;
17891 + } set_generic_info_elem;
17892 + struct {
17893 + u16 mode; /* MODE_* */
17894 + u16 chan;
17895 + u32 flag;
17896 + u8 power_level; /* regulatory limit in dBm */
17897 + u8 antenna_max;
17898 + } set_channel_flag;
17899 + struct {
17900 + u32 rd;
17901 + } set_regulatory_domain;
17902 + struct {
17903 + u32 queue;
17904 + s32 aifs;
17905 + u32 cw_min;
17906 + u32 cw_max;
17907 + u32 burst_time; /* maximum burst time in 0.1 ms, i.e.,
17908 + * 10 = 1 ms */
17909 + } tx_queue_params;
17910 + struct {
17911 + u32 bss_count;
17912 + u8 bssid_mask[ETH_ALEN];
17913 + } set_bss;
17914 + struct ieee80211_tx_stats {
17915 + struct {
17916 + unsigned int len; /* num packets in queue */
17917 + unsigned int limit; /* queue len (soft) limit
17918 + */
17919 + unsigned int count; /* total num frames sent */
17920 + } data[4];
17921 + } get_tx_stats;
17922 + struct {
17923 + u8 ssid_len;
17924 + u8 ssid[0] ALIGNED;
17925 + } scan_req;
17926 + struct {
17927 + u32 state;
17928 + } sta_get_state;
17929 + struct {
17930 +#define MLME_STA_DEAUTH 0
17931 +#define MLME_STA_DISASSOC 1
17932 + u16 cmd;
17933 + u16 reason_code;
17934 + } mlme;
17935 + struct {
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;
17941 + } radar;
17942 + struct {
17943 + unsigned int period;
17944 + unsigned int offset;
17945 + unsigned int duration;
17946 + } quiet;
17947 + struct {
17948 + unsigned int tx_power_min;
17949 + unsigned int tx_power_max;
17950 + } tx_power;
17951 + struct {
17952 + u8 dummy[80]; /* Make sizeof() this struct large enough
17953 + * with some compiler versions. */
17954 + } dummy;
17955 + } u;
17956 +};
17957 +
17958 +
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 */
17964 +enum {
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
17972 +};
17973 +#endif /* IEEE80211_TX_QUEUE_NUMS */
17974 +
17975 +
17976 +#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
17977 +#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
17978 +
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
17985 +
17986 +#define HOSTAP_HW_FLAG_NULLFUNC_OK BIT(0)
17987 +
17988 +enum {
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,
17993 +};
17994 +
17995 +
17996 +/* Data structures used for get_hw_features ioctl */
17997 +struct hostapd_ioctl_hw_modes_hdr {
17998 + int mode;
17999 + int num_channels;
18000 + int num_rates;
18001 +};
18002 +
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_*) */
18007 +};
18008 +
18009 +struct ieee80211_rate_data {
18010 + int rate; /* rate in 100 kbps */
18011 + int flags; /* IEEE80211_RATE_ flags */
18012 +};
18013 +
18014 +
18015 +/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
18016 +enum {
18017 + HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
18018 + HOSTAP_IF_STA = 4
18019 +};
18020 +
18021 +struct hostapd_if_wds {
18022 + u8 remote_addr[ETH_ALEN];
18023 +};
18024 +
18025 +struct hostapd_if_vlan {
18026 + u8 id;
18027 +};
18028 +
18029 +struct hostapd_if_bss {
18030 + u8 bssid[ETH_ALEN];
18031 +};
18032 +
18033 +struct hostapd_if_sta {
18034 +};
18035 +
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
18040 @@ -0,0 +1,4896 @@
18041 +/*
18042 + * Copyright 2002-2005, Instant802 Networks, Inc.
18043 + * Copyright 2005-2006, Devicescape Software, Inc.
18044 + *
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.
18048 + */
18049 +
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>
18063 +
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"
18070 +#include "wep.h"
18071 +#include "wpa.h"
18072 +#include "tkip.h"
18073 +#include "wme.h"
18074 +
18075 +
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) */
18084 +
18085 +static unsigned char eapol_header[] =
18086 +{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
18087 +
18088 +
18089 +struct rate_control_algs {
18090 + struct rate_control_algs *next;
18091 + struct rate_control_ops *ops;
18092 +};
18093 +
18094 +static struct rate_control_algs *ieee80211_rate_ctrl_algs;
18095 +
18096 +static int rate_control_initialize(struct ieee80211_local *local);
18097 +
18098 +
18099 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
18100 +
18101 +
18102 +struct ieee80211_key_conf *
18103 +ieee80211_key_data2conf(struct ieee80211_local *local,
18104 + struct ieee80211_key *data)
18105 +{
18106 + struct ieee80211_key_conf *conf;
18107 +
18108 + conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
18109 + if (conf == NULL)
18110 + return NULL;
18111 +
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);
18120 +
18121 + return conf;
18122 +}
18123 +
18124 +
18125 +static int rate_list_match(int *rate_list, int rate)
18126 +{
18127 + int i;
18128 +
18129 + if (rate_list == NULL)
18130 + return 0;
18131 +
18132 + for (i = 0; rate_list[i] >= 0; i++)
18133 + if (rate_list[i] == rate)
18134 + return 1;
18135 +
18136 + return 0;
18137 +}
18138 +
18139 +
18140 +void ieee80211_prepare_rates(struct net_device *dev)
18141 +{
18142 + struct ieee80211_local *local = dev->priv;
18143 + int i;
18144 +
18145 + for (i = 0; i < local->num_curr_rates; i++) {
18146 + struct ieee80211_rate *rate = &local->curr_rates[i];
18147 +
18148 + rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
18149 + IEEE80211_RATE_BASIC);
18150 +
18151 + if (local->supp_rates[local->conf.phymode]) {
18152 + if (!rate_list_match(local->supp_rates
18153 + [local->conf.phymode],
18154 + rate->rate))
18155 + continue;
18156 + }
18157 +
18158 + rate->flags |= IEEE80211_RATE_SUPPORTED;
18159 +
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],
18165 + rate->rate))
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;
18172 + break;
18173 + case MODE_IEEE80211B:
18174 + if (rate->rate == 10 || rate->rate == 20)
18175 + rate->flags |= IEEE80211_RATE_BASIC;
18176 + break;
18177 + case MODE_ATHEROS_TURBO:
18178 + if (rate->rate == 120 || rate->rate == 240 ||
18179 + rate->rate == 480)
18180 + rate->flags |= IEEE80211_RATE_BASIC;
18181 + break;
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;
18186 + break;
18187 + }
18188 +
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;
18195 + break;
18196 + case MODE_IEEE80211B:
18197 + if (rate->rate == 10)
18198 + rate->flags |= IEEE80211_RATE_MANDATORY;
18199 + break;
18200 + case MODE_ATHEROS_TURBO:
18201 + break;
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;
18211 + break;
18212 + }
18213 + }
18214 +}
18215 +
18216 +
18217 +static void ieee80211_key_threshold_notify(struct net_device *dev,
18218 + struct ieee80211_key *key,
18219 + struct sta_info *sta)
18220 +{
18221 + struct sk_buff *skb;
18222 + struct ieee80211_msg_key_notification *msg;
18223 +
18224 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
18225 + sizeof(struct ieee80211_msg_key_notification));
18226 + if (skb == NULL)
18227 + return;
18228 +
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);
18234 + if (sta)
18235 + memcpy(msg->addr, sta->addr, ETH_ALEN);
18236 + else
18237 + memset(msg->addr, 0xff, ETH_ALEN);
18238 +
18239 + key->tx_rx_count = 0;
18240 +
18241 + ieee80211_rx_mgmt(dev, skb, 0,
18242 + ieee80211_msg_key_threshold_notification);
18243 +}
18244 +
18245 +
18246 +int ieee80211_get_hdrlen(u16 fc)
18247 +{
18248 + int hdrlen = 24;
18249 +
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 */
18256 + break;
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:
18261 + hdrlen = 10;
18262 + break;
18263 + default:
18264 + hdrlen = 16;
18265 + break;
18266 + }
18267 + break;
18268 + }
18269 +
18270 + return hdrlen;
18271 +}
18272 +
18273 +
18274 +int ieee80211_get_hdrlen_from_skb(struct sk_buff *skb)
18275 +{
18276 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18277 + int hdrlen;
18278 +
18279 + if (unlikely(skb->len < 10))
18280 + return 0;
18281 + hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
18282 + if (unlikely(hdrlen > skb->len))
18283 + return 0;
18284 + return hdrlen;
18285 +}
18286 +
18287 +
18288 +#ifdef IEEE80211_VERBOSE_DEBUG_FRAME_DUMP
18289 +static void ieee80211_dump_frame(const char *ifname, const char *title,
18290 + struct sk_buff *skb)
18291 +{
18292 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
18293 + u16 fc;
18294 + int hdrlen;
18295 +
18296 + printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
18297 + if (skb->len < 4) {
18298 + printk("\n");
18299 + return;
18300 + }
18301 +
18302 + fc = le16_to_cpu(hdr->frame_control);
18303 + hdrlen = ieee80211_get_hdrlen(fc);
18304 + if (hdrlen > skb->len)
18305 + hdrlen = skb->len;
18306 + if (hdrlen >= 4)
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));
18317 + printk("\n");
18318 +}
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)
18322 +{
18323 +}
18324 +#endif /* IEEE80211_VERBOSE_DEBUG_FRAME_DUMP */
18325 +
18326 +
18327 +static int ieee80211_is_eapol(struct sk_buff *skb)
18328 +{
18329 + struct ieee80211_hdr *hdr;
18330 + u16 fc;
18331 + int hdrlen;
18332 +
18333 + if (unlikely(skb->len < 10))
18334 + return 0;
18335 +
18336 + hdr = (struct ieee80211_hdr *) skb->data;
18337 + fc = le16_to_cpu(hdr->frame_control);
18338 +
18339 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
18340 + return 0;
18341 +
18342 + hdrlen = ieee80211_get_hdrlen(fc);
18343 +
18344 + if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
18345 + memcmp(skb->data + hdrlen, eapol_header,
18346 + sizeof(eapol_header)) == 0))
18347 + return 1;
18348 +
18349 + return 0;
18350 +}
18351 +
18352 +
18353 +static ieee80211_txrx_result
18354 +ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
18355 +{
18356 + struct rate_control_extra extra;
18357 +
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;
18364 +
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;
18371 + } else {
18372 + tx->u.tx.control->alt_retry_rate = -1;
18373 + }
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 &&
18378 + extra.nonerp) {
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;
18382 +
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;
18386 + } else {
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;
18390 + }
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;
18397 + }
18398 +
18399 + return TXRX_CONTINUE;
18400 +}
18401 +
18402 +
18403 +static ieee80211_txrx_result
18404 +ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
18405 +{
18406 + if (tx->sta)
18407 + tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
18408 + else
18409 + tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
18410 +
18411 + if (unlikely(tx->u.tx.control->do_not_encrypt))
18412 + tx->key = NULL;
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;
18421 + } else
18422 + tx->key = NULL;
18423 +
18424 + if (tx->key) {
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,
18430 + tx->sta);
18431 + }
18432 + }
18433 +
18434 + return TXRX_CONTINUE;
18435 +}
18436 +
18437 +
18438 +static ieee80211_txrx_result
18439 +ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
18440 +{
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;
18444 + int i;
18445 + u8 *pos;
18446 + int frag_threshold = tx->local->fragmentation_threshold;
18447 +
18448 + if (!tx->fragmented)
18449 + return TXRX_CONTINUE;
18450 +
18451 + first = tx->skb;
18452 +
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;
18457 +
18458 + frags = (struct sk_buff **)
18459 + kmalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
18460 + if (frags == NULL)
18461 + goto fail;
18462 + memset(frags, 0, num_fragm * sizeof(struct sk_buff *));
18463 +
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;
18469 + size_t copylen;
18470 +
18471 + if (left <= 0)
18472 + goto fail;
18473 +
18474 + /* reserve enough extra head and tail room for possible
18475 + * encryption */
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);
18482 + if (!frag)
18483 + goto fail;
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);
18495 +
18496 + pos += copylen;
18497 + left -= copylen;
18498 + }
18499 + skb_trim(first, hdrlen + per_fragm);
18500 +
18501 + tx->u.tx.num_extra_frag = num_fragm - 1;
18502 + tx->u.tx.extra_frag = frags;
18503 +
18504 + return TXRX_CONTINUE;
18505 +
18506 + fail:
18507 + printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
18508 + if (frags) {
18509 + for (i = 0; i < num_fragm - 1; i++)
18510 + if (frags[i])
18511 + dev_kfree_skb(frags[i]);
18512 + kfree(frags);
18513 + }
18514 + I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
18515 + return TXRX_DROP;
18516 +}
18517 +
18518 +
18519 +static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
18520 +{
18521 + if (tx->key->force_sw_encrypt || tx->local->conf.sw_encrypt) {
18522 + if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
18523 + return -1;
18524 + } else {
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) ==
18528 + NULL)
18529 + return -1;
18530 + }
18531 + }
18532 + return 0;
18533 +}
18534 +
18535 +
18536 +void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
18537 +{
18538 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18539 +
18540 + hdr->frame_control |= cpu_to_le16(WLAN_FC_ISWEP);
18541 + if (tx->u.tx.extra_frag) {
18542 + struct ieee80211_hdr *fhdr;
18543 + int i;
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);
18548 + }
18549 + }
18550 +}
18551 +
18552 +
18553 +static ieee80211_txrx_result
18554 +ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
18555 +{
18556 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18557 + u16 fc;
18558 +
18559 + fc = le16_to_cpu(hdr->frame_control);
18560 +
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;
18566 +
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);
18570 +
18571 + if (wep_encrypt_skb(tx, tx->skb) < 0) {
18572 + I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
18573 + return TXRX_DROP;
18574 + }
18575 +
18576 + if (tx->u.tx.extra_frag) {
18577 + int i;
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;
18583 + }
18584 + }
18585 + }
18586 +
18587 + return TXRX_CONTINUE;
18588 +}
18589 +
18590 +
18591 +static inline int ceiling_div(int dividend, int divisor)
18592 +{
18593 + return ((dividend + divisor - 1) / divisor);
18594 +}
18595 +
18596 +
18597 +static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
18598 + int rate, int erp, int short_preamble)
18599 +{
18600 + int dur;
18601 +
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.
18606 + *
18607 + * rate is in 100 kbps, so divident is multiplied by 10 in the
18608 + * ceiling_div() operations.
18609 + */
18610 +
18611 + if (local->conf.phymode == MODE_IEEE80211A || erp ||
18612 + local->conf.phymode == MODE_ATHEROS_TURBO) {
18613 + /*
18614 + * OFDM:
18615 + *
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
18620 + *
18621 + * T_SYM = 4 usec
18622 + * 802.11a - 17.5.2: aSIFSTime = 16 usec
18623 + * 802.11g - 19.8.4: aSIFSTime = 10 usec +
18624 + * signal ext = 6 usec
18625 + */
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 */
18632 + } else {
18633 + /*
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.
18637 + *
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
18642 + */
18643 + dur = 10; /* aSIFSTime = 10 usec */
18644 + dur += short_preamble ? (72 + 24) : (144 + 48);
18645 +
18646 + dur += ceiling_div(8 * (len + 4) * 10, rate);
18647 + }
18648 +
18649 + return dur;
18650 +}
18651 +
18652 +
18653 +static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
18654 + int next_frag_len)
18655 +{
18656 + int rate, mrate, erp, dur, i;
18657 + struct ieee80211_rate *txrate = tx->u.tx.rate;
18658 + struct ieee80211_local *local = tx->local;
18659 +
18660 + erp = txrate->flags & IEEE80211_RATE_ERP;
18661 +
18662 + /*
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
18671 + *
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
18678 + */
18679 +
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.
18684 + *
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
18692 + * and its SIFS
18693 + * PS Poll: BIT(15) | BIT(14) | aid
18694 + */
18695 + return 0;
18696 + }
18697 +
18698 + /* data/mgmt */
18699 + if (0 /* FIX: data/mgmt during CFP */)
18700 + return 32768;
18701 +
18702 + if (group_addr) /* Group address as the destination - no ACK */
18703 + return 0;
18704 +
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
18714 + */
18715 + rate = -1;
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)
18720 + break;
18721 +
18722 + if (IEEE80211_RATE_MODULATION(txrate->flags) !=
18723 + IEEE80211_RATE_MODULATION(r->flags))
18724 + continue;
18725 +
18726 + if (r->flags & IEEE80211_RATE_BASIC)
18727 + rate = r->rate;
18728 + else if (r->flags & IEEE80211_RATE_MANDATORY)
18729 + mrate = r->rate;
18730 + }
18731 + if (rate == -1) {
18732 + /* No matching basic rate found; use highest suitable mandatory
18733 + * PHY rate */
18734 + rate = mrate;
18735 + }
18736 +
18737 + /* Time needed to transmit ACK
18738 + * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
18739 + * to closest integer */
18740 +
18741 + dur = ieee80211_frame_duration(local, 10, rate, erp,
18742 + local->short_preamble);
18743 +
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);
18752 + }
18753 +
18754 + return dur;
18755 +}
18756 +
18757 +
18758 +static ieee80211_txrx_result
18759 +ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
18760 +{
18761 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
18762 + u16 dur;
18763 + struct ieee80211_tx_control *control = tx->u.tx.control;
18764 +
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;
18771 + } else {
18772 + control->retry_limit =
18773 + tx->local->short_retry_limit;
18774 + }
18775 + } else {
18776 + control->retry_limit = 1;
18777 + }
18778 +
18779 + if (tx->fragmented) {
18780 + /* Do not use multiple retry rates when sending fragmented
18781 + * frames.
18782 + * TODO: The last fragment could still use multiple retry
18783 + * rates. */
18784 + control->alt_retry_rate = -1;
18785 + }
18786 +
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;
18796 +
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 :
18802 + 0);
18803 + hdr->duration_id = cpu_to_le16(dur);
18804 +
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;
18808 +
18809 + /* Do not use multiple retry rates when using RTS/CTS */
18810 + control->alt_retry_rate = -1;
18811 +
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))
18816 + rate--;
18817 +
18818 + if (control->use_rts_cts)
18819 + dur += ieee80211_frame_duration(tx->local, 10,
18820 + rate->rate, erp,
18821 + tx->local->
18822 + short_preamble);
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;
18828 + }
18829 +
18830 + if (tx->sta) {
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) {
18835 + int i;
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;
18840 + }
18841 + }
18842 + }
18843 + tx->local->scan.txrx_count++;
18844 +
18845 + return TXRX_CONTINUE;
18846 +}
18847 +
18848 +
18849 +static void ieee80211_rate_limit(unsigned long data)
18850 +{
18851 + struct ieee80211_local *local = (struct ieee80211_local *) data;
18852 +
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);
18859 + }
18860 +}
18861 +
18862 +
18863 +static ieee80211_txrx_result
18864 +ieee80211_tx_h_rate_limit(struct ieee80211_txrx_data *tx)
18865 +{
18866 +
18867 + if (likely(!tx->local->rate_limit || tx->u.tx.unicast))
18868 + return TXRX_CONTINUE;
18869 +
18870 + /* rate limit */
18871 + if (tx->local->rate_limit_bucket) {
18872 + tx->local->rate_limit_bucket--;
18873 + return TXRX_CONTINUE;
18874 + }
18875 +
18876 + I802_DEBUG_INC(tx->local->tx_handlers_drop_rate_limit);
18877 + return TXRX_DROP;
18878 +}
18879 +
18880 +
18881 +static ieee80211_txrx_result
18882 +ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
18883 +{
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 */
18888 + u32 sta_flags;
18889 +
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;
18894 +
18895 + if (tx->u.tx.ps_buffered)
18896 + return TXRX_CONTINUE;
18897 +
18898 + sta_flags = tx->sta ? tx->sta->flags : 0;
18899 +
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;
18911 + }
18912 + } else {
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)) {
18917 + /*
18918 + * No associated STAs - no need to send multicast
18919 + * frames.
18920 + */
18921 + return TXRX_DROP;
18922 + }
18923 + return TXRX_CONTINUE;
18924 + }
18925 +
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));
18934 +#endif
18935 + I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
18936 + return TXRX_DROP;
18937 + }
18938 +
18939 + return TXRX_CONTINUE;
18940 +}
18941 +
18942 +
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)
18948 +{
18949 + int total = 0, purged = 0;
18950 + struct sk_buff *skb;
18951 + struct list_head *ptr;
18952 +
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)
18960 + continue;
18961 + ap = &sdata->u.ap;
18962 + skb = skb_dequeue(&ap->ps_bc_buf);
18963 + if (skb) {
18964 + purged++;
18965 + dev_kfree_skb(skb);
18966 + }
18967 + total += skb_queue_len(&ap->ps_bc_buf);
18968 + }
18969 + spin_unlock_bh(&local->sub_if_lock);
18970 +
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);
18976 + if (skb) {
18977 + purged++;
18978 + dev_kfree_skb(skb);
18979 + }
18980 + total += skb_queue_len(&sta->ps_tx_buf);
18981 + }
18982 + spin_unlock_bh(&local->sta_lock);
18983 +
18984 + local->total_ps_buffered = total;
18985 + printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
18986 + local->mdev->name, purged);
18987 +}
18988 +
18989 +
18990 +static inline ieee80211_txrx_result
18991 +ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
18992 +{
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",
19007 + tx->dev->name);
19008 + }
19009 + dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
19010 + } else
19011 + tx->local->total_ps_buffered++;
19012 + skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
19013 + return TXRX_QUEUED;
19014 + }
19015 +
19016 + return TXRX_CONTINUE;
19017 +}
19018 +
19019 +
19020 +static inline ieee80211_txrx_result
19021 +ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
19022 +{
19023 + struct sta_info *sta = tx->sta;
19024 +
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;
19029 +
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 "
19034 + "before %d)\n",
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));
19047 + }
19048 + dev_kfree_skb(old);
19049 + } else
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;
19058 + }
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));
19064 + }
19065 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
19066 + sta->pspoll = 0;
19067 +
19068 + return TXRX_CONTINUE;
19069 +}
19070 +
19071 +
19072 +static ieee80211_txrx_result
19073 +ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
19074 +{
19075 + if (unlikely(tx->u.tx.ps_buffered))
19076 + return TXRX_CONTINUE;
19077 +
19078 + if (tx->u.tx.unicast)
19079 + return ieee80211_tx_h_unicast_ps_buf(tx);
19080 + else
19081 + return ieee80211_tx_h_multicast_ps_buf(tx);
19082 +}
19083 +
19084 +
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)
19089 +{
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;
19093 + int hdrlen;
19094 +
19095 + pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
19096 +
19097 + memset(tx, 0, sizeof(*tx));
19098 + tx->skb = skb;
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;
19117 + }
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];
19125 + }
19126 +
19127 +}
19128 +
19129 +
19130 +static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
19131 + struct ieee80211_tx_control *control, int mgmt)
19132 +{
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;
19138 + int ret, i;
19139 +
19140 + if (unlikely(skb->len < 10)) {
19141 + dev_kfree_skb(skb);
19142 + return 0;
19143 + }
19144 +
19145 + ieee80211_tx_prepare(&tx, skb, dev, control);
19146 + sta = tx.sta;
19147 + tx.u.tx.mgmt_interface = mgmt;
19148 +
19149 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19150 + res = (*handler)(&tx);
19151 + if (res != TXRX_CONTINUE)
19152 + break;
19153 + }
19154 +
19155 + skb = tx.skb; /* handlers are allowed to change skb */
19156 +
19157 + if (sta)
19158 + sta_info_release(local, sta);
19159 +
19160 + if (unlikely(res == TXRX_DROP)) {
19161 + I802_DEBUG_INC(local->tx_handlers_drop);
19162 + goto drop;
19163 + }
19164 +
19165 + if (unlikely(res == TXRX_QUEUED)) {
19166 + I802_DEBUG_INC(local->tx_handlers_queued);
19167 + return 0;
19168 + }
19169 +
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);
19175 + }
19176 +#endif /* IEEE80211_LEDS */
19177 + if (tx.u.tx.extra_frag) {
19178 + if (ret > 0) {
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
19184 + * retry. */
19185 + goto drop;
19186 + }
19187 +
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;
19199 + else {
19200 + next_len = 0;
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;
19207 + }
19208 + dur = ieee80211_duration(&tx, 0, next_len);
19209 + hdr->duration_id = cpu_to_le16(dur);
19210 +
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],
19214 + control);
19215 + if (ret > 0)
19216 + goto drop;
19217 +#ifdef IEEE80211_LEDS
19218 + if (local->tx_led_counter++ == 0) {
19219 + ieee80211_tx_led(1, dev);
19220 + }
19221 +#endif /* IEEE80211_LEDS */
19222 + tx.u.tx.extra_frag[i] = NULL;
19223 + }
19224 + kfree(tx.u.tx.extra_frag);
19225 + }
19226 + if (ret == -1)
19227 + ret = 0;
19228 + return ret;
19229 +
19230 + drop:
19231 + if (skb)
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);
19237 + return 0;
19238 +}
19239 +
19240 +
19241 +static int ieee80211_master_start_xmit(struct sk_buff *skb,
19242 + struct net_device *dev)
19243 +{
19244 + struct ieee80211_tx_control control;
19245 + struct ieee80211_tx_packet_data *pkt_data;
19246 + struct ieee80211_sub_if_data *sdata;
19247 + int ret;
19248 +
19249 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19250 +
19251 + /*
19252 + * copy control out of the skb so other people can use skb->cb
19253 + */
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;
19263 +
19264 + ret = ieee80211_tx(dev, skb, &control,
19265 + control.sdata->type == IEEE80211_SUB_IF_TYPE_MGMT);
19266 +
19267 + return ret;
19268 +}
19269 +
19270 +
19271 +/**
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
19276 + *
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
19279 + * skb).
19280 + *
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).
19285 + */
19286 +static int ieee80211_subif_start_xmit(struct sk_buff *skb,
19287 + struct net_device *dev)
19288 +{
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;
19295 + u8 *encaps_data;
19296 + int encaps_len, skip_header_bytes;
19297 + int nh_pos, h_pos, no_encrypt = 0;
19298 + struct sta_info *sta;
19299 +
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);
19304 + ret = 0;
19305 + goto fail;
19306 + }
19307 +
19308 + nh_pos = skb->nh.raw - skb->data;
19309 + h_pos = skb->h.raw - skb->data;
19310 +
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);
19316 +
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);
19336 + }
19337 + hdrlen = 24;
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);
19345 + hdrlen = 30;
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);
19353 + } else {
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);
19358 + }
19359 + hdrlen = 24;
19360 + } else {
19361 + ret = 0;
19362 + goto fail;
19363 + }
19364 +
19365 + /* receiver is QoS enabled, use a QoS type frame */
19366 + sta = sta_info_get(local, hdr.addr1);
19367 + if (sta) {
19368 + if (sta->flags & WLAN_STA_WME) {
19369 + fc |= WLAN_FC_STYPE_QOS_DATA << 4;
19370 + hdrlen += 2;
19371 + }
19372 + sta_info_release(local, sta);
19373 + }
19374 +
19375 + hdr.frame_control = cpu_to_le16(fc);
19376 + hdr.duration_id = 0;
19377 + hdr.seq_ctrl = 0;
19378 +
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;
19388 + } else {
19389 + encaps_data = NULL;
19390 + encaps_len = 0;
19391 + }
19392 +
19393 + skb_pull(skb, skip_header_bytes);
19394 + nh_pos -= skip_header_bytes;
19395 + h_pos -= skip_header_bytes;
19396 +
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
19401 + * somehow
19402 + *
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)
19409 + */
19410 + head_need = hdrlen + encaps_len + (local->hw->extra_hdr_room ? 2 : 0);
19411 + head_need -= skb_headroom(skb);
19412 +
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. */
19416 +
19417 + if (head_need > 0 || skb_cloned(skb)) {
19418 +#if 0
19419 + printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
19420 + "of headroom\n", dev->name, head_need);
19421 +#endif
19422 +
19423 + if (skb_cloned(skb))
19424 + I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
19425 + else
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);
19434 + goto fail;
19435 + }
19436 + }
19437 +
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;
19442 + }
19443 + memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
19444 + nh_pos += hdrlen;
19445 + h_pos += hdrlen;
19446 +
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;
19451 +
19452 + skb->dev = sdata->master;
19453 + sdata->stats.tx_packets++;
19454 + sdata->stats.tx_bytes += skb->len;
19455 +
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;
19462 +
19463 + dev_queue_xmit(skb);
19464 +
19465 + return 0;
19466 +
19467 + fail:
19468 + if (!ret)
19469 + dev_kfree_skb(skb);
19470 +
19471 + return ret;
19472 +}
19473 +
19474 +
19475 +/*
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
19479 + */
19480 +static int
19481 +ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
19482 +{
19483 + struct ieee80211_sub_if_data *sdata;
19484 + struct ieee80211_tx_packet_data *pkt_data;
19485 + struct ieee80211_hdr *hdr;
19486 + u16 fc;
19487 +
19488 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19489 +
19490 + if (skb->len < 10) {
19491 + dev_kfree_skb(skb);
19492 + return 0;
19493 + }
19494 +
19495 + hdr = (struct ieee80211_hdr *) skb->data;
19496 + fc = le16_to_cpu(hdr->frame_control);
19497 +
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;
19501 +
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;
19505 +
19506 + skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
19507 + skb->dev = sdata->master;
19508 +
19509 + /*
19510 + * We're using the protocol field of the the frame control header
19511 + * to request TX callback for hostapd. BIT(1) is checked.
19512 + */
19513 + if ((fc & BIT(1)) == BIT(1)) {
19514 + pkt_data->req_tx_status = 1;
19515 + fc &= ~BIT(1);
19516 + hdr->frame_control = cpu_to_le16(fc);
19517 + }
19518 +
19519 + pkt_data->do_not_encrypt = !(fc & WLAN_FC_ISWEP);
19520 +
19521 + sdata->stats.tx_packets++;
19522 + sdata->stats.tx_bytes += skb->len;
19523 +
19524 + dev_queue_xmit(skb);
19525 +
19526 + return 0;
19527 +}
19528 +
19529 +
19530 +static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
19531 + struct ieee80211_if_ap *bss,
19532 + struct sk_buff *skb)
19533 +{
19534 + u8 *pos, *tim;
19535 + int aid0 = 0;
19536 + int i, num_bits = 0, n1, n2;
19537 + u8 bitmap[251];
19538 +
19539 + /* Generate bitmap for TIM only if there are any STAs in power save
19540 + * mode. */
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)))
19548 + {
19549 + bitmap[(i + 1) / 8] |= 1 << (i + 1) % 8;
19550 + num_bits++;
19551 + }
19552 + }
19553 + spin_unlock_bh(&local->sta_lock);
19554 + }
19555 +
19556 + if (bss->dtim_count == 0)
19557 + bss->dtim_count = bss->dtim_period - 1;
19558 + else
19559 + bss->dtim_count--;
19560 +
19561 + tim = pos = (u8 *) skb_put(skb, 6);
19562 + *pos++ = WLAN_EID_TIM;
19563 + *pos++ = 4;
19564 + *pos++ = bss->dtim_count;
19565 + *pos++ = bss->dtim_period;
19566 +
19567 + if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) {
19568 + aid0 = 1;
19569 + }
19570 +
19571 + if (num_bits) {
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. */
19575 + n1 = 0;
19576 + for (i = 0; i < sizeof(bitmap); i++) {
19577 + if (bitmap[i]) {
19578 + n1 = i & 0xfe;
19579 + break;
19580 + }
19581 + }
19582 + n2 = n1;
19583 + for (i = sizeof(bitmap) - 1; i >= n1; i--) {
19584 + if (bitmap[i]) {
19585 + n2 = i;
19586 + break;
19587 + }
19588 + }
19589 +
19590 + /* Bitmap control */
19591 + *pos++ = n1 | (aid0 ? 1 : 0);
19592 + /* Part Virt Bitmap */
19593 + memcpy(pos, bitmap + n1, n2 - n1 + 1);
19594 +
19595 + tim[1] = n2 - n1 + 4;
19596 + skb_put(skb, n2 - n1);
19597 + } else {
19598 + *pos++ = aid0 ? 1 : 0; /* Bitmap control */
19599 + *pos++ = 0; /* Part Virt Bitmap */
19600 + }
19601 +}
19602 +
19603 +
19604 +struct sk_buff * ieee80211_beacon_get(struct net_device *dev, int bss_idx,
19605 + struct ieee80211_tx_control *control)
19606 +{
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;
19616 +
19617 + spin_lock_bh(&local->sub_if_lock);
19618 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count)
19619 + bdev = NULL;
19620 + else {
19621 + bdev = local->bss_devs[bss_idx];
19622 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19623 + ap = &sdata->u.ap;
19624 + }
19625 + spin_unlock_bh(&local->sub_if_lock);
19626 +
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 */
19633 + return NULL;
19634 + }
19635 +
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;
19641 +
19642 + skb = dev_alloc_skb(bh_len + bt_len + 256 /* maximum TIM len */);
19643 + if (!skb)
19644 + return NULL;
19645 +
19646 + memcpy(skb_put(skb, bh_len), b_head, bh_len);
19647 +
19648 + ieee80211_beacon_add_tim(local, ap, skb);
19649 +
19650 + if (b_tail) {
19651 + memcpy(skb_put(skb, bt_len), b_tail, bt_len);
19652 + }
19653 +
19654 + memset(&extra, 0, sizeof(extra));
19655 + extra.endidx = local->num_curr_rates;
19656 +
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);
19662 + }
19663 + dev_kfree_skb(skb);
19664 + return NULL;
19665 + }
19666 +
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;
19676 +
19677 + ap->num_beacons++;
19678 + return skb;
19679 +}
19680 +
19681 +
19682 +struct sk_buff *
19683 +ieee80211_get_buffered_bc(struct net_device *dev, int bss_idx,
19684 + struct ieee80211_tx_control *control)
19685 +{
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;
19695 +
19696 + spin_lock_bh(&local->sub_if_lock);
19697 + if (bss_idx < 0 || bss_idx >= local->bss_dev_count) {
19698 + bdev = NULL;
19699 + bss = NULL;
19700 + } else {
19701 + bdev = local->bss_devs[bss_idx];
19702 + sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
19703 + bss = &sdata->u.ap;
19704 + }
19705 + spin_unlock_bh(&local->sub_if_lock);
19706 + if (bdev == NULL || bss == NULL || bss->beacon_head == NULL)
19707 + return NULL;
19708 +
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));
19713 + if (skb == NULL)
19714 + return NULL;
19715 + local->total_ps_buffered--;
19716 +
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);
19722 + }
19723 +
19724 + ieee80211_tx_prepare(&tx, skb, dev, control);
19725 + sta = tx.sta;
19726 + tx.u.tx.ps_buffered = 1;
19727 +
19728 + for (handler = local->tx_handlers; *handler != NULL; handler++) {
19729 + res = (*handler)(&tx);
19730 + if (res == TXRX_DROP || res == TXRX_QUEUED)
19731 + break;
19732 + }
19733 +
19734 + if (res == TXRX_DROP) {
19735 + I802_DEBUG_INC(local->tx_handlers_drop);
19736 + dev_kfree_skb(skb);
19737 + skb = NULL;
19738 + } else if (res == TXRX_QUEUED) {
19739 + I802_DEBUG_INC(local->tx_handlers_queued);
19740 + skb = NULL;
19741 + }
19742 +
19743 + if (sta)
19744 + sta_info_release(local, sta);
19745 +
19746 + return skb;
19747 +}
19748 +
19749 +
19750 +int ieee80211_hw_config(struct net_device *dev)
19751 +{
19752 + struct ieee80211_local *local = dev->priv;
19753 + int i, ret = 0;
19754 +
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 */
19760 +
19761 + if (local->hw->config)
19762 + ret = local->hw->config(dev, &local->conf);
19763 +
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);
19769 + }
19770 + local->curr_rates = mode->rates;
19771 + local->num_curr_rates = mode->num_rates;
19772 + ieee80211_prepare_rates(dev);
19773 + break;
19774 + }
19775 + }
19776 +
19777 + return ret;
19778 +}
19779 +
19780 +
19781 +struct ieee80211_conf *ieee80211_get_hw_conf(struct net_device *dev)
19782 +{
19783 + struct ieee80211_local *local = dev->priv;
19784 + return &local->conf;
19785 +}
19786 +
19787 +
19788 +static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
19789 +{
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);
19795 + return -EINVAL;
19796 + }
19797 +
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;
19802 + return 0;
19803 +}
19804 +
19805 +
19806 +static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
19807 +{
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);
19813 + return -EINVAL;
19814 + }
19815 +
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;
19820 + return 0;
19821 +}
19822 +
19823 +
19824 +static void ieee80211_tx_timeout(struct net_device *dev)
19825 +{
19826 + struct ieee80211_local *local = dev->priv;
19827 +
19828 + printk(KERN_WARNING "%s: resetting interface.\n", dev->name);
19829 +
19830 + if (local->hw->reset(dev))
19831 + printk(KERN_ERR "%s: failed to reset interface.\n", dev->name);
19832 + else
19833 + netif_wake_queue(dev);
19834 +}
19835 +
19836 +
19837 +static int ieee80211_set_mac_address(struct net_device *dev, void *addr)
19838 +{
19839 + struct ieee80211_local *local = dev->priv;
19840 + struct sockaddr *a = addr;
19841 + struct list_head *ptr;
19842 + int res;
19843 +
19844 + if (!local->hw->set_mac_address)
19845 + return -EOPNOTSUPP;
19846 +
19847 + res = local->hw->set_mac_address(dev, addr);
19848 + if (res)
19849 + return res;
19850 +
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);
19855 + }
19856 +
19857 + return 0;
19858 +}
19859 +
19860 +
19861 +static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
19862 +{
19863 + struct ieee80211_sub_if_data *sdata;
19864 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19865 + return &(sdata->stats);
19866 +}
19867 +
19868 +
19869 +static int ieee80211_open(struct net_device *dev)
19870 +{
19871 + struct ieee80211_sub_if_data *sdata;
19872 + struct ieee80211_local *local = dev->priv;
19873 + int res;
19874 +
19875 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19876 +
19877 + if (local->open_count == 0) {
19878 + res = local->hw->open(sdata->master);
19879 + if (res)
19880 + return res;
19881 + ieee80211_init_scan(sdata->master);
19882 + }
19883 + local->open_count++;
19884 +
19885 + netif_start_queue(dev);
19886 + return 0;
19887 +}
19888 +
19889 +
19890 +static int ieee80211_stop(struct net_device *dev)
19891 +{
19892 + struct ieee80211_sub_if_data *sdata;
19893 + struct ieee80211_local *local = dev->priv;
19894 + int res;
19895 +
19896 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
19897 +
19898 + netif_stop_queue(dev);
19899 +
19900 + local->open_count--;
19901 + if (local->open_count == 0) {
19902 + ieee80211_stop_scan(sdata->master);
19903 + res = local->hw->stop(sdata->master);
19904 + if (res)
19905 + return res;
19906 + }
19907 +
19908 + return 0;
19909 +}
19910 +
19911 +
19912 +static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
19913 +{
19914 + memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
19915 + return ETH_ALEN;
19916 +}
19917 +
19918 +
19919 +static struct net_device *
19920 +ieee80211_get_wds_dev(struct ieee80211_local *local, u8 *addr)
19921 +{
19922 + struct list_head *ptr;
19923 +
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;
19930 + }
19931 +
19932 + return NULL;
19933 +}
19934 +
19935 +
19936 +static struct net_device * ieee80211_own_bssid(struct ieee80211_local *local,
19937 + u8 *addr)
19938 +{
19939 + int i;
19940 + struct net_device *dev = NULL;
19941 +
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)
19945 + ) {
19946 + dev = local->bss_devs[i];
19947 + break;
19948 + }
19949 + }
19950 + spin_unlock_bh(&local->sub_if_lock);
19951 +
19952 + return dev;
19953 +}
19954 +
19955 +
19956 +static struct net_device * ieee80211_sta_bssid(struct ieee80211_local *local,
19957 + u8 *addr, u8 *a1,
19958 + int *sta_multicast)
19959 +{
19960 + struct list_head *ptr;
19961 + int multicast;
19962 + u8 *own_addr = local->mdev->dev_addr;
19963 +
19964 + multicast = a1[0] & 0x01;
19965 +
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;
19979 + return dev;
19980 + }
19981 + }
19982 + }
19983 +
19984 + if (!multicast)
19985 + return NULL;
19986 +
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)
19992 + continue;
19993 + if (!multicast &&
19994 + memcmp(a1, sdata->dev->dev_addr, ETH_ALEN) != 0)
19995 + continue;
19996 +
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;
20002 + }
20003 + }
20004 +
20005 + return NULL;
20006 +}
20007 +
20008 +
20009 +static int ieee80211_own_addr(struct net_device *dev, u8 *addr)
20010 +{
20011 + struct ieee80211_local *local = dev->priv;
20012 + u8 *own = dev->dev_addr;
20013 + int index;
20014 +
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])
20018 + return 0;
20019 +
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])
20024 + return 1;
20025 +
20026 + return 0;
20027 +}
20028 +
20029 +
20030 +static ieee80211_txrx_result
20031 +ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
20032 +{
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;
20037 + u8 *payload;
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;
20042 +
20043 + fc = rx->fc;
20044 + if (unlikely(WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA))
20045 + return TXRX_CONTINUE;
20046 +
20047 + if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
20048 + return TXRX_DROP;
20049 +
20050 + hdrlen = ieee80211_get_hdrlen(fc);
20051 +
20052 + /* convert IEEE 802.11 header + possible LLC headers into Ethernet
20053 + * header
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
20060 + */
20061 +
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);
20067 +
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;
20075 + }
20076 + break;
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);
20081 +
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="
20086 + MACSTR ")\n",
20087 + rx->dev->name, MAC2STR(hdr->addr1),
20088 + MAC2STR(hdr->addr2), MAC2STR(hdr->addr3),
20089 + MAC2STR(hdr->addr4));
20090 + return TXRX_DROP;
20091 + }
20092 + break;
20093 + case WLAN_FC_FROMDS:
20094 + /* DA BSSID SA */
20095 + memcpy(dst, hdr->addr1, ETH_ALEN);
20096 + memcpy(src, hdr->addr3, ETH_ALEN);
20097 +
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;
20103 + }
20104 + break;
20105 + case 0:
20106 + /* DA SA BSSID */
20107 + memcpy(dst, hdr->addr1, ETH_ALEN);
20108 + memcpy(src, hdr->addr2, ETH_ALEN);
20109 +
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
20115 + ")\n",
20116 + dev->name, MAC2STR(hdr->addr1),
20117 + MAC2STR(hdr->addr2),
20118 + MAC2STR(hdr->addr3));
20119 + }
20120 + return TXRX_DROP;
20121 + }
20122 + break;
20123 + }
20124 +
20125 + payload = skb->data + hdrlen;
20126 +
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);
20131 + }
20132 + return TXRX_DROP;
20133 + }
20134 +
20135 + ethertype = (payload[6] << 8) | payload[7];
20136 +
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);
20145 + } else {
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;
20154 + }
20155 +
20156 + if (rx->sta && !rx->sta->assoc_ap &&
20157 + !(rx->sta && (rx->sta->flags & WLAN_STA_WDS)))
20158 + skb->dev = rx->sta->dev;
20159 + else
20160 + skb->dev = dev;
20161 +
20162 + skb2 = NULL;
20163 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20164 +
20165 + /*
20166 + * don't count the master since the low level code
20167 + * counts it already for us.
20168 + */
20169 + if (skb->dev != sdata->master) {
20170 + sdata->stats.rx_packets++;
20171 + sdata->stats.rx_bytes += skb->len;
20172 + }
20173 +
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);
20183 + } else {
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 "
20188 + "structure!\n");
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.
20193 + */
20194 + skb2 = skb;
20195 + skb = NULL;
20196 + }
20197 + if (dsta)
20198 + sta_info_release(local, dsta);
20199 + }
20200 + }
20201 +
20202 + if (skb) {
20203 + /* deliver to local stack */
20204 + skb->protocol = eth_type_trans(skb, dev);
20205 + memset(skb->cb, 0, sizeof(skb->cb));
20206 + netif_rx(skb);
20207 + }
20208 +
20209 + if (skb2) {
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);
20214 + }
20215 +
20216 + return TXRX_QUEUED;
20217 +}
20218 +
20219 +
20220 +static struct ieee80211_rate *
20221 +ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
20222 +{
20223 + int m, r;
20224 +
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)
20228 + continue;
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))
20234 + return rate;
20235 + }
20236 + }
20237 +
20238 + return NULL;
20239 +}
20240 +
20241 +
20242 +void
20243 +ieee80211_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
20244 + struct ieee80211_rx_status *status, u32 msg_type)
20245 +{
20246 + struct ieee80211_local *local = dev->priv;
20247 + struct ieee80211_frame_info *fi;
20248 + size_t hlen;
20249 + struct ieee80211_sub_if_data *sdata;
20250 +
20251 + dev = local->apdev;
20252 + skb->dev = dev;
20253 +
20254 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
20255 +
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);
20261 + return;
20262 + }
20263 + }
20264 +
20265 + hlen = sizeof(struct ieee80211_frame_info);
20266 + if (msg_type == ieee80211_msg_monitor)
20267 + hlen -= sizeof(fi->msg_type);
20268 +
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);
20275 + if (status) {
20276 + struct timespec ts;
20277 + struct ieee80211_rate *rate;
20278 +
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);
20286 + break;
20287 + case MODE_IEEE80211B:
20288 + fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
20289 + break;
20290 + case MODE_IEEE80211G:
20291 + fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
20292 + break;
20293 + case MODE_ATHEROS_TURBO:
20294 + fi->phytype =
20295 + htonl(ieee80211_phytype_dsss_dot11_turbo);
20296 + break;
20297 + default:
20298 + fi->phytype = 0xAAAAAAAA;
20299 + break;
20300 + }
20301 + fi->channel = htonl(status->channel);
20302 + rate = ieee80211_get_rate(local, status->phymode,
20303 + status->rate);
20304 + if (rate) {
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 */
20311 + } else
20312 + fi->preamble = htonl(0);
20313 + } else {
20314 + fi->datarate = htonl(0);
20315 + fi->preamble = htonl(0);
20316 + }
20317 +
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;
20324 + } else {
20325 + fi->ssi_type = htonl(ieee80211_ssi_none);
20326 + }
20327 +
20328 + sdata->stats.rx_packets++;
20329 + sdata->stats.rx_bytes += skb->len;
20330 +
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));
20336 + netif_rx(skb);
20337 +}
20338 +
20339 +
20340 +int ieee80211_radar_status(struct net_device *dev, int channel, int radar,
20341 + int radar_type)
20342 +{
20343 + struct sk_buff *skb;
20344 + struct ieee80211_radar_info *msg;
20345 +
20346 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20347 + sizeof(struct ieee80211_radar_info));
20348 +
20349 + if (skb == NULL)
20350 + return -ENOMEM;
20351 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20352 +
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;
20358 +
20359 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_radar);
20360 + return 0;
20361 +}
20362 +
20363 +
20364 +int ieee80211_set_aid_for_sta(struct net_device *dev, u8 *peer_address,
20365 + u16 aid)
20366 +{
20367 + struct sk_buff *skb;
20368 + struct ieee80211_msg_set_aid_for_sta *msg;
20369 +
20370 + skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
20371 + sizeof(struct ieee80211_msg_set_aid_for_sta));
20372 +
20373 + if (skb == NULL)
20374 + return -ENOMEM;
20375 + skb_reserve(skb, sizeof(struct ieee80211_frame_info));
20376 +
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);
20380 + msg->aid = aid;
20381 +
20382 + ieee80211_rx_mgmt(dev, skb, 0, ieee80211_msg_set_aid_for_sta);
20383 + return 0;
20384 +}
20385 +
20386 +
20387 +static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
20388 +{
20389 + struct ieee80211_sub_if_data *sdata;
20390 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20391 +
20392 + if (sdata->bss)
20393 + atomic_inc(&sdata->bss->num_sta_ps);
20394 + sta->flags |= WLAN_STA_PS;
20395 + sta->pspoll = 0;
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 */
20400 +}
20401 +
20402 +
20403 +static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
20404 +{
20405 + struct ieee80211_local *local = dev->priv;
20406 + struct sk_buff *skb;
20407 + int sent = 0;
20408 + struct ieee80211_sub_if_data *sdata;
20409 + struct ieee80211_tx_packet_data *pkt_data;
20410 +
20411 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
20412 + if (sdata->bss)
20413 + atomic_dec(&sdata->bss->num_sta_ps);
20414 + sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
20415 + sta->pspoll = 0;
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;
20425 + sent++;
20426 + pkt_data->requeue = 1;
20427 + dev_queue_xmit(skb);
20428 + }
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--;
20432 + sent++;
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);
20440 + }
20441 +
20442 + return sent;
20443 +}
20444 +
20445 +
20446 +static ieee80211_txrx_result
20447 +ieee80211_rx_h_ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
20448 +{
20449 + struct sk_buff *skb;
20450 + int no_pending_pkts;
20451 +
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;
20455 +
20456 + skb = skb_dequeue(&rx->sta->tx_filtered);
20457 + if (skb == NULL) {
20458 + skb = skb_dequeue(&rx->sta->ps_tx_buf);
20459 + if (skb)
20460 + rx->local->total_ps_buffered--;
20461 + }
20462 + no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
20463 + skb_queue_empty(&rx->sta->ps_tx_buf);
20464 +
20465 + if (skb) {
20466 + struct ieee80211_hdr *hdr =
20467 + (struct ieee80211_hdr *) skb->data;
20468 +
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;
20472 +
20473 +#ifdef IEEE80211_VERBOSE_DEBUG_PS
20474 + printk(KERN_DEBUG "STA " MACSTR " aid %d: PS Poll (entries "
20475 + "after %d)\n",
20476 + MAC2STR(rx->sta->addr), rx->sta->aid,
20477 + skb_queue_len(&rx->sta->ps_tx_buf));
20478 +#endif /* IEEE80211_VERBOSE_DEBUG_PS */
20479 +
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;
20485 + } else
20486 + hdr->frame_control |= cpu_to_le16(WLAN_FC_MOREDATA);
20487 +
20488 + dev_queue_xmit(skb);
20489 +
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 */
20498 +
20499 + }
20500 +
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);
20504 +
20505 + return TXRX_QUEUED;
20506 +}
20507 +
20508 +
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)
20513 +{
20514 + struct ieee80211_fragment_entry *entry;
20515 + int idx;
20516 +
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;
20521 +
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);
20535 + }
20536 +
20537 + entry->skb = *skb;
20538 + *skb = NULL;
20539 + entry->first_frag_time = jiffies;
20540 + entry->seq = seq;
20541 + entry->rx_queue = rx_queue;
20542 + entry->last_frag = frag;
20543 + entry->ccmp = 0;
20544 +
20545 + return entry;
20546 +}
20547 +
20548 +
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)
20553 +{
20554 + struct ieee80211_fragment_entry *entry;
20555 + int i, idx;
20556 +
20557 + idx = local->fragment_next;
20558 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
20559 + struct ieee80211_hdr *f_hdr;
20560 + u16 f_fc;
20561 +
20562 + idx--;
20563 + if (idx < 0)
20564 + idx = IEEE80211_FRAGMENT_MAX - 1;
20565 +
20566 + entry = &local->fragments[idx];
20567 + if (!entry->skb || entry->seq != seq ||
20568 + entry->rx_queue != rx_queue ||
20569 + entry->last_frag + 1 != frag)
20570 + continue;
20571 +
20572 + f_hdr = (struct ieee80211_hdr *) entry->skb->data;
20573 + f_fc = le16_to_cpu(f_hdr->frame_control);
20574 +
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)
20578 + continue;
20579 +
20580 + if (entry->first_frag_time + 2 * HZ < jiffies) {
20581 + dev_kfree_skb(entry->skb);
20582 + entry->skb = NULL;
20583 + continue;
20584 + }
20585 + return entry;
20586 + }
20587 +
20588 + return NULL;
20589 +}
20590 +
20591 +
20592 +static ieee80211_txrx_result
20593 +ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
20594 +{
20595 + struct ieee80211_hdr *hdr;
20596 + u16 sc;
20597 + unsigned int frag, seq;
20598 + struct ieee80211_fragment_entry *entry;
20599 +
20600 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20601 + sc = le16_to_cpu(hdr->seq_ctrl);
20602 + frag = WLAN_GET_SEQ_FRAG(sc);
20603 +
20604 + if (likely((!(rx->fc & WLAN_FC_MOREFRAG) && frag == 0) ||
20605 + (rx->skb)->len < 24 || MULTICAST_ADDR(hdr->addr1))) {
20606 + /* not fragmented */
20607 + goto out;
20608 + }
20609 + I802_DEBUG_INC(rx->local->rx_handlers_fragments);
20610 +
20611 + seq = WLAN_GET_SEQ_SEQ(sc);
20612 +
20613 + if (frag == 0) {
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. */
20621 + entry->ccmp = 1;
20622 + memcpy(entry->last_pn,
20623 + rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
20624 + CCMP_PN_LEN);
20625 + }
20626 + return TXRX_QUEUED;
20627 + }
20628 +
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.
20631 + */
20632 + entry = ieee80211_reassemble_find(rx->local, rx->fc, frag, seq,
20633 + rx->u.rx.queue, hdr);
20634 + if (!entry) {
20635 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20636 + return TXRX_DROP;
20637 + }
20638 +
20639 + /* Verify that MPDUs within one MSDU have sequential PN values.
20640 + * (IEEE 802.11i, 8.3.3.4.5) */
20641 + if (entry->ccmp) {
20642 + int i;
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--) {
20648 + pn[i]++;
20649 + if (pn[i])
20650 + break;
20651 + }
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;
20661 + }
20662 + memcpy(entry->last_pn, pn, CCMP_PN_LEN);
20663 + }
20664 +
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,
20671 + GFP_ATOMIC))) {
20672 + I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
20673 + return TXRX_DROP;
20674 + }
20675 + }
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);
20679 +
20680 + if (rx->fc & WLAN_FC_MOREFRAG) {
20681 + rx->skb = NULL;
20682 + return TXRX_QUEUED;
20683 + }
20684 +
20685 + /* Complete frame has been reassembled - process it now */
20686 + rx->skb = entry->skb;
20687 + rx->fragmented = 1;
20688 + entry->skb = NULL;
20689 +
20690 + out:
20691 + if (rx->sta)
20692 + rx->sta->rx_packets++;
20693 + if (MULTICAST_ADDR(hdr->addr1))
20694 + rx->local->dot11MulticastReceivedFrameCount++;
20695 +#ifdef IEEE80211_LEDS
20696 + else
20697 + ieee80211_rx_led(2, rx->dev);
20698 +#endif /* IEEE80211_LEDS */
20699 + return TXRX_CONTINUE;
20700 +}
20701 +
20702 +
20703 +static ieee80211_txrx_result
20704 +ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
20705 +{
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;
20710 + }
20711 +
20712 + return TXRX_CONTINUE;
20713 +}
20714 +
20715 +
20716 +static ieee80211_txrx_result
20717 +ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
20718 +{
20719 + struct ieee80211_hdr *hdr;
20720 + int always_sta_key;
20721 + hdr = (struct ieee80211_hdr *) rx->skb->data;
20722 +
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;
20731 + } else
20732 + rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
20733 + }
20734 +
20735 + if (rx->local->hw->rx_includes_fcs && rx->skb->len > FCS_LEN)
20736 + skb_trim(rx->skb, rx->skb->len - FCS_LEN);
20737 +
20738 + if (unlikely(rx->skb->len < 16)) {
20739 + I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
20740 + return TXRX_DROP;
20741 + }
20742 +
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;
20749 +
20750 + /* Drop disallowed frame classes based on STA auth/assoc state;
20751 + * IEEE 802.11, Chap 5.5.
20752 + *
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.
20757 + */
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;
20766 + }
20767 +
20768 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
20769 + ieee80211_msg_sta_not_assoc);
20770 + return TXRX_QUEUED;
20771 + }
20772 +
20773 + if (rx->local->conf.mode == IW_MODE_INFRA)
20774 + always_sta_key = 0;
20775 + else
20776 + always_sta_key = 1;
20777 +
20778 + if (rx->sta && rx->sta->key && always_sta_key) {
20779 + rx->key = rx->sta->key;
20780 + } else {
20781 + if (!rx->sdata) {
20782 + printk(KERN_DEBUG "%s: sdata was null in packet!!\n",
20783 + rx->dev->name);
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;
20791 + }
20792 + if (rx->sta && rx->sta->key)
20793 + rx->key = rx->sta->key;
20794 + else
20795 + rx->key = rx->sdata->default_key;
20796 +
20797 + if (rx->local->hw->wep_include_iv &&
20798 + rx->fc & WLAN_FC_ISWEP) {
20799 + int keyidx = ieee80211_wep_get_keyidx(rx->skb);
20800 +
20801 + if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
20802 + (rx->sta == NULL || rx->sta->key == NULL ||
20803 + keyidx > 0)) {
20804 + rx->key = rx->sdata->keys[keyidx];
20805 + }
20806 + if (!rx->key) {
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;
20818 + }
20819 + }
20820 + }
20821 +
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,
20828 + rx->sta);
20829 + }
20830 + }
20831 +
20832 + return TXRX_CONTINUE;
20833 +}
20834 +
20835 +
20836 +static ieee80211_txrx_result
20837 +ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
20838 +{
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;
20842 +
20843 + if (!sta)
20844 + return TXRX_CONTINUE;
20845 +
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;
20853 + } else
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.
20859 + */
20860 + sta->last_rx = jiffies;
20861 + }
20862 + sta->rx_fragments++;
20863 + sta->rx_bytes += rx->skb->len;
20864 + sta->last_rssi = rx->u.rx.status->ssi;
20865 +
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);
20874 + }
20875 +
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;
20886 + }
20887 +
20888 + return TXRX_CONTINUE;
20889 +}
20890 +
20891 +
20892 +static ieee80211_txrx_result
20893 +ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
20894 +{
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;
20899 +
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);
20904 + if (iv) {
20905 + rx->sta->wep_weak_iv_count++;
20906 + }
20907 + }
20908 +
20909 + return TXRX_CONTINUE;
20910 +}
20911 +
20912 +
20913 +static ieee80211_txrx_result
20914 +ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
20915 +{
20916 + /* If the device handles decryption totally, skip this test */
20917 + if (rx->local->hw->device_hides_wep)
20918 + return TXRX_CONTINUE;
20919 +
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;
20926 +
20927 + if (!rx->key) {
20928 + printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
20929 + rx->dev->name);
20930 + return TXRX_DROP;
20931 + }
20932 +
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;
20939 + }
20940 + } else if (rx->local->hw->wep_include_iv) {
20941 + ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
20942 + /* remove ICV */
20943 + skb_trim(rx->skb, rx->skb->len - 4);
20944 + }
20945 +
20946 + return TXRX_CONTINUE;
20947 +}
20948 +
20949 +
20950 +static ieee80211_txrx_result
20951 +ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
20952 +{
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;
20960 + }
20961 +
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;
20975 + }
20976 +
20977 + return TXRX_CONTINUE;
20978 +}
20979 +
20980 +
20981 +static ieee80211_txrx_result
20982 +ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
20983 +{
20984 + /* If the device handles decryption totally, skip this test */
20985 + if (rx->local->hw->device_hides_wep)
20986 + return TXRX_CONTINUE;
20987 +
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;
20998 + }
20999 + return TXRX_CONTINUE;
21000 +}
21001 +
21002 +
21003 +static ieee80211_txrx_result
21004 +ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
21005 +{
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);
21010 + } else {
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);
21014 + }
21015 + return TXRX_QUEUED;
21016 +}
21017 +
21018 +
21019 +static ieee80211_txrx_result
21020 +ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
21021 +{
21022 + struct ieee80211_local *local = rx->local;
21023 + struct sk_buff *skb = rx->skb;
21024 +
21025 + if (unlikely(local->sta_scanning != 0)) {
21026 + ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
21027 + return TXRX_QUEUED;
21028 + }
21029 +
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;
21035 + u16 fc;
21036 +
21037 + local->scan.rx_packets++;
21038 +
21039 + hdr = (struct ieee80211_hdr *) skb->data;
21040 + fc = le16_to_cpu(hdr->frame_control);
21041 +
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);
21050 +
21051 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21052 + ieee80211_msg_passive_scan);
21053 + return TXRX_QUEUED;
21054 + } else {
21055 + I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
21056 + return TXRX_DROP;
21057 + }
21058 + }
21059 +
21060 + return TXRX_CONTINUE;
21061 +}
21062 +
21063 +
21064 +static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
21065 +{
21066 + u16 fc;
21067 +
21068 + if (len < 24)
21069 + return NULL;
21070 +
21071 + fc = le16_to_cpu(hdr->frame_control);
21072 +
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):
21079 + return NULL;
21080 + case WLAN_FC_FROMDS:
21081 + return hdr->addr2;
21082 + case 0:
21083 + return hdr->addr3;
21084 + }
21085 + break;
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;
21091 + else
21092 + return NULL;
21093 + }
21094 +
21095 + return NULL;
21096 +}
21097 +
21098 +
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)
21102 +{
21103 + u8 *bssid;
21104 + struct net_device *dev;
21105 + u16 fc;
21106 +
21107 + bssid = ieee80211_get_bssid(hdr, len);
21108 + if (bssid) {
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,
21113 + sta_broadcast);
21114 + if (dev)
21115 + return dev;
21116 + }
21117 +
21118 + if (len >= 30) {
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);
21124 + if (dev)
21125 + return dev;
21126 + }
21127 + }
21128 +
21129 + /* Default to default device if nothing else matches */
21130 + return local->wdev;
21131 +}
21132 +
21133 +
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)
21138 +{
21139 + int keyidx, hdrlen;
21140 +
21141 + hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
21142 + if (rx->skb->len >= hdrlen + 4)
21143 + keyidx = rx->skb->data[hdrlen + 3] >> 6;
21144 + else
21145 + keyidx = -1;
21146 +
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);
21152 +
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));
21160 + goto ignore;
21161 + }
21162 +
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));
21167 + goto ignore;
21168 + }
21169 +
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. */
21177 + if (keyidx) {
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));
21181 + goto ignore;
21182 + }
21183 + }
21184 +
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));
21192 + goto ignore;
21193 + }
21194 +
21195 + do {
21196 + union iwreq_data wrqu;
21197 + char *buf = kmalloc(128, GFP_ATOMIC);
21198 + if (buf == NULL)
21199 + break;
21200 +
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);
21209 + kfree(buf);
21210 + } while (0);
21211 +
21212 + /* TODO: consider verifying the MIC error report with software
21213 + * implementation if we get too many spurious reports from the
21214 + * hardware. */
21215 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
21216 + ieee80211_msg_michael_mic_failure);
21217 + return;
21218 +
21219 + ignore:
21220 + dev_kfree_skb(rx->skb);
21221 + rx->skb = NULL;
21222 +}
21223 +
21224 +
21225 +static void ieee80211_sta_rx_broadcast(struct ieee80211_txrx_data *rx)
21226 +{
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;
21234 +
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);
21239 + return;
21240 + }
21241 + memcpy(bssid, _bssid, ETH_ALEN);
21242 +
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)))
21249 + continue;
21250 +
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);
21257 + }
21258 + continue;
21259 + }
21260 +
21261 + hdr = (struct ieee80211_hdr *) skb->data;
21262 + rx->skb = skb;
21263 + rx->dev = sdata->dev;
21264 + rx->sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
21265 +
21266 + res = TXRX_DROP;
21267 + for (handler = local->rx_handlers; *handler != NULL; handler++)
21268 + {
21269 + res = (*handler)(rx);
21270 + if (res == TXRX_DROP || res == TXRX_QUEUED)
21271 + break;
21272 + }
21273 +
21274 + if (res == TXRX_DROP || *handler == NULL)
21275 + dev_kfree_skb(skb);
21276 + }
21277 +
21278 + dev_kfree_skb(orig_skb);
21279 +}
21280 +
21281 +
21282 +/*
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.
21285 + */
21286 +void __ieee80211_rx(struct net_device *dev, struct sk_buff *skb,
21287 + struct ieee80211_rx_status *status)
21288 +{
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;
21295 + u16 type;
21296 + int sta_broadcast = 0;
21297 +
21298 + hdr = (struct ieee80211_hdr *) skb->data;
21299 + memset(&rx, 0, sizeof(rx));
21300 + rx.skb = skb;
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);
21307 + if (bssid &&
21308 + memcmp(bssid, local->bssid, ETH_ALEN) == 0)
21309 + sta = rx.sta =
21310 + ieee80211_ibss_add_sta(dev, skb, bssid,
21311 + hdr->addr2);
21312 + }
21313 + } else
21314 + sta = rx.sta = NULL;
21315 + if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS))
21316 + rx.dev = sta->dev;
21317 + else
21318 + rx.dev = ieee80211_get_rx_dev(local, hdr, skb->len,
21319 + &sta_broadcast);
21320 +
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);
21329 + goto end;
21330 + }
21331 +
21332 + if ((status->flag & RX_FLAG_MMIC_ERROR)) {
21333 + ieee80211_rx_michael_mic_report(dev, hdr, sta, &rx);
21334 + goto end;
21335 + }
21336 +
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);
21342 + if (sta)
21343 + sta->rx_dropped++;
21344 + }
21345 + if (res == TXRX_QUEUED)
21346 + I802_DEBUG_INC(local->rx_handlers_queued);
21347 + break;
21348 + }
21349 + }
21350 + skb = rx.skb; /* handlers are allowed to change skb */
21351 +
21352 + if (res == TXRX_DROP || *handler == NULL)
21353 + dev_kfree_skb(skb);
21354 +
21355 + end:
21356 + if (sta)
21357 + sta_info_release(local, sta);
21358 +}
21359 +
21360 +
21361 +static ieee80211_txrx_result
21362 +ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
21363 +{
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;
21368 +
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 */
21372 +
21373 + /* Estimate total channel use caused by this frame */
21374 +
21375 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21376 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21377 +
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;
21384 + else
21385 + hdrtime = CHAN_UTIL_HDR_LONG;
21386 +
21387 + load = hdrtime;
21388 + if (!MULTICAST_ADDR(hdr->addr1))
21389 + load += hdrtime;
21390 +
21391 + if (tx->u.tx.control->use_rts_cts)
21392 + load += 2 * hdrtime;
21393 + else if (tx->u.tx.control->use_cts_protect)
21394 + load += hdrtime;
21395 +
21396 + load += skb->len * tx->u.tx.rate->rate_inv;
21397 +
21398 + if (tx->u.tx.extra_frag) {
21399 + int i;
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;
21404 + }
21405 + }
21406 +
21407 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21408 + load >>= CHAN_UTIL_SHIFT;
21409 + local->channel_use_raw += load;
21410 + if (tx->sta)
21411 + tx->sta->channel_use_raw += load;
21412 + tx->sdata->channel_use_raw += load;
21413 +
21414 + return TXRX_CONTINUE;
21415 +}
21416 +
21417 +
21418 +static ieee80211_txrx_result
21419 +ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
21420 +{
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;
21426 + int i;
21427 +
21428 + /* Estimate total channel use caused by this frame */
21429 +
21430 + if (unlikely(local->num_curr_rates < 0))
21431 + return TXRX_CONTINUE;
21432 +
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];
21437 + break;
21438 + }
21439 + }
21440 +
21441 + /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
21442 + * 1 usec = 1/8 * (1080 / 10) = 13.5 */
21443 +
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;
21450 + else
21451 + hdrtime = CHAN_UTIL_HDR_LONG;
21452 +
21453 + load = hdrtime;
21454 + if (!MULTICAST_ADDR(hdr->addr1))
21455 + load += hdrtime;
21456 +
21457 + load += skb->len * rate->rate_inv;
21458 +
21459 + /* Divide channel_use by 8 to avoid wrapping around the counter */
21460 + load >>= CHAN_UTIL_SHIFT;
21461 + local->channel_use_raw += load;
21462 + if (rx->sta)
21463 + rx->sta->channel_use_raw += load;
21464 + rx->sdata->channel_use_raw += load;
21465 +
21466 + return TXRX_CONTINUE;
21467 +}
21468 +
21469 +
21470 +static void ieee80211_stat_refresh(unsigned long data)
21471 +{
21472 + struct ieee80211_local *local = (struct ieee80211_local *) data;
21473 + struct list_head *ptr, *n;
21474 +
21475 + if (!local->stat_time)
21476 + return;
21477 +
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;
21486 + }
21487 + spin_unlock_bh(&local->sta_lock);
21488 +
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;
21496 +
21497 + }
21498 +
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;
21503 +
21504 + local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
21505 + add_timer(&local->stat_timer);
21506 +}
21507 +
21508 +
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)
21513 +{
21514 + struct ieee80211_local *local = dev->priv;
21515 + struct ieee80211_rx_status *saved;
21516 +
21517 + skb->dev = dev;
21518 + saved = kmalloc(sizeof(struct ieee80211_rx_status), GFP_ATOMIC);
21519 + if (saved)
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);
21525 +}
21526 +
21527 +
21528 +void ieee80211_tx_status_irqsafe(struct net_device *dev, struct sk_buff *skb,
21529 + struct ieee80211_tx_status *status)
21530 +{
21531 + struct ieee80211_local *local = dev->priv;
21532 + struct ieee80211_tx_status *saved;
21533 + int tmp;
21534 +
21535 + skb->dev = dev;
21536 + saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
21537 + if (saved)
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));
21548 + kfree(saved);
21549 + dev_kfree_skb_irq(skb);
21550 + tmp--;
21551 + I802_DEBUG_INC(local->tx_status_drop);
21552 + }
21553 + tasklet_schedule(&local->tasklet);
21554 +}
21555 +
21556 +
21557 +static void ieee80211_tasklet_handler(unsigned long data)
21558 +{
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;
21563 +
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",
21573 + skb->dev->name);
21574 + dev_kfree_skb(skb);
21575 + return;
21576 + }
21577 + /* Clear skb->type in order to not confuse kernel
21578 + * netstack. */
21579 + skb->pkt_type = 0;
21580 + __ieee80211_rx(skb->dev, skb, rx_status);
21581 + kfree(rx_status);
21582 + break;
21583 + case ieee80211_tx_status_msg:
21584 + memcpy(&tx_status, skb->cb, sizeof(tx_status));
21585 + if (!tx_status) {
21586 + dev_kfree_skb(skb);
21587 + return;
21588 + }
21589 + skb->pkt_type = 0;
21590 + ieee80211_tx_status(skb->dev, skb, tx_status);
21591 + kfree(tx_status);
21592 + break;
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);
21597 + break;
21598 + }
21599 + }
21600 +}
21601 +
21602 +
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)
21611 +{
21612 + int hdrlen, iv_len, mic_len;
21613 + struct ieee80211_tx_packet_data *pkt_data;
21614 +
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;
21622 +
21623 + if (key == NULL)
21624 + return;
21625 +
21626 + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
21627 +
21628 + switch (key->alg) {
21629 + case ALG_WEP:
21630 + iv_len = WEP_IV_LEN;
21631 + mic_len = WEP_ICV_LEN;
21632 + break;
21633 + case ALG_TKIP:
21634 + iv_len = TKIP_IV_LEN;
21635 + mic_len = TKIP_ICV_LEN;
21636 + break;
21637 + case ALG_CCMP:
21638 + iv_len = CCMP_HDR_LEN;
21639 + mic_len = CCMP_MIC_LEN;
21640 + break;
21641 + default:
21642 + return;
21643 + }
21644 +
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);
21650 + }
21651 +
21652 + {
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);
21660 + }
21661 + }
21662 +}
21663 +
21664 +
21665 +void ieee80211_tx_status(struct net_device *dev, struct sk_buff *skb,
21666 + struct ieee80211_tx_status *status)
21667 +{
21668 + struct sk_buff *skb2;
21669 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
21670 + struct ieee80211_local *local = dev->priv;
21671 + u16 frag, type;
21672 + u32 msg_type;
21673 +
21674 + if (!status) {
21675 + printk(KERN_ERR
21676 + "%s: ieee80211_tx_status called with NULL status\n",
21677 + dev->name);
21678 + dev_kfree_skb(skb);
21679 + return;
21680 + }
21681 +
21682 + if (status->excessive_retries) {
21683 + struct sta_info *sta;
21684 + sta = sta_info_get(local, hdr->addr1);
21685 + if (sta) {
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.
21689 + */
21690 + status->excessive_retries = 0;
21691 + status->tx_filtered = 1;
21692 + }
21693 + sta_info_release(local, sta);
21694 + }
21695 + }
21696 +
21697 + if (status->tx_filtered) {
21698 + struct sta_info *sta;
21699 + sta = sta_info_get(local, hdr->addr1);
21700 + if (sta) {
21701 + sta->tx_filtered_count++;
21702 +
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
21706 + * time. */
21707 + sta->clear_dst_mask = 1;
21708 +
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,
21718 + skb,
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,
21726 + skb,
21727 + &status->control);
21728 + dev_queue_xmit(skb);
21729 + } else {
21730 + if (net_ratelimit()) {
21731 + printk(KERN_DEBUG "%s: dropped TX "
21732 + "filtered frame queue_len=%d "
21733 + "PS=%d @%lu\n",
21734 + dev->name,
21735 + skb_queue_len(
21736 + &sta->tx_filtered),
21737 + !!(sta->flags & WLAN_STA_PS),
21738 + jiffies);
21739 + }
21740 + dev_kfree_skb(skb);
21741 + }
21742 + sta_info_release(local, sta);
21743 + return;
21744 + }
21745 + } else {
21746 + rate_control_tx_status(dev, skb, status);
21747 + }
21748 +
21749 +#ifdef IEEE80211_LEDS
21750 + if (local->tx_led_counter && (local->tx_led_counter-- == 1)) {
21751 + ieee80211_tx_led(0, dev);
21752 + }
21753 +#endif /* IEEE80211_LEDS */
21754 + /* SNMP counters
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. */
21758 +
21759 + frag = WLAN_GET_SEQ_FRAG(le16_to_cpu(hdr->seq_ctrl));
21760 + type = WLAN_FC_GET_TYPE(le16_to_cpu(hdr->frame_control));
21761 +
21762 + if (status->ack) {
21763 + if (frag == 0) {
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++;
21771 + }
21772 +
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++;
21780 + } else {
21781 + if (frag == 0)
21782 + local->dot11FailedCount++;
21783 + }
21784 +
21785 + if (!status->control.req_tx_status) {
21786 + dev_kfree_skb(skb);
21787 + return;
21788 + }
21789 +
21790 + msg_type = status->ack ? ieee80211_msg_tx_callback_ack :
21791 + ieee80211_msg_tx_callback_fail;
21792 +
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);
21796 + if (!skb2) {
21797 + dev_kfree_skb(skb);
21798 + return;
21799 + }
21800 + dev_kfree_skb(skb);
21801 + skb = skb2;
21802 +
21803 + /* Send frame to hostapd */
21804 + ieee80211_rx_mgmt(dev, skb, NULL, msg_type);
21805 +}
21806 +
21807 +
21808 +/* TODO: implement register/unregister functions for adding TX/RX handlers
21809 + * into ordered list */
21810 +
21811 +static ieee80211_rx_handler ieee80211_rx_handlers[] =
21812 +{
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
21829 + */
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,
21835 + NULL
21836 +};
21837 +
21838 +static ieee80211_tx_handler ieee80211_tx_handlers[] =
21839 +{
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,
21852 + NULL
21853 +};
21854 +
21855 +
21856 +static void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
21857 +{
21858 + /* Default values for sub-interface parameters */
21859 + sdata->drop_unencrypted = 0;
21860 + sdata->eapol = 1;
21861 +}
21862 +
21863 +
21864 +static struct net_device *ieee80211_if_add(struct net_device *dev,
21865 + const char *name, int locked)
21866 +{
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;
21870 + int alloc_size;
21871 + int ret;
21872 + int i;
21873 +
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;
21877 +
21878 + wds_dev = (struct net_device *) kmalloc(alloc_size, GFP_KERNEL);
21879 + if (wds_dev == NULL)
21880 + return NULL;
21881 +
21882 + memset(wds_dev, 0, alloc_size);
21883 + wds_dev->priv = local;
21884 + ether_setup(wds_dev);
21885 + if (strlen(name) == 0) {
21886 + i = 0;
21887 + do {
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)
21891 + break;
21892 + dev_put(tmp_dev);
21893 + } while (i < 10000);
21894 + } else {
21895 + snprintf(wds_dev->name, IFNAMSIZ, "%s", name);
21896 + }
21897 +
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;
21913 +
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;
21923 + else {
21924 + printk(KERN_DEBUG "%s: could not set BSS pointer for new "
21925 + "interface %s\n", dev->name, wds_dev->name);
21926 + }
21927 + ieee80211_if_sdata_init(sdata);
21928 +
21929 + if (locked)
21930 + ret = register_netdevice(wds_dev);
21931 + else
21932 + ret = register_netdev(wds_dev);
21933 + if (ret) {
21934 + kfree(wds_dev);
21935 + return NULL;
21936 + }
21937 +
21938 + list_add(&sdata->list, &local->sub_if_list);
21939 +
21940 + return wds_dev;
21941 +}
21942 +
21943 +
21944 +int ieee80211_if_add_wds(struct net_device *dev, const char *name,
21945 + struct ieee80211_if_wds *wds, int locked)
21946 +{
21947 + struct net_device *wds_dev = NULL;
21948 + struct ieee80211_sub_if_data *sdata = NULL;
21949 +
21950 + if (strlen(name) != 0) {
21951 + wds_dev = dev_get_by_name(name);
21952 + if (wds_dev) {
21953 + dev_put(wds_dev);
21954 + return -EEXIST;
21955 + }
21956 + }
21957 +
21958 + wds_dev = ieee80211_if_add(dev, name, locked);
21959 + if (wds_dev == NULL)
21960 + return -ENOANO;
21961 +
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));
21965 +
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 */
21971 +
21972 + ieee80211_proc_init_virtual(wds_dev);
21973 +
21974 + return 0;
21975 +}
21976 +
21977 +
21978 +int ieee80211_if_update_wds(struct net_device *dev, char *name,
21979 + struct ieee80211_if_wds *wds, int locked)
21980 +{
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;
21986 +
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;
21991 + break;
21992 + }
21993 + }
21994 +
21995 + if (wds_dev == NULL || sdata->type != IEEE80211_SUB_IF_TYPE_WDS)
21996 + return -ENODEV;
21997 +
21998 + /* Remove STA entry for the old peer */
21999 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22000 + if (sta) {
22001 + sta_info_release(local, sta);
22002 + sta_info_free(local, sta, 0);
22003 + } else {
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));
22008 + }
22009 +
22010 + /* Update WDS link data */
22011 + memcpy(&sdata->u.wds, wds, sizeof(struct ieee80211_if_wds));
22012 +
22013 + return 0;
22014 +}
22015 +
22016 +
22017 +static void ieee80211_if_init(struct net_device *dev)
22018 +{
22019 + struct ieee80211_local *local = dev->priv;
22020 +
22021 + spin_lock_init(&local->sub_if_lock);
22022 + INIT_LIST_HEAD(&local->sub_if_list);
22023 +}
22024 +
22025 +
22026 +int ieee80211_if_add_vlan(struct net_device *dev, const char *name,
22027 + struct ieee80211_if_vlan *vlan, int locked)
22028 +{
22029 + struct net_device *vlan_dev = NULL;
22030 + struct ieee80211_sub_if_data *sdata = NULL;
22031 +
22032 + if (strlen(name) != 0) {
22033 + vlan_dev = dev_get_by_name(name);
22034 + if (vlan_dev) {
22035 + dev_put(vlan_dev);
22036 + return -EEXIST;
22037 + }
22038 + }
22039 +
22040 + vlan_dev = ieee80211_if_add(dev, name, locked);
22041 + if (vlan_dev == NULL)
22042 + return -ENOANO;
22043 +
22044 + sdata = IEEE80211_DEV_TO_SUB_IF(vlan_dev);
22045 + sdata->type = IEEE80211_SUB_IF_TYPE_VLAN;
22046 + ieee80211_proc_init_virtual(vlan_dev);
22047 + return 0;
22048 +}
22049 +
22050 +
22051 +static void ieee80211_if_ap_init(struct ieee80211_sub_if_data *sdata)
22052 +{
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;
22059 +}
22060 +
22061 +
22062 +int ieee80211_if_add_ap(struct net_device *dev, const char *name, u8 *bssid,
22063 + int locked)
22064 +{
22065 + struct ieee80211_local *local = dev->priv;
22066 + struct net_device *ap_dev = NULL;
22067 + struct ieee80211_sub_if_data *sdata = NULL;
22068 +
22069 + if (local->bss_dev_count >= local->conf.bss_count)
22070 + return -ENOBUFS;
22071 +
22072 + if (strlen(name) != 0) {
22073 + ap_dev = dev_get_by_name(name);
22074 + if (ap_dev) {
22075 + dev_put(ap_dev);
22076 + return -EEXIST;
22077 + }
22078 + }
22079 +
22080 + ap_dev = ieee80211_if_add(dev, name, locked);
22081 + if (ap_dev == NULL)
22082 + return -ENOANO;
22083 +
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);
22092 +
22093 + return 0;
22094 +}
22095 +
22096 +
22097 +static void ieee80211_addr_inc(u8 *addr)
22098 +{
22099 + int pos = 5;
22100 + while (pos >= 0) {
22101 + addr[pos]++;
22102 + if (addr[pos] != 0)
22103 + break;
22104 + pos--;
22105 + }
22106 +}
22107 +
22108 +
22109 +int ieee80211_if_add_sta(struct net_device *dev, const char *name, int locked)
22110 +{
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;
22115 + int i;
22116 +
22117 + if (local->sta_dev_count >= local->conf.bss_count)
22118 + return -ENOBUFS;
22119 +
22120 + if (strlen(name) != 0) {
22121 + sta_dev = dev_get_by_name(name);
22122 + if (sta_dev) {
22123 + dev_put(sta_dev);
22124 + return -EEXIST;
22125 + }
22126 + }
22127 +
22128 + sta_dev = ieee80211_if_add(dev, name, locked);
22129 + if (sta_dev == NULL)
22130 + return -ENOANO;
22131 +
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);
22136 +
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);
22144 + while (i > 0) {
22145 + ieee80211_addr_inc(sta_dev->dev_addr);
22146 + i--;
22147 + }
22148 + printk(KERN_DEBUG "%s: MAC address " MACSTR "\n",
22149 + sta_dev->name, MAC2STR(sta_dev->dev_addr));
22150 + break;
22151 + }
22152 + }
22153 + spin_unlock_bh(&local->sub_if_lock);
22154 +
22155 + init_timer(&ifsta->timer);
22156 + ifsta->timer.data = (unsigned long) sta_dev;
22157 + ifsta->timer.function = ieee80211_sta_timer;
22158 +
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;
22164 +
22165 + return 0;
22166 +}
22167 +
22168 +
22169 +static void ieee80211_if_del(struct ieee80211_local *local,
22170 + struct ieee80211_sub_if_data *sdata, int locked)
22171 +{
22172 + struct sta_info *sta;
22173 + u8 addr[ETH_ALEN];
22174 + int i, j;
22175 + struct list_head *ptr, *n;
22176 +
22177 + memset(addr, 0xff, ETH_ALEN);
22178 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
22179 + if (!sdata->keys[i])
22180 + continue;
22181 +#if 0
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);
22188 +#endif
22189 + kfree(sdata->keys[i]);
22190 + }
22191 +
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,
22199 + list);
22200 +
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);
22207 + }
22208 + }
22209 +
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 -
22221 + 1] = NULL;
22222 + } else
22223 + local->bss_devs[j] = NULL;
22224 + local->bss_dev_count--;
22225 + break;
22226 + }
22227 + }
22228 + spin_unlock_bh(&local->sub_if_lock);
22229 +
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);
22235 + }
22236 + }
22237 +
22238 + break;
22239 + case IEEE80211_SUB_IF_TYPE_WDS:
22240 + sta = sta_info_get(local, sdata->u.wds.remote_addr);
22241 + if (sta) {
22242 + sta_info_release(local, sta);
22243 + sta_info_free(local, sta, 0);
22244 + } else {
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 */
22249 + }
22250 + break;
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;
22264 + }
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--;
22269 + break;
22270 + }
22271 + }
22272 +
22273 + break;
22274 + }
22275 +
22276 + /* remove all STAs that are bound to this virtual interface */
22277 + sta_info_flush(local, sdata->dev);
22278 +
22279 + list_del(&sdata->list);
22280 + ieee80211_proc_deinit_virtual(sdata->dev);
22281 + if (locked)
22282 + unregister_netdevice(sdata->dev);
22283 + else
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);
22291 +}
22292 +
22293 +
22294 +static int ieee80211_if_remove(struct net_device *dev, const char *name,
22295 + int id, int locked)
22296 +{
22297 + struct ieee80211_local *local = dev->priv;
22298 + struct list_head *ptr, *n;
22299 +
22300 + /* Make sure not to touch sdata->master since it may
22301 + * have already been deleted, etc. */
22302 +
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);
22306 +
22307 + if (sdata->type == id && strcmp(name, sdata->dev->name) == 0) {
22308 + ieee80211_if_del(local, sdata, locked);
22309 + break;
22310 + }
22311 + }
22312 +
22313 + return 0;
22314 +}
22315 +
22316 +
22317 +int ieee80211_if_remove_wds(struct net_device *dev, const char *name,
22318 + int locked)
22319 +{
22320 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_WDS,
22321 + locked);
22322 +}
22323 +
22324 +
22325 +int ieee80211_if_remove_vlan(struct net_device *dev, const char *name,
22326 + int locked)
22327 +{
22328 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_VLAN,
22329 + locked);
22330 +}
22331 +
22332 +
22333 +int ieee80211_if_remove_ap(struct net_device *dev, const char *name,
22334 + int locked)
22335 +{
22336 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_AP,
22337 + locked);
22338 +}
22339 +
22340 +
22341 +int ieee80211_if_remove_sta(struct net_device *dev, const char *name,
22342 + int locked)
22343 +{
22344 + return ieee80211_if_remove(dev, name, IEEE80211_SUB_IF_TYPE_STA,
22345 + locked);
22346 +}
22347 +
22348 +
22349 +int ieee80211_if_flush(struct net_device *dev, int locked)
22350 +{
22351 + struct ieee80211_local *local = dev->priv;
22352 + struct list_head *ptr, *n;
22353 +
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);
22357 +
22358 + if (sdata->dev != local->mdev &&
22359 + sdata->dev != local->wdev &&
22360 + sdata->dev != local->apdev)
22361 + ieee80211_if_del(local, sdata, locked);
22362 + }
22363 +
22364 + return 0;
22365 +}
22366 +
22367 +
22368 +static void ieee80211_precalc_rates(struct ieee80211_hw *hw)
22369 +{
22370 + struct ieee80211_hw_modes *mode;
22371 + struct ieee80211_rate *rate;
22372 + int m, r;
22373 +
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;
22379 + }
22380 + }
22381 +}
22382 +
22383 +
22384 +struct net_device *ieee80211_alloc_hw(size_t priv_data_len,
22385 + void (*setup)(struct net_device *))
22386 +{
22387 + struct net_device *dev, *apdev, *mdev;
22388 + struct ieee80211_local *local;
22389 + struct ieee80211_sub_if_data *sdata;
22390 + int alloc_size;
22391 +
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.
22395 + *
22396 + * Sample memory map looks something like:
22397 + *
22398 + * 0000 *****************
22399 + * * net_dev *
22400 + * 015c *****************
22401 + * * sub_if *
22402 + * 017c *****************
22403 + * * local *
22404 + * 0b84 *****************
22405 + * * hw_priv *
22406 + * 1664 *****************
22407 + * * ap net_dev *
22408 + * 17c0 *****************
22409 + * * sub_if *
22410 + * *****************
22411 + * * master net_dev*
22412 + * *****************
22413 + * * sub_if *
22414 + * *****************
22415 + */
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 +
22424 + 4096;
22425 + mdev = (struct net_device *) kzalloc(alloc_size, GFP_KERNEL);
22426 + if (mdev == NULL)
22427 + return NULL;
22428 +
22429 + mdev->priv = (struct net_device *)
22430 + ((char *) mdev +
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;
22443 +
22444 + ether_setup(dev);
22445 + memcpy(dev->name, "wlan%d", 7);
22446 +
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;
22458 +
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;
22464 +
22465 + local->bridge_packets = 1;
22466 +
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)
22478 + goto fail;
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)
22483 + goto fail;
22484 + local->sta_devs[0] = NULL;
22485 +
22486 + local->scan.in_scan = 0;
22487 + local->hw_modes = (unsigned int) -1;
22488 +
22489 + init_timer(&local->scan.timer); /* clear it out */
22490 +
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);
22499 +
22500 + sta_info_init(local);
22501 +
22502 + ieee80211_if_init(dev);
22503 +
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);
22511 +
22512 + if (strlen(dev->name) + 2 >= sizeof(dev->name))
22513 + goto fail;
22514 +
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);
22529 +
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);
22536 +
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);
22550 +
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);
22557 +
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);
22563 +
22564 + if (setup)
22565 + setup(mdev);
22566 +
22567 + return mdev;
22568 +
22569 + fail:
22570 + ieee80211_free_hw(mdev);
22571 + return NULL;
22572 +}
22573 +
22574 +
22575 +int ieee80211_register_hw(struct net_device *dev, struct ieee80211_hw *hw)
22576 +{
22577 + struct ieee80211_local *local = dev->priv;
22578 + int result;
22579 +
22580 + if (!hw)
22581 + return -1;
22582 +
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);
22587 + return -1;
22588 + }
22589 +
22590 + result = ieee80211_dev_alloc_index(local);
22591 + if (result < 0)
22592 + return -1;
22593 +
22594 + local->class_dev.dev = dev->class_dev.dev;
22595 + result = ieee80211_register_sysfs(local);
22596 + if (result < 0)
22597 + goto fail_sysfs;
22598 +
22599 + local->conf.mode = IW_MODE_MASTER;
22600 + local->conf.beacon_int = 1000;
22601 +
22602 + ieee80211_update_hw(dev, hw); /* Don't care about the result. */
22603 +
22604 + sta_info_start(local);
22605 +
22606 + result = register_netdev(local->wdev);
22607 + if (result < 0)
22608 + goto fail_1st_dev;
22609 +
22610 + result = register_netdev(local->apdev);
22611 + if (result < 0)
22612 + goto fail_2nd_dev;
22613 +
22614 + if (hw->fraglist)
22615 + dev->features |= NETIF_F_FRAGLIST;
22616 + result = register_netdev(dev);
22617 + if (result < 0)
22618 + goto fail_3rd_dev;
22619 +
22620 + if (rate_control_initialize(local) < 0) {
22621 + printk(KERN_DEBUG "%s: Failed to initialize rate control "
22622 + "algorithm\n", dev->name);
22623 + goto fail_rate;
22624 + }
22625 +
22626 + /* TODO: add rtnl locking around device creation and qdisc install */
22627 + ieee80211_install_qdisc(dev);
22628 +
22629 + ieee80211_wep_init(local);
22630 + ieee80211_proc_init_interface(local);
22631 + return 0;
22632 +
22633 +fail_rate:
22634 + unregister_netdev(dev);
22635 +fail_3rd_dev:
22636 + unregister_netdev(local->apdev);
22637 +fail_2nd_dev:
22638 + unregister_netdev(local->wdev);
22639 +fail_1st_dev:
22640 + sta_info_stop(local);
22641 + ieee80211_unregister_sysfs(local);
22642 +fail_sysfs:
22643 + ieee80211_dev_free_index(local);
22644 + return result;
22645 +}
22646 +
22647 +int ieee80211_update_hw(struct net_device *dev, struct ieee80211_hw *hw)
22648 +{
22649 + struct ieee80211_local *local = dev->priv;
22650 +
22651 + local->hw = hw;
22652 +
22653 + /* Backwards compatibility for low-level drivers that do not set number
22654 + * of TX queues. */
22655 + if (hw->queues == 0)
22656 + hw->queues = 1;
22657 +
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;
22663 +
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;
22669 +
22670 + if (!hw->modes || !hw->modes->channels || !hw->modes->rates ||
22671 + !hw->modes->num_channels || !hw->modes->num_rates)
22672 + return -1;
22673 +
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);
22679 +
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. */
22684 +
22685 + return 0;
22686 +}
22687 +
22688 +
22689 +void ieee80211_unregister_hw(struct net_device *dev)
22690 +{
22691 + struct ieee80211_local *local = dev->priv;
22692 + struct list_head *ptr, *n;
22693 + int i;
22694 +
22695 + tasklet_disable(&local->tasklet);
22696 + /* TODO: skb_queue should be empty here, no need to do anything? */
22697 +
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);
22705 +
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);
22710 + }
22711 +
22712 + sta_info_stop(local);
22713 + ieee80211_unregister_sysfs(local);
22714 +
22715 + for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
22716 + if (local->fragments[i].skb)
22717 + dev_kfree_skb(local->fragments[i].skb);
22718 +
22719 + for (i = 0; i < NUM_IEEE80211_MODES; i++) {
22720 + kfree(local->supp_rates[i]);
22721 + kfree(local->basic_rates[i]);
22722 + }
22723 +
22724 + kfree(local->conf.ssid);
22725 + kfree(local->conf.generic_elem);
22726 +
22727 + ieee80211_proc_deinit_interface(local);
22728 +
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);
22734 +
22735 + rate_control_free(local);
22736 + ieee80211_dev_free_index(local);
22737 +}
22738 +
22739 +void ieee80211_free_hw(struct net_device *dev)
22740 +{
22741 + struct ieee80211_local *local = dev->priv;
22742 +
22743 + kfree(local->sta_devs);
22744 + kfree(local->bss_devs);
22745 + kfree(dev);
22746 +}
22747 +
22748 +
22749 +/* Perform netif operations on all configured interfaces */
22750 +int ieee80211_netif_oper(struct net_device *sdev, Netif_Oper op)
22751 +{
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;
22755 +
22756 + switch (op) {
22757 + case NETIF_ATTACH:
22758 + netif_device_attach(dev);
22759 + break;
22760 + case NETIF_DETACH:
22761 + netif_device_detach(dev);
22762 + break;
22763 + case NETIF_START:
22764 + netif_start_queue(dev);
22765 + break;
22766 + case NETIF_STOP:
22767 + break;
22768 + case NETIF_WAKE:
22769 + if (local->scan.in_scan == 0) {
22770 + netif_wake_queue(dev);
22771 +#if 1
22772 + if (/* FIX: 802.11 qdisc in use */ 1)
22773 + __netif_schedule(dev);
22774 +#endif
22775 + }
22776 + break;
22777 + case NETIF_IS_STOPPED:
22778 + if (netif_queue_stopped(dev))
22779 + return 1;
22780 + break;
22781 + case NETIF_UPDATE_TX_START:
22782 + dev->trans_start = jiffies;
22783 + break;
22784 + }
22785 +
22786 + return 0;
22787 +}
22788 +
22789 +
22790 +void * ieee80211_dev_hw_data(struct net_device *dev)
22791 +{
22792 + struct ieee80211_local *local = dev->priv;
22793 + return local->hw_priv;
22794 +}
22795 +
22796 +
22797 +void * ieee80211_dev_stats(struct net_device *dev)
22798 +{
22799 + struct ieee80211_sub_if_data *sdata;
22800 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
22801 + return &(sdata->stats);
22802 +}
22803 +
22804 +
22805 +int ieee80211_rate_control_register(struct rate_control_ops *ops)
22806 +{
22807 + struct rate_control_algs *alg;
22808 +
22809 + alg = kmalloc(sizeof(*alg), GFP_KERNEL);
22810 + if (alg == NULL) {
22811 + return -1;
22812 + }
22813 + memset(alg, 0, sizeof(*alg));
22814 + alg->next = ieee80211_rate_ctrl_algs;
22815 + alg->ops = ops;
22816 + ieee80211_rate_ctrl_algs = alg;
22817 +
22818 + return 0;
22819 +}
22820 +
22821 +
22822 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops)
22823 +{
22824 + struct rate_control_algs *alg, *prev;
22825 +
22826 + prev = NULL;
22827 + alg = ieee80211_rate_ctrl_algs;
22828 + while (alg) {
22829 + if (alg->ops == ops) {
22830 + if (prev)
22831 + prev->next = alg->next;
22832 + else
22833 + ieee80211_rate_ctrl_algs = alg->next;
22834 + kfree(alg);
22835 + break;
22836 + }
22837 + prev = alg;
22838 + alg = alg->next;
22839 + }
22840 +}
22841 +
22842 +
22843 +static int rate_control_initialize(struct ieee80211_local *local)
22844 +{
22845 + struct rate_control_algs *algs;
22846 +
22847 + if (!ieee80211_rate_ctrl_algs)
22848 + request_module("ieee80211_rate_control");
22849 +
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);
22857 + return 0;
22858 + }
22859 + }
22860 +
22861 + printk(KERN_WARNING "%s: Failed to select rate control algorithm\n",
22862 + local->wdev->name);
22863 + return -1;
22864 +}
22865 +
22866 +
22867 +static int __init ieee80211_init(void)
22868 +{
22869 + struct sk_buff *skb;
22870 + int ret;
22871 +
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));
22877 + return -EINVAL;
22878 + }
22879 + if ((ret = ieee80211_sysfs_init())) {
22880 + printk(KERN_WARNING "ieee80211_init: sysfs initialization "
22881 + "failed\n");
22882 + return ret;
22883 + }
22884 +
22885 + ieee80211_proc_init();
22886 + {
22887 + ret = ieee80211_wme_register();
22888 + if (ret) {
22889 + printk(KERN_DEBUG "ieee80211_init: failed to "
22890 + "initialize WME (err=%d)\n", ret);
22891 + ieee80211_proc_deinit();
22892 + return ret;
22893 + }
22894 + }
22895 +
22896 + return 0;
22897 +}
22898 +
22899 +
22900 +static void __exit ieee80211_exit(void)
22901 +{
22902 + ieee80211_wme_unregister();
22903 + ieee80211_proc_deinit();
22904 + ieee80211_sysfs_deinit();
22905 +}
22906 +
22907 +
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);
22931 +
22932 +module_init(ieee80211_init);
22933 +module_exit(ieee80211_exit);
22934 +
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
22940 @@ -0,0 +1,85 @@
22941 +/*
22942 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
22943 + *
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.
22947 + */
22948 +
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"
22956 +
22957 +struct ieee80211_dev_list {
22958 + struct list_head list;
22959 + int dev_index;
22960 + struct ieee80211_local *local;
22961 +};
22962 +
22963 +static LIST_HEAD(dev_list);
22964 +static DEFINE_SPINLOCK(dev_list_lock);
22965 +
22966 +
22967 +/* Caller must hold dev_list_lock */
22968 +static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
22969 +{
22970 + struct ieee80211_dev_list *dev_item;
22971 +
22972 + list_for_each_entry(dev_item, &dev_list, list) {
22973 + if (dev_item->dev_index == index)
22974 + return dev_item;
22975 + }
22976 + return NULL;
22977 +}
22978 +
22979 +int ieee80211_dev_alloc_index(struct ieee80211_local *local)
22980 +{
22981 + struct list_head *i;
22982 + struct ieee80211_dev_list *dev_item, *new;
22983 + int index = 0;
22984 +
22985 + new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
22986 + if (!new)
22987 + return -ENOMEM;
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)
22993 + break;
22994 + index++;
22995 + }
22996 + new->dev_index = index;
22997 + list_add_tail(&new->list, i);
22998 + spin_unlock(&dev_list_lock);
22999 + local->dev_index = index;
23000 + return index;
23001 +}
23002 +
23003 +void ieee80211_dev_free_index(struct ieee80211_local *local)
23004 +{
23005 + struct ieee80211_dev_list *dev_item;
23006 +
23007 + spin_lock(&dev_list_lock);
23008 + dev_item = __ieee80211_dev_find(local->dev_index);
23009 + if (dev_item)
23010 + list_del(&dev_item->list);
23011 + spin_unlock(&dev_list_lock);
23012 + if (dev_item)
23013 + kfree(dev_item);
23014 + local->dev_index = -1;
23015 +}
23016 +
23017 +struct ieee80211_local *ieee80211_dev_find(int index)
23018 +{
23019 + struct ieee80211_dev_list *dev_item;
23020 +
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;
23025 +}
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
23029 @@ -0,0 +1,596 @@
23030 +/*
23031 + * Copyright 2002-2005, Instant802 Networks, Inc.
23032 + * Copyright 2005, Devicescape Software, Inc.
23033 + *
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.
23037 + */
23038 +
23039 +#ifndef IEEE80211_I_H
23040 +#define IEEE80211_I_H
23041 +
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"
23051 +
23052 +/* ieee80211.o internal definitions, etc. These are not included into
23053 + * low-level drivers. */
23054 +
23055 +#ifndef ETH_P_PAE
23056 +#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
23057 +#endif /* ETH_P_PAE */
23058 +
23059 +#define IEEE80211_MAX_SSID_LEN 32
23060 +
23061 +struct ieee80211_local;
23062 +
23063 +#define BIT(x) (1 << (x))
23064 +
23065 +#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
23066 +
23067 +
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
23071 +
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
23076 +
23077 +
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"
23081 +
23082 +#define MULTICAST_ADDR(a) ((a)[0] & 0x01)
23083 +
23084 +
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
23090 +
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 */
23099 +};
23100 +
23101 +
23102 +struct ieee80211_sta_bss {
23103 + struct list_head list;
23104 + struct ieee80211_sta_bss *hnext;
23105 + atomic_t users;
23106 +
23107 + u8 bssid[ETH_ALEN];
23108 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23109 + size_t ssid_len;
23110 + u16 capability; /* host byte order */
23111 + int hw_mode;
23112 + int channel;
23113 + int freq;
23114 + int rssi;
23115 + u8 *wpa_ie;
23116 + size_t wpa_ie_len;
23117 + u8 *rsn_ie;
23118 + size_t rsn_ie_len;
23119 + u8 *wmm_ie;
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;
23124 + int beacon_int;
23125 + u64 timestamp;
23126 +
23127 + int probe_resp;
23128 + unsigned long last_update;
23129 +
23130 +};
23131 +
23132 +
23133 +typedef enum {
23134 + TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
23135 +} ieee80211_txrx_result;
23136 +
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 */
23146 + union {
23147 + struct {
23148 + struct ieee80211_tx_control *control;
23149 + int unicast:1;
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;
23160 +
23161 + /* Extra fragments (in addition to the first fragment
23162 + * in skb) */
23163 + int num_extra_frag;
23164 + struct sk_buff **extra_frag;
23165 + } tx;
23166 + struct {
23167 + struct ieee80211_rx_status *status;
23168 + int sent_ps_buffered;
23169 + int queue;
23170 + } rx;
23171 + } u;
23172 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23173 + int wpa_test;
23174 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
23175 +};
23176 +
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
23181 + */
23182 + int interval; /* time in seconds between scans */
23183 + int time; /* time in microseconds to scan for */
23184 + int channel; /* channel to be scanned */
23185 + int tries;
23186 +
23187 + int mode_idx;
23188 + int chan_idx;
23189 +
23190 + int freq;
23191 + int rx_packets;
23192 + int rx_beacon;
23193 + int txrx_count;
23194 +
23195 + struct timer_list timer;
23196 +
23197 + struct sk_buff *skb; /* skb to transmit before changing channels,
23198 + * maybe null for none */
23199 + struct ieee80211_tx_control tx_control;
23200 +
23201 + unsigned int num_scans;
23202 +};
23203 +
23204 +typedef ieee80211_txrx_result (*ieee80211_tx_handler)
23205 +(struct ieee80211_txrx_data *tx);
23206 +
23207 +typedef ieee80211_txrx_result (*ieee80211_rx_handler)
23208 +(struct ieee80211_txrx_data *rx);
23209 +
23210 +struct ieee80211_if_ap {
23211 + u8 *beacon_head, *beacon_tail;
23212 + int beacon_head_len, beacon_tail_len;
23213 +
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 */
23227 +};
23228 +
23229 +struct ieee80211_if_wds {
23230 + u8 remote_addr[ETH_ALEN];
23231 + struct sta_info *sta;
23232 +};
23233 +
23234 +struct ieee80211_if_vlan {
23235 + u8 id;
23236 +};
23237 +
23238 +struct ieee80211_if_sta {
23239 + enum {
23240 + IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
23241 + IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
23242 + IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
23243 + } state;
23244 + struct timer_list timer;
23245 + u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
23246 + u8 ssid[IEEE80211_MAX_SSID_LEN];
23247 + size_t ssid_len;
23248 + u16 aid;
23249 + u16 ap_capab, capab;
23250 + u8 *extra_ie; /* to be added to the end of AssocReq */
23251 + size_t extra_ie_len;
23252 +
23253 + /* The last AssocReq/Resp IEs */
23254 + u8 *assocreq_ies, *assocresp_ies;
23255 + size_t assocreq_ies_len, assocresp_ies_len;
23256 +
23257 + int auth_tries, assoc_tries;
23258 +
23259 + int ssid_set:1;
23260 + int bssid_set:1;
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;
23269 +
23270 + int key_mgmt;
23271 + unsigned long last_probe;
23272 +
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;
23279 +
23280 + unsigned long ibss_join_req;
23281 + struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
23282 + u32 supp_rates_bits;
23283 +
23284 + int wmm_last_param_set;
23285 +};
23286 +
23287 +
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
23293 +
23294 +struct ieee80211_sub_if_data {
23295 + struct list_head list;
23296 + unsigned int type;
23297 +
23298 + struct net_device *dev;
23299 + struct net_device *master;
23300 + struct ieee80211_local *local;
23301 +
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
23306 + * (default) */
23307 + int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
23308 + * port */
23309 +
23310 +#define NUM_DEFAULT_KEYS 4
23311 + struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
23312 + struct ieee80211_key *default_key;
23313 +
23314 + struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
23315 +
23316 + union {
23317 + struct ieee80211_if_ap ap;
23318 + struct ieee80211_if_wds wds;
23319 + struct ieee80211_if_vlan vlan;
23320 + struct ieee80211_if_sta sta;
23321 + } u;
23322 + int channel_use;
23323 + int channel_use_raw;
23324 +};
23325 +
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)))
23330 +
23331 +
23332 +struct ieee80211_local {
23333 + struct ieee80211_hw *hw;
23334 + void *hw_priv;
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) */
23338 + int open_count;
23339 + struct ieee80211_conf conf;
23340 +
23341 + int dev_index;
23342 + struct class_device class_dev;
23343 +
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;
23352 + enum {
23353 + ieee80211_rx_msg = 1,
23354 + ieee80211_tx_status_msg = 2
23355 + } ieee80211_msg_enum;
23356 +
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;
23364 +
23365 + /* Current rate table. This is a pointer to hw->modes structure. */
23366 + struct ieee80211_rate *curr_rates;
23367 + int num_curr_rates;
23368 +
23369 + void *rate_ctrl_priv;
23370 + struct rate_control_ops *rate_ctrl;
23371 +
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. */
23376 +
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];
23381 +
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 */
23388 +
23389 + u32 wep_iv;
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. */
23393 +
23394 + /* Fragment table for host-based reassembly */
23395 + struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
23396 + unsigned int fragment_next;
23397 +
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 */
23401 +
23402 + struct ieee80211_passive_scan scan;
23403 +
23404 +
23405 + ieee80211_rx_handler *rx_handlers;
23406 + ieee80211_tx_handler *tx_handlers;
23407 +
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)
23438 + int scan_flags;
23439 +
23440 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
23441 + u32 wpa_trigger;
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;
23455 +
23456 + int tx_led_counter;
23457 +
23458 + u32 channel_use;
23459 + u32 channel_use_raw;
23460 + u32 stat_time;
23461 + struct timer_list stat_timer;
23462 +
23463 + u8 bssid[ETH_ALEN]; /* BSSID for STA modes (Adhoc/Managed) */
23464 + struct timer_list rate_limit_timer;
23465 + u32 rate_limit;
23466 + u32 rate_limit_burst;
23467 + u32 rate_limit_bucket;
23468 + struct proc_dir_entry *proc, *proc_sta, *proc_iface;
23469 +
23470 + struct work_struct sta_proc_add;
23471 +
23472 + enum {
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;
23477 +
23478 + int rate_ctrl_num_up, rate_ctrl_num_down;
23479 +
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 */
23508 +
23509 +
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
23515 + */
23516 + int allow_broadcast_always; /* whether to allow TX of broadcast frames
23517 + * even when there are no associated STAs
23518 + */
23519 +
23520 + int wifi_wme_noack_test;
23521 + unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
23522 +
23523 + unsigned int hw_modes; /* bitfield of allowed hardware modes;
23524 + * (1 << MODE_*) */
23525 +};
23526 +
23527 +
23528 +/* ieee80211.c */
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,
23542 + int locked);
23543 +
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);
23550 +
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;
23554 +
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);
23559 +
23560 +/* ieee80211_scan.c */
23561 +void ieee80211_init_scan(struct net_device *dev);
23562 +void ieee80211_stop_scan(struct net_device *dev);
23563 +
23564 +
23565 +
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)
23583 +
23584 +
23585 +
23586 +/* ieee80211.c */
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,
23593 + u8 *bssid_mask);
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,
23610 + u8 *addr);
23611 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
23612 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
23613 +
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);
23618 +
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);
23624 +
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
23629 @@ -0,0 +1,3040 @@
23630 +/*
23631 + * Copyright 2002-2005, Instant802 Networks, Inc.
23632 + * Copyright 2005-2006, Devicescape Software, Inc.
23633 + *
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.
23637 + */
23638 +
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>
23651 +
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"
23657 +#include "wpa.h"
23658 +#include "aes_ccm.h"
23659 +
23660 +
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");
23664 +
23665 +/*
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
23669 + * module.
23670 + */
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");
23674 +
23675 +
23676 +static int ieee80211_ioctl_set_beacon(struct net_device *dev,
23677 + struct prism2_hostapd_param *param,
23678 + int param_len,
23679 + int flag)
23680 +{
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;
23685 + int len;
23686 +
23687 + len = ((char *) param->u.beacon.data - (char *) param) +
23688 + param->u.beacon.head_len + param->u.beacon.tail_len;
23689 +
23690 + if (param_len > len)
23691 + param_len = len;
23692 + else if (param_len != len)
23693 + return -EINVAL;
23694 +
23695 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
23696 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
23697 + return -EINVAL;
23698 + ap = &sdata->u.ap;
23699 +
23700 + switch (flag) {
23701 + case 0:
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;
23706 + break;
23707 + default:
23708 + printk(KERN_DEBUG "%s: unknown beacon flag %d\n",
23709 + dev->name, flag);
23710 + return -EINVAL;
23711 + }
23712 +
23713 + kfree(*b_head);
23714 + kfree(*b_tail);
23715 + *b_head = NULL;
23716 + *b_tail = NULL;
23717 +
23718 + *b_head_len = param->u.beacon.head_len;
23719 + *b_tail_len = param->u.beacon.tail_len;
23720 +
23721 + *b_head = kmalloc(*b_head_len, GFP_KERNEL);
23722 + if (*b_head)
23723 + memcpy(*b_head, param->u.beacon.data, *b_head_len);
23724 + else {
23725 + printk(KERN_DEBUG "%s: failed to allocate beacon_head\n",
23726 + dev->name);
23727 + return -ENOMEM;
23728 + }
23729 +
23730 + if (*b_tail_len > 0) {
23731 + *b_tail = kmalloc(*b_tail_len, GFP_KERNEL);
23732 + if (*b_tail)
23733 + memcpy(*b_tail, param->u.beacon.data + (*b_head_len),
23734 + (*b_tail_len));
23735 + else {
23736 + printk(KERN_DEBUG "%s: failed to allocate "
23737 + "beacon_tail\n", dev->name);
23738 + return -ENOMEM;
23739 + }
23740 + }
23741 +
23742 + return 0;
23743 +}
23744 +
23745 +
23746 +static int ieee80211_ioctl_get_hw_features(struct net_device *dev,
23747 + struct prism2_hostapd_param *param,
23748 + int param_len)
23749 +{
23750 + struct ieee80211_local *local = dev->priv;
23751 + u8 *pos = param->u.hw_features.data;
23752 + int left = param_len - (pos - (u8 *) param);
23753 + int mode, i;
23754 + struct hostapd_ioctl_hw_modes_hdr *hdr;
23755 + struct ieee80211_rate_data *rate;
23756 + struct ieee80211_channel_data *chan;
23757 +
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;
23761 +
23762 + param->u.hw_features.num_modes = local->hw->num_modes;
23763 + for (mode = 0; mode < local->hw->num_modes; mode++) {
23764 + int clen, rlen;
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)
23769 + return -E2BIG;
23770 + left -= sizeof(*hdr) + clen + rlen;
23771 +
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;
23776 +
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;
23783 + }
23784 + pos += clen;
23785 +
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;
23790 + }
23791 + pos += rlen;
23792 + }
23793 +
23794 + return 0;
23795 +}
23796 +
23797 +
23798 +static int ieee80211_ioctl_scan(struct net_device *dev,
23799 + struct prism2_hostapd_param *param)
23800 +{
23801 + struct ieee80211_local *local = dev->priv;
23802 +
23803 + if (local->hw->passive_scan == NULL)
23804 + return -EOPNOTSUPP;
23805 +
23806 + if ((param->u.scan.now == 1) && (local->scan.in_scan == 1))
23807 + return -EBUSY;
23808 +
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);
23820 + }
23821 +
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;
23827 + else {
23828 + param->u.scan.last_rx = local->scan.rx_packets;
23829 + local->scan.rx_packets = -1;
23830 + }
23831 + param->u.scan.channel = local->hw->modes[local->scan.mode_idx].
23832 + channels[local->scan.chan_idx].chan;
23833 +
23834 + return 0;
23835 +}
23836 +
23837 +
23838 +static int ieee80211_ioctl_flush(struct net_device *dev,
23839 + struct prism2_hostapd_param *param)
23840 +{
23841 + struct ieee80211_local *local = dev->priv;
23842 + sta_info_flush(local, NULL);
23843 + return 0;
23844 +}
23845 +
23846 +
23847 +static int ieee80211_ioctl_add_sta(struct net_device *dev,
23848 + struct prism2_hostapd_param *param)
23849 +{
23850 + struct ieee80211_local *local = dev->priv;
23851 + struct sta_info *sta;
23852 + u32 rates;
23853 + int i, j;
23854 + struct ieee80211_sub_if_data *sdata;
23855 + int add_key_entry = 1;
23856 +
23857 + sta = sta_info_get(local, param->sta_addr);
23858 +
23859 + if (sta == NULL) {
23860 + sta = sta_info_add(local, dev, param->sta_addr);
23861 + if (sta == NULL)
23862 + return -ENOMEM;
23863 + }
23864 +
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);
23869 + }
23870 +
23871 + /* TODO
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
23875 + */
23876 + sta->dev = dev;
23877 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
23878 +
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)
23882 + sta->aid = 0;
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;
23887 +
23888 + rates = 0;
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)
23893 + rate *= 2;
23894 + for (j = 0; j < local->num_curr_rates; j++) {
23895 + if (local->curr_rates[j].rate == rate)
23896 + rates |= BIT(j);
23897 + }
23898 +
23899 + }
23900 + sta->supp_rates = rates;
23901 +
23902 + rate_control_rate_init(local, sta);
23903 +
23904 + if (param->u.add_sta.wds_flags & 0x01)
23905 + sta->flags |= WLAN_STA_WDS;
23906 + else
23907 + sta->flags &= ~WLAN_STA_WDS;
23908 +
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,
23919 + sta->aid)) {
23920 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
23921 + } else {
23922 + sta->key_idx_compression = conf.hw_key_idx;
23923 + }
23924 + }
23925 +
23926 + sta_info_release(local, sta);
23927 +
23928 + return 0;
23929 +}
23930 +
23931 +
23932 +static int ieee80211_ioctl_remove_sta(struct net_device *dev,
23933 + struct prism2_hostapd_param *param)
23934 +{
23935 + struct ieee80211_local *local = dev->priv;
23936 + struct sta_info *sta;
23937 +
23938 + sta = sta_info_get(local, param->sta_addr);
23939 + if (sta) {
23940 + sta_info_release(local, sta);
23941 + sta_info_free(local, sta, 1);
23942 + }
23943 +
23944 + return sta ? 0 : -ENOENT;
23945 +}
23946 +
23947 +
23948 +static int ieee80211_ioctl_get_dot11counterstable(struct net_device *dev,
23949 + struct prism2_hostapd_param *param)
23950 +{
23951 + struct ieee80211_local *local = dev->priv;
23952 + struct ieee80211_low_level_stats stats;
23953 +
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;
23975 +
23976 + return 0;
23977 +}
23978 +
23979 +
23980 +static int ieee80211_ioctl_get_info_sta(struct net_device *dev,
23981 + struct prism2_hostapd_param *param)
23982 +{
23983 + struct ieee80211_local *local = dev->priv;
23984 + struct sta_info *sta;
23985 +
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;
23991 +
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;
23999 + return 0;
24000 + }
24001 +
24002 + sta = sta_info_get(local, param->sta_addr);
24003 +
24004 + if (!sta)
24005 + return -ENOENT;
24006 +
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];
24024 +
24025 + sta_info_release(local, sta);
24026 +
24027 + return 0;
24028 +}
24029 +
24030 +
24031 +static int ieee80211_ioctl_set_flags_sta(struct net_device *dev,
24032 + struct prism2_hostapd_param *param)
24033 +{
24034 + struct ieee80211_local *local = dev->priv;
24035 + struct sta_info *sta;
24036 +
24037 + sta = sta_info_get(local, param->sta_addr);
24038 + if (sta) {
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);
24054 + }
24055 +
24056 + return sta ? 0 : -ENOENT;
24057 +}
24058 +
24059 +
24060 +int ieee80211_set_hw_encryption(struct net_device *dev,
24061 + struct sta_info *sta, u8 addr[ETH_ALEN],
24062 + struct ieee80211_key *key)
24063 +{
24064 + struct ieee80211_key_conf *keyconf = NULL;
24065 + struct ieee80211_local *local = dev->priv;
24066 + int rc = 0;
24067 +
24068 + /* default to sw encryption; this will be cleared by low-level
24069 + * driver if the hw supports requested encryption */
24070 + if (key)
24071 + key->force_sw_encrypt = 1;
24072 +
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;
24081 + } else {
24082 + key->force_sw_encrypt =
24083 + keyconf->force_sw_encrypt;
24084 + key->hw_key_idx =
24085 + keyconf->hw_key_idx;
24086 +
24087 + }
24088 + }
24089 + kfree(keyconf);
24090 +
24091 + return rc;
24092 +}
24093 +
24094 +
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)
24098 +{
24099 + struct ieee80211_local *local = dev->priv;
24100 + int ret = 0;
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;
24106 +
24107 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24108 +
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) {
24112 + sta = NULL;
24113 + if (idx >= NUM_DEFAULT_KEYS) {
24114 + printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
24115 + dev->name, idx);
24116 + return -EINVAL;
24117 + }
24118 + key = &sdata->keys[idx];
24119 +
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 */)
24133 + try_hwaccel = 0;
24134 + } else
24135 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP ||
24136 + dev != local->wdev)
24137 + try_hwaccel = 0;
24138 + } else {
24139 + set_tx_key = 0;
24140 + if (idx != 0) {
24141 + printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
24142 + "individual key\n", dev->name);
24143 + return -EINVAL;
24144 + }
24145 +
24146 + sta = sta_info_get(local, sta_addr);
24147 + if (sta == NULL) {
24148 + if (err)
24149 + *err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24150 +#ifdef CONFIG_D80211_VERBOSE_DEBUG
24151 + printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
24152 + MACSTR "\n",
24153 + dev->name, MAC2STR(sta_addr));
24154 +#endif /* CONFIG_D80211_VERBOSE_DEBUG */
24155 +
24156 + return -ENOENT;
24157 + }
24158 +
24159 + key = &sta->key;
24160 + }
24161 +
24162 + /* FIX:
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
24166 + * these frames.
24167 + *
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).
24171 + */
24172 + if (!sta && alg == ALG_WEP && !local->default_wep_only &&
24173 + local->conf.mode != IW_MODE_ADHOC &&
24174 + local->conf.mode != IW_MODE_INFRA) {
24175 + try_hwaccel = 0;
24176 + }
24177 +
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. */
24182 + try_hwaccel = 1;
24183 + }
24184 +
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.
24188 + */
24189 + try_hwaccel = 0;
24190 + }
24191 + else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
24192 + sta = sta_info_get(local, sdata->u.sta.bssid);
24193 + if (sta) {
24194 + if (sta->flags & WLAN_STA_WME) {
24195 + try_hwaccel = 0;
24196 + }
24197 + sta_info_release(local, sta);
24198 + sta = NULL;
24199 + }
24200 + }
24201 + }
24202 +
24203 + if (alg == ALG_NONE) {
24204 + keyconf = NULL;
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)) {
24209 + if (err)
24210 + *err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
24211 + printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
24212 + " failed\n", dev->name);
24213 + ret = -EINVAL;
24214 + }
24215 + kfree(keyconf);
24216 +
24217 + if (sdata->default_key == *key)
24218 + sdata->default_key = NULL;
24219 + kfree(*key);
24220 + *key = NULL;
24221 + } else {
24222 + if (*key == NULL || (*key)->keylen < key_len) {
24223 + kfree(*key);
24224 + *key = kmalloc(sizeof(struct ieee80211_key) +
24225 + key_len, GFP_ATOMIC);
24226 + if (*key == NULL) {
24227 + ret = -ENOMEM;
24228 + goto done;
24229 + }
24230 + }
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;
24236 +
24237 + (*key)->alg = alg;
24238 + (*key)->keyidx = idx;
24239 + (*key)->keylen = key_len;
24240 + memcpy((*key)->key, _key, key_len);
24241 + if (set_tx_key)
24242 + (*key)->default_tx_key = 1;
24243 +
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
24247 + * packet. */
24248 + ieee80211_aes_key_setup_encrypt(
24249 + (*key)->u.ccmp.aes_state, (*key)->key);
24250 + }
24251 +
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,
24255 + *key);
24256 + if (err)
24257 + *err = e;
24258 + }
24259 + }
24260 +
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);
24267 + }
24268 +
24269 + done:
24270 + if (sta)
24271 + sta_info_release(local, sta);
24272 +
24273 + return ret;
24274 +}
24275 +
24276 +
24277 +static int ieee80211_ioctl_set_encryption(struct net_device *dev,
24278 + struct prism2_hostapd_param *param,
24279 + int param_len)
24280 +{
24281 + int alg;
24282 +
24283 + param->u.crypt.err = 0;
24284 + param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
24285 +
24286 + if (param_len <
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",
24290 + dev->name);
24291 + return -EINVAL;
24292 + }
24293 +
24294 + if (strcmp(param->u.crypt.alg, "none") == 0)
24295 + alg = ALG_NONE;
24296 + else if (strcmp(param->u.crypt.alg, "WEP") == 0)
24297 + alg = ALG_WEP;
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);
24303 + return -EINVAL;
24304 + }
24305 + alg = ALG_TKIP;
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);
24311 + return -EINVAL;
24312 + }
24313 + alg = ALG_CCMP;
24314 + } else {
24315 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
24316 + printk(KERN_DEBUG "%s: set_encrypt - unknown alg\n",
24317 + dev->name);
24318 + return -EINVAL;
24319 + }
24320 +
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 + &param->u.crypt.err, param->u.crypt.key,
24326 + param->u.crypt.key_len);
24327 +}
24328 +
24329 +
24330 +static int ieee80211_ioctl_get_encryption(struct net_device *dev,
24331 + struct prism2_hostapd_param *param,
24332 + int param_len)
24333 +{
24334 + struct ieee80211_local *local = dev->priv;
24335 + int ret = 0;
24336 + struct sta_info *sta;
24337 + struct ieee80211_key **key;
24338 + int max_key_len;
24339 + struct ieee80211_sub_if_data *sdata;
24340 + u8 *pos;
24341 +
24342 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24343 +
24344 + param->u.crypt.err = 0;
24345 +
24346 + max_key_len = param_len -
24347 + (int) ((char *) param->u.crypt.key - (char *) param);
24348 + if (max_key_len < 0)
24349 + return -EINVAL;
24350 +
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) {
24354 + sta = NULL;
24355 + if (param->u.crypt.idx > NUM_DEFAULT_KEYS) {
24356 + param->u.crypt.idx = sdata->default_key ?
24357 + sdata->default_key->keyidx : 0;
24358 + return 0;
24359 + } else
24360 + key = &sdata->keys[param->u.crypt.idx];
24361 + } else {
24362 + sta = sta_info_get(local, param->sta_addr);
24363 + if (sta == NULL) {
24364 + param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
24365 + return -EINVAL;
24366 + }
24367 +
24368 + key = &sta->key;
24369 + }
24370 +
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;
24376 + } else {
24377 + switch ((*key)->alg) {
24378 + case ALG_WEP:
24379 + memcpy(param->u.crypt.alg, "WEP", 4);
24380 + break;
24381 + case ALG_TKIP:
24382 + {
24383 + u32 iv32;
24384 + u16 iv16;
24385 +
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,
24390 + param->sta_addr,
24391 + (*key)->keyidx,
24392 + IEEE80211_SEQ_COUNTER_TX,
24393 + &iv32,
24394 + &iv16)) {
24395 + /* Error getting value from device */
24396 + return -EIO;
24397 + }
24398 + } else {
24399 + /* Get it from our own local data */
24400 + iv32 = (*key)->u.tkip.iv32;
24401 + iv16 = (*key)->u.tkip.iv16;
24402 + }
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;
24410 + break;
24411 + }
24412 + case ALG_CCMP:
24413 + {
24414 + u8 *pn;
24415 + memcpy(param->u.crypt.alg, "CCMP", 5);
24416 + pos = param->u.crypt.seq_counter;
24417 + pn = (*key)->u.ccmp.tx_pn;
24418 + *pos++ = pn[5];
24419 + *pos++ = pn[4];
24420 + *pos++ = pn[3];
24421 + *pos++ = pn[2];
24422 + *pos++ = pn[1];
24423 + *pos++ = pn[0];
24424 + break;
24425 + }
24426 + default:
24427 + memcpy(param->u.crypt.alg, "unknown", 8);
24428 + break;
24429 + }
24430 +
24431 + if (max_key_len < (*key)->keylen)
24432 + ret = -E2BIG;
24433 + else {
24434 + param->u.crypt.key_len = (*key)->keylen;
24435 + memcpy(param->u.crypt.key, (*key)->key,
24436 + (*key)->keylen);
24437 + }
24438 + }
24439 +
24440 + if (sta)
24441 + sta_info_release(local, sta);
24442 +
24443 + return ret;
24444 +}
24445 +
24446 +
24447 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
24448 +static int ieee80211_ioctl_wpa_trigger(struct net_device *dev,
24449 + struct prism2_hostapd_param *param)
24450 +{
24451 + struct ieee80211_local *local = dev->priv;
24452 + struct sta_info *sta;
24453 +
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;
24458 + return 0;
24459 + }
24460 +
24461 + sta = sta_info_get(local, param->sta_addr);
24462 + if (sta == NULL) {
24463 + printk(KERN_DEBUG "%s: wpa_trigger - unknown addr\n",
24464 + dev->name);
24465 + return -EINVAL;
24466 + }
24467 +
24468 + sta->wpa_trigger = param->u.wpa_trigger.trigger;
24469 +
24470 + sta_info_release(local, sta);
24471 + return 0;
24472 +}
24473 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
24474 +
24475 +
24476 +static int ieee80211_ioctl_set_rate_sets(struct net_device *dev,
24477 + struct prism2_hostapd_param *param,
24478 + int param_len)
24479 +{
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;
24484 +
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;
24488 +
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);
24493 + return -EINVAL;
24494 + }
24495 +
24496 + supp = (int *) kmalloc((num_supp + 1) * sizeof(int), GFP_KERNEL);
24497 + basic = (int *) kmalloc((num_basic + 1) * sizeof(int), GFP_KERNEL);
24498 +
24499 + if (!supp || !basic) {
24500 + kfree(supp);
24501 + kfree(basic);
24502 + return -ENOMEM;
24503 + }
24504 +
24505 + for (i = 0; i < num_supp; i++)
24506 + supp[i] = *pos++;
24507 + supp[i] = -1;
24508 +
24509 + for (i = 0; i < num_basic; i++)
24510 + basic[i] = *pos++;
24511 + basic[i] = -1;
24512 +
24513 + if (num_supp == 0) {
24514 + kfree(supp);
24515 + supp = NULL;
24516 + }
24517 +
24518 + if (num_basic == 0) {
24519 + kfree(basic);
24520 + basic = NULL;
24521 + }
24522 +
24523 + prev = local->supp_rates[mode];
24524 + local->supp_rates[mode] = supp;
24525 + kfree(prev);
24526 +
24527 + prev = local->basic_rates[mode];
24528 + local->basic_rates[mode] = basic;
24529 + kfree(prev);
24530 +
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
24534 + */
24535 + ieee80211_prepare_rates(dev);
24536 + }
24537 +
24538 + return 0;
24539 +}
24540 +
24541 +
24542 +static int ieee80211_ioctl_add_if(struct net_device *dev,
24543 + struct prism2_hostapd_param *param,
24544 + int param_len)
24545 +{
24546 + u8 *pos = param->u.if_info.data;
24547 + int left = param_len - ((u8 *) pos - (u8 *) param);
24548 +
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;
24553 +
24554 + if (left < sizeof(struct ieee80211_if_wds))
24555 + return -EPROTO;
24556 +
24557 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24558 +
24559 + return ieee80211_if_add_wds(dev, param->u.if_info.name,
24560 + &iwds, 1);
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;
24564 +
24565 + if (left < sizeof(struct hostapd_if_vlan))
24566 + return -EPROTO;
24567 +
24568 + ivlan.id = vlan->id;
24569 +
24570 + return ieee80211_if_add_vlan(dev, param->u.if_info.name,
24571 + &ivlan, 1);
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;
24575 +
24576 + if (left < sizeof(struct hostapd_if_bss))
24577 + return -EPROTO;
24578 +
24579 + return ieee80211_if_add_ap(dev, param->u.if_info.name,
24580 + bss->bssid, 1);
24581 + } else if (param->u.if_info.type == HOSTAP_IF_STA) {
24582 +#if 0
24583 + struct hostapd_if_sta *sta =
24584 + (struct hostapd_if_sta *) param->u.if_info.data;
24585 +#endif
24586 +
24587 + if (left < sizeof(struct hostapd_if_sta))
24588 + return -EPROTO;
24589 +
24590 + return ieee80211_if_add_sta(dev, param->u.if_info.name, 1);
24591 + } else
24592 + return -EINVAL;
24593 +
24594 + return 0;
24595 +}
24596 +
24597 +
24598 +static int ieee80211_ioctl_remove_if(struct net_device *dev,
24599 + struct prism2_hostapd_param *param)
24600 +{
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);
24609 + } else {
24610 + return -EINVAL;
24611 + }
24612 +}
24613 +
24614 +
24615 +static int ieee80211_ioctl_update_if(struct net_device *dev,
24616 + struct prism2_hostapd_param *param,
24617 + int param_len)
24618 +{
24619 + u8 *pos = param->u.if_info.data;
24620 + int left = param_len - ((u8 *) pos - (u8 *) param);
24621 +
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;
24626 +
24627 + if (left < sizeof(struct ieee80211_if_wds))
24628 + return -EPROTO;
24629 +
24630 + memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
24631 +
24632 + return ieee80211_if_update_wds(dev, param->u.if_info.name,
24633 + &iwds, 1);
24634 + } else {
24635 + return -EOPNOTSUPP;
24636 + }
24637 +}
24638 +
24639 +
24640 +static int ieee80211_ioctl_flush_ifs(struct net_device *dev,
24641 + struct prism2_hostapd_param *param)
24642 +{
24643 + return ieee80211_if_flush(dev, 1);
24644 +}
24645 +
24646 +
24647 +static int ieee80211_ioctl_scan_req(struct net_device *dev,
24648 + struct prism2_hostapd_param *param,
24649 + int param_len)
24650 +{
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;
24654 +
24655 + if (left < len || len > IEEE80211_MAX_SSID_LEN)
24656 + return -EINVAL;
24657 +
24658 + return ieee80211_sta_req_scan(dev, pos, len);
24659 +}
24660 +
24661 +
24662 +static int ieee80211_ioctl_sta_get_state(struct net_device *dev,
24663 + struct prism2_hostapd_param *param)
24664 +{
24665 + struct ieee80211_sub_if_data *sdata;
24666 +
24667 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24668 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24669 + return -EINVAL;
24670 + param->u.sta_get_state.state = sdata->u.sta.state;
24671 + return 0;
24672 +}
24673 +
24674 +
24675 +static int ieee80211_ioctl_mlme(struct net_device *dev,
24676 + struct prism2_hostapd_param *param)
24677 +{
24678 + struct ieee80211_sub_if_data *sdata;
24679 +
24680 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
24681 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
24682 + return -EINVAL;
24683 + switch (param->u.mlme.cmd) {
24684 + case MLME_STA_DEAUTH:
24685 + ieee80211_sta_deauthenticate(dev, param->u.mlme.reason_code);
24686 + break;
24687 + case MLME_STA_DISASSOC:
24688 + ieee80211_sta_disassociate(dev, param->u.mlme.reason_code);
24689 + break;
24690 + }
24691 + return 0;
24692 +}
24693 +
24694 +
24695 +static int ieee80211_ioctl_get_load_stats(struct net_device *dev,
24696 + struct prism2_hostapd_param *param)
24697 +{
24698 + struct ieee80211_local *local = dev->priv;
24699 +
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 */
24703 +
24704 + return 0;
24705 +}
24706 +
24707 +
24708 +static int ieee80211_ioctl_set_sta_vlan(struct net_device *dev,
24709 + struct prism2_hostapd_param *param)
24710 +{
24711 + struct ieee80211_local *local = dev->priv;
24712 + struct sta_info *sta;
24713 +
24714 + sta = sta_info_get(local, param->sta_addr);
24715 + if (sta) {
24716 + struct net_device *new_vlan_dev;
24717 + new_vlan_dev =
24718 + dev_get_by_name(param->u.set_sta_vlan.vlan_name);
24719 + if (new_vlan_dev) {
24720 +#if 0
24721 + printk("%s: Station " MACSTR " moved to vlan: %s\n",
24722 + dev->name, MAC2STR(param->sta_addr),
24723 + new_vlan_dev->name);
24724 +#endif
24725 + sta->dev = new_vlan_dev;
24726 + sta->vlan_id = param->u.set_sta_vlan.vlan_id;
24727 + dev_put(new_vlan_dev);
24728 + }
24729 + sta_info_release(local, sta);
24730 + }
24731 +
24732 + return sta ? 0 : -ENOENT;
24733 +}
24734 +
24735 +
24736 +static int ieee80211_set_gen_ie(struct net_device *dev, u8 *ie, size_t len)
24737 +{
24738 + struct ieee80211_local *local = dev->priv;
24739 + struct ieee80211_sub_if_data *sdata;
24740 +
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);
24744 +
24745 + kfree(local->conf.generic_elem);
24746 + local->conf.generic_elem = kmalloc(len, GFP_KERNEL);
24747 + if (local->conf.generic_elem == NULL)
24748 + return -ENOMEM;
24749 + memcpy(local->conf.generic_elem, ie, len);
24750 + local->conf.generic_elem_len = len;
24751 +
24752 + return ieee80211_hw_config(dev);
24753 +}
24754 +
24755 +
24756 +static int
24757 +ieee80211_ioctl_set_generic_info_elem(struct net_device *dev,
24758 + struct prism2_hostapd_param *param,
24759 + int param_len)
24760 +{
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;
24764 +
24765 + if (left < len)
24766 + return -EINVAL;
24767 +
24768 + return ieee80211_set_gen_ie(dev, pos, len);
24769 +}
24770 +
24771 +
24772 +static int ieee80211_ioctl_set_regulatory_domain(struct net_device *dev,
24773 + struct prism2_hostapd_param *param)
24774 +{
24775 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24776 + conf->regulatory_domain = param->u.set_regulatory_domain.rd;
24777 + return 0;
24778 +}
24779 +
24780 +
24781 +static int ieee80211_ioctl_set_adm_status(struct net_device *dev,
24782 + int val)
24783 +{
24784 + struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
24785 + conf->adm_status = val;
24786 + return ieee80211_hw_config(dev);
24787 +}
24788 +
24789 +static int
24790 +ieee80211_ioctl_set_tx_queue_params(struct net_device *dev,
24791 + struct prism2_hostapd_param *param)
24792 +{
24793 + struct ieee80211_local *local = dev->priv;
24794 + struct ieee80211_tx_queue_params qparam;
24795 +
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;
24800 + }
24801 +
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;
24807 +
24808 + return local->hw->conf_tx(dev, param->u.tx_queue_params.queue,
24809 + &qparam);
24810 +}
24811 +
24812 +
24813 +static int ieee80211_ioctl_get_tx_stats(struct net_device *dev,
24814 + struct prism2_hostapd_param *param)
24815 +{
24816 + struct ieee80211_local *local = dev->priv;
24817 + struct ieee80211_tx_queue_stats stats;
24818 + int ret, i;
24819 +
24820 + if (!local->hw->get_tx_stats)
24821 + return -EOPNOTSUPP;
24822 +
24823 + memset(&stats, 0, sizeof(stats));
24824 + ret = local->hw->get_tx_stats(dev, &stats);
24825 + if (ret)
24826 + return ret;
24827 +
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;
24832 + }
24833 +
24834 + return 0;
24835 +}
24836 +
24837 +
24838 +int ieee80211_set_bss_count(struct net_device *dev, int new_count,
24839 + u8 *bssid_mask)
24840 +{
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;
24846 +
24847 + bss_count = 0;
24848 + for (i = 0; i < conf->bss_count; i++) {
24849 + if (local->bss_devs[i])
24850 + bss_count++;
24851 + }
24852 +
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);
24856 + return -EINVAL;
24857 + }
24858 +
24859 + bss_devs = kmalloc(new_count * sizeof(struct net_device *),
24860 + GFP_KERNEL);
24861 + if (bss_devs == NULL)
24862 + return -ENOMEM;
24863 + sta_devs = kmalloc(new_count * sizeof(struct net_device *),
24864 + GFP_KERNEL);
24865 + if (sta_devs == NULL) {
24866 + kfree(bss_devs);
24867 + return -ENOMEM;
24868 + }
24869 +
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 *));
24875 +
24876 + if (bssid_mask)
24877 + memcpy(conf->bssid_mask, bssid_mask, ETH_ALEN);
24878 +
24879 + prev = local->bss_devs;
24880 + local->bss_devs = bss_devs;
24881 + conf->bss_count = new_count;
24882 +
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;
24889 +
24890 + spin_unlock_bh(&local->sub_if_lock);
24891 + kfree(prev);
24892 + kfree(prev_sta_devs);
24893 +
24894 + return ieee80211_hw_config(dev);
24895 +}
24896 +
24897 +static int ieee80211_ioctl_set_bss(struct net_device *dev,
24898 + struct prism2_hostapd_param *param)
24899 +{
24900 + return ieee80211_set_bss_count(dev, param->u.set_bss.bss_count,
24901 + param->u.set_bss.bssid_mask);
24902 +}
24903 +
24904 +
24905 +static int ieee80211_ioctl_set_channel_flag(struct net_device *dev,
24906 + struct prism2_hostapd_param *param)
24907 +{
24908 + struct ieee80211_local *local = dev->priv;
24909 + struct ieee80211_hw_modes *mode = NULL;
24910 + struct ieee80211_channel *chan = NULL;
24911 + int i;
24912 +
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)
24916 + break;
24917 + mode = NULL;
24918 + }
24919 +
24920 + if (!mode)
24921 + return -ENOENT;
24922 +
24923 + for (i = 0; i < mode->num_channels; i++) {
24924 + chan = &mode->channels[i];
24925 + if (chan->chan == param->u.set_channel_flag.chan)
24926 + break;
24927 + chan = NULL;
24928 + }
24929 +
24930 + if (!chan)
24931 + return -ENOENT;
24932 +
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;
24936 +
24937 + return 0;
24938 +}
24939 +
24940 +
24941 +static int ieee80211_ioctl_set_quiet_params(struct net_device *dev,
24942 + struct prism2_hostapd_param *param)
24943 +{
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;
24948 + return 0;
24949 +}
24950 +
24951 +
24952 +static int ieee80211_ioctl_set_radar_params(struct net_device *dev,
24953 + struct prism2_hostapd_param *param)
24954 +{
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;
24961 + return 0;
24962 +}
24963 +
24964 +
24965 +static int ieee80211_ioctl_priv_hostapd(struct net_device *dev,
24966 + struct iw_point *p)
24967 +{
24968 + struct prism2_hostapd_param *param;
24969 + int ret = 0;
24970 +
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);
24977 + return -EINVAL;
24978 + }
24979 +
24980 + param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
24981 + if (param == NULL)
24982 + return -ENOMEM;
24983 +
24984 + if (copy_from_user(param, p->pointer, p->length)) {
24985 + ret = -EFAULT;
24986 + goto out;
24987 + }
24988 +
24989 + switch (param->cmd) {
24990 + case PRISM2_HOSTAPD_FLUSH:
24991 + ret = ieee80211_ioctl_flush(dev, param);
24992 + break;
24993 + case PRISM2_HOSTAPD_ADD_STA:
24994 + ret = ieee80211_ioctl_add_sta(dev, param);
24995 + break;
24996 + case PRISM2_HOSTAPD_REMOVE_STA:
24997 + ret = ieee80211_ioctl_remove_sta(dev, param);
24998 + break;
24999 + case PRISM2_HOSTAPD_GET_INFO_STA:
25000 + ret = ieee80211_ioctl_get_info_sta(dev, param);
25001 + break;
25002 + case PRISM2_SET_ENCRYPTION:
25003 + ret = ieee80211_ioctl_set_encryption(dev, param, p->length);
25004 + break;
25005 + case PRISM2_GET_ENCRYPTION:
25006 + ret = ieee80211_ioctl_get_encryption(dev, param, p->length);
25007 + break;
25008 + case PRISM2_HOSTAPD_SET_FLAGS_STA:
25009 + ret = ieee80211_ioctl_set_flags_sta(dev, param);
25010 + break;
25011 + case PRISM2_HOSTAPD_SET_BEACON:
25012 + ret = ieee80211_ioctl_set_beacon(dev, param, p->length, 0);
25013 + break;
25014 + case PRISM2_HOSTAPD_GET_HW_FEATURES:
25015 + ret = ieee80211_ioctl_get_hw_features(dev, param, p->length);
25016 + break;
25017 + case PRISM2_HOSTAPD_SCAN:
25018 + ret = ieee80211_ioctl_scan(dev, param);
25019 + break;
25020 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
25021 + case PRISM2_HOSTAPD_WPA_TRIGGER:
25022 + ret = ieee80211_ioctl_wpa_trigger(dev, param);
25023 + break;
25024 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
25025 + case PRISM2_HOSTAPD_SET_RATE_SETS:
25026 + ret = ieee80211_ioctl_set_rate_sets(dev, param, p->length);
25027 + break;
25028 + case PRISM2_HOSTAPD_ADD_IF:
25029 + ret = ieee80211_ioctl_add_if(dev, param, p->length);
25030 + break;
25031 + case PRISM2_HOSTAPD_REMOVE_IF:
25032 + ret = ieee80211_ioctl_remove_if(dev, param);
25033 + break;
25034 + case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE:
25035 + ret = ieee80211_ioctl_get_dot11counterstable(dev, param);
25036 + break;
25037 + case PRISM2_HOSTAPD_GET_LOAD_STATS:
25038 + ret = ieee80211_ioctl_get_load_stats(dev, param);
25039 + break;
25040 + case PRISM2_HOSTAPD_SET_STA_VLAN:
25041 + ret = ieee80211_ioctl_set_sta_vlan(dev, param);
25042 + break;
25043 + case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM:
25044 + ret = ieee80211_ioctl_set_generic_info_elem(dev, param,
25045 + p->length);
25046 + break;
25047 + case PRISM2_HOSTAPD_SET_CHANNEL_FLAG:
25048 + ret = ieee80211_ioctl_set_channel_flag(dev, param);
25049 + break;
25050 + case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN:
25051 + ret = ieee80211_ioctl_set_regulatory_domain(dev, param);
25052 + break;
25053 + case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS:
25054 + ret = ieee80211_ioctl_set_tx_queue_params(dev, param);
25055 + break;
25056 + case PRISM2_HOSTAPD_SET_BSS:
25057 + ret = ieee80211_ioctl_set_bss(dev, param);
25058 + break;
25059 + case PRISM2_HOSTAPD_GET_TX_STATS:
25060 + ret = ieee80211_ioctl_get_tx_stats(dev, param);
25061 + break;
25062 + case PRISM2_HOSTAPD_UPDATE_IF:
25063 + ret = ieee80211_ioctl_update_if(dev, param, p->length);
25064 + break;
25065 + case PRISM2_HOSTAPD_SCAN_REQ:
25066 + ret = ieee80211_ioctl_scan_req(dev, param, p->length);
25067 + break;
25068 + case PRISM2_STA_GET_STATE:
25069 + ret = ieee80211_ioctl_sta_get_state(dev, param);
25070 + break;
25071 + case PRISM2_HOSTAPD_MLME:
25072 + ret = ieee80211_ioctl_mlme(dev, param);
25073 + break;
25074 + case PRISM2_HOSTAPD_FLUSH_IFS:
25075 + ret = ieee80211_ioctl_flush_ifs(dev, param);
25076 + break;
25077 + case PRISM2_HOSTAPD_SET_RADAR_PARAMS:
25078 + ret = ieee80211_ioctl_set_radar_params(dev, param);
25079 + break;
25080 + case PRISM2_HOSTAPD_SET_QUIET_PARAMS:
25081 + ret = ieee80211_ioctl_set_quiet_params(dev, param);
25082 + break;
25083 + default:
25084 + ret = -EOPNOTSUPP;
25085 + break;
25086 + }
25087 +
25088 + if (copy_to_user(p->pointer, param, p->length))
25089 + ret = -EFAULT;
25090 +
25091 + out:
25092 + kfree(param);
25093 +
25094 + return ret;
25095 +}
25096 +
25097 +
25098 +static int ieee80211_ioctl_giwname(struct net_device *dev,
25099 + struct iw_request_info *info,
25100 + char *name, char *extra)
25101 +{
25102 + struct ieee80211_local *local = dev->priv;
25103 +
25104 + switch (local->conf.phymode) {
25105 + case MODE_IEEE80211A:
25106 + strcpy(name, "IEEE 802.11a");
25107 + break;
25108 + case MODE_IEEE80211B:
25109 + strcpy(name, "IEEE 802.11b");
25110 + break;
25111 + case MODE_IEEE80211G:
25112 + strcpy(name, "IEEE 802.11g");
25113 + break;
25114 + case MODE_ATHEROS_TURBO:
25115 + strcpy(name, "5GHz Turbo");
25116 + break;
25117 + default:
25118 + strcpy(name, "IEEE 802.11");
25119 + break;
25120 + }
25121 +
25122 + return 0;
25123 +}
25124 +
25125 +
25126 +static int ieee80211_ioctl_giwrange(struct net_device *dev,
25127 + struct iw_request_info *info,
25128 + struct iw_point *data, char *extra)
25129 +{
25130 + struct iw_range *range = (struct iw_range *) extra;
25131 +
25132 + data->length = sizeof(struct iw_range);
25133 + memset(range, 0, sizeof(struct iw_range));
25134 +
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;
25145 +
25146 + return 0;
25147 +}
25148 +
25149 +
25150 +struct ieee80211_channel_range {
25151 + short start_freq;
25152 + short end_freq;
25153 + unsigned char power_level;
25154 + unsigned char antenna_max;
25155 +};
25156 +
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 */,
25162 + { 0 }
25163 +};
25164 +
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 */,
25169 + { 0 }
25170 +};
25171 +
25172 +
25173 +static const struct ieee80211_channel_range *channel_range =
25174 + ieee80211_fcc_channels;
25175 +
25176 +
25177 +static void ieee80211_unmask_channel(struct net_device *dev, int mode,
25178 + struct ieee80211_channel *chan)
25179 +{
25180 + int i;
25181 +
25182 + chan->flag = 0;
25183 +
25184 + if (ieee80211_regdom == 64 &&
25185 + (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
25186 + /* Do not allow Turbo modes in Japan. */
25187 + return;
25188 + }
25189 +
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) {
25195 + /*
25196 + * Skip new channels in Japan since the
25197 + * firmware was not marked having been upgraded
25198 + * by the vendor.
25199 + */
25200 + continue;
25201 + }
25202 +
25203 + if (ieee80211_regdom == 0x10 &&
25204 + (chan->freq == 5190 || chan->freq == 5210 ||
25205 + chan->freq == 5230)) {
25206 + /* Skip MKK channels when in FCC domain. */
25207 + continue;
25208 + }
25209 +
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;
25215 +
25216 + if (ieee80211_regdom == 64 &&
25217 + (chan->freq == 5170 || chan->freq == 5190 ||
25218 + chan->freq == 5210 || chan->freq == 5230)) {
25219 + /*
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.
25224 + */
25225 + chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
25226 + }
25227 +
25228 + if (ieee80211_regdom == 64 &&
25229 + (chan->freq == 5260 || chan->freq == 5280 ||
25230 + chan->freq == 5300 || chan->freq == 5320)) {
25231 + /*
25232 + * IBSS is not allowed on 5.25-5.35 GHz band
25233 + * due to radar detection requirements.
25234 + */
25235 + chan->flag &= ~IEEE80211_CHAN_W_IBSS;
25236 + }
25237 +
25238 + break;
25239 + }
25240 + }
25241 +}
25242 +
25243 +
25244 +static int ieee80211_unmask_channels(struct net_device *dev)
25245 +{
25246 + struct ieee80211_local *local = dev->priv;
25247 + int m, c;
25248 +
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]);
25254 + }
25255 + }
25256 + return 0;
25257 +}
25258 +
25259 +
25260 +static int ieee80211_init_client(struct net_device *dev)
25261 +{
25262 + if (ieee80211_regdom == 0x40)
25263 + channel_range = ieee80211_mkk_channels;
25264 + ieee80211_unmask_channels(dev);
25265 + ieee80211_ioctl_set_adm_status(dev, 1);
25266 + return 0;
25267 +}
25268 +
25269 +
25270 +static int ieee80211_is_client_mode(int iw_mode)
25271 +{
25272 + return (iw_mode == IW_MODE_INFRA || iw_mode == IW_MODE_ADHOC);
25273 +}
25274 +
25275 +
25276 +static int ieee80211_ioctl_siwmode(struct net_device *dev,
25277 + struct iw_request_info *info,
25278 + __u32 *mode, char *extra)
25279 +{
25280 + struct ieee80211_local *local = dev->priv;
25281 +
25282 + if (!ieee80211_is_client_mode(local->conf.mode) &&
25283 + ieee80211_is_client_mode(*mode)) {
25284 + ieee80211_init_client(dev);
25285 + }
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
25294 + * in 80211.o. */
25295 + sdata->drop_unencrypted = 0;
25296 + }
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;
25301 + }
25302 + }
25303 + local->conf.mode = *mode;
25304 + return ieee80211_hw_config(dev);
25305 +}
25306 +
25307 +
25308 +static int ieee80211_ioctl_giwmode(struct net_device *dev,
25309 + struct iw_request_info *info,
25310 + __u32 *mode, char *extra)
25311 +{
25312 + struct ieee80211_local *local = dev->priv;
25313 + struct ieee80211_sub_if_data *sdata;
25314 +
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;
25319 + else
25320 + *mode = IW_MODE_INFRA;
25321 + } else
25322 + *mode = local->conf.mode;
25323 + return 0;
25324 +}
25325 +
25326 +
25327 +int ieee80211_ioctl_siwfreq(struct net_device *dev,
25328 + struct iw_request_info *info,
25329 + struct iw_freq *freq, char *extra)
25330 +{
25331 + struct ieee80211_local *local = dev->priv;
25332 + int m, c, nfreq, set = 0;
25333 +
25334 + /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
25335 + if (freq->e == 0)
25336 + nfreq = -1;
25337 + else {
25338 + int i, div = 1000000;
25339 + for (i = 0; i < freq->e; i++)
25340 + div /= 10;
25341 + if (div > 0)
25342 + nfreq = freq->m / div;
25343 + else
25344 + return -EINVAL;
25345 + }
25346 +
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)
25358 + continue;
25359 +
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;
25366 + set++;
25367 + }
25368 + }
25369 + }
25370 +
25371 + if (set) {
25372 + local->sta_scanning = 0; /* Abort possible scan */
25373 + return ieee80211_hw_config(dev);
25374 + }
25375 +
25376 + return -EINVAL;
25377 +}
25378 +
25379 +
25380 +static int ieee80211_ioctl_giwfreq(struct net_device *dev,
25381 + struct iw_request_info *info,
25382 + struct iw_freq *freq, char *extra)
25383 +{
25384 + struct ieee80211_local *local = dev->priv;
25385 +
25386 + /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
25387 + * driver for the current channel with firmware-based management */
25388 +
25389 + freq->m = local->conf.freq;
25390 + freq->e = 6;
25391 +
25392 + return 0;
25393 +}
25394 +
25395 +
25396 +static int ieee80211_ioctl_siwessid(struct net_device *dev,
25397 + struct iw_request_info *info,
25398 + struct iw_point *data, char *ssid)
25399 +{
25400 + struct ieee80211_local *local = dev->priv;
25401 + struct ieee80211_sub_if_data *sdata;
25402 + size_t len = data->length;
25403 +
25404 + /* iwconfig uses nul termination in SSID.. */
25405 + if (len > 0 && ssid[len - 1] == '\0')
25406 + len--;
25407 +
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);
25411 +
25412 + kfree(local->conf.ssid);
25413 + local->conf.ssid = kmalloc(len + 1, GFP_KERNEL);
25414 + if (local->conf.ssid == NULL)
25415 + return -ENOMEM;
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);
25420 +}
25421 +
25422 +
25423 +static int ieee80211_ioctl_giwessid(struct net_device *dev,
25424 + struct iw_request_info *info,
25425 + struct iw_point *data, char *ssid)
25426 +{
25427 + struct ieee80211_local *local = dev->priv;
25428 + size_t len;
25429 +
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);
25434 + if (res == 0)
25435 + data->length = len;
25436 + return res;
25437 + }
25438 +
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;
25444 + return 0;
25445 +}
25446 +
25447 +
25448 +static int ieee80211_ioctl_siwap(struct net_device *dev,
25449 + struct iw_request_info *info,
25450 + struct sockaddr *ap_addr, char *extra)
25451 +{
25452 + struct ieee80211_local *local = dev->priv;
25453 + struct ieee80211_sub_if_data *sdata;
25454 +
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,
25459 + ETH_ALEN) != 0)
25460 + changed_bssid = 1;
25461 + memcpy(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
25462 + ETH_ALEN);
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);
25466 + }
25467 + return ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
25468 + }
25469 +
25470 + return -EOPNOTSUPP;
25471 +}
25472 +
25473 +
25474 +static int ieee80211_ioctl_giwap(struct net_device *dev,
25475 + struct iw_request_info *info,
25476 + struct sockaddr *ap_addr, char *extra)
25477 +{
25478 + struct ieee80211_sub_if_data *sdata;
25479 +
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);
25484 + return 0;
25485 + }
25486 +
25487 + return -EOPNOTSUPP;
25488 +}
25489 +
25490 +
25491 +static int ieee80211_ioctl_siwscan(struct net_device *dev,
25492 + struct iw_request_info *info,
25493 + struct iw_point *data, char *extra)
25494 +{
25495 + struct ieee80211_local *local = dev->priv;
25496 + u8 *ssid = NULL;
25497 + size_t ssid_len = 0;
25498 +
25499 + if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
25500 + ssid = local->conf.ssid;
25501 + ssid_len = local->conf.ssid_len;
25502 + }
25503 + return ieee80211_sta_req_scan(dev, ssid, ssid_len);
25504 +}
25505 +
25506 +
25507 +static int ieee80211_ioctl_giwscan(struct net_device *dev,
25508 + struct iw_request_info *info,
25509 + struct iw_point *data, char *extra)
25510 +{
25511 + int res;
25512 + struct ieee80211_local *local = dev->priv;
25513 + if (local->sta_scanning)
25514 + return -EAGAIN;
25515 + res = ieee80211_sta_scan_results(dev, extra, IW_SCAN_MAX_DATA);
25516 + if (res >= 0) {
25517 + data->length = res;
25518 + return 0;
25519 + }
25520 + data->length = 0;
25521 + return res;
25522 +}
25523 +
25524 +
25525 +static int ieee80211_ioctl_siwrts(struct net_device *dev,
25526 + struct iw_request_info *info,
25527 + struct iw_param *rts, char *extra)
25528 +{
25529 + struct ieee80211_local *local = dev->priv;
25530 +
25531 + if (rts->disabled)
25532 + local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
25533 + else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
25534 + return -EINVAL;
25535 + else
25536 + local->rts_threshold = rts->value;
25537 +
25538 + /* If the wlan card performs RTS/CTS in hardware/firmware,
25539 + * configure it here */
25540 +
25541 + if (local->hw->set_rts_threshold) {
25542 + local->hw->set_rts_threshold(dev, local->rts_threshold);
25543 + }
25544 +
25545 + return 0;
25546 +}
25547 +
25548 +static int ieee80211_ioctl_giwrts(struct net_device *dev,
25549 + struct iw_request_info *info,
25550 + struct iw_param *rts, char *extra)
25551 +{
25552 + struct ieee80211_local *local = dev->priv;
25553 +
25554 + rts->value = local->rts_threshold;
25555 + rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
25556 + rts->fixed = 1;
25557 +
25558 + return 0;
25559 +}
25560 +
25561 +
25562 +static int ieee80211_ioctl_siwfrag(struct net_device *dev,
25563 + struct iw_request_info *info,
25564 + struct iw_param *frag, char *extra)
25565 +{
25566 + struct ieee80211_local *local = dev->priv;
25567 +
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)
25572 + return -EINVAL;
25573 + else {
25574 + /* Fragment length must be even, so strip LSB. */
25575 + local->fragmentation_threshold = frag->value & ~0x1;
25576 + }
25577 +
25578 + /* If the wlan card performs fragmentation in hardware/firmware,
25579 + * configure it here */
25580 +
25581 + if (local->hw->set_frag_threshold) {
25582 + local->hw->set_frag_threshold(
25583 + dev, local->fragmentation_threshold);
25584 + }
25585 +
25586 + return 0;
25587 +}
25588 +
25589 +static int ieee80211_ioctl_giwfrag(struct net_device *dev,
25590 + struct iw_request_info *info,
25591 + struct iw_param *frag, char *extra)
25592 +{
25593 + struct ieee80211_local *local = dev->priv;
25594 +
25595 + frag->value = local->fragmentation_threshold;
25596 + frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
25597 + frag->fixed = 1;
25598 +
25599 + return 0;
25600 +}
25601 +
25602 +
25603 +static int ieee80211_ioctl_siwretry(struct net_device *dev,
25604 + struct iw_request_info *info,
25605 + struct iw_param *retry, char *extra)
25606 +{
25607 + struct ieee80211_local *local = dev->priv;
25608 +
25609 + if (retry->disabled ||
25610 + (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25611 + return -EINVAL;
25612 +
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;
25617 + else {
25618 + local->long_retry_limit = retry->value;
25619 + local->short_retry_limit = retry->value;
25620 + }
25621 +
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);
25626 + }
25627 +
25628 + return 0;
25629 +}
25630 +
25631 +
25632 +static int ieee80211_ioctl_giwretry(struct net_device *dev,
25633 + struct iw_request_info *info,
25634 + struct iw_param *retry, char *extra)
25635 +{
25636 + struct ieee80211_local *local = dev->priv;
25637 +
25638 + retry->disabled = 0;
25639 + if ((retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
25640 + return -EINVAL;
25641 + if (retry->flags & IW_RETRY_MAX) {
25642 + retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
25643 + retry->value = local->long_retry_limit;
25644 + } else {
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;
25649 + }
25650 +
25651 + return 0;
25652 +}
25653 +
25654 +
25655 +static void ieee80211_ioctl_unmask_channels(struct ieee80211_local *local)
25656 +{
25657 + int m, c;
25658 +
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;
25664 + }
25665 + }
25666 +}
25667 +
25668 +
25669 +static int ieee80211_ioctl_test_mode(struct net_device *dev, int mode)
25670 +{
25671 + struct ieee80211_local *local = dev->priv;
25672 + int ret = -EOPNOTSUPP;
25673 +
25674 + if (mode == IEEE80211_TEST_UNMASK_CHANNELS) {
25675 + ieee80211_ioctl_unmask_channels(local);
25676 + ret = 0;
25677 + }
25678 +
25679 + if (local->hw->test_mode)
25680 + ret = local->hw->test_mode(dev, mode);
25681 +
25682 + return ret;
25683 +}
25684 +
25685 +
25686 +static int ieee80211_ioctl_clear_keys(struct net_device *dev)
25687 +{
25688 + struct ieee80211_local *local = dev->priv;
25689 + struct ieee80211_key_conf key;
25690 + struct list_head *ptr;
25691 + int i;
25692 + u8 addr[ETH_ALEN];
25693 + struct ieee80211_key_conf *keyconf;
25694 +
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++) {
25700 + keyconf = NULL;
25701 + if (sdata->keys[i] &&
25702 + !sdata->keys[i]->force_sw_encrypt &&
25703 + local->hw->set_key &&
25704 + (keyconf = ieee80211_key_data2conf(local,
25705 + sdata->keys[i]))
25706 + != NULL)
25707 + local->hw->set_key(dev, DISABLE_KEY, addr,
25708 + keyconf, 0);
25709 + kfree(keyconf);
25710 + kfree(sdata->keys[i]);
25711 + sdata->keys[i] = NULL;
25712 + }
25713 + sdata->default_key = NULL;
25714 + }
25715 +
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);
25720 + keyconf = NULL;
25721 + if (sta->key && !sta->key->force_sw_encrypt &&
25722 + local->hw->set_key &&
25723 + (keyconf = ieee80211_key_data2conf(local, sta->key))
25724 + != NULL)
25725 + local->hw->set_key(dev, DISABLE_KEY, sta->addr,
25726 + keyconf, sta->aid);
25727 + kfree(keyconf);
25728 + kfree(sta->key);
25729 + sta->key = NULL;
25730 + }
25731 + spin_unlock_bh(&local->sta_lock);
25732 +
25733 + memset(&key, 0, sizeof(key));
25734 + if (local->hw->set_key &&
25735 + local->hw->set_key(dev, REMOVE_ALL_KEYS, NULL,
25736 + &key, 0))
25737 + printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
25738 + dev->name);
25739 +
25740 + return 0;
25741 +}
25742 +
25743 +
25744 +static int
25745 +ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
25746 + struct ieee80211_sub_if_data *sdata,
25747 + int rate)
25748 +{
25749 + struct ieee80211_local *local = dev->priv;
25750 + int i;
25751 +
25752 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25753 + return -ENOENT;
25754 +
25755 + if (rate == 0) {
25756 + sdata->u.ap.force_unicast_rateidx = -1;
25757 + return 0;
25758 + }
25759 +
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;
25763 + return 0;
25764 + }
25765 + }
25766 + return -EINVAL;
25767 +}
25768 +
25769 +
25770 +static int
25771 +ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
25772 + struct ieee80211_sub_if_data *sdata,
25773 + int rate)
25774 +{
25775 + struct ieee80211_local *local = dev->priv;
25776 + int i;
25777 +
25778 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25779 + return -ENOENT;
25780 +
25781 + if (rate == 0) {
25782 + sdata->u.ap.max_ratectrl_rateidx = -1;
25783 + return 0;
25784 + }
25785 +
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;
25789 + return 0;
25790 + }
25791 + }
25792 + return -EINVAL;
25793 +}
25794 +
25795 +
25796 +static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
25797 + struct ieee80211_key *key)
25798 +{
25799 + struct ieee80211_key_conf *keyconf;
25800 + u8 addr[ETH_ALEN];
25801 +
25802 + if (key == NULL || key->alg != ALG_WEP || !key->force_sw_encrypt ||
25803 + local->hw->device_hides_wep)
25804 + return;
25805 +
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;
25812 + }
25813 + kfree(keyconf);
25814 +}
25815 +
25816 +
25817 +static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
25818 + struct ieee80211_key *key)
25819 +{
25820 + struct ieee80211_key_conf *keyconf;
25821 + u8 addr[ETH_ALEN];
25822 +
25823 + if (key == NULL || key->alg != ALG_WEP || key->force_sw_encrypt ||
25824 + local->hw->device_hides_wep)
25825 + return;
25826 +
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);
25831 + kfree(keyconf);
25832 + key->force_sw_encrypt = 1;
25833 +}
25834 +
25835 +
25836 +static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
25837 + int value)
25838 +{
25839 + int i;
25840 + struct list_head *ptr;
25841 +
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++) {
25847 + if (value) {
25848 + ieee80211_key_enable_hwaccel(local,
25849 + sdata->keys[i]);
25850 + } else {
25851 + ieee80211_key_disable_hwaccel(local,
25852 + sdata->keys[i]);
25853 + }
25854 + }
25855 + }
25856 +
25857 + return 0;
25858 +}
25859 +
25860 +
25861 +static int ieee80211_ioctl_prism2_param(struct net_device *dev,
25862 + struct iw_request_info *info,
25863 + void *wrqu, char *extra)
25864 +{
25865 + struct ieee80211_local *local = dev->priv;
25866 + struct ieee80211_sub_if_data *sdata;
25867 + int *i = (int *) extra;
25868 + int param = *i;
25869 + int value = *(i + 1);
25870 + int ret = 0;
25871 +
25872 + if (!capable(CAP_NET_ADMIN))
25873 + return -EPERM;
25874 +
25875 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
25876 +
25877 + switch (param) {
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 */
25882 + break;
25883 +
25884 + case PRISM2_PARAM_BEACON_INT:
25885 + local->conf.beacon_int = value;
25886 + if (ieee80211_hw_config(dev))
25887 + ret = -EINVAL;
25888 + break;
25889 +
25890 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
25891 + local->bridge_packets = value;
25892 + break;
25893 +
25894 + case PRISM2_PARAM_AP_AUTH_ALGS:
25895 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
25896 + sdata->u.sta.auth_algs = value;
25897 + } else
25898 + ret = -EOPNOTSUPP;
25899 + break;
25900 +
25901 + case PRISM2_PARAM_DTIM_PERIOD:
25902 + if (value < 1)
25903 + ret = -EINVAL;
25904 + else if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
25905 + ret = -ENOENT;
25906 + else
25907 + sdata->u.ap.dtim_period = value;
25908 + break;
25909 +
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);
25916 + break;
25917 +
25918 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
25919 + local->cts_protect_erp_frames = value;
25920 + break;
25921 +
25922 + case PRISM2_PARAM_DROP_UNENCRYPTED:
25923 + sdata->drop_unencrypted = value;
25924 + break;
25925 +
25926 + case PRISM2_PARAM_PREAMBLE:
25927 + local->short_preamble = value;
25928 + break;
25929 +
25930 + case PRISM2_PARAM_RATE_LIMIT_BURST:
25931 + local->rate_limit_burst = value;
25932 + local->rate_limit_bucket = value;
25933 + break;
25934 +
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 =
25939 + value;
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);
25945 + }
25946 + local->rate_limit = value;
25947 + break;
25948 +
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);
25955 + }
25956 + local->stat_time = value;
25957 + break;
25958 + case PRISM2_PARAM_SHORT_SLOT_TIME:
25959 + local->conf.short_slot_time = value;
25960 + if (ieee80211_hw_config(dev))
25961 + ret = -EINVAL;
25962 + break;
25963 +
25964 + case PRISM2_PARAM_PRIVACY_INVOKED:
25965 + if (local->hw->set_privacy_invoked)
25966 + ret = local->hw->set_privacy_invoked(dev, value);
25967 + break;
25968 +
25969 + case PRISM2_PARAM_TEST_MODE:
25970 + ret = ieee80211_ioctl_test_mode(dev, value);
25971 + break;
25972 +
25973 + case PRISM2_PARAM_NEXT_MODE:
25974 + local->next_mode = value;
25975 + break;
25976 +
25977 + case PRISM2_PARAM_CLEAR_KEYS:
25978 + ret = ieee80211_ioctl_clear_keys(dev);
25979 + break;
25980 +
25981 + case PRISM2_PARAM_ADM_STATUS:
25982 + ret = ieee80211_ioctl_set_adm_status(dev, value);
25983 + break;
25984 +
25985 + case PRISM2_PARAM_ANTENNA_SEL:
25986 + local->conf.antenna_sel = value;
25987 + if (ieee80211_hw_config(dev))
25988 + ret = -EINVAL;
25989 + break;
25990 +
25991 + case PRISM2_PARAM_CALIB_INT:
25992 + local->conf.calib_int = value;
25993 + if (ieee80211_hw_config(dev))
25994 + ret = -EINVAL;
25995 + break;
25996 +
25997 + case PRISM2_PARAM_ANTENNA_MODE:
25998 + local->conf.antenna_mode = value;
25999 + if (ieee80211_hw_config(dev))
26000 + ret = -EINVAL;
26001 + break;
26002 +
26003 + case PRISM2_PARAM_BROADCAST_SSID:
26004 + if ((value < 0) || (value > 1))
26005 + ret = -EINVAL;
26006 + else
26007 + local->conf.ssid_hidden = value;
26008 + break;
26009 +
26010 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26011 + local->sta_antenna_sel = value;
26012 + break;
26013 +
26014 + case PRISM2_PARAM_FORCE_UNICAST_RATE:
26015 + ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
26016 + break;
26017 +
26018 + case PRISM2_PARAM_MAX_RATECTRL_RATE:
26019 + ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
26020 + break;
26021 +
26022 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26023 + local->rate_ctrl_num_up = value;
26024 + break;
26025 +
26026 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26027 + local->rate_ctrl_num_down = value;
26028 + break;
26029 +
26030 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26031 + if (value < 0)
26032 + ret = -EINVAL;
26033 + else
26034 + local->conf.tx_power_reduction = value;
26035 + break;
26036 +
26037 + case PRISM2_PARAM_EAPOL:
26038 + sdata->eapol = value;
26039 + break;
26040 +
26041 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26042 + local->key_tx_rx_threshold = value;
26043 + break;
26044 +
26045 + case PRISM2_PARAM_KEY_INDEX:
26046 + if (value < 0 || value >= NUM_DEFAULT_KEYS)
26047 + ret = -EINVAL;
26048 + else if (sdata->keys[value] == NULL)
26049 + ret = -ENOENT;
26050 + else
26051 + sdata->default_key = sdata->keys[value];
26052 + break;
26053 +
26054 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26055 + ret = ieee80211_ioctl_default_wep_only(local, value);
26056 + break;
26057 +
26058 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26059 + local->wifi_wme_noack_test = value;
26060 + break;
26061 +
26062 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26063 + local->allow_broadcast_always = value;
26064 + break;
26065 +
26066 + case PRISM2_PARAM_SCAN_FLAGS:
26067 + local->scan_flags = value;
26068 + break;
26069 +
26070 + case PRISM2_PARAM_MIXED_CELL:
26071 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26072 + ret = -EINVAL;
26073 + else
26074 + sdata->u.sta.mixed_cell = !!value;
26075 + break;
26076 +
26077 + case PRISM2_PARAM_KEY_MGMT:
26078 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26079 + ret = -EINVAL;
26080 + else
26081 + sdata->u.sta.key_mgmt = value;
26082 + break;
26083 +
26084 + case PRISM2_PARAM_HW_MODES:
26085 + local->hw_modes = value;
26086 + break;
26087 +
26088 + case PRISM2_PARAM_CREATE_IBSS:
26089 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26090 + ret = -EINVAL;
26091 + else
26092 + sdata->u.sta.create_ibss = !!value;
26093 + break;
26094 + case PRISM2_PARAM_WMM_ENABLED:
26095 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26096 + ret = -EINVAL;
26097 + else
26098 + sdata->u.sta.wmm_enabled = !!value;
26099 + break;
26100 + case PRISM2_PARAM_RADAR_DETECT:
26101 + local->conf.radar_detect = value;
26102 + break;
26103 + case PRISM2_PARAM_SPECTRUM_MGMT:
26104 + local->conf.spect_mgmt = value;
26105 + break;
26106 + default:
26107 + ret = -EOPNOTSUPP;
26108 + break;
26109 + }
26110 +
26111 + return ret;
26112 +}
26113 +
26114 +
26115 +static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
26116 + struct iw_request_info *info,
26117 + void *wrqu, char *extra)
26118 +{
26119 + struct ieee80211_local *local = dev->priv;
26120 + struct ieee80211_sub_if_data *sdata;
26121 + int *param = (int *) extra;
26122 + int ret = 0;
26123 +
26124 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26125 +
26126 + switch (*param) {
26127 + case PRISM2_PARAM_BEACON_INT:
26128 + *param = local->conf.beacon_int;
26129 + break;
26130 +
26131 + case PRISM2_PARAM_AP_BRIDGE_PACKETS:
26132 + *param = local->bridge_packets;
26133 + break;
26134 +
26135 + case PRISM2_PARAM_AP_AUTH_ALGS:
26136 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
26137 + *param = sdata->u.sta.auth_algs;
26138 + } else
26139 + ret = -EOPNOTSUPP;
26140 + break;
26141 +
26142 + case PRISM2_PARAM_DTIM_PERIOD:
26143 + if (sdata->type != IEEE80211_SUB_IF_TYPE_AP)
26144 + ret = -ENOENT;
26145 + else
26146 + *param = sdata->u.ap.dtim_period;
26147 + break;
26148 +
26149 + case PRISM2_PARAM_IEEE_802_1X:
26150 + *param = sdata->ieee802_1x;
26151 + break;
26152 +
26153 + case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
26154 + *param = local->cts_protect_erp_frames;
26155 + break;
26156 +
26157 + case PRISM2_PARAM_DROP_UNENCRYPTED:
26158 + *param = sdata->drop_unencrypted;
26159 + break;
26160 +
26161 + case PRISM2_PARAM_PREAMBLE:
26162 + *param = local->short_preamble;
26163 + break;
26164 +
26165 + case PRISM2_PARAM_RATE_LIMIT_BURST:
26166 + *param = local->rate_limit_burst;
26167 + break;
26168 +
26169 + case PRISM2_PARAM_RATE_LIMIT:
26170 + *param = local->rate_limit;
26171 + break;
26172 +
26173 + case PRISM2_PARAM_STAT_TIME:
26174 + *param = local->stat_time;
26175 + break;
26176 + case PRISM2_PARAM_SHORT_SLOT_TIME:
26177 + *param = local->conf.short_slot_time;
26178 + break;
26179 +
26180 + case PRISM2_PARAM_NEXT_MODE:
26181 + *param = local->next_mode;
26182 + break;
26183 +
26184 + case PRISM2_PARAM_ANTENNA_SEL:
26185 + *param = local->conf.antenna_sel;
26186 + break;
26187 +
26188 + case PRISM2_PARAM_CALIB_INT:
26189 + *param = local->conf.calib_int;
26190 + break;
26191 +
26192 + case PRISM2_PARAM_ANTENNA_MODE:
26193 + *param = local->conf.antenna_mode;
26194 + break;
26195 +
26196 + case PRISM2_PARAM_BROADCAST_SSID:
26197 + *param = local->conf.ssid_hidden;
26198 + break;
26199 +
26200 + case PRISM2_PARAM_STA_ANTENNA_SEL:
26201 + *param = local->sta_antenna_sel;
26202 + break;
26203 +
26204 + case PRISM2_PARAM_RATE_CTRL_NUM_UP:
26205 + *param = local->rate_ctrl_num_up;
26206 + break;
26207 +
26208 + case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
26209 + *param = local->rate_ctrl_num_down;
26210 + break;
26211 +
26212 + case PRISM2_PARAM_TX_POWER_REDUCTION:
26213 + *param = local->conf.tx_power_reduction;
26214 + break;
26215 +
26216 + case PRISM2_PARAM_EAPOL:
26217 + *param = sdata->eapol;
26218 + break;
26219 +
26220 + case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
26221 + *param = local->key_tx_rx_threshold;
26222 + break;
26223 +
26224 + case PRISM2_PARAM_KEY_INDEX:
26225 + if (sdata->default_key == NULL)
26226 + ret = -ENOENT;
26227 + else if (sdata->default_key == sdata->keys[0])
26228 + *param = 0;
26229 + else if (sdata->default_key == sdata->keys[1])
26230 + *param = 1;
26231 + else if (sdata->default_key == sdata->keys[2])
26232 + *param = 2;
26233 + else if (sdata->default_key == sdata->keys[3])
26234 + *param = 3;
26235 + else
26236 + ret = -ENOENT;
26237 + break;
26238 +
26239 + case PRISM2_PARAM_DEFAULT_WEP_ONLY:
26240 + *param = local->default_wep_only;
26241 + break;
26242 +
26243 + case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
26244 + *param = local->wifi_wme_noack_test;
26245 + break;
26246 +
26247 + case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
26248 + *param = local->allow_broadcast_always;
26249 + break;
26250 +
26251 + case PRISM2_PARAM_SCAN_FLAGS:
26252 + *param = local->scan_flags;
26253 + break;
26254 +
26255 + case PRISM2_PARAM_HW_MODES:
26256 + *param = local->hw_modes;
26257 + break;
26258 +
26259 + case PRISM2_PARAM_CREATE_IBSS:
26260 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26261 + ret = -EINVAL;
26262 + else
26263 + *param = !!sdata->u.sta.create_ibss;
26264 + break;
26265 +
26266 + case PRISM2_PARAM_MIXED_CELL:
26267 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26268 + ret = -EINVAL;
26269 + else
26270 + *param = !!sdata->u.sta.mixed_cell;
26271 + break;
26272 +
26273 + case PRISM2_PARAM_KEY_MGMT:
26274 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26275 + ret = -EINVAL;
26276 + else
26277 + *param = sdata->u.sta.key_mgmt;
26278 + break;
26279 + case PRISM2_PARAM_WMM_ENABLED:
26280 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26281 + ret = -EINVAL;
26282 + else
26283 + *param = !!sdata->u.sta.wmm_enabled;
26284 + break;
26285 +
26286 + default:
26287 + ret = -EOPNOTSUPP;
26288 + break;
26289 + }
26290 +
26291 + return ret;
26292 +}
26293 +
26294 +
26295 +static int ieee80211_ioctl_test_param(struct net_device *dev,
26296 + struct iw_request_info *info,
26297 + void *wrqu, char *extra)
26298 +{
26299 + struct ieee80211_local *local = dev->priv;
26300 + int *i = (int *) extra;
26301 + int param = *i;
26302 + int value = *(i + 1);
26303 +
26304 + if (!capable(CAP_NET_ADMIN))
26305 + return -EPERM;
26306 +
26307 + if (local->hw->test_param)
26308 + return local->hw->test_param(local->mdev, param, value);
26309 +
26310 + return -EOPNOTSUPP;
26311 +}
26312 +
26313 +
26314 +static int ieee80211_ioctl_siwmlme(struct net_device *dev,
26315 + struct iw_request_info *info,
26316 + struct iw_point *data, char *extra)
26317 +{
26318 + struct ieee80211_sub_if_data *sdata;
26319 + struct iw_mlme *mlme = (struct iw_mlme *) extra;
26320 +
26321 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26322 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26323 + return -EINVAL;
26324 +
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);
26332 + default:
26333 + return -EOPNOTSUPP;
26334 + }
26335 +}
26336 +
26337 +
26338 +static int ieee80211_ioctl_siwencode(struct net_device *dev,
26339 + struct iw_request_info *info,
26340 + struct iw_point *erq, char *keybuf)
26341 +{
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 };
26345 +
26346 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26347 +
26348 + idx = erq->flags & IW_ENCODE_INDEX;
26349 + if (idx < 1 || idx > 4) {
26350 + idx = -1;
26351 + if (sdata->default_key == NULL)
26352 + idx = 0;
26353 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26354 + if (sdata->default_key == sdata->keys[i])
26355 + idx = i;
26356 + break;
26357 + }
26358 + if (idx < 0)
26359 + return -EINVAL;
26360 + } else
26361 + idx--;
26362 +
26363 + if (erq->flags & IW_ENCODE_DISABLED)
26364 + alg = ALG_NONE;
26365 + else if (erq->length == 0) {
26366 + /* No key data - just set the default TX key index */
26367 + sdata->default_key = sdata->keys[idx];
26368 + }
26369 +
26370 + return ieee80211_set_encryption(
26371 + dev, bcaddr,
26372 + idx, erq->length == 0 ? ALG_NONE : ALG_WEP,
26373 + sdata->default_key == NULL,
26374 + NULL, keybuf, erq->length);
26375 +
26376 + return 0;
26377 +}
26378 +
26379 +
26380 +static int ieee80211_ioctl_giwencode(struct net_device *dev,
26381 + struct iw_request_info *info,
26382 + struct iw_point *erq, char *key)
26383 +{
26384 + struct ieee80211_sub_if_data *sdata;
26385 + int idx, i;
26386 +
26387 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26388 +
26389 + idx = erq->flags & IW_ENCODE_INDEX;
26390 + if (idx < 1 || idx > 4) {
26391 + idx = -1;
26392 + if (sdata->default_key == NULL)
26393 + idx = 0;
26394 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26395 + if (sdata->default_key == sdata->keys[i])
26396 + idx = i;
26397 + break;
26398 + }
26399 + if (idx < 0)
26400 + return -EINVAL;
26401 + } else
26402 + idx--;
26403 +
26404 + erq->flags = idx + 1;
26405 +
26406 + if (sdata->keys[idx] == NULL) {
26407 + erq->length = 0;
26408 + erq->flags |= IW_ENCODE_DISABLED;
26409 + return 0;
26410 + }
26411 +
26412 + erq->length = 0;
26413 + erq->flags |= IW_ENCODE_ENABLED;
26414 +
26415 + return 0;
26416 +}
26417 +
26418 +
26419 +static int ieee80211_ioctl_siwgenie(struct net_device *dev,
26420 + struct iw_request_info *info,
26421 + struct iw_point *data, char *extra)
26422 +{
26423 + return ieee80211_set_gen_ie(dev, extra, data->length);
26424 +}
26425 +
26426 +
26427 +static int ieee80211_ioctl_siwauth(struct net_device *dev,
26428 + struct iw_request_info *info,
26429 + struct iw_param *data, char *extra)
26430 +{
26431 + struct ieee80211_local *local = dev->priv;
26432 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26433 + int ret = 0;
26434 +
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:
26441 + break;
26442 + case IW_AUTH_KEY_MGMT:
26443 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
26444 + ret = -EINVAL;
26445 + else {
26446 + /*
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.
26452 + */
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;
26459 + } else {
26460 + sdata->u.sta.key_mgmt =
26461 + IEEE80211_KEY_MGMT_NONE;
26462 + }
26463 + }
26464 + break;
26465 + case IW_AUTH_80211_AUTH_ALG:
26466 + if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
26467 + sdata->u.sta.auth_algs = data->value;
26468 + else
26469 + ret = -EOPNOTSUPP;
26470 + break;
26471 + case IW_AUTH_PRIVACY_INVOKED:
26472 + if (local->hw->set_privacy_invoked)
26473 + ret = local->hw->set_privacy_invoked(dev, data->value);
26474 + break;
26475 + default:
26476 + ret = -EOPNOTSUPP;
26477 + break;
26478 + }
26479 + return ret;
26480 +}
26481 +
26482 +
26483 +static int ieee80211_ioctl_giwauth(struct net_device *dev,
26484 + struct iw_request_info *info,
26485 + struct iw_param *data, char *extra)
26486 +{
26487 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26488 + int ret = 0;
26489 +
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;
26494 + else
26495 + ret = -EOPNOTSUPP;
26496 + break;
26497 + default:
26498 + ret = -EOPNOTSUPP;
26499 + break;
26500 + }
26501 + return ret;
26502 +}
26503 +
26504 +
26505 +static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
26506 + struct iw_request_info *info,
26507 + struct iw_point *erq, char *extra)
26508 +{
26509 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
26510 + struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
26511 + int alg, idx, i;
26512 +
26513 + switch (ext->alg) {
26514 + case IW_ENCODE_ALG_NONE:
26515 + alg = ALG_NONE;
26516 + break;
26517 + case IW_ENCODE_ALG_WEP:
26518 + alg = ALG_WEP;
26519 + break;
26520 + case IW_ENCODE_ALG_TKIP:
26521 + alg = ALG_TKIP;
26522 + break;
26523 + case IW_ENCODE_ALG_CCMP:
26524 + alg = ALG_CCMP;
26525 + break;
26526 + default:
26527 + return -EOPNOTSUPP;
26528 + }
26529 +
26530 + if (erq->flags & IW_ENCODE_DISABLED)
26531 + alg = ALG_NONE;
26532 +
26533 + idx = erq->flags & IW_ENCODE_INDEX;
26534 + if (idx < 1 || idx > 4) {
26535 + idx = -1;
26536 + if (sdata->default_key == NULL)
26537 + idx = 0;
26538 + else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
26539 + if (sdata->default_key == sdata->keys[i])
26540 + idx = i;
26541 + break;
26542 + }
26543 + if (idx < 0)
26544 + return -EINVAL;
26545 + } else
26546 + idx--;
26547 +
26548 + return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
26549 + ext->ext_flags &
26550 + IW_ENCODE_EXT_SET_TX_KEY,
26551 + NULL, ext->key, ext->key_len);
26552 +}
26553 +
26554 +
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" },
26563 +};
26564 +
26565 +
26566 +int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
26567 +{
26568 + struct iwreq *wrq = (struct iwreq *) rq;
26569 + int ret = 0;
26570 +
26571 + switch (cmd) {
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);
26577 + break;
26578 + case PRISM2_IOCTL_HOSTAPD:
26579 + if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
26580 + else ret = ieee80211_ioctl_priv_hostapd(dev, &wrq->u.data);
26581 + break;
26582 + default:
26583 + ret = -EOPNOTSUPP;
26584 + break;
26585 + }
26586 +
26587 + return ret;
26588 +}
26589 +
26590 +
26591 +/* Structures to export the Wireless Handlers */
26592 +
26593 +static const iw_handler ieee80211_handler[] =
26594 +{
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 -- */
26651 +};
26652 +
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 */
26657 +};
26658 +
26659 +const struct iw_handler_def ieee80211_iw_handler_def =
26660 +{
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,
26669 +};
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
26673 @@ -0,0 +1,83 @@
26674 +/*
26675 + * Copyright 2002-2004, Instant802 Networks, Inc.
26676 + * Copyright 2005, Devicescape Software, Inc.
26677 + *
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.
26681 + */
26682 +
26683 +#ifndef IEEE80211_KEY_H
26684 +#define IEEE80211_KEY_H
26685 +
26686 +#include <linux/types.h>
26687 +#include <net/d80211.h>
26688 +
26689 +/* ALG_TKIP
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)
26694 + */
26695 +
26696 +#define WEP_IV_LEN 4
26697 +#define WEP_ICV_LEN 4
26698 +
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
26706 +
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
26712 +
26713 +#define NUM_RX_DATA_QUEUES 17
26714 +
26715 +struct ieee80211_key {
26716 + int hw_key_idx; /* filled and used by low-level driver */
26717 + ieee80211_key_alg alg;
26718 + union {
26719 + struct {
26720 + /* last used TSC */
26721 + u32 iv32;
26722 + u16 iv16;
26723 + u16 p1k[5];
26724 + int tx_initialized;
26725 +
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];
26731 + } tkip;
26732 + struct {
26733 + u8 tx_pn[6];
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
26738 +#endif
26739 + u32 aes_state[AES_STATE_LEN];
26740 + u32 replays; /* dot11RSNAStatsCCMPReplays */
26741 + } ccmp;
26742 + } u;
26743 + int tx_rx_count; /* number of times this key has been used */
26744 + int keylen;
26745 +
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). */
26752 +
26753 + u8 key[0];
26754 +};
26755 +
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
26760 @@ -0,0 +1,32 @@
26761 +/*
26762 + * Copyright 2002-2004, Instant802 Networks, Inc.
26763 + *
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.
26767 + */
26768 +
26769 +#include <linux/config.h>
26770 +#include <linux/netdevice.h>
26771 +#include <linux/types.h>
26772 +
26773 +#ifdef CONFIG_OAP_LEDS_WLAN
26774 +extern void leds_wlan_set(int unit, int tx, int state);
26775 +#endif
26776 +
26777 +void ieee80211_rx_led(int state, struct net_device *dev) {
26778 +#ifdef CONFIG_OAP_LEDS_WLAN
26779 + static unsigned int count = 0;
26780 +
26781 + if (state == 2) {
26782 + leds_wlan_set(0, 0, (++count) & 1);
26783 + }
26784 +#endif
26785 +}
26786 +
26787 +void ieee80211_tx_led(int state, struct net_device *dev) {
26788 +#ifdef CONFIG_OAP_LEDS_WLAN
26789 + leds_wlan_set(0, 1, state);
26790 +#endif
26791 +}
26792 +
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
26796 @@ -0,0 +1,777 @@
26797 +/*
26798 + * Copyright 2003-2005, Devicescape Software, Inc.
26799 + *
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.
26803 + */
26804 +
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>
26811 +
26812 +#ifdef CONFIG_PROC_FS
26813 +
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"
26821 +
26822 +
26823 +static struct proc_dir_entry *ieee80211_proc;
26824 +
26825 +#define PROC_LIMIT (PAGE_SIZE - 80)
26826 +
26827 +
26828 +static char * ieee80211_proc_key(char *p, struct ieee80211_key *key,
26829 + int idx, int def_key)
26830 +{
26831 + int i;
26832 + u8 *tpn, *rpn;
26833 +
26834 + if (!key)
26835 + return p;
26836 +
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) {
26843 + case ALG_WEP:
26844 + p += sprintf(p, " alg=WEP");
26845 + break;
26846 + case ALG_TKIP:
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)
26852 + continue;
26853 + p += sprintf(p, " iv(rx %d)=%08x %04x", i,
26854 + key->u.tkip.iv32_rx[i],
26855 + key->u.tkip.iv16_rx[i]);
26856 + }
26857 + break;
26858 + case ALG_CCMP:
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)
26865 + continue;
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],
26868 + rpn[5]);
26869 + }
26870 + p += sprintf(p, " replays=%u", key->u.ccmp.replays);
26871 + break;
26872 + default:
26873 + break;
26874 + }
26875 +
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");
26880 + return p;
26881 +}
26882 +
26883 +
26884 +static char * ieee80211_proc_sub_if_ap(char *p,
26885 + struct ieee80211_if_ap *ap)
26886 +{
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);
26892 + p += sprintf(p,
26893 + "max_aid=%d\n"
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);
26905 + return p;
26906 +}
26907 +
26908 +
26909 +static char * ieee80211_proc_sub_if_sta(char *p,
26910 + struct ieee80211_if_sta *ifsta)
26911 +{
26912 + p += sprintf(p, "type=sta\n");
26913 + p += sprintf(p,
26914 + "state=%d\n"
26915 + "bssid=" MACSTR "\n"
26916 + "prev_bssid=" MACSTR "\n"
26917 + "ssid_len=%zd\n"
26918 + "aid=%d\n"
26919 + "ap_capab=0x%x\n"
26920 + "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"
26926 + "auth_alg=%d\n"
26927 + "auth_transaction=%d\n",
26928 + ifsta->state,
26929 + MAC2STR(ifsta->bssid),
26930 + MAC2STR(ifsta->prev_bssid),
26931 + ifsta->ssid_len,
26932 + ifsta->aid,
26933 + ifsta->ap_capab,
26934 + ifsta->capab,
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,
26946 + ifsta->auth_alg,
26947 + ifsta->auth_transaction);
26948 + return p;
26949 +}
26950 +
26951 +
26952 +static char * ieee80211_proc_sub_if(char *p,
26953 + struct ieee80211_sub_if_data *sdata)
26954 +{
26955 + if (sdata == NULL)
26956 + return p;
26957 +
26958 + if (sdata->bss)
26959 + p += sprintf(p, "bss=%p\n", sdata->bss);
26960 +
26961 + switch (sdata->type) {
26962 + case IEEE80211_SUB_IF_TYPE_AP:
26963 + p = ieee80211_proc_sub_if_ap(p, &sdata->u.ap);
26964 + break;
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));
26969 + break;
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);
26973 + break;
26974 + case IEEE80211_SUB_IF_TYPE_STA:
26975 + p = ieee80211_proc_sub_if_sta(p, &sdata->u.sta);
26976 + break;
26977 + }
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);
26982 +
26983 + return p;
26984 +}
26985 +
26986 +
26987 +static int ieee80211_proc_iface_read(char *page, char **start, off_t off,
26988 + int count, int *eof, void *data)
26989 +{
26990 + char *p = page;
26991 + struct net_device *dev = (struct net_device *) data;
26992 + struct ieee80211_sub_if_data *sdata;
26993 + int i;
26994 +
26995 + if (off != 0) {
26996 + *eof = 1;
26997 + return 0;
26998 + }
26999 +
27000 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
27001 + if (!sdata)
27002 + return -1;
27003 +
27004 + p = ieee80211_proc_sub_if(p, sdata);
27005 +
27006 + for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
27007 + if (sdata->keys[i] == NULL)
27008 + continue;
27009 +
27010 + p = ieee80211_proc_key(p, sdata->keys[i], i,
27011 + sdata->keys[i] == sdata->default_key);
27012 + }
27013 +
27014 + return (p - page);
27015 +}
27016 +
27017 +
27018 +static int ieee80211_proc_sta_read(char *page, char **start, off_t off,
27019 + int count, int *eof, void *data)
27020 +{
27021 + char *p = page;
27022 + struct sta_info *sta = (struct sta_info *) data;
27023 + struct ieee80211_local *local;
27024 + int inactive, i;
27025 +
27026 + if (off != 0) {
27027 + *eof = 1;
27028 + return 0;
27029 + }
27030 +
27031 + if (!sta || !sta->dev)
27032 + return -1;
27033 +
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);
27061 +
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);
27066 + }
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);
27071 + }
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");
27092 +
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]);
27101 + }
27102 + p += sprintf(p, "\n");
27103 +
27104 + p += rate_control_status_sta(local, sta, p);
27105 +
27106 + return (p - page);
27107 +}
27108 +
27109 +
27110 +static int ieee80211_proc_counters_read(char *page, char **start, off_t off,
27111 + int count, int *eof, void *data)
27112 +{
27113 + char *p = page;
27114 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27115 + struct ieee80211_low_level_stats stats;
27116 +
27117 + if (off != 0) {
27118 + *eof = 1;
27119 + return 0;
27120 + }
27121 +
27122 + p += sprintf(p,
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);
27143 +
27144 + memset(&stats, 0, sizeof(stats));
27145 + if (local->hw->get_stats &&
27146 + local->hw->get_stats(local->mdev, &stats) == 0) {
27147 + p += sprintf(p,
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);
27156 + }
27157 +
27158 + return (p - page);
27159 +}
27160 +
27161 +
27162 +static int ieee80211_proc_debug_read(char *page, char **start, off_t off,
27163 + int count, int *eof, void *data)
27164 +{
27165 + char *p = page;
27166 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27167 + int i;
27168 +
27169 + if (off != 0) {
27170 + *eof = 1;
27171 + return 0;
27172 + }
27173 +
27174 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
27175 + p += sprintf(p,
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);
27216 + {
27217 + int i;
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");
27222 +
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");
27227 + }
27228 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
27229 +
27230 + p += sprintf(p, "num_scans=%u\n", local->scan.num_scans);
27231 +
27232 + p += sprintf(p,
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");
27241 + }
27242 +
27243 + return (p - page);
27244 +}
27245 +
27246 +
27247 +static const char * ieee80211_mode_str_short(int mode)
27248 +{
27249 + switch (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";
27258 + default:
27259 + return "UNKNOWN";
27260 + }
27261 +}
27262 +
27263 +
27264 +static const char * ieee80211_mode_str(int mode)
27265 +{
27266 + switch (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)";
27275 + default:
27276 + return "UNKNOWN";
27277 + }
27278 +}
27279 +
27280 +
27281 +static int ieee80211_proc_info_read(char *page, char **start, off_t off,
27282 + int count, int *eof, void *data)
27283 +{
27284 + char *p = page;
27285 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27286 + int m;
27287 + struct ieee80211_hw_modes *mode;
27288 +
27289 + if (off != 0) {
27290 + *eof = 1;
27291 + return 0;
27292 + }
27293 +
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));
27299 + }
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);
27304 +}
27305 +
27306 +
27307 +static int ieee80211_proc_config_read(char *page, char **start, off_t off,
27308 + int count, int *eof, void *data)
27309 +{
27310 + char *p = page;
27311 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27312 +
27313 + if (off != 0) {
27314 + *eof = 1;
27315 + return 0;
27316 + }
27317 +
27318 + p += sprintf(p,
27319 + "low_level_driver=%s\n"
27320 + "channel=%d\n"
27321 + "freq=%d\n"
27322 + "mode=%s\n"
27323 + "802.11h=%d\n"
27324 + "wep_iv=0x%06x\n"
27325 + "antenna_sel=%d\n"
27326 + "calib_int=%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);
27352 +
27353 + return (p - page);
27354 +}
27355 +
27356 +
27357 +static int ieee80211_proc_channels_read(char *page, char **start, off_t off,
27358 + int count, int *eof, void *data)
27359 +{
27360 + char *p = page;
27361 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27362 + int m, c;
27363 + struct ieee80211_hw_modes *mode;
27364 + struct ieee80211_channel *chan;
27365 +
27366 + if (off != 0) {
27367 + *eof = 1;
27368 + return 0;
27369 + }
27370 +
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 ?
27380 + "[W_SCAN]" : "",
27381 + chan->flag & IEEE80211_CHAN_W_ACTIVE_SCAN
27382 + ? "[W_ACTIVE_SCAN]" : "",
27383 + chan->flag & IEEE80211_CHAN_W_IBSS ?
27384 + "[W_IBSS]" : "");
27385 + }
27386 + }
27387 + return (p - page);
27388 +}
27389 +
27390 +
27391 +static int ieee80211_proc_rates_read(char *page, char **start, off_t off,
27392 + int count, int *eof, void *data)
27393 +{
27394 + char *p = page;
27395 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27396 + int r;
27397 + struct ieee80211_rate *rate;
27398 +
27399 + if (off != 0) {
27400 + *eof = 1;
27401 + return 0;
27402 + }
27403 +
27404 + p += sprintf(p, "RATE VAL VAL2 MIN_RSSI_ACK MIN_RSSI_ACK_DELTA "
27405 + "FLAGS\n");
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,
27411 + rate->flags,
27412 + rate->flags & IEEE80211_RATE_ERP ? "[ERP]" : "",
27413 + rate->flags & IEEE80211_RATE_BASIC ?
27414 + "[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 ?
27422 + "[TURBO]" : "",
27423 + rate->flags & IEEE80211_RATE_MANDATORY ?
27424 + "[MANDATORY]" : "");
27425 + }
27426 + return (p - page);
27427 +}
27428 +
27429 +
27430 +static int ieee80211_proc_multicast_read(char *page, char **start, off_t off,
27431 + int count, int *eof, void *data)
27432 +{
27433 + char *p = page;
27434 + struct ieee80211_local *local = (struct ieee80211_local *) data;
27435 +
27436 + if (off != 0) {
27437 + *eof = 1;
27438 + return 0;
27439 + }
27440 +
27441 + return rate_control_status_global(local, p);
27442 +
27443 +}
27444 +
27445 +
27446 +void ieee80211_proc_init_sta(struct ieee80211_local *local,
27447 + struct sta_info *sta)
27448 +{
27449 + char buf[30];
27450 + struct proc_dir_entry *entry;
27451 +
27452 + sprintf(buf, MACSTR, MAC2STR(sta->addr));
27453 +
27454 + if (!local->proc_sta)
27455 + return;
27456 +
27457 + entry = create_proc_read_entry(buf, 0, local->proc_sta,
27458 + ieee80211_proc_sta_read, sta);
27459 + if (entry) {
27460 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27461 + sta->proc_entry_added = 1;
27462 + }
27463 +}
27464 +
27465 +
27466 +void ieee80211_proc_deinit_sta(struct ieee80211_local *local,
27467 + struct sta_info *sta)
27468 +{
27469 + char buf[30];
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;
27474 + }
27475 +}
27476 +
27477 +
27478 +void ieee80211_proc_init_virtual(struct net_device *dev)
27479 +{
27480 + struct proc_dir_entry *entry;
27481 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27482 +
27483 + if (!local->proc_iface)
27484 + return;
27485 +
27486 + entry = create_proc_read_entry(dev->name, 0, local->proc_iface,
27487 + ieee80211_proc_iface_read, dev);
27488 + if (entry)
27489 + entry->mode &= ~(S_IRWXG | S_IRWXO);
27490 +}
27491 +
27492 +
27493 +void ieee80211_proc_deinit_virtual(struct net_device *dev)
27494 +{
27495 + struct ieee80211_local *local = (struct ieee80211_local *) dev->priv;
27496 +
27497 + if (local->proc_iface)
27498 + remove_proc_entry(dev->name, local->proc_iface);
27499 +}
27500 +
27501 +
27502 +void ieee80211_proc_init_interface(struct ieee80211_local *local)
27503 +{
27504 + if (!ieee80211_proc)
27505 + return;
27506 +
27507 + local->proc = proc_mkdir(local->wdev->name, ieee80211_proc);
27508 + if (!local->proc)
27509 + return;
27510 +
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);
27528 +}
27529 +
27530 +
27531 +void ieee80211_proc_deinit_interface(struct ieee80211_local *local)
27532 +{
27533 + if (!local->proc)
27534 + return;
27535 +
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);
27548 +}
27549 +
27550 +
27551 +void ieee80211_proc_init(void)
27552 +{
27553 + if (proc_net == NULL) {
27554 + ieee80211_proc = NULL;
27555 + return;
27556 + }
27557 +
27558 + ieee80211_proc = proc_mkdir("ieee80211", proc_net);
27559 + if (!ieee80211_proc)
27560 + printk(KERN_WARNING "Failed to mkdir /proc/net/ieee80211\n");
27561 +}
27562 +
27563 +
27564 +void ieee80211_proc_deinit(void)
27565 +{
27566 + if (!ieee80211_proc)
27567 + return;
27568 +
27569 + ieee80211_proc = NULL;
27570 + remove_proc_entry("ieee80211", proc_net);
27571 +}
27572 +
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
27577 @@ -0,0 +1,45 @@
27578 +/*
27579 + * Copyright 2003-2004, Instant802 Networks, Inc.
27580 + *
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.
27584 + */
27585 +
27586 +#ifndef IEEE80211_PROC_H
27587 +#define IEEE80211_PROC_H
27588 +
27589 +#include <linux/netdevice.h>
27590 +#include "ieee80211_i.h"
27591 +#include "sta_info.h"
27592 +
27593 +#ifdef CONFIG_PROC_FS
27594 +
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);
27605 +
27606 +#else /* CONFIG_PROC_FS */
27607 +
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 */
27621 +
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
27626 @@ -0,0 +1,352 @@
27627 +/*
27628 + * Copyright 2002-2004, Instant802 Networks, Inc.
27629 + *
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.
27633 + */
27634 +
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>
27642 +
27643 +#include <net/d80211.h>
27644 +#include "ieee80211_i.h"
27645 +#include "rate_control.h"
27646 +
27647 +
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
27653 +
27654 +static void get_channel_params(struct ieee80211_local *local, int channel,
27655 + struct ieee80211_hw_modes **mode,
27656 + struct ieee80211_channel **chan)
27657 +{
27658 + int m;
27659 +
27660 + for (m = 0; m < local->hw->num_modes; m++) {
27661 + *mode = &local->hw->modes[m];
27662 + if ((*mode)->mode == local->conf.phymode)
27663 + break;
27664 + }
27665 + local->scan.mode_idx = m;
27666 + local->scan.chan_idx = 0;
27667 + do {
27668 + *chan = &(*mode)->channels[local->scan.chan_idx];
27669 + if ((*chan)->chan == channel) {
27670 + return;
27671 + }
27672 + local->scan.chan_idx++;
27673 + } while (local->scan.chan_idx < (*mode)->num_channels);
27674 + *chan = NULL;
27675 +}
27676 +
27677 +
27678 +static void next_chan_same_mode(struct ieee80211_local *local,
27679 + struct ieee80211_hw_modes **mode,
27680 + struct ieee80211_channel **chan)
27681 +{
27682 + int m, prev;
27683 +
27684 + for (m = 0; m < local->hw->num_modes; m++) {
27685 + *mode = &local->hw->modes[m];
27686 + if ((*mode)->mode == local->conf.phymode)
27687 + break;
27688 + }
27689 + local->scan.mode_idx = m;
27690 +
27691 + /* Select next channel - scan only channels marked with W_SCAN flag */
27692 + prev = local->scan.chan_idx;
27693 + do {
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)
27699 + break;
27700 + } while (local->scan.chan_idx != prev);
27701 +}
27702 +
27703 +
27704 +static void next_chan_all_modes(struct ieee80211_local *local,
27705 + struct ieee80211_hw_modes **mode,
27706 + struct ieee80211_channel **chan)
27707 +{
27708 + int prev, prev_m;
27709 +
27710 + if (local->scan.mode_idx >= local->hw->num_modes) {
27711 + local->scan.mode_idx = 0;
27712 + local->scan.chan_idx = 0;
27713 + }
27714 +
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;
27718 + do {
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];
27727 + }
27728 + *chan = &(*mode)->channels[local->scan.chan_idx];
27729 + if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
27730 + break;
27731 + } while (local->scan.chan_idx != prev ||
27732 + local->scan.mode_idx != prev_m);
27733 +}
27734 +
27735 +
27736 +static void ieee80211_scan_start(struct net_device *dev,
27737 + struct ieee80211_scan_conf *conf)
27738 +{
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;
27744 + int ret;
27745 +
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",
27749 + dev->name);
27750 + return;
27751 + }
27752 +
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
27758 + * threshold. */
27759 + local->scan.txrx_count = 0;
27760 + local->scan.timer.expires = jiffies + HZ;
27761 + add_timer(&local->scan.timer);
27762 + return;
27763 + }
27764 +
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);
27768 + }
27769 +
27770 + if (local->scan.our_mode_only) {
27771 + if (local->scan.channel > 0) {
27772 + get_channel_params(local, local->scan.channel, &mode,
27773 + &chan);
27774 + } else
27775 + next_chan_same_mode(local, &mode, &chan);
27776 + }
27777 + else
27778 + next_chan_all_modes(local, &mode, &chan);
27779 +
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;
27791 +#if 0
27792 + printk(KERN_DEBUG "%s: Doing scan on mode: %d freq: %d chan: %d "
27793 + "for %d ms\n",
27794 + dev->name, conf->scan_phymode, conf->scan_freq,
27795 + conf->scan_channel, conf->scan_time);
27796 +#endif
27797 + local->scan.rx_packets = 0;
27798 + local->scan.rx_beacon = 0;
27799 + local->scan.freq = chan->freq;
27800 + local->scan.in_scan = 1;
27801 +
27802 + ieee80211_netif_oper(dev, NETIF_STOP);
27803 +
27804 + ret = local->hw->passive_scan(dev, IEEE80211_SCAN_START, conf);
27805 +
27806 + if (ret == 0) {
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;
27812 + } else {
27813 + local->scan.in_scan = 0;
27814 + if (conf->skb)
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;
27822 + } else {
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);
27827 + }
27828 + local->scan.in_scan = 0;
27829 + }
27830 +
27831 + add_timer(&local->scan.timer);
27832 +}
27833 +
27834 +
27835 +static void ieee80211_scan_stop(struct net_device *dev,
27836 + struct ieee80211_scan_conf *conf)
27837 +{
27838 + struct ieee80211_local *local = dev->priv;
27839 + struct ieee80211_hw_modes *mode;
27840 + struct ieee80211_channel *chan;
27841 + int wait;
27842 +
27843 + if (local->hw->passive_scan == NULL)
27844 + return;
27845 +
27846 + if (local->scan.mode_idx >= local->hw->num_modes) {
27847 + local->scan.mode_idx = 0;
27848 + local->scan.chan_idx = 0;
27849 + }
27850 +
27851 + mode = &local->hw->modes[local->scan.mode_idx];
27852 +
27853 + if (local->scan.chan_idx >= mode->num_channels) {
27854 + local->scan.chan_idx = 0;
27855 + }
27856 +
27857 + chan = &mode->channels[local->scan.chan_idx];
27858 +
27859 + local->hw->passive_scan(dev, IEEE80211_SCAN_END, conf);
27860 +
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",
27864 + dev->name,
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++;
27870 +
27871 + local->scan.in_scan = 0;
27872 + ieee80211_netif_oper(dev, NETIF_WAKE);
27873 +
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)) /
27877 + 128;
27878 + local->scan.timer.expires = jiffies + wait;
27879 +
27880 + add_timer(&local->scan.timer);
27881 +}
27882 +
27883 +
27884 +static void ieee80211_scan_handler(unsigned long uldev)
27885 +{
27886 + struct net_device *dev = (struct net_device *) uldev;
27887 + struct ieee80211_local *local = dev->priv;
27888 + struct ieee80211_scan_conf conf;
27889 +
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);
27895 + return;
27896 + }
27897 +
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;
27905 +
27906 + if (local->scan.in_scan == 0)
27907 + ieee80211_scan_start(dev, &conf);
27908 + else
27909 + ieee80211_scan_stop(dev, &conf);
27910 +}
27911 +
27912 +
27913 +void ieee80211_init_scan(struct net_device *dev)
27914 +{
27915 + struct ieee80211_local *local = dev->priv;
27916 + struct ieee80211_hdr hdr;
27917 + u16 fc;
27918 + int len = 10;
27919 + struct rate_control_extra extra;
27920 +
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);
27928 + return;
27929 + }
27930 +
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);
27938 +
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);
27945 + return;
27946 + }
27947 +
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;
27955 +
27956 + memcpy(skb_put(local->scan.skb, len), &hdr, len);
27957 +
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;
27966 +}
27967 +
27968 +
27969 +void ieee80211_stop_scan(struct net_device *dev)
27970 +{
27971 + struct ieee80211_local *local = dev->priv;
27972 +
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;
27977 + }
27978 +}
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
27982 @@ -0,0 +1,2866 @@
27983 +/*
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.
27988 + *
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.
27992 + */
27993 +
27994 +/* TODO:
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,
27998 + * SSID)
27999 + */
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>
28011 +
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"
28017 +
28018 +/* #define IEEE80211_IBSS_DEBUG */
28019 +
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)
28030 +
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)
28037 +
28038 +#define IEEE80211_IBSS_MAX_STA_ENTRIES 128
28039 +
28040 +
28041 +#define IEEE80211_FC(type, stype) cpu_to_le16((type << 2) | (stype << 4))
28042 +
28043 +#define ERP_INFO_USE_PROTECTION BIT(1)
28044 +
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);
28054 +
28055 +
28056 +/* Parsed Information Elements */
28057 +struct ieee802_11_elems {
28058 + u8 *ssid;
28059 + u8 ssid_len;
28060 + u8 *supp_rates;
28061 + u8 supp_rates_len;
28062 + u8 *fh_params;
28063 + u8 fh_params_len;
28064 + u8 *ds_params;
28065 + u8 ds_params_len;
28066 + u8 *cf_params;
28067 + u8 cf_params_len;
28068 + u8 *tim;
28069 + u8 tim_len;
28070 + u8 *ibss_params;
28071 + u8 ibss_params_len;
28072 + u8 *challenge;
28073 + u8 challenge_len;
28074 + u8 *wpa;
28075 + u8 wpa_len;
28076 + u8 *rsn;
28077 + u8 rsn_len;
28078 + u8 *erp_info;
28079 + u8 erp_info_len;
28080 + u8 *ext_supp_rates;
28081 + u8 ext_supp_rates_len;
28082 + u8 *wmm_info;
28083 + u8 wmm_info_len;
28084 + u8 *wmm_param;
28085 + u8 wmm_param_len;
28086 +};
28087 +
28088 +typedef enum { ParseOK = 0, ParseUnknown = 1, ParseFailed = -1 } ParseRes;
28089 +
28090 +
28091 +static ParseRes ieee802_11_parse_elems(u8 *start, size_t len,
28092 + struct ieee802_11_elems *elems)
28093 +{
28094 + size_t left = len;
28095 + u8 *pos = start;
28096 + int unknown = 0;
28097 +
28098 + memset(elems, 0, sizeof(*elems));
28099 +
28100 + while (left >= 2) {
28101 + u8 id, elen;
28102 +
28103 + id = *pos++;
28104 + elen = *pos++;
28105 + left -= 2;
28106 +
28107 + if (elen > left) {
28108 +#if 0
28109 + if (net_ratelimit())
28110 + printk(KERN_DEBUG "IEEE 802.11 element parse "
28111 + "failed (id=%d elen=%d left=%d)\n",
28112 + id, elen, left);
28113 +#endif
28114 + return ParseFailed;
28115 + }
28116 +
28117 + switch (id) {
28118 + case WLAN_EID_SSID:
28119 + elems->ssid = pos;
28120 + elems->ssid_len = elen;
28121 + break;
28122 + case WLAN_EID_SUPP_RATES:
28123 + elems->supp_rates = pos;
28124 + elems->supp_rates_len = elen;
28125 + break;
28126 + case WLAN_EID_FH_PARAMS:
28127 + elems->fh_params = pos;
28128 + elems->fh_params_len = elen;
28129 + break;
28130 + case WLAN_EID_DS_PARAMS:
28131 + elems->ds_params = pos;
28132 + elems->ds_params_len = elen;
28133 + break;
28134 + case WLAN_EID_CF_PARAMS:
28135 + elems->cf_params = pos;
28136 + elems->cf_params_len = elen;
28137 + break;
28138 + case WLAN_EID_TIM:
28139 + elems->tim = pos;
28140 + elems->tim_len = elen;
28141 + break;
28142 + case WLAN_EID_IBSS_PARAMS:
28143 + elems->ibss_params = pos;
28144 + elems->ibss_params_len = elen;
28145 + break;
28146 + case WLAN_EID_CHALLENGE:
28147 + elems->challenge = pos;
28148 + elems->challenge_len = elen;
28149 + break;
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;
28165 + }
28166 + }
28167 + }
28168 + break;
28169 + case WLAN_EID_RSN:
28170 + elems->rsn = pos;
28171 + elems->rsn_len = elen;
28172 + break;
28173 + case WLAN_EID_ERP_INFO:
28174 + elems->erp_info = pos;
28175 + elems->erp_info_len = elen;
28176 + break;
28177 + case WLAN_EID_EXT_SUPP_RATES:
28178 + elems->ext_supp_rates = pos;
28179 + elems->ext_supp_rates_len = elen;
28180 + break;
28181 + default:
28182 +#if 0
28183 + printk(KERN_DEBUG "IEEE 802.11 element parse ignored "
28184 + "unknown element (id=%d elen=%d)\n",
28185 + id, elen);
28186 +#endif
28187 + unknown++;
28188 + break;
28189 + }
28190 +
28191 + left -= elen;
28192 + pos += elen;
28193 + }
28194 +
28195 + /* Do not trigger error if left == 1 as Apple Airport base stations
28196 + * send AssocResps that are one spurious byte too long. */
28197 +
28198 + return unknown ? ParseUnknown : ParseOK;
28199 +}
28200 +
28201 +
28202 +
28203 +
28204 +static int ecw2cw(int ecw)
28205 +{
28206 + int cw = 1;
28207 + while (ecw > 0) {
28208 + cw <<= 1;
28209 + ecw--;
28210 + }
28211 + return cw - 1;
28212 +}
28213 +
28214 +
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)
28218 +{
28219 + struct ieee80211_local *local = dev->priv;
28220 + struct ieee80211_tx_queue_params params;
28221 + size_t left;
28222 + int count;
28223 + u8 *pos;
28224 +
28225 + if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
28226 + return;
28227 + count = wmm_param[6] & 0x0f;
28228 + if (count == ifsta->wmm_last_param_set)
28229 + return;
28230 + ifsta->wmm_last_param_set = count;
28231 +
28232 + pos = wmm_param + 8;
28233 + left = wmm_param_len - 8;
28234 +
28235 + memset(&params, 0, sizeof(params));
28236 +
28237 + if (local->hw->conf_tx == NULL)
28238 + return;
28239 +
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;
28244 + int queue;
28245 +
28246 + switch (aci) {
28247 + case 1:
28248 + queue = IEEE80211_TX_QUEUE_DATA3;
28249 + if (acm) {
28250 + local->wmm_acm |= BIT(1) | BIT(2);
28251 + }
28252 + break;
28253 + case 2:
28254 + queue = IEEE80211_TX_QUEUE_DATA1;
28255 + if (acm) {
28256 + local->wmm_acm |= BIT(4) | BIT(5);
28257 + }
28258 + break;
28259 + case 3:
28260 + queue = IEEE80211_TX_QUEUE_DATA0;
28261 + if (acm) {
28262 + local->wmm_acm |= BIT(6) | BIT(7);
28263 + }
28264 + break;
28265 + case 0:
28266 + default:
28267 + queue = IEEE80211_TX_QUEUE_DATA2;
28268 + if (acm) {
28269 + local->wmm_acm |= BIT(0) | BIT(3);
28270 + }
28271 + break;
28272 + }
28273 +
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
28284 + * AC for now) */
28285 + if (local->hw->conf_tx(local->mdev, queue, &params)) {
28286 + printk(KERN_DEBUG "%s: failed to set TX queue "
28287 + "parameters for queue %d\n", dev->name, queue);
28288 + }
28289 + }
28290 +}
28291 +
28292 +
28293 +static void ieee80211_sta_send_associnfo(struct net_device *dev,
28294 + struct ieee80211_if_sta *ifsta)
28295 +{
28296 + char *buf;
28297 + size_t len;
28298 + int i;
28299 + union iwreq_data wrqu;
28300 +
28301 + if (ifsta->assocreq_ies == NULL && ifsta->assocresp_ies == NULL)
28302 + return;
28303 +
28304 + buf = kmalloc(50 + 2 * (ifsta->assocreq_ies_len +
28305 + ifsta->assocresp_ies_len), GFP_ATOMIC);
28306 + if (buf == NULL)
28307 + return;
28308 +
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]);
28315 + }
28316 + }
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]);
28324 + }
28325 + }
28326 + len += sprintf(buf + len, ")");
28327 +
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]);
28333 + }
28334 + }
28335 +
28336 + memset(&wrqu, 0, sizeof(wrqu));
28337 + wrqu.data.length = len;
28338 + wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
28339 +
28340 + kfree(buf);
28341 +}
28342 +
28343 +
28344 +static void ieee80211_set_associated(struct net_device *dev,
28345 + struct ieee80211_if_sta *ifsta, int assoc)
28346 +{
28347 + union iwreq_data wrqu;
28348 +
28349 + if (ifsta->associated == assoc)
28350 + return;
28351 +
28352 + ifsta->associated = assoc;
28353 +
28354 + if (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)
28358 + return;
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);
28363 + } else {
28364 + memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
28365 + }
28366 + wrqu.ap_addr.sa_family = ARPHRD_ETHER;
28367 + wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
28368 + ifsta->last_probe = jiffies;
28369 +}
28370 +
28371 +
28372 +static void ieee80211_sta_tx(struct net_device *dev, struct sk_buff *skb,
28373 + int encrypt, int probe_resp)
28374 +{
28375 + struct ieee80211_sub_if_data *sdata;
28376 + struct ieee80211_tx_packet_data *pkt_data;
28377 +
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;
28381 +
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;
28386 + if (probe_resp)
28387 + pkt_data->pkt_probe_resp = 1;
28388 +
28389 + dev_queue_xmit(skb);
28390 +}
28391 +
28392 +
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,
28396 + int encrypt)
28397 +{
28398 + struct sk_buff *skb;
28399 + struct ieee80211_mgmt *mgmt;
28400 +
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);
28405 + return;
28406 + }
28407 +
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);
28412 + if (encrypt)
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);
28421 + if (extra)
28422 + memcpy(skb_put(skb, extra_len), extra, extra_len);
28423 +
28424 + ieee80211_sta_tx(dev, skb, encrypt, 0);
28425 +}
28426 +
28427 +
28428 +static void ieee80211_authenticate(struct net_device *dev,
28429 + struct ieee80211_if_sta *ifsta)
28430 +{
28431 + ifsta->auth_tries++;
28432 + if (ifsta->auth_tries > IEEE80211_AUTH_MAX_TRIES) {
28433 + printk(KERN_DEBUG "%s: authentication with AP " MACSTR
28434 + " timed out\n",
28435 + dev->name, MAC2STR(ifsta->bssid));
28436 + return;
28437 + }
28438 +
28439 + ifsta->state = IEEE80211_AUTHENTICATE;
28440 + printk(KERN_DEBUG "%s: authenticate with AP " MACSTR "\n",
28441 + dev->name, MAC2STR(ifsta->bssid));
28442 +
28443 + ieee80211_send_auth(dev, ifsta, 1, NULL, 0, 0);
28444 +
28445 + mod_timer(&ifsta->timer, jiffies + IEEE80211_AUTH_TIMEOUT);
28446 +}
28447 +
28448 +
28449 +static void ieee80211_send_assoc(struct net_device *dev,
28450 + struct ieee80211_if_sta *ifsta)
28451 +{
28452 + struct ieee80211_local *local = dev->priv;
28453 + struct sk_buff *skb;
28454 + struct ieee80211_mgmt *mgmt;
28455 + u8 *pos, *ies;
28456 + int i, len;
28457 + u16 capab;
28458 + struct ieee80211_sta_bss *bss;
28459 + int wmm = 0;
28460 +
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);
28466 + return;
28467 + }
28468 +
28469 + capab = ifsta->capab;
28470 + if (local->conf.phymode == MODE_IEEE80211G) {
28471 + capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME |
28472 + WLAN_CAPABILITY_SHORT_PREAMBLE;
28473 + }
28474 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28475 + if (bss) {
28476 + if (bss->capability & WLAN_CAPABILITY_PRIVACY)
28477 + capab |= WLAN_CAPABILITY_PRIVACY;
28478 + if (bss->wmm_ie) {
28479 + wmm = 1;
28480 + }
28481 + ieee80211_rx_bss_put(dev, bss);
28482 + }
28483 +
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);
28489 +
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,
28497 + ETH_ALEN);
28498 + } else {
28499 + skb_put(skb, 4);
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);
28504 + }
28505 +
28506 + /* SSID */
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);
28511 +
28512 + len = local->num_curr_rates;
28513 + if (len > 8)
28514 + len = 8;
28515 + pos = skb_put(skb, len + 2);
28516 + *pos++ = WLAN_EID_SUPP_RATES;
28517 + *pos++ = len;
28518 + for (i = 0; i < len; i++) {
28519 + int rate = local->curr_rates[i].rate;
28520 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28521 + rate /= 2;
28522 + *pos++ = (u8) (rate / 5);
28523 + }
28524 +
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)
28532 + rate /= 2;
28533 + *pos++ = (u8) (rate / 5);
28534 + }
28535 + }
28536 +
28537 + if (ifsta->extra_ie) {
28538 + pos = skb_put(skb, ifsta->extra_ie_len);
28539 + memcpy(pos, ifsta->extra_ie, ifsta->extra_ie_len);
28540 + }
28541 +
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 */
28547 + *pos++ = 0x50;
28548 + *pos++ = 0xf2;
28549 + *pos++ = 2; /* WME */
28550 + *pos++ = 0; /* WME info */
28551 + *pos++ = 1; /* WME ver */
28552 + *pos++ = 0;
28553 + }
28554 +
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);
28560 +
28561 + ieee80211_sta_tx(dev, skb, 0, 0);
28562 +}
28563 +
28564 +
28565 +static void ieee80211_send_deauth(struct net_device *dev,
28566 + struct ieee80211_if_sta *ifsta, u16 reason)
28567 +{
28568 + struct sk_buff *skb;
28569 + struct ieee80211_mgmt *mgmt;
28570 +
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);
28575 + return;
28576 + }
28577 +
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);
28585 + skb_put(skb, 2);
28586 + mgmt->u.deauth.reason_code = cpu_to_le16(reason);
28587 +
28588 + ieee80211_sta_tx(dev, skb, 0, 0);
28589 +}
28590 +
28591 +
28592 +static void ieee80211_send_disassoc(struct net_device *dev,
28593 + struct ieee80211_if_sta *ifsta, u16 reason)
28594 +{
28595 + struct sk_buff *skb;
28596 + struct ieee80211_mgmt *mgmt;
28597 +
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);
28602 + return;
28603 + }
28604 +
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);
28612 + skb_put(skb, 2);
28613 + mgmt->u.disassoc.reason_code = cpu_to_le16(reason);
28614 +
28615 + ieee80211_sta_tx(dev, skb, 0, 0);
28616 +}
28617 +
28618 +
28619 +static int ieee80211_privacy_mismatch(struct net_device *dev,
28620 + struct ieee80211_if_sta *ifsta)
28621 +{
28622 + struct ieee80211_sta_bss *bss;
28623 + int res = 0;
28624 +
28625 + if (ifsta == NULL || ifsta->mixed_cell ||
28626 + ifsta->key_mgmt != IEEE80211_KEY_MGMT_NONE)
28627 + return 0;
28628 +
28629 + bss = ieee80211_rx_bss_get(dev, ifsta->bssid);
28630 + if (bss == NULL)
28631 + return 0;
28632 +
28633 + if (ieee80211_sta_wep_configured(dev) !=
28634 + !!(bss->capability & WLAN_CAPABILITY_PRIVACY))
28635 + res = 1;
28636 +
28637 + ieee80211_rx_bss_put(dev, bss);
28638 +
28639 + return res;
28640 +}
28641 +
28642 +
28643 +static void ieee80211_associate(struct net_device *dev,
28644 + struct ieee80211_if_sta *ifsta)
28645 +{
28646 + ifsta->assoc_tries++;
28647 + if (ifsta->assoc_tries > IEEE80211_ASSOC_MAX_TRIES) {
28648 + printk(KERN_DEBUG "%s: association with AP " MACSTR
28649 + " timed out\n",
28650 + dev->name, MAC2STR(ifsta->bssid));
28651 + return;
28652 + }
28653 +
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);
28660 + return;
28661 + }
28662 +
28663 + ieee80211_send_assoc(dev, ifsta);
28664 +
28665 + mod_timer(&ifsta->timer, jiffies + IEEE80211_ASSOC_TIMEOUT);
28666 +}
28667 +
28668 +
28669 +static void ieee80211_associated(struct net_device *dev,
28670 + struct ieee80211_if_sta *ifsta)
28671 +{
28672 + struct ieee80211_local *local = dev->priv;
28673 + struct sta_info *sta;
28674 + int disassoc;
28675 +
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 */
28680 +
28681 + ifsta->state = IEEE80211_ASSOCIATED;
28682 +
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));
28687 + disassoc = 1;
28688 + } else {
28689 + disassoc = 0;
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 "
28695 + "range\n",
28696 + dev->name, MAC2STR(ifsta->bssid));
28697 + disassoc = 1;
28698 + } else {
28699 + ieee80211_send_probe_req(dev, ifsta->bssid,
28700 + local->scan_ssid,
28701 + local->scan_ssid_len);
28702 + ifsta->probereq_poll = 1;
28703 + }
28704 + } else {
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,
28710 + ifsta->ssid,
28711 + ifsta->ssid_len);
28712 + }
28713 + }
28714 + sta_info_release(local, sta);
28715 + }
28716 + if (disassoc) {
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);
28723 + } else {
28724 + mod_timer(&ifsta->timer,
28725 + jiffies + IEEE80211_MONITORING_INTERVAL);
28726 + }
28727 +}
28728 +
28729 +
28730 +static void ieee80211_send_probe_req(struct net_device *dev, u8 *dst,
28731 + u8 *ssid, size_t ssid_len)
28732 +{
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;
28737 + int i;
28738 +
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);
28743 + return;
28744 + }
28745 +
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);
28751 + if (dst) {
28752 + memcpy(mgmt->da, dst, ETH_ALEN);
28753 + memcpy(mgmt->bssid, dst, ETH_ALEN);
28754 + } else {
28755 + memset(mgmt->da, 0xff, ETH_ALEN);
28756 + memset(mgmt->bssid, 0xff, ETH_ALEN);
28757 + }
28758 + pos = skb_put(skb, 2 + ssid_len);
28759 + *pos++ = WLAN_EID_SSID;
28760 + *pos++ = ssid_len;
28761 + memcpy(pos, ssid, ssid_len);
28762 +
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))
28769 + continue;
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];
28778 + } else {
28779 + pos = skb_put(skb, 1);
28780 + supp_rates[1]++;
28781 + }
28782 + if (local->conf.phymode == MODE_ATHEROS_TURBO)
28783 + *pos = rate->rate / 10;
28784 + else
28785 + *pos = rate->rate / 5;
28786 + }
28787 +
28788 + ieee80211_sta_tx(dev, skb, 0, 0);
28789 +}
28790 +
28791 +
28792 +static int ieee80211_sta_wep_configured(struct net_device *dev)
28793 +{
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)
28797 + return 0;
28798 + return 1;
28799 +}
28800 +
28801 +
28802 +static void ieee80211_auth_completed(struct net_device *dev,
28803 + struct ieee80211_if_sta *ifsta)
28804 +{
28805 + printk(KERN_DEBUG "%s: authenticated\n", dev->name);
28806 + ifsta->authenticated = 1;
28807 + ieee80211_associate(dev, ifsta);
28808 +}
28809 +
28810 +
28811 +static void ieee80211_auth_challenge(struct net_device *dev,
28812 + struct ieee80211_if_sta *ifsta,
28813 + struct ieee80211_mgmt *mgmt,
28814 + size_t len,
28815 + struct ieee80211_rx_status *rx_status)
28816 +{
28817 + u8 *pos;
28818 + struct ieee802_11_elems elems;
28819 +
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",
28825 + dev->name);
28826 + return;
28827 + }
28828 + if (elems.challenge == NULL) {
28829 + printk(KERN_DEBUG "%s: no challenge IE in shared key auth "
28830 + "frame\n", dev->name);
28831 + return;
28832 + }
28833 + ieee80211_send_auth(dev, ifsta, 3, elems.challenge - 2,
28834 + elems.challenge_len + 2, 1);
28835 +}
28836 +
28837 +
28838 +static void ieee80211_rx_mgmt_auth(struct net_device *dev,
28839 + struct ieee80211_if_sta *ifsta,
28840 + struct ieee80211_mgmt *mgmt,
28841 + size_t len,
28842 + struct ieee80211_rx_status *rx_status)
28843 +{
28844 + struct ieee80211_local *local = dev->priv;
28845 + u16 auth_alg, auth_transaction, status_code;
28846 +
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));
28852 + return;
28853 + }
28854 +
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));
28859 + return;
28860 + }
28861 +
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));
28868 + return;
28869 + }
28870 +
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));
28877 + return;
28878 + }
28879 +
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);
28883 +
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);
28888 +
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);
28899 + return;
28900 + }
28901 + ieee80211_send_auth(dev, ifsta, 2, NULL, 0, 0);
28902 + }
28903 +
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);
28909 + return;
28910 + }
28911 +
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];
28918 + int i, pos;
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)
28927 + pos = 0;
28928 + else if (ifsta->auth_alg == WLAN_AUTH_SHARED_KEY)
28929 + pos = 1;
28930 + else
28931 + pos = 2;
28932 + for (i = 0; i < num_algs; i++) {
28933 + pos++;
28934 + if (pos >= num_algs)
28935 + pos = 0;
28936 + if (algs[pos] == ifsta->auth_alg ||
28937 + algs[pos] == 0xff)
28938 + continue;
28939 + if (algs[pos] == WLAN_AUTH_SHARED_KEY &&
28940 + !ieee80211_sta_wep_configured(dev))
28941 + continue;
28942 + ifsta->auth_alg = algs[pos];
28943 + printk(KERN_DEBUG "%s: set auth_alg=%d for "
28944 + "next try\n",
28945 + dev->name, ifsta->auth_alg);
28946 + break;
28947 + }
28948 + }
28949 + return;
28950 + }
28951 +
28952 + switch (ifsta->auth_alg) {
28953 + case WLAN_AUTH_OPEN:
28954 + case WLAN_AUTH_LEAP:
28955 + ieee80211_auth_completed(dev, ifsta);
28956 + break;
28957 + case WLAN_AUTH_SHARED_KEY:
28958 + if (ifsta->auth_transaction == 4)
28959 + ieee80211_auth_completed(dev, ifsta);
28960 + else
28961 + ieee80211_auth_challenge(dev, ifsta, mgmt, len,
28962 + rx_status);
28963 + break;
28964 + }
28965 +}
28966 +
28967 +
28968 +static void ieee80211_rx_mgmt_deauth(struct net_device *dev,
28969 + struct ieee80211_if_sta *ifsta,
28970 + struct ieee80211_mgmt *mgmt,
28971 + size_t len,
28972 + struct ieee80211_rx_status *rx_status)
28973 +{
28974 + u16 reason_code;
28975 +
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));
28980 + return;
28981 + }
28982 +
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));
28988 + return;
28989 + }
28990 +
28991 + reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
28992 +
28993 + printk(KERN_DEBUG "%s: RX deauthentication from " MACSTR
28994 + " (reason=%d)\n",
28995 + dev->name, MAC2STR(mgmt->sa), reason_code);
28996 +
28997 + if (ifsta->authenticated) {
28998 + printk(KERN_DEBUG "%s: deauthenticated\n", dev->name);
28999 + }
29000 +
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);
29007 + }
29008 +
29009 + ieee80211_set_associated(dev, ifsta, 0);
29010 + ifsta->authenticated = 0;
29011 +}
29012 +
29013 +
29014 +static void ieee80211_rx_mgmt_disassoc(struct net_device *dev,
29015 + struct ieee80211_if_sta *ifsta,
29016 + struct ieee80211_mgmt *mgmt,
29017 + size_t len,
29018 + struct ieee80211_rx_status *rx_status)
29019 +{
29020 + u16 reason_code;
29021 +
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));
29026 + return;
29027 + }
29028 +
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));
29034 + return;
29035 + }
29036 +
29037 + reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
29038 +
29039 + printk(KERN_DEBUG "%s: RX disassociation from " MACSTR
29040 + " (reason=%d)\n",
29041 + dev->name, MAC2STR(mgmt->sa), reason_code);
29042 +
29043 + if (ifsta->associated)
29044 + printk(KERN_DEBUG "%s: disassociated\n", dev->name);
29045 +
29046 + if (ifsta->state == IEEE80211_ASSOCIATED) {
29047 + ifsta->state = IEEE80211_ASSOCIATE;
29048 + mod_timer(&ifsta->timer,
29049 + jiffies + IEEE80211_RETRY_AUTH_INTERVAL);
29050 + }
29051 +
29052 + ieee80211_set_associated(dev, ifsta, 0);
29053 +}
29054 +
29055 +
29056 +static void ieee80211_rx_mgmt_assoc_resp(struct net_device *dev,
29057 + struct ieee80211_if_sta *ifsta,
29058 + struct ieee80211_mgmt *mgmt,
29059 + size_t len,
29060 + struct ieee80211_rx_status *rx_status,
29061 + int reassoc)
29062 +{
29063 + struct ieee80211_local *local = dev->priv;
29064 + struct sta_info *sta;
29065 + u32 rates;
29066 + u16 capab_info, status_code, aid;
29067 + struct ieee802_11_elems elems;
29068 + u8 *pos;
29069 + int i, j;
29070 +
29071 + /* AssocResp and ReassocResp have identical structure, so process both
29072 + * of them in this function. */
29073 +
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));
29078 + return;
29079 + }
29080 +
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));
29085 + return;
29086 + }
29087 +
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));
29093 + return;
29094 + }
29095 +
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));
29103 +
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);
29108 +
29109 + if (status_code != WLAN_STATUS_SUCCESS) {
29110 + printk(KERN_DEBUG "%s: AP denied association (code=%d)\n",
29111 + dev->name, status_code);
29112 + return;
29113 + }
29114 +
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",
29119 + dev->name);
29120 + return;
29121 + }
29122 +
29123 + if (elems.supp_rates == NULL) {
29124 + printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
29125 + dev->name);
29126 + return;
29127 + }
29128 +
29129 + printk(KERN_DEBUG "%s: associated\n", dev->name);
29130 + ifsta->aid = aid;
29131 + ifsta->ap_capab = capab_info;
29132 +
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);
29138 +
29139 + ieee80211_set_associated(dev, ifsta, 1);
29140 +
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);
29148 + return;
29149 + }
29150 + }
29151 +
29152 + sta->dev = dev;
29153 + sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
29154 + sta->assoc_ap = 1;
29155 +
29156 + rates = 0;
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)
29160 + rate *= 2;
29161 + for (j = 0; j < local->num_curr_rates; j++)
29162 + if (local->curr_rates[j].rate == rate)
29163 + rates |= BIT(j);
29164 + }
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)
29168 + rate *= 2;
29169 + for (j = 0; j < local->num_curr_rates; j++)
29170 + if (local->curr_rates[j].rate == rate)
29171 + rates |= BIT(j);
29172 + }
29173 + sta->supp_rates = rates;
29174 +
29175 + rate_control_rate_init(local, sta);
29176 +
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);
29181 + }
29182 +
29183 +
29184 + sta_info_release(local, sta);
29185 +
29186 + ieee80211_associated(dev, ifsta);
29187 +}
29188 +
29189 +
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)
29193 +{
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;
29197 +}
29198 +
29199 +
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)
29203 +{
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)];
29207 + while (b) {
29208 + if (b == bss) {
29209 + if (prev == NULL) {
29210 + local->sta_bss_hash[STA_HASH(bss->bssid)] =
29211 + bss->hnext;
29212 + } else {
29213 + prev->hnext = bss->hnext;
29214 + }
29215 + break;
29216 + }
29217 + prev = b;
29218 + b = b->hnext;
29219 + }
29220 +}
29221 +
29222 +
29223 +static struct ieee80211_sta_bss *
29224 +ieee80211_rx_bss_add(struct net_device *dev, u8 *bssid)
29225 +{
29226 + struct ieee80211_local *local = dev->priv;
29227 + struct ieee80211_sta_bss *bss;
29228 +
29229 + bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
29230 + if (bss == NULL)
29231 + return NULL;
29232 + memset(bss, 0, sizeof(*bss));
29233 + atomic_inc(&bss->users);
29234 + atomic_inc(&bss->users);
29235 + memcpy(bss->bssid, bssid, ETH_ALEN);
29236 +
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);
29242 + return bss;
29243 +}
29244 +
29245 +
29246 +static struct ieee80211_sta_bss *
29247 +ieee80211_rx_bss_get(struct net_device *dev, u8 *bssid)
29248 +{
29249 + struct ieee80211_local *local = dev->priv;
29250 + struct ieee80211_sta_bss *bss;
29251 +
29252 + spin_lock_bh(&local->sta_bss_lock);
29253 + bss = local->sta_bss_hash[STA_HASH(bssid)];
29254 + while (bss) {
29255 + if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0) {
29256 + atomic_inc(&bss->users);
29257 + break;
29258 + }
29259 + bss = bss->hnext;
29260 + }
29261 + spin_unlock_bh(&local->sta_bss_lock);
29262 + return bss;
29263 +}
29264 +
29265 +
29266 +static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss)
29267 +{
29268 + kfree(bss->wpa_ie);
29269 + kfree(bss->rsn_ie);
29270 + kfree(bss->wmm_ie);
29271 + kfree(bss);
29272 +}
29273 +
29274 +
29275 +static void ieee80211_rx_bss_put(struct net_device *dev,
29276 + struct ieee80211_sta_bss *bss)
29277 +{
29278 + struct ieee80211_local *local = dev->priv;
29279 + if (!atomic_dec_and_test(&bss->users))
29280 + return;
29281 +
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);
29287 +}
29288 +
29289 +
29290 +void ieee80211_rx_bss_list_init(struct net_device *dev)
29291 +{
29292 + struct ieee80211_local *local = dev->priv;
29293 + spin_lock_init(&local->sta_bss_lock);
29294 + INIT_LIST_HEAD(&local->sta_bss_list);
29295 +}
29296 +
29297 +
29298 +void ieee80211_rx_bss_list_deinit(struct net_device *dev)
29299 +{
29300 + struct ieee80211_local *local = dev->priv;
29301 + struct ieee80211_sta_bss *bss;
29302 + struct list_head *ptr;
29303 +
29304 + for (;;) {
29305 + ptr = local->sta_bss_list.next;
29306 + if (!ptr || ptr == &local->sta_bss_list)
29307 + break;
29308 + bss = list_entry(ptr, struct ieee80211_sta_bss, list);
29309 + ieee80211_rx_bss_put(dev, bss);
29310 + }
29311 +}
29312 +
29313 +
29314 +static void ieee80211_rx_bss_info(struct net_device *dev,
29315 + struct ieee80211_mgmt *mgmt,
29316 + size_t len,
29317 + struct ieee80211_rx_status *rx_status,
29318 + int beacon)
29319 +{
29320 + struct ieee80211_local *local = dev->priv;
29321 + struct ieee802_11_elems elems;
29322 + size_t baselen;
29323 + int channel, invalid = 0, clen;
29324 + struct ieee80211_sta_bss *bss;
29325 + struct sta_info *sta;
29326 + struct ieee80211_sub_if_data *sdata;
29327 + u64 timestamp;
29328 + u8 *pos;
29329 +
29330 + if (!beacon && memcmp(mgmt->da, dev->dev_addr, ETH_ALEN))
29331 + return; /* ignore ProbeResp to foreign address */
29332 +
29333 +#if 0
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));
29337 +#endif
29338 +
29339 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29340 + if (baselen > len)
29341 + return;
29342 +
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]);
29348 +
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;
29353 + u64 tsf;
29354 + if (local->hw->get_tsf)
29355 + tsf = local->hw->get_tsf(local->mdev);
29356 + else
29357 + tsf = -1LLU;
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 "
29361 + "@%ld\n",
29362 + MAC2STR(mgmt->sa), MAC2STR(mgmt->bssid),
29363 + tsf, timestamp, tsf - timestamp, jiffies);
29364 + last_tsf_debug = jiffies;
29365 + }
29366 +#endif /* IEEE80211_IBSS_DEBUG */
29367 + }
29368 +
29369 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29370 + &elems) == ParseFailed)
29371 + invalid = 1;
29372 +
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;
29382 +
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;
29392 + break;
29393 + }
29394 + }
29395 +
29396 + supp_rates = 0;
29397 + for (i = 0; i < elems.supp_rates_len +
29398 + elems.ext_supp_rates_len; i++) {
29399 + u8 rate = 0;
29400 + int own_rate;
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)
29408 + own_rate *= 2;
29409 + for (j = 0; j < num_rates; j++)
29410 + if (rates[j].rate == own_rate)
29411 + supp_rates |= BIT(j);
29412 + }
29413 +
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;
29421 + }
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 -> "
29425 + "0x%x)\n",
29426 + dev->name, MAC2STR(sta->addr), prev_rates,
29427 + supp_rates, sta->supp_rates);
29428 + }
29429 + sta_info_release(local, sta);
29430 + }
29431 +
29432 + if (elems.ssid == NULL)
29433 + return;
29434 +
29435 + if (elems.ds_params && elems.ds_params_len == 1)
29436 + channel = elems.ds_params[0];
29437 + else
29438 + channel = rx_status->channel;
29439 +
29440 + bss = ieee80211_rx_bss_get(dev, mgmt->bssid);
29441 + if (bss == NULL) {
29442 + bss = ieee80211_rx_bss_add(dev, mgmt->bssid);
29443 + if (bss == NULL)
29444 + return;
29445 + } else {
29446 +#if 0
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);
29451 +#endif
29452 + }
29453 +
29454 + if (bss->probe_resp && beacon) {
29455 + /* Do not allow beacon to override data from Probe Response. */
29456 + ieee80211_rx_bss_put(dev, bss);
29457 + return;
29458 + }
29459 +
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;
29465 + }
29466 +
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,
29473 + clen);
29474 + bss->supp_rates_len += clen;
29475 + }
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;
29483 + }
29484 +
29485 + if (elems.wpa &&
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;
29493 + } else
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;
29499 + }
29500 +
29501 + if (elems.rsn &&
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;
29509 + } else
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;
29515 + }
29516 +
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;
29526 + } else
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;
29532 + }
29533 +
29534 +
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
29545 + };
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];
29549 + }
29550 + bss->timestamp = timestamp;
29551 + bss->last_update = jiffies;
29552 + bss->rssi = rx_status->ssi;
29553 + if (!beacon)
29554 + bss->probe_resp++;
29555 + ieee80211_rx_bss_put(dev, bss);
29556 +}
29557 +
29558 +
29559 +static void ieee80211_rx_mgmt_probe_resp(struct net_device *dev,
29560 + struct ieee80211_mgmt *mgmt,
29561 + size_t len,
29562 + struct ieee80211_rx_status *rx_status)
29563 +{
29564 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 0);
29565 +}
29566 +
29567 +
29568 +static void ieee80211_rx_mgmt_beacon(struct net_device *dev,
29569 + struct ieee80211_mgmt *mgmt,
29570 + size_t len,
29571 + struct ieee80211_rx_status *rx_status)
29572 +{
29573 + struct ieee80211_local *local = dev->priv;
29574 + struct ieee80211_sub_if_data *sdata;
29575 + struct ieee80211_if_sta *ifsta;
29576 + int use_protection;
29577 + size_t baselen;
29578 + struct ieee802_11_elems elems;
29579 +
29580 + ieee80211_rx_bss_info(dev, mgmt, len, rx_status, 1);
29581 +
29582 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29583 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
29584 + return;
29585 + ifsta = &sdata->u.sta;
29586 +
29587 + if (!ifsta->associated ||
29588 + memcmp(ifsta->bssid, mgmt->bssid, ETH_ALEN) != 0)
29589 + return;
29590 +
29591 + /* Process beacon from the current BSS */
29592 + baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
29593 + if (baselen > len)
29594 + return;
29595 +
29596 + if (ieee802_11_parse_elems(mgmt->u.beacon.variable, len - baselen,
29597 + &elems) == ParseFailed)
29598 + return;
29599 +
29600 + use_protection = 0;
29601 + if (elems.erp_info && elems.erp_info_len >= 1) {
29602 + use_protection =
29603 + (elems.erp_info[0] & ERP_INFO_USE_PROTECTION) != 0;
29604 + }
29605 +
29606 + if (use_protection != !!ifsta->use_protection) {
29607 + if (net_ratelimit()) {
29608 + printk(KERN_DEBUG "%s: CTS protection %s (BSSID="
29609 + MACSTR ")\n",
29610 + dev->name,
29611 + use_protection ? "enabled" : "disabled",
29612 + MAC2STR(ifsta->bssid));
29613 + }
29614 + ifsta->use_protection = use_protection ? 1 : 0;
29615 + local->cts_protect_erp_frames = use_protection;
29616 + }
29617 +
29618 + if (elems.wmm_param && ifsta->wmm_enabled) {
29619 + ieee80211_sta_wmm_params(dev, ifsta, elems.wmm_param,
29620 + elems.wmm_param_len);
29621 + }
29622 +}
29623 +
29624 +
29625 +static void ieee80211_rx_mgmt_probe_req(struct net_device *dev,
29626 + struct ieee80211_if_sta *ifsta,
29627 + struct ieee80211_mgmt *mgmt,
29628 + size_t len,
29629 + struct ieee80211_rx_status *rx_status)
29630 +{
29631 + struct ieee80211_local *local = dev->priv;
29632 + int tx_last_beacon;
29633 + struct sk_buff *skb;
29634 + struct ieee80211_mgmt *resp;
29635 + u8 *pos, *end;
29636 +
29637 + if (local->conf.mode != IW_MODE_ADHOC ||
29638 + ifsta->state != IEEE80211_IBSS_JOINED ||
29639 + len < 24 + 2 || ifsta->probe_resp == NULL)
29640 + return;
29641 +
29642 + if (local->hw->tx_last_beacon)
29643 + tx_last_beacon = local->hw->tx_last_beacon(local->mdev);
29644 + else
29645 + tx_last_beacon = 1;
29646 +
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 */
29653 +
29654 + if (!tx_last_beacon)
29655 + return;
29656 +
29657 + if (memcmp(mgmt->bssid, ifsta->bssid, ETH_ALEN) != 0 &&
29658 + memcmp(mgmt->bssid, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) != 0)
29659 + return;
29660 +
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));
29669 + }
29670 + return;
29671 + }
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 */
29676 + return;
29677 + }
29678 +
29679 + /* Reply with ProbeResp */
29680 + skb = skb_copy(ifsta->probe_resp, GFP_ATOMIC);
29681 + if (skb == NULL)
29682 + return;
29683 +
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);
29691 +}
29692 +
29693 +
29694 +void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
29695 + struct ieee80211_rx_status *rx_status)
29696 +{
29697 + struct ieee80211_sub_if_data *sdata;
29698 + struct ieee80211_if_sta *ifsta;
29699 + struct ieee80211_mgmt *mgmt;
29700 + u16 fc;
29701 +
29702 + if (skb->len < 24)
29703 + goto fail;
29704 +
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);
29709 + goto fail;
29710 + }
29711 + ifsta = &sdata->u.sta;
29712 +
29713 + mgmt = (struct ieee80211_mgmt *) skb->data;
29714 + fc = le16_to_cpu(mgmt->frame_control);
29715 +
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,
29719 + rx_status);
29720 + break;
29721 + case WLAN_FC_STYPE_PROBE_RESP:
29722 + ieee80211_rx_mgmt_probe_resp(dev, mgmt, skb->len, rx_status);
29723 + break;
29724 + case WLAN_FC_STYPE_BEACON:
29725 + ieee80211_rx_mgmt_beacon(dev, mgmt, skb->len, rx_status);
29726 + break;
29727 + case WLAN_FC_STYPE_AUTH:
29728 + ieee80211_rx_mgmt_auth(dev, ifsta, mgmt, skb->len, rx_status);
29729 + break;
29730 + case WLAN_FC_STYPE_ASSOC_RESP:
29731 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29732 + rx_status, 0);
29733 + break;
29734 + case WLAN_FC_STYPE_REASSOC_RESP:
29735 + ieee80211_rx_mgmt_assoc_resp(dev, ifsta, mgmt, skb->len,
29736 + rx_status, 1);
29737 + break;
29738 + case WLAN_FC_STYPE_DEAUTH:
29739 + ieee80211_rx_mgmt_deauth(dev, ifsta, mgmt, skb->len,
29740 + rx_status);
29741 + break;
29742 + case WLAN_FC_STYPE_DISASSOC:
29743 + ieee80211_rx_mgmt_disassoc(dev, ifsta, mgmt, skb->len,
29744 + rx_status);
29745 + break;
29746 + default:
29747 + printk(KERN_DEBUG "%s: received unknown management frame - "
29748 + "stype=%d\n", dev->name, WLAN_FC_GET_STYPE(fc));
29749 + break;
29750 + }
29751 +
29752 + fail:
29753 + dev_kfree_skb(skb);
29754 +}
29755 +
29756 +
29757 +void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
29758 + struct ieee80211_rx_status *rx_status)
29759 +{
29760 + struct ieee80211_mgmt *mgmt;
29761 + u16 fc;
29762 +
29763 + if (skb->len < 24) {
29764 + dev_kfree_skb(skb);
29765 + return;
29766 + }
29767 +
29768 + mgmt = (struct ieee80211_mgmt *) skb->data;
29769 + fc = le16_to_cpu(mgmt->frame_control);
29770 +
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,
29777 + rx_status);
29778 + }
29779 + }
29780 +
29781 + dev_kfree_skb(skb);
29782 +}
29783 +
29784 +
29785 +static int ieee80211_sta_active_ibss(struct net_device *dev)
29786 +{
29787 + struct ieee80211_local *local = dev->priv;
29788 + struct list_head *ptr;
29789 + int active = 0;
29790 + struct sta_info *sta;
29791 +
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,
29797 + jiffies)) {
29798 + active++;
29799 + break;
29800 + }
29801 + }
29802 + spin_unlock_bh(&local->sta_lock);
29803 +
29804 + return active;
29805 +}
29806 +
29807 +
29808 +static void ieee80211_sta_expire(struct net_device *dev)
29809 +{
29810 + struct ieee80211_local *local = dev->priv;
29811 + struct list_head *ptr, *n;
29812 + struct sta_info *sta;
29813 +
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);
29822 + }
29823 + }
29824 + spin_unlock_bh(&local->sta_lock);
29825 +}
29826 +
29827 +
29828 +static void ieee80211_sta_merge_ibss(struct net_device *dev,
29829 + struct ieee80211_if_sta *ifsta)
29830 +{
29831 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
29832 +
29833 + ieee80211_sta_expire(dev);
29834 + if (ieee80211_sta_active_ibss(dev))
29835 + return;
29836 +
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);
29840 +}
29841 +
29842 +
29843 +void ieee80211_sta_timer(unsigned long ptr)
29844 +{
29845 + struct net_device *dev;
29846 + struct ieee80211_sub_if_data *sdata;
29847 + struct ieee80211_if_sta *ifsta;
29848 +
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);
29854 + return;
29855 + }
29856 + ifsta = &sdata->u.sta;
29857 +
29858 + switch (ifsta->state) {
29859 + case IEEE80211_DISABLED:
29860 + break;
29861 + case IEEE80211_AUTHENTICATE:
29862 + ieee80211_authenticate(dev, ifsta);
29863 + break;
29864 + case IEEE80211_ASSOCIATE:
29865 + ieee80211_associate(dev, ifsta);
29866 + break;
29867 + case IEEE80211_ASSOCIATED:
29868 + ieee80211_associated(dev, ifsta);
29869 + break;
29870 + case IEEE80211_IBSS_SEARCH:
29871 + ieee80211_sta_find_ibss(dev, ifsta);
29872 + break;
29873 + case IEEE80211_IBSS_JOINED:
29874 + ieee80211_sta_merge_ibss(dev, ifsta);
29875 + break;
29876 + default:
29877 + printk(KERN_DEBUG "ieee80211_sta_timer: Unknown state %d\n",
29878 + ifsta->state);
29879 + break;
29880 + }
29881 +
29882 + if (ieee80211_privacy_mismatch(dev, ifsta)) {
29883 + printk(KERN_DEBUG "%s: privacy configuration mismatch and "
29884 + "mixed-cell disabled - disassociate\n", dev->name);
29885 +
29886 + ieee80211_send_disassoc(dev, ifsta, WLAN_REASON_UNSPECIFIED);
29887 + ieee80211_set_associated(dev, ifsta, 0);
29888 + }
29889 +}
29890 +
29891 +
29892 +static void ieee80211_sta_new_auth(struct net_device *dev,
29893 + struct ieee80211_if_sta *ifsta)
29894 +{
29895 + struct ieee80211_local *local = dev->priv;
29896 +
29897 + if (local->conf.mode != IW_MODE_INFRA)
29898 + return;
29899 +
29900 + if (local->hw->reset_tsf) {
29901 + /* Reset own TSF to allow time synchronization work. */
29902 + local->hw->reset_tsf(local->mdev);
29903 + }
29904 +
29905 + ifsta->wmm_last_param_set = -1; /* allow any WMM update */
29906 +
29907 +
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;
29914 + else
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);
29921 +}
29922 +
29923 +
29924 +static int ieee80211_ibss_allowed(struct ieee80211_local *local)
29925 +{
29926 + int m, c;
29927 +
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)
29931 + continue;
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)
29937 + return 1;
29938 + break;
29939 + }
29940 + }
29941 + }
29942 +
29943 + return 0;
29944 +}
29945 +
29946 +
29947 +extern int ieee80211_ioctl_siwfreq(struct net_device *dev,
29948 + struct iw_request_info *info,
29949 + struct iw_freq *freq, char *extra);
29950 +
29951 +static int ieee80211_sta_join_ibss(struct net_device *dev,
29952 + struct ieee80211_if_sta *ifsta,
29953 + struct ieee80211_sta_bss *bss)
29954 +{
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;
29963 + u8 *pos;
29964 + struct ieee80211_sub_if_data *sdata;
29965 +
29966 + /* Remove possible STA entries from other IBSS networks. */
29967 + sta_info_flush(local, NULL);
29968 +
29969 + if (local->hw->reset_tsf) {
29970 + /* Reset own TSF to allow time synchronization work. */
29971 + local->hw->reset_tsf(local->mdev);
29972 + }
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);
29976 +
29977 + local->conf.beacon_int = bss->beacon_int >= 10 ? bss->beacon_int : 10;
29978 +
29979 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
29980 + sdata->drop_unencrypted = bss->capability &
29981 + cpu_to_le16(WLAN_CAPABILITY_PRIVACY) ? 1 : 0;
29982 +
29983 + memset(&rq, 0, sizeof(rq));
29984 + rq.m = bss->freq * 100000;
29985 + rq.e = 1;
29986 + res = ieee80211_ioctl_siwfreq(dev, NULL, &rq, NULL);
29987 +
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);
29992 + return -1;
29993 + }
29994 +
29995 + /* Set beacon template based on scan results */
29996 + skb = dev_alloc_skb(400);
29997 + do {
29998 + if (skb == NULL)
29999 + break;
30000 +
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);
30012 +
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);
30017 +
30018 + rates = bss->supp_rates_len;
30019 + if (rates > 8)
30020 + rates = 8;
30021 + pos = skb_put(skb, 2 + rates);
30022 + *pos++ = WLAN_EID_SUPP_RATES;
30023 + *pos++ = rates;
30024 + memcpy(pos, bss->supp_rates, rates);
30025 +
30026 + pos = skb_put(skb, 2 + 1);
30027 + *pos++ = WLAN_EID_DS_PARAMS;
30028 + *pos++ = 1;
30029 + *pos++ = bss->channel;
30030 +
30031 + pos = skb_put(skb, 2 + 2);
30032 + *pos++ = WLAN_EID_IBSS_PARAMS;
30033 + *pos++ = 2;
30034 + /* FIX: set ATIM window based on scan results */
30035 + *pos++ = 0;
30036 + *pos++ = 0;
30037 +
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;
30042 + *pos++ = rates;
30043 + memcpy(pos, &bss->supp_rates[8], rates);
30044 + }
30045 +
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);
30054 + break;
30055 + }
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;
30064 +
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);
30072 + } else {
30073 + printk(KERN_DEBUG "%s: Could not allocate ProbeResp "
30074 + "template for IBSS\n", dev->name);
30075 + }
30076 +
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);
30081 + skb = NULL;
30082 + }
30083 +
30084 + rates = 0;
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)
30088 + rate *= 2;
30089 + for (j = 0; j < local->num_curr_rates; j++)
30090 + if (local->curr_rates[j].rate == rate)
30091 + rates |= BIT(j);
30092 + }
30093 + ifsta->supp_rates_bits = rates;
30094 + } while (0);
30095 +
30096 + if (skb) {
30097 + printk(KERN_DEBUG "%s: Failed to configure IBSS beacon "
30098 + "template\n", dev->name);
30099 + dev_kfree_skb(skb);
30100 + }
30101 +
30102 + ifsta->state = IEEE80211_IBSS_JOINED;
30103 + mod_timer(&ifsta->timer, jiffies + IEEE80211_IBSS_MERGE_INTERVAL);
30104 +
30105 + ieee80211_rx_bss_put(dev, bss);
30106 +
30107 + return res;
30108 +}
30109 +
30110 +
30111 +static int ieee80211_sta_create_ibss(struct net_device *dev,
30112 + struct ieee80211_if_sta *ifsta)
30113 +{
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;
30118 + int i;
30119 +
30120 +#if 0
30121 + /* Easier testing, use fixed BSSID. */
30122 + memset(bssid, 0xfe, ETH_ALEN);
30123 +#else
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;
30132 +#endif
30133 +
30134 + printk(KERN_DEBUG "%s: Creating new IBSS network, BSSID " MACSTR "\n",
30135 + dev->name, MAC2STR(bssid));
30136 +
30137 + bss = ieee80211_rx_bss_add(dev, bssid);
30138 + if (bss == NULL)
30139 + return -ENOMEM;
30140 +
30141 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30142 +
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);
30153 + } else
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)
30160 + rate /= 2;
30161 + *pos++ = (u8) (rate / 5);
30162 + }
30163 +
30164 + return ieee80211_sta_join_ibss(dev, ifsta, bss);
30165 +}
30166 +
30167 +
30168 +static int ieee80211_sta_find_ibss(struct net_device *dev,
30169 + struct ieee80211_if_sta *ifsta)
30170 +{
30171 + struct ieee80211_local *local = dev->priv;
30172 + struct ieee80211_sta_bss *bss;
30173 + int found = 0;
30174 + u8 bssid[ETH_ALEN];
30175 + struct list_head *ptr;
30176 + int active_ibss;
30177 +
30178 + if (ifsta->ssid_len == 0)
30179 + return -EINVAL;
30180 +
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))
30192 + continue;
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);
30198 + found = 1;
30199 + if (active_ibss || memcmp(bssid, ifsta->bssid, ETH_ALEN) != 0)
30200 + break;
30201 + }
30202 + spin_unlock_bh(&local->sta_bss_lock);
30203 +
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);
30214 + }
30215 +#ifdef IEEE80211_IBSS_DEBUG
30216 + printk(KERN_DEBUG " did not try to join ibss\n");
30217 +#endif /* IEEE80211_IBSS_DEBUG */
30218 +
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;
30232 +
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);
30243 + }
30244 +
30245 + /* No IBSS found - decrease scan interval and continue
30246 + * scanning. */
30247 + interval = IEEE80211_SCAN_INTERVAL_SLOW;
30248 + }
30249 +
30250 + ifsta->state = IEEE80211_IBSS_SEARCH;
30251 + mod_timer(&ifsta->timer, jiffies + interval);
30252 + return 0;
30253 + }
30254 +
30255 + return 0;
30256 +}
30257 +
30258 +
30259 +int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len)
30260 +{
30261 + struct ieee80211_sub_if_data *sdata;
30262 + struct ieee80211_if_sta *ifsta;
30263 + struct ieee80211_local *local = dev->priv;
30264 +
30265 + if (len > IEEE80211_MAX_SSID_LEN)
30266 + return -EINVAL;
30267 +
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;
30272 + int i;
30273 +
30274 + memset(&qparam, 0, sizeof(qparam));
30275 + /* TODO: are these ok defaults for all hw_modes? */
30276 + qparam.aifs = 2;
30277 + qparam.cw_min =
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++)
30282 + {
30283 + local->hw->conf_tx(dev, i + IEEE80211_TX_QUEUE_DATA0,
30284 + &qparam);
30285 + }
30286 + /* IBSS uses different parameters for Beacon sending */
30287 + qparam.cw_min++;
30288 + qparam.cw_min *= 2;
30289 + qparam.cw_min--;
30290 + local->hw->conf_tx(dev, IEEE80211_TX_QUEUE_BEACON, &qparam);
30291 + }
30292 +
30293 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30294 + ifsta = &sdata->u.sta;
30295 +
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;
30301 +
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);
30307 + }
30308 +
30309 + if (ifsta->bssid_set && ifsta->state != IEEE80211_AUTHENTICATE)
30310 + ieee80211_sta_new_auth(dev, ifsta);
30311 +
30312 + return 0;
30313 +}
30314 +
30315 +
30316 +int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len)
30317 +{
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;
30322 + return 0;
30323 +}
30324 +
30325 +
30326 +int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid)
30327 +{
30328 + struct ieee80211_local *local = dev->priv;
30329 + struct ieee80211_sub_if_data *sdata;
30330 + struct ieee80211_if_sta *ifsta;
30331 +
30332 + sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30333 + ifsta = &sdata->u.sta;
30334 +
30335 + memcpy(ifsta->bssid, bssid, ETH_ALEN);
30336 + if (local->conf.mode == IW_MODE_ADHOC)
30337 + memcpy(local->bssid, bssid, ETH_ALEN);
30338 +
30339 + if (memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0)
30340 + ifsta->bssid_set = 0;
30341 + else
30342 + ifsta->bssid_set = 1;
30343 + if (ifsta->ssid_set)
30344 + ieee80211_sta_new_auth(dev, ifsta);
30345 +
30346 + return 0;
30347 +}
30348 +
30349 +
30350 +static void ieee80211_sta_save_oper_chan(struct net_device *dev)
30351 +{
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;
30359 +}
30360 +
30361 +
30362 +static int ieee80211_sta_restore_oper_chan(struct net_device *dev)
30363 +{
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);
30372 +}
30373 +
30374 +
30375 +static int ieee80211_active_scan(struct ieee80211_local *local)
30376 +{
30377 + int m, c;
30378 +
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)
30382 + continue;
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)
30388 + return 1;
30389 + break;
30390 + }
30391 + }
30392 + }
30393 +
30394 + return 0;
30395 +}
30396 +
30397 +
30398 +static void ieee80211_sta_scan_timer(unsigned long ptr)
30399 +{
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;
30404 + int skip;
30405 + union iwreq_data wrqu;
30406 +
30407 + if (!local->sta_scanning)
30408 + return;
30409 +
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",
30419 + dev->name);
30420 + }
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);
30434 + }
30435 + return;
30436 + }
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))
30444 + skip = 1;
30445 +
30446 + if (!skip) {
30447 +#if 0
30448 + printk(KERN_DEBUG "%s: scan channel %d (%d MHz)\n",
30449 + dev->name, chan->chan, chan->freq);
30450 +#endif
30451 +
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);
30462 + skip = 1;
30463 + }
30464 + }
30465 +
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;
30471 + }
30472 +
30473 + if (skip) {
30474 + local->scan_timer.expires = jiffies;
30475 + break;
30476 + }
30477 +
30478 + local->scan_timer.expires = jiffies + IEEE80211_PROBE_DELAY;
30479 + local->scan_state = SCAN_SEND_PROBE;
30480 + break;
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;
30487 + } else {
30488 + local->scan_timer.expires =
30489 + jiffies + IEEE80211_PASSIVE_CHANNEL_TIME;
30490 + }
30491 + local->scan_state = SCAN_SET_CHANNEL;
30492 + break;
30493 + }
30494 +
30495 + add_timer(&local->scan_timer);
30496 +}
30497 +
30498 +
30499 +int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len)
30500 +{
30501 + struct ieee80211_local *local = dev->priv;
30502 +
30503 + if (ssid_len > IEEE80211_MAX_SSID_LEN)
30504 + return -EINVAL;
30505 +
30506 + /* MLME-SCAN.request (page 118) page 144 (11.1.3.1)
30507 + * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS
30508 + * BSSID: MACAddress
30509 + * SSID
30510 + * ScanType: ACTIVE, PASSIVE
30511 + * ProbeDelay: delay (in microseconds) to be used prior to transmitting
30512 + * a Probe frame during active scanning
30513 + * ChannelList
30514 + * MinChannelTime (>= ProbeDelay), in TU
30515 + * MaxChannelTime: (>= MinChannelTime), in TU
30516 + */
30517 +
30518 + /* MLME-SCAN.confirm
30519 + * BSSDescriptionSet
30520 + * ResultCode: SUCCESS, INVALID_PARAMETERS
30521 + */
30522 +
30523 + /* TODO: if assoc, move to power save mode for the duration of the
30524 + * scan */
30525 +
30526 + if (local->sta_scanning)
30527 + return -EBUSY;
30528 +
30529 + printk(KERN_DEBUG "%s: starting scan\n", dev->name);
30530 +
30531 + ieee80211_sta_save_oper_chan(dev);
30532 +
30533 + local->sta_scanning = 1;
30534 + /* TODO: stop TX queue? */
30535 +
30536 + if (ssid) {
30537 + local->scan_ssid_len = ssid_len;
30538 + memcpy(local->scan_ssid, ssid, ssid_len);
30539 + } else
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);
30550 +
30551 + return 0;
30552 +}
30553 +
30554 +
30555 +static char *
30556 +ieee80211_sta_scan_result(struct net_device *dev,
30557 + struct ieee80211_sta_bss *bss,
30558 + char *current_ev, char *end_buf)
30559 +{
30560 + struct ieee80211_local *local = dev->priv;
30561 + struct iw_event iwe;
30562 +
30563 + if (time_after(jiffies,
30564 + bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE))
30565 + return current_ev;
30566 +
30567 + if (!(local->hw_modes & (1 << bss->hw_mode)))
30568 + return current_ev;
30569 +
30570 + if (local->scan_flags & IEEE80211_SCAN_WPA_ONLY &&
30571 + bss->wpa_ie == NULL && bss->rsn_ie == NULL)
30572 + return current_ev;
30573 +
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;
30578 +
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,
30584 + IW_EV_ADDR_LEN);
30585 +
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,
30591 + bss->ssid);
30592 +
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;
30598 + else
30599 + iwe.u.mode = IW_MODE_ADHOC;
30600 + current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
30601 + IW_EV_UINT_LEN);
30602 + }
30603 +
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,
30609 + IW_EV_FREQ_LEN);
30610 +
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;
30615 + else
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, "");
30619 +
30620 + if (bss && bss->wpa_ie) {
30621 + char *buf, *p;
30622 + int i;
30623 + buf = kmalloc(30 + bss->wpa_ie_len * 2, GFP_ATOMIC);
30624 + if (buf) {
30625 + p = buf;
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,
30633 + &iwe, buf);
30634 + kfree(buf);
30635 + }
30636 + }
30637 +
30638 + if (bss && bss->rsn_ie) {
30639 + char *buf, *p;
30640 + int i;
30641 + buf = kmalloc(30 + bss->rsn_ie_len * 2, GFP_ATOMIC);
30642 + if (buf) {
30643 + p = buf;
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,
30651 + &iwe, buf);
30652 + kfree(buf);
30653 + }
30654 + }
30655 +
30656 + if (bss) {
30657 + char *buf;
30658 + buf = kmalloc(30, GFP_ATOMIC);
30659 + if (buf) {
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,
30665 + &iwe, buf);
30666 + kfree(buf);
30667 + }
30668 + }
30669 +
30670 + do {
30671 + char *buf, *p;
30672 + int i;
30673 +
30674 + if (!(local->scan_flags & IEEE80211_SCAN_EXTRA_INFO))
30675 + break;
30676 +
30677 + buf = kmalloc(100, GFP_ATOMIC);
30678 + if (buf == NULL)
30679 + break;
30680 +
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,
30686 + buf);
30687 +
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,
30693 + buf);
30694 +
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,
30700 + buf);
30701 +
30702 + p = buf;
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,
30710 + buf);
30711 +
30712 + kfree(buf);
30713 + break;
30714 + } while (0);
30715 +
30716 + return current_ev;
30717 +}
30718 +
30719 +
30720 +int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len)
30721 +{
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;
30727 +
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,
30732 + end_buf);
30733 + }
30734 + spin_unlock_bh(&local->sta_bss_lock);
30735 + return current_ev - buf;
30736 +}
30737 +
30738 +
30739 +int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len)
30740 +{
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);
30744 + if (len == 0) {
30745 + ifsta->extra_ie = NULL;
30746 + ifsta->extra_ie_len = 0;
30747 + return 0;
30748 + }
30749 + ifsta->extra_ie = kmalloc(len, GFP_KERNEL);
30750 + if (ifsta->extra_ie == NULL) {
30751 + ifsta->extra_ie_len = 0;
30752 + return -ENOMEM;
30753 + }
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);
30759 + return 0;
30760 +}
30761 +
30762 +
30763 +struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
30764 + struct sk_buff *skb, u8 *bssid,
30765 + u8 *addr)
30766 +{
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;
30772 +
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));
30779 + }
30780 + return NULL;
30781 + }
30782 +
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;
30789 + break;
30790 + }
30791 + }
30792 + spin_unlock_bh(&local->sub_if_lock);
30793 +
30794 + if (sta_dev == NULL)
30795 + return NULL;
30796 +
30797 + printk(KERN_DEBUG "%s: Adding new IBSS station " MACSTR " (dev=%s)\n",
30798 + dev->name, MAC2STR(addr), sta_dev->name);
30799 +
30800 + sta = sta_info_add(local, dev, addr);
30801 + if (sta == NULL) {
30802 + return NULL;
30803 + }
30804 +
30805 + sta->dev = sta_dev;
30806 + sta->supp_rates = sdata->u.sta.supp_rates_bits;
30807 +
30808 + rate_control_rate_init(local, sta);
30809 +
30810 + return sta; /* caller will call sta_info_release() */
30811 +}
30812 +
30813 +
30814 +int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason)
30815 +{
30816 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30817 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30818 +
30819 + printk(KERN_DEBUG "%s: deauthenticate(reason=%d)\n",
30820 + dev->name, reason);
30821 +
30822 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30823 + return -EINVAL;
30824 +
30825 + ieee80211_send_deauth(dev, ifsta, reason);
30826 + ieee80211_set_associated(dev, ifsta, 0);
30827 + return 0;
30828 +}
30829 +
30830 +
30831 +int ieee80211_sta_disassociate(struct net_device *dev, u16 reason)
30832 +{
30833 + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
30834 + struct ieee80211_if_sta *ifsta = &sdata->u.sta;
30835 +
30836 + printk(KERN_DEBUG "%s: disassociate(reason=%d)\n",
30837 + dev->name, reason);
30838 +
30839 + if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
30840 + return -EINVAL;
30841 +
30842 + if (!ifsta->associated)
30843 + return -1;
30844 +
30845 + ieee80211_send_disassoc(dev, ifsta, reason);
30846 + ieee80211_set_associated(dev, ifsta, 0);
30847 + return 0;
30848 +}
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
30852 @@ -0,0 +1,135 @@
30853 +/*
30854 + * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
30855 + *
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.
30859 + */
30860 +
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"
30868 +
30869 +#define to_ieee80211_local(class) container_of(class, struct ieee80211_local, class_dev)
30870 +
30871 +
30872 +static ssize_t store_add_iface(struct class_device *dev,
30873 + const char *buf, size_t len)
30874 +{
30875 + struct ieee80211_local *local = to_ieee80211_local(dev);
30876 + int res;
30877 +
30878 + if (!capable(CAP_NET_ADMIN))
30879 + return -EPERM;
30880 + if (len > IFNAMSIZ)
30881 + return -EINVAL;
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. */
30885 + rtnl_lock();
30886 + res = ieee80211_if_add_sta(local->mdev, buf, 1);
30887 + rtnl_unlock();
30888 + return res < 0 ? res : len;
30889 +}
30890 +
30891 +static ssize_t store_remove_iface(struct class_device *dev,
30892 + const char *buf, size_t len)
30893 +{
30894 + struct ieee80211_local *local = to_ieee80211_local(dev);
30895 + int res;
30896 +
30897 + if (!capable(CAP_NET_ADMIN))
30898 + return -EPERM;
30899 + if (len > IFNAMSIZ)
30900 + return -EINVAL;
30901 + res = ieee80211_if_remove_sta(local->mdev, buf, 0);
30902 + return res < 0 ? res : len;
30903 +}
30904 +
30905 +static ssize_t show_max_iface_count(struct class_device *dev,
30906 + char *buf)
30907 +{
30908 + struct ieee80211_local *local = to_ieee80211_local(dev);
30909 +
30910 + return sprintf(buf, "%d\n", local->conf.bss_count);
30911 +}
30912 +
30913 +static ssize_t store_max_iface_count(struct class_device *dev,
30914 + const char *buf, size_t len)
30915 +{
30916 + struct ieee80211_local *local = to_ieee80211_local(dev);
30917 + unsigned long new_count;
30918 + char *endp;
30919 + int res;
30920 +
30921 + if (!capable(CAP_NET_ADMIN))
30922 + return -EPERM;
30923 + new_count = simple_strtoul(buf, &endp, 0);
30924 + if (endp == buf)
30925 + return -EINVAL;
30926 + rtnl_lock();
30927 + res = ieee80211_set_bss_count(local->mdev, new_count, NULL);
30928 + rtnl_unlock();
30929 + return res < 0 ? res : len;
30930 +}
30931 +
30932 +#ifdef CONFIG_HOTPLUG
30933 +static int ieee80211_uevent(struct class_device *cd, char **envp,
30934 + int num_envp, char *buf, int size)
30935 +{
30936 + struct ieee80211_local *local = to_ieee80211_local(cd);
30937 +
30938 + if (num_envp < 2)
30939 + return -ENOMEM;
30940 + envp[0] = buf;
30941 + if (snprintf(buf, size, "IEEE80211_DEV=phy%d",
30942 + local->dev_index) + 1 >= size)
30943 + return -ENOMEM;
30944 + envp[1] = NULL;
30945 + return 0;
30946 +}
30947 +#endif
30948 +
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),
30954 + {}
30955 +};
30956 +
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,
30962 +#endif
30963 +};
30964 +
30965 +int ieee80211_register_sysfs(struct ieee80211_local *local)
30966 +{
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);
30972 +}
30973 +
30974 +void ieee80211_unregister_sysfs(struct ieee80211_local *local)
30975 +{
30976 + class_device_del(&local->class_dev);
30977 +}
30978 +
30979 +int ieee80211_sysfs_init(void)
30980 +{
30981 + return class_register(&ieee80211_class);
30982 +}
30983 +
30984 +void ieee80211_sysfs_deinit(void)
30985 +{
30986 + class_unregister(&ieee80211_class);
30987 +}
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
30991 @@ -0,0 +1,31 @@
30992 +config D80211
30993 + tristate "Generic IEEE 802.11 Networking Stack (dscape)"
30994 + ---help---
30995 + This option enables the hardware independent IEEE 802.11
30996 + networking stack.
30997 +
30998 +config D80211_DEBUG
30999 + bool "Enable debugging output"
31000 + depends on D80211
31001 + ---help---
31002 + This option will enable debug tracing output for the
31003 + ieee80211 network stack.
31004 +
31005 + If you are not trying to debug or develop the ieee80211
31006 + subsystem, you most likely want to say N here.
31007 +
31008 +config D80211_VERBOSE_DEBUG
31009 + bool "Verbose debugging output"
31010 + depends on D80211_DEBUG
31011 +
31012 +config TKIP_DEBUG
31013 + bool "TKIP debugging"
31014 + depends on D80211_DEBUG
31015 +
31016 +config D80211_DEBUG_COUNTERS
31017 + bool "Extra statistics for TX/RX debugging"
31018 + depends on D80211_DEBUG
31019 +
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
31026 @@ -0,0 +1,26 @@
31027 +obj-$(CONFIG_D80211) += 80211.o rate_control.o
31028 +
31029 +80211-objs := \
31030 + ieee80211.o \
31031 + ieee80211_ioctl.o \
31032 + sta_info.o \
31033 + wep.o \
31034 + wpa.o \
31035 + ieee80211_proc.o \
31036 + ieee80211_scan.o \
31037 + ieee80211_sta.o \
31038 + ieee80211_dev.o \
31039 + ieee80211_sysfs.o \
31040 + michael.o \
31041 + tkip.o \
31042 + aes_ccm.o \
31043 + wme.o
31044 +
31045 +ifeq ($(CONFIG_NET_SCHED),)
31046 + 80211-objs += fifo_qdisc.o
31047 +endif
31048 +
31049 +ifeq ($(CONFIG_D80211_LEDS),y)
31050 + 80211-objs += ieee80211_led.o
31051 +endif
31052 +
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
31056 @@ -0,0 +1,104 @@
31057 +/*
31058 + * Michael MIC implementation - optimized for TKIP MIC operations
31059 + * Copyright 2002-2003, Instant802 Networks, Inc.
31060 + *
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.
31064 + */
31065 +
31066 +#include <linux/types.h>
31067 +
31068 +#include "michael.h"
31069 +
31070 +static inline u32 rotr(u32 val, int bits)
31071 +{
31072 + return (val >> bits) | (val << (32 - bits));
31073 +}
31074 +
31075 +
31076 +static inline u32 rotl(u32 val, int bits)
31077 +{
31078 + return (val << bits) | (val >> (32 - bits));
31079 +}
31080 +
31081 +
31082 +static inline u32 xswap(u32 val)
31083 +{
31084 + return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
31085 +}
31086 +
31087 +
31088 +#define michael_block(l, r) \
31089 +do { \
31090 + r ^= rotl(l, 17); \
31091 + l += r; \
31092 + r ^= xswap(l); \
31093 + l += r; \
31094 + r ^= rotl(l, 3); \
31095 + l += r; \
31096 + r ^= rotr(l, 2); \
31097 + l += r; \
31098 +} while (0)
31099 +
31100 +
31101 +static inline u32 michael_get32(u8 *data)
31102 +{
31103 + return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
31104 +}
31105 +
31106 +
31107 +static inline void michael_put32(u32 val, u8 *data)
31108 +{
31109 + data[0] = val & 0xff;
31110 + data[1] = (val >> 8) & 0xff;
31111 + data[2] = (val >> 16) & 0xff;
31112 + data[3] = (val >> 24) & 0xff;
31113 +}
31114 +
31115 +
31116 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31117 + u8 *data, size_t data_len, u8 *mic)
31118 +{
31119 + u32 l, r, val;
31120 + size_t block, blocks, left;
31121 +
31122 + l = michael_get32(key);
31123 + r = michael_get32(key + 4);
31124 +
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);
31133 + l ^= priority;
31134 + michael_block(l, r);
31135 +
31136 + /* Real data */
31137 + blocks = data_len / 4;
31138 + left = data_len % 4;
31139 +
31140 + for (block = 0; block < blocks; block++) {
31141 + l ^= michael_get32(&data[block * 4]);
31142 + michael_block(l, r);
31143 + }
31144 +
31145 + /* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
31146 + * total length a multiple of 4. */
31147 + val = 0x5a;
31148 + while (left > 0) {
31149 + val <<= 8;
31150 + left--;
31151 + val |= data[blocks * 4 + left];
31152 + }
31153 + l ^= val;
31154 + michael_block(l, r);
31155 + /* last block is zero, so l ^ 0 = l */
31156 + michael_block(l, r);
31157 +
31158 + michael_put32(l, mic);
31159 + michael_put32(r, mic + 4);
31160 +}
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
31164 @@ -0,0 +1,20 @@
31165 +/*
31166 + * Michael MIC implementation - optimized for TKIP MIC operations
31167 + * Copyright 2002-2003, Instant802 Networks, Inc.
31168 + *
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.
31172 + */
31173 +
31174 +#ifndef MICHAEL_H
31175 +#define MICHAEL_H
31176 +
31177 +#include <linux/types.h>
31178 +
31179 +#define MICHAEL_MIC_LEN 8
31180 +
31181 +void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
31182 + u8 *data, size_t data_len, u8 *mic);
31183 +
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
31188 @@ -0,0 +1,385 @@
31189 +/*
31190 + * Copyright 2002-2005, Instant802 Networks, Inc.
31191 + * Copyright 2005, Devicescape Software, Inc.
31192 + *
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.
31196 + */
31197 +
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>
31207 +
31208 +#include <net/d80211.h>
31209 +#include "ieee80211_i.h"
31210 +#include "rate_control.h"
31211 +
31212 +
31213 +/* This is a minimal implementation of TX rate controlling that can be used
31214 + * as the default when no improved mechanisms are available. */
31215 +
31216 +
31217 +#define RATE_CONTROL_EMERG_DEC 2
31218 +#define RATE_CONTROL_INTERVAL (HZ / 20)
31219 +#define RATE_CONTROL_MIN_TX 10
31220 +
31221 +MODULE_ALIAS("ieee80211_rate_control");
31222 +
31223 +static void rate_control_rate_inc(struct ieee80211_local *local,
31224 + struct sta_info *sta)
31225 +{
31226 + struct ieee80211_sub_if_data *sdata;
31227 + int i = sta->txrate;
31228 + int maxrate;
31229 +
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 */
31233 + return;
31234 + }
31235 +
31236 + maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
31237 +
31238 + if (i > local->num_curr_rates)
31239 + i = local->num_curr_rates - 2;
31240 +
31241 + while (i + 1 < local->num_curr_rates) {
31242 + i++;
31243 + if (sta->supp_rates & BIT(i) &&
31244 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED &&
31245 + (maxrate < 0 || i <= maxrate)) {
31246 + sta->txrate = i;
31247 + break;
31248 + }
31249 + }
31250 +}
31251 +
31252 +
31253 +static void rate_control_rate_dec(struct ieee80211_local *local,
31254 + struct sta_info *sta)
31255 +{
31256 + struct ieee80211_sub_if_data *sdata;
31257 + int i = sta->txrate;
31258 +
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 */
31262 + return;
31263 + }
31264 +
31265 + if (i > local->num_curr_rates)
31266 + i = local->num_curr_rates;
31267 +
31268 + while (i > 0) {
31269 + i--;
31270 + if (sta->supp_rates & BIT(i) &&
31271 + local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED) {
31272 + sta->txrate = i;
31273 + break;
31274 + }
31275 + }
31276 +}
31277 +
31278 +
31279 +static struct ieee80211_rate *
31280 +rate_control_lowest_rate(struct ieee80211_local *local)
31281 +{
31282 + int i;
31283 +
31284 + for (i = 0; i < local->num_curr_rates; i++) {
31285 + struct ieee80211_rate *rate = &local->curr_rates[i];
31286 +
31287 + if (rate->flags & IEEE80211_RATE_SUPPORTED
31288 + )
31289 + return rate;
31290 + }
31291 +
31292 + printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
31293 + "found\n");
31294 + return &local->curr_rates[0];
31295 +}
31296 +
31297 +
31298 +struct global_rate_control {
31299 + int dummy;
31300 +};
31301 +
31302 +struct sta_rate_control {
31303 + unsigned long last_rate_change;
31304 + u32 tx_num_failures;
31305 + u32 tx_num_xmit;
31306 +
31307 + unsigned long avg_rate_update;
31308 + u32 tx_avg_rate_sum;
31309 + u32 tx_avg_rate_num;
31310 +};
31311 +
31312 +
31313 +static void rate_control_simple_tx_status(struct net_device *dev,
31314 + struct sk_buff *skb,
31315 + struct ieee80211_tx_status *status)
31316 +{
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;
31321 +
31322 + sta = sta_info_get(local, hdr->addr1);
31323 +
31324 + if (!sta)
31325 + return;
31326 +
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 "
31333 + "(@%lu)\n",
31334 + dev->name, MAC2STR(hdr->addr1),
31335 + sta->antenna_sel, jiffies);
31336 + }
31337 + srctrl->tx_num_failures++;
31338 + sta->tx_retry_failed++;
31339 + sta->tx_num_consecutive_failures++;
31340 + sta->tx_num_mpdu_fail++;
31341 + } else {
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++;
31347 + }
31348 + sta->tx_retry_count += status->retry_count;
31349 + sta->tx_num_mpdu_fail += status->retry_count;
31350 +
31351 + if (time_after(jiffies,
31352 + srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
31353 + srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
31354 + u32 per_failed;
31355 + srctrl->last_rate_change = jiffies;
31356 +
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 */
31361 +#if 0
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,
31365 + per_failed);
31366 + }
31367 +#endif
31368 +
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);
31373 + }
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);
31381 + }
31382 +
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: "
31388 + "%d (%d/%d)\n",
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;
31397 + }
31398 + }
31399 +
31400 + sta_info_release(local, sta);
31401 +}
31402 +
31403 +
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)
31407 +{
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;
31413 + u16 fc;
31414 +
31415 + memset(extra, 0, sizeof(*extra));
31416 +
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);
31424 + }
31425 +
31426 + sta = sta_info_get(local, hdr->addr1);
31427 +
31428 + if (!sta)
31429 + return rate_control_lowest_rate(local);
31430 +
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;
31434 +
31435 + rateidx = sta->txrate;
31436 +
31437 + if (rateidx >= local->num_curr_rates)
31438 + rateidx = local->num_curr_rates - 1;
31439 +
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))))
31447 + nonerp_idx--;
31448 + extra->nonerp_idx = nonerp_idx;
31449 + extra->nonerp = &local->curr_rates[extra->nonerp_idx];
31450 +
31451 + sta_info_release(local, sta);
31452 +
31453 + return &local->curr_rates[rateidx];
31454 +}
31455 +
31456 +
31457 +static void rate_control_simple_rate_init(struct ieee80211_local *local,
31458 + struct sta_info *sta)
31459 +{
31460 + int i;
31461 + sta->txrate = 0;
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))
31469 + sta->txrate = i;
31470 + }
31471 +}
31472 +
31473 +
31474 +static void * rate_control_simple_alloc(struct ieee80211_local *local)
31475 +{
31476 + struct global_rate_control *rctrl;
31477 +
31478 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31479 + if (rctrl == NULL) {
31480 + return NULL;
31481 + }
31482 + memset(rctrl, 0, sizeof(*rctrl));
31483 + return rctrl;
31484 +}
31485 +
31486 +
31487 +static void rate_control_simple_free(void *priv)
31488 +{
31489 + struct global_rate_control *rctrl = priv;
31490 + kfree(rctrl);
31491 +}
31492 +
31493 +
31494 +static void rate_control_simple_clear(void *priv)
31495 +{
31496 +}
31497 +
31498 +
31499 +static void * rate_control_simple_alloc_sta(void)
31500 +{
31501 + struct sta_rate_control *rctrl;
31502 +
31503 + rctrl = kmalloc(sizeof(*rctrl), GFP_ATOMIC);
31504 + if (rctrl == NULL) {
31505 + return NULL;
31506 + }
31507 + memset(rctrl, 0, sizeof(*rctrl));
31508 + return rctrl;
31509 +}
31510 +
31511 +
31512 +static void rate_control_simple_free_sta(void *priv)
31513 +{
31514 + struct sta_rate_control *rctrl = priv;
31515 + kfree(rctrl);
31516 +}
31517 +
31518 +
31519 +static int rate_control_simple_status_sta(struct ieee80211_local *local,
31520 + struct sta_info *sta, char *buf)
31521 +{
31522 + char *p = buf;
31523 + struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
31524 +
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);
31531 + return p - buf;
31532 +}
31533 +
31534 +
31535 +static int rate_control_simple_status_global(struct ieee80211_local *local,
31536 + char *buf)
31537 +{
31538 + return 0;
31539 +}
31540 +
31541 +
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,
31554 +};
31555 +
31556 +
31557 +int __init rate_control_simple_init(void)
31558 +{
31559 + return ieee80211_rate_control_register(&rate_control_simple);
31560 +}
31561 +
31562 +
31563 +static void __exit rate_control_simple_exit(void)
31564 +{
31565 + ieee80211_rate_control_unregister(&rate_control_simple);
31566 +}
31567 +
31568 +
31569 +module_init(rate_control_simple_init);
31570 +module_exit(rate_control_simple_exit);
31571 +
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
31577 @@ -0,0 +1,135 @@
31578 +/*
31579 + * Copyright 2002-2005, Instant802 Networks, Inc.
31580 + * Copyright 2005, Devicescape Software, Inc.
31581 + *
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.
31585 + */
31586 +
31587 +#ifndef RATE_CONTROL
31588 +#define RATE_CONTROL
31589 +
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"
31596 +
31597 +#define RATE_CONTROL_NUM_DOWN 20
31598 +#define RATE_CONTROL_NUM_UP 15
31599 +
31600 +
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
31604 + * probing */
31605 + int startidx, endidx, rateidx;
31606 + struct ieee80211_rate *nonerp;
31607 + int nonerp_idx;
31608 +
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) */
31612 + u16 ethertype;
31613 +};
31614 +
31615 +
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);
31628 +
31629 + void * (*alloc)(struct ieee80211_local *local);
31630 + void (*free)(void *priv);
31631 + void * (*alloc_sta)(void);
31632 + void (*free_sta)(void *priv);
31633 +};
31634 +
31635 +
31636 +int ieee80211_rate_control_register(struct rate_control_ops *ops);
31637 +void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
31638 +
31639 +
31640 +static inline void rate_control_tx_status(struct net_device *dev,
31641 + struct sk_buff *skb,
31642 + struct ieee80211_tx_status *status)
31643 +{
31644 + struct ieee80211_local *local = dev->priv;
31645 + local->rate_ctrl->tx_status(dev, skb, status);
31646 +}
31647 +
31648 +
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)
31652 +{
31653 + struct ieee80211_local *local = dev->priv;
31654 + return local->rate_ctrl->get_rate(dev, skb, extra);
31655 +}
31656 +
31657 +
31658 +static inline void rate_control_rate_init(struct ieee80211_local *local,
31659 + struct sta_info *sta)
31660 +{
31661 + local->rate_ctrl->rate_init(local, sta);
31662 +}
31663 +
31664 +
31665 +static inline void rate_control_clear(struct ieee80211_local *local)
31666 +{
31667 + local->rate_ctrl->clear(local->rate_ctrl_priv);
31668 +}
31669 +
31670 +
31671 +static inline int rate_control_status_sta(struct ieee80211_local *local,
31672 + struct sta_info *sta, char *buf)
31673 +{
31674 + return local->rate_ctrl->status_sta(local, sta, buf);
31675 +}
31676 +
31677 +
31678 +static inline int rate_control_status_global(struct ieee80211_local *local,
31679 + char *buf)
31680 +{
31681 + return local->rate_ctrl->status_global(local, buf);
31682 +}
31683 +
31684 +
31685 +static inline void * rate_control_alloc(struct ieee80211_local *local)
31686 +{
31687 + return local->rate_ctrl->alloc(local);
31688 +}
31689 +
31690 +
31691 +static inline void rate_control_free(struct ieee80211_local *local)
31692 +{
31693 + if (local->rate_ctrl == NULL || local->rate_ctrl_priv == NULL)
31694 + return;
31695 + local->rate_ctrl->free(local->rate_ctrl_priv);
31696 + local->rate_ctrl_priv = NULL;
31697 +}
31698 +
31699 +
31700 +static inline void * rate_control_alloc_sta(struct ieee80211_local *local)
31701 +{
31702 + return local->rate_ctrl->alloc_sta();
31703 +}
31704 +
31705 +
31706 +static inline void rate_control_free_sta(struct ieee80211_local *local,
31707 + void *priv)
31708 +{
31709 + local->rate_ctrl->free_sta(priv);
31710 +}
31711 +
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
31716 @@ -0,0 +1,413 @@
31717 +/*
31718 + * Copyright 2002-2005, Instant802 Networks, Inc.
31719 + *
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.
31723 + */
31724 +
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>
31734 +
31735 +#include <net/d80211.h>
31736 +#include "ieee80211_i.h"
31737 +#include "ieee80211_proc.h"
31738 +#include "rate_control.h"
31739 +
31740 +
31741 +/* Caller must hold local->sta_lock */
31742 +static void sta_info_hash_add(struct ieee80211_local *local,
31743 + struct sta_info *sta)
31744 +{
31745 + sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
31746 + local->sta_hash[STA_HASH(sta->addr)] = sta;
31747 +}
31748 +
31749 +
31750 +/* Caller must hold local->sta_lock */
31751 +static void sta_info_hash_del(struct ieee80211_local *local,
31752 + struct sta_info *sta)
31753 +{
31754 + struct sta_info *s;
31755 +
31756 + s = local->sta_hash[STA_HASH(sta->addr)];
31757 + if (s == NULL)
31758 + return;
31759 + if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
31760 + local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
31761 + return;
31762 + }
31763 +
31764 + while (s->hnext != NULL &&
31765 + memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
31766 + s = s->hnext;
31767 + if (s->hnext != NULL)
31768 + s->hnext = s->hnext->hnext;
31769 + else
31770 + printk(KERN_ERR "%s: could not remove STA " MACSTR " from "
31771 + "hash table\n", local->mdev->name, MAC2STR(sta->addr));
31772 +}
31773 +
31774 +
31775 +struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr)
31776 +{
31777 + struct sta_info *sta;
31778 +
31779 + spin_lock_bh(&local->sta_lock);
31780 + sta = local->sta_hash[STA_HASH(addr)];
31781 + while (sta) {
31782 + if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
31783 + atomic_inc(&sta->users);
31784 + break;
31785 + }
31786 + sta = sta->hnext;
31787 + }
31788 + spin_unlock_bh(&local->sta_lock);
31789 +
31790 + return sta;
31791 +}
31792 +
31793 +
31794 +int sta_info_min_txrate_get(struct ieee80211_local *local)
31795 +{
31796 + struct sta_info *sta;
31797 + int min_txrate = 9999999;
31798 + int i;
31799 +
31800 + spin_lock_bh(&local->sta_lock);
31801 + for (i = 0; i < STA_HASH_SIZE; i++) {
31802 + sta = local->sta_hash[i];
31803 + while (sta) {
31804 + if (sta->txrate < min_txrate)
31805 + min_txrate = sta->txrate;
31806 + sta = sta->hnext;
31807 + }
31808 + }
31809 + spin_unlock_bh(&local->sta_lock);
31810 + if (min_txrate == 9999999)
31811 + min_txrate = 0;
31812 +
31813 + return min_txrate;
31814 +}
31815 +
31816 +
31817 +void sta_info_release(struct ieee80211_local *local, struct sta_info *sta)
31818 +{
31819 + struct sk_buff *skb;
31820 +
31821 + if (!atomic_dec_and_test(&sta->users))
31822 + return;
31823 +
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);
31831 + }
31832 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31833 + dev_kfree_skb_any(skb);
31834 + }
31835 + rate_control_free_sta(local, sta->rate_ctrl_priv);
31836 + kfree(sta);
31837 +}
31838 +
31839 +
31840 +struct sta_info * sta_info_add(struct ieee80211_local *local,
31841 + struct net_device *dev, u8 *addr)
31842 +{
31843 + struct sta_info *sta;
31844 +
31845 + sta = kmalloc(sizeof(*sta), GFP_ATOMIC);
31846 + if (!sta)
31847 + return NULL;
31848 +
31849 + memset(sta, 0, sizeof(*sta));
31850 +
31851 + sta->rate_ctrl_priv = rate_control_alloc_sta(local);
31852 + if (sta->rate_ctrl_priv == NULL) {
31853 + kfree(sta);
31854 + return NULL;
31855 + }
31856 +
31857 + memcpy(sta->addr, addr, ETH_ALEN);
31858 + sta->dev = dev;
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;
31873 +
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 */
31878 +
31879 + if (!in_interrupt()) {
31880 + ieee80211_proc_init_sta(local, sta);
31881 + } else {
31882 + /* procfs entry adding might sleep, so schedule process context
31883 + * task for adding proc entry for STAs that do not yet have
31884 + * one. */
31885 + schedule_work(&local->sta_proc_add);
31886 + }
31887 +
31888 + return sta;
31889 +}
31890 +
31891 +
31892 +void sta_info_free(struct ieee80211_local *local, struct sta_info *sta,
31893 + int locked)
31894 +{
31895 + struct sk_buff *skb;
31896 + struct ieee80211_sub_if_data *sdata;
31897 +
31898 + if (!locked)
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;
31905 + if (sdata->bss)
31906 + atomic_dec(&sdata->bss->num_sta_ps);
31907 + }
31908 + local->num_sta--;
31909 + sta_info_remove_aid_ptr(sta);
31910 + if (!locked)
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);
31914 +
31915 + while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
31916 + local->total_ps_buffered--;
31917 + dev_kfree_skb_any(skb);
31918 + }
31919 + while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
31920 + dev_kfree_skb_any(skb);
31921 + }
31922 +
31923 + if (sta->key) {
31924 + if (local->hw->set_key) {
31925 + struct ieee80211_key_conf *key;
31926 + key = ieee80211_key_data2conf(local, sta->key);
31927 + if (key) {
31928 + local->hw->set_key(local->mdev, DISABLE_KEY,
31929 + sta->addr, key, sta->aid);
31930 + kfree(key);
31931 + }
31932 + }
31933 + kfree(sta->key);
31934 + sta->key = NULL;
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,
31942 + sta->aid);
31943 + sta->key_idx_compression = HW_KEY_IDX_INVALID;
31944 + }
31945 +
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 */
31950 +
31951 + ieee80211_proc_deinit_sta(local, sta);
31952 +
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));
31960 + }
31961 +
31962 + sta_info_release(local, sta);
31963 +}
31964 +
31965 +
31966 +static inline int sta_info_buffer_expired(struct sk_buff *skb)
31967 +{
31968 + struct ieee80211_tx_packet_data *pkt_data;
31969 + if (!skb)
31970 + return 0;
31971 +
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 */
31975 +
31976 + pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
31977 + return time_after(jiffies, pkt_data->jiffies + STA_TX_BUFFER_EXPIRE);
31978 +}
31979 +
31980 +
31981 +static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
31982 + struct sta_info *sta)
31983 +{
31984 + unsigned long flags;
31985 + struct sk_buff *skb;
31986 +
31987 + if (skb_queue_empty(&sta->ps_tx_buf))
31988 + return;
31989 +
31990 + for (;;) {
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);
31995 + else
31996 + skb = NULL;
31997 + spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
31998 +
31999 + if (skb) {
32000 + local->total_ps_buffered--;
32001 + printk(KERN_DEBUG "Buffered frame expired (STA "
32002 + MACSTR ")\n", MAC2STR(sta->addr));
32003 + dev_kfree_skb(skb);
32004 + } else
32005 + break;
32006 + }
32007 +}
32008 +
32009 +
32010 +static void sta_info_cleanup(unsigned long data)
32011 +{
32012 + struct ieee80211_local *local = (struct ieee80211_local *) data;
32013 + struct list_head *ptr;
32014 +
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);
32022 + ptr = ptr->next;
32023 + }
32024 + spin_unlock_bh(&local->sta_lock);
32025 +
32026 + local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
32027 + add_timer(&local->sta_cleanup);
32028 +}
32029 +
32030 +
32031 +static void sta_info_proc_add_task(void *data)
32032 +{
32033 + struct ieee80211_local *local = data;
32034 + struct list_head *ptr;
32035 + struct sta_info *sta;
32036 + int max_adds = 100;
32037 +
32038 + while (max_adds > 0) {
32039 + sta = NULL;
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);
32045 + break;
32046 + }
32047 + sta = NULL;
32048 + }
32049 + spin_unlock_bh(&local->sta_lock);
32050 +
32051 + if (!sta)
32052 + break;
32053 +
32054 + ieee80211_proc_init_sta(local, sta);
32055 + atomic_dec(&sta->users);
32056 +
32057 + max_adds--;
32058 + }
32059 +}
32060 +
32061 +
32062 +void sta_info_init(struct ieee80211_local *local)
32063 +{
32064 + spin_lock_init(&local->sta_lock);
32065 + INIT_LIST_HEAD(&local->sta_list);
32066 +
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;
32071 +
32072 + INIT_WORK(&local->sta_proc_add, sta_info_proc_add_task, local);
32073 +}
32074 +
32075 +void sta_info_start(struct ieee80211_local *local)
32076 +{
32077 + add_timer(&local->sta_cleanup);
32078 +}
32079 +
32080 +void sta_info_stop(struct ieee80211_local *local)
32081 +{
32082 + struct list_head *ptr;
32083 +
32084 + del_timer(&local->sta_cleanup);
32085 +
32086 + ptr = local->sta_list.next;
32087 + while (ptr && ptr != &local->sta_list) {
32088 + struct sta_info *sta = (struct sta_info *) ptr;
32089 + ptr = ptr->next;
32090 + sta_info_free(local, sta, 0);
32091 + }
32092 +}
32093 +
32094 +
32095 +void sta_info_remove_aid_ptr(struct sta_info *sta)
32096 +{
32097 + struct ieee80211_sub_if_data *sdata;
32098 +
32099 + sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
32100 + if (sta->aid <= 0 || !sdata->bss)
32101 + return;
32102 +
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--;
32108 + }
32109 +}
32110 +
32111 +
32112 +/**
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
32116 + */
32117 +void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
32118 +{
32119 + struct list_head *ptr, *n;
32120 +
32121 + spin_lock_bh(&local->sta_lock);
32122 +
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);
32127 + }
32128 + spin_unlock_bh(&local->sta_lock);
32129 +}
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
32133 @@ -0,0 +1,148 @@
32134 +/*
32135 + * Copyright 2002-2005, Devicescape Software, Inc.
32136 + *
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.
32140 + */
32141 +
32142 +#ifndef STA_INFO_H
32143 +#define STA_INFO_H
32144 +
32145 +#include <linux/if_ether.h>
32146 +#include <linux/types.h>
32147 +#include "ieee80211_i.h"
32148 +#include "ieee80211_key.h"
32149 +
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
32159 + */
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)
32164 +
32165 +
32166 +struct sta_info {
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) */
32170 +
32171 + u8 addr[ETH_ALEN];
32172 + u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
32173 + u32 flags; /* WLAN_STA_ */
32174 +
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;
32182 +
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;
32187 +
32188 + unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
32189 +
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;
32195 +
32196 + struct net_device *dev; /* which net device is this station associated
32197 + * to */
32198 +
32199 + struct ieee80211_key *key;
32200 +
32201 + u32 tx_num_consecutive_failures;
32202 + u32 tx_num_mpdu_ok;
32203 + u32 tx_num_mpdu_fail;
32204 +
32205 + void *rate_ctrl_priv;
32206 +
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 */
32214 +
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;
32218 + int channel_use;
32219 + int channel_use_raw;
32220 +
32221 + int antenna_sel;
32222 +
32223 +
32224 + int key_idx_compression; /* key table index for compression and TX
32225 + * filtering; used only if sta->key is not
32226 + * set */
32227 +
32228 + int proc_entry_added:1;
32229 + int assoc_ap:1; /* whether this is an AP that we are associated with
32230 + * as a client */
32231 +
32232 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
32233 + u32 wpa_trigger;
32234 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
32235 +
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 */
32240 +
32241 + int vlan_id;
32242 +};
32243 +
32244 +
32245 +/* Maximum number of concurrently registered stations */
32246 +#define MAX_STA_COUNT 2007
32247 +
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
32251 +
32252 +#define STA_HASH_SIZE 256
32253 +#define STA_HASH(sta) (sta[5])
32254 +
32255 +
32256 +/* Maximum number of frames to buffer per power saving station */
32257 +#define STA_MAX_TX_BUFFER 128
32258 +
32259 +/* Buffered frame expiry time */
32260 +#define STA_TX_BUFFER_EXPIRE (10 * HZ)
32261 +
32262 +/* How often station data is cleaned up (e.g., expiration of buffered frames)
32263 + */
32264 +#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
32265 +
32266 +struct ieee80211_local;
32267 +
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,
32274 + int locked);
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);
32280 +
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
32285 @@ -0,0 +1,341 @@
32286 +/*
32287 + * Copyright 2002-2004, Instant802 Networks, Inc.
32288 + * Copyright 2005, Devicescape Software, Inc.
32289 + *
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.
32293 + */
32294 +
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 */
32302 +
32303 +#include <linux/types.h>
32304 +#include <linux/netdevice.h>
32305 +
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 */
32311 +#include "tkip.h"
32312 +
32313 +/* Dummy prototypes for structures used in wep.h, but not really needed for
32314 + * TKIP. */
32315 +struct ieee80211_local;
32316 +struct sk_buff;
32317 +#include "wep.h"
32318 +
32319 +
32320 +/* TKIP key mixing functions */
32321 +
32322 +
32323 +#define PHASE1_LOOP_COUNT 8
32324 +
32325 +
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] =
32329 +{
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,
32362 +};
32363 +
32364 +
32365 +static inline u16 Mk16(u8 x, u8 y)
32366 +{
32367 + return ((u16) x << 8) | (u16) y;
32368 +}
32369 +
32370 +
32371 +static inline u8 Hi8(u16 v)
32372 +{
32373 + return v >> 8;
32374 +}
32375 +
32376 +
32377 +static inline u8 Lo8(u16 v)
32378 +{
32379 + return v & 0xff;
32380 +}
32381 +
32382 +
32383 +static inline u16 Hi16(u32 v)
32384 +{
32385 + return v >> 16;
32386 +}
32387 +
32388 +
32389 +static inline u16 Lo16(u32 v)
32390 +{
32391 + return v & 0xffff;
32392 +}
32393 +
32394 +
32395 +static inline u16 RotR1(u16 v)
32396 +{
32397 + return (v >> 1) | ((v & 0x0001) << 15);
32398 +}
32399 +
32400 +
32401 +static inline u16 tkip_S(u16 val)
32402 +{
32403 + u16 a = tkip_sbox[Hi8(val)];
32404 +
32405 + return tkip_sbox[Lo8(val)] ^ Hi8(a) ^ (Lo8(a) << 8);
32406 +}
32407 +
32408 +
32409 +
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)
32414 + * P1K: 80 bits
32415 + */
32416 +static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
32417 + u16 *p1k)
32418 +{
32419 + int i, j;
32420 +
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]);
32426 +
32427 + for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
32428 + j = 2 * (i & 1);
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;
32434 + }
32435 +}
32436 +
32437 +
32438 +static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
32439 + u8 *rc4key)
32440 +{
32441 + u16 ppk[6];
32442 + int i;
32443 +
32444 + ppk[0] = p1k[0];
32445 + ppk[1] = p1k[1];
32446 + ppk[2] = p1k[2];
32447 + ppk[3] = p1k[3];
32448 + ppk[4] = p1k[4];
32449 + ppk[5] = p1k[4] + tsc_IV16;
32450 +
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]);
32463 +
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);
32468 +
32469 + for (i = 0; i < 6; i++) {
32470 + rc4key[4 + 2 * i] = Lo8(ppk[i]);
32471 + rc4key[5 + 2 * i] = Hi8(ppk[i]);
32472 + }
32473 +}
32474 +
32475 +
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)
32481 +{
32482 + *pos++ = iv0;
32483 + *pos++ = iv1;
32484 + *pos++ = 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;
32490 + return pos;
32491 +}
32492 +
32493 +
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)
32501 +{
32502 + u8 rc4key[16];
32503 +
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;
32510 + }
32511 +
32512 + tkip_mixing_phase2(key->u.tkip.p1k, &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32513 + key->u.tkip.iv16, rc4key);
32514 +
32515 + pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]);
32516 + ieee80211_wep_encrypt_data(rc4key, 16, pos, payload_len);
32517 +}
32518 +
32519 +
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,
32526 + int queue)
32527 +{
32528 + u32 iv32;
32529 + u32 iv16;
32530 + u8 rc4key[16], keyid, *pos = payload;
32531 + int res;
32532 +
32533 + if (payload_len < 12)
32534 + return -1;
32535 +
32536 + iv16 = (pos[0] << 8) | pos[2];
32537 + keyid = pos[3];
32538 + iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
32539 + pos += 8;
32540 +#ifdef CONFIG_TKIP_DEBUG
32541 + {
32542 + int i;
32543 + printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len);
32544 + for (i = 0; i < payload_len; i++)
32545 + printk(" %02x", payload[i]);
32546 + printk("\n");
32547 + printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n",
32548 + iv16, iv32);
32549 + }
32550 +#endif /* CONFIG_TKIP_DEBUG */
32551 +
32552 + if (!(keyid & (1 << 5)))
32553 + return TKIP_DECRYPT_NO_EXT_IV;
32554 +
32555 + if ((keyid >> 6) != key->keyidx)
32556 + return TKIP_DECRYPT_INVALID_KEYIDX;
32557 +
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",
32565 + MAC2STR(ta),
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;
32570 + }
32571 +
32572 + if (only_iv) {
32573 + res = TKIP_DECRYPT_OK;
32574 + goto done;
32575 + }
32576 +
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
32584 + {
32585 + int i;
32586 + printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=" MACSTR
32587 + " TK=", MAC2STR(ta));
32588 + for (i = 0; i < 16; i++)
32589 + printk("%02x ",
32590 + key->key[ALG_TKIP_TEMP_ENCR_KEY + i]);
32591 + printk("\n");
32592 + printk(KERN_DEBUG "TKIP decrypt: P1K=");
32593 + for (i = 0; i < 5; i++)
32594 + printk("%04x ", key->u.tkip.p1k_rx[queue][i]);
32595 + printk("\n");
32596 + }
32597 +#endif /* CONFIG_TKIP_DEBUG */
32598 + }
32599 +
32600 + tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
32601 + &key->key[ALG_TKIP_TEMP_ENCR_KEY],
32602 + iv16, rc4key);
32603 +#ifdef CONFIG_TKIP_DEBUG
32604 + {
32605 + int i;
32606 + printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key=");
32607 + for (i = 0; i < 16; i++)
32608 + printk("%02x ", rc4key[i]);
32609 + printk("\n");
32610 + }
32611 +#endif /* CONFIG_TKIP_DEBUG */
32612 +
32613 + res = ieee80211_wep_decrypt_data(rc4key, 16, pos, payload_len - 12);
32614 + done:
32615 + if (res == TKIP_DECRYPT_OK) {
32616 + /* FIX: these should be updated only after Michael MIC has been
32617 + * verified */
32618 + /* Record previously received IV */
32619 + key->u.tkip.iv32_rx[queue] = iv32;
32620 + key->u.tkip.iv16_rx[queue] = iv16;
32621 + }
32622 +
32623 + return res;
32624 +}
32625 +
32626 +
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
32630 @@ -0,0 +1,29 @@
32631 +/*
32632 + * Copyright 2002-2004, Instant802 Networks, Inc.
32633 + *
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.
32637 + */
32638 +
32639 +#ifndef TKIP_H
32640 +#define TKIP_H
32641 +
32642 +#include <linux/types.h>
32643 +#include "ieee80211_key.h"
32644 +
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);
32649 +enum {
32650 + TKIP_DECRYPT_OK = 0,
32651 + TKIP_DECRYPT_NO_EXT_IV = -1,
32652 + TKIP_DECRYPT_INVALID_KEYIDX = -2,
32653 + TKIP_DECRYPT_REPLAY = -3,
32654 +};
32655 +int ieee80211_tkip_decrypt_data(struct ieee80211_key *key, u8 *payload,
32656 + size_t payload_len, u8 *ta, int only_iv,
32657 + int queue);
32658 +
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
32663 @@ -0,0 +1,423 @@
32664 +/*
32665 + * Software WEP encryption implementation
32666 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
32667 + * Copyright 2003, Instant802 Networks, Inc.
32668 + *
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.
32672 + */
32673 +
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>
32680 +
32681 +#include <net/d80211.h>
32682 +#include "ieee80211_i.h"
32683 +#include "wep.h"
32684 +
32685 +
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,
32738 + 0x2d02ef8dL
32739 +};
32740 +
32741 +
32742 +void ieee80211_wep_init(struct ieee80211_local *local)
32743 +{
32744 + /* start WEP IV from a random value */
32745 + get_random_bytes(&local->wep_iv, WEP_IV_LEN);
32746 +}
32747 +
32748 +
32749 +static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
32750 +{
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)
32757 + return 1;
32758 + }
32759 + return 0;
32760 +}
32761 +
32762 +
32763 +void ieee80211_wep_get_iv(struct ieee80211_local *local,
32764 + struct ieee80211_key *key, u8 *iv)
32765 +{
32766 + local->wep_iv++;
32767 + if (ieee80211_wep_weak_iv(local->wep_iv, key->keylen))
32768 + local->wep_iv += 0x0100;
32769 +
32770 + if (iv == NULL)
32771 + return;
32772 +
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;
32777 +}
32778 +
32779 +
32780 +u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
32781 + struct sk_buff *skb,
32782 + struct ieee80211_key *key)
32783 +{
32784 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32785 + u16 fc;
32786 + int hdrlen;
32787 + u8 *newhdr;
32788 +
32789 + fc = le16_to_cpu(hdr->frame_control);
32790 + fc |= WLAN_FC_ISWEP;
32791 + hdr->frame_control = cpu_to_le16(fc);
32792 +
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,
32797 + GFP_ATOMIC)))
32798 + return NULL;
32799 + }
32800 +
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;
32806 +}
32807 +
32808 +
32809 +void ieee80211_wep_remove_iv(struct ieee80211_local *local,
32810 + struct sk_buff *skb,
32811 + struct ieee80211_key *key)
32812 +{
32813 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32814 + u16 fc;
32815 + int hdrlen;
32816 +
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);
32821 +}
32822 +
32823 +
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,
32828 + size_t data_len)
32829 +{
32830 + u32 i, j, k, crc;
32831 + u8 S[256];
32832 + u8 kpos, *pos;
32833 +#define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
32834 +
32835 + /* Setup RC4 state */
32836 + for (i = 0; i < 256; i++)
32837 + S[i] = i;
32838 + j = 0;
32839 + kpos = 0;
32840 + for (i = 0; i < 256; i++) {
32841 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32842 + kpos++;
32843 + if (kpos >= klen)
32844 + kpos = 0;
32845 + S_SWAP(i, j);
32846 + }
32847 +
32848 + /* Compute CRC32 over unencrypted data and apply RC4 to data */
32849 + pos = data;
32850 + crc = ~0;
32851 + i = j = 0;
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;
32856 + S_SWAP(i, j);
32857 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32858 + }
32859 + crc = ~crc;
32860 +
32861 + /* Append little-endian CRC32 and encrypt it to produce ICV */
32862 + pos[0] = crc;
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;
32869 + S_SWAP(i, j);
32870 + *pos++ ^= S[(S[i] + S[j]) & 0xff];
32871 + }
32872 +}
32873 +
32874 +
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.
32879 + *
32880 + * WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
32881 + */
32882 +int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
32883 + struct ieee80211_key *key)
32884 +{
32885 + u32 klen;
32886 + u8 *rc4key, *iv;
32887 + size_t len;
32888 +
32889 + if (key == NULL || key->alg != ALG_WEP)
32890 + return -1;
32891 +
32892 + klen = 3 + key->keylen;
32893 + rc4key = kmalloc(klen, GFP_ATOMIC);
32894 + if (rc4key == NULL)
32895 + return -1;
32896 +
32897 + iv = ieee80211_wep_add_iv(local, skb, key);
32898 + if (iv == NULL) {
32899 + kfree(rc4key);
32900 + return -1;
32901 + }
32902 +
32903 + len = skb->len - (iv + WEP_IV_LEN - skb->data);
32904 +
32905 + /* Prepend 24-bit IV to RC4 key */
32906 + memcpy(rc4key, iv, 3);
32907 +
32908 + /* Copy rest of the WEP key (the secret part) */
32909 + memcpy(rc4key + 3, key->key, key->keylen);
32910 +
32911 + /* Add room for ICV */
32912 + skb_put(skb, WEP_ICV_LEN);
32913 +
32914 + ieee80211_wep_encrypt_data(rc4key, klen, iv + WEP_IV_LEN, len);
32915 +
32916 + kfree(rc4key);
32917 +
32918 + return 0;
32919 +}
32920 +
32921 +
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,
32926 + size_t data_len)
32927 +{
32928 + u32 i, j, k, crc;
32929 + u8 S[256];
32930 + u8 kpos, *pos, crcbuf[WEP_ICV_LEN], *cpos;
32931 +
32932 + /* Setup RC4 state */
32933 + for (i = 0; i < 256; i++)
32934 + S[i] = i;
32935 + j = 0;
32936 + kpos = 0;
32937 + for (i = 0; i < 256; i++) {
32938 + j = (j + S[i] + rc4key[kpos]) & 0xff;
32939 + kpos++;
32940 + if (kpos >= klen)
32941 + kpos = 0;
32942 + S_SWAP(i, j);
32943 + }
32944 +
32945 + /* Apply RC4 to data and compute CRC32 over decrypted data */
32946 + pos = data;
32947 + crc = ~0;
32948 + i = j = 0;
32949 + for (k = 0; k < data_len; k++) {
32950 + i = (i + 1) & 0xff;
32951 + j = (j + S[i]) & 0xff;
32952 + S_SWAP(i, j);
32953 + *pos ^= S[(S[i] + S[j]) & 0xff];
32954 + crc = crc32_table[(crc ^ *pos++) & 0xff] ^ (crc >> 8);
32955 + }
32956 + crc = ~crc;
32957 +
32958 + /* Decrypt little-endian CRC32 and verify that it matches with the
32959 + * received ICV */
32960 + cpos = crcbuf;
32961 + crcbuf[0] = crc;
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;
32968 + S_SWAP(i, j);
32969 + if (*cpos++ != (*pos++ ^ S[(S[i] + S[j]) & 0xff])) {
32970 + /* ICV mismatch */
32971 + return -1;
32972 + }
32973 + }
32974 +
32975 + return 0;
32976 +}
32977 +
32978 +
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.
32982 + *
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.
32986 + */
32987 +int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
32988 + struct ieee80211_key *key)
32989 +{
32990 + u32 klen;
32991 + u8 *rc4key;
32992 + u8 keyidx;
32993 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
32994 + u16 fc;
32995 + int hdrlen;
32996 + size_t len;
32997 + int ret = 0;
32998 +
32999 + fc = le16_to_cpu(hdr->frame_control);
33000 + if (!(fc & WLAN_FC_ISWEP))
33001 + return -1;
33002 +
33003 + hdrlen = ieee80211_get_hdrlen(fc);
33004 +
33005 + if (skb->len < 8 + hdrlen)
33006 + return -1;
33007 +
33008 + len = skb->len - hdrlen - 8;
33009 +
33010 + keyidx = skb->data[hdrlen + 3] >> 6;
33011 +
33012 + if (key == NULL || keyidx != key->keyidx || key->alg != ALG_WEP)
33013 + return -1;
33014 +
33015 + klen = 3 + key->keylen;
33016 +
33017 + rc4key = kmalloc(klen, GFP_ATOMIC);
33018 + if (rc4key == NULL)
33019 + return -1;
33020 +
33021 + /* Prepend 24-bit IV to RC4 key */
33022 + memcpy(rc4key, skb->data + hdrlen, 3);
33023 +
33024 + /* Copy rest of the WEP key (the secret part) */
33025 + memcpy(rc4key + 3, key->key, key->keylen);
33026 +
33027 + if (ieee80211_wep_decrypt_data(rc4key, klen,
33028 + skb->data + hdrlen + WEP_IV_LEN,
33029 + len)) {
33030 + printk(KERN_DEBUG "WEP decrypt failed (ICV)\n");
33031 + ret = -1;
33032 + }
33033 +
33034 + kfree(rc4key);
33035 +
33036 + /* Trim ICV */
33037 + skb_trim(skb, skb->len - WEP_ICV_LEN);
33038 +
33039 + /* Remove IV */
33040 + memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
33041 + skb_pull(skb, WEP_IV_LEN);
33042 +
33043 + return ret;
33044 +}
33045 +
33046 +
33047 +int ieee80211_wep_get_keyidx(struct sk_buff *skb)
33048 +{
33049 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33050 + u16 fc;
33051 + int hdrlen;
33052 +
33053 + fc = le16_to_cpu(hdr->frame_control);
33054 + if (!(fc & WLAN_FC_ISWEP))
33055 + return -1;
33056 +
33057 + hdrlen = ieee80211_get_hdrlen(fc);
33058 +
33059 + if (skb->len < 8 + hdrlen)
33060 + return -1;
33061 +
33062 + return skb->data[hdrlen + 3] >> 6;
33063 +}
33064 +
33065 +
33066 +u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
33067 +{
33068 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
33069 + u16 fc;
33070 + int hdrlen;
33071 + u8 *ivpos;
33072 + u32 iv;
33073 +
33074 + fc = le16_to_cpu(hdr->frame_control);
33075 + if (!(fc & WLAN_FC_ISWEP))
33076 + return NULL;
33077 +
33078 + hdrlen = ieee80211_get_hdrlen(fc);
33079 + ivpos = skb->data + hdrlen;
33080 + iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
33081 +
33082 + if (ieee80211_wep_weak_iv(iv, key->keylen))
33083 + return ivpos;
33084 +
33085 + return NULL;
33086 +}
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
33090 @@ -0,0 +1,39 @@
33091 +/*
33092 + * Software WEP encryption implementation
33093 + * Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
33094 + * Copyright 2003, Instant802 Networks, Inc.
33095 + *
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.
33099 + */
33100 +
33101 +#ifndef WEP_H
33102 +#define WEP_H
33103 +
33104 +#include <linux/skbuff.h>
33105 +#include <linux/types.h>
33106 +#include "ieee80211_i.h"
33107 +#include "ieee80211_key.h"
33108 +
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);
33128 +
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
33133 @@ -0,0 +1,695 @@
33134 +/*
33135 + * Copyright 2004, Instant802 Networks, Inc.
33136 + *
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.
33140 + */
33141 +
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>
33149 +
33150 +#include <net/d80211.h>
33151 +#include "ieee80211_i.h"
33152 +#include "wme.h"
33153 +
33154 +#define CHILD_QDISC_OPS pfifo_qdisc_ops
33155 +
33156 +static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
33157 +{
33158 + return (fc & 0x8C) == 0x88;
33159 +}
33160 +
33161 +
33162 +ieee80211_txrx_result
33163 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
33164 +{
33165 + u8 *data = rx->skb->data;
33166 + int tid;
33167 +
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;
33173 + } else {
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;
33177 + } else {
33178 + /* no qos control present */
33179 + tid = 0; /* 802.1d - Best Effort */
33180 + }
33181 + }
33182 +#ifdef CONFIG_D80211_DEBUG_COUNTERS
33183 + I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
33184 + if (rx->sta) {
33185 + I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
33186 + }
33187 +#endif /* CONFIG_D80211_DEBUG_COUNTERS */
33188 +
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;
33193 +
33194 + return TXRX_CONTINUE;
33195 +}
33196 +
33197 +
33198 +ieee80211_txrx_result
33199 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
33200 +{
33201 + u16 fc = rx->fc;
33202 + u8 *data = rx->skb->data;
33203 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
33204 +
33205 + if (!WLAN_FC_IS_QOS_DATA(fc))
33206 + return TXRX_CONTINUE;
33207 +
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);
33214 +
33215 + return TXRX_CONTINUE;
33216 +}
33217 +
33218 +
33219 +/* maximum number of hardware queues we support. */
33220 +#define TC_80211_MAX_QUEUES 8
33221 +
33222 +struct ieee80211_sched_data
33223 +{
33224 + struct tcf_proto *filter_list;
33225 + struct Qdisc *queues[TC_80211_MAX_QUEUES];
33226 + struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
33227 +};
33228 +
33229 +
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)
33232 +{
33233 + struct iphdr *ip;
33234 + int dscp;
33235 + int offset;
33236 +
33237 +#ifdef CONFIG_NET_SCHED
33238 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33239 + struct tcf_result res = { -1, 0 };
33240 +
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;
33246 + }
33247 +#endif /* CONFIG_NET_SCHED */
33248 +
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;
33255 +
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))
33260 + return 0;
33261 +
33262 + ip = (struct iphdr *) (skb->data + offset);
33263 +
33264 + dscp = ip->tos & 0xfc;
33265 + switch (dscp) {
33266 + case 0x20:
33267 + return 2;
33268 + case 0x40:
33269 + return 1;
33270 + case 0x60:
33271 + return 3;
33272 + case 0x80:
33273 + return 4;
33274 + case 0xa0:
33275 + return 5;
33276 + case 0xc0:
33277 + return 6;
33278 + case 0xe0:
33279 + return 7;
33280 + default:
33281 + return 0;
33282 + }
33283 +}
33284 +
33285 +
33286 +static inline int wme_downgrade_ac(struct sk_buff *skb)
33287 +{
33288 + switch (skb->priority) {
33289 + case 6:
33290 + case 7:
33291 + skb->priority = 5; /* VO -> VI */
33292 + return 0;
33293 + case 4:
33294 + case 5:
33295 + skb->priority = 3; /* VI -> BE */
33296 + return 0;
33297 + case 0:
33298 + case 3:
33299 + skb->priority = 2; /* BE -> BK */
33300 + return 0;
33301 + default:
33302 + return -1;
33303 + }
33304 +}
33305 +
33306 +
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)
33310 +{
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);
33316 + int qos;
33317 + const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
33318 +
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;
33324 + }
33325 +
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];
33332 + }
33333 +
33334 + /* is this a QoS frame? */
33335 + qos = fc & (WLAN_FC_STYPE_QOS_DATA << 4);
33336 +
33337 + if (!qos) {
33338 + skb->priority = 0; /* required for correct WPA/11i MIC */
33339 + return ieee802_1d_to_ac[skb->priority];
33340 + }
33341 +
33342 + /* use the data classifier to determine what 802.1d tag the
33343 + * data frame has */
33344 + skb->priority = classify_1d(skb, qd);
33345 +
33346 + /* incase we are a client verify acm is not set for this ac */
33347 + for (; unlikely(local->wmm_acm & BIT(skb->priority)); )
33348 + {
33349 + if (wme_downgrade_ac(skb)) {
33350 + /* No AC with lower priority has acm=0,
33351 + * drop packet. */
33352 + return -1;
33353 + }
33354 + }
33355 +
33356 + /* look up which queue to use for frames with this 1d tag */
33357 + return ieee802_1d_to_ac[skb->priority];
33358 +}
33359 +
33360 +
33361 +static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
33362 +{
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;
33370 + int err, queue;
33371 +
33372 + if (pkt_data->requeue) {
33373 + skb_queue_tail(&q->requeued[pkt_data->queue], skb);
33374 + return 0;
33375 + }
33376 +
33377 + queue = classify80211(skb, qd);
33378 +
33379 + /* now we know the 1d priority, fill in the QoS header if there is one
33380 + */
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 */
33387 + *p = 0;
33388 + qc->tag1d = skb->priority;
33389 + if (local->wifi_wme_noack_test)
33390 + qc->ack_policy = 1;
33391 + }
33392 +
33393 + if (unlikely(queue >= local->hw->queues)) {
33394 +#if 0
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);
33399 + }
33400 +#endif
33401 + queue = local->hw->queues - 1;
33402 + }
33403 +
33404 + if (unlikely(queue < 0)) {
33405 + kfree_skb(skb);
33406 + err = NET_XMIT_DROP;
33407 + } else {
33408 + pkt_data->queue = (unsigned int) queue;
33409 + qdisc = q->queues[queue];
33410 + err = qdisc->enqueue(skb, qdisc);
33411 + if (err == NET_XMIT_SUCCESS) {
33412 + qd->q.qlen++;
33413 + qd->bstats.bytes += skb->len;
33414 + qd->bstats.packets++;
33415 + return NET_XMIT_SUCCESS;
33416 + }
33417 + }
33418 + qd->qstats.drops++;
33419 + return err;
33420 +}
33421 +
33422 +
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)
33427 +{
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;
33432 + int err;
33433 +
33434 + /* we recorded which queue to use earlier! */
33435 + qdisc = q->queues[pkt_data->queue];
33436 +
33437 + if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
33438 + qd->q.qlen++;
33439 + return 0;
33440 + }
33441 + qd->qstats.drops++;
33442 + return err;
33443 +}
33444 +
33445 +
33446 +static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
33447 +{
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;
33455 + int queue;
33456 +
33457 + /* find which hardware queues have space in them */
33458 + hw->get_tx_stats(dev, &stats);
33459 +
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)
33464 + continue;
33465 +
33466 + /* there is space - try and get a frame */
33467 + skb = skb_dequeue(&q->requeued[queue]);
33468 + if (skb)
33469 + return skb;
33470 +
33471 + qdisc = q->queues[queue];
33472 + skb = qdisc->dequeue(qdisc);
33473 + if (skb) {
33474 + qd->q.qlen--;
33475 + return skb;
33476 + }
33477 + }
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 */
33480 + return NULL;
33481 +}
33482 +
33483 +
33484 +static void wme_qdiscop_reset(struct Qdisc* qd)
33485 +{
33486 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33487 + struct ieee80211_local *local = qd->dev->priv;
33488 + struct ieee80211_hw *hw = local->hw;
33489 + int queue;
33490 +
33491 + /* QUESTION: should we have some hardware flush functionality here? */
33492 +
33493 + for (queue = 0; queue < hw->queues; queue++) {
33494 + skb_queue_purge(&q->requeued[queue]);
33495 + qdisc_reset(q->queues[queue]);
33496 + }
33497 + qd->q.qlen = 0;
33498 +}
33499 +
33500 +
33501 +static void wme_qdiscop_destroy(struct Qdisc* qd)
33502 +{
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;
33507 + int queue;
33508 +
33509 + while ((tp = q->filter_list) != NULL) {
33510 + q->filter_list = tp->next;
33511 + tp->ops->destroy(tp);
33512 + }
33513 +
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;
33518 + }
33519 +}
33520 +
33521 +
33522 +/* called whenever parameters are updated on existing qdisc */
33523 +static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
33524 +{
33525 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33526 +*/
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);
33531 +
33532 + if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
33533 + return -EINVAL;
33534 + memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
33535 +*/
33536 + return 0;
33537 +}
33538 +
33539 +
33540 +/* called during initial creation of qdisc on device */
33541 +static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
33542 +{
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;
33547 + int err = 0, i;
33548 +
33549 + /* check this device is an ieee80211 master type device */
33550 + if (dev->type != ARPHRD_IEEE80211)
33551 + return -EINVAL;
33552 +
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)
33557 + return -EINVAL;
33558 +
33559 + if (qd->flags & TCQ_F_INGRESS)
33560 + return -EINVAL;
33561 +
33562 + /* if options were passed in, set them */
33563 + if (opt) {
33564 + err = wme_qdiscop_tune(qd, opt);
33565 + }
33566 +
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);
33574 + }
33575 + }
33576 +
33577 + return err;
33578 +}
33579 +
33580 +static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
33581 +{
33582 +/* struct ieee80211_sched_data *q = qdisc_priv(qd);
33583 + unsigned char *p = skb->tail;
33584 + struct tc_ieee80211_qopt opt;
33585 +
33586 + memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
33587 + RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
33588 +*/ return skb->len;
33589 +/*
33590 +rtattr_failure:
33591 + skb_trim(skb, p - skb->data);*/
33592 + return -1;
33593 +}
33594 +
33595 +
33596 +static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
33597 + struct Qdisc *new, struct Qdisc **old)
33598 +{
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;
33603 +
33604 + if (queue >= hw->queues)
33605 + return -EINVAL;
33606 +
33607 + if (new == NULL)
33608 + new = &noop_qdisc;
33609 +
33610 + sch_tree_lock(qd);
33611 + *old = q->queues[queue];
33612 + q->queues[queue] = new;
33613 + qdisc_reset(*old);
33614 + sch_tree_unlock(qd);
33615 +
33616 + return 0;
33617 +}
33618 +
33619 +
33620 +static struct Qdisc *
33621 +wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
33622 +{
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;
33627 +
33628 + if (queue >= hw->queues)
33629 + return NULL;
33630 +
33631 + return q->queues[queue];
33632 +}
33633 +
33634 +
33635 +static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
33636 +{
33637 + struct ieee80211_local *local = qd->dev->priv;
33638 + struct ieee80211_hw *hw = local->hw;
33639 + unsigned long queue = TC_H_MIN(classid);
33640 +
33641 + if (queue - 1 >= hw->queues)
33642 + return 0;
33643 +
33644 + return queue;
33645 +}
33646 +
33647 +
33648 +static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
33649 + u32 classid)
33650 +{
33651 + return wme_classop_get(qd, classid);
33652 +}
33653 +
33654 +
33655 +static void wme_classop_put(struct Qdisc *q, unsigned long cl)
33656 +{
33657 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33658 +}
33659 +
33660 +
33661 +static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
33662 + struct rtattr **tca, unsigned long *arg)
33663 +{
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__); */
33668 +
33669 + if (cl - 1 > hw->queues)
33670 + return -ENOENT;
33671 +
33672 + /* TODO: put code to program hardware queue parameters here,
33673 + * to allow programming from tc command line */
33674 +
33675 + return 0;
33676 +}
33677 +
33678 +
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)
33682 +{
33683 + struct ieee80211_local *local = qd->dev->priv;
33684 + struct ieee80211_hw *hw = local->hw;
33685 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33686 +
33687 + if (cl - 1 > hw->queues)
33688 + return -ENOENT;
33689 + return 0;
33690 +}
33691 +
33692 +
33693 +static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
33694 + struct sk_buff *skb, struct tcmsg *tcm)
33695 +{
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__); */
33700 +
33701 + if (cl - 1 > hw->queues)
33702 + return -ENOENT;
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? */
33706 + return 0;
33707 +}
33708 +
33709 +
33710 +static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
33711 +{
33712 + struct ieee80211_local *local = qd->dev->priv;
33713 + struct ieee80211_hw *hw = local->hw;
33714 + int queue;
33715 + /* printk(KERN_DEBUG "entering %s\n", __func__); */
33716 +
33717 + if (arg->stop)
33718 + return;
33719 +
33720 + for (queue = 0; queue < hw->queues; queue++) {
33721 + if (arg->count < arg->skip) {
33722 + arg->count++;
33723 + continue;
33724 + }
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) {
33728 + arg->stop = 1;
33729 + break;
33730 + }
33731 + arg->count++;
33732 + }
33733 +}
33734 +
33735 +
33736 +static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
33737 + unsigned long cl)
33738 +{
33739 + struct ieee80211_sched_data *q = qdisc_priv(qd);
33740 + /* printk("entering %s\n", __func__); */
33741 +
33742 + if (cl)
33743 + return NULL;
33744 +
33745 + return &q->filter_list;
33746 +}
33747 +
33748 +
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 =
33752 +{
33753 + .graft = wme_classop_graft,
33754 + .leaf = wme_classop_leaf,
33755 +
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,
33761 +
33762 + .tcf_chain = wme_classop_find_tcf,
33763 + .bind_tcf = wme_classop_bind,
33764 + .unbind_tcf = wme_classop_put,
33765 +
33766 + .dump = wme_classop_dump_class,
33767 +};
33768 +
33769 +
33770 +/* queueing discipline operations */
33771 +static struct Qdisc_ops wme_qdisc_ops =
33772 +{
33773 + .next = NULL,
33774 + .cl_ops = &class_ops,
33775 + .id = "ieee80211",
33776 + .priv_size = sizeof(struct ieee80211_sched_data),
33777 +
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 */
33782 +
33783 + .init = wme_qdiscop_init,
33784 + .reset = wme_qdiscop_reset,
33785 + .destroy = wme_qdiscop_destroy,
33786 + .change = wme_qdiscop_tune,
33787 +
33788 + .dump = wme_qdiscop_dump,
33789 +};
33790 +
33791 +
33792 +void ieee80211_install_qdisc(struct net_device *dev)
33793 +{
33794 + struct Qdisc *qdisc;
33795 +
33796 + qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops);
33797 + if (qdisc == NULL) {
33798 + printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
33799 + return;
33800 + }
33801 +
33802 + /* same handle as would be allocated by qdisc_alloc_handle() */
33803 + qdisc->handle = 0x80010000;
33804 +
33805 + qdisc_lock_tree(dev);
33806 + list_add_tail(&qdisc->list, &dev->qdisc_list);
33807 + dev->qdisc_sleeping = qdisc;
33808 + qdisc_unlock_tree(dev);
33809 +}
33810 +
33811 +
33812 +int ieee80211_wme_register(void)
33813 +{
33814 + int err = 0;
33815 +
33816 +#ifdef CONFIG_NET_SCHED
33817 + err = register_qdisc(&wme_qdisc_ops);
33818 +#endif
33819 + return err;
33820 +}
33821 +
33822 +
33823 +void ieee80211_wme_unregister(void)
33824 +{
33825 +#ifdef CONFIG_NET_SCHED
33826 + unregister_qdisc(&wme_qdisc_ops);
33827 +#endif
33828 +}
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
33832 @@ -0,0 +1,59 @@
33833 +/*
33834 + * IEEE 802.11 driver (80211.o) - QoS datatypes
33835 + * Copyright 2004, Instant802 Networks, Inc.
33836 + * Copyright 2005, Devicescape Software, Inc.
33837 + *
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.
33841 + */
33842 +
33843 +#ifndef _WME_H
33844 +#define _WME_H
33845 +
33846 +#include <asm/byteorder.h>
33847 +#include <linux/netdevice.h>
33848 +#include <linux/types.h>
33849 +#include <net/pkt_sched.h>
33850 +
33851 +#define QOS_CONTROL_LEN 2
33852 +
33853 +#define QOS_CONTROL_ACK_POLICY_NORMAL 0
33854 +#define QOS_CONTROL_ACK_POLICY_NOACK 1
33855 +
33856 +#define QOS_CONTROL_TID_MASK 0x0f
33857 +#define QOS_CONTROL_ACK_POLICY_SHIFT 5
33858 +
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 */
33864 + reserved1:1,
33865 + eosp:1,
33866 + ack_policy:2,
33867 + reserved2:1;
33868 +#elif defined (__BIG_ENDIAN_BITFIELD)
33869 + u8 reserved2:1,
33870 + ack_policy:2,
33871 + eosp:1,
33872 + reserved1:1,
33873 + tag1d:3; /* bits 0-2 */
33874 +#else
33875 +#error "Please fix <asm/byteorder.h>"
33876 +#endif
33877 + u8 reserved;
33878 +} __attribute__ ((packed));
33879 +
33880 +ieee80211_txrx_result
33881 +ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx);
33882 +
33883 +ieee80211_txrx_result
33884 +ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx);
33885 +
33886 +void ieee80211_install_qdisc(struct net_device *dev);
33887 +
33888 +int ieee80211_wme_register(void);
33889 +void ieee80211_wme_unregister(void);
33890 +
33891 +#endif
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
33895 @@ -0,0 +1,825 @@
33896 +/*
33897 + * Copyright 2002-2004, Instant802 Networks, Inc.
33898 + *
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.
33902 + */
33903 +
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>
33914 +
33915 +#include <net/d80211.h>
33916 +#include <net/d80211_common.h>
33917 +#include "ieee80211_i.h"
33918 +#include "michael.h"
33919 +#include "tkip.h"
33920 +#include "aes_ccm.h"
33921 +#include "wpa.h"
33922 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
33923 +#include "hostapd_ioctl.h"
33924 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
33925 +
33926 +
33927 +#define MICHAEL_MIC_HWACCEL
33928 +
33929 +
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)
33932 +{
33933 + struct ieee80211_hdr *hdr;
33934 + size_t hdrlen;
33935 + u16 fc;
33936 + int a4_included;
33937 + u8 *pos;
33938 +
33939 + hdr = (struct ieee80211_hdr *) skb->data;
33940 + fc = le16_to_cpu(hdr->frame_control);
33941 +
33942 + hdrlen = 24;
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;
33954 + } else {
33955 + *sa = hdr->addr2;
33956 + *da = hdr->addr1;
33957 + }
33958 +
33959 + if (fc & 0x80)
33960 + hdrlen += 2;
33961 +
33962 + *data = skb->data + hdrlen;
33963 + *data_len = skb->len - hdrlen;
33964 +
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;
33970 + if (a4_included)
33971 + pos += 6;
33972 + *qos_tid = pos[0] & 0x0f;
33973 + *qos_tid |= 0x80; /* qos_included flag */
33974 + } else
33975 + *qos_tid = 0;
33976 +
33977 + return skb->len < hdrlen ? -1 : 0;
33978 +}
33979 +
33980 +
33981 +ieee80211_txrx_result
33982 +ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
33983 +{
33984 + u8 *data, *sa, *da, *key, *mic, qos_tid;
33985 + size_t data_len;
33986 + u16 fc;
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;
33991 +#endif
33992 +
33993 + fc = tx->fc;
33994 +
33995 + if (!tx->key || tx->key->alg != ALG_TKIP || skb->len < 24 ||
33996 + !WLAN_FC_DATA_PRESENT(fc))
33997 + return TXRX_CONTINUE;
33998 +
33999 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
34000 + return TXRX_DROP;
34001 +
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)) {
34006 + wpa_test = 1;
34007 + }
34008 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34009 +
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
34014 + */
34015 + return TXRX_CONTINUE;
34016 + }
34017 +#endif /* MICHAEL_MIC_HWACCEL */
34018 +
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,
34023 + GFP_ATOMIC))) {
34024 + printk(KERN_DEBUG "%s: failed to allocate more memory "
34025 + "for Michael MIC\n", tx->dev->name);
34026 + return TXRX_DROP;
34027 + }
34028 + }
34029 +
34030 +#if 0
34031 + authenticator = fc & WLAN_FC_FROMDS; /* FIX */
34032 +#else
34033 + authenticator = 1;
34034 +#endif
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);
34039 +
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;
34048 + mic[0]++;
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;
34056 + mic[0]++;
34057 + }
34058 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34059 +
34060 + return TXRX_CONTINUE;
34061 +}
34062 +
34063 +
34064 +ieee80211_txrx_result
34065 +ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
34066 +{
34067 + u8 *data, *sa, *da, *key = NULL, qos_tid;
34068 + size_t data_len;
34069 + u16 fc;
34070 + u8 mic[MICHAEL_MIC_LEN];
34071 + struct sk_buff *skb = rx->skb;
34072 + int authenticator = 1, wpa_test = 0;
34073 +
34074 + fc = rx->fc;
34075 +
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;
34080 +
34081 + if (!rx->key || rx->key->alg != ALG_TKIP ||
34082 + !(rx->fc & WLAN_FC_ISWEP) || !WLAN_FC_DATA_PRESENT(fc))
34083 + return TXRX_CONTINUE;
34084 +
34085 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34086 + if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
34087 + wpa_test = 1;
34088 + }
34089 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34090 +
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;
34097 + }
34098 + /* Need to verify Michael MIC sometimes in software even when
34099 + * hwaccel is used. Atheros ar5212: fragmented frames and QoS
34100 + * frames. */
34101 + if (!rx->fragmented && !wpa_test)
34102 + goto remove_mic;
34103 + }
34104 +#endif /* MICHAEL_MIC_HWACCEL */
34105 +
34106 + if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
34107 + || data_len < MICHAEL_MIC_LEN)
34108 + return TXRX_DROP;
34109 +
34110 + data_len -= MICHAEL_MIC_LEN;
34111 +
34112 +#if 0
34113 + authenticator = fc & WLAN_FC_TODS; /* FIX */
34114 +#else
34115 + authenticator = 1;
34116 +#endif
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;
34126 + mic[0]++;
34127 + }
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
34131 + int i;
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]);
34142 + printk("\n");
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 */
34149 +
34150 + do {
34151 + struct ieee80211_hdr *hdr;
34152 + union iwreq_data wrqu;
34153 + char *buf = kmalloc(128, GFP_ATOMIC);
34154 + if (buf == NULL)
34155 + break;
34156 +
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 ")",
34161 + rx->key->keyidx,
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);
34167 + kfree(buf);
34168 + } while (0);
34169 +
34170 + ieee80211_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status,
34171 + ieee80211_msg_michael_mic_failure);
34172 +
34173 + return TXRX_QUEUED;
34174 + }
34175 +
34176 +#ifdef MICHAEL_MIC_HWACCEL
34177 + remove_mic:
34178 +#endif /* MICHAEL_MIC_HWACCEL */
34179 + /* remove Michael MIC from payload */
34180 + skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
34181 +
34182 + return TXRX_CONTINUE;
34183 +}
34184 +
34185 +
34186 +static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
34187 + struct sk_buff *skb, int test)
34188 +{
34189 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34190 + struct ieee80211_key *key = tx->key;
34191 + int hdrlen, len, tailneed;
34192 + u16 fc;
34193 + u8 *pos;
34194 +
34195 + fc = le16_to_cpu(hdr->frame_control);
34196 + hdrlen = ieee80211_get_hdrlen(fc);
34197 + len = skb->len - hdrlen;
34198 +
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,
34205 + GFP_ATOMIC)))
34206 + return -1;
34207 + }
34208 +
34209 + pos = skb_push(skb, TKIP_IV_LEN);
34210 + memmove(pos, pos + TKIP_IV_LEN, hdrlen);
34211 + pos += hdrlen;
34212 +
34213 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34214 + if (test & WPA_TRIGGER_TX_REPLAY)
34215 + goto skip_iv_inc;
34216 +iv_inc:
34217 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34218 +
34219 + /* Increase IV for the frame */
34220 + key->u.tkip.iv16++;
34221 + if (key->u.tkip.iv16 == 0)
34222 + key->u.tkip.iv32++;
34223 +
34224 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34225 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34226 + test = 0;
34227 + goto iv_inc;
34228 + }
34229 +skip_iv_inc:
34230 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34231 +
34232 + if (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt
34233 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34234 + && !tx->wpa_test
34235 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34236 + ) {
34237 + /* hwaccel - with preallocated room for IV */
34238 +
34239 + ieee80211_tkip_add_iv(pos, key,
34240 + (u8) (key->u.tkip.iv16 >> 8),
34241 + (u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
34242 + 0x7f),
34243 + (u8) key->u.tkip.iv16);
34244 +
34245 + tx->u.tx.control->key_idx = tx->key->hw_key_idx;
34246 + return 0;
34247 + }
34248 +
34249 + /* Add room for ICV */
34250 + skb_put(skb, TKIP_ICV_LEN);
34251 +
34252 + hdr = (struct ieee80211_hdr *) skb->data;
34253 + ieee80211_tkip_encrypt_data(key, pos, len, hdr->addr2);
34254 + return 0;
34255 +}
34256 +
34257 +
34258 +ieee80211_txrx_result
34259 +ieee80211_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx)
34260 +{
34261 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34262 + u16 fc;
34263 + struct ieee80211_key *key = tx->key;
34264 + struct sk_buff *skb = tx->skb;
34265 + int wpa_test = 0, test = 0;
34266 +
34267 + fc = le16_to_cpu(hdr->frame_control);
34268 +
34269 + if (!key || key->alg != ALG_TKIP || !WLAN_FC_DATA_PRESENT(fc))
34270 + return TXRX_CONTINUE;
34271 +
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);
34275 +
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)) {
34280 + wpa_test = 1;
34281 + }
34282 +
34283 + if (tx->sta) {
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);
34288 + } else {
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);
34293 + }
34294 + if (test &
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]" : "");
34304 + }
34305 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34306 +
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;
34312 + }
34313 +
34314 + if (tkip_encrypt_skb(tx, skb, test) < 0)
34315 + return TXRX_DROP;
34316 +
34317 + if (tx->u.tx.extra_frag) {
34318 + int i;
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)
34325 + < 0)
34326 + return TXRX_DROP;
34327 + }
34328 + }
34329 +
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",
34342 + tx->dev->name);
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]++;
34346 + }
34347 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34348 +
34349 + return TXRX_CONTINUE;
34350 +}
34351 +
34352 +
34353 +ieee80211_txrx_result
34354 +ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx)
34355 +{
34356 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34357 + u16 fc;
34358 + int hdrlen, res, hwaccel = 0, wpa_test = 0;
34359 + struct ieee80211_key *key = rx->key;
34360 + struct sk_buff *skb = rx->skb;
34361 +
34362 + fc = le16_to_cpu(hdr->frame_control);
34363 + hdrlen = ieee80211_get_hdrlen(fc);
34364 +
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;
34369 +
34370 + if (!rx->sta || skb->len - hdrlen < 12)
34371 + return TXRX_DROP;
34372 +
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]++;
34380 + wpa_test = 1;
34381 + }
34382 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34383 +
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;
34390 + }
34391 +
34392 + /* let TKIP code verify IV, but skip decryption */
34393 + hwaccel = 1;
34394 + }
34395 +
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;
34404 + }
34405 +
34406 + /* Trim ICV */
34407 + skb_trim(skb, skb->len - TKIP_ICV_LEN);
34408 +
34409 + /* Remove IV */
34410 + memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
34411 + skb_pull(skb, TKIP_IV_LEN);
34412 +
34413 + return TXRX_CONTINUE;
34414 +}
34415 +
34416 +
34417 +static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
34418 + int encrypted)
34419 +{
34420 + u16 fc;
34421 + int a4_included, qos_included;
34422 + u8 qos_tid, *fc_pos, *data, *sa, *da;
34423 + int len_a;
34424 + size_t data_len;
34425 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34426 +
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);
34431 +
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;
34436 + qos_tid &= 0x0f;
34437 + } else
34438 + qos_included = 0;
34439 + /* First block, b_0 */
34440 +
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);
34446 + /* l(m) */
34447 + b_0[14] = (data_len >> 8) & 0xff;
34448 + b_0[15] = data_len & 0xff;
34449 +
34450 +
34451 + /* AAD (extra authenticate-only data) / masked 802.11 header
34452 + * FC | A1 | A2 | A3 | SC | [A4] | [QC] */
34453 +
34454 + len_a = a4_included ? 28 : 22;
34455 + if (qos_included)
34456 + len_a += 2;
34457 +
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);
34465 +
34466 + /* Mask Seq#, leave Frag# */
34467 + aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
34468 + aad[23] = 0;
34469 + if (a4_included) {
34470 + memcpy(&aad[24], hdr->addr4, 6);
34471 + aad[30] = 0;
34472 + aad[31] = 0;
34473 + } else
34474 + memset(&aad[24], 0, 8);
34475 + if (qos_included) {
34476 + u8 *dpos = &aad[a4_included ? 30 : 24];
34477 +
34478 + /* Mask QoS Control field */
34479 + dpos[0] = qos_tid;
34480 + dpos[1] = 0;
34481 + }
34482 +}
34483 +
34484 +
34485 +static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
34486 +{
34487 + hdr[0] = pn[5];
34488 + hdr[1] = pn[4];
34489 + hdr[2] = 0;
34490 + hdr[3] = 0x20 | (key_id << 6);
34491 + hdr[4] = pn[3];
34492 + hdr[5] = pn[2];
34493 + hdr[6] = pn[1];
34494 + hdr[7] = pn[0];
34495 +}
34496 +
34497 +
34498 +static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
34499 +{
34500 + pn[0] = hdr[7];
34501 + pn[1] = hdr[6];
34502 + pn[2] = hdr[5];
34503 + pn[3] = hdr[4];
34504 + pn[4] = hdr[1];
34505 + pn[5] = hdr[0];
34506 + return (hdr[3] >> 6) & 0x03;
34507 +}
34508 +
34509 +
34510 +static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
34511 + struct sk_buff *skb, int test)
34512 +{
34513 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
34514 + struct ieee80211_key *key = tx->key;
34515 + int hdrlen, len, tailneed;
34516 + u16 fc;
34517 + u8 *pos, *pn;
34518 + u8 b_0[AES_BLOCK_LEN], aad[2 * AES_BLOCK_LEN];
34519 + int i;
34520 +
34521 + fc = le16_to_cpu(hdr->frame_control);
34522 + hdrlen = ieee80211_get_hdrlen(fc);
34523 + len = skb->len - hdrlen;
34524 +
34525 + tailneed = (!tx->key->force_sw_encrypt && !tx->local->conf.sw_decrypt)
34526 + ? 0 : CCMP_MIC_LEN;
34527 +
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,
34532 + GFP_ATOMIC)))
34533 + return -1;
34534 + }
34535 +
34536 + pos = skb_push(skb, CCMP_HDR_LEN);
34537 + memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
34538 + hdr = (struct ieee80211_hdr *) pos;
34539 + pos += hdrlen;
34540 +
34541 + /* PN = PN + 1 */
34542 + pn = key->u.ccmp.tx_pn;
34543 +
34544 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34545 + if (test & WPA_TRIGGER_TX_REPLAY)
34546 + goto skip_pn_inc;
34547 +pn_inc:
34548 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34549 +
34550 + for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
34551 + pn[i]++;
34552 + if (pn[i])
34553 + break;
34554 + }
34555 +
34556 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34557 + if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
34558 + test = 0;
34559 + goto pn_inc;
34560 + }
34561 +skip_pn_inc:
34562 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34563 +
34564 + ccmp_pn2hdr(pos, pn, key->keyidx);
34565 +
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;
34569 + return 0;
34570 + }
34571 +
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));
34576 +
34577 + return 0;
34578 +}
34579 +
34580 +
34581 +ieee80211_txrx_result
34582 +ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx)
34583 +{
34584 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
34585 + struct ieee80211_key *key = tx->key;
34586 + u16 fc;
34587 + struct sk_buff *skb = tx->skb;
34588 + int test = 0;
34589 +
34590 + fc = le16_to_cpu(hdr->frame_control);
34591 +
34592 + if (!key || key->alg != ALG_CCMP || !WLAN_FC_DATA_PRESENT(fc))
34593 + return TXRX_CONTINUE;
34594 +
34595 +#ifdef CONFIG_HOSTAPD_WPA_TESTING
34596 + if (tx->sta) {
34597 + test = tx->sta->wpa_trigger;
34598 + tx->sta->wpa_trigger = 0;
34599 + } else {
34600 + test = tx->local->wpa_trigger;
34601 + tx->local->wpa_trigger = 0;
34602 + }
34603 + if (test &
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]" : "");
34613 + }
34614 +#endif /* CONFIG_HOSTAPD_WPA_TESTING */
34615 +
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);
34619 +
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;
34626 + }
34627 +
34628 + if (ccmp_encrypt_skb(tx, skb, test) < 0)
34629 + return TXRX_DROP;
34630 +
34631 + if (tx->u.tx.extra_frag) {
34632 + int i;
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)
34639 + < 0)
34640 + return TXRX_DROP;
34641 + }
34642 + }
34643 +
34644 + return TXRX_CONTINUE;
34645 +}
34646 +
34647 +
34648 +ieee80211_txrx_result
34649 +ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx)
34650 +{
34651 + struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
34652 + u16 fc;
34653 + int hdrlen;
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];
34658 + int data_len;
34659 +
34660 + fc = le16_to_cpu(hdr->frame_control);
34661 + hdrlen = ieee80211_get_hdrlen(fc);
34662 +
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;
34667 +
34668 + data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
34669 + if (!rx->sta || data_len < 0)
34670 + return TXRX_DROP;
34671 +
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;
34676 +
34677 + (void) ccmp_hdr2pn(pn, skb->data + hdrlen);
34678 +
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;
34691 + }
34692 +
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 */
34696 + } else {
34697 + ccmp_special_blocks(skb, pn, b_0, aad, 1);
34698 +
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;
34708 + }
34709 + }
34710 +
34711 + memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
34712 +
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);
34717 +
34718 + return TXRX_CONTINUE;
34719 +}
34720 +
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
34724 @@ -0,0 +1,34 @@
34725 +/*
34726 + * Copyright 2002-2004, Instant802 Networks, Inc.
34727 + *
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.
34731 + */
34732 +
34733 +#ifndef WPA_H
34734 +#define WPA_H
34735 +
34736 +#include <linux/skbuff.h>
34737 +#include <linux/types.h>
34738 +#include "ieee80211_i.h"
34739 +
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);
34744 +
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);
34749 +
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);
34754 +
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);
34757 +
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
34762 @@ -18,7 +18,6 @@
34763 #include <linux/string.h>
34764 #include <net/ieee80211.h>
34765
34766 -
34767 MODULE_AUTHOR("Jouni Malinen");
34768 MODULE_DESCRIPTION("HostAP crypto");
34769 MODULE_LICENSE("GPL");
34770 @@ -33,11 +32,11 @@
34771
34772 void ieee80211_crypt_deinit_entries(struct ieee80211_device *ieee, int force)
34773 {
34774 - struct ieee80211_crypt_data *entry, *next;
34775 + struct ieee80211_crypt_data *entry, *next;
34776 unsigned long flags;
34777
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)
34782 continue;
34783
34784 @@ -141,9 +140,9 @@
34785 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34786 return -EINVAL;
34787
34788 - found:
34789 + found:
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);
34795 kfree(alg);
34796 @@ -163,7 +162,7 @@
34797 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34798 return NULL;
34799
34800 - found:
34801 + found:
34802 spin_unlock_irqrestore(&ieee80211_crypto_lock, flags);
34803 return alg->ops;
34804 }
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);
34810 }
34811
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)
34815 {
34816 struct ieee80211_ccmp_data *key = priv;
34817 int i;
34818 @@ -199,6 +200,9 @@
34819 if (skb_headroom(skb) < CCMP_HDR_LEN || skb->len < hdr_len)
34820 return -1;
34821
34822 + if (aeskey != NULL && keylen >= CCMP_TK_LEN)
34823 + memcpy(aeskey, key->key, CCMP_TK_LEN);
34824 +
34825 pos = skb_push(skb, CCMP_HDR_LEN);
34826 memmove(pos, pos + CCMP_HDR_LEN, hdr_len);
34827 pos += hdr_len;
34828 @@ -238,7 +242,7 @@
34829 return -1;
34830
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);
34834 if (len < 0)
34835 return -1;
34836
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
34840 @@ -80,10 +80,9 @@
34841 {
34842 struct ieee80211_tkip_data *priv;
34843
34844 - priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
34845 + priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
34846 if (priv == NULL)
34847 goto fail;
34848 - memset(priv, 0, sizeof(*priv));
34849
34850 priv->key_idx = key_idx;
34851
34852 @@ -271,34 +270,33 @@
34853 #endif
34854 }
34855
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)
34859 {
34860 struct ieee80211_tkip_data *tkey = priv;
34861 int len;
34862 - u8 *rc4key, *pos, *icv;
34863 + u8 *pos;
34864 struct ieee80211_hdr_4addr *hdr;
34865 - u32 crc;
34866
34867 hdr = (struct ieee80211_hdr_4addr *)skb->data;
34868
34869 if (skb_headroom(skb) < 8 || skb->len < hdr_len)
34870 - return NULL;
34871 + return -1;
34872 +
34873 + if (rc4key == NULL || keylen < 16)
34874 + return -1;
34875
34876 if (!tkey->tx_phase1_done) {
34877 tkip_mixing_phase1(tkey->tx_ttak, tkey->key, hdr->addr2,
34878 tkey->tx_iv32);
34879 tkey->tx_phase1_done = 1;
34880 }
34881 - rc4key = kmalloc(16, GFP_ATOMIC);
34882 - if (!rc4key)
34883 - return NULL;
34884 tkip_mixing_phase2(rc4key, tkey->key, tkey->tx_ttak, tkey->tx_iv16);
34885
34886 len = skb->len - hdr_len;
34887 pos = skb_push(skb, 8);
34888 memmove(pos, pos + 8, hdr_len);
34889 pos += hdr_len;
34890 - icv = skb_put(skb, 4);
34891
34892 *pos++ = *rc4key;
34893 *pos++ = *(rc4key + 1);
34894 @@ -309,28 +307,28 @@
34895 *pos++ = (tkey->tx_iv32 >> 16) & 0xff;
34896 *pos++ = (tkey->tx_iv32 >> 24) & 0xff;
34897
34898 - crc = ~crc32_le(~0, pos, len);
34899 - icv[0] = crc;
34900 - icv[1] = crc >> 8;
34901 - icv[2] = crc >> 16;
34902 - icv[3] = crc >> 24;
34903 + tkey->tx_iv16++;
34904 + if (tkey->tx_iv16 == 0) {
34905 + tkey->tx_phase1_done = 0;
34906 + tkey->tx_iv32++;
34907 + }
34908
34909 - return rc4key;
34910 + return 8;
34911 }
34912
34913 static int ieee80211_tkip_encrypt(struct sk_buff *skb, int hdr_len, void *priv)
34914 {
34915 struct ieee80211_tkip_data *tkey = priv;
34916 int len;
34917 - const u8 *rc4key;
34918 - u8 *pos;
34919 + u8 rc4key[16], *pos, *icv;
34920 + u32 crc;
34921 struct scatterlist sg;
34922
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));
34931 }
34932 @@ -343,22 +341,23 @@
34933 len = skb->len - hdr_len;
34934 pos = skb->data + hdr_len;
34935
34936 - rc4key = ieee80211_tkip_hdr(skb, hdr_len, priv);
34937 - if (!rc4key)
34938 + if ((ieee80211_tkip_hdr(skb, hdr_len, rc4key, 16, priv)) < 0)
34939 return -1;
34940
34941 + icv = skb_put(skb, 4);
34942 +
34943 + crc = ~crc32_le(~0, pos, len);
34944 + icv[0] = crc;
34945 + icv[1] = crc >> 8;
34946 + icv[2] = crc >> 16;
34947 + icv[3] = crc >> 24;
34948 +
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);
34954
34955 - tkey->tx_iv16++;
34956 - if (tkey->tx_iv16 == 0) {
34957 - tkey->tx_phase1_done = 0;
34958 - tkey->tx_iv32++;
34959 - }
34960 -
34961 return 0;
34962 }
34963
34964 @@ -379,7 +378,7 @@
34965
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));
34972 }
34973 @@ -695,6 +694,7 @@
34974 .name = "TKIP",
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
34984 @@ -76,7 +76,8 @@
34985 }
34986
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)
34991 {
34992 struct prism2_wep_data *wep = priv;
34993 u32 klen, len;
34994 @@ -131,7 +132,7 @@
34995 return -1;
34996
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))
35000 return -1;
35001
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
35006 @@ -50,7 +50,8 @@
35007
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)
35012 + return 0;
35013
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
35018 * as valid. */
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;
35024
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;
35031
35032 return 0;
35033 @@ -76,7 +79,8 @@
35034
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)
35039 + return -1;
35040
35041 if (ieee->freq_band & IEEE80211_24GHZ_BAND)
35042 for (i = 0; i < ieee->geo.bg_channels; i++)
35043 @@ -97,7 +101,8 @@
35044
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)
35049 + return 0;
35050
35051 freq /= 100000;
35052
35053 @@ -133,6 +138,41 @@
35054 return &ieee->geo;
35055 }
35056
35057 +u8 ieee80211_get_channel_flags(struct ieee80211_device * ieee, u8 channel)
35058 +{
35059 + int index = ieee80211_channel_to_index(ieee, channel);
35060 +
35061 + if (index == -1)
35062 + return IEEE80211_CH_INVALID;
35063 +
35064 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35065 + return ieee->geo.bg[index].flags;
35066 +
35067 + return ieee->geo.a[index].flags;
35068 +}
35069 +
35070 +static const struct ieee80211_channel bad_channel = {
35071 + .channel = 0,
35072 + .flags = IEEE80211_CH_INVALID,
35073 + .max_power = 0,
35074 +};
35075 +
35076 +const struct ieee80211_channel *ieee80211_get_channel(struct ieee80211_device
35077 + *ieee, u8 channel)
35078 +{
35079 + int index = ieee80211_channel_to_index(ieee, channel);
35080 +
35081 + if (index == -1)
35082 + return &bad_channel;
35083 +
35084 + if (channel <= IEEE80211_24GHZ_CHANNELS)
35085 + return &ieee->geo.bg[index];
35086 +
35087 + return &ieee->geo.a[index];
35088 +}
35089 +
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 @@
35099 return 0;
35100 }
35101
35102 +void ieee80211_network_reset(struct ieee80211_network *network)
35103 +{
35104 + if (!network)
35105 + return;
35106 +
35107 + if (network->ibss_dfs) {
35108 + kfree(network->ibss_dfs);
35109 + network->ibss_dfs = NULL;
35110 + }
35111 +}
35112 +
35113 static inline void ieee80211_networks_free(struct ieee80211_device *ieee)
35114 {
35115 + int i;
35116 +
35117 if (!ieee->networks)
35118 return;
35119 +
35120 + for (i = 0; i < MAX_NETWORK_COUNT; i++)
35121 + if (ieee->networks[i].ibss_dfs)
35122 + kfree(ieee->networks[i].ibss_dfs);
35123 +
35124 kfree(ieee->networks);
35125 ieee->networks = NULL;
35126 }
35127 @@ -195,7 +213,7 @@
35128
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;
35133
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 @@
35140
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);
35152 }
35153 -#endif /* CONFIG_NET_RADIO */
35154 #endif /* IW_WIRELESS_SPY */
35155 +#endif /* CONFIG_WIRELESS_EXT */
35156
35157 #ifdef NOT_YET
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)) {
35165 int flen;
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));
35170 skb->dev = dev;
35171 skb->ip_summed = CHECKSUM_NONE; /* 802.11 crc not sufficient */
35172 - netif_rx(skb);
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++;
35180 + }
35181 }
35182
35183 rx_exit:
35184 @@ -930,6 +937,45 @@
35185 return rc;
35186 }
35187
35188 +#ifdef CONFIG_IEEE80211_DEBUG
35189 +#define MFIE_STRING(x) case MFIE_TYPE_ ##x: return #x
35190 +
35191 +static const char *get_info_element_string(u16 id)
35192 +{
35193 + switch (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);
35221 + default:
35222 + return "UNKNOWN";
35223 + }
35224 +}
35225 +#endif
35226 +
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 @@
35231 break;
35232
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");
35238 break;
35239
35240 case MFIE_TYPE_ERP_INFO:
35241 @@ -1091,10 +1139,49 @@
35242 printk(KERN_ERR
35243 "QoS Error need to parse QOS_PARAMETER IE\n");
35244 break;
35245 + /* 802.11h */
35246 + case MFIE_TYPE_POWER_CONSTRAINT:
35247 + network->power_constraint = info_element->data[0];
35248 + network->flags |= NETWORK_HAS_POWER_CONSTRAINT;
35249 + break;
35250 +
35251 + case MFIE_TYPE_CSA:
35252 + network->power_constraint = info_element->data[0];
35253 + network->flags |= NETWORK_HAS_CSA;
35254 + break;
35255 +
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;
35262 + break;
35263 +
35264 + case MFIE_TYPE_IBSS_DFS:
35265 + if (network->ibss_dfs)
35266 + break;
35267 + network->ibss_dfs =
35268 + kmalloc(info_element->len, GFP_ATOMIC);
35269 + if (!network->ibss_dfs)
35270 + return 1;
35271 + memcpy(network->ibss_dfs, info_element->data,
35272 + info_element->len);
35273 + network->flags |= NETWORK_HAS_IBSS_DFS;
35274 + break;
35275 +
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;
35281 + break;
35282
35283 default:
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);
35290 break;
35291 }
35292
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)
35296 {
35297 - struct ieee80211_network network_resp;
35298 + struct ieee80211_network network_resp = {
35299 + .ibss_dfs = NULL,
35300 + };
35301 struct ieee80211_network *network = &network_resp;
35302 struct net_device *dev = ieee->dev;
35303
35304 @@ -1253,7 +1342,22 @@
35305 int qos_active;
35306 u8 old_param;
35307
35308 - memcpy(&dst->stats, &src->stats, sizeof(struct ieee80211_rx_stats));
35309 + ieee80211_network_reset(dst);
35310 + dst->ibss_dfs = src->ibss_dfs;
35311 +
35312 + /* We only update the statistics if they were created by receiving
35313 + * the network information on the actual channel the network is on.
35314 + *
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));
35320 + else
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);
35324 +
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;
35333
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 @@
35337 *stats)
35338 {
35339 struct net_device *dev = ieee->dev;
35340 - struct ieee80211_network network;
35341 + struct ieee80211_network network = {
35342 + .ibss_dfs = NULL,
35343 + };
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,
35349 target->ssid_len),
35350 MAC_ARG(target->bssid));
35351 + ieee80211_network_reset(target);
35352 } else {
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");
35357 #endif
35358 memcpy(target, &network, sizeof(*target));
35359 + network.ibss_dfs = NULL;
35360 list_add_tail(&target->list, &ieee->network_list);
35361 } else {
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;
35368 }
35369
35370 spin_unlock_irqrestore(&ieee->lock, flags);
35371 @@ -1495,10 +1605,43 @@
35372 header);
35373 break;
35374
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 *)
35380 + header, stats);
35381 + break;
35382 +
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)));
35387 +
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 *)
35393 + header);
35394 + break;
35395 +
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)));
35400 +
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);
35405 + break;
35406 +
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 *)
35414 header);
35415 break;
35416 default:
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
35420 @@ -56,7 +56,18 @@
35421 `--------------------------------------------------| |------'
35422 Total: 28 non-data bytes `----.----'
35423 |
35424 - .- 'Frame data' expands to <---------------------------'
35425 + .- 'Frame data' expands, if WEP enabled, to <----------'
35426 + |
35427 + V
35428 + ,-----------------------.
35429 +Bytes | 4 | 0-2296 | 4 |
35430 + |-----|-----------|-----|
35431 +Desc. | IV | Encrypted | ICV |
35432 + | | Packet | |
35433 + `-----| |-----'
35434 + `-----.-----'
35435 + |
35436 + .- 'Encrypted Packet' expands to
35437 |
35438 V
35439 ,---------------------------------------------------.
35440 @@ -65,18 +76,7 @@
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 `----.----'
35446 - |
35447 - .- 'IP Packet' expands, if WEP enabled, to <--'
35448 - |
35449 - V
35450 - ,-----------------------.
35451 -Bytes | 4 | 0-2296 | 4 |
35452 - |-----|-----------|-----|
35453 -Desc. | IV | Encrypted | ICV |
35454 - | | IP Packet | |
35455 - `-----------------------'
35456 + `----------------------------------------------------
35457 Total: 8 non-data bytes
35458
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,
35464 - crypt->priv);
35465 + ieee->sec.keys[ieee->sec.active_key],
35466 + ieee->sec.key_sizes[ieee->sec.active_key],
35467 + crypt->priv);
35468 atomic_dec(&crypt->refcnt);
35469 }
35470
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;
35479 } else {
35480 - iwe.u.qual.level = network->stats.rssi;
35481 if (ieee->perfect_rssi == ieee->worst_rssi)
35482 iwe.u.qual.qual = 100;
35483 else
35484 @@ -179,6 +177,13 @@
35485 iwe.u.qual.noise = network->stats.noise;
35486 }
35487
35488 + if (!(network->stats.mask & IEEE80211_STATMASK_SIGNAL)) {
35489 + iwe.u.qual.updated |= IW_QUAL_LEVEL_INVALID;
35490 + iwe.u.qual.level = 0;
35491 + } else {
35492 + iwe.u.qual.level = network->stats.signal;
35493 + }
35494 +
35495 start = iwe_stream_add_event(start, stop, &iwe, IW_EV_QUAL_LEN);
35496
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);
35501
35502 + memset(&iwe, 0, sizeof(iwe));
35503 if (network->wpa_ie_len) {
35504 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35505 -
35506 - u8 *p = buf;
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]);
35510 - }
35511 -
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);
35520 }
35521
35522 + memset(&iwe, 0, sizeof(iwe));
35523 if (network->rsn_ie_len) {
35524 - char buf[MAX_WPA_IE_LEN * 2 + 30];
35525 -
35526 - u8 *p = buf;
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]);
35530 - }
35531 -
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);
35540 }
35541
35542 @@ -229,6 +222,28 @@
35543 if (iwe.u.data.length)
35544 start = iwe_stream_add_point(start, stop, &iwe, custom);
35545
35546 + /* Add spectrum management information */
35547 + iwe.cmd = -1;
35548 + p = custom;
35549 + p += snprintf(p, MAX_CUSTOM_LEN - (p - custom), " Channel flags: ");
35550 +
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 ");
35555 + }
35556 +
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 ");
35561 + }
35562 +
35563 + if (iwe.cmd == IWEVCUSTOM) {
35564 + iwe.u.data.length = p - custom;
35565 + start = iwe_stream_add_point(start, stop, &iwe, custom);
35566 + }
35567 +
35568 return start;
35569 }
35570
35571 @@ -734,9 +749,98 @@
35572 return 0;
35573 }
35574
35575 +int ieee80211_wx_set_auth(struct net_device *dev,
35576 + struct iw_request_info *info,
35577 + union iwreq_data *wrqu,
35578 + char *extra)
35579 +{
35580 + struct ieee80211_device *ieee = netdev_priv(dev);
35581 + unsigned long flags;
35582 + int err = 0;
35583 +
35584 + spin_lock_irqsave(&ieee->lock, flags);
35585 +
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:
35591 + /*
35592 + * Host AP driver does not use these parameters and allows
35593 + * wpa_supplicant to control them internally.
35594 + */
35595 + break;
35596 + case IW_AUTH_TKIP_COUNTERMEASURES:
35597 + break; /* FIXME */
35598 + case IW_AUTH_DROP_UNENCRYPTED:
35599 + ieee->drop_unencrypted = !!wrqu->param.value;
35600 + break;
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;
35605 + break;
35606 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35607 + ieee->ieee802_1x = !!wrqu->param.value;
35608 + break;
35609 + case IW_AUTH_PRIVACY_INVOKED:
35610 + ieee->privacy_invoked = !!wrqu->param.value;
35611 + break;
35612 + default:
35613 + err = -EOPNOTSUPP;
35614 + break;
35615 + }
35616 + spin_unlock_irqrestore(&ieee->lock, flags);
35617 + return err;
35618 +}
35619 +
35620 +int ieee80211_wx_get_auth(struct net_device *dev,
35621 + struct iw_request_info *info,
35622 + union iwreq_data *wrqu,
35623 + char *extra)
35624 +{
35625 + struct ieee80211_device *ieee = netdev_priv(dev);
35626 + unsigned long flags;
35627 + int err = 0;
35628 +
35629 + spin_lock_irqsave(&ieee->lock, flags);
35630 +
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 */
35638 + /*
35639 + * Host AP driver does not use these parameters and allows
35640 + * wpa_supplicant to control them internally.
35641 + */
35642 + err = -EOPNOTSUPP;
35643 + break;
35644 + case IW_AUTH_DROP_UNENCRYPTED:
35645 + wrqu->param.value = ieee->drop_unencrypted;
35646 + break;
35647 + case IW_AUTH_WPA_ENABLED:
35648 + wrqu->param.value = ieee->wpa_enabled;
35649 + break;
35650 + case IW_AUTH_RX_UNENCRYPTED_EAPOL:
35651 + wrqu->param.value = ieee->ieee802_1x;
35652 + break;
35653 + default:
35654 + err = -EOPNOTSUPP;
35655 + break;
35656 + }
35657 + spin_unlock_irqrestore(&ieee->lock, flags);
35658 + return err;
35659 +}
35660 +
35661 EXPORT_SYMBOL(ieee80211_wx_set_encodeext);
35662 EXPORT_SYMBOL(ieee80211_wx_get_encodeext);
35663
35664 EXPORT_SYMBOL(ieee80211_wx_get_scan);
35665 EXPORT_SYMBOL(ieee80211_wx_set_encode);
35666 EXPORT_SYMBOL(ieee80211_wx_get_encode);
35667 +
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"
35679
35680 +config WIRELESS_EXT
35681 + bool
35682 +
35683 endif # if NET
35684 endmenu # Networking
35685
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
35689 @@ -44,6 +44,7 @@
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/
35696
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
35700 @@ -84,10 +84,7 @@
35701 #include <linux/compat.h>
35702 #include <linux/kmod.h>
35703 #include <linux/audit.h>
35704 -
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>
35709
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);
35715 } else
35716 -#ifdef WIRELESS_EXT
35717 +#ifdef CONFIG_WIRELESS_EXT
35718 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
35719 err = dev_ioctl(cmd, argp);
35720 } else
35721 -#endif /* WIRELESS_EXT */
35722 +#endif /* CONFIG_WIRELESS_EXT */
35723 switch (cmd) {
35724 case FIOSETOWN:
35725 case SIOCSPGRP:
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
35729 @@ -0,0 +1,80 @@
35730 +#!/bin/bash
35731 +
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."
35735 + echo
35736 + echo "Usage:"
35737 + echo "$0 [ wlan_device local_ip wpasupplicant_config ]"
35738 + echo
35739 + echo "Examples:"
35740 + echo "Run with default parameters: $0"
35741 + echo "Manually define parameters: $0 wlan0 192.168.1.1 ./wpasupp.conf"
35742 + echo
35743 + echo "Default parameters are: $0 wlan0 192.168.1.101 /etc/wpa_supplicant.conf"
35744 + exit 1
35745 +fi
35746 +
35747 +wlan_dev="$1"
35748 +ip_addr="$2"
35749 +wpasupp_conf="$3"
35750 +
35751 +if [ -z "$wlan_dev" ]; then
35752 + wlan_dev="wlan0"
35753 +fi
35754 +if [ -z "$sta_dev" ]; then
35755 + sta_dev="sta0"
35756 +fi
35757 +if [ -z "$ip_addr" ]; then
35758 + ip_addr="192.168.1.101"
35759 +fi
35760 +if [ -z "$wpasupp_conf" ]; then
35761 + wpasupp_conf="/etc/wpa_supplicant.conf"
35762 +fi
35763 +
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"
35767 + exit 1
35768 +fi
35769 +sta_dev="sta$idx"
35770 +phy_dev="phy$idx"
35771 +
35772 +function run()
35773 +{
35774 + echo "$@"
35775 + $@
35776 + res=$?
35777 + if [ $res -ne 0 ]; then
35778 + echo "FAILED ($res)"
35779 + exit 1
35780 + fi
35781 +}
35782 +
35783 +if [ -z "$(grep -e bcm43xx /proc/modules)" ]; then
35784 + echo "ERROR: bcm43xx module not loaded."
35785 + exit 1
35786 +fi
35787 +
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."
35792 + exit 1
35793 +fi
35794 +run iwconfig $wlan_dev.11 mode managed
35795 +run ifconfig $wlan_dev.11 up
35796 +
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
35802 +
35803 +run wpa_supplicant -B -Dwext -i$sta_dev -c$wpasupp_conf
35804 +
35805 +echo
35806 +echo "You may want to set the default route, now:"
35807 +echo " route add default gw GATEWAY_IP_ADDRESS"
35808 +
35809 +exit 0