blob: 01cf28568bc2b2bb2598d3c14865ca8356f5acee [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
2 *
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
5 *
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
9 *
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
15 *
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
17 *
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
26 *
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
31 *
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
35 * Reserved.
36 *
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
47
48/*
49 * v0.01 -> v0.02 - 21/3/2001 - Jean II
50 * o Allow to use regular ethX device name instead of dldwdX
51 * o Warning on IBSS with ESSID=any for firmware 6.06
52 * o Put proper range.throughput values (optimistic)
53 * o IWSPY support (IOCTL and stat gather in Rx path)
54 * o Allow setting frequency in Ad-Hoc mode
55 * o Disable WEP setting if !has_wep to work on old firmware
56 * o Fix txpower range
57 * o Start adding support for Samsung/Compaq firmware
58 *
59 * v0.02 -> v0.03 - 23/3/2001 - Jean II
60 * o Start adding Symbol support - need to check all that
61 * o Fix Prism2/Symbol WEP to accept 128 bits keys
62 * o Add Symbol WEP (add authentication type)
63 * o Add Prism2/Symbol rate
64 * o Add PM timeout (holdover duration)
65 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
66 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
67 * o Try with an Intel card. It report firmware 1.01, behave like
68 * an antiquated firmware, however on windows it says 2.00. Yuck !
69 * o Workaround firmware bug in allocate buffer (Intel 1.01)
70 * o Finish external renaming to orinoco...
71 * o Testing with various Wavelan firmwares
72 *
73 * v0.03 -> v0.04 - 30/3/2001 - Jean II
74 * o Update to Wireless 11 -> add retry limit/lifetime support
75 * o Tested with a D-Link DWL 650 card, fill in firmware support
76 * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
77 * o Fixed the Prism2 WEP bugs that I introduced in v0.03 :-(
78 * It works on D-Link *only* after a tcpdump. Weird...
79 * And still doesn't work on Intel card. Grrrr...
80 * o Update the mode after a setport3
81 * o Add preamble setting for Symbol cards (not yet enabled)
82 * o Don't complain as much about Symbol cards...
83 *
84 * v0.04 -> v0.04b - 22/4/2001 - David Gibson
85 * o Removed the 'eth' parameter - always use ethXX as the
86 * interface name instead of dldwdXX. The other was racy
87 * anyway.
88 * o Clean up RID definitions in hermes.h, other cleanups
89 *
90 * v0.04b -> v0.04c - 24/4/2001 - Jean II
91 * o Tim Hurley <timster AT seiki.bliztech.com> reported a D-Link card
92 * with vendor 02 and firmware 0.08. Added in the capabilities...
93 * o Tested Lucent firmware 7.28, everything works...
94 *
95 * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
96 * o Spin-off Pcmcia code. This file is renamed orinoco.c,
97 * and orinoco_cs.c now contains only the Pcmcia specific stuff
98 * o Add Airport driver support on top of orinoco.c (see airport.c)
99 *
100 * v0.05 -> v0.05a - 4/5/2001 - Jean II
101 * o Revert to old Pcmcia code to fix breakage of Ben's changes...
102 *
103 * v0.05a -> v0.05b - 4/5/2001 - Jean II
104 * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
105 * o D-Link firmware doesn't support multicast. We just print a few
106 * error messages, but otherwise everything works...
107 * o For David : set/getport3 works fine, just upgrade iwpriv...
108 *
109 * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
110 * o Adapt airport.c to latest changes in orinoco.c
111 * o Remove deferred power enabling code
112 *
113 * v0.05c -> v0.05d - 5/5/2001 - Jean II
114 * o Workaround to SNAP decapsulate frame from Linksys AP
115 * original patch from : Dong Liu <dliu AT research.bell-labs.com>
116 * (note : the memcmp bug was mine - fixed)
117 * o Remove set_retry stuff, no firmware support it (bloat--).
118 *
119 * v0.05d -> v0.06 - 25/5/2001 - Jean II
120 * Original patch from "Hong Lin" <alin AT redhat.com>,
121 * "Ian Kinner" <ikinner AT redhat.com>
122 * and "David Smith" <dsmith AT redhat.com>
123 * o Init of priv->tx_rate_ctrl in firmware specific section.
124 * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
125 * o Spectrum card always need cor_reset (for every reset)
126 * o Fix cor_reset to not lose bit 7 in the register
127 * o flush_stale_links to remove zombie Pcmcia instances
128 * o Ack previous hermes event before reset
129 * Me (with my little hands)
130 * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
131 * o Add priv->need_card_reset to toggle this feature
132 * o Fix various buglets when setting WEP in Symbol firmware
133 * Now, encryption is fully functional on Symbol cards. Youpi !
134 *
135 * v0.06 -> v0.06b - 25/5/2001 - Jean II
136 * o IBSS on Symbol use port_mode = 4. Please don't ask...
137 *
138 * v0.06b -> v0.06c - 29/5/2001 - Jean II
139 * o Show first spy address in /proc/net/wireless for IBSS mode as well
140 *
141 * v0.06c -> v0.06d - 6/7/2001 - David Gibson
142 * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
143 * wishes to reduce the number of unnecessary messages.
144 * o Removed bogus message on CRC error.
145 * o Merged fixes for v0.08 Prism 2 firmware from William Waghorn
146 * <willwaghorn AT yahoo.co.uk>
147 * o Slight cleanup/re-arrangement of firmware detection code.
148 *
149 * v0.06d -> v0.06e - 1/8/2001 - David Gibson
150 * o Removed some redundant global initializers (orinoco_cs.c).
151 * o Added some module metadata
152 *
153 * v0.06e -> v0.06f - 14/8/2001 - David Gibson
154 * o Wording fix to license
155 * o Added a 'use_alternate_encaps' module parameter for APs which need an
156 * oui of 00:00:00. We really need a better way of handling this, but
157 * the module flag is better than nothing for now.
158 *
159 * v0.06f -> v0.07 - 20/8/2001 - David Gibson
160 * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
161 * let the upper layers handle the retry, we retry explicitly in the
162 * Rx path, but don't make as much noise about it.
163 * o Firmware detection cleanups.
164 *
165 * v0.07 -> v0.07a - 1/10/3001 - Jean II
166 * o Add code to read Symbol firmware revision, inspired by latest code
167 * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
168 * o Thanks to Jared Valentine <hidden AT xmission.com> for "providing" me
169 * a 3Com card with a recent firmware, fill out Symbol firmware
170 * capabilities of latest rev (2.20), as well as older Symbol cards.
171 * o Disable Power Management in newer Symbol firmware, the API
172 * has changed (documentation needed).
173 *
174 * v0.07a -> v0.08 - 3/10/2001 - David Gibson
175 * o Fixed a possible buffer overrun found by the Stanford checker (in
176 * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
177 * a big problem.
178 * o Turned has_big_wep on for Intersil cards. That's not true for all of
179 * them but we should at least let the capable ones try.
180 * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
181 * realized that my assumption that the driver's serialization
182 * would prevent the BAP being busy on entry was possibly false, because
183 * things other than seeks may make the BAP busy.
184 * o Use "alternate" (oui 00:00:00) encapsulation by default.
185 * Setting use_old_encaps will mimic the old behaviour, but I think we
186 * will be able to eliminate this.
187 * o Don't try to make __initdata const (the version string). This can't
188 * work because of the way the __initdata sectioning works.
189 * o Added MODULE_LICENSE tags.
190 * o Support for PLX (transparent PCMCIA->PCI bridge) cards.
191 * o Changed to using the new type-fascist min/max.
192 *
193 * v0.08 -> v0.08a - 9/10/2001 - David Gibson
194 * o Inserted some missing acknowledgements/info into the Changelog.
195 * o Fixed some bugs in the normalization of signal level reporting.
196 * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
197 * which led to an instant crash on big-endian machines.
198 *
199 * v0.08a -> v0.08b - 20/11/2001 - David Gibson
200 * o Lots of cleanup and bugfixes in orinoco_plx.c
201 * o Cleanup to handling of Tx rate setting.
202 * o Removed support for old encapsulation method.
203 * o Removed old "dldwd" names.
204 * o Split RID constants into a new file hermes_rid.h
205 * o Renamed RID constants to match linux-wlan-ng and prism2.o
206 * o Bugfixes in hermes.c
207 * o Poke the PLX's INTCSR register, so it actually starts
208 * generating interrupts. These cards might actually work now.
209 * o Update to wireless extensions v12 (Jean II)
210 * o Support for tallies and inquire command (Jean II)
211 * o Airport updates for newer PPC kernels (BenH)
212 *
213 * v0.08b -> v0.09 - 21/12/2001 - David Gibson
214 * o Some new PCI IDs for PLX cards.
215 * o Removed broken attempt to do ALLMULTI reception. Just use
216 * promiscuous mode instead
217 * o Preliminary work for list-AP (Jean II)
218 * o Airport updates from (BenH)
219 * o Eliminated racy hw_ready stuff
220 * o Fixed generation of fake events in irq handler. This should
221 * finally kill the EIO problems (Jean II & dgibson)
222 * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
223 *
224 * v0.09 -> v0.09a - 2/1/2002 - David Gibson
225 * o Fixed stupid mistake in multicast list handling, triggering
226 * a BUG()
227 *
228 * v0.09a -> v0.09b - 16/1/2002 - David Gibson
229 * o Fixed even stupider mistake in new interrupt handling, which
230 * seriously broke things on big-endian machines.
231 * o Removed a bunch of redundant includes and exports.
232 * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
233 * o Don't attempt to do hardware level multicast reception on
234 * Intersil firmware, just go promisc instead.
235 * o Typo fixed in hermes_issue_cmd()
236 * o Eliminated WIRELESS_SPY #ifdefs
237 * o Status code reported on Tx exceptions
238 * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
239 * interrupts, which should fix the timeouts we're seeing.
240 *
241 * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
242 * o Removed nested structures used for header parsing, so the
243 * driver should now work without hackery on ARM
244 * o Fix for WEP handling on Intersil (Hawk Newton)
245 * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
246 * was never very useful.
247 * o Make Rx errors less noisy.
248 *
249 * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
250 * o Laid the groundwork in hermes.[ch] for devices which map
251 * into PCI memory space rather than IO space.
252 * o Fixed bug in multicast handling (cleared multicast list when
253 * leaving promiscuous mode).
254 * o Relegated Tx error messages to debug.
255 * o Cleaned up / corrected handling of allocation lengths.
256 * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
257 * o Change to using alloc_etherdev() for structure allocations.
258 * o Check for and drop undersized packets.
259 * o Fixed a race in stopping/waking the queue. This should fix
260 * the timeout problems (Pavel Roskin)
261 * o Reverted to netif_wake_queue() on the ALLOC event.
262 * o Fixes for recent Symbol firmwares which lack AP density
263 * (Pavel Roskin).
264 *
265 * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
266 * o Handle different register spacing, necessary for Prism 2.5
267 * PCI adaptors (Steve Hill).
268 * o Cleaned up initialization of card structures in orinoco_cs
269 * and airport. Removed card->priv field.
270 * o Make response structure optional for hermes_docmd_wait()
271 * Pavel Roskin)
272 * o Added PCI id for Nortel emobility to orinoco_plx.c.
273 * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
274 * o Cleanups to firmware capability detection.
275 * o Arrange for orinoco_pci.c to override firmware detection.
276 * We should be able to support the PCI Intersil cards now.
277 * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
278 * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
279 * Malinen).
280 * o Makefile changes for better integration into David Hinds
281 * pcmcia-cs package.
282 *
283 * v0.11a -> v0.11b - 1 May 2002 - David Gibson
284 * o Better error reporting in orinoco_plx_init_one()
285 * o Fixed multiple bad kfree() bugs introduced by the
286 * alloc_orinocodev() changes.
287 *
288 * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
289 * o Support changing the MAC address.
290 * o Correct display of Intersil firmware revision numbers.
291 * o Entirely revised locking scheme. Should be both simpler and
292 * better.
293 * o Merged some common code in orinoco_plx, orinoco_pci and
294 * airport by creating orinoco_default_{open,stop,reset}()
295 * which are used as the dev->open, dev->stop, priv->reset
296 * callbacks if none are specified when alloc_orinocodev() is
297 * called.
298 * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
299 * They didn't do anything.
300 *
301 * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
302 * o Some rearrangement of code.
303 * o Numerous fixups to locking and rest handling, particularly
304 * for PCMCIA.
305 * o This allows open and stop net_device methods to be in
306 * orinoco.c now, rather than in the init modules.
307 * o In orinoco_cs.c link->priv now points to the struct
308 * net_device not to the struct orinoco_private.
309 * o Added a check for undersized SNAP frames, which could cause
310 * crashes.
311 *
312 * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
313 * o Fix hw->num_init testing code, so num_init is actually
314 * incremented.
315 * o Fix very stupid bug in orinoco_cs which broke compile with
316 * CONFIG_SMP.
317 * o Squashed a warning.
318 *
319 * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
320 * o Change to C9X style designated initializers.
321 * o Add support for 3Com AirConnect PCI.
322 * o No longer ignore the hard_reset argument to
323 * alloc_orinocodev(). Oops.
324 *
325 * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
326 * o Revert the broken 0.12* locking scheme and go to a new yet
327 * simpler scheme.
328 * o Do firmware resets only in orinoco_init() and when waking
329 * the card from hard sleep.
330 *
331 * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
332 * o Re-introduced full resets (via schedule_task()) on Tx
333 * timeout.
334 *
335 * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
336 * o Minor cleanups to info frame handling. Add basic support
337 * for linkstatus info frames.
338 * o Include required kernel headers in orinoco.h, to avoid
339 * compile problems.
340 *
341 * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
342 * o Implemented hard reset for Airport cards
343 * o Experimental suspend/resume implementation for orinoco_pci
344 * o Abolished /proc debugging support, replaced with a debugging
345 * iwpriv. Now it's ugly and simple instead of ugly and complex.
346 * o Bugfix in hermes.c if the firmware returned a record length
347 * of 0, we could go clobbering memory.
348 * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
349 * was set, which was usually true on PCMCIA hot removes.
350 * o Track LINKSTATUS messages, silently drop Tx packets before
351 * we are connected (avoids confusing the firmware), and only
352 * give LINKSTATUS printk()s if the status has changed.
353 *
354 * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
355 * o Cleanup: use dev instead of priv in various places.
356 * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
357 * if we're in the middle of a (driver initiated) hard reset.
358 * o Bug fix: ETH_ZLEN is supposed to include the header
359 * (Dionysus Blazakis & Manish Karir)
360 * o Convert to using workqueues instead of taskqueues (and
361 * backwards compatibility macros for pre 2.5.41 kernels).
362 * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
363 * airport.c
364 * o New orinoco_tmd.c init module from Joerg Dorchain for
365 * TMD7160 based PCI to PCMCIA bridges (similar to
366 * orinoco_plx.c).
367 *
368 * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
369 * o Make hw_unavailable a counter, rather than just a flag, this
370 * is necessary to avoid some races (such as a card being
371 * removed in the middle of orinoco_reset().
372 * o Restore Release/RequestConfiguration in the PCMCIA event handler
373 * when dealing with a driver initiated hard reset. This is
374 * necessary to prevent hangs due to a spurious interrupt while
375 * the reset is in progress.
376 * o Clear the 802.11 header when transmitting, even though we
377 * don't use it. This fixes a long standing bug on some
378 * firmwares, which seem to get confused if that isn't done.
379 * o Be less eager to de-encapsulate SNAP frames, only do so if
380 * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
381 * behaviour broke CDP (Cisco Discovery Protocol).
382 * o Use dev instead of priv for free_irq() as well as
383 * request_irq() (oops).
384 * o Attempt to reset rather than giving up if we get too many
385 * IRQs.
386 * o Changed semantics of __orinoco_down() so it can be called
387 * safely with hw_unavailable set. It also now clears the
388 * linkstatus (since we're going to have to reassociate).
389 *
390 * v0.13d -> v0.13e - 12 May 2003 - David Gibson
391 * o Support for post-2.5.68 return values from irq handler.
392 * o Fixed bug where underlength packets would be double counted
393 * in the rx_dropped statistics.
394 * o Provided a module parameter to suppress linkstatus messages.
395 *
396 * v0.13e -> v0.14alpha1 - 30 Sep 2003 - David Gibson
397 * o Replaced priv->connected logic with netif_carrier_on/off()
398 * calls.
399 * o Remove has_ibss_any and never set the CREATEIBSS RID when
400 * the ESSID is empty. Too many firmwares break if we do.
401 * o 2.6 merges: Replace pdev->slot_name with pci_name(), remove
402 * __devinitdata from PCI ID tables, use free_netdev().
403 * o Enabled shared-key authentication for Agere firmware (from
404 * Robert J. Moore <Robert.J.Moore AT allanbank.com>
405 * o Move netif_wake_queue() (back) to the Tx completion from the
406 * ALLOC event. This seems to prevent/mitigate the rolling
407 * error -110 problems at least on some Intersil firmwares.
408 * Theoretically reduces performance, but I can't measure it.
409 * Patch from Andrew Tridgell <tridge AT samba.org>
410 *
411 * v0.14alpha1 -> v0.14alpha2 - 20 Oct 2003 - David Gibson
412 * o Correctly turn off shared-key authentication when requested
413 * (bugfix from Robert J. Moore).
414 * o Correct airport sleep interfaces for current 2.6 kernels.
415 * o Add code for key change without disabling/enabling the MAC
416 * port. This is supposed to allow 802.1x to work sanely, but
417 * doesn't seem to yet.
418 *
419 * TODO
420 * o New wireless extensions API (patch from Moustafa
421 * Youssef, updated by Jim Carter and Pavel Roskin).
422 * o Handle de-encapsulation within network layer, provide 802.11
423 * headers (patch from Thomas 'Dent' Mirlacher)
424 * o RF monitor mode support
425 * o Fix possible races in SPY handling.
426 * o Disconnect wireless extensions from fundamental configuration.
427 * o (maybe) Software WEP support (patch from Stano Meduna).
428 * o (maybe) Use multiple Tx buffers - driver handling queue
429 * rather than firmware.
430 */
431
432/* Locking and synchronization:
433 *
434 * The basic principle is that everything is serialized through a
435 * single spinlock, priv->lock. The lock is used in user, bh and irq
436 * context, so when taken outside hardirq context it should always be
437 * taken with interrupts disabled. The lock protects both the
438 * hardware and the struct orinoco_private.
439 *
440 * Another flag, priv->hw_unavailable indicates that the hardware is
441 * unavailable for an extended period of time (e.g. suspended, or in
442 * the middle of a hard reset). This flag is protected by the
443 * spinlock. All code which touches the hardware should check the
444 * flag after taking the lock, and if it is set, give up on whatever
445 * they are doing and drop the lock again. The orinoco_lock()
446 * function handles this (it unlocks and returns -EBUSY if
447 * hw_unavailable is non-zero).
448 */
449
450#define DRIVER_NAME "orinoco"
451
452#include <linux/config.h>
453
454#include <linux/module.h>
455#include <linux/kernel.h>
456#include <linux/init.h>
457#include <linux/ptrace.h>
458#include <linux/slab.h>
459#include <linux/string.h>
460#include <linux/timer.h>
461#include <linux/ioport.h>
462#include <linux/netdevice.h>
463#include <linux/if_arp.h>
464#include <linux/etherdevice.h>
465#include <linux/wireless.h>
466
467#include <asm/uaccess.h>
468#include <asm/io.h>
469#include <asm/system.h>
470
471#include "hermes.h"
472#include "hermes_rid.h"
473#include "orinoco.h"
474#include "ieee802_11.h"
475
476/********************************************************************/
477/* Module information */
478/********************************************************************/
479
480MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
481MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
482MODULE_LICENSE("Dual MPL/GPL");
483
484/* Level of debugging. Used in the macros in orinoco.h */
485#ifdef ORINOCO_DEBUG
486int orinoco_debug = ORINOCO_DEBUG;
487module_param(orinoco_debug, int, 0644);
488MODULE_PARM_DESC(orinoco_debug, "Debug level");
489EXPORT_SYMBOL(orinoco_debug);
490#endif
491
492static int suppress_linkstatus; /* = 0 */
493module_param(suppress_linkstatus, bool, 0644);
494MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Gibson7bb7c3a2005-05-12 20:02:10 -0400495static int ignore_disconnect; /* = 0 */
496module_param(ignore_disconnect, int, 0644);
497MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499/********************************************************************/
500/* Compile time configuration and compatibility stuff */
501/********************************************************************/
502
503/* We do this this way to avoid ifdefs in the actual code */
504#ifdef WIRELESS_SPY
505#define SPY_NUMBER(priv) (priv->spy_number)
506#else
507#define SPY_NUMBER(priv) 0
508#endif /* WIRELESS_SPY */
509
510/********************************************************************/
511/* Internal constants */
512/********************************************************************/
513
514#define ORINOCO_MIN_MTU 256
515#define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
516
517#define SYMBOL_MAX_VER_LEN (14)
518#define USER_BAP 0
519#define IRQ_BAP 1
520#define MAX_IRQLOOPS_PER_IRQ 10
521#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
522 * how many events the
523 * device could
524 * legitimately generate */
525#define SMALL_KEY_SIZE 5
526#define LARGE_KEY_SIZE 13
527#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
528
529#define DUMMY_FID 0xFFFF
530
531/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
532 HERMES_MAX_MULTICAST : 0)*/
533#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
534
535#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
536 | HERMES_EV_TX | HERMES_EV_TXEXC \
537 | HERMES_EV_WTERR | HERMES_EV_INFO \
538 | HERMES_EV_INFDROP )
539
540/********************************************************************/
541/* Data tables */
542/********************************************************************/
543
544/* The frequency of each channel in MHz */
545static const long channel_frequency[] = {
546 2412, 2417, 2422, 2427, 2432, 2437, 2442,
547 2447, 2452, 2457, 2462, 2467, 2472, 2484
548};
549#define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
550
551/* This tables gives the actual meanings of the bitrate IDs returned
552 * by the firmware. */
553static struct {
554 int bitrate; /* in 100s of kilobits */
555 int automatic;
556 u16 agere_txratectrl;
557 u16 intersil_txratectrl;
558} bitrate_table[] = {
559 {110, 1, 3, 15}, /* Entry 0 is the default */
560 {10, 0, 1, 1},
561 {10, 1, 1, 1},
562 {20, 0, 2, 2},
563 {20, 1, 6, 3},
564 {55, 0, 4, 4},
565 {55, 1, 7, 7},
566 {110, 0, 5, 8},
567};
568#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
569
570/********************************************************************/
571/* Data types */
572/********************************************************************/
573
574struct header_struct {
575 /* 802.3 */
576 u8 dest[ETH_ALEN];
577 u8 src[ETH_ALEN];
578 u16 len;
579 /* 802.2 */
580 u8 dsap;
581 u8 ssap;
582 u8 ctrl;
583 /* SNAP */
584 u8 oui[3];
585 u16 ethertype;
586} __attribute__ ((packed));
587
588/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
589u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
590
591#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
592
593struct hermes_rx_descriptor {
594 u16 status;
595 u32 time;
596 u8 silence;
597 u8 signal;
598 u8 rate;
599 u8 rxflow;
600 u32 reserved;
601} __attribute__ ((packed));
602
603/********************************************************************/
604/* Function prototypes */
605/********************************************************************/
606
607static int orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
608static int __orinoco_program_rids(struct net_device *dev);
609static void __orinoco_set_multicast_list(struct net_device *dev);
610static int orinoco_debug_dump_recs(struct net_device *dev);
611
612/********************************************************************/
613/* Internal helper functions */
614/********************************************************************/
615
616static inline void set_port_type(struct orinoco_private *priv)
617{
618 switch (priv->iw_mode) {
619 case IW_MODE_INFRA:
620 priv->port_type = 1;
621 priv->createibss = 0;
622 break;
623 case IW_MODE_ADHOC:
624 if (priv->prefer_port3) {
625 priv->port_type = 3;
626 priv->createibss = 0;
627 } else {
628 priv->port_type = priv->ibss_port;
629 priv->createibss = 1;
630 }
631 break;
632 default:
633 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
634 priv->ndev->name);
635 }
636}
637
638/********************************************************************/
639/* Device methods */
640/********************************************************************/
641
642static int orinoco_open(struct net_device *dev)
643{
644 struct orinoco_private *priv = netdev_priv(dev);
645 unsigned long flags;
646 int err;
647
648 if (orinoco_lock(priv, &flags) != 0)
649 return -EBUSY;
650
651 err = __orinoco_up(dev);
652
653 if (! err)
654 priv->open = 1;
655
656 orinoco_unlock(priv, &flags);
657
658 return err;
659}
660
661int orinoco_stop(struct net_device *dev)
662{
663 struct orinoco_private *priv = netdev_priv(dev);
664 int err = 0;
665
666 /* We mustn't use orinoco_lock() here, because we need to be
667 able to close the interface even if hw_unavailable is set
668 (e.g. as we're released after a PC Card removal) */
669 spin_lock_irq(&priv->lock);
670
671 priv->open = 0;
672
673 err = __orinoco_down(dev);
674
675 spin_unlock_irq(&priv->lock);
676
677 return err;
678}
679
680static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
681{
682 struct orinoco_private *priv = netdev_priv(dev);
683
684 return &priv->stats;
685}
686
687static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
688{
689 struct orinoco_private *priv = netdev_priv(dev);
690 hermes_t *hw = &priv->hw;
691 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400692 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 unsigned long flags;
694
695 if (! netif_device_present(dev)) {
696 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
697 dev->name);
698 return NULL; /* FIXME: Can we do better than this? */
699 }
700
David Gibsone67d9d92005-05-12 20:01:22 -0400701 /* If busy, return the old stats. Returning NULL may cause
702 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400704 return wstats;
705
706 /* We can't really wait for the tallies inquiry command to
707 * complete, so we just use the previous results and trigger
708 * a new tallies inquiry command for next time - Jean II */
709 /* FIXME: Really we should wait for the inquiry to come back -
710 * as it is the stats we give don't make a whole lot of sense.
711 * Unfortunately, it's not clear how to do that within the
712 * wireless extensions framework: I think we're in user
713 * context, but a lock seems to be held by the time we get in
714 * here so we're not safe to sleep here. */
715 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 if (priv->iw_mode == IW_MODE_ADHOC) {
718 memset(&wstats->qual, 0, sizeof(wstats->qual));
719 /* If a spy address is defined, we report stats of the
720 * first spy address - Jean II */
721 if (SPY_NUMBER(priv)) {
722 wstats->qual.qual = priv->spy_stat[0].qual;
723 wstats->qual.level = priv->spy_stat[0].level;
724 wstats->qual.noise = priv->spy_stat[0].noise;
725 wstats->qual.updated = priv->spy_stat[0].updated;
726 }
727 } else {
728 struct {
729 u16 qual, signal, noise;
730 } __attribute__ ((packed)) cq;
731
732 err = HERMES_READ_RECORD(hw, USER_BAP,
733 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400734
735 if (!err) {
736 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
737 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
738 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
739 wstats->qual.updated = 7;
740 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 return wstats;
745}
746
747static void orinoco_set_multicast_list(struct net_device *dev)
748{
749 struct orinoco_private *priv = netdev_priv(dev);
750 unsigned long flags;
751
752 if (orinoco_lock(priv, &flags) != 0) {
753 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
754 "called when hw_unavailable\n", dev->name);
755 return;
756 }
757
758 __orinoco_set_multicast_list(dev);
759 orinoco_unlock(priv, &flags);
760}
761
762static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
763{
764 struct orinoco_private *priv = netdev_priv(dev);
765
766 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
767 return -EINVAL;
768
769 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
770 (priv->nicbuf_size - ETH_HLEN) )
771 return -EINVAL;
772
773 dev->mtu = new_mtu;
774
775 return 0;
776}
777
778/********************************************************************/
779/* Tx path */
780/********************************************************************/
781
782static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
783{
784 struct orinoco_private *priv = netdev_priv(dev);
785 struct net_device_stats *stats = &priv->stats;
786 hermes_t *hw = &priv->hw;
787 int err = 0;
788 u16 txfid = priv->txfid;
789 char *p;
790 struct ethhdr *eh;
791 int len, data_len, data_off;
792 struct hermes_tx_descriptor desc;
793 unsigned long flags;
794
795 TRACE_ENTER(dev->name);
796
797 if (! netif_running(dev)) {
798 printk(KERN_ERR "%s: Tx on stopped device!\n",
799 dev->name);
800 TRACE_EXIT(dev->name);
801 return 1;
802 }
803
804 if (netif_queue_stopped(dev)) {
805 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
806 dev->name);
807 TRACE_EXIT(dev->name);
808 return 1;
809 }
810
811 if (orinoco_lock(priv, &flags) != 0) {
812 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
813 dev->name);
814 TRACE_EXIT(dev->name);
815 return 1;
816 }
817
818 if (! netif_carrier_ok(dev)) {
819 /* Oops, the firmware hasn't established a connection,
820 silently drop the packet (this seems to be the
821 safest approach). */
822 stats->tx_errors++;
823 orinoco_unlock(priv, &flags);
824 dev_kfree_skb(skb);
825 TRACE_EXIT(dev->name);
826 return 0;
827 }
828
829 /* Length of the packet body */
830 /* FIXME: what if the skb is smaller than this? */
831 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
832
833 eh = (struct ethhdr *)skb->data;
834
835 memset(&desc, 0, sizeof(desc));
836 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
837 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
838 if (err) {
839 if (net_ratelimit())
840 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
841 "to BAP\n", dev->name, err);
842 stats->tx_errors++;
843 goto fail;
844 }
845
846 /* Clear the 802.11 header and data length fields - some
847 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
848 * if this isn't done. */
849 hermes_clear_words(hw, HERMES_DATA0,
850 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
851
852 /* Encapsulate Ethernet-II frames */
853 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
854 struct header_struct hdr;
855 data_len = len;
856 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
857 p = skb->data + ETH_HLEN;
858
859 /* 802.3 header */
860 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
861 memcpy(hdr.src, eh->h_source, ETH_ALEN);
862 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
863
864 /* 802.2 header */
865 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
866
867 hdr.ethertype = eh->h_proto;
868 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
869 txfid, HERMES_802_3_OFFSET);
870 if (err) {
871 if (net_ratelimit())
872 printk(KERN_ERR "%s: Error %d writing packet "
873 "header to BAP\n", dev->name, err);
874 stats->tx_errors++;
875 goto fail;
876 }
877 } else { /* IEEE 802.3 frame */
878 data_len = len + ETH_HLEN;
879 data_off = HERMES_802_3_OFFSET;
880 p = skb->data;
881 }
882
883 /* Round up for odd length packets */
884 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
885 txfid, data_off);
886 if (err) {
887 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
888 dev->name, err);
889 stats->tx_errors++;
890 goto fail;
891 }
892
893 /* Finally, we actually initiate the send */
894 netif_stop_queue(dev);
895
896 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
897 txfid, NULL);
898 if (err) {
899 netif_start_queue(dev);
900 printk(KERN_ERR "%s: Error %d transmitting packet\n",
901 dev->name, err);
902 stats->tx_errors++;
903 goto fail;
904 }
905
906 dev->trans_start = jiffies;
907 stats->tx_bytes += data_off + data_len;
908
909 orinoco_unlock(priv, &flags);
910
911 dev_kfree_skb(skb);
912
913 TRACE_EXIT(dev->name);
914
915 return 0;
916 fail:
917 TRACE_EXIT(dev->name);
918
919 orinoco_unlock(priv, &flags);
920 return err;
921}
922
923static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
924{
925 struct orinoco_private *priv = netdev_priv(dev);
926 u16 fid = hermes_read_regn(hw, ALLOCFID);
927
928 if (fid != priv->txfid) {
929 if (fid != DUMMY_FID)
930 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
931 dev->name, fid);
932 return;
933 }
934
935 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
936}
937
938static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
939{
940 struct orinoco_private *priv = netdev_priv(dev);
941 struct net_device_stats *stats = &priv->stats;
942
943 stats->tx_packets++;
944
945 netif_wake_queue(dev);
946
947 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
948}
949
950static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
951{
952 struct orinoco_private *priv = netdev_priv(dev);
953 struct net_device_stats *stats = &priv->stats;
954 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
955 struct hermes_tx_descriptor desc;
956 int err = 0;
957
958 if (fid == DUMMY_FID)
959 return; /* Nothing's really happened */
960
961 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
962 if (err) {
963 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
964 "(FID=%04X error %d)\n",
965 dev->name, fid, err);
966 } else {
967 DEBUG(1, "%s: Tx error, status %d\n",
968 dev->name, le16_to_cpu(desc.status));
969 }
970
971 stats->tx_errors++;
972
973 netif_wake_queue(dev);
974 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
975}
976
977static void orinoco_tx_timeout(struct net_device *dev)
978{
979 struct orinoco_private *priv = netdev_priv(dev);
980 struct net_device_stats *stats = &priv->stats;
981 struct hermes *hw = &priv->hw;
982
983 printk(KERN_WARNING "%s: Tx timeout! "
984 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
985 dev->name, hermes_read_regn(hw, ALLOCFID),
986 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
987
988 stats->tx_errors++;
989
990 schedule_work(&priv->reset_work);
991}
992
993/********************************************************************/
994/* Rx path (data frames) */
995/********************************************************************/
996
997/* Does the frame have a SNAP header indicating it should be
998 * de-encapsulated to Ethernet-II? */
999static inline int is_ethersnap(void *_hdr)
1000{
1001 u8 *hdr = _hdr;
1002
1003 /* We de-encapsulate all packets which, a) have SNAP headers
1004 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1005 * and where b) the OUI of the SNAP header is 00:00:00 or
1006 * 00:00:f8 - we need both because different APs appear to use
1007 * different OUIs for some reason */
1008 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1009 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1010}
1011
1012static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1013 int level, int noise)
1014{
1015 struct orinoco_private *priv = netdev_priv(dev);
1016 int i;
1017
1018 /* Gather wireless spy statistics: for each packet, compare the
1019 * source address with out list, and if match, get the stats... */
1020 for (i = 0; i < priv->spy_number; i++)
1021 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
1022 priv->spy_stat[i].level = level - 0x95;
1023 priv->spy_stat[i].noise = noise - 0x95;
1024 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
1025 priv->spy_stat[i].updated = 7;
1026 }
1027}
1028
1029static void orinoco_stat_gather(struct net_device *dev,
1030 struct sk_buff *skb,
1031 struct hermes_rx_descriptor *desc)
1032{
1033 struct orinoco_private *priv = netdev_priv(dev);
1034
1035 /* Using spy support with lots of Rx packets, like in an
1036 * infrastructure (AP), will really slow down everything, because
1037 * the MAC address must be compared to each entry of the spy list.
1038 * If the user really asks for it (set some address in the
1039 * spy list), we do it, but he will pay the price.
1040 * Note that to get here, you need both WIRELESS_SPY
1041 * compiled in AND some addresses in the list !!!
1042 */
1043 /* Note : gcc will optimise the whole section away if
1044 * WIRELESS_SPY is not defined... - Jean II */
1045 if (SPY_NUMBER(priv)) {
1046 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
1047 desc->signal, desc->silence);
1048 }
1049}
1050
1051static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1052{
1053 struct orinoco_private *priv = netdev_priv(dev);
1054 struct net_device_stats *stats = &priv->stats;
1055 struct iw_statistics *wstats = &priv->wstats;
1056 struct sk_buff *skb = NULL;
1057 u16 rxfid, status;
1058 int length, data_len, data_off;
1059 char *p;
1060 struct hermes_rx_descriptor desc;
1061 struct header_struct hdr;
1062 struct ethhdr *eh;
1063 int err;
1064
1065 rxfid = hermes_read_regn(hw, RXFID);
1066
1067 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1068 rxfid, 0);
1069 if (err) {
1070 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1071 "Frame dropped.\n", dev->name, err);
1072 stats->rx_errors++;
1073 goto drop;
1074 }
1075
1076 status = le16_to_cpu(desc.status);
1077
1078 if (status & HERMES_RXSTAT_ERR) {
1079 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1080 wstats->discard.code++;
1081 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1082 dev->name);
1083 } else {
1084 stats->rx_crc_errors++;
1085 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
1086 }
1087 stats->rx_errors++;
1088 goto drop;
1089 }
1090
1091 /* For now we ignore the 802.11 header completely, assuming
1092 that the card's firmware has handled anything vital */
1093
1094 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
1095 rxfid, HERMES_802_3_OFFSET);
1096 if (err) {
1097 printk(KERN_ERR "%s: error %d reading frame header. "
1098 "Frame dropped.\n", dev->name, err);
1099 stats->rx_errors++;
1100 goto drop;
1101 }
1102
1103 length = ntohs(hdr.len);
1104
1105 /* Sanity checks */
1106 if (length < 3) { /* No for even an 802.2 LLC header */
1107 /* At least on Symbol firmware with PCF we get quite a
1108 lot of these legitimately - Poll frames with no
1109 data. */
1110 stats->rx_dropped++;
1111 goto drop;
1112 }
1113 if (length > IEEE802_11_DATA_LEN) {
1114 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1115 dev->name, length);
1116 stats->rx_length_errors++;
1117 stats->rx_errors++;
1118 goto drop;
1119 }
1120
1121 /* We need space for the packet data itself, plus an ethernet
1122 header, plus 2 bytes so we can align the IP header on a
1123 32bit boundary, plus 1 byte so we can read in odd length
1124 packets from the card, which has an IO granularity of 16
1125 bits */
1126 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1127 if (!skb) {
1128 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1129 dev->name);
1130 goto drop;
1131 }
1132
1133 skb_reserve(skb, 2); /* This way the IP header is aligned */
1134
1135 /* Handle decapsulation
1136 * In most cases, the firmware tell us about SNAP frames.
1137 * For some reason, the SNAP frames sent by LinkSys APs
1138 * are not properly recognised by most firmwares.
1139 * So, check ourselves */
1140 if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1141 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1142 is_ethersnap(&hdr)) {
1143 /* These indicate a SNAP within 802.2 LLC within
1144 802.11 frame which we'll need to de-encapsulate to
1145 the original EthernetII frame. */
1146
1147 if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
1148 stats->rx_length_errors++;
1149 goto drop;
1150 }
1151
1152 /* Remove SNAP header, reconstruct EthernetII frame */
1153 data_len = length - ENCAPS_OVERHEAD;
1154 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
1155
1156 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1157
1158 memcpy(eh, &hdr, 2 * ETH_ALEN);
1159 eh->h_proto = hdr.ethertype;
1160 } else {
1161 /* All other cases indicate a genuine 802.3 frame. No
1162 decapsulation needed. We just throw the whole
1163 thing in, and hope the protocol layer can deal with
1164 it as 802.3 */
1165 data_len = length;
1166 data_off = HERMES_802_3_OFFSET;
1167 /* FIXME: we re-read from the card data we already read here */
1168 }
1169
1170 p = skb_put(skb, data_len);
1171 err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2),
1172 rxfid, data_off);
1173 if (err) {
1174 printk(KERN_ERR "%s: error %d reading frame. "
1175 "Frame dropped.\n", dev->name, err);
1176 stats->rx_errors++;
1177 goto drop;
1178 }
1179
1180 dev->last_rx = jiffies;
1181 skb->dev = dev;
1182 skb->protocol = eth_type_trans(skb, dev);
1183 skb->ip_summed = CHECKSUM_NONE;
1184
1185 /* Process the wireless stats if needed */
1186 orinoco_stat_gather(dev, skb, &desc);
1187
1188 /* Pass the packet to the networking stack */
1189 netif_rx(skb);
1190 stats->rx_packets++;
1191 stats->rx_bytes += length;
1192
1193 return;
1194
1195 drop:
1196 stats->rx_dropped++;
1197
1198 if (skb)
1199 dev_kfree_skb_irq(skb);
1200 return;
1201}
1202
1203/********************************************************************/
1204/* Rx path (info frames) */
1205/********************************************************************/
1206
1207static void print_linkstatus(struct net_device *dev, u16 status)
1208{
1209 char * s;
1210
1211 if (suppress_linkstatus)
1212 return;
1213
1214 switch (status) {
1215 case HERMES_LINKSTATUS_NOT_CONNECTED:
1216 s = "Not Connected";
1217 break;
1218 case HERMES_LINKSTATUS_CONNECTED:
1219 s = "Connected";
1220 break;
1221 case HERMES_LINKSTATUS_DISCONNECTED:
1222 s = "Disconnected";
1223 break;
1224 case HERMES_LINKSTATUS_AP_CHANGE:
1225 s = "AP Changed";
1226 break;
1227 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1228 s = "AP Out of Range";
1229 break;
1230 case HERMES_LINKSTATUS_AP_IN_RANGE:
1231 s = "AP In Range";
1232 break;
1233 case HERMES_LINKSTATUS_ASSOC_FAILED:
1234 s = "Association Failed";
1235 break;
1236 default:
1237 s = "UNKNOWN";
1238 }
1239
1240 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1241 dev->name, s, status);
1242}
1243
1244static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1245{
1246 struct orinoco_private *priv = netdev_priv(dev);
1247 u16 infofid;
1248 struct {
1249 u16 len;
1250 u16 type;
1251 } __attribute__ ((packed)) info;
1252 int len, type;
1253 int err;
1254
1255 /* This is an answer to an INQUIRE command that we did earlier,
1256 * or an information "event" generated by the card
1257 * The controller return to us a pseudo frame containing
1258 * the information in question - Jean II */
1259 infofid = hermes_read_regn(hw, INFOFID);
1260
1261 /* Read the info frame header - don't try too hard */
1262 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1263 infofid, 0);
1264 if (err) {
1265 printk(KERN_ERR "%s: error %d reading info frame. "
1266 "Frame dropped.\n", dev->name, err);
1267 return;
1268 }
1269
1270 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1271 type = le16_to_cpu(info.type);
1272
1273 switch (type) {
1274 case HERMES_INQ_TALLIES: {
1275 struct hermes_tallies_frame tallies;
1276 struct iw_statistics *wstats = &priv->wstats;
1277
1278 if (len > sizeof(tallies)) {
1279 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1280 dev->name, len);
1281 len = sizeof(tallies);
1282 }
1283
1284 /* Read directly the data (no seek) */
1285 hermes_read_words(hw, HERMES_DATA1, (void *) &tallies,
1286 len / 2); /* FIXME: blech! */
1287
1288 /* Increment our various counters */
1289 /* wstats->discard.nwid - no wrong BSSID stuff */
1290 wstats->discard.code +=
1291 le16_to_cpu(tallies.RxWEPUndecryptable);
1292 if (len == sizeof(tallies))
1293 wstats->discard.code +=
1294 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1295 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1296 wstats->discard.misc +=
1297 le16_to_cpu(tallies.TxDiscardsWrongSA);
1298 wstats->discard.fragment +=
1299 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1300 wstats->discard.retries +=
1301 le16_to_cpu(tallies.TxRetryLimitExceeded);
1302 /* wstats->miss.beacon - no match */
1303 }
1304 break;
1305 case HERMES_INQ_LINKSTATUS: {
1306 struct hermes_linkstatus linkstatus;
1307 u16 newstatus;
1308 int connected;
1309
1310 if (len != sizeof(linkstatus)) {
1311 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1312 dev->name, len);
1313 break;
1314 }
1315
1316 hermes_read_words(hw, HERMES_DATA1, (void *) &linkstatus,
1317 len / 2);
1318 newstatus = le16_to_cpu(linkstatus.linkstatus);
1319
1320 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1321 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1322 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1323
1324 if (connected)
1325 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001326 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 netif_carrier_off(dev);
1328
1329 if (newstatus != priv->last_linkstatus)
1330 print_linkstatus(dev, newstatus);
1331
1332 priv->last_linkstatus = newstatus;
1333 }
1334 break;
1335 default:
1336 printk(KERN_DEBUG "%s: Unknown information frame received: "
1337 "type 0x%04x, length %d\n", dev->name, type, len);
1338 /* We don't actually do anything about it */
1339 break;
1340 }
1341}
1342
1343static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1344{
1345 if (net_ratelimit())
1346 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1347}
1348
1349/********************************************************************/
1350/* Internal hardware control routines */
1351/********************************************************************/
1352
1353int __orinoco_up(struct net_device *dev)
1354{
1355 struct orinoco_private *priv = netdev_priv(dev);
1356 struct hermes *hw = &priv->hw;
1357 int err;
1358
1359 err = __orinoco_program_rids(dev);
1360 if (err) {
1361 printk(KERN_ERR "%s: Error %d configuring card\n",
1362 dev->name, err);
1363 return err;
1364 }
1365
1366 /* Fire things up again */
1367 hermes_set_irqmask(hw, ORINOCO_INTEN);
1368 err = hermes_enable_port(hw, 0);
1369 if (err) {
1370 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1371 dev->name, err);
1372 return err;
1373 }
1374
1375 netif_start_queue(dev);
1376
1377 return 0;
1378}
1379
1380int __orinoco_down(struct net_device *dev)
1381{
1382 struct orinoco_private *priv = netdev_priv(dev);
1383 struct hermes *hw = &priv->hw;
1384 int err;
1385
1386 netif_stop_queue(dev);
1387
1388 if (! priv->hw_unavailable) {
1389 if (! priv->broken_disableport) {
1390 err = hermes_disable_port(hw, 0);
1391 if (err) {
1392 /* Some firmwares (e.g. Intersil 1.3.x) seem
1393 * to have problems disabling the port, oh
1394 * well, too bad. */
1395 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1396 dev->name, err);
1397 priv->broken_disableport = 1;
1398 }
1399 }
1400 hermes_set_irqmask(hw, 0);
1401 hermes_write_regn(hw, EVACK, 0xffff);
1402 }
1403
1404 /* firmware will have to reassociate */
1405 netif_carrier_off(dev);
1406 priv->last_linkstatus = 0xffff;
1407
1408 return 0;
1409}
1410
1411int orinoco_reinit_firmware(struct net_device *dev)
1412{
1413 struct orinoco_private *priv = netdev_priv(dev);
1414 struct hermes *hw = &priv->hw;
1415 int err;
1416
1417 err = hermes_init(hw);
1418 if (err)
1419 return err;
1420
1421 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1422 if (err == -EIO) {
1423 /* Try workaround for old Symbol firmware bug */
1424 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1425 "(old Symbol firmware?). Trying to work around... ",
1426 dev->name);
1427
1428 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1429 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1430 if (err)
1431 printk("failed!\n");
1432 else
1433 printk("ok.\n");
1434 }
1435
1436 return err;
1437}
1438
1439static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1440{
1441 hermes_t *hw = &priv->hw;
1442 int err = 0;
1443
1444 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1445 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1446 priv->ndev->name, priv->bitratemode);
1447 return -EINVAL;
1448 }
1449
1450 switch (priv->firmware_type) {
1451 case FIRMWARE_TYPE_AGERE:
1452 err = hermes_write_wordrec(hw, USER_BAP,
1453 HERMES_RID_CNFTXRATECONTROL,
1454 bitrate_table[priv->bitratemode].agere_txratectrl);
1455 break;
1456 case FIRMWARE_TYPE_INTERSIL:
1457 case FIRMWARE_TYPE_SYMBOL:
1458 err = hermes_write_wordrec(hw, USER_BAP,
1459 HERMES_RID_CNFTXRATECONTROL,
1460 bitrate_table[priv->bitratemode].intersil_txratectrl);
1461 break;
1462 default:
1463 BUG();
1464 }
1465
1466 return err;
1467}
1468
1469/* Change the WEP keys and/or the current keys. Can be called
1470 * either from __orinoco_hw_setup_wep() or directly from
1471 * orinoco_ioctl_setiwencode(). In the later case the association
1472 * with the AP is not broken (if the firmware can handle it),
1473 * which is needed for 802.1x implementations. */
1474static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1475{
1476 hermes_t *hw = &priv->hw;
1477 int err = 0;
1478
1479 switch (priv->firmware_type) {
1480 case FIRMWARE_TYPE_AGERE:
1481 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1482 HERMES_RID_CNFWEPKEYS_AGERE,
1483 &priv->keys);
1484 if (err)
1485 return err;
1486 err = hermes_write_wordrec(hw, USER_BAP,
1487 HERMES_RID_CNFTXKEY_AGERE,
1488 priv->tx_key);
1489 if (err)
1490 return err;
1491 break;
1492 case FIRMWARE_TYPE_INTERSIL:
1493 case FIRMWARE_TYPE_SYMBOL:
1494 {
1495 int keylen;
1496 int i;
1497
1498 /* Force uniform key length to work around firmware bugs */
1499 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1500
1501 if (keylen > LARGE_KEY_SIZE) {
1502 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1503 priv->ndev->name, priv->tx_key, keylen);
1504 return -E2BIG;
1505 }
1506
1507 /* Write all 4 keys */
1508 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1509 err = hermes_write_ltv(hw, USER_BAP,
1510 HERMES_RID_CNFDEFAULTKEY0 + i,
1511 HERMES_BYTES_TO_RECLEN(keylen),
1512 priv->keys[i].data);
1513 if (err)
1514 return err;
1515 }
1516
1517 /* Write the index of the key used in transmission */
1518 err = hermes_write_wordrec(hw, USER_BAP,
1519 HERMES_RID_CNFWEPDEFAULTKEYID,
1520 priv->tx_key);
1521 if (err)
1522 return err;
1523 }
1524 break;
1525 }
1526
1527 return 0;
1528}
1529
1530static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1531{
1532 hermes_t *hw = &priv->hw;
1533 int err = 0;
1534 int master_wep_flag;
1535 int auth_flag;
1536
1537 if (priv->wep_on)
1538 __orinoco_hw_setup_wepkeys(priv);
1539
1540 if (priv->wep_restrict)
1541 auth_flag = HERMES_AUTH_SHARED_KEY;
1542 else
1543 auth_flag = HERMES_AUTH_OPEN;
1544
1545 switch (priv->firmware_type) {
1546 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1547 if (priv->wep_on) {
1548 /* Enable the shared-key authentication. */
1549 err = hermes_write_wordrec(hw, USER_BAP,
1550 HERMES_RID_CNFAUTHENTICATION_AGERE,
1551 auth_flag);
1552 }
1553 err = hermes_write_wordrec(hw, USER_BAP,
1554 HERMES_RID_CNFWEPENABLED_AGERE,
1555 priv->wep_on);
1556 if (err)
1557 return err;
1558 break;
1559
1560 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1561 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1562 if (priv->wep_on) {
1563 if (priv->wep_restrict ||
1564 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1565 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1566 HERMES_WEP_EXCL_UNENCRYPTED;
1567 else
1568 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1569
1570 err = hermes_write_wordrec(hw, USER_BAP,
1571 HERMES_RID_CNFAUTHENTICATION,
1572 auth_flag);
1573 if (err)
1574 return err;
1575 } else
1576 master_wep_flag = 0;
1577
1578 if (priv->iw_mode == IW_MODE_MONITOR)
1579 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1580
1581 /* Master WEP setting : on/off */
1582 err = hermes_write_wordrec(hw, USER_BAP,
1583 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1584 master_wep_flag);
1585 if (err)
1586 return err;
1587
1588 break;
1589 }
1590
1591 return 0;
1592}
1593
1594static int __orinoco_program_rids(struct net_device *dev)
1595{
1596 struct orinoco_private *priv = netdev_priv(dev);
1597 hermes_t *hw = &priv->hw;
1598 int err;
1599 struct hermes_idstring idbuf;
1600
1601 /* Set the MAC address */
1602 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1603 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1604 if (err) {
1605 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1606 dev->name, err);
1607 return err;
1608 }
1609
1610 /* Set up the link mode */
1611 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1612 priv->port_type);
1613 if (err) {
1614 printk(KERN_ERR "%s: Error %d setting port type\n",
1615 dev->name, err);
1616 return err;
1617 }
1618 /* Set the channel/frequency */
1619 if (priv->channel == 0) {
1620 printk(KERN_DEBUG "%s: Channel is 0 in __orinoco_program_rids()\n", dev->name);
1621 if (priv->createibss)
1622 priv->channel = 10;
1623 }
1624 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL,
1625 priv->channel);
1626 if (err) {
1627 printk(KERN_ERR "%s: Error %d setting channel\n",
1628 dev->name, err);
1629 return err;
1630 }
1631
1632 if (priv->has_ibss) {
1633 u16 createibss;
1634
1635 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1636 printk(KERN_WARNING "%s: This firmware requires an "
1637 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1638 /* With wvlan_cs, in this case, we would crash.
1639 * hopefully, this driver will behave better...
1640 * Jean II */
1641 createibss = 0;
1642 } else {
1643 createibss = priv->createibss;
1644 }
1645
1646 err = hermes_write_wordrec(hw, USER_BAP,
1647 HERMES_RID_CNFCREATEIBSS,
1648 createibss);
1649 if (err) {
1650 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1651 dev->name, err);
1652 return err;
1653 }
1654 }
1655
1656 /* Set the desired ESSID */
1657 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1658 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1659 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1660 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1661 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1662 &idbuf);
1663 if (err) {
1664 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1665 dev->name, err);
1666 return err;
1667 }
1668 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1669 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1670 &idbuf);
1671 if (err) {
1672 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1673 dev->name, err);
1674 return err;
1675 }
1676
1677 /* Set the station name */
1678 idbuf.len = cpu_to_le16(strlen(priv->nick));
1679 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1680 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1681 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1682 &idbuf);
1683 if (err) {
1684 printk(KERN_ERR "%s: Error %d setting nickname\n",
1685 dev->name, err);
1686 return err;
1687 }
1688
1689 /* Set AP density */
1690 if (priv->has_sensitivity) {
1691 err = hermes_write_wordrec(hw, USER_BAP,
1692 HERMES_RID_CNFSYSTEMSCALE,
1693 priv->ap_density);
1694 if (err) {
1695 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1696 "Disabling sensitivity control\n",
1697 dev->name, err);
1698
1699 priv->has_sensitivity = 0;
1700 }
1701 }
1702
1703 /* Set RTS threshold */
1704 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1705 priv->rts_thresh);
1706 if (err) {
1707 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1708 dev->name, err);
1709 return err;
1710 }
1711
1712 /* Set fragmentation threshold or MWO robustness */
1713 if (priv->has_mwo)
1714 err = hermes_write_wordrec(hw, USER_BAP,
1715 HERMES_RID_CNFMWOROBUST_AGERE,
1716 priv->mwo_robust);
1717 else
1718 err = hermes_write_wordrec(hw, USER_BAP,
1719 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1720 priv->frag_thresh);
1721 if (err) {
1722 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1723 dev->name, err);
1724 return err;
1725 }
1726
1727 /* Set bitrate */
1728 err = __orinoco_hw_set_bitrate(priv);
1729 if (err) {
1730 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1731 dev->name, err);
1732 return err;
1733 }
1734
1735 /* Set power management */
1736 if (priv->has_pm) {
1737 err = hermes_write_wordrec(hw, USER_BAP,
1738 HERMES_RID_CNFPMENABLED,
1739 priv->pm_on);
1740 if (err) {
1741 printk(KERN_ERR "%s: Error %d setting up PM\n",
1742 dev->name, err);
1743 return err;
1744 }
1745
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFMULTICASTRECEIVE,
1748 priv->pm_mcast);
1749 if (err) {
1750 printk(KERN_ERR "%s: Error %d setting up PM\n",
1751 dev->name, err);
1752 return err;
1753 }
1754 err = hermes_write_wordrec(hw, USER_BAP,
1755 HERMES_RID_CNFMAXSLEEPDURATION,
1756 priv->pm_period);
1757 if (err) {
1758 printk(KERN_ERR "%s: Error %d setting up PM\n",
1759 dev->name, err);
1760 return err;
1761 }
1762 err = hermes_write_wordrec(hw, USER_BAP,
1763 HERMES_RID_CNFPMHOLDOVERDURATION,
1764 priv->pm_timeout);
1765 if (err) {
1766 printk(KERN_ERR "%s: Error %d setting up PM\n",
1767 dev->name, err);
1768 return err;
1769 }
1770 }
1771
1772 /* Set preamble - only for Symbol so far... */
1773 if (priv->has_preamble) {
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFPREAMBLE_SYMBOL,
1776 priv->preamble);
1777 if (err) {
1778 printk(KERN_ERR "%s: Error %d setting preamble\n",
1779 dev->name, err);
1780 return err;
1781 }
1782 }
1783
1784 /* Set up encryption */
1785 if (priv->has_wep) {
1786 err = __orinoco_hw_setup_wep(priv);
1787 if (err) {
1788 printk(KERN_ERR "%s: Error %d activating WEP\n",
1789 dev->name, err);
1790 return err;
1791 }
1792 }
1793
1794 /* Set promiscuity / multicast*/
1795 priv->promiscuous = 0;
1796 priv->mc_count = 0;
1797 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1798
1799 return 0;
1800}
1801
1802/* FIXME: return int? */
1803static void
1804__orinoco_set_multicast_list(struct net_device *dev)
1805{
1806 struct orinoco_private *priv = netdev_priv(dev);
1807 hermes_t *hw = &priv->hw;
1808 int err = 0;
1809 int promisc, mc_count;
1810
1811 /* The Hermes doesn't seem to have an allmulti mode, so we go
1812 * into promiscuous mode and let the upper levels deal. */
1813 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1814 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1815 promisc = 1;
1816 mc_count = 0;
1817 } else {
1818 promisc = 0;
1819 mc_count = dev->mc_count;
1820 }
1821
1822 if (promisc != priv->promiscuous) {
1823 err = hermes_write_wordrec(hw, USER_BAP,
1824 HERMES_RID_CNFPROMISCUOUSMODE,
1825 promisc);
1826 if (err) {
1827 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1828 dev->name, err);
1829 } else
1830 priv->promiscuous = promisc;
1831 }
1832
1833 if (! promisc && (mc_count || priv->mc_count) ) {
1834 struct dev_mc_list *p = dev->mc_list;
1835 struct hermes_multicast mclist;
1836 int i;
1837
1838 for (i = 0; i < mc_count; i++) {
1839 /* paranoia: is list shorter than mc_count? */
1840 BUG_ON(! p);
1841 /* paranoia: bad address size in list? */
1842 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1843
1844 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1845 p = p->next;
1846 }
1847
1848 if (p)
1849 printk(KERN_WARNING "%s: Multicast list is "
1850 "longer than mc_count\n", dev->name);
1851
1852 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1853 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1854 &mclist);
1855 if (err)
1856 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1857 dev->name, err);
1858 else
1859 priv->mc_count = mc_count;
1860 }
1861
1862 /* Since we can set the promiscuous flag when it wasn't asked
1863 for, make sure the net_device knows about it. */
1864 if (priv->promiscuous)
1865 dev->flags |= IFF_PROMISC;
1866 else
1867 dev->flags &= ~IFF_PROMISC;
1868}
1869
1870static int orinoco_reconfigure(struct net_device *dev)
1871{
1872 struct orinoco_private *priv = netdev_priv(dev);
1873 struct hermes *hw = &priv->hw;
1874 unsigned long flags;
1875 int err = 0;
1876
1877 if (priv->broken_disableport) {
1878 schedule_work(&priv->reset_work);
1879 return 0;
1880 }
1881
1882 if (orinoco_lock(priv, &flags) != 0)
1883 return -EBUSY;
1884
1885 err = hermes_disable_port(hw, 0);
1886 if (err) {
1887 printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
1888 dev->name);
1889 priv->broken_disableport = 1;
1890 goto out;
1891 }
1892
1893 err = __orinoco_program_rids(dev);
1894 if (err) {
1895 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
1896 dev->name);
1897 goto out;
1898 }
1899
1900 err = hermes_enable_port(hw, 0);
1901 if (err) {
1902 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
1903 dev->name);
1904 goto out;
1905 }
1906
1907 out:
1908 if (err) {
1909 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1910 schedule_work(&priv->reset_work);
1911 err = 0;
1912 }
1913
1914 orinoco_unlock(priv, &flags);
1915 return err;
1916
1917}
1918
1919/* This must be called from user context, without locks held - use
1920 * schedule_work() */
1921static void orinoco_reset(struct net_device *dev)
1922{
1923 struct orinoco_private *priv = netdev_priv(dev);
1924 struct hermes *hw = &priv->hw;
1925 int err = 0;
1926 unsigned long flags;
1927
1928 if (orinoco_lock(priv, &flags) != 0)
1929 /* When the hardware becomes available again, whatever
1930 * detects that is responsible for re-initializing
1931 * it. So no need for anything further */
1932 return;
1933
1934 netif_stop_queue(dev);
1935
1936 /* Shut off interrupts. Depending on what state the hardware
1937 * is in, this might not work, but we'll try anyway */
1938 hermes_set_irqmask(hw, 0);
1939 hermes_write_regn(hw, EVACK, 0xffff);
1940
1941 priv->hw_unavailable++;
1942 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1943 netif_carrier_off(dev);
1944
1945 orinoco_unlock(priv, &flags);
1946
1947 if (priv->hard_reset)
1948 err = (*priv->hard_reset)(priv);
1949 if (err) {
1950 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1951 "performing hard reset\n", dev->name, err);
1952 /* FIXME: shutdown of some sort */
1953 return;
1954 }
1955
1956 err = orinoco_reinit_firmware(dev);
1957 if (err) {
1958 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1959 dev->name, err);
1960 return;
1961 }
1962
1963 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1964
1965 priv->hw_unavailable--;
1966
1967 /* priv->open or priv->hw_unavailable might have changed while
1968 * we dropped the lock */
1969 if (priv->open && (! priv->hw_unavailable)) {
1970 err = __orinoco_up(dev);
1971 if (err) {
1972 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1973 dev->name, err);
1974 } else
1975 dev->trans_start = jiffies;
1976 }
1977
1978 spin_unlock_irq(&priv->lock);
1979
1980 return;
1981}
1982
1983/********************************************************************/
1984/* Interrupt handler */
1985/********************************************************************/
1986
1987static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1988{
1989 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1990}
1991
1992static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1993{
1994 /* This seems to happen a fair bit under load, but ignoring it
1995 seems to work fine...*/
1996 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1997 dev->name);
1998}
1999
2000irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2001{
2002 struct net_device *dev = (struct net_device *)dev_id;
2003 struct orinoco_private *priv = netdev_priv(dev);
2004 hermes_t *hw = &priv->hw;
2005 int count = MAX_IRQLOOPS_PER_IRQ;
2006 u16 evstat, events;
2007 /* These are used to detect a runaway interrupt situation */
2008 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2009 * we panic and shut down the hardware */
2010 static int last_irq_jiffy = 0; /* jiffies value the last time
2011 * we were called */
2012 static int loops_this_jiffy = 0;
2013 unsigned long flags;
2014
2015 if (orinoco_lock(priv, &flags) != 0) {
2016 /* If hw is unavailable - we don't know if the irq was
2017 * for us or not */
2018 return IRQ_HANDLED;
2019 }
2020
2021 evstat = hermes_read_regn(hw, EVSTAT);
2022 events = evstat & hw->inten;
2023 if (! events) {
2024 orinoco_unlock(priv, &flags);
2025 return IRQ_NONE;
2026 }
2027
2028 if (jiffies != last_irq_jiffy)
2029 loops_this_jiffy = 0;
2030 last_irq_jiffy = jiffies;
2031
2032 while (events && count--) {
2033 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2034 printk(KERN_WARNING "%s: IRQ handler is looping too "
2035 "much! Resetting.\n", dev->name);
2036 /* Disable interrupts for now */
2037 hermes_set_irqmask(hw, 0);
2038 schedule_work(&priv->reset_work);
2039 break;
2040 }
2041
2042 /* Check the card hasn't been removed */
2043 if (! hermes_present(hw)) {
2044 DEBUG(0, "orinoco_interrupt(): card removed\n");
2045 break;
2046 }
2047
2048 if (events & HERMES_EV_TICK)
2049 __orinoco_ev_tick(dev, hw);
2050 if (events & HERMES_EV_WTERR)
2051 __orinoco_ev_wterr(dev, hw);
2052 if (events & HERMES_EV_INFDROP)
2053 __orinoco_ev_infdrop(dev, hw);
2054 if (events & HERMES_EV_INFO)
2055 __orinoco_ev_info(dev, hw);
2056 if (events & HERMES_EV_RX)
2057 __orinoco_ev_rx(dev, hw);
2058 if (events & HERMES_EV_TXEXC)
2059 __orinoco_ev_txexc(dev, hw);
2060 if (events & HERMES_EV_TX)
2061 __orinoco_ev_tx(dev, hw);
2062 if (events & HERMES_EV_ALLOC)
2063 __orinoco_ev_alloc(dev, hw);
2064
2065 hermes_write_regn(hw, EVACK, events);
2066
2067 evstat = hermes_read_regn(hw, EVSTAT);
2068 events = evstat & hw->inten;
2069 };
2070
2071 orinoco_unlock(priv, &flags);
2072 return IRQ_HANDLED;
2073}
2074
2075/********************************************************************/
2076/* Initialization */
2077/********************************************************************/
2078
2079struct comp_id {
2080 u16 id, variant, major, minor;
2081} __attribute__ ((packed));
2082
2083static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2084{
2085 if (nic_id->id < 0x8000)
2086 return FIRMWARE_TYPE_AGERE;
2087 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2088 return FIRMWARE_TYPE_SYMBOL;
2089 else
2090 return FIRMWARE_TYPE_INTERSIL;
2091}
2092
2093/* Set priv->firmware type, determine firmware properties */
2094static int determine_firmware(struct net_device *dev)
2095{
2096 struct orinoco_private *priv = netdev_priv(dev);
2097 hermes_t *hw = &priv->hw;
2098 int err;
2099 struct comp_id nic_id, sta_id;
2100 unsigned int firmver;
2101 char tmp[SYMBOL_MAX_VER_LEN+1];
2102
2103 /* Get the hardware version */
2104 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2105 if (err) {
2106 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2107 dev->name, err);
2108 return err;
2109 }
2110
2111 le16_to_cpus(&nic_id.id);
2112 le16_to_cpus(&nic_id.variant);
2113 le16_to_cpus(&nic_id.major);
2114 le16_to_cpus(&nic_id.minor);
2115 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2116 dev->name, nic_id.id, nic_id.variant,
2117 nic_id.major, nic_id.minor);
2118
2119 priv->firmware_type = determine_firmware_type(&nic_id);
2120
2121 /* Get the firmware version */
2122 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2123 if (err) {
2124 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2125 dev->name, err);
2126 return err;
2127 }
2128
2129 le16_to_cpus(&sta_id.id);
2130 le16_to_cpus(&sta_id.variant);
2131 le16_to_cpus(&sta_id.major);
2132 le16_to_cpus(&sta_id.minor);
2133 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2134 dev->name, sta_id.id, sta_id.variant,
2135 sta_id.major, sta_id.minor);
2136
2137 switch (sta_id.id) {
2138 case 0x15:
2139 printk(KERN_ERR "%s: Primary firmware is active\n",
2140 dev->name);
2141 return -ENODEV;
2142 case 0x14b:
2143 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2144 dev->name);
2145 return -ENODEV;
2146 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2147 case 0x21: /* Symbol Spectrum24 Trilogy */
2148 break;
2149 default:
2150 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2151 dev->name);
2152 break;
2153 }
2154
2155 /* Default capabilities */
2156 priv->has_sensitivity = 1;
2157 priv->has_mwo = 0;
2158 priv->has_preamble = 0;
2159 priv->has_port3 = 1;
2160 priv->has_ibss = 1;
2161 priv->has_wep = 0;
2162 priv->has_big_wep = 0;
2163
2164 /* Determine capabilities from the firmware version */
2165 switch (priv->firmware_type) {
2166 case FIRMWARE_TYPE_AGERE:
2167 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2168 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2169 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2170 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2171
2172 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2173
2174 priv->has_ibss = (firmver >= 0x60006);
2175 priv->has_wep = (firmver >= 0x40020);
2176 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2177 Gold cards from the others? */
2178 priv->has_mwo = (firmver >= 0x60000);
2179 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2180 priv->ibss_port = 1;
2181
2182 /* Tested with Agere firmware :
2183 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2184 * Tested CableTron firmware : 4.32 => Anton */
2185 break;
2186 case FIRMWARE_TYPE_SYMBOL:
2187 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2188 /* Intel MAC : 00:02:B3:* */
2189 /* 3Com MAC : 00:50:DA:* */
2190 memset(tmp, 0, sizeof(tmp));
2191 /* Get the Symbol firmware version */
2192 err = hermes_read_ltv(hw, USER_BAP,
2193 HERMES_RID_SECONDARYVERSION_SYMBOL,
2194 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2195 if (err) {
2196 printk(KERN_WARNING
2197 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2198 dev->name, err);
2199 firmver = 0;
2200 tmp[0] = '\0';
2201 } else {
2202 /* The firmware revision is a string, the format is
2203 * something like : "V2.20-01".
2204 * Quick and dirty parsing... - Jean II
2205 */
2206 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2207 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2208 | (tmp[7] - '0');
2209
2210 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2211 }
2212
2213 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2214 "Symbol %s", tmp);
2215
2216 priv->has_ibss = (firmver >= 0x20000);
2217 priv->has_wep = (firmver >= 0x15012);
2218 priv->has_big_wep = (firmver >= 0x20000);
2219 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2220 (firmver >= 0x29000 && firmver < 0x30000) ||
2221 firmver >= 0x31000;
2222 priv->has_preamble = (firmver >= 0x20000);
2223 priv->ibss_port = 4;
2224 /* Tested with Intel firmware : 0x20015 => Jean II */
2225 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2226 break;
2227 case FIRMWARE_TYPE_INTERSIL:
2228 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2229 * Samsung, Compaq 100/200 and Proxim are slightly
2230 * different and less well tested */
2231 /* D-Link MAC : 00:40:05:* */
2232 /* Addtron MAC : 00:90:D1:* */
2233 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2234 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2235 sta_id.variant);
2236
2237 firmver = ((unsigned long)sta_id.major << 16) |
2238 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2239
2240 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2241 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2242 priv->has_pm = (firmver >= 0x000700);
2243
2244 if (firmver >= 0x000800)
2245 priv->ibss_port = 0;
2246 else {
2247 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2248 "than v0.8.x - several features not supported\n",
2249 dev->name);
2250 priv->ibss_port = 1;
2251 }
2252 break;
2253 }
2254 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2255 priv->fw_name);
2256
2257 return 0;
2258}
2259
2260static int orinoco_init(struct net_device *dev)
2261{
2262 struct orinoco_private *priv = netdev_priv(dev);
2263 hermes_t *hw = &priv->hw;
2264 int err = 0;
2265 struct hermes_idstring nickbuf;
2266 u16 reclen;
2267 int len;
2268
2269 TRACE_ENTER(dev->name);
2270
2271 /* No need to lock, the hw_unavailable flag is already set in
2272 * alloc_orinocodev() */
2273 priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
2274
2275 /* Initialize the firmware */
2276 err = hermes_init(hw);
2277 if (err != 0) {
2278 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2279 dev->name, err);
2280 goto out;
2281 }
2282
2283 err = determine_firmware(dev);
2284 if (err != 0) {
2285 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2286 dev->name);
2287 goto out;
2288 }
2289
2290 if (priv->has_port3)
2291 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2292 if (priv->has_ibss)
2293 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2294 dev->name);
2295 if (priv->has_wep) {
2296 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2297 if (priv->has_big_wep)
2298 printk("104-bit key\n");
2299 else
2300 printk("40-bit key\n");
2301 }
2302
2303 /* Get the MAC address */
2304 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2305 ETH_ALEN, NULL, dev->dev_addr);
2306 if (err) {
2307 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2308 dev->name);
2309 goto out;
2310 }
2311
2312 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2313 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2314 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2315 dev->dev_addr[5]);
2316
2317 /* Get the station name */
2318 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2319 sizeof(nickbuf), &reclen, &nickbuf);
2320 if (err) {
2321 printk(KERN_ERR "%s: failed to read station name\n",
2322 dev->name);
2323 goto out;
2324 }
2325 if (nickbuf.len)
2326 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2327 else
2328 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2329 memcpy(priv->nick, &nickbuf.val, len);
2330 priv->nick[len] = '\0';
2331
2332 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2333
2334 /* Get allowed channels */
2335 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2336 &priv->channel_mask);
2337 if (err) {
2338 printk(KERN_ERR "%s: failed to read channel list!\n",
2339 dev->name);
2340 goto out;
2341 }
2342
2343 /* Get initial AP density */
2344 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2345 &priv->ap_density);
2346 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2347 priv->has_sensitivity = 0;
2348 }
2349
2350 /* Get initial RTS threshold */
2351 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2352 &priv->rts_thresh);
2353 if (err) {
2354 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2355 dev->name);
2356 goto out;
2357 }
2358
2359 /* Get initial fragmentation settings */
2360 if (priv->has_mwo)
2361 err = hermes_read_wordrec(hw, USER_BAP,
2362 HERMES_RID_CNFMWOROBUST_AGERE,
2363 &priv->mwo_robust);
2364 else
2365 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2366 &priv->frag_thresh);
2367 if (err) {
2368 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2369 dev->name);
2370 goto out;
2371 }
2372
2373 /* Power management setup */
2374 if (priv->has_pm) {
2375 priv->pm_on = 0;
2376 priv->pm_mcast = 1;
2377 err = hermes_read_wordrec(hw, USER_BAP,
2378 HERMES_RID_CNFMAXSLEEPDURATION,
2379 &priv->pm_period);
2380 if (err) {
2381 printk(KERN_ERR "%s: failed to read power management period!\n",
2382 dev->name);
2383 goto out;
2384 }
2385 err = hermes_read_wordrec(hw, USER_BAP,
2386 HERMES_RID_CNFPMHOLDOVERDURATION,
2387 &priv->pm_timeout);
2388 if (err) {
2389 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2390 dev->name);
2391 goto out;
2392 }
2393 }
2394
2395 /* Preamble setup */
2396 if (priv->has_preamble) {
2397 err = hermes_read_wordrec(hw, USER_BAP,
2398 HERMES_RID_CNFPREAMBLE_SYMBOL,
2399 &priv->preamble);
2400 if (err)
2401 goto out;
2402 }
2403
2404 /* Set up the default configuration */
2405 priv->iw_mode = IW_MODE_INFRA;
2406 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2407 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2408 set_port_type(priv);
2409 priv->channel = 10; /* default channel, more-or-less arbitrary */
2410
2411 priv->promiscuous = 0;
2412 priv->wep_on = 0;
2413 priv->tx_key = 0;
2414
2415 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2416 if (err == -EIO) {
2417 /* Try workaround for old Symbol firmware bug */
2418 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2419 "(old Symbol firmware?). Trying to work around... ",
2420 dev->name);
2421
2422 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2423 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2424 if (err)
2425 printk("failed!\n");
2426 else
2427 printk("ok.\n");
2428 }
2429 if (err) {
2430 printk("%s: Error %d allocating Tx buffer\n", dev->name, err);
2431 goto out;
2432 }
2433
2434 /* Make the hardware available, as long as it hasn't been
2435 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2436 spin_lock_irq(&priv->lock);
2437 priv->hw_unavailable--;
2438 spin_unlock_irq(&priv->lock);
2439
2440 printk(KERN_DEBUG "%s: ready\n", dev->name);
2441
2442 out:
2443 TRACE_EXIT(dev->name);
2444 return err;
2445}
2446
2447struct net_device *alloc_orinocodev(int sizeof_card,
2448 int (*hard_reset)(struct orinoco_private *))
2449{
2450 struct net_device *dev;
2451 struct orinoco_private *priv;
2452
2453 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2454 if (! dev)
2455 return NULL;
2456 priv = netdev_priv(dev);
2457 priv->ndev = dev;
2458 if (sizeof_card)
2459 priv->card = (void *)((unsigned long)netdev_priv(dev)
2460 + sizeof(struct orinoco_private));
2461 else
2462 priv->card = NULL;
2463
2464 /* Setup / override net_device fields */
2465 dev->init = orinoco_init;
2466 dev->hard_start_xmit = orinoco_xmit;
2467 dev->tx_timeout = orinoco_tx_timeout;
2468 dev->watchdog_timeo = HZ; /* 1 second timeout */
2469 dev->get_stats = orinoco_get_stats;
2470 dev->get_wireless_stats = orinoco_get_wireless_stats;
2471 dev->do_ioctl = orinoco_ioctl;
2472 dev->change_mtu = orinoco_change_mtu;
2473 dev->set_multicast_list = orinoco_set_multicast_list;
2474 /* we use the default eth_mac_addr for setting the MAC addr */
2475
2476 /* Set up default callbacks */
2477 dev->open = orinoco_open;
2478 dev->stop = orinoco_stop;
2479 priv->hard_reset = hard_reset;
2480
2481 spin_lock_init(&priv->lock);
2482 priv->open = 0;
2483 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2484 * before anything else touches the
2485 * hardware */
2486 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2487
2488 netif_carrier_off(dev);
2489 priv->last_linkstatus = 0xffff;
2490
2491 return dev;
2492
2493}
2494
2495void free_orinocodev(struct net_device *dev)
2496{
2497 free_netdev(dev);
2498}
2499
2500/********************************************************************/
2501/* Wireless extensions */
2502/********************************************************************/
2503
2504static int orinoco_hw_get_bssid(struct orinoco_private *priv,
2505 char buf[ETH_ALEN])
2506{
2507 hermes_t *hw = &priv->hw;
2508 int err = 0;
2509 unsigned long flags;
2510
2511 if (orinoco_lock(priv, &flags) != 0)
2512 return -EBUSY;
2513
2514 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2515 ETH_ALEN, NULL, buf);
2516
2517 orinoco_unlock(priv, &flags);
2518
2519 return err;
2520}
2521
2522static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2523 char buf[IW_ESSID_MAX_SIZE+1])
2524{
2525 hermes_t *hw = &priv->hw;
2526 int err = 0;
2527 struct hermes_idstring essidbuf;
2528 char *p = (char *)(&essidbuf.val);
2529 int len;
2530 unsigned long flags;
2531
2532 if (orinoco_lock(priv, &flags) != 0)
2533 return -EBUSY;
2534
2535 if (strlen(priv->desired_essid) > 0) {
2536 /* We read the desired SSID from the hardware rather
2537 than from priv->desired_essid, just in case the
2538 firmware is allowed to change it on us. I'm not
2539 sure about this */
2540 /* My guess is that the OWNSSID should always be whatever
2541 * we set to the card, whereas CURRENT_SSID is the one that
2542 * may change... - Jean II */
2543 u16 rid;
2544
2545 *active = 1;
2546
2547 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2548 HERMES_RID_CNFDESIREDSSID;
2549
2550 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2551 NULL, &essidbuf);
2552 if (err)
2553 goto fail_unlock;
2554 } else {
2555 *active = 0;
2556
2557 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2558 sizeof(essidbuf), NULL, &essidbuf);
2559 if (err)
2560 goto fail_unlock;
2561 }
2562
2563 len = le16_to_cpu(essidbuf.len);
2564
2565 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2566 memcpy(buf, p, len);
2567 buf[len] = '\0';
2568
2569 fail_unlock:
2570 orinoco_unlock(priv, &flags);
2571
2572 return err;
2573}
2574
2575static long orinoco_hw_get_freq(struct orinoco_private *priv)
2576{
2577
2578 hermes_t *hw = &priv->hw;
2579 int err = 0;
2580 u16 channel;
2581 long freq = 0;
2582 unsigned long flags;
2583
2584 if (orinoco_lock(priv, &flags) != 0)
2585 return -EBUSY;
2586
2587 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2588 if (err)
2589 goto out;
2590
2591 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2592 if (channel == 0) {
2593 err = -EBUSY;
2594 goto out;
2595 }
2596
2597 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2598 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2599 priv->ndev->name, channel);
2600 err = -EBUSY;
2601 goto out;
2602
2603 }
2604 freq = channel_frequency[channel-1] * 100000;
2605
2606 out:
2607 orinoco_unlock(priv, &flags);
2608
2609 if (err > 0)
2610 err = -EBUSY;
2611 return err ? err : freq;
2612}
2613
2614static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2615 int *numrates, s32 *rates, int max)
2616{
2617 hermes_t *hw = &priv->hw;
2618 struct hermes_idstring list;
2619 unsigned char *p = (unsigned char *)&list.val;
2620 int err = 0;
2621 int num;
2622 int i;
2623 unsigned long flags;
2624
2625 if (orinoco_lock(priv, &flags) != 0)
2626 return -EBUSY;
2627
2628 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2629 sizeof(list), NULL, &list);
2630 orinoco_unlock(priv, &flags);
2631
2632 if (err)
2633 return err;
2634
2635 num = le16_to_cpu(list.len);
2636 *numrates = num;
2637 num = min(num, max);
2638
2639 for (i = 0; i < num; i++) {
2640 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2641 }
2642
2643 return 0;
2644}
2645
2646static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
2647{
2648 struct orinoco_private *priv = netdev_priv(dev);
2649 int err = 0;
2650 int mode;
2651 struct iw_range range;
2652 int numrates;
2653 int i, k;
2654 unsigned long flags;
2655
2656 TRACE_ENTER(dev->name);
2657
2658 if (!access_ok(VERIFY_WRITE, rrq->pointer, sizeof(range)))
2659 return -EFAULT;
2660
2661 rrq->length = sizeof(range);
2662
2663 if (orinoco_lock(priv, &flags) != 0)
2664 return -EBUSY;
2665
2666 mode = priv->iw_mode;
2667 orinoco_unlock(priv, &flags);
2668
2669 memset(&range, 0, sizeof(range));
2670
2671 /* Much of this shamelessly taken from wvlan_cs.c. No idea
2672 * what it all means -dgibson */
2673 range.we_version_compiled = WIRELESS_EXT;
2674 range.we_version_source = 11;
2675
2676 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
2677
2678 /* Set available channels/frequencies */
2679 range.num_channels = NUM_CHANNELS;
2680 k = 0;
2681 for (i = 0; i < NUM_CHANNELS; i++) {
2682 if (priv->channel_mask & (1 << i)) {
2683 range.freq[k].i = i + 1;
2684 range.freq[k].m = channel_frequency[i] * 100000;
2685 range.freq[k].e = 1;
2686 k++;
2687 }
2688
2689 if (k >= IW_MAX_FREQUENCIES)
2690 break;
2691 }
2692 range.num_frequency = k;
2693
2694 range.sensitivity = 3;
2695
2696 if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2697 /* Quality stats meaningless in ad-hoc mode */
2698 range.max_qual.qual = 0;
2699 range.max_qual.level = 0;
2700 range.max_qual.noise = 0;
2701 range.avg_qual.qual = 0;
2702 range.avg_qual.level = 0;
2703 range.avg_qual.noise = 0;
2704 } else {
2705 range.max_qual.qual = 0x8b - 0x2f;
2706 range.max_qual.level = 0x2f - 0x95 - 1;
2707 range.max_qual.noise = 0x2f - 0x95 - 1;
2708 /* Need to get better values */
2709 range.avg_qual.qual = 0x24;
2710 range.avg_qual.level = 0xC2;
2711 range.avg_qual.noise = 0x9E;
2712 }
2713
2714 err = orinoco_hw_get_bitratelist(priv, &numrates,
2715 range.bitrate, IW_MAX_BITRATES);
2716 if (err)
2717 return err;
2718 range.num_bitrates = numrates;
2719
2720 /* Set an indication of the max TCP throughput in bit/s that we can
2721 * expect using this interface. May be use for QoS stuff...
2722 * Jean II */
2723 if(numrates > 2)
2724 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2725 else
2726 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2727
2728 range.min_rts = 0;
2729 range.max_rts = 2347;
2730 range.min_frag = 256;
2731 range.max_frag = 2346;
2732
2733 if (orinoco_lock(priv, &flags) != 0)
2734 return -EBUSY;
2735 if (priv->has_wep) {
2736 range.max_encoding_tokens = ORINOCO_MAX_KEYS;
2737
2738 range.encoding_size[0] = SMALL_KEY_SIZE;
2739 range.num_encoding_sizes = 1;
2740
2741 if (priv->has_big_wep) {
2742 range.encoding_size[1] = LARGE_KEY_SIZE;
2743 range.num_encoding_sizes = 2;
2744 }
2745 } else {
2746 range.num_encoding_sizes = 0;
2747 range.max_encoding_tokens = 0;
2748 }
2749 orinoco_unlock(priv, &flags);
2750
2751 range.min_pmp = 0;
2752 range.max_pmp = 65535000;
2753 range.min_pmt = 0;
2754 range.max_pmt = 65535 * 1000; /* ??? */
2755 range.pmp_flags = IW_POWER_PERIOD;
2756 range.pmt_flags = IW_POWER_TIMEOUT;
2757 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2758
2759 range.num_txpower = 1;
2760 range.txpower[0] = 15; /* 15dBm */
2761 range.txpower_capa = IW_TXPOW_DBM;
2762
2763 range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2764 range.retry_flags = IW_RETRY_LIMIT;
2765 range.r_time_flags = IW_RETRY_LIFETIME;
2766 range.min_retry = 0;
2767 range.max_retry = 65535; /* ??? */
2768 range.min_r_time = 0;
2769 range.max_r_time = 65535 * 1000; /* ??? */
2770
2771 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
2772 return -EFAULT;
2773
2774 TRACE_EXIT(dev->name);
2775
2776 return 0;
2777}
2778
2779static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
2780{
2781 struct orinoco_private *priv = netdev_priv(dev);
2782 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2783 int setindex = priv->tx_key;
2784 int enable = priv->wep_on;
2785 int restricted = priv->wep_restrict;
2786 u16 xlen = 0;
2787 int err = 0;
2788 char keybuf[ORINOCO_MAX_KEY_SIZE];
2789 unsigned long flags;
2790
2791 if (! priv->has_wep)
2792 return -EOPNOTSUPP;
2793
2794 if (erq->pointer) {
2795 /* We actually have a key to set - check its length */
2796 if (erq->length > LARGE_KEY_SIZE)
2797 return -E2BIG;
2798
2799 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2800 return -E2BIG;
2801
2802 if (copy_from_user(keybuf, erq->pointer, erq->length))
2803 return -EFAULT;
2804 }
2805
2806 if (orinoco_lock(priv, &flags) != 0)
2807 return -EBUSY;
2808
2809 if (erq->pointer) {
2810 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2811 index = priv->tx_key;
2812
2813 /* Adjust key length to a supported value */
2814 if (erq->length > SMALL_KEY_SIZE) {
2815 xlen = LARGE_KEY_SIZE;
2816 } else if (erq->length > 0) {
2817 xlen = SMALL_KEY_SIZE;
2818 } else
2819 xlen = 0;
2820
2821 /* Switch on WEP if off */
2822 if ((!enable) && (xlen > 0)) {
2823 setindex = index;
2824 enable = 1;
2825 }
2826 } else {
2827 /* Important note : if the user do "iwconfig eth0 enc off",
2828 * we will arrive there with an index of -1. This is valid
2829 * but need to be taken care off... Jean II */
2830 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2831 if((index != -1) || (erq->flags == 0)) {
2832 err = -EINVAL;
2833 goto out;
2834 }
2835 } else {
2836 /* Set the index : Check that the key is valid */
2837 if(priv->keys[index].len == 0) {
2838 err = -EINVAL;
2839 goto out;
2840 }
2841 setindex = index;
2842 }
2843 }
2844
2845 if (erq->flags & IW_ENCODE_DISABLED)
2846 enable = 0;
2847 if (erq->flags & IW_ENCODE_OPEN)
2848 restricted = 0;
2849 if (erq->flags & IW_ENCODE_RESTRICTED)
2850 restricted = 1;
2851
2852 if (erq->pointer) {
2853 priv->keys[index].len = cpu_to_le16(xlen);
2854 memset(priv->keys[index].data, 0,
2855 sizeof(priv->keys[index].data));
2856 memcpy(priv->keys[index].data, keybuf, erq->length);
2857 }
2858 priv->tx_key = setindex;
2859
2860 /* Try fast key change if connected and only keys are changed */
2861 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2862 netif_carrier_ok(dev)) {
2863 err = __orinoco_hw_setup_wepkeys(priv);
2864 /* No need to commit if successful */
2865 goto out;
2866 }
2867
2868 priv->wep_on = enable;
2869 priv->wep_restrict = restricted;
2870
2871 out:
2872 orinoco_unlock(priv, &flags);
2873
2874 return err;
2875}
2876
2877static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
2878{
2879 struct orinoco_private *priv = netdev_priv(dev);
2880 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2881 u16 xlen = 0;
2882 char keybuf[ORINOCO_MAX_KEY_SIZE];
2883 unsigned long flags;
2884
2885 if (! priv->has_wep)
2886 return -EOPNOTSUPP;
2887
2888 if (orinoco_lock(priv, &flags) != 0)
2889 return -EBUSY;
2890
2891 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2892 index = priv->tx_key;
2893
2894 erq->flags = 0;
2895 if (! priv->wep_on)
2896 erq->flags |= IW_ENCODE_DISABLED;
2897 erq->flags |= index + 1;
2898
2899 if (priv->wep_restrict)
2900 erq->flags |= IW_ENCODE_RESTRICTED;
2901 else
2902 erq->flags |= IW_ENCODE_OPEN;
2903
2904 xlen = le16_to_cpu(priv->keys[index].len);
2905
2906 erq->length = xlen;
2907
2908 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2909
2910 orinoco_unlock(priv, &flags);
2911
2912 if (erq->pointer) {
2913 if (copy_to_user(erq->pointer, keybuf, xlen))
2914 return -EFAULT;
2915 }
2916
2917 return 0;
2918}
2919
2920static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
2921{
2922 struct orinoco_private *priv = netdev_priv(dev);
2923 char essidbuf[IW_ESSID_MAX_SIZE+1];
2924 unsigned long flags;
2925
2926 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2927 * anyway... - Jean II */
2928
2929 memset(&essidbuf, 0, sizeof(essidbuf));
2930
2931 if (erq->flags) {
2932 if (erq->length > IW_ESSID_MAX_SIZE)
2933 return -E2BIG;
2934
2935 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2936 return -EFAULT;
2937
2938 essidbuf[erq->length] = '\0';
2939 }
2940
2941 if (orinoco_lock(priv, &flags) != 0)
2942 return -EBUSY;
2943
2944 memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
2945
2946 orinoco_unlock(priv, &flags);
2947
2948 return 0;
2949}
2950
2951static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2952{
2953 struct orinoco_private *priv = netdev_priv(dev);
2954 char essidbuf[IW_ESSID_MAX_SIZE+1];
2955 int active;
2956 int err = 0;
2957 unsigned long flags;
2958
2959 TRACE_ENTER(dev->name);
2960
2961 if (netif_running(dev)) {
2962 err = orinoco_hw_get_essid(priv, &active, essidbuf);
2963 if (err)
2964 return err;
2965 } else {
2966 if (orinoco_lock(priv, &flags) != 0)
2967 return -EBUSY;
2968 memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
2969 orinoco_unlock(priv, &flags);
2970 }
2971
2972 erq->flags = 1;
2973 erq->length = strlen(essidbuf) + 1;
2974 if (erq->pointer)
2975 if (copy_to_user(erq->pointer, essidbuf, erq->length))
2976 return -EFAULT;
2977
2978 TRACE_EXIT(dev->name);
2979
2980 return 0;
2981}
2982
2983static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
2984{
2985 struct orinoco_private *priv = netdev_priv(dev);
2986 char nickbuf[IW_ESSID_MAX_SIZE+1];
2987 unsigned long flags;
2988
2989 if (nrq->length > IW_ESSID_MAX_SIZE)
2990 return -E2BIG;
2991
2992 memset(nickbuf, 0, sizeof(nickbuf));
2993
2994 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2995 return -EFAULT;
2996
2997 nickbuf[nrq->length] = '\0';
2998
2999 if (orinoco_lock(priv, &flags) != 0)
3000 return -EBUSY;
3001
3002 memcpy(priv->nick, nickbuf, sizeof(priv->nick));
3003
3004 orinoco_unlock(priv, &flags);
3005
3006 return 0;
3007}
3008
3009static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
3010{
3011 struct orinoco_private *priv = netdev_priv(dev);
3012 char nickbuf[IW_ESSID_MAX_SIZE+1];
3013 unsigned long flags;
3014
3015 if (orinoco_lock(priv, &flags) != 0)
3016 return -EBUSY;
3017
3018 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3019 orinoco_unlock(priv, &flags);
3020
3021 nrq->length = strlen(nickbuf)+1;
3022
3023 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
3024 return -EFAULT;
3025
3026 return 0;
3027}
3028
3029static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
3030{
3031 struct orinoco_private *priv = netdev_priv(dev);
3032 int chan = -1;
3033 unsigned long flags;
3034
3035 /* We can only use this in Ad-Hoc demo mode to set the operating
3036 * frequency, or in IBSS mode to set the frequency where the IBSS
3037 * will be created - Jean II */
3038 if (priv->iw_mode != IW_MODE_ADHOC)
3039 return -EOPNOTSUPP;
3040
3041 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3042 /* Setting by channel number */
3043 chan = frq->m;
3044 } else {
3045 /* Setting by frequency - search the table */
3046 int mult = 1;
3047 int i;
3048
3049 for (i = 0; i < (6 - frq->e); i++)
3050 mult *= 10;
3051
3052 for (i = 0; i < NUM_CHANNELS; i++)
3053 if (frq->m == (channel_frequency[i] * mult))
3054 chan = i+1;
3055 }
3056
3057 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3058 ! (priv->channel_mask & (1 << (chan-1)) ) )
3059 return -EINVAL;
3060
3061 if (orinoco_lock(priv, &flags) != 0)
3062 return -EBUSY;
3063 priv->channel = chan;
3064 orinoco_unlock(priv, &flags);
3065
3066 return 0;
3067}
3068
3069static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
3070{
3071 struct orinoco_private *priv = netdev_priv(dev);
3072 hermes_t *hw = &priv->hw;
3073 u16 val;
3074 int err;
3075 unsigned long flags;
3076
3077 if (!priv->has_sensitivity)
3078 return -EOPNOTSUPP;
3079
3080 if (orinoco_lock(priv, &flags) != 0)
3081 return -EBUSY;
3082 err = hermes_read_wordrec(hw, USER_BAP,
3083 HERMES_RID_CNFSYSTEMSCALE, &val);
3084 orinoco_unlock(priv, &flags);
3085
3086 if (err)
3087 return err;
3088
3089 srq->value = val;
3090 srq->fixed = 0; /* auto */
3091
3092 return 0;
3093}
3094
3095static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
3096{
3097 struct orinoco_private *priv = netdev_priv(dev);
3098 int val = srq->value;
3099 unsigned long flags;
3100
3101 if (!priv->has_sensitivity)
3102 return -EOPNOTSUPP;
3103
3104 if ((val < 1) || (val > 3))
3105 return -EINVAL;
3106
3107 if (orinoco_lock(priv, &flags) != 0)
3108 return -EBUSY;
3109 priv->ap_density = val;
3110 orinoco_unlock(priv, &flags);
3111
3112 return 0;
3113}
3114
3115static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
3116{
3117 struct orinoco_private *priv = netdev_priv(dev);
3118 int val = rrq->value;
3119 unsigned long flags;
3120
3121 if (rrq->disabled)
3122 val = 2347;
3123
3124 if ( (val < 0) || (val > 2347) )
3125 return -EINVAL;
3126
3127 if (orinoco_lock(priv, &flags) != 0)
3128 return -EBUSY;
3129
3130 priv->rts_thresh = val;
3131 orinoco_unlock(priv, &flags);
3132
3133 return 0;
3134}
3135
3136static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
3137{
3138 struct orinoco_private *priv = netdev_priv(dev);
3139 int err = 0;
3140 unsigned long flags;
3141
3142 if (orinoco_lock(priv, &flags) != 0)
3143 return -EBUSY;
3144
3145 if (priv->has_mwo) {
3146 if (frq->disabled)
3147 priv->mwo_robust = 0;
3148 else {
3149 if (frq->fixed)
3150 printk(KERN_WARNING "%s: Fixed fragmentation is "
3151 "not supported on this firmware. "
3152 "Using MWO robust instead.\n", dev->name);
3153 priv->mwo_robust = 1;
3154 }
3155 } else {
3156 if (frq->disabled)
3157 priv->frag_thresh = 2346;
3158 else {
3159 if ( (frq->value < 256) || (frq->value > 2346) )
3160 err = -EINVAL;
3161 else
3162 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3163 }
3164 }
3165
3166 orinoco_unlock(priv, &flags);
3167
3168 return err;
3169}
3170
3171static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
3172{
3173 struct orinoco_private *priv = netdev_priv(dev);
3174 hermes_t *hw = &priv->hw;
3175 int err = 0;
3176 u16 val;
3177 unsigned long flags;
3178
3179 if (orinoco_lock(priv, &flags) != 0)
3180 return -EBUSY;
3181
3182 if (priv->has_mwo) {
3183 err = hermes_read_wordrec(hw, USER_BAP,
3184 HERMES_RID_CNFMWOROBUST_AGERE,
3185 &val);
3186 if (err)
3187 val = 0;
3188
3189 frq->value = val ? 2347 : 0;
3190 frq->disabled = ! val;
3191 frq->fixed = 0;
3192 } else {
3193 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3194 &val);
3195 if (err)
3196 val = 0;
3197
3198 frq->value = val;
3199 frq->disabled = (val >= 2346);
3200 frq->fixed = 1;
3201 }
3202
3203 orinoco_unlock(priv, &flags);
3204
3205 return err;
3206}
3207
3208static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
3209{
3210 struct orinoco_private *priv = netdev_priv(dev);
3211 int err = 0;
3212 int ratemode = -1;
3213 int bitrate; /* 100s of kilobits */
3214 int i;
3215 unsigned long flags;
3216
3217 /* As the user space doesn't know our highest rate, it uses -1
3218 * to ask us to set the highest rate. Test it using "iwconfig
3219 * ethX rate auto" - Jean II */
3220 if (rrq->value == -1)
3221 bitrate = 110;
3222 else {
3223 if (rrq->value % 100000)
3224 return -EINVAL;
3225 bitrate = rrq->value / 100000;
3226 }
3227
3228 if ( (bitrate != 10) && (bitrate != 20) &&
3229 (bitrate != 55) && (bitrate != 110) )
3230 return -EINVAL;
3231
3232 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3233 if ( (bitrate_table[i].bitrate == bitrate) &&
3234 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3235 ratemode = i;
3236 break;
3237 }
3238
3239 if (ratemode == -1)
3240 return -EINVAL;
3241
3242 if (orinoco_lock(priv, &flags) != 0)
3243 return -EBUSY;
3244 priv->bitratemode = ratemode;
3245 orinoco_unlock(priv, &flags);
3246
3247 return err;
3248}
3249
3250static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
3251{
3252 struct orinoco_private *priv = netdev_priv(dev);
3253 hermes_t *hw = &priv->hw;
3254 int err = 0;
3255 int ratemode;
3256 int i;
3257 u16 val;
3258 unsigned long flags;
3259
3260 if (orinoco_lock(priv, &flags) != 0)
3261 return -EBUSY;
3262
3263 ratemode = priv->bitratemode;
3264
3265 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3266
3267 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3268 rrq->fixed = ! bitrate_table[ratemode].automatic;
3269 rrq->disabled = 0;
3270
3271 /* If the interface is running we try to find more about the
3272 current mode */
3273 if (netif_running(dev)) {
3274 err = hermes_read_wordrec(hw, USER_BAP,
3275 HERMES_RID_CURRENTTXRATE, &val);
3276 if (err)
3277 goto out;
3278
3279 switch (priv->firmware_type) {
3280 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3281 /* Note : in Lucent firmware, the return value of
3282 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3283 * and therefore is totally different from the
3284 * encoding of HERMES_RID_CNFTXRATECONTROL.
3285 * Don't forget that 6Mb/s is really 5.5Mb/s */
3286 if (val == 6)
3287 rrq->value = 5500000;
3288 else
3289 rrq->value = val * 1000000;
3290 break;
3291 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3292 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3293 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3294 if (bitrate_table[i].intersil_txratectrl == val) {
3295 ratemode = i;
3296 break;
3297 }
3298 if (i >= BITRATE_TABLE_SIZE)
3299 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3300 dev->name, val);
3301
3302 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3303 break;
3304 default:
3305 BUG();
3306 }
3307 }
3308
3309 out:
3310 orinoco_unlock(priv, &flags);
3311
3312 return err;
3313}
3314
3315static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
3316{
3317 struct orinoco_private *priv = netdev_priv(dev);
3318 int err = 0;
3319 unsigned long flags;
3320
3321 if (orinoco_lock(priv, &flags) != 0)
3322 return -EBUSY;
3323
3324 if (prq->disabled) {
3325 priv->pm_on = 0;
3326 } else {
3327 switch (prq->flags & IW_POWER_MODE) {
3328 case IW_POWER_UNICAST_R:
3329 priv->pm_mcast = 0;
3330 priv->pm_on = 1;
3331 break;
3332 case IW_POWER_ALL_R:
3333 priv->pm_mcast = 1;
3334 priv->pm_on = 1;
3335 break;
3336 case IW_POWER_ON:
3337 /* No flags : but we may have a value - Jean II */
3338 break;
3339 default:
3340 err = -EINVAL;
3341 }
3342 if (err)
3343 goto out;
3344
3345 if (prq->flags & IW_POWER_TIMEOUT) {
3346 priv->pm_on = 1;
3347 priv->pm_timeout = prq->value / 1000;
3348 }
3349 if (prq->flags & IW_POWER_PERIOD) {
3350 priv->pm_on = 1;
3351 priv->pm_period = prq->value / 1000;
3352 }
3353 /* It's valid to not have a value if we are just toggling
3354 * the flags... Jean II */
3355 if(!priv->pm_on) {
3356 err = -EINVAL;
3357 goto out;
3358 }
3359 }
3360
3361 out:
3362 orinoco_unlock(priv, &flags);
3363
3364 return err;
3365}
3366
3367static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
3368{
3369 struct orinoco_private *priv = netdev_priv(dev);
3370 hermes_t *hw = &priv->hw;
3371 int err = 0;
3372 u16 enable, period, timeout, mcast;
3373 unsigned long flags;
3374
3375 if (orinoco_lock(priv, &flags) != 0)
3376 return -EBUSY;
3377
3378 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3379 if (err)
3380 goto out;
3381
3382 err = hermes_read_wordrec(hw, USER_BAP,
3383 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3384 if (err)
3385 goto out;
3386
3387 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3388 if (err)
3389 goto out;
3390
3391 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3392 if (err)
3393 goto out;
3394
3395 prq->disabled = !enable;
3396 /* Note : by default, display the period */
3397 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3398 prq->flags = IW_POWER_TIMEOUT;
3399 prq->value = timeout * 1000;
3400 } else {
3401 prq->flags = IW_POWER_PERIOD;
3402 prq->value = period * 1000;
3403 }
3404 if (mcast)
3405 prq->flags |= IW_POWER_ALL_R;
3406 else
3407 prq->flags |= IW_POWER_UNICAST_R;
3408
3409 out:
3410 orinoco_unlock(priv, &flags);
3411
3412 return err;
3413}
3414
3415static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
3416{
3417 struct orinoco_private *priv = netdev_priv(dev);
3418 hermes_t *hw = &priv->hw;
3419 int err = 0;
3420 u16 short_limit, long_limit, lifetime;
3421 unsigned long flags;
3422
3423 if (orinoco_lock(priv, &flags) != 0)
3424 return -EBUSY;
3425
3426 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3427 &short_limit);
3428 if (err)
3429 goto out;
3430
3431 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3432 &long_limit);
3433 if (err)
3434 goto out;
3435
3436 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3437 &lifetime);
3438 if (err)
3439 goto out;
3440
3441 rrq->disabled = 0; /* Can't be disabled */
3442
3443 /* Note : by default, display the retry number */
3444 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3445 rrq->flags = IW_RETRY_LIFETIME;
3446 rrq->value = lifetime * 1000; /* ??? */
3447 } else {
3448 /* By default, display the min number */
3449 if ((rrq->flags & IW_RETRY_MAX)) {
3450 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3451 rrq->value = long_limit;
3452 } else {
3453 rrq->flags = IW_RETRY_LIMIT;
3454 rrq->value = short_limit;
3455 if(short_limit != long_limit)
3456 rrq->flags |= IW_RETRY_MIN;
3457 }
3458 }
3459
3460 out:
3461 orinoco_unlock(priv, &flags);
3462
3463 return err;
3464}
3465
3466static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
3467{
3468 struct orinoco_private *priv = netdev_priv(dev);
3469 int val = *( (int *) wrq->u.name );
3470 unsigned long flags;
3471
3472 if (orinoco_lock(priv, &flags) != 0)
3473 return -EBUSY;
3474
3475 priv->ibss_port = val ;
3476
3477 /* Actually update the mode we are using */
3478 set_port_type(priv);
3479
3480 orinoco_unlock(priv, &flags);
3481 return 0;
3482}
3483
3484static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
3485{
3486 struct orinoco_private *priv = netdev_priv(dev);
3487 int *val = (int *)wrq->u.name;
3488 unsigned long flags;
3489
3490 if (orinoco_lock(priv, &flags) != 0)
3491 return -EBUSY;
3492
3493 *val = priv->ibss_port;
3494 orinoco_unlock(priv, &flags);
3495
3496 return 0;
3497}
3498
3499static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
3500{
3501 struct orinoco_private *priv = netdev_priv(dev);
3502 int val = *( (int *) wrq->u.name );
3503 int err = 0;
3504 unsigned long flags;
3505
3506 if (orinoco_lock(priv, &flags) != 0)
3507 return -EBUSY;
3508
3509 switch (val) {
3510 case 0: /* Try to do IEEE ad-hoc mode */
3511 if (! priv->has_ibss) {
3512 err = -EINVAL;
3513 break;
3514 }
3515 priv->prefer_port3 = 0;
3516
3517 break;
3518
3519 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3520 if (! priv->has_port3) {
3521 err = -EINVAL;
3522 break;
3523 }
3524 priv->prefer_port3 = 1;
3525 break;
3526
3527 default:
3528 err = -EINVAL;
3529 }
3530
3531 if (! err)
3532 /* Actually update the mode we are using */
3533 set_port_type(priv);
3534
3535 orinoco_unlock(priv, &flags);
3536
3537 return err;
3538}
3539
3540static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
3541{
3542 struct orinoco_private *priv = netdev_priv(dev);
3543 int *val = (int *)wrq->u.name;
3544 unsigned long flags;
3545
3546 if (orinoco_lock(priv, &flags) != 0)
3547 return -EBUSY;
3548
3549 *val = priv->prefer_port3;
3550 orinoco_unlock(priv, &flags);
3551 return 0;
3552}
3553
3554/* Spy is used for link quality/strength measurements in Ad-Hoc mode
3555 * Jean II */
3556static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
3557{
3558 struct orinoco_private *priv = netdev_priv(dev);
3559 struct sockaddr address[IW_MAX_SPY];
3560 int number = srq->length;
3561 int i;
3562 int err = 0;
3563 unsigned long flags;
3564
3565 /* Check the number of addresses */
3566 if (number > IW_MAX_SPY)
3567 return -E2BIG;
3568
3569 /* Get the data in the driver */
3570 if (srq->pointer) {
3571 if (copy_from_user(address, srq->pointer,
3572 sizeof(struct sockaddr) * number))
3573 return -EFAULT;
3574 }
3575
3576 /* Make sure nobody mess with the structure while we do */
3577 if (orinoco_lock(priv, &flags) != 0)
3578 return -EBUSY;
3579
3580 /* orinoco_lock() doesn't disable interrupts, so make sure the
3581 * interrupt rx path don't get confused while we copy */
3582 priv->spy_number = 0;
3583
3584 if (number > 0) {
3585 /* Extract the addresses */
3586 for (i = 0; i < number; i++)
3587 memcpy(priv->spy_address[i], address[i].sa_data,
3588 ETH_ALEN);
3589 /* Reset stats */
3590 memset(priv->spy_stat, 0,
3591 sizeof(struct iw_quality) * IW_MAX_SPY);
3592 /* Set number of addresses */
3593 priv->spy_number = number;
3594 }
3595
3596 /* Now, let the others play */
3597 orinoco_unlock(priv, &flags);
3598
3599 return err;
3600}
3601
3602static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3603{
3604 struct orinoco_private *priv = netdev_priv(dev);
3605 struct sockaddr address[IW_MAX_SPY];
3606 struct iw_quality spy_stat[IW_MAX_SPY];
3607 int number;
3608 int i;
3609 unsigned long flags;
3610
3611 if (orinoco_lock(priv, &flags) != 0)
3612 return -EBUSY;
3613
3614 number = priv->spy_number;
3615 if ((number > 0) && (srq->pointer)) {
3616 /* Create address struct */
3617 for (i = 0; i < number; i++) {
3618 memcpy(address[i].sa_data, priv->spy_address[i],
3619 ETH_ALEN);
3620 address[i].sa_family = AF_UNIX;
3621 }
3622 /* Copy stats */
3623 /* In theory, we should disable irqs while copying the stats
3624 * because the rx path might update it in the middle...
3625 * Bah, who care ? - Jean II */
3626 memcpy(&spy_stat, priv->spy_stat,
3627 sizeof(struct iw_quality) * IW_MAX_SPY);
3628 for (i=0; i < number; i++)
3629 priv->spy_stat[i].updated = 0;
3630 }
3631
3632 orinoco_unlock(priv, &flags);
3633
3634 /* Push stuff to user space */
3635 srq->length = number;
3636 if(copy_to_user(srq->pointer, address,
3637 sizeof(struct sockaddr) * number))
3638 return -EFAULT;
3639 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
3640 &spy_stat, sizeof(struct iw_quality) * number))
3641 return -EFAULT;
3642
3643 return 0;
3644}
3645
3646static int
3647orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3648{
3649 struct orinoco_private *priv = netdev_priv(dev);
3650 struct iwreq *wrq = (struct iwreq *)rq;
3651 int err = 0;
3652 int tmp;
3653 int changed = 0;
3654 unsigned long flags;
3655
3656 TRACE_ENTER(dev->name);
3657
3658 /* In theory, we could allow most of the the SET stuff to be
3659 * done. In practice, the lapse of time at startup when the
3660 * card is not ready is very short, so why bother... Note
3661 * that netif_device_present is different from up/down
3662 * (ifconfig), when the device is not yet up, it is usually
3663 * already ready... Jean II */
3664 if (! netif_device_present(dev))
3665 return -ENODEV;
3666
3667 switch (cmd) {
3668 case SIOCGIWNAME:
3669 strcpy(wrq->u.name, "IEEE 802.11-DS");
3670 break;
3671
3672 case SIOCGIWAP:
3673 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
3674 err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
3675 break;
3676
3677 case SIOCGIWRANGE:
3678 err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
3679 break;
3680
3681 case SIOCSIWMODE:
3682 if (orinoco_lock(priv, &flags) != 0)
3683 return -EBUSY;
3684 switch (wrq->u.mode) {
3685 case IW_MODE_ADHOC:
3686 if (! (priv->has_ibss || priv->has_port3) )
3687 err = -EINVAL;
3688 else {
3689 priv->iw_mode = IW_MODE_ADHOC;
3690 changed = 1;
3691 }
3692 break;
3693
3694 case IW_MODE_INFRA:
3695 priv->iw_mode = IW_MODE_INFRA;
3696 changed = 1;
3697 break;
3698
3699 default:
3700 err = -EINVAL;
3701 break;
3702 }
3703 set_port_type(priv);
3704 orinoco_unlock(priv, &flags);
3705 break;
3706
3707 case SIOCGIWMODE:
3708 if (orinoco_lock(priv, &flags) != 0)
3709 return -EBUSY;
3710 wrq->u.mode = priv->iw_mode;
3711 orinoco_unlock(priv, &flags);
3712 break;
3713
3714 case SIOCSIWENCODE:
3715 err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
3716 if (! err)
3717 changed = 1;
3718 break;
3719
3720 case SIOCGIWENCODE:
3721 if (! capable(CAP_NET_ADMIN)) {
3722 err = -EPERM;
3723 break;
3724 }
3725
3726 err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
3727 break;
3728
3729 case SIOCSIWESSID:
3730 err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
3731 if (! err)
3732 changed = 1;
3733 break;
3734
3735 case SIOCGIWESSID:
3736 err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
3737 break;
3738
3739 case SIOCSIWNICKN:
3740 err = orinoco_ioctl_setnick(dev, &wrq->u.data);
3741 if (! err)
3742 changed = 1;
3743 break;
3744
3745 case SIOCGIWNICKN:
3746 err = orinoco_ioctl_getnick(dev, &wrq->u.data);
3747 break;
3748
3749 case SIOCGIWFREQ:
3750 tmp = orinoco_hw_get_freq(priv);
3751 if (tmp < 0) {
3752 err = tmp;
3753 } else {
3754 wrq->u.freq.m = tmp;
3755 wrq->u.freq.e = 1;
3756 }
3757 break;
3758
3759 case SIOCSIWFREQ:
3760 err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
3761 if (! err)
3762 changed = 1;
3763 break;
3764
3765 case SIOCGIWSENS:
3766 err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
3767 break;
3768
3769 case SIOCSIWSENS:
3770 err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
3771 if (! err)
3772 changed = 1;
3773 break;
3774
3775 case SIOCGIWRTS:
3776 wrq->u.rts.value = priv->rts_thresh;
3777 wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
3778 wrq->u.rts.fixed = 1;
3779 break;
3780
3781 case SIOCSIWRTS:
3782 err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
3783 if (! err)
3784 changed = 1;
3785 break;
3786
3787 case SIOCSIWFRAG:
3788 err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
3789 if (! err)
3790 changed = 1;
3791 break;
3792
3793 case SIOCGIWFRAG:
3794 err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
3795 break;
3796
3797 case SIOCSIWRATE:
3798 err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
3799 if (! err)
3800 changed = 1;
3801 break;
3802
3803 case SIOCGIWRATE:
3804 err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
3805 break;
3806
3807 case SIOCSIWPOWER:
3808 err = orinoco_ioctl_setpower(dev, &wrq->u.power);
3809 if (! err)
3810 changed = 1;
3811 break;
3812
3813 case SIOCGIWPOWER:
3814 err = orinoco_ioctl_getpower(dev, &wrq->u.power);
3815 break;
3816
3817 case SIOCGIWTXPOW:
3818 /* The card only supports one tx power, so this is easy */
3819 wrq->u.txpower.value = 15; /* dBm */
3820 wrq->u.txpower.fixed = 1;
3821 wrq->u.txpower.disabled = 0;
3822 wrq->u.txpower.flags = IW_TXPOW_DBM;
3823 break;
3824
3825 case SIOCSIWRETRY:
3826 err = -EOPNOTSUPP;
3827 break;
3828
3829 case SIOCGIWRETRY:
3830 err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
3831 break;
3832
3833 case SIOCSIWSPY:
3834 err = orinoco_ioctl_setspy(dev, &wrq->u.data);
3835 break;
3836
3837 case SIOCGIWSPY:
3838 err = orinoco_ioctl_getspy(dev, &wrq->u.data);
3839 break;
3840
3841 case SIOCGIWPRIV:
3842 if (wrq->u.data.pointer) {
3843 struct iw_priv_args privtab[] = {
3844 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
3845 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
3846 { SIOCIWFIRSTPRIV + 0x2,
3847 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3848 0, "set_port3" },
3849 { SIOCIWFIRSTPRIV + 0x3, 0,
3850 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3851 "get_port3" },
3852 { SIOCIWFIRSTPRIV + 0x4,
3853 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3854 0, "set_preamble" },
3855 { SIOCIWFIRSTPRIV + 0x5, 0,
3856 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3857 "get_preamble" },
3858 { SIOCIWFIRSTPRIV + 0x6,
3859 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3860 0, "set_ibssport" },
3861 { SIOCIWFIRSTPRIV + 0x7, 0,
3862 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3863 "get_ibssport" },
3864 { SIOCIWLASTPRIV, 0, 0, "dump_recs" },
3865 };
3866
3867 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
3868 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
3869 err = -EFAULT;
3870 }
3871 break;
3872
3873 case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
3874 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
3875 if (! capable(CAP_NET_ADMIN)) {
3876 err = -EPERM;
3877 break;
3878 }
3879
3880 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3881
3882 schedule_work(&priv->reset_work);
3883 break;
3884
3885 case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
3886 if (! capable(CAP_NET_ADMIN)) {
3887 err = -EPERM;
3888 break;
3889 }
3890
3891 err = orinoco_ioctl_setport3(dev, wrq);
3892 if (! err)
3893 changed = 1;
3894 break;
3895
3896 case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
3897 err = orinoco_ioctl_getport3(dev, wrq);
3898 break;
3899
3900 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
3901 if (! capable(CAP_NET_ADMIN)) {
3902 err = -EPERM;
3903 break;
3904 }
3905
3906 /* 802.11b has recently defined some short preamble.
3907 * Basically, the Phy header has been reduced in size.
3908 * This increase performance, especially at high rates
3909 * (the preamble is transmitted at 1Mb/s), unfortunately
3910 * this give compatibility troubles... - Jean II */
3911 if(priv->has_preamble) {
3912 int val = *( (int *) wrq->u.name );
3913
3914 if (orinoco_lock(priv, &flags) != 0)
3915 return -EBUSY;
3916 if (val)
3917 priv->preamble = 1;
3918 else
3919 priv->preamble = 0;
3920 orinoco_unlock(priv, &flags);
3921 changed = 1;
3922 } else
3923 err = -EOPNOTSUPP;
3924 break;
3925
3926 case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
3927 if(priv->has_preamble) {
3928 int *val = (int *)wrq->u.name;
3929
3930 if (orinoco_lock(priv, &flags) != 0)
3931 return -EBUSY;
3932 *val = priv->preamble;
3933 orinoco_unlock(priv, &flags);
3934 } else
3935 err = -EOPNOTSUPP;
3936 break;
3937 case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
3938 if (! capable(CAP_NET_ADMIN)) {
3939 err = -EPERM;
3940 break;
3941 }
3942
3943 err = orinoco_ioctl_setibssport(dev, wrq);
3944 if (! err)
3945 changed = 1;
3946 break;
3947
3948 case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
3949 err = orinoco_ioctl_getibssport(dev, wrq);
3950 break;
3951
3952 case SIOCIWLASTPRIV:
3953 err = orinoco_debug_dump_recs(dev);
3954 if (err)
3955 printk(KERN_ERR "%s: Unable to dump records (%d)\n",
3956 dev->name, err);
3957 break;
3958
3959
3960 default:
3961 err = -EOPNOTSUPP;
3962 }
3963
3964 if (! err && changed && netif_running(dev)) {
3965 err = orinoco_reconfigure(dev);
3966 }
3967
3968 TRACE_EXIT(dev->name);
3969
3970 return err;
3971}
3972
3973struct {
3974 u16 rid;
3975 char *name;
3976 int displaytype;
3977#define DISPLAY_WORDS 0
3978#define DISPLAY_BYTES 1
3979#define DISPLAY_STRING 2
3980#define DISPLAY_XSTRING 3
3981} record_table[] = {
3982#define DEBUG_REC(name,type) { HERMES_RID_##name, #name, DISPLAY_##type }
3983 DEBUG_REC(CNFPORTTYPE,WORDS),
3984 DEBUG_REC(CNFOWNMACADDR,BYTES),
3985 DEBUG_REC(CNFDESIREDSSID,STRING),
3986 DEBUG_REC(CNFOWNCHANNEL,WORDS),
3987 DEBUG_REC(CNFOWNSSID,STRING),
3988 DEBUG_REC(CNFOWNATIMWINDOW,WORDS),
3989 DEBUG_REC(CNFSYSTEMSCALE,WORDS),
3990 DEBUG_REC(CNFMAXDATALEN,WORDS),
3991 DEBUG_REC(CNFPMENABLED,WORDS),
3992 DEBUG_REC(CNFPMEPS,WORDS),
3993 DEBUG_REC(CNFMULTICASTRECEIVE,WORDS),
3994 DEBUG_REC(CNFMAXSLEEPDURATION,WORDS),
3995 DEBUG_REC(CNFPMHOLDOVERDURATION,WORDS),
3996 DEBUG_REC(CNFOWNNAME,STRING),
3997 DEBUG_REC(CNFOWNDTIMPERIOD,WORDS),
3998 DEBUG_REC(CNFMULTICASTPMBUFFERING,WORDS),
3999 DEBUG_REC(CNFWEPENABLED_AGERE,WORDS),
4000 DEBUG_REC(CNFMANDATORYBSSID_SYMBOL,WORDS),
4001 DEBUG_REC(CNFWEPDEFAULTKEYID,WORDS),
4002 DEBUG_REC(CNFDEFAULTKEY0,BYTES),
4003 DEBUG_REC(CNFDEFAULTKEY1,BYTES),
4004 DEBUG_REC(CNFMWOROBUST_AGERE,WORDS),
4005 DEBUG_REC(CNFDEFAULTKEY2,BYTES),
4006 DEBUG_REC(CNFDEFAULTKEY3,BYTES),
4007 DEBUG_REC(CNFWEPFLAGS_INTERSIL,WORDS),
4008 DEBUG_REC(CNFWEPKEYMAPPINGTABLE,WORDS),
4009 DEBUG_REC(CNFAUTHENTICATION,WORDS),
4010 DEBUG_REC(CNFMAXASSOCSTA,WORDS),
4011 DEBUG_REC(CNFKEYLENGTH_SYMBOL,WORDS),
4012 DEBUG_REC(CNFTXCONTROL,WORDS),
4013 DEBUG_REC(CNFROAMINGMODE,WORDS),
4014 DEBUG_REC(CNFHOSTAUTHENTICATION,WORDS),
4015 DEBUG_REC(CNFRCVCRCERROR,WORDS),
4016 DEBUG_REC(CNFMMLIFE,WORDS),
4017 DEBUG_REC(CNFALTRETRYCOUNT,WORDS),
4018 DEBUG_REC(CNFBEACONINT,WORDS),
4019 DEBUG_REC(CNFAPPCFINFO,WORDS),
4020 DEBUG_REC(CNFSTAPCFINFO,WORDS),
4021 DEBUG_REC(CNFPRIORITYQUSAGE,WORDS),
4022 DEBUG_REC(CNFTIMCTRL,WORDS),
4023 DEBUG_REC(CNFTHIRTY2TALLY,WORDS),
4024 DEBUG_REC(CNFENHSECURITY,WORDS),
4025 DEBUG_REC(CNFGROUPADDRESSES,BYTES),
4026 DEBUG_REC(CNFCREATEIBSS,WORDS),
4027 DEBUG_REC(CNFFRAGMENTATIONTHRESHOLD,WORDS),
4028 DEBUG_REC(CNFRTSTHRESHOLD,WORDS),
4029 DEBUG_REC(CNFTXRATECONTROL,WORDS),
4030 DEBUG_REC(CNFPROMISCUOUSMODE,WORDS),
4031 DEBUG_REC(CNFBASICRATES_SYMBOL,WORDS),
4032 DEBUG_REC(CNFPREAMBLE_SYMBOL,WORDS),
4033 DEBUG_REC(CNFSHORTPREAMBLE,WORDS),
4034 DEBUG_REC(CNFWEPKEYS_AGERE,BYTES),
4035 DEBUG_REC(CNFEXCLUDELONGPREAMBLE,WORDS),
4036 DEBUG_REC(CNFTXKEY_AGERE,WORDS),
4037 DEBUG_REC(CNFAUTHENTICATIONRSPTO,WORDS),
4038 DEBUG_REC(CNFBASICRATES,WORDS),
4039 DEBUG_REC(CNFSUPPORTEDRATES,WORDS),
4040 DEBUG_REC(CNFTICKTIME,WORDS),
4041 DEBUG_REC(CNFSCANREQUEST,WORDS),
4042 DEBUG_REC(CNFJOINREQUEST,WORDS),
4043 DEBUG_REC(CNFAUTHENTICATESTATION,WORDS),
4044 DEBUG_REC(CNFCHANNELINFOREQUEST,WORDS),
4045 DEBUG_REC(MAXLOADTIME,WORDS),
4046 DEBUG_REC(DOWNLOADBUFFER,WORDS),
4047 DEBUG_REC(PRIID,WORDS),
4048 DEBUG_REC(PRISUPRANGE,WORDS),
4049 DEBUG_REC(CFIACTRANGES,WORDS),
4050 DEBUG_REC(NICSERNUM,XSTRING),
4051 DEBUG_REC(NICID,WORDS),
4052 DEBUG_REC(MFISUPRANGE,WORDS),
4053 DEBUG_REC(CFISUPRANGE,WORDS),
4054 DEBUG_REC(CHANNELLIST,WORDS),
4055 DEBUG_REC(REGULATORYDOMAINS,WORDS),
4056 DEBUG_REC(TEMPTYPE,WORDS),
4057/* DEBUG_REC(CIS,BYTES), */
4058 DEBUG_REC(STAID,WORDS),
4059 DEBUG_REC(CURRENTSSID,STRING),
4060 DEBUG_REC(CURRENTBSSID,BYTES),
4061 DEBUG_REC(COMMSQUALITY,WORDS),
4062 DEBUG_REC(CURRENTTXRATE,WORDS),
4063 DEBUG_REC(CURRENTBEACONINTERVAL,WORDS),
4064 DEBUG_REC(CURRENTSCALETHRESHOLDS,WORDS),
4065 DEBUG_REC(PROTOCOLRSPTIME,WORDS),
4066 DEBUG_REC(SHORTRETRYLIMIT,WORDS),
4067 DEBUG_REC(LONGRETRYLIMIT,WORDS),
4068 DEBUG_REC(MAXTRANSMITLIFETIME,WORDS),
4069 DEBUG_REC(MAXRECEIVELIFETIME,WORDS),
4070 DEBUG_REC(CFPOLLABLE,WORDS),
4071 DEBUG_REC(AUTHENTICATIONALGORITHMS,WORDS),
4072 DEBUG_REC(PRIVACYOPTIONIMPLEMENTED,WORDS),
4073 DEBUG_REC(OWNMACADDR,BYTES),
4074 DEBUG_REC(SCANRESULTSTABLE,WORDS),
4075 DEBUG_REC(PHYTYPE,WORDS),
4076 DEBUG_REC(CURRENTCHANNEL,WORDS),
4077 DEBUG_REC(CURRENTPOWERSTATE,WORDS),
4078 DEBUG_REC(CCAMODE,WORDS),
4079 DEBUG_REC(SUPPORTEDDATARATES,WORDS),
4080 DEBUG_REC(BUILDSEQ,BYTES),
4081 DEBUG_REC(FWID,XSTRING)
4082#undef DEBUG_REC
4083};
4084
4085#define DEBUG_LTV_SIZE 128
4086
4087static int orinoco_debug_dump_recs(struct net_device *dev)
4088{
4089 struct orinoco_private *priv = netdev_priv(dev);
4090 hermes_t *hw = &priv->hw;
4091 u8 *val8;
4092 u16 *val16;
4093 int i,j;
4094 u16 length;
4095 int err;
4096
4097 /* I'm not sure: we might have a lock here, so we'd better go
4098 atomic, just in case. */
4099 val8 = kmalloc(DEBUG_LTV_SIZE + 2, GFP_ATOMIC);
4100 if (! val8)
4101 return -ENOMEM;
4102 val16 = (u16 *)val8;
4103
4104 for (i = 0; i < ARRAY_SIZE(record_table); i++) {
4105 u16 rid = record_table[i].rid;
4106 int len;
4107
4108 memset(val8, 0, DEBUG_LTV_SIZE + 2);
4109
4110 err = hermes_read_ltv(hw, USER_BAP, rid, DEBUG_LTV_SIZE,
4111 &length, val8);
4112 if (err) {
4113 DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
4114 continue;
4115 }
4116 val16 = (u16 *)val8;
4117 if (length == 0)
4118 continue;
4119
4120 printk(KERN_DEBUG "%-15s (0x%04x): length=%d (%d bytes)\tvalue=",
4121 record_table[i].name,
4122 rid, length, (length-1)*2);
4123 len = min(((int)length-1)*2, DEBUG_LTV_SIZE);
4124
4125 switch (record_table[i].displaytype) {
4126 case DISPLAY_WORDS:
4127 for (j = 0; j < len / 2; j++)
4128 printk("%04X-", le16_to_cpu(val16[j]));
4129 break;
4130
4131 case DISPLAY_BYTES:
4132 default:
4133 for (j = 0; j < len; j++)
4134 printk("%02X:", val8[j]);
4135 break;
4136
4137 case DISPLAY_STRING:
4138 len = min(len, le16_to_cpu(val16[0])+2);
4139 val8[len] = '\0';
4140 printk("\"%s\"", (char *)&val16[1]);
4141 break;
4142
4143 case DISPLAY_XSTRING:
4144 printk("'%s'", (char *)val8);
4145 }
4146
4147 printk("\n");
4148 }
4149
4150 kfree(val8);
4151
4152 return 0;
4153}
4154
4155/********************************************************************/
4156/* Debugging */
4157/********************************************************************/
4158
4159#if 0
4160static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4161{
4162 printk(KERN_DEBUG "RX descriptor:\n");
4163 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4164 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4165 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4166 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4167 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4168 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4169 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4170
4171 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4172 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4173 frame->p80211.frame_ctl);
4174 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4175 frame->p80211.duration_id);
4176 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4177 frame->p80211.addr1[0], frame->p80211.addr1[1],
4178 frame->p80211.addr1[2], frame->p80211.addr1[3],
4179 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4180 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4181 frame->p80211.addr2[0], frame->p80211.addr2[1],
4182 frame->p80211.addr2[2], frame->p80211.addr2[3],
4183 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4184 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4185 frame->p80211.addr3[0], frame->p80211.addr3[1],
4186 frame->p80211.addr3[2], frame->p80211.addr3[3],
4187 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4188 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4189 frame->p80211.seq_ctl);
4190 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4191 frame->p80211.addr4[0], frame->p80211.addr4[1],
4192 frame->p80211.addr4[2], frame->p80211.addr4[3],
4193 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4194 printk(KERN_DEBUG " data_len = 0x%04x\n",
4195 frame->p80211.data_len);
4196
4197 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4198 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4199 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4200 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4201 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4202 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4203 frame->p8023.h_source[0], frame->p8023.h_source[1],
4204 frame->p8023.h_source[2], frame->p8023.h_source[3],
4205 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4206 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4207
4208 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4209 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4210 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4211 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4212 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4213 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4214 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4215}
4216#endif /* 0 */
4217
4218/********************************************************************/
4219/* Module initialization */
4220/********************************************************************/
4221
4222EXPORT_SYMBOL(alloc_orinocodev);
4223EXPORT_SYMBOL(free_orinocodev);
4224
4225EXPORT_SYMBOL(__orinoco_up);
4226EXPORT_SYMBOL(__orinoco_down);
4227EXPORT_SYMBOL(orinoco_stop);
4228EXPORT_SYMBOL(orinoco_reinit_firmware);
4229
4230EXPORT_SYMBOL(orinoco_interrupt);
4231
4232/* Can't be declared "const" or the whole __initdata section will
4233 * become const */
4234static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4235 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4236 "Pavel Roskin <proski@gnu.org>, et al)";
4237
4238static int __init init_orinoco(void)
4239{
4240 printk(KERN_DEBUG "%s\n", version);
4241 return 0;
4242}
4243
4244static void __exit exit_orinoco(void)
4245{
4246}
4247
4248module_init(init_orinoco);
4249module_exit(exit_orinoco);