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