1 /* orinoco.c 0.13e - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Copyright (C) 2000 David Gibson, Linuxcare Australia <hermes@gibson.dropbear.id.au>
7 * With some help from :
8 * Copyright (C) 2001 Jean Tourrilhes, HP Labs <jt@hpl.hp.com>
9 * Copyright (C) 2001 Benjamin Herrenschmidt <benh@kernel.crashing.org>
11 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
13 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy@fasta.fh-dortmund.de>
14 * http://www.fasta.fh-dortmund.de/users/andy/wvlan/
16 * The contents of this file are subject to the Mozilla Public License
17 * Version 1.1 (the "License"); you may not use this file except in
18 * compliance with the License. You may obtain a copy of the License
19 * at http://www.mozilla.org/MPL/
21 * Software distributed under the License is distributed on an "AS IS"
22 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
23 * the License for the specific language governing rights and
24 * limitations under the License.
26 * The initial developer of the original code is David A. Hinds
27 * <dahinds@users.sourceforge.net>. Portions created by David
28 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
31 * Alternatively, the contents of this file may be used under the
32 * terms of the GNU General Public License version 2 (the "GPL"), in
33 * which case the provisions of the GPL are applicable instead of the
34 * above. If you wish to allow the use of your version of this file
35 * only under the terms of the GPL and not to allow others to use your
36 * version of this file under the MPL, indicate your decision by
37 * deleting the provisions above and replace them with the notice and
38 * other provisions required by the GPL. If you do not delete the
39 * provisions above, a recipient may use your version of this file
40 * under either the MPL or the GPL. */
43 * v0.01 -> v0.02 - 21/3/2001 - Jean II
44 * o Allow to use regular ethX device name instead of dldwdX
45 * o Warning on IBSS with ESSID=any for firmware 6.06
46 * o Put proper range.throughput values (optimistic)
47 * o IWSPY support (IOCTL and stat gather in Rx path)
48 * o Allow setting frequency in Ad-Hoc mode
49 * o Disable WEP setting if !has_wep to work on old firmware
51 * o Start adding support for Samsung/Compaq firmware
53 * v0.02 -> v0.03 - 23/3/2001 - Jean II
54 * o Start adding Symbol support - need to check all that
55 * o Fix Prism2/Symbol WEP to accept 128 bits keys
56 * o Add Symbol WEP (add authentication type)
57 * o Add Prism2/Symbol rate
58 * o Add PM timeout (holdover duration)
59 * o Enable "iwconfig eth0 key off" and friends (toggle flags)
60 * o Enable "iwconfig eth0 power unicast/all" (toggle flags)
61 * o Try with an intel card. It report firmware 1.01, behave like
62 * an antiquated firmware, however on windows it says 2.00. Yuck !
63 * o Workaround firmware bug in allocate buffer (Intel 1.01)
64 * o Finish external renaming to orinoco...
65 * o Testing with various Wavelan firmwares
67 * v0.03 -> v0.04 - 30/3/2001 - Jean II
68 * o Update to Wireless 11 -> add retry limit/lifetime support
69 * o Tested with a D-Link DWL 650 card, fill in firmware support
70 * o Warning on Vcc mismatch (D-Link 3.3v card in Lucent 5v only slot)
71 * o Fixed the Prims2 WEP bugs that I introduced in v0.03 :-(
72 * It work on D-Link *only* after a tcpdump. Weird...
73 * And still doesn't work on Intel card. Grrrr...
74 * o Update the mode after a setport3
75 * o Add preamble setting for Symbol cards (not yet enabled)
76 * o Don't complain as much about Symbol cards...
78 * v0.04 -> v0.04b - 22/4/2001 - David Gibson
79 * o Removed the 'eth' parameter - always use ethXX as the
80 * interface name instead of dldwdXX. The other was racy
82 * o Clean up RID definitions in hermes.h, other cleanups
84 * v0.04b -> v0.04c - 24/4/2001 - Jean II
85 * o Tim Hurley <timster@seiki.bliztech.com> reported a D-Link card
86 * with vendor 02 and firmware 0.08. Added in the capabilities...
87 * o Tested Lucent firmware 7.28, everything works...
89 * v0.04c -> v0.05 - 3/5/2001 - Benjamin Herrenschmidt
90 * o Spin-off Pcmcia code. This file is renamed orinoco.c,
91 * and orinoco_cs.c now contains only the Pcmcia specific stuff
92 * o Add Airport driver support on top of orinoco.c (see airport.c)
94 * v0.05 -> v0.05a - 4/5/2001 - Jean II
95 * o Revert to old Pcmcia code to fix breakage of Ben's changes...
97 * v0.05a -> v0.05b - 4/5/2001 - Jean II
98 * o add module parameter 'ignore_cis_vcc' for D-Link @ 5V
99 * o D-Link firmware doesn't support multicast. We just print a few
100 * error messages, but otherwise everything works...
101 * o For David : set/getport3 works fine, just upgrade iwpriv...
103 * v0.05b -> v0.05c - 5/5/2001 - Benjamin Herrenschmidt
104 * o Adapt airport.c to latest changes in orinoco.c
105 * o Remove deferred power enabling code
107 * v0.05c -> v0.05d - 5/5/2001 - Jean II
108 * o Workaround to SNAP decapsulate frame from LinkSys AP
109 * original patch from : Dong Liu <dliu@research.bell-labs.com>
110 * (note : the memcmp bug was mine - fixed)
111 * o Remove set_retry stuff, no firmware support it (bloat--).
113 * v0.05d -> v0.06 - 25/5/2001 - Jean II
114 * Original patch from "Hong Lin" <alin@redhat.com>,
115 * "Ian Kinner" <ikinner@redhat.com>
116 * and "David Smith" <dsmith@redhat.com>
117 * o Init of priv->tx_rate_ctrl in firmware specific section.
118 * o Prism2/Symbol rate, upto should be 0xF and not 0x15. Doh !
119 * o Spectrum card always need cor_reset (for every reset)
120 * o Fix cor_reset to not lose bit 7 in the register
121 * o flush_stale_links to remove zombie Pcmcia instances
122 * o Ack previous hermes event before reset
123 * Me (with my little hands)
124 * o Allow orinoco.c to call cor_reset via priv->card_reset_handler
125 * o Add priv->need_card_reset to toggle this feature
126 * o Fix various buglets when setting WEP in Symbol firmware
127 * Now, encryption is fully functional on Symbol cards. Youpi !
129 * v0.06 -> v0.06b - 25/5/2001 - Jean II
130 * o IBSS on Symbol use port_mode = 4. Please don't ask...
132 * v0.06b -> v0.06c - 29/5/2001 - Jean II
133 * o Show first spy address in /proc/net/wireless for IBSS mode as well
135 * v0.06c -> v0.06d - 6/7/2001 - David Gibson
136 * o Change a bunch of KERN_INFO messages to KERN_DEBUG, as per Linus'
137 * wishes to reduce the number of unecessary messages.
138 * o Removed bogus message on CRC error.
139 * o Merged fixeds for v0.08 Prism 2 firmware from William Waghorn
140 * <willwaghorn@yahoo.co.uk>
141 * o Slight cleanup/re-arrangement of firmware detection code.
143 * v0.06d -> v0.06e - 1/8/2001 - David Gibson
144 * o Removed some redundant global initializers (orinoco_cs.c).
145 * o Added some module metadataa
147 * v0.06e -> v0.06f - 14/8/2001 - David Gibson
148 * o Wording fix to license
149 * o Added a 'use_alternate_encaps' module parameter for APs which need an
150 * oui of 00:00:00. We really need a better way of handling this, but
151 * the module flag is better than nothing for now.
153 * v0.06f -> v0.07 - 20/8/2001 - David Gibson
154 * o Removed BAP error retries from hermes_bap_seek(). For Tx we now
155 * let the upper layers handle the retry, we retry explicitly in the
156 * Rx path, but don't make as much noise about it.
157 * o Firmware detection cleanups.
159 * v0.07 -> v0.07a - 1/10/3001 - Jean II
160 * o Add code to read Symbol firmware revision, inspired by latest code
161 * in Spectrum24 by Lee John Keyser-Allen - Thanks Lee !
162 * o Thanks to Jared Valentine <hidden@xmission.com> for "providing" me
163 * a 3Com card with a recent firmware, fill out Symbol firmware
164 * capabilities of latest rev (2.20), as well as older Symbol cards.
165 * o Disable Power Management in newer Symbol firmware, the API
166 * has changed (documentation needed).
168 * v0.07a -> v0.08 - 3/10/2001 - David Gibson
169 * o Fixed a possible buffer overrun found by the Stanford checker (in
170 * dldwd_ioctl_setiwencode()). Can only be called by root anyway, so not
172 * o Turned has_big_wep on for Intersil cards. That's not true for all of
173 * them but we should at least let the capable ones try.
174 * o Wait for BUSY to clear at the beginning of hermes_bap_seek(). I
175 * realised that my assumption that the driver's serialization
176 * would prevent the BAP being busy on entry was possibly false, because
177 * things other than seeks may make the BAP busy.
178 * o Use "alternate" (oui 00:00:00) encapsulation by default.
179 * Setting use_old_encaps will mimic the old behaviour, but I think we
180 * will be able to eliminate this.
181 * o Don't try to make __initdata const (the version string). This can't
182 * work because of the way the __initdata sectioning works.
183 * o Added MODULE_LICENSE tags.
184 * o Support for PLX (transparent PCMCIA->PCI brdge) cards.
185 * o Changed to using the new type-facist min/max.
187 * v0.08 -> v0.08a - 9/10/2001 - David Gibson
188 * o Inserted some missing acknowledgements/info into the Changelog.
189 * o Fixed some bugs in the normalisation of signel level reporting.
190 * o Fixed bad bug in WEP key handling on Intersil and Symbol firmware,
191 * which led to an instant crash on big-endian machines.
193 * v0.08a -> v0.08b - 20/11/2001 - David Gibson
194 * o Lots of cleanup and bugfixes in orinoco_plx.c
195 * o Cleanup to handling of Tx rate setting.
196 * o Removed support for old encapsulation method.
197 * o Removed old "dldwd" names.
198 * o Split RID constants into a new file hermes_rid.h
199 * o Renamed RID constants to match linux-wlan-ng and prism2.o
200 * o Bugfixes in hermes.c
201 * o Poke the PLX's INTCSR register, so it actually starts
202 * generating interrupts. These cards might actually work now.
203 * o Update to wireless extensions v12 (Jean II)
204 * o Support for tallies and inquire command (Jean II)
205 * o Airport updates for newer PPC kernels (BenH)
207 * v0.08b -> v0.09 - 21/12/2001 - David Gibson
208 * o Some new PCI IDs for PLX cards.
209 * o Removed broken attempt to do ALLMULTI reception. Just use
210 * promiscuous mode instead
211 * o Preliminary work for list-AP (Jean II)
212 * o Airport updates from (BenH)
213 * o Eliminated racy hw_ready stuff
214 * o Fixed generation of fake events in irq handler. This should
215 * finally kill the EIO problems (Jean II & dgibson)
216 * o Fixed breakage of bitrate set/get on Agere firmware (Jean II)
218 * v0.09 -> v0.09a - 2/1/2002 - David Gibson
219 * o Fixed stupid mistake in multicast list handling, triggering
222 * v0.09a -> v0.09b - 16/1/2002 - David Gibson
223 * o Fixed even stupider mistake in new interrupt handling, which
224 * seriously broke things on big-endian machines.
225 * o Removed a bunch of redundant includes and exports.
226 * o Removed a redundant MOD_{INC,DEC}_USE_COUNT pair in airport.c
227 * o Don't attempt to do hardware level multicast reception on
228 * Intersil firmware, just go promisc instead.
229 * o Typo fixed in hermes_issue_cmd()
230 * o Eliminated WIRELESS_SPY #ifdefs
231 * o Status code reported on Tx exceptions
232 * o Moved netif_wake_queue() from ALLOC interrupts to TX and TXEXC
233 * interrupts, which should fix the timeouts we're seeing.
235 * v0.09b -> v0.10 - 25 Feb 2002 - David Gibson
236 * o Removed nested structures used for header parsing, so the
237 * driver should now work without hackery on ARM
238 * o Fix for WEP handling on Intersil (Hawk Newton)
239 * o Eliminated the /proc/hermes/ethXX/regs debugging file. It
240 * was never very useful.
241 * o Make Rx errors less noisy.
243 * v0.10 -> v0.11 - 5 Apr 2002 - David Gibson
244 * o Laid the groundwork in hermes.[ch] for devices which map
245 * into PCI memory space rather than IO space.
246 * o Fixed bug in multicast handling (cleared multicast list when
247 * leaving promiscuous mode).
248 * o Relegated Tx error messages to debug.
249 * o Cleaned up / corrected handling of allocation lengths.
250 * o Set OWNSSID in IBSS mode for WinXP interoperability (jimc).
251 * o Change to using alloc_etherdev() for structure allocations.
252 * o Check for and drop undersized packets.
253 * o Fixed a race in stopping/waking the queue. This should fix
254 * the timeout problems (Pavel Roskin)
255 * o Reverted to netif_wake_queue() on the ALLOC event.
256 * o Fixes for recent Symbol firmwares which lack AP density
259 * v0.11 -> v0.11a - 29 Apr 2002 - David Gibson
260 * o Handle different register spacing, necessary for Prism 2.5
261 * PCI adaptors (Steve Hill).
262 * o Cleaned up initialization of card structures in orinoco_cs
263 * and airport. Removed card->priv field.
264 * o Make response structure optional for hermes_docmd_wait()
266 * o Added PCI id for Nortel emobility to orinoco_plx.c.
267 * o Cleanup to handling of Symbol's allocation bug. (Pavel Roskin)
268 * o Cleanups to firmware capability detection.
269 * o Arrange for orinoco_pci.c to override firmware detection.
270 * We should be able to support the PCI Intersil cards now.
271 * o Cleanup handling of reset_cor and hard_reset (Pavel Roskin).
272 * o Remove erroneous use of USER_BAP in the TxExc handler (Jouni
274 * o Makefile changes for better integration into David Hinds
277 * v0.11a -> v0.11b - 1 May 2002 - David Gibson
278 * o Better error reporting in orinoco_plx_init_one()
279 * o Fixed multiple bad kfree() bugs introduced by the
280 * alloc_orinocodev() changes.
282 * v0.11b -> v0.12 - 19 Jun 2002 - David Gibson
283 * o Support changing the MAC address.
284 * o Correct display of Intersil firmware revision numbers.
285 * o Entirely revised locking scheme. Should be both simpler and
287 * o Merged some common code in orinoco_plx, orinoco_pci and
288 * airport by creating orinoco_default_{open,stop,reset}()
289 * which are used as the dev->open, dev->stop, priv->reset
290 * callbacks if none are specified when alloc_orinocodev() is
292 * o Removed orinoco_plx_interrupt() and orinoco_pci_interrupt().
293 * They didn't do anything.
295 * v0.12 -> v0.12a - 4 Jul 2002 - David Gibson
296 * o Some rearrangement of code.
297 * o Numerous fixups to locking and rest handling, particularly
299 * o This allows open and stop net_device methods to be in
300 * orinoco.c now, rather than in the init modules.
301 * o In orinoco_cs.c link->priv now points to the struct
302 * net_device not to the struct orinoco_private.
303 * o Added a check for undersized SNAP frames, which could cause
306 * v0.12a -> v0.12b - 11 Jul 2002 - David Gibson
307 * o Fix hw->num_init testing code, so num_init is actually
309 * o Fix very stupid bug in orinoco_cs which broke compile with
311 * o Squashed a warning.
313 * v0.12b -> v0.12c - 26 Jul 2002 - David Gibson
314 * o Change to C9X style designated initializers.
315 * o Add support for 3Com AirConnect PCI.
316 * o No longer ignore the hard_reset argument to
317 * alloc_orinocodev(). Oops.
319 * v0.12c -> v0.13beta1 - 13 Sep 2002 - David Gibson
320 * o Revert the broken 0.12* locking scheme and go to a new yet
322 * o Do firmware resets only in orinoco_init() and when waking
323 * the card from hard sleep.
325 * v0.13beta1 -> v0.13 - 27 Sep 2002 - David Gibson
326 * o Re-introduced full resets (via schedule_task()) on Tx
329 * v0.13 -> v0.13a - 30 Sep 2002 - David Gibson
330 * o Minor cleanups to info frame handling. Add basic support
331 * for linkstatus info frames.
332 * o Include required kernel headers in orinoco.h, to avoid
335 * v0.13a -> v0.13b - 10 Feb 2003 - David Gibson
336 * o Implemented hard reset for Airport cards
337 * o Experimental suspend/resume implementation for orinoco_pci
338 * o Abolished /proc debugging support, replaced with a debugging
339 * iwpriv. Now it's ugly and simple instead of ugly and complex.
340 * o Bugfix in hermes.c if the firmware returned a record length
341 * of 0, we could go clobbering memory.
342 * o Bugfix in orinoco_stop() - it used to fail if hw_unavailable
343 * was set, which was usually true on PCMCIA hot removes.
344 * o Track LINKSTATUS messages, silently drop Tx packets before
345 * we are connected (avoids cofusing the firmware), and only
346 * give LINKSTATUS printk()s if the status has changed.
348 * v0.13b -> v0.13c - 11 Mar 2003 - David Gibson
349 * o Cleanup: use dev instead of priv in various places.
350 * o Bug fix: Don't ReleaseConfiguration on RESET_PHYSICAL event
351 * if we're in the middle of a (driver initiated) hard reset.
352 * o Bug fix: ETH_ZLEN is supposed to include the header
353 * (Dionysus Blazakis & Manish Karir)
354 * o Convert to using workqueues instead of taskqueues (and
355 * backwards compatibility macros for pre 2.5.41 kernels).
356 * o Drop redundant (I think...) MOD_{INC,DEC}_USE_COUNT in
358 * o New orinoco_tmd.c init module from Joerg Dorchain for
359 * TMD7160 based PCI to PCMCIA bridges (similar to
362 * v0.13c -> v0.13d - 22 Apr 2003 - David Gibson
363 * o Make hw_unavailable a counter, rather than just a flag, this
364 * is necessary to avoid some races (such as a card being
365 * removed in the middle of orinoco_reset().
366 * o Restore Release/RequestConfiguration in the PCMCIA event handler
367 * when dealing with a driver initiated hard reset. This is
368 * necessary to prevent hangs due to a spurious interrupt while
369 * the reset is in progress.
370 * o Clear the 802.11 header when transmitting, even though we
371 * don't use it. This fixes a long standing bug on some
372 * firmwares, which seem to get confused if that isn't done.
373 * o Be less eager to de-encapsulate SNAP frames, only do so if
374 * the OUI is 00:00:00 or 00:00:f8, leave others alone. The old
375 * behaviour broke CDP (Cisco Discovery Protocol).
376 * o Use dev instead of priv for free_irq() as well as
377 * request_irq() (oops).
378 * o Attempt to reset rather than giving up if we get too many
380 * o Changed semantics of __orinoco_down() so it can be called
381 * safely with hw_unavailable set. It also now clears the
382 * linkstatus (since we're going to have to reassociate).
384 * v0.13d -> v0.13e - 12 May 2003 - David Gibson
385 * o Support for post-2.5.68 return values from irq handler.
386 * o Fixed bug where underlength packets would be double counted
387 * in the rx_dropped statistics.
388 * o Provided a module parameter to suppress linkstatus messages.
391 * o New wireless extensions API (patch from Moustafa
392 * Youssef, updated by Jim Carter and Pavel Roskin).
393 * o Handle de-encapsulation within network layer, provide 802.11
394 * headers (patch from Thomas 'Dent' Mirlacher)
395 * o RF monitor mode support
396 * o Fix possible races in SPY handling.
397 * o Disconnect wireless extensions from fundamental configuration.
398 * o (maybe) Software WEP support (patch from Stano Meduna).
399 * o (maybe) Use multiple Tx buffers - driver handling queue
400 * rather than firmware. */
402 /* Locking and synchronization:
404 * The basic principle is that everything is serialized through a
405 * single spinlock, priv->lock. The lock is used in user, bh and irq
406 * context, so when taken outside hardirq context it should always be
407 * taken with interrupts disabled. The lock protects both the
408 * hardware and the struct orinoco_private.
410 * Another flag, priv->hw_unavailable indicates that the hardware is
411 * unavailable for an extended period of time (e.g. suspended, or in
412 * the middle of a hard reset). This flag is protected by the
413 * spinlock. All code which touches the hardware should check the
414 * flag after taking the lock, and if it is set, give up on whatever
415 * they are doing and drop the lock again. The orinoco_lock()
416 * function handles this (it unlocks and returns -EBUSY if
417 * hw_unavailable is non-zero). */
419 #include <linux/config.h>
421 #include <linux/module.h>
422 #include <linux/kernel.h>
423 #include <linux/init.h>
424 #include <linux/ptrace.h>
425 #include <linux/slab.h>
426 #include <linux/string.h>
427 #include <linux/timer.h>
428 #include <linux/ioport.h>
429 #include <linux/netdevice.h>
430 #include <linux/if_arp.h>
431 #include <linux/etherdevice.h>
432 #include <linux/wireless.h>
434 #include <asm/uaccess.h>
436 #include <asm/system.h>
439 #include "hermes_rid.h"
441 #include "ieee802_11.h"
443 /********************************************************************/
444 /* Module information */
445 /********************************************************************/
447 MODULE_AUTHOR("David Gibson <hermes@gibson.dropbear.id.au>");
448 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
449 #ifdef MODULE_LICENSE
450 MODULE_LICENSE("Dual MPL/GPL");
453 /* Level of debugging. Used in the macros in orinoco.h */
455 int orinoco_debug = ORINOCO_DEBUG;
456 MODULE_PARM(orinoco_debug, "i");
457 EXPORT_SYMBOL(orinoco_debug);
460 static int suppress_linkstatus; /* = 0 */
461 MODULE_PARM(suppress_linkstatus, "i");
463 /********************************************************************/
464 /* Compile time configuration and compatibility stuff */
465 /********************************************************************/
467 /* Wireless extensions backwards compatibility */
468 #ifndef SIOCIWFIRSTPRIV
469 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
470 #endif /* SIOCIWFIRSTPRIV */
472 /* We do this this way to avoid ifdefs in the actual code */
474 #define SPY_NUMBER(priv) (priv->spy_number)
476 #define SPY_NUMBER(priv) 0
477 #endif /* WIRELESS_SPY */
479 /********************************************************************/
480 /* Internal constants */
481 /********************************************************************/
483 #define ORINOCO_MIN_MTU 256
484 #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD)
486 #define SYMBOL_MAX_VER_LEN (14)
489 #define MAX_IRQLOOPS_PER_IRQ 10
490 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
491 * how many events the
493 * legitimately generate */
494 #define SMALL_KEY_SIZE 5
495 #define LARGE_KEY_SIZE 13
496 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
498 #define DUMMY_FID 0xFFFF
500 #define RUP_EVEN(a) (((a) + 1) & (~1))
502 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
503 HERMES_MAX_MULTICAST : 0)*/
504 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
506 /********************************************************************/
508 /********************************************************************/
510 /* The frequency of each channel in MHz */
511 const long channel_frequency[] = {
512 2412, 2417, 2422, 2427, 2432, 2437, 2442,
513 2447, 2452, 2457, 2462, 2467, 2472, 2484
515 #define NUM_CHANNELS ( sizeof(channel_frequency) / sizeof(channel_frequency[0]) )
517 /* This tables gives the actual meanings of the bitrate IDs returned by the firmware. */
519 int bitrate; /* in 100s of kilobits */
521 u16 agere_txratectrl;
522 u16 intersil_txratectrl;
523 } bitrate_table[] = {
524 {110, 1, 3, 15}, /* Entry 0 is the default */
533 #define BITRATE_TABLE_SIZE (sizeof(bitrate_table) / sizeof(bitrate_table[0]))
535 /********************************************************************/
537 /********************************************************************/
539 struct header_struct {
551 } __attribute__ ((packed));
553 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
554 u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
556 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
558 /********************************************************************/
559 /* Function prototypes */
560 /********************************************************************/
562 static void orinoco_stat_gather(struct net_device *dev,
564 struct hermes_rx_descriptor *desc);
566 static struct net_device_stats *orinoco_get_stats(struct net_device *dev);
567 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev);
569 /* Hardware control routines */
571 static int __orinoco_program_rids(struct net_device *dev);
573 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv);
574 static int __orinoco_hw_setup_wep(struct orinoco_private *priv);
575 static int orinoco_hw_get_bssid(struct orinoco_private *priv, char buf[ETH_ALEN]);
576 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
577 char buf[IW_ESSID_MAX_SIZE+1]);
578 static long orinoco_hw_get_freq(struct orinoco_private *priv);
579 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv, int *numrates,
580 s32 *rates, int max);
581 static void __orinoco_set_multicast_list(struct net_device *dev);
583 /* Interrupt handling routines */
584 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw);
585 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw);
586 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw);
587 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw);
588 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw);
589 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw);
590 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw);
591 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw);
593 /* ioctl() routines */
594 static int orinoco_debug_dump_recs(struct net_device *dev);
596 /********************************************************************/
597 /* Function prototypes */
598 /********************************************************************/
600 int __orinoco_up(struct net_device *dev)
602 struct orinoco_private *priv = netdev_priv(dev);
603 struct hermes *hw = &priv->hw;
606 err = __orinoco_program_rids(dev);
608 printk(KERN_ERR "%s: Error %d configuring card\n",
613 /* Fire things up again */
614 hermes_set_irqmask(hw, ORINOCO_INTEN);
615 err = hermes_enable_port(hw, 0);
617 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
622 netif_start_queue(dev);
627 int __orinoco_down(struct net_device *dev)
629 struct orinoco_private *priv = netdev_priv(dev);
630 struct hermes *hw = &priv->hw;
633 netif_stop_queue(dev);
635 if (! priv->hw_unavailable) {
636 if (! priv->broken_disableport) {
637 err = hermes_disable_port(hw, 0);
639 /* Some firmwares (e.g. Intersil 1.3.x) seem
640 * to have problems disabling the port, oh
642 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
644 priv->broken_disableport = 1;
647 hermes_set_irqmask(hw, 0);
648 hermes_write_regn(hw, EVACK, 0xffff);
651 /* firmware will have to reassociate */
652 priv->last_linkstatus = 0xffff;
658 int orinoco_reinit_firmware(struct net_device *dev)
660 struct orinoco_private *priv = netdev_priv(dev);
661 struct hermes *hw = &priv->hw;
664 err = hermes_init(hw);
668 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
670 /* Try workaround for old Symbol firmware bug */
671 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
672 "(old Symbol firmware?). Trying to work around... ",
675 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
676 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
686 static int orinoco_open(struct net_device *dev)
688 struct orinoco_private *priv = netdev_priv(dev);
692 err = orinoco_lock(priv, &flags);
696 err = __orinoco_up(dev);
701 orinoco_unlock(priv, &flags);
706 int orinoco_stop(struct net_device *dev)
708 struct orinoco_private *priv = netdev_priv(dev);
711 /* We mustn't use orinoco_lock() here, because we need to be
712 able to close the interface even if hw_unavailable is set
713 (e.g. as we're released after a PC Card removal) */
714 spin_lock_irq(&priv->lock);
718 err = __orinoco_down(dev);
720 spin_unlock_irq(&priv->lock);
725 static int __orinoco_program_rids(struct net_device *dev)
727 struct orinoco_private *priv = netdev_priv(dev);
728 hermes_t *hw = &priv->hw;
730 struct hermes_idstring idbuf;
732 /* Set the MAC address */
733 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
734 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
736 printk(KERN_ERR "%s: Error %d setting MAC address\n", dev->name, err);
740 /* Set up the link mode */
741 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE, priv->port_type);
743 printk(KERN_ERR "%s: Error %d setting port type\n", dev->name, err);
746 /* Set the channel/frequency */
747 if (priv->channel == 0) {
748 printk(KERN_DEBUG "%s: Channel is 0 in __orinoco_program_rids()\n", dev->name);
749 if (priv->createibss)
752 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFOWNCHANNEL, priv->channel);
754 printk(KERN_ERR "%s: Error %d setting channel\n", dev->name, err);
758 if (priv->has_ibss) {
759 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFCREATEIBSS,
762 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n", dev->name, err);
766 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)
767 && (!priv->has_ibss_any)) {
768 printk(KERN_WARNING "%s: This firmware requires an \
769 ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
770 /* With wvlan_cs, in this case, we would crash.
771 * hopefully, this driver will behave better...
776 /* Set the desired ESSID */
777 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
778 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
779 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
780 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
781 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
784 printk(KERN_ERR "%s: Error %d setting OWNSSID\n", dev->name, err);
787 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
788 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
791 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n", dev->name, err);
795 /* Set the station name */
796 idbuf.len = cpu_to_le16(strlen(priv->nick));
797 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
798 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
799 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
802 printk(KERN_ERR "%s: Error %d setting nickname\n", dev->name, err);
807 if (priv->has_sensitivity) {
808 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
811 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
812 "Disabling sensitivity control\n", dev->name, err);
814 priv->has_sensitivity = 0;
818 /* Set RTS threshold */
819 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, priv->rts_thresh);
821 printk(KERN_ERR "%s: Error %d setting RTS threshold\n", dev->name, err);
825 /* Set fragmentation threshold or MWO robustness */
827 err = hermes_write_wordrec(hw, USER_BAP,
828 HERMES_RID_CNFMWOROBUST_AGERE,
831 err = hermes_write_wordrec(hw, USER_BAP,
832 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
835 printk(KERN_ERR "%s: Error %d setting framentation\n", dev->name, err);
840 err = __orinoco_hw_set_bitrate(priv);
842 printk(KERN_ERR "%s: Error %d setting bitrate\n", dev->name, err);
846 /* Set power management */
848 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED,
851 printk(KERN_ERR "%s: Error %d setting up PM\n",
856 err = hermes_write_wordrec(hw, USER_BAP,
857 HERMES_RID_CNFMULTICASTRECEIVE,
860 printk(KERN_ERR "%s: Error %d setting up PM\n",
864 err = hermes_write_wordrec(hw, USER_BAP,
865 HERMES_RID_CNFMAXSLEEPDURATION,
868 printk(KERN_ERR "%s: Error %d setting up PM\n",
872 err = hermes_write_wordrec(hw, USER_BAP,
873 HERMES_RID_CNFPMHOLDOVERDURATION,
876 printk(KERN_ERR "%s: Error %d setting up PM\n",
882 /* Set preamble - only for Symbol so far... */
883 if (priv->has_preamble) {
884 err = hermes_write_wordrec(hw, USER_BAP,
885 HERMES_RID_CNFPREAMBLE_SYMBOL,
888 printk(KERN_ERR "%s: Error %d setting preamble\n",
894 /* Set up encryption */
896 err = __orinoco_hw_setup_wep(priv);
898 printk(KERN_ERR "%s: Error %d activating WEP\n",
904 /* Set promiscuity / multicast*/
905 priv->promiscuous = 0;
907 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
913 static int orinoco_reconfigure(struct net_device *dev)
915 struct orinoco_private *priv = netdev_priv(dev);
916 struct hermes *hw = &priv->hw;
920 if (priv->broken_disableport) {
921 schedule_work(&priv->reset_work);
925 err = orinoco_lock(priv, &flags);
930 err = hermes_disable_port(hw, 0);
932 printk(KERN_WARNING "%s: Unable to disable port while reconfiguring card\n",
934 priv->broken_disableport = 1;
938 err = __orinoco_program_rids(dev);
940 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
945 err = hermes_enable_port(hw, 0);
947 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
954 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
955 schedule_work(&priv->reset_work);
959 orinoco_unlock(priv, &flags);
964 /* This must be called from user context, without locks held - use
966 static void orinoco_reset(struct net_device *dev)
968 struct orinoco_private *priv = netdev_priv(dev);
969 struct hermes *hw = &priv->hw;
973 err = orinoco_lock(priv, &flags);
975 /* When the hardware becomes available again, whatever
976 * detects that is responsible for re-initializing
977 * it. So no need for anything further*/
980 netif_stop_queue(dev);
982 /* Shut off interrupts. Depending on what state the hardware
983 * is in, this might not work, but we'll try anyway */
984 hermes_set_irqmask(hw, 0);
985 hermes_write_regn(hw, EVACK, 0xffff);
987 priv->hw_unavailable++;
988 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
991 orinoco_unlock(priv, &flags);
993 if (priv->hard_reset)
994 err = (*priv->hard_reset)(priv);
996 printk(KERN_ERR "%s: orinoco_reset: Error %d performing hard reset\n",
998 /* FIXME: shutdown of some sort */
1002 err = orinoco_reinit_firmware(dev);
1004 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1009 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1011 priv->hw_unavailable--;
1013 /* priv->open or priv->hw_unavailable might have changed while
1014 * we dropped the lock */
1015 if (priv->open && (! priv->hw_unavailable)) {
1016 err = __orinoco_up(dev);
1018 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1021 dev->trans_start = jiffies;
1024 spin_unlock_irq(&priv->lock);
1029 /********************************************************************/
1030 /* Internal helper functions */
1031 /********************************************************************/
1034 set_port_type(struct orinoco_private *priv)
1036 switch (priv->iw_mode) {
1038 priv->port_type = 1;
1039 priv->createibss = 0;
1042 if (priv->prefer_port3) {
1043 priv->port_type = 3;
1044 priv->createibss = 0;
1046 priv->port_type = priv->ibss_port;
1047 priv->createibss = 1;
1051 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
1056 /* Does the frame have a SNAP header indicating it should be
1057 * de-encapsulated to Ethernet-II? */
1059 is_ethersnap(struct header_struct *hdr)
1061 /* We de-encapsulate all packets which, a) have SNAP headers
1062 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1063 * and where b) the OUI of the SNAP header is 00:00:00 or
1064 * 00:00:f8 - we need both because different APs appear to use
1065 * different OUIs for some reason */
1066 return (memcmp(&hdr->dsap, &encaps_hdr, 5) == 0)
1067 && ( (hdr->oui[2] == 0x00) || (hdr->oui[2] == 0xf8) );
1071 orinoco_set_multicast_list(struct net_device *dev)
1073 struct orinoco_private *priv = netdev_priv(dev);
1074 unsigned long flags;
1076 if (orinoco_lock(priv, &flags) != 0) {
1077 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
1078 "called when hw_unavailable\n", dev->name);
1082 __orinoco_set_multicast_list(dev);
1083 orinoco_unlock(priv, &flags);
1086 /********************************************************************/
1087 /* Hardware control functions */
1088 /********************************************************************/
1091 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1093 hermes_t *hw = &priv->hw;
1096 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1097 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1098 priv->ndev->name, priv->bitratemode);
1102 switch (priv->firmware_type) {
1103 case FIRMWARE_TYPE_AGERE:
1104 err = hermes_write_wordrec(hw, USER_BAP,
1105 HERMES_RID_CNFTXRATECONTROL,
1106 bitrate_table[priv->bitratemode].agere_txratectrl);
1108 case FIRMWARE_TYPE_INTERSIL:
1109 case FIRMWARE_TYPE_SYMBOL:
1110 err = hermes_write_wordrec(hw, USER_BAP,
1111 HERMES_RID_CNFTXRATECONTROL,
1112 bitrate_table[priv->bitratemode].intersil_txratectrl);
1122 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1124 hermes_t *hw = &priv->hw;
1126 int master_wep_flag;
1129 switch (priv->firmware_type) {
1130 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1132 err = hermes_write_wordrec(hw, USER_BAP,
1133 HERMES_RID_CNFTXKEY_AGERE,
1138 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1139 HERMES_RID_CNFWEPKEYS_AGERE,
1144 err = hermes_write_wordrec(hw, USER_BAP,
1145 HERMES_RID_CNFWEPENABLED_AGERE,
1151 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1152 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1153 master_wep_flag = 0; /* Off */
1158 /* Fudge around firmware weirdness */
1159 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1161 /* Write all 4 keys */
1162 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1163 /* int keylen = le16_to_cpu(priv->keys[i].len); */
1165 if (keylen > LARGE_KEY_SIZE) {
1166 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1167 priv->ndev->name, i, keylen);
1171 err = hermes_write_ltv(hw, USER_BAP,
1172 HERMES_RID_CNFDEFAULTKEY0 + i,
1173 HERMES_BYTES_TO_RECLEN(keylen),
1174 priv->keys[i].data);
1179 /* Write the index of the key used in transmission */
1180 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFWEPDEFAULTKEYID,
1185 if (priv->wep_restrict) {
1187 master_wep_flag = 3;
1189 /* Authentication is where Intersil and Symbol
1190 * firmware differ... */
1192 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
1193 master_wep_flag = 3; /* Symbol */
1195 master_wep_flag = 1; /* Intersil */
1199 err = hermes_write_wordrec(hw, USER_BAP,
1200 HERMES_RID_CNFAUTHENTICATION, auth_flag);
1205 /* Master WEP setting : on/off */
1206 err = hermes_write_wordrec(hw, USER_BAP,
1207 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1216 printk(KERN_ERR "%s: WEP enabled, although not supported!\n",
1225 static int orinoco_hw_get_bssid(struct orinoco_private *priv,
1228 hermes_t *hw = &priv->hw;
1230 unsigned long flags;
1232 err = orinoco_lock(priv, &flags);
1236 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1237 ETH_ALEN, NULL, buf);
1239 orinoco_unlock(priv, &flags);
1244 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
1245 char buf[IW_ESSID_MAX_SIZE+1])
1247 hermes_t *hw = &priv->hw;
1249 struct hermes_idstring essidbuf;
1250 char *p = (char *)(&essidbuf.val);
1252 unsigned long flags;
1254 err = orinoco_lock(priv, &flags);
1258 if (strlen(priv->desired_essid) > 0) {
1259 /* We read the desired SSID from the hardware rather
1260 than from priv->desired_essid, just in case the
1261 firmware is allowed to change it on us. I'm not
1263 /* My guess is that the OWNSSID should always be whatever
1264 * we set to the card, whereas CURRENT_SSID is the one that
1265 * may change... - Jean II */
1270 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
1271 HERMES_RID_CNFDESIREDSSID;
1273 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
1280 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
1281 sizeof(essidbuf), NULL, &essidbuf);
1286 len = le16_to_cpu(essidbuf.len);
1288 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
1289 memcpy(buf, p, len);
1293 orinoco_unlock(priv, &flags);
1298 static long orinoco_hw_get_freq(struct orinoco_private *priv)
1301 hermes_t *hw = &priv->hw;
1305 unsigned long flags;
1307 err = orinoco_lock(priv, &flags);
1311 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
1315 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
1321 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
1322 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
1323 priv->ndev->name, channel);
1328 freq = channel_frequency[channel-1] * 100000;
1331 orinoco_unlock(priv, &flags);
1335 return err ? err : freq;
1338 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
1339 int *numrates, s32 *rates, int max)
1341 hermes_t *hw = &priv->hw;
1342 struct hermes_idstring list;
1343 unsigned char *p = (unsigned char *)&list.val;
1347 unsigned long flags;
1349 err = orinoco_lock(priv, &flags);
1353 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
1354 sizeof(list), NULL, &list);
1355 orinoco_unlock(priv, &flags);
1360 num = le16_to_cpu(list.len);
1362 num = min(num, max);
1364 for (i = 0; i < num; i++) {
1365 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
1372 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
1374 printk(KERN_DEBUG "RX descriptor:\n");
1375 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
1376 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
1377 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
1378 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
1379 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
1380 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
1381 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
1383 printk(KERN_DEBUG "IEEE 802.11 header:\n");
1384 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
1385 frame->p80211.frame_ctl);
1386 printk(KERN_DEBUG " duration_id = 0x%04x\n",
1387 frame->p80211.duration_id);
1388 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
1389 frame->p80211.addr1[0], frame->p80211.addr1[1],
1390 frame->p80211.addr1[2], frame->p80211.addr1[3],
1391 frame->p80211.addr1[4], frame->p80211.addr1[5]);
1392 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
1393 frame->p80211.addr2[0], frame->p80211.addr2[1],
1394 frame->p80211.addr2[2], frame->p80211.addr2[3],
1395 frame->p80211.addr2[4], frame->p80211.addr2[5]);
1396 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
1397 frame->p80211.addr3[0], frame->p80211.addr3[1],
1398 frame->p80211.addr3[2], frame->p80211.addr3[3],
1399 frame->p80211.addr3[4], frame->p80211.addr3[5]);
1400 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
1401 frame->p80211.seq_ctl);
1402 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
1403 frame->p80211.addr4[0], frame->p80211.addr4[1],
1404 frame->p80211.addr4[2], frame->p80211.addr4[3],
1405 frame->p80211.addr4[4], frame->p80211.addr4[5]);
1406 printk(KERN_DEBUG " data_len = 0x%04x\n",
1407 frame->p80211.data_len);
1409 printk(KERN_DEBUG "IEEE 802.3 header:\n");
1410 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
1411 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
1412 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
1413 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
1414 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
1415 frame->p8023.h_source[0], frame->p8023.h_source[1],
1416 frame->p8023.h_source[2], frame->p8023.h_source[3],
1417 frame->p8023.h_source[4], frame->p8023.h_source[5]);
1418 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
1420 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
1421 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
1422 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
1423 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
1424 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
1425 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
1426 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
1433 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1435 struct net_device *dev = (struct net_device *)dev_id;
1436 struct orinoco_private *priv = netdev_priv(dev);
1437 hermes_t *hw = &priv->hw;
1438 int count = MAX_IRQLOOPS_PER_IRQ;
1440 /* These are used to detect a runaway interrupt situation */
1441 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1442 * we panic and shut down the hardware */
1443 static int last_irq_jiffy = 0; /* jiffies value the last time we were called */
1444 static int loops_this_jiffy = 0;
1445 unsigned long flags;
1447 if (orinoco_lock(priv, &flags) != 0) {
1448 /* If hw is unavailable - we don't know if the irq was
1453 evstat = hermes_read_regn(hw, EVSTAT);
1454 events = evstat & hw->inten;
1456 orinoco_unlock(priv, &flags);
1460 if (jiffies != last_irq_jiffy)
1461 loops_this_jiffy = 0;
1462 last_irq_jiffy = jiffies;
1464 while (events && count--) {
1465 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1466 printk(KERN_WARNING "%s: IRQ handler is looping too "
1467 "much! Resetting.\n", dev->name);
1468 /* Disable interrupts for now */
1469 hermes_set_irqmask(hw, 0);
1470 schedule_work(&priv->reset_work);
1474 /* Check the card hasn't been removed */
1475 if (! hermes_present(hw)) {
1476 DEBUG(0, "orinoco_interrupt(): card removed\n");
1480 if (events & HERMES_EV_TICK)
1481 __orinoco_ev_tick(dev, hw);
1482 if (events & HERMES_EV_WTERR)
1483 __orinoco_ev_wterr(dev, hw);
1484 if (events & HERMES_EV_INFDROP)
1485 __orinoco_ev_infdrop(dev, hw);
1486 if (events & HERMES_EV_INFO)
1487 __orinoco_ev_info(dev, hw);
1488 if (events & HERMES_EV_RX)
1489 __orinoco_ev_rx(dev, hw);
1490 if (events & HERMES_EV_TXEXC)
1491 __orinoco_ev_txexc(dev, hw);
1492 if (events & HERMES_EV_TX)
1493 __orinoco_ev_tx(dev, hw);
1494 if (events & HERMES_EV_ALLOC)
1495 __orinoco_ev_alloc(dev, hw);
1497 hermes_write_regn(hw, EVACK, events);
1499 evstat = hermes_read_regn(hw, EVSTAT);
1500 events = evstat & hw->inten;
1503 orinoco_unlock(priv, &flags);
1507 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1509 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1512 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1514 /* This seems to happen a fair bit under load, but ignoring it
1515 seems to work fine...*/
1516 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1520 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1522 printk(KERN_WARNING "%s: Information frame lost.\n", dev->name);
1525 static void print_linkstatus(struct net_device *dev, u16 status)
1529 if (suppress_linkstatus)
1533 case HERMES_LINKSTATUS_NOT_CONNECTED:
1534 s = "Not Connected";
1536 case HERMES_LINKSTATUS_CONNECTED:
1539 case HERMES_LINKSTATUS_DISCONNECTED:
1542 case HERMES_LINKSTATUS_AP_CHANGE:
1545 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1546 s = "AP Out of Range";
1548 case HERMES_LINKSTATUS_AP_IN_RANGE:
1551 case HERMES_LINKSTATUS_ASSOC_FAILED:
1552 s = "Association Failed";
1558 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1559 dev->name, s, status);
1562 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1564 struct orinoco_private *priv = netdev_priv(dev);
1569 } __attribute__ ((packed)) info;
1573 /* This is an answer to an INQUIRE command that we did earlier,
1574 * or an information "event" generated by the card
1575 * The controller return to us a pseudo frame containing
1576 * the information in question - Jean II */
1577 infofid = hermes_read_regn(hw, INFOFID);
1579 /* Read the info frame header - don't try too hard */
1580 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1583 printk(KERN_ERR "%s: error %d reading info frame. "
1584 "Frame dropped.\n", dev->name, err);
1588 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1589 type = le16_to_cpu(info.type);
1592 case HERMES_INQ_TALLIES: {
1593 struct hermes_tallies_frame tallies;
1594 struct iw_statistics *wstats = &priv->wstats;
1596 if (len > sizeof(tallies)) {
1597 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1599 len = sizeof(tallies);
1602 /* Read directly the data (no seek) */
1603 hermes_read_words(hw, HERMES_DATA1, (void *) &tallies,
1604 len / 2); /* FIXME: blech! */
1606 /* Increment our various counters */
1607 /* wstats->discard.nwid - no wrong BSSID stuff */
1608 wstats->discard.code +=
1609 le16_to_cpu(tallies.RxWEPUndecryptable);
1610 if (len == sizeof(tallies))
1611 wstats->discard.code +=
1612 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1613 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1614 wstats->discard.misc +=
1615 le16_to_cpu(tallies.TxDiscardsWrongSA);
1616 #if WIRELESS_EXT > 11
1617 wstats->discard.fragment +=
1618 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1619 wstats->discard.retries +=
1620 le16_to_cpu(tallies.TxRetryLimitExceeded);
1621 /* wstats->miss.beacon - no match */
1622 #endif /* WIRELESS_EXT > 11 */
1625 case HERMES_INQ_LINKSTATUS: {
1626 struct hermes_linkstatus linkstatus;
1629 if (len != sizeof(linkstatus)) {
1630 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1635 hermes_read_words(hw, HERMES_DATA1, (void *) &linkstatus,
1637 newstatus = le16_to_cpu(linkstatus.linkstatus);
1639 if ( (newstatus == HERMES_LINKSTATUS_CONNECTED)
1640 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1641 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE) )
1642 priv->connected = 1;
1643 else if ( (newstatus == HERMES_LINKSTATUS_NOT_CONNECTED)
1644 || (newstatus == HERMES_LINKSTATUS_DISCONNECTED)
1645 || (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE)
1646 || (newstatus == HERMES_LINKSTATUS_ASSOC_FAILED) )
1647 priv->connected = 0;
1649 if (newstatus != priv->last_linkstatus)
1650 print_linkstatus(dev, newstatus);
1652 priv->last_linkstatus = newstatus;
1656 printk(KERN_DEBUG "%s: Unknown information frame received (type %04x).\n",
1658 /* We don't actually do anything about it */
1663 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1665 struct orinoco_private *priv = netdev_priv(dev);
1666 struct net_device_stats *stats = &priv->stats;
1667 struct iw_statistics *wstats = &priv->wstats;
1668 struct sk_buff *skb = NULL;
1670 int length, data_len, data_off;
1672 struct hermes_rx_descriptor desc;
1673 struct header_struct hdr;
1677 rxfid = hermes_read_regn(hw, RXFID);
1679 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1682 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1683 "Frame dropped.\n", dev->name, err);
1688 status = le16_to_cpu(desc.status);
1690 if (status & HERMES_RXSTAT_ERR) {
1691 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1692 wstats->discard.code++;
1693 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1696 stats->rx_crc_errors++;
1697 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name);
1703 /* For now we ignore the 802.11 header completely, assuming
1704 that the card's firmware has handled anything vital */
1706 err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr),
1707 rxfid, HERMES_802_3_OFFSET);
1709 printk(KERN_ERR "%s: error %d reading frame header. "
1710 "Frame dropped.\n", dev->name, err);
1715 length = ntohs(hdr.len);
1718 if (length < 3) { /* No for even an 802.2 LLC header */
1719 /* At least on Symbol firmware with PCF we get quite a
1720 lot of these legitimately - Poll frames with no
1722 stats->rx_dropped++;
1725 if (length > IEEE802_11_DATA_LEN) {
1726 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1728 stats->rx_length_errors++;
1733 /* We need space for the packet data itself, plus an ethernet
1734 header, plus 2 bytes so we can align the IP header on a
1735 32bit boundary, plus 1 byte so we can read in odd length
1736 packets from the card, which has an IO granularity of 16
1738 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1740 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1745 skb_reserve(skb, 2); /* This way the IP header is aligned */
1747 /* Handle decapsulation
1748 * In most cases, the firmware tell us about SNAP frames.
1749 * For some reason, the SNAP frames sent by LinkSys APs
1750 * are not properly recognised by most firmwares.
1751 * So, check ourselves */
1752 if(((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1753 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1754 is_ethersnap(&hdr)) {
1755 /* These indicate a SNAP within 802.2 LLC within
1756 802.11 frame which we'll need to de-encapsulate to
1757 the original EthernetII frame. */
1759 if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */
1760 stats->rx_length_errors++;
1764 /* Remove SNAP header, reconstruct EthernetII frame */
1765 data_len = length - ENCAPS_OVERHEAD;
1766 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
1768 eh = (struct ethhdr *)skb_put(skb, ETH_HLEN);
1770 memcpy(eh, &hdr, 2 * ETH_ALEN);
1771 eh->h_proto = hdr.ethertype;
1773 /* All other cases indicate a genuine 802.3 frame. No
1774 decapsulation needed. We just throw the whole
1775 thing in, and hope the protocol layer can deal with
1778 data_off = HERMES_802_3_OFFSET;
1779 /* FIXME: we re-read from the card data we already read here */
1782 p = skb_put(skb, data_len);
1783 err = hermes_bap_pread(hw, IRQ_BAP, p, RUP_EVEN(data_len),
1786 printk(KERN_ERR "%s: error %d reading frame. "
1787 "Frame dropped.\n", dev->name, err);
1792 dev->last_rx = jiffies;
1794 skb->protocol = eth_type_trans(skb, dev);
1795 skb->ip_summed = CHECKSUM_NONE;
1797 /* Process the wireless stats if needed */
1798 orinoco_stat_gather(dev, skb, &desc);
1800 /* Pass the packet to the networking stack */
1802 stats->rx_packets++;
1803 stats->rx_bytes += length;
1808 stats->rx_dropped++;
1811 dev_kfree_skb_irq(skb);
1815 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1817 struct orinoco_private *priv = netdev_priv(dev);
1818 struct net_device_stats *stats = &priv->stats;
1819 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
1820 struct hermes_tx_descriptor desc;
1823 if (fid == DUMMY_FID)
1824 return; /* Nothing's really happened */
1826 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0);
1828 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1829 "(FID=%04X error %d)\n",
1830 dev->name, fid, err);
1832 DEBUG(1, "%s: Tx error, status %d\n",
1833 dev->name, le16_to_cpu(desc.status));
1838 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1841 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1843 struct orinoco_private *priv = netdev_priv(dev);
1844 struct net_device_stats *stats = &priv->stats;
1846 stats->tx_packets++;
1848 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1851 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1853 struct orinoco_private *priv = netdev_priv(dev);
1855 u16 fid = hermes_read_regn(hw, ALLOCFID);
1857 if (fid != priv->txfid) {
1858 if (fid != DUMMY_FID)
1859 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1863 netif_wake_queue(dev);
1866 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1870 u16 id, variant, major, minor;
1871 } __attribute__ ((packed));
1873 static int determine_firmware_type(struct net_device *dev, struct sta_id *sta_id)
1875 /* FIXME: this is fundamentally broken */
1876 unsigned int firmver = ((u32)sta_id->major << 16) | sta_id->minor;
1878 if (sta_id->variant == 1)
1879 return FIRMWARE_TYPE_AGERE;
1880 else if ((sta_id->variant == 2) &&
1881 ((firmver == 0x10001) || (firmver == 0x20001)))
1882 return FIRMWARE_TYPE_SYMBOL;
1884 return FIRMWARE_TYPE_INTERSIL;
1887 static void determine_firmware(struct net_device *dev)
1889 struct orinoco_private *priv = netdev_priv(dev);
1890 hermes_t *hw = &priv->hw;
1892 struct sta_id sta_id;
1893 unsigned int firmver;
1894 char tmp[SYMBOL_MAX_VER_LEN+1];
1896 /* Get the firmware version */
1897 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
1899 printk(KERN_WARNING "%s: Error %d reading firmware info. Wildly guessing capabilities...\n",
1901 memset(&sta_id, 0, sizeof(sta_id));
1903 le16_to_cpus(&sta_id.id);
1904 le16_to_cpus(&sta_id.variant);
1905 le16_to_cpus(&sta_id.major);
1906 le16_to_cpus(&sta_id.minor);
1908 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
1909 dev->name, sta_id.id, sta_id.variant,
1910 sta_id.major, sta_id.minor);
1912 if (! priv->firmware_type)
1913 priv->firmware_type = determine_firmware_type(dev, &sta_id);
1915 /* Default capabilities */
1916 priv->has_sensitivity = 1;
1918 priv->has_preamble = 0;
1919 priv->has_port3 = 1;
1921 priv->has_ibss_any = 0;
1923 priv->has_big_wep = 0;
1925 /* Determine capabilities from the firmware version */
1926 switch (priv->firmware_type) {
1927 case FIRMWARE_TYPE_AGERE:
1928 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
1929 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
1930 printk(KERN_DEBUG "%s: Looks like a Lucent/Agere firmware "
1931 "version %d.%02d\n", dev->name,
1932 sta_id.major, sta_id.minor);
1934 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
1936 priv->has_ibss = (firmver >= 0x60006);
1937 priv->has_ibss_any = (firmver >= 0x60010);
1938 priv->has_wep = (firmver >= 0x40020);
1939 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
1940 Gold cards from the others? */
1941 priv->has_mwo = (firmver >= 0x60000);
1942 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
1943 priv->ibss_port = 1;
1945 /* Tested with Agere firmware :
1946 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
1947 * Tested CableTron firmware : 4.32 => Anton */
1949 case FIRMWARE_TYPE_SYMBOL:
1950 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
1951 /* Intel MAC : 00:02:B3:* */
1952 /* 3Com MAC : 00:50:DA:* */
1953 memset(tmp, 0, sizeof(tmp));
1954 /* Get the Symbol firmware version */
1955 err = hermes_read_ltv(hw, USER_BAP,
1956 HERMES_RID_SECONDARYVERSION_SYMBOL,
1957 SYMBOL_MAX_VER_LEN, NULL, &tmp);
1960 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
1965 /* The firmware revision is a string, the format is
1966 * something like : "V2.20-01".
1967 * Quick and dirty parsing... - Jean II
1969 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
1970 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
1973 tmp[SYMBOL_MAX_VER_LEN] = '\0';
1976 printk(KERN_DEBUG "%s: Looks like a Symbol firmware "
1977 "version [%s] (parsing to %X)\n", dev->name,
1980 priv->has_ibss = (firmver >= 0x20000);
1981 priv->has_wep = (firmver >= 0x15012);
1982 priv->has_big_wep = (firmver >= 0x20000);
1983 priv->has_pm = (firmver >= 0x20000) && (firmver < 0x22000);
1984 priv->has_preamble = (firmver >= 0x20000);
1985 priv->ibss_port = 4;
1986 /* Tested with Intel firmware : 0x20015 => Jean II */
1987 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
1989 case FIRMWARE_TYPE_INTERSIL:
1990 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
1991 * Samsung, Compaq 100/200 and Proxim are slightly
1992 * different and less well tested */
1993 /* D-Link MAC : 00:40:05:* */
1994 /* Addtron MAC : 00:90:D1:* */
1995 printk(KERN_DEBUG "%s: Looks like an Intersil firmware "
1996 "version %d.%d.%d\n", dev->name,
1997 sta_id.major, sta_id.minor, sta_id.variant);
1999 firmver = ((unsigned long)sta_id.major << 16) |
2000 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2002 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2003 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2004 priv->has_pm = (firmver >= 0x000700);
2006 if (firmver >= 0x000800)
2007 priv->ibss_port = 0;
2009 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2010 "than v0.8.x - several features not supported\n",
2012 priv->ibss_port = 1;
2021 * struct net_device methods
2025 orinoco_init(struct net_device *dev)
2027 struct orinoco_private *priv = netdev_priv(dev);
2028 hermes_t *hw = &priv->hw;
2030 struct hermes_idstring nickbuf;
2034 TRACE_ENTER(dev->name);
2036 /* No need to lock, the hw_unavailable flag is already set in
2037 * alloc_orinocodev() */
2038 priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN;
2040 /* Initialize the firmware */
2041 err = hermes_init(hw);
2043 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2048 determine_firmware(dev);
2050 if (priv->has_port3)
2051 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2053 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2055 if (priv->has_wep) {
2056 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2057 if (priv->has_big_wep)
2058 printk("104-bit key\n");
2060 printk("40-bit key\n");
2063 /* Get the MAC address */
2064 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2065 ETH_ALEN, NULL, dev->dev_addr);
2067 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2072 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2073 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2074 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2077 /* Get the station name */
2078 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2079 sizeof(nickbuf), &reclen, &nickbuf);
2081 printk(KERN_ERR "%s: failed to read station name\n",
2086 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2088 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2089 memcpy(priv->nick, &nickbuf.val, len);
2090 priv->nick[len] = '\0';
2092 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2094 /* Get allowed channels */
2095 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2096 &priv->channel_mask);
2098 printk(KERN_ERR "%s: failed to read channel list!\n",
2103 /* Get initial AP density */
2104 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2106 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2107 priv->has_sensitivity = 0;
2110 /* Get initial RTS threshold */
2111 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2114 printk(KERN_ERR "%s: failed to read RTS threshold!\n", dev->name);
2118 /* Get initial fragmentation settings */
2120 err = hermes_read_wordrec(hw, USER_BAP,
2121 HERMES_RID_CNFMWOROBUST_AGERE,
2124 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2125 &priv->frag_thresh);
2127 printk(KERN_ERR "%s: failed to read fragmentation settings!\n", dev->name);
2131 /* Power management setup */
2135 err = hermes_read_wordrec(hw, USER_BAP,
2136 HERMES_RID_CNFMAXSLEEPDURATION,
2139 printk(KERN_ERR "%s: failed to read power management period!\n",
2143 err = hermes_read_wordrec(hw, USER_BAP,
2144 HERMES_RID_CNFPMHOLDOVERDURATION,
2147 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2153 /* Preamble setup */
2154 if (priv->has_preamble) {
2155 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPREAMBLE_SYMBOL,
2161 /* Set up the default configuration */
2162 priv->iw_mode = IW_MODE_INFRA;
2163 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2164 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2165 set_port_type(priv);
2166 priv->channel = 10; /* default channel, more-or-less arbitrary */
2168 priv->promiscuous = 0;
2172 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2174 /* Try workaround for old Symbol firmware bug */
2175 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2176 "(old Symbol firmware?). Trying to work around... ",
2179 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2180 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2182 printk("failed!\n");
2187 printk("%s: Error %d allocating Tx buffer\n", dev->name, err);
2191 /* Make the hardware available, as long as it hasn't been
2192 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2193 spin_lock_irq(&priv->lock);
2194 priv->hw_unavailable--;
2195 spin_unlock_irq(&priv->lock);
2197 printk(KERN_DEBUG "%s: ready\n", dev->name);
2200 TRACE_EXIT(dev->name);
2204 struct net_device_stats *
2205 orinoco_get_stats(struct net_device *dev)
2207 struct orinoco_private *priv = netdev_priv(dev);
2209 return &priv->stats;
2212 struct iw_statistics *
2213 orinoco_get_wireless_stats(struct net_device *dev)
2215 struct orinoco_private *priv = netdev_priv(dev);
2216 hermes_t *hw = &priv->hw;
2217 struct iw_statistics *wstats = &priv->wstats;
2219 unsigned long flags;
2221 if (! netif_device_present(dev)) {
2222 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
2224 return NULL; /* FIXME: Can we do better than this? */
2227 err = orinoco_lock(priv, &flags);
2229 return NULL; /* FIXME: Erg, we've been signalled, how
2230 * do we propagate this back up? */
2232 if (priv->iw_mode == IW_MODE_ADHOC) {
2233 memset(&wstats->qual, 0, sizeof(wstats->qual));
2234 /* If a spy address is defined, we report stats of the
2235 * first spy address - Jean II */
2236 if (SPY_NUMBER(priv)) {
2237 wstats->qual.qual = priv->spy_stat[0].qual;
2238 wstats->qual.level = priv->spy_stat[0].level;
2239 wstats->qual.noise = priv->spy_stat[0].noise;
2240 wstats->qual.updated = priv->spy_stat[0].updated;
2244 u16 qual, signal, noise;
2245 } __attribute__ ((packed)) cq;
2247 err = HERMES_READ_RECORD(hw, USER_BAP,
2248 HERMES_RID_COMMSQUALITY, &cq);
2250 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
2251 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
2252 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
2253 wstats->qual.updated = 7;
2256 /* We can't really wait for the tallies inquiry command to
2257 * complete, so we just use the previous results and trigger
2258 * a new tallies inquiry command for next time - Jean II */
2259 /* FIXME: We're in user context (I think?), so we should just
2260 wait for the tallies to come through */
2261 err = hermes_inquire(hw, HERMES_INQ_TALLIES);
2263 orinoco_unlock(priv, &flags);
2271 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
2272 int level, int noise)
2274 struct orinoco_private *priv = netdev_priv(dev);
2277 /* Gather wireless spy statistics: for each packet, compare the
2278 * source address with out list, and if match, get the stats... */
2279 for (i = 0; i < priv->spy_number; i++)
2280 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
2281 priv->spy_stat[i].level = level - 0x95;
2282 priv->spy_stat[i].noise = noise - 0x95;
2283 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
2284 priv->spy_stat[i].updated = 7;
2289 orinoco_stat_gather(struct net_device *dev,
2290 struct sk_buff *skb,
2291 struct hermes_rx_descriptor *desc)
2293 struct orinoco_private *priv = netdev_priv(dev);
2295 /* Using spy support with lots of Rx packets, like in an
2296 * infrastructure (AP), will really slow down everything, because
2297 * the MAC address must be compared to each entry of the spy list.
2298 * If the user really asks for it (set some address in the
2299 * spy list), we do it, but he will pay the price.
2300 * Note that to get here, you need both WIRELESS_SPY
2301 * compiled in AND some addresses in the list !!!
2303 /* Note : gcc will optimise the whole section away if
2304 * WIRELESS_SPY is not defined... - Jean II */
2305 if (SPY_NUMBER(priv)) {
2306 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
2307 desc->signal, desc->silence);
2312 orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
2314 struct orinoco_private *priv = netdev_priv(dev);
2315 struct net_device_stats *stats = &priv->stats;
2316 hermes_t *hw = &priv->hw;
2318 u16 txfid = priv->txfid;
2321 int len, data_len, data_off;
2322 struct hermes_tx_descriptor desc;
2323 unsigned long flags;
2325 TRACE_ENTER(dev->name);
2327 if (! netif_running(dev)) {
2328 printk(KERN_ERR "%s: Tx on stopped device!\n",
2330 TRACE_EXIT(dev->name);
2334 if (netif_queue_stopped(dev)) {
2335 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
2337 TRACE_EXIT(dev->name);
2341 if (orinoco_lock(priv, &flags) != 0) {
2342 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
2344 TRACE_EXIT(dev->name);
2349 if (! priv->connected) {
2350 /* Oops, the firmware hasn't established a connection,
2351 silently drop the packet (this seems to be the
2352 safest approach). */
2354 orinoco_unlock(priv, &flags);
2356 TRACE_EXIT(dev->name);
2360 /* Length of the packet body */
2361 /* FIXME: what if the skb is smaller than this? */
2362 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
2364 eh = (struct ethhdr *)skb->data;
2366 memset(&desc, 0, sizeof(desc));
2367 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
2368 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
2370 printk(KERN_ERR "%s: Error %d writing Tx descriptor to BAP\n",
2376 /* Clear the 802.11 header and data length fields - some
2377 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
2378 * if this isn't done. */
2379 hermes_clear_words(hw, HERMES_DATA0,
2380 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
2382 /* Encapsulate Ethernet-II frames */
2383 if (ntohs(eh->h_proto) > 1500) { /* Ethernet-II frame */
2384 struct header_struct hdr;
2386 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
2387 p = skb->data + ETH_HLEN;
2390 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
2391 memcpy(hdr.src, eh->h_source, ETH_ALEN);
2392 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
2395 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
2397 hdr.ethertype = eh->h_proto;
2398 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
2399 txfid, HERMES_802_3_OFFSET);
2401 printk(KERN_ERR "%s: Error %d writing packet header to BAP\n",
2406 } else { /* IEEE 802.3 frame */
2407 data_len = len + ETH_HLEN;
2408 data_off = HERMES_802_3_OFFSET;
2412 /* Round up for odd length packets */
2413 err = hermes_bap_pwrite(hw, USER_BAP, p, RUP_EVEN(data_len), txfid, data_off);
2415 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
2421 /* Finally, we actually initiate the send */
2422 netif_stop_queue(dev);
2424 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, txfid, NULL);
2426 netif_start_queue(dev);
2427 printk(KERN_ERR "%s: Error %d transmitting packet\n", dev->name, err);
2432 dev->trans_start = jiffies;
2433 stats->tx_bytes += data_off + data_len;
2435 orinoco_unlock(priv, &flags);
2439 TRACE_EXIT(dev->name);
2443 TRACE_EXIT(dev->name);
2445 orinoco_unlock(priv, &flags);
2450 orinoco_tx_timeout(struct net_device *dev)
2452 struct orinoco_private *priv = netdev_priv(dev);
2453 struct net_device_stats *stats = &priv->stats;
2454 struct hermes *hw = &priv->hw;
2456 printk(KERN_WARNING "%s: Tx timeout! "
2457 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
2458 dev->name, hermes_read_regn(hw, ALLOCFID),
2459 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
2463 schedule_work(&priv->reset_work);
2467 orinoco_change_mtu(struct net_device *dev, int new_mtu)
2469 struct orinoco_private *priv = netdev_priv(dev);
2471 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
2474 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) >
2475 (priv->nicbuf_size - ETH_HLEN) )
2483 /* FIXME: return int? */
2485 __orinoco_set_multicast_list(struct net_device *dev)
2487 struct orinoco_private *priv = netdev_priv(dev);
2488 hermes_t *hw = &priv->hw;
2490 int promisc, mc_count;
2492 /* The Hermes doesn't seem to have an allmulti mode, so we go
2493 * into promiscuous mode and let the upper levels deal. */
2494 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2495 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2500 mc_count = dev->mc_count;
2503 if (promisc != priv->promiscuous) {
2504 err = hermes_write_wordrec(hw, USER_BAP,
2505 HERMES_RID_CNFPROMISCUOUSMODE,
2508 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2511 priv->promiscuous = promisc;
2514 if (! promisc && (mc_count || priv->mc_count) ) {
2515 struct dev_mc_list *p = dev->mc_list;
2516 hermes_multicast_t mclist;
2519 for (i = 0; i < mc_count; i++) {
2522 BUG(); /* Multicast list shorter than mc_count */
2523 if (p->dmi_addrlen != ETH_ALEN)
2524 BUG(); /* Bad address size in multicast list */
2526 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2531 printk(KERN_WARNING "Multicast list is longer than mc_count\n");
2533 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2534 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2537 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2540 priv->mc_count = mc_count;
2543 /* Since we can set the promiscuous flag when it wasn't asked
2544 for, make sure the net_device knows about it. */
2545 if (priv->promiscuous)
2546 dev->flags |= IFF_PROMISC;
2548 dev->flags &= ~IFF_PROMISC;
2551 /********************************************************************/
2552 /* Wireless extensions support */
2553 /********************************************************************/
2555 static int orinoco_ioctl_getiwrange(struct net_device *dev, struct iw_point *rrq)
2557 struct orinoco_private *priv = netdev_priv(dev);
2560 struct iw_range range;
2563 unsigned long flags;
2565 TRACE_ENTER(dev->name);
2567 err = verify_area(VERIFY_WRITE, rrq->pointer, sizeof(range));
2571 rrq->length = sizeof(range);
2573 err = orinoco_lock(priv, &flags);
2577 mode = priv->iw_mode;
2578 orinoco_unlock(priv, &flags);
2580 memset(&range, 0, sizeof(range));
2582 /* Much of this shamelessly taken from wvlan_cs.c. No idea
2583 * what it all means -dgibson */
2584 #if WIRELESS_EXT > 10
2585 range.we_version_compiled = WIRELESS_EXT;
2586 range.we_version_source = 11;
2587 #endif /* WIRELESS_EXT > 10 */
2589 range.min_nwid = range.max_nwid = 0; /* We don't use nwids */
2591 /* Set available channels/frequencies */
2592 range.num_channels = NUM_CHANNELS;
2594 for (i = 0; i < NUM_CHANNELS; i++) {
2595 if (priv->channel_mask & (1 << i)) {
2596 range.freq[k].i = i + 1;
2597 range.freq[k].m = channel_frequency[i] * 100000;
2598 range.freq[k].e = 1;
2602 if (k >= IW_MAX_FREQUENCIES)
2605 range.num_frequency = k;
2607 range.sensitivity = 3;
2609 if ((mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2610 /* Quality stats meaningless in ad-hoc mode */
2611 range.max_qual.qual = 0;
2612 range.max_qual.level = 0;
2613 range.max_qual.noise = 0;
2614 #if WIRELESS_EXT > 11
2615 range.avg_qual.qual = 0;
2616 range.avg_qual.level = 0;
2617 range.avg_qual.noise = 0;
2618 #endif /* WIRELESS_EXT > 11 */
2621 range.max_qual.qual = 0x8b - 0x2f;
2622 range.max_qual.level = 0x2f - 0x95 - 1;
2623 range.max_qual.noise = 0x2f - 0x95 - 1;
2624 #if WIRELESS_EXT > 11
2625 /* Need to get better values */
2626 range.avg_qual.qual = 0x24;
2627 range.avg_qual.level = 0xC2;
2628 range.avg_qual.noise = 0x9E;
2629 #endif /* WIRELESS_EXT > 11 */
2632 err = orinoco_hw_get_bitratelist(priv, &numrates,
2633 range.bitrate, IW_MAX_BITRATES);
2636 range.num_bitrates = numrates;
2638 /* Set an indication of the max TCP throughput in bit/s that we can
2639 * expect using this interface. May be use for QoS stuff...
2642 range.throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2644 range.throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2647 range.max_rts = 2347;
2648 range.min_frag = 256;
2649 range.max_frag = 2346;
2651 err = orinoco_lock(priv, &flags);
2654 if (priv->has_wep) {
2655 range.max_encoding_tokens = ORINOCO_MAX_KEYS;
2657 range.encoding_size[0] = SMALL_KEY_SIZE;
2658 range.num_encoding_sizes = 1;
2660 if (priv->has_big_wep) {
2661 range.encoding_size[1] = LARGE_KEY_SIZE;
2662 range.num_encoding_sizes = 2;
2665 range.num_encoding_sizes = 0;
2666 range.max_encoding_tokens = 0;
2668 orinoco_unlock(priv, &flags);
2671 range.max_pmp = 65535000;
2673 range.max_pmt = 65535 * 1000; /* ??? */
2674 range.pmp_flags = IW_POWER_PERIOD;
2675 range.pmt_flags = IW_POWER_TIMEOUT;
2676 range.pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2678 range.num_txpower = 1;
2679 range.txpower[0] = 15; /* 15dBm */
2680 range.txpower_capa = IW_TXPOW_DBM;
2682 #if WIRELESS_EXT > 10
2683 range.retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2684 range.retry_flags = IW_RETRY_LIMIT;
2685 range.r_time_flags = IW_RETRY_LIFETIME;
2686 range.min_retry = 0;
2687 range.max_retry = 65535; /* ??? */
2688 range.min_r_time = 0;
2689 range.max_r_time = 65535 * 1000; /* ??? */
2690 #endif /* WIRELESS_EXT > 10 */
2692 if (copy_to_user(rrq->pointer, &range, sizeof(range)))
2695 TRACE_EXIT(dev->name);
2700 static int orinoco_ioctl_setiwencode(struct net_device *dev, struct iw_point *erq)
2702 struct orinoco_private *priv = netdev_priv(dev);
2703 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2704 int setindex = priv->tx_key;
2705 int enable = priv->wep_on;
2706 int restricted = priv->wep_restrict;
2709 char keybuf[ORINOCO_MAX_KEY_SIZE];
2710 unsigned long flags;
2713 /* We actually have a key to set */
2714 if ( (erq->length < SMALL_KEY_SIZE) || (erq->length > ORINOCO_MAX_KEY_SIZE) )
2717 if (copy_from_user(keybuf, erq->pointer, erq->length))
2721 err = orinoco_lock(priv, &flags);
2726 if (erq->length > ORINOCO_MAX_KEY_SIZE) {
2731 if ( (erq->length > LARGE_KEY_SIZE)
2732 || ( ! priv->has_big_wep && (erq->length > SMALL_KEY_SIZE)) ) {
2737 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2738 index = priv->tx_key;
2740 if (erq->length > SMALL_KEY_SIZE) {
2741 xlen = LARGE_KEY_SIZE;
2742 } else if (erq->length > 0) {
2743 xlen = SMALL_KEY_SIZE;
2747 /* Switch on WEP if off */
2748 if ((!enable) && (xlen > 0)) {
2753 /* Important note : if the user do "iwconfig eth0 enc off",
2754 * we will arrive there with an index of -1. This is valid
2755 * but need to be taken care off... Jean II */
2756 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2757 if((index != -1) || (erq->flags == 0)) {
2762 /* Set the index : Check that the key is valid */
2763 if(priv->keys[index].len == 0) {
2771 if (erq->flags & IW_ENCODE_DISABLED)
2773 /* Only for Prism2 & Symbol cards (so far) - Jean II */
2774 if (erq->flags & IW_ENCODE_OPEN)
2776 if (erq->flags & IW_ENCODE_RESTRICTED)
2780 priv->keys[index].len = cpu_to_le16(xlen);
2781 memset(priv->keys[index].data, 0, sizeof(priv->keys[index].data));
2782 memcpy(priv->keys[index].data, keybuf, erq->length);
2784 priv->tx_key = setindex;
2785 priv->wep_on = enable;
2786 priv->wep_restrict = restricted;
2790 orinoco_unlock(priv, &flags);
2795 static int orinoco_ioctl_getiwencode(struct net_device *dev, struct iw_point *erq)
2797 struct orinoco_private *priv = netdev_priv(dev);
2798 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2800 char keybuf[ORINOCO_MAX_KEY_SIZE];
2802 unsigned long flags;
2804 err = orinoco_lock(priv, &flags);
2808 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2809 index = priv->tx_key;
2813 erq->flags |= IW_ENCODE_DISABLED;
2814 erq->flags |= index + 1;
2816 /* Only for symbol cards - Jean II */
2817 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
2818 if(priv->wep_restrict)
2819 erq->flags |= IW_ENCODE_RESTRICTED;
2821 erq->flags |= IW_ENCODE_OPEN;
2824 xlen = le16_to_cpu(priv->keys[index].len);
2829 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2832 orinoco_unlock(priv, &flags);
2835 if (copy_to_user(erq->pointer, keybuf, xlen))
2842 static int orinoco_ioctl_setessid(struct net_device *dev, struct iw_point *erq)
2844 struct orinoco_private *priv = netdev_priv(dev);
2845 char essidbuf[IW_ESSID_MAX_SIZE+1];
2847 unsigned long flags;
2849 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2850 * anyway... - Jean II */
2852 memset(&essidbuf, 0, sizeof(essidbuf));
2855 if (erq->length > IW_ESSID_MAX_SIZE)
2858 if (copy_from_user(&essidbuf, erq->pointer, erq->length))
2861 essidbuf[erq->length] = '\0';
2864 err = orinoco_lock(priv, &flags);
2868 memcpy(priv->desired_essid, essidbuf, sizeof(priv->desired_essid));
2870 orinoco_unlock(priv, &flags);
2875 static int orinoco_ioctl_getessid(struct net_device *dev, struct iw_point *erq)
2877 struct orinoco_private *priv = netdev_priv(dev);
2878 char essidbuf[IW_ESSID_MAX_SIZE+1];
2881 unsigned long flags;
2883 TRACE_ENTER(dev->name);
2885 if (netif_running(dev)) {
2886 err = orinoco_hw_get_essid(priv, &active, essidbuf);
2890 err = orinoco_lock(priv, &flags);
2893 memcpy(essidbuf, priv->desired_essid, sizeof(essidbuf));
2894 orinoco_unlock(priv, &flags);
2898 erq->length = strlen(essidbuf) + 1;
2900 if (copy_to_user(erq->pointer, essidbuf, erq->length))
2903 TRACE_EXIT(dev->name);
2908 static int orinoco_ioctl_setnick(struct net_device *dev, struct iw_point *nrq)
2910 struct orinoco_private *priv = netdev_priv(dev);
2911 char nickbuf[IW_ESSID_MAX_SIZE+1];
2913 unsigned long flags;
2915 if (nrq->length > IW_ESSID_MAX_SIZE)
2918 memset(nickbuf, 0, sizeof(nickbuf));
2920 if (copy_from_user(nickbuf, nrq->pointer, nrq->length))
2923 nickbuf[nrq->length] = '\0';
2925 err = orinoco_lock(priv, &flags);
2929 memcpy(priv->nick, nickbuf, sizeof(priv->nick));
2931 orinoco_unlock(priv, &flags);
2936 static int orinoco_ioctl_getnick(struct net_device *dev, struct iw_point *nrq)
2938 struct orinoco_private *priv = netdev_priv(dev);
2939 char nickbuf[IW_ESSID_MAX_SIZE+1];
2941 unsigned long flags;
2943 err = orinoco_lock(priv, &flags);
2947 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
2948 orinoco_unlock(priv, &flags);
2950 nrq->length = strlen(nickbuf)+1;
2952 if (copy_to_user(nrq->pointer, nickbuf, sizeof(nickbuf)))
2958 static int orinoco_ioctl_setfreq(struct net_device *dev, struct iw_freq *frq)
2960 struct orinoco_private *priv = netdev_priv(dev);
2963 unsigned long flags;
2965 /* We can only use this in Ad-Hoc demo mode to set the operating
2966 * frequency, or in IBSS mode to set the frequency where the IBSS
2967 * will be created - Jean II */
2968 if (priv->iw_mode != IW_MODE_ADHOC)
2971 if ( (frq->e == 0) && (frq->m <= 1000) ) {
2972 /* Setting by channel number */
2975 /* Setting by frequency - search the table */
2979 for (i = 0; i < (6 - frq->e); i++)
2982 for (i = 0; i < NUM_CHANNELS; i++)
2983 if (frq->m == (channel_frequency[i] * mult))
2987 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
2988 ! (priv->channel_mask & (1 << (chan-1)) ) )
2991 err = orinoco_lock(priv, &flags);
2994 priv->channel = chan;
2995 orinoco_unlock(priv, &flags);
3000 static int orinoco_ioctl_getsens(struct net_device *dev, struct iw_param *srq)
3002 struct orinoco_private *priv = netdev_priv(dev);
3003 hermes_t *hw = &priv->hw;
3006 unsigned long flags;
3008 if (!priv->has_sensitivity)
3011 err = orinoco_lock(priv, &flags);
3014 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, &val);
3015 orinoco_unlock(priv, &flags);
3021 srq->fixed = 0; /* auto */
3026 static int orinoco_ioctl_setsens(struct net_device *dev, struct iw_param *srq)
3028 struct orinoco_private *priv = netdev_priv(dev);
3029 int val = srq->value;
3031 unsigned long flags;
3033 if (!priv->has_sensitivity)
3036 if ((val < 1) || (val > 3))
3039 err = orinoco_lock(priv, &flags);
3042 priv->ap_density = val;
3043 orinoco_unlock(priv, &flags);
3048 static int orinoco_ioctl_setrts(struct net_device *dev, struct iw_param *rrq)
3050 struct orinoco_private *priv = netdev_priv(dev);
3051 int val = rrq->value;
3053 unsigned long flags;
3058 if ( (val < 0) || (val > 2347) )
3061 err = orinoco_lock(priv, &flags);
3065 priv->rts_thresh = val;
3066 orinoco_unlock(priv, &flags);
3071 static int orinoco_ioctl_setfrag(struct net_device *dev, struct iw_param *frq)
3073 struct orinoco_private *priv = netdev_priv(dev);
3075 unsigned long flags;
3077 err = orinoco_lock(priv, &flags);
3081 if (priv->has_mwo) {
3083 priv->mwo_robust = 0;
3086 printk(KERN_WARNING "%s: Fixed fragmentation not \
3087 supported on this firmware. Using MWO robust instead.\n", dev->name);
3088 priv->mwo_robust = 1;
3092 priv->frag_thresh = 2346;
3094 if ( (frq->value < 256) || (frq->value > 2346) )
3097 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3101 orinoco_unlock(priv, &flags);
3106 static int orinoco_ioctl_getfrag(struct net_device *dev, struct iw_param *frq)
3108 struct orinoco_private *priv = netdev_priv(dev);
3109 hermes_t *hw = &priv->hw;
3112 unsigned long flags;
3114 err = orinoco_lock(priv, &flags);
3118 if (priv->has_mwo) {
3119 err = hermes_read_wordrec(hw, USER_BAP,
3120 HERMES_RID_CNFMWOROBUST_AGERE,
3125 frq->value = val ? 2347 : 0;
3126 frq->disabled = ! val;
3129 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3135 frq->disabled = (val >= 2346);
3139 orinoco_unlock(priv, &flags);
3144 static int orinoco_ioctl_setrate(struct net_device *dev, struct iw_param *rrq)
3146 struct orinoco_private *priv = netdev_priv(dev);
3149 int bitrate; /* 100s of kilobits */
3151 unsigned long flags;
3153 /* As the user space doesn't know our highest rate, it uses -1
3154 * to ask us to set the highest rate. Test it using "iwconfig
3155 * ethX rate auto" - Jean II */
3156 if (rrq->value == -1)
3159 if (rrq->value % 100000)
3161 bitrate = rrq->value / 100000;
3164 if ( (bitrate != 10) && (bitrate != 20) &&
3165 (bitrate != 55) && (bitrate != 110) )
3168 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3169 if ( (bitrate_table[i].bitrate == bitrate) &&
3170 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3178 err = orinoco_lock(priv, &flags);
3181 priv->bitratemode = ratemode;
3182 orinoco_unlock(priv, &flags);
3187 static int orinoco_ioctl_getrate(struct net_device *dev, struct iw_param *rrq)
3189 struct orinoco_private *priv = netdev_priv(dev);
3190 hermes_t *hw = &priv->hw;
3195 unsigned long flags;
3197 err = orinoco_lock(priv, &flags);
3201 ratemode = priv->bitratemode;
3203 if ( (ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE) )
3206 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3207 rrq->fixed = ! bitrate_table[ratemode].automatic;
3210 /* If the interface is running we try to find more about the
3212 if (netif_running(dev)) {
3213 err = hermes_read_wordrec(hw, USER_BAP,
3214 HERMES_RID_CURRENTTXRATE, &val);
3218 switch (priv->firmware_type) {
3219 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3220 /* Note : in Lucent firmware, the return value of
3221 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3222 * and therefore is totally different from the
3223 * encoding of HERMES_RID_CNFTXRATECONTROL.
3224 * Don't forget that 6Mb/s is really 5.5Mb/s */
3226 rrq->value = 5500000;
3228 rrq->value = val * 1000000;
3230 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3231 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3232 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3233 if (bitrate_table[i].intersil_txratectrl == val) {
3237 if (i >= BITRATE_TABLE_SIZE)
3238 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3241 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3249 orinoco_unlock(priv, &flags);
3254 static int orinoco_ioctl_setpower(struct net_device *dev, struct iw_param *prq)
3256 struct orinoco_private *priv = netdev_priv(dev);
3258 unsigned long flags;
3260 err = orinoco_lock(priv, &flags);
3264 if (prq->disabled) {
3267 switch (prq->flags & IW_POWER_MODE) {
3268 case IW_POWER_UNICAST_R:
3272 case IW_POWER_ALL_R:
3277 /* No flags : but we may have a value - Jean II */
3285 if (prq->flags & IW_POWER_TIMEOUT) {
3287 priv->pm_timeout = prq->value / 1000;
3289 if (prq->flags & IW_POWER_PERIOD) {
3291 priv->pm_period = prq->value / 1000;
3293 /* It's valid to not have a value if we are just toggling
3294 * the flags... Jean II */
3302 orinoco_unlock(priv, &flags);
3307 static int orinoco_ioctl_getpower(struct net_device *dev, struct iw_param *prq)
3309 struct orinoco_private *priv = netdev_priv(dev);
3310 hermes_t *hw = &priv->hw;
3312 u16 enable, period, timeout, mcast;
3313 unsigned long flags;
3315 err = orinoco_lock(priv, &flags);
3319 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3323 err = hermes_read_wordrec(hw, USER_BAP,
3324 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3328 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3332 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3336 prq->disabled = !enable;
3337 /* Note : by default, display the period */
3338 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3339 prq->flags = IW_POWER_TIMEOUT;
3340 prq->value = timeout * 1000;
3342 prq->flags = IW_POWER_PERIOD;
3343 prq->value = period * 1000;
3346 prq->flags |= IW_POWER_ALL_R;
3348 prq->flags |= IW_POWER_UNICAST_R;
3351 orinoco_unlock(priv, &flags);
3356 #if WIRELESS_EXT > 10
3357 static int orinoco_ioctl_getretry(struct net_device *dev, struct iw_param *rrq)
3359 struct orinoco_private *priv = netdev_priv(dev);
3360 hermes_t *hw = &priv->hw;
3362 u16 short_limit, long_limit, lifetime;
3363 unsigned long flags;
3365 err = orinoco_lock(priv, &flags);
3369 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3374 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3379 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3384 rrq->disabled = 0; /* Can't be disabled */
3386 /* Note : by default, display the retry number */
3387 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3388 rrq->flags = IW_RETRY_LIFETIME;
3389 rrq->value = lifetime * 1000; /* ??? */
3391 /* By default, display the min number */
3392 if ((rrq->flags & IW_RETRY_MAX)) {
3393 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3394 rrq->value = long_limit;
3396 rrq->flags = IW_RETRY_LIMIT;
3397 rrq->value = short_limit;
3398 if(short_limit != long_limit)
3399 rrq->flags |= IW_RETRY_MIN;
3404 orinoco_unlock(priv, &flags);
3408 #endif /* WIRELESS_EXT > 10 */
3410 static int orinoco_ioctl_setibssport(struct net_device *dev, struct iwreq *wrq)
3412 struct orinoco_private *priv = netdev_priv(dev);
3413 int val = *( (int *) wrq->u.name );
3415 unsigned long flags;
3417 err = orinoco_lock(priv, &flags);
3421 priv->ibss_port = val ;
3423 /* Actually update the mode we are using */
3424 set_port_type(priv);
3426 orinoco_unlock(priv, &flags);
3430 static int orinoco_ioctl_getibssport(struct net_device *dev, struct iwreq *wrq)
3432 struct orinoco_private *priv = netdev_priv(dev);
3433 int *val = (int *)wrq->u.name;
3435 unsigned long flags;
3437 err = orinoco_lock(priv, &flags);
3441 *val = priv->ibss_port;
3442 orinoco_unlock(priv, &flags);
3447 static int orinoco_ioctl_setport3(struct net_device *dev, struct iwreq *wrq)
3449 struct orinoco_private *priv = netdev_priv(dev);
3450 int val = *( (int *) wrq->u.name );
3452 unsigned long flags;
3454 err = orinoco_lock(priv, &flags);
3459 case 0: /* Try to do IEEE ad-hoc mode */
3460 if (! priv->has_ibss) {
3464 priv->prefer_port3 = 0;
3468 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3469 if (! priv->has_port3) {
3473 priv->prefer_port3 = 1;
3481 /* Actually update the mode we are using */
3482 set_port_type(priv);
3484 orinoco_unlock(priv, &flags);
3489 static int orinoco_ioctl_getport3(struct net_device *dev, struct iwreq *wrq)
3491 struct orinoco_private *priv = netdev_priv(dev);
3492 int *val = (int *)wrq->u.name;
3494 unsigned long flags;
3496 err = orinoco_lock(priv, &flags);
3500 *val = priv->prefer_port3;
3501 orinoco_unlock(priv, &flags);
3506 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3508 static int orinoco_ioctl_setspy(struct net_device *dev, struct iw_point *srq)
3510 struct orinoco_private *priv = netdev_priv(dev);
3511 struct sockaddr address[IW_MAX_SPY];
3512 int number = srq->length;
3515 unsigned long flags;
3517 /* Check the number of addresses */
3518 if (number > IW_MAX_SPY)
3521 /* Get the data in the driver */
3523 if (copy_from_user(address, srq->pointer,
3524 sizeof(struct sockaddr) * number))
3528 /* Make sure nobody mess with the structure while we do */
3529 err = orinoco_lock(priv, &flags);
3533 /* orinoco_lock() doesn't disable interrupts, so make sure the
3534 * interrupt rx path don't get confused while we copy */
3535 priv->spy_number = 0;
3538 /* Extract the addresses */
3539 for (i = 0; i < number; i++)
3540 memcpy(priv->spy_address[i], address[i].sa_data,
3543 memset(priv->spy_stat, 0,
3544 sizeof(struct iw_quality) * IW_MAX_SPY);
3545 /* Set number of addresses */
3546 priv->spy_number = number;
3549 /* Now, let the others play */
3550 orinoco_unlock(priv, &flags);
3555 static int orinoco_ioctl_getspy(struct net_device *dev, struct iw_point *srq)
3557 struct orinoco_private *priv = netdev_priv(dev);
3558 struct sockaddr address[IW_MAX_SPY];
3559 struct iw_quality spy_stat[IW_MAX_SPY];
3563 unsigned long flags;
3565 err = orinoco_lock(priv, &flags);
3569 number = priv->spy_number;
3570 if ((number > 0) && (srq->pointer)) {
3571 /* Create address struct */
3572 for (i = 0; i < number; i++) {
3573 memcpy(address[i].sa_data, priv->spy_address[i],
3575 address[i].sa_family = AF_UNIX;
3578 /* In theory, we should disable irqs while copying the stats
3579 * because the rx path migh update it in the middle...
3580 * Bah, who care ? - Jean II */
3581 memcpy(&spy_stat, priv->spy_stat,
3582 sizeof(struct iw_quality) * IW_MAX_SPY);
3583 for (i=0; i < number; i++)
3584 priv->spy_stat[i].updated = 0;
3587 orinoco_unlock(priv, &flags);
3589 /* Push stuff to user space */
3590 srq->length = number;
3591 if(copy_to_user(srq->pointer, address,
3592 sizeof(struct sockaddr) * number))
3594 if(copy_to_user(srq->pointer + (sizeof(struct sockaddr)*number),
3595 &spy_stat, sizeof(struct iw_quality) * number))
3602 orinoco_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3604 struct orinoco_private *priv = netdev_priv(dev);
3605 struct iwreq *wrq = (struct iwreq *)rq;
3609 unsigned long flags;
3611 TRACE_ENTER(dev->name);
3613 /* In theory, we could allow most of the the SET stuff to be
3614 * done. In practice, the lapse of time at startup when the
3615 * card is not ready is very short, so why bother... Note
3616 * that netif_device_present is different from up/down
3617 * (ifconfig), when the device is not yet up, it is usually
3618 * already ready... Jean II */
3619 if (! netif_device_present(dev))
3624 strcpy(wrq->u.name, "IEEE 802.11-DS");
3628 wrq->u.ap_addr.sa_family = ARPHRD_ETHER;
3629 err = orinoco_hw_get_bssid(priv, wrq->u.ap_addr.sa_data);
3633 err = orinoco_ioctl_getiwrange(dev, &wrq->u.data);
3637 err = orinoco_lock(priv, &flags);
3640 switch (wrq->u.mode) {
3642 if (! (priv->has_ibss || priv->has_port3) )
3645 priv->iw_mode = IW_MODE_ADHOC;
3651 priv->iw_mode = IW_MODE_INFRA;
3659 set_port_type(priv);
3660 orinoco_unlock(priv, &flags);
3664 err = orinoco_lock(priv, &flags);
3667 wrq->u.mode = priv->iw_mode;
3668 orinoco_unlock(priv, &flags);
3672 if (! priv->has_wep) {
3677 err = orinoco_ioctl_setiwencode(dev, &wrq->u.encoding);
3683 if (! priv->has_wep) {
3688 if (! capable(CAP_NET_ADMIN)) {
3693 err = orinoco_ioctl_getiwencode(dev, &wrq->u.encoding);
3697 err = orinoco_ioctl_setessid(dev, &wrq->u.essid);
3703 err = orinoco_ioctl_getessid(dev, &wrq->u.essid);
3707 err = orinoco_ioctl_setnick(dev, &wrq->u.data);
3713 err = orinoco_ioctl_getnick(dev, &wrq->u.data);
3717 tmp = orinoco_hw_get_freq(priv);
3721 wrq->u.freq.m = tmp;
3727 err = orinoco_ioctl_setfreq(dev, &wrq->u.freq);
3733 err = orinoco_ioctl_getsens(dev, &wrq->u.sens);
3737 err = orinoco_ioctl_setsens(dev, &wrq->u.sens);
3743 wrq->u.rts.value = priv->rts_thresh;
3744 wrq->u.rts.disabled = (wrq->u.rts.value == 2347);
3745 wrq->u.rts.fixed = 1;
3749 err = orinoco_ioctl_setrts(dev, &wrq->u.rts);
3755 err = orinoco_ioctl_setfrag(dev, &wrq->u.frag);
3761 err = orinoco_ioctl_getfrag(dev, &wrq->u.frag);
3765 err = orinoco_ioctl_setrate(dev, &wrq->u.bitrate);
3771 err = orinoco_ioctl_getrate(dev, &wrq->u.bitrate);
3775 err = orinoco_ioctl_setpower(dev, &wrq->u.power);
3781 err = orinoco_ioctl_getpower(dev, &wrq->u.power);
3785 /* The card only supports one tx power, so this is easy */
3786 wrq->u.txpower.value = 15; /* dBm */
3787 wrq->u.txpower.fixed = 1;
3788 wrq->u.txpower.disabled = 0;
3789 wrq->u.txpower.flags = IW_TXPOW_DBM;
3792 #if WIRELESS_EXT > 10
3798 err = orinoco_ioctl_getretry(dev, &wrq->u.retry);
3800 #endif /* WIRELESS_EXT > 10 */
3803 err = orinoco_ioctl_setspy(dev, &wrq->u.data);
3807 err = orinoco_ioctl_getspy(dev, &wrq->u.data);
3811 if (wrq->u.data.pointer) {
3812 struct iw_priv_args privtab[] = {
3813 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
3814 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
3815 { SIOCIWFIRSTPRIV + 0x2,
3816 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3818 { SIOCIWFIRSTPRIV + 0x3, 0,
3819 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3821 { SIOCIWFIRSTPRIV + 0x4,
3822 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3823 0, "set_preamble" },
3824 { SIOCIWFIRSTPRIV + 0x5, 0,
3825 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3827 { SIOCIWFIRSTPRIV + 0x6,
3828 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3829 0, "set_ibssport" },
3830 { SIOCIWFIRSTPRIV + 0x7, 0,
3831 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3833 { SIOCIWLASTPRIV, 0, 0, "dump_recs" },
3836 wrq->u.data.length = sizeof(privtab) / sizeof(privtab[0]);
3837 if (copy_to_user(wrq->u.data.pointer, privtab, sizeof(privtab)))
3842 case SIOCIWFIRSTPRIV + 0x0: /* force_reset */
3843 case SIOCIWFIRSTPRIV + 0x1: /* card_reset */
3844 if (! capable(CAP_NET_ADMIN)) {
3849 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3851 schedule_work(&priv->reset_work);
3854 case SIOCIWFIRSTPRIV + 0x2: /* set_port3 */
3855 if (! capable(CAP_NET_ADMIN)) {
3860 err = orinoco_ioctl_setport3(dev, wrq);
3865 case SIOCIWFIRSTPRIV + 0x3: /* get_port3 */
3866 err = orinoco_ioctl_getport3(dev, wrq);
3869 case SIOCIWFIRSTPRIV + 0x4: /* set_preamble */
3870 if (! capable(CAP_NET_ADMIN)) {
3875 /* 802.11b has recently defined some short preamble.
3876 * Basically, the Phy header has been reduced in size.
3877 * This increase performance, especially at high rates
3878 * (the preamble is transmitted at 1Mb/s), unfortunately
3879 * this give compatibility troubles... - Jean II */
3880 if(priv->has_preamble) {
3881 int val = *( (int *) wrq->u.name );
3883 err = orinoco_lock(priv, &flags);
3890 orinoco_unlock(priv, &flags);
3896 case SIOCIWFIRSTPRIV + 0x5: /* get_preamble */
3897 if(priv->has_preamble) {
3898 int *val = (int *)wrq->u.name;
3900 err = orinoco_lock(priv, &flags);
3903 *val = priv->preamble;
3904 orinoco_unlock(priv, &flags);
3908 case SIOCIWFIRSTPRIV + 0x6: /* set_ibssport */
3909 if (! capable(CAP_NET_ADMIN)) {
3914 err = orinoco_ioctl_setibssport(dev, wrq);
3919 case SIOCIWFIRSTPRIV + 0x7: /* get_ibssport */
3920 err = orinoco_ioctl_getibssport(dev, wrq);
3923 case SIOCIWLASTPRIV:
3924 err = orinoco_debug_dump_recs(dev);
3926 printk(KERN_ERR "%s: Unable to dump records (%d)\n",
3935 if (! err && changed && netif_running(dev)) {
3936 err = orinoco_reconfigure(dev);
3939 TRACE_EXIT(dev->name);
3948 #define DISPLAY_WORDS 0
3949 #define DISPLAY_BYTES 1
3950 #define DISPLAY_STRING 2
3951 #define DISPLAY_XSTRING 3
3952 } record_table[] = {
3953 #define DEBUG_REC(name,type) { HERMES_RID_##name, #name, DISPLAY_##type }
3954 DEBUG_REC(CNFPORTTYPE,WORDS),
3955 DEBUG_REC(CNFOWNMACADDR,BYTES),
3956 DEBUG_REC(CNFDESIREDSSID,STRING),
3957 DEBUG_REC(CNFOWNCHANNEL,WORDS),
3958 DEBUG_REC(CNFOWNSSID,STRING),
3959 DEBUG_REC(CNFOWNATIMWINDOW,WORDS),
3960 DEBUG_REC(CNFSYSTEMSCALE,WORDS),
3961 DEBUG_REC(CNFMAXDATALEN,WORDS),
3962 DEBUG_REC(CNFPMENABLED,WORDS),
3963 DEBUG_REC(CNFPMEPS,WORDS),
3964 DEBUG_REC(CNFMULTICASTRECEIVE,WORDS),
3965 DEBUG_REC(CNFMAXSLEEPDURATION,WORDS),
3966 DEBUG_REC(CNFPMHOLDOVERDURATION,WORDS),
3967 DEBUG_REC(CNFOWNNAME,STRING),
3968 DEBUG_REC(CNFOWNDTIMPERIOD,WORDS),
3969 DEBUG_REC(CNFMULTICASTPMBUFFERING,WORDS),
3970 DEBUG_REC(CNFWEPENABLED_AGERE,WORDS),
3971 DEBUG_REC(CNFMANDATORYBSSID_SYMBOL,WORDS),
3972 DEBUG_REC(CNFWEPDEFAULTKEYID,WORDS),
3973 DEBUG_REC(CNFDEFAULTKEY0,BYTES),
3974 DEBUG_REC(CNFDEFAULTKEY1,BYTES),
3975 DEBUG_REC(CNFMWOROBUST_AGERE,WORDS),
3976 DEBUG_REC(CNFDEFAULTKEY2,BYTES),
3977 DEBUG_REC(CNFDEFAULTKEY3,BYTES),
3978 DEBUG_REC(CNFWEPFLAGS_INTERSIL,WORDS),
3979 DEBUG_REC(CNFWEPKEYMAPPINGTABLE,WORDS),
3980 DEBUG_REC(CNFAUTHENTICATION,WORDS),
3981 DEBUG_REC(CNFMAXASSOCSTA,WORDS),
3982 DEBUG_REC(CNFKEYLENGTH_SYMBOL,WORDS),
3983 DEBUG_REC(CNFTXCONTROL,WORDS),
3984 DEBUG_REC(CNFROAMINGMODE,WORDS),
3985 DEBUG_REC(CNFHOSTAUTHENTICATION,WORDS),
3986 DEBUG_REC(CNFRCVCRCERROR,WORDS),
3987 DEBUG_REC(CNFMMLIFE,WORDS),
3988 DEBUG_REC(CNFALTRETRYCOUNT,WORDS),
3989 DEBUG_REC(CNFBEACONINT,WORDS),
3990 DEBUG_REC(CNFAPPCFINFO,WORDS),
3991 DEBUG_REC(CNFSTAPCFINFO,WORDS),
3992 DEBUG_REC(CNFPRIORITYQUSAGE,WORDS),
3993 DEBUG_REC(CNFTIMCTRL,WORDS),
3994 DEBUG_REC(CNFTHIRTY2TALLY,WORDS),
3995 DEBUG_REC(CNFENHSECURITY,WORDS),
3996 DEBUG_REC(CNFGROUPADDRESSES,BYTES),
3997 DEBUG_REC(CNFCREATEIBSS,WORDS),
3998 DEBUG_REC(CNFFRAGMENTATIONTHRESHOLD,WORDS),
3999 DEBUG_REC(CNFRTSTHRESHOLD,WORDS),
4000 DEBUG_REC(CNFTXRATECONTROL,WORDS),
4001 DEBUG_REC(CNFPROMISCUOUSMODE,WORDS),
4002 DEBUG_REC(CNFBASICRATES_SYMBOL,WORDS),
4003 DEBUG_REC(CNFPREAMBLE_SYMBOL,WORDS),
4004 DEBUG_REC(CNFSHORTPREAMBLE,WORDS),
4005 DEBUG_REC(CNFWEPKEYS_AGERE,BYTES),
4006 DEBUG_REC(CNFEXCLUDELONGPREAMBLE,WORDS),
4007 DEBUG_REC(CNFTXKEY_AGERE,WORDS),
4008 DEBUG_REC(CNFAUTHENTICATIONRSPTO,WORDS),
4009 DEBUG_REC(CNFBASICRATES,WORDS),
4010 DEBUG_REC(CNFSUPPORTEDRATES,WORDS),
4011 DEBUG_REC(CNFTICKTIME,WORDS),
4012 DEBUG_REC(CNFSCANREQUEST,WORDS),
4013 DEBUG_REC(CNFJOINREQUEST,WORDS),
4014 DEBUG_REC(CNFAUTHENTICATESTATION,WORDS),
4015 DEBUG_REC(CNFCHANNELINFOREQUEST,WORDS),
4016 DEBUG_REC(MAXLOADTIME,WORDS),
4017 DEBUG_REC(DOWNLOADBUFFER,WORDS),
4018 DEBUG_REC(PRIID,WORDS),
4019 DEBUG_REC(PRISUPRANGE,WORDS),
4020 DEBUG_REC(CFIACTRANGES,WORDS),
4021 DEBUG_REC(NICSERNUM,XSTRING),
4022 DEBUG_REC(NICID,WORDS),
4023 DEBUG_REC(MFISUPRANGE,WORDS),
4024 DEBUG_REC(CFISUPRANGE,WORDS),
4025 DEBUG_REC(CHANNELLIST,WORDS),
4026 DEBUG_REC(REGULATORYDOMAINS,WORDS),
4027 DEBUG_REC(TEMPTYPE,WORDS),
4028 /* DEBUG_REC(CIS,BYTES), */
4029 DEBUG_REC(STAID,WORDS),
4030 DEBUG_REC(CURRENTSSID,STRING),
4031 DEBUG_REC(CURRENTBSSID,BYTES),
4032 DEBUG_REC(COMMSQUALITY,WORDS),
4033 DEBUG_REC(CURRENTTXRATE,WORDS),
4034 DEBUG_REC(CURRENTBEACONINTERVAL,WORDS),
4035 DEBUG_REC(CURRENTSCALETHRESHOLDS,WORDS),
4036 DEBUG_REC(PROTOCOLRSPTIME,WORDS),
4037 DEBUG_REC(SHORTRETRYLIMIT,WORDS),
4038 DEBUG_REC(LONGRETRYLIMIT,WORDS),
4039 DEBUG_REC(MAXTRANSMITLIFETIME,WORDS),
4040 DEBUG_REC(MAXRECEIVELIFETIME,WORDS),
4041 DEBUG_REC(CFPOLLABLE,WORDS),
4042 DEBUG_REC(AUTHENTICATIONALGORITHMS,WORDS),
4043 DEBUG_REC(PRIVACYOPTIONIMPLEMENTED,WORDS),
4044 DEBUG_REC(OWNMACADDR,BYTES),
4045 DEBUG_REC(SCANRESULTSTABLE,WORDS),
4046 DEBUG_REC(PHYTYPE,WORDS),
4047 DEBUG_REC(CURRENTCHANNEL,WORDS),
4048 DEBUG_REC(CURRENTPOWERSTATE,WORDS),
4049 DEBUG_REC(CCAMODE,WORDS),
4050 DEBUG_REC(SUPPORTEDDATARATES,WORDS),
4051 DEBUG_REC(BUILDSEQ,BYTES),
4052 DEBUG_REC(FWID,XSTRING)
4056 #define DEBUG_LTV_SIZE 128
4058 static int orinoco_debug_dump_recs(struct net_device *dev)
4060 struct orinoco_private *priv = netdev_priv(dev);
4061 hermes_t *hw = &priv->hw;
4068 /* I'm not sure: we might have a lock here, so we'd better go
4069 atomic, just in case. */
4070 val8 = kmalloc(DEBUG_LTV_SIZE + 2, GFP_ATOMIC);
4073 val16 = (u16 *)val8;
4075 for (i = 0; i < ARRAY_SIZE(record_table); i++) {
4076 u16 rid = record_table[i].rid;
4079 memset(val8, 0, DEBUG_LTV_SIZE + 2);
4081 err = hermes_read_ltv(hw, USER_BAP, rid, DEBUG_LTV_SIZE,
4084 DEBUG(0, "Error %d reading RID 0x%04x\n", err, rid);
4087 val16 = (u16 *)val8;
4091 printk(KERN_DEBUG "%-15s (0x%04x): length=%d (%d bytes)\tvalue=",
4092 record_table[i].name,
4093 rid, length, (length-1)*2);
4094 len = min(((int)length-1)*2, DEBUG_LTV_SIZE);
4096 switch (record_table[i].displaytype) {
4098 for (j = 0; j < len / 2; j++)
4099 printk("%04X-", le16_to_cpu(val16[j]));
4104 for (j = 0; j < len; j++)
4105 printk("%02X:", val8[j]);
4108 case DISPLAY_STRING:
4109 len = min(len, le16_to_cpu(val16[0])+2);
4111 printk("\"%s\"", (char *)&val16[1]);
4114 case DISPLAY_XSTRING:
4115 printk("'%s'", (char *)val8);
4126 struct net_device *alloc_orinocodev(int sizeof_card, int (*hard_reset)(struct orinoco_private *))
4128 struct net_device *dev;
4129 struct orinoco_private *priv;
4131 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
4134 priv = netdev_priv(dev);
4137 priv->card = (void *)((unsigned long)dev->priv + sizeof(struct orinoco_private));
4141 /* Setup / override net_device fields */
4142 dev->init = orinoco_init;
4143 dev->hard_start_xmit = orinoco_xmit;
4144 dev->tx_timeout = orinoco_tx_timeout;
4145 dev->watchdog_timeo = HZ; /* 1 second timeout */
4146 dev->get_stats = orinoco_get_stats;
4147 dev->get_wireless_stats = orinoco_get_wireless_stats;
4148 dev->do_ioctl = orinoco_ioctl;
4149 dev->change_mtu = orinoco_change_mtu;
4150 dev->set_multicast_list = orinoco_set_multicast_list;
4151 /* we use the default eth_mac_addr for setting the MAC addr */
4153 /* Set up default callbacks */
4154 dev->open = orinoco_open;
4155 dev->stop = orinoco_stop;
4156 priv->hard_reset = hard_reset;
4158 spin_lock_init(&priv->lock);
4160 priv->hw_unavailable = 1; /* orinoco_init() must clear this
4161 * before anything else touches the
4163 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
4165 priv->last_linkstatus = 0xffff;
4166 priv->connected = 0;
4172 /********************************************************************/
4173 /* Module initialization */
4174 /********************************************************************/
4176 EXPORT_SYMBOL(alloc_orinocodev);
4178 EXPORT_SYMBOL(__orinoco_up);
4179 EXPORT_SYMBOL(__orinoco_down);
4180 EXPORT_SYMBOL(orinoco_stop);
4181 EXPORT_SYMBOL(orinoco_reinit_firmware);
4183 EXPORT_SYMBOL(orinoco_interrupt);
4185 /* Can't be declared "const" or the whole __initdata section will
4187 static char version[] __initdata = "orinoco.c 0.13e (David Gibson <hermes@gibson.dropbear.id.au> and others)";
4189 static int __init init_orinoco(void)
4191 printk(KERN_DEBUG "%s\n", version);
4195 static void __exit exit_orinoco(void)
4199 module_init(init_orinoco);
4200 module_exit(exit_orinoco);