Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* 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> | |
1fab2e8b | 465 | #include <linux/ethtool.h> |
1da177e4 | 466 | #include <linux/wireless.h> |
620554e4 | 467 | #include <net/iw_handler.h> |
5d558b7f | 468 | #include <net/ieee80211.h> |
1da177e4 LT |
469 | |
470 | #include <asm/uaccess.h> | |
471 | #include <asm/io.h> | |
472 | #include <asm/system.h> | |
473 | ||
474 | #include "hermes.h" | |
475 | #include "hermes_rid.h" | |
476 | #include "orinoco.h" | |
477 | #include "ieee802_11.h" | |
478 | ||
479 | /********************************************************************/ | |
480 | /* Module information */ | |
481 | /********************************************************************/ | |
482 | ||
483 | MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>"); | |
484 | MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards"); | |
485 | MODULE_LICENSE("Dual MPL/GPL"); | |
486 | ||
487 | /* Level of debugging. Used in the macros in orinoco.h */ | |
488 | #ifdef ORINOCO_DEBUG | |
489 | int orinoco_debug = ORINOCO_DEBUG; | |
490 | module_param(orinoco_debug, int, 0644); | |
491 | MODULE_PARM_DESC(orinoco_debug, "Debug level"); | |
492 | EXPORT_SYMBOL(orinoco_debug); | |
493 | #endif | |
494 | ||
495 | static int suppress_linkstatus; /* = 0 */ | |
496 | module_param(suppress_linkstatus, bool, 0644); | |
497 | MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes"); | |
7bb7c3a3 DG |
498 | static int ignore_disconnect; /* = 0 */ |
499 | module_param(ignore_disconnect, int, 0644); | |
500 | MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer"); | |
1da177e4 LT |
501 | |
502 | /********************************************************************/ | |
503 | /* Compile time configuration and compatibility stuff */ | |
504 | /********************************************************************/ | |
505 | ||
506 | /* We do this this way to avoid ifdefs in the actual code */ | |
507 | #ifdef WIRELESS_SPY | |
508 | #define SPY_NUMBER(priv) (priv->spy_number) | |
509 | #else | |
510 | #define SPY_NUMBER(priv) 0 | |
511 | #endif /* WIRELESS_SPY */ | |
512 | ||
513 | /********************************************************************/ | |
514 | /* Internal constants */ | |
515 | /********************************************************************/ | |
516 | ||
517 | #define ORINOCO_MIN_MTU 256 | |
518 | #define ORINOCO_MAX_MTU (IEEE802_11_DATA_LEN - ENCAPS_OVERHEAD) | |
519 | ||
520 | #define SYMBOL_MAX_VER_LEN (14) | |
521 | #define USER_BAP 0 | |
522 | #define IRQ_BAP 1 | |
523 | #define MAX_IRQLOOPS_PER_IRQ 10 | |
524 | #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of | |
525 | * how many events the | |
526 | * device could | |
527 | * legitimately generate */ | |
528 | #define SMALL_KEY_SIZE 5 | |
529 | #define LARGE_KEY_SIZE 13 | |
530 | #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */ | |
531 | ||
532 | #define DUMMY_FID 0xFFFF | |
533 | ||
534 | /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \ | |
535 | HERMES_MAX_MULTICAST : 0)*/ | |
536 | #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST) | |
537 | ||
538 | #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \ | |
539 | | HERMES_EV_TX | HERMES_EV_TXEXC \ | |
540 | | HERMES_EV_WTERR | HERMES_EV_INFO \ | |
541 | | HERMES_EV_INFDROP ) | |
542 | ||
620554e4 CH |
543 | #define MAX_RID_LEN 1024 |
544 | ||
545 | static const struct iw_handler_def orinoco_handler_def; | |
1fab2e8b | 546 | static struct ethtool_ops orinoco_ethtool_ops; |
620554e4 | 547 | |
1da177e4 LT |
548 | /********************************************************************/ |
549 | /* Data tables */ | |
550 | /********************************************************************/ | |
551 | ||
552 | /* The frequency of each channel in MHz */ | |
553 | static const long channel_frequency[] = { | |
554 | 2412, 2417, 2422, 2427, 2432, 2437, 2442, | |
555 | 2447, 2452, 2457, 2462, 2467, 2472, 2484 | |
556 | }; | |
557 | #define NUM_CHANNELS ARRAY_SIZE(channel_frequency) | |
558 | ||
559 | /* This tables gives the actual meanings of the bitrate IDs returned | |
560 | * by the firmware. */ | |
561 | static struct { | |
562 | int bitrate; /* in 100s of kilobits */ | |
563 | int automatic; | |
564 | u16 agere_txratectrl; | |
565 | u16 intersil_txratectrl; | |
566 | } bitrate_table[] = { | |
567 | {110, 1, 3, 15}, /* Entry 0 is the default */ | |
568 | {10, 0, 1, 1}, | |
569 | {10, 1, 1, 1}, | |
570 | {20, 0, 2, 2}, | |
571 | {20, 1, 6, 3}, | |
572 | {55, 0, 4, 4}, | |
573 | {55, 1, 7, 7}, | |
574 | {110, 0, 5, 8}, | |
575 | }; | |
576 | #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table) | |
577 | ||
578 | /********************************************************************/ | |
579 | /* Data types */ | |
580 | /********************************************************************/ | |
581 | ||
582 | struct header_struct { | |
583 | /* 802.3 */ | |
584 | u8 dest[ETH_ALEN]; | |
585 | u8 src[ETH_ALEN]; | |
586 | u16 len; | |
587 | /* 802.2 */ | |
588 | u8 dsap; | |
589 | u8 ssap; | |
590 | u8 ctrl; | |
591 | /* SNAP */ | |
592 | u8 oui[3]; | |
593 | u16 ethertype; | |
594 | } __attribute__ ((packed)); | |
595 | ||
596 | /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */ | |
597 | u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00}; | |
598 | ||
599 | #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2) | |
600 | ||
601 | struct hermes_rx_descriptor { | |
602 | u16 status; | |
603 | u32 time; | |
604 | u8 silence; | |
605 | u8 signal; | |
606 | u8 rate; | |
607 | u8 rxflow; | |
608 | u32 reserved; | |
609 | } __attribute__ ((packed)); | |
610 | ||
611 | /********************************************************************/ | |
612 | /* Function prototypes */ | |
613 | /********************************************************************/ | |
614 | ||
1da177e4 LT |
615 | static int __orinoco_program_rids(struct net_device *dev); |
616 | static void __orinoco_set_multicast_list(struct net_device *dev); | |
1da177e4 LT |
617 | |
618 | /********************************************************************/ | |
619 | /* Internal helper functions */ | |
620 | /********************************************************************/ | |
621 | ||
622 | static inline void set_port_type(struct orinoco_private *priv) | |
623 | { | |
624 | switch (priv->iw_mode) { | |
625 | case IW_MODE_INFRA: | |
626 | priv->port_type = 1; | |
627 | priv->createibss = 0; | |
628 | break; | |
629 | case IW_MODE_ADHOC: | |
630 | if (priv->prefer_port3) { | |
631 | priv->port_type = 3; | |
632 | priv->createibss = 0; | |
633 | } else { | |
634 | priv->port_type = priv->ibss_port; | |
635 | priv->createibss = 1; | |
636 | } | |
637 | break; | |
638 | default: | |
639 | printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n", | |
640 | priv->ndev->name); | |
641 | } | |
642 | } | |
643 | ||
644 | /********************************************************************/ | |
645 | /* Device methods */ | |
646 | /********************************************************************/ | |
647 | ||
648 | static int orinoco_open(struct net_device *dev) | |
649 | { | |
650 | struct orinoco_private *priv = netdev_priv(dev); | |
651 | unsigned long flags; | |
652 | int err; | |
653 | ||
654 | if (orinoco_lock(priv, &flags) != 0) | |
655 | return -EBUSY; | |
656 | ||
657 | err = __orinoco_up(dev); | |
658 | ||
659 | if (! err) | |
660 | priv->open = 1; | |
661 | ||
662 | orinoco_unlock(priv, &flags); | |
663 | ||
664 | return err; | |
665 | } | |
666 | ||
ad8f451b | 667 | static int orinoco_stop(struct net_device *dev) |
1da177e4 LT |
668 | { |
669 | struct orinoco_private *priv = netdev_priv(dev); | |
670 | int err = 0; | |
671 | ||
672 | /* We mustn't use orinoco_lock() here, because we need to be | |
673 | able to close the interface even if hw_unavailable is set | |
674 | (e.g. as we're released after a PC Card removal) */ | |
675 | spin_lock_irq(&priv->lock); | |
676 | ||
677 | priv->open = 0; | |
678 | ||
679 | err = __orinoco_down(dev); | |
680 | ||
681 | spin_unlock_irq(&priv->lock); | |
682 | ||
683 | return err; | |
684 | } | |
685 | ||
686 | static struct net_device_stats *orinoco_get_stats(struct net_device *dev) | |
687 | { | |
688 | struct orinoco_private *priv = netdev_priv(dev); | |
689 | ||
690 | return &priv->stats; | |
691 | } | |
692 | ||
693 | static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev) | |
694 | { | |
695 | struct orinoco_private *priv = netdev_priv(dev); | |
696 | hermes_t *hw = &priv->hw; | |
697 | struct iw_statistics *wstats = &priv->wstats; | |
e67d9d9d | 698 | int err; |
1da177e4 LT |
699 | unsigned long flags; |
700 | ||
701 | if (! netif_device_present(dev)) { | |
702 | printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n", | |
703 | dev->name); | |
704 | return NULL; /* FIXME: Can we do better than this? */ | |
705 | } | |
706 | ||
e67d9d9d DG |
707 | /* If busy, return the old stats. Returning NULL may cause |
708 | * the interface to disappear from /proc/net/wireless */ | |
1da177e4 | 709 | if (orinoco_lock(priv, &flags) != 0) |
e67d9d9d DG |
710 | return wstats; |
711 | ||
712 | /* We can't really wait for the tallies inquiry command to | |
713 | * complete, so we just use the previous results and trigger | |
714 | * a new tallies inquiry command for next time - Jean II */ | |
715 | /* FIXME: Really we should wait for the inquiry to come back - | |
716 | * as it is the stats we give don't make a whole lot of sense. | |
717 | * Unfortunately, it's not clear how to do that within the | |
718 | * wireless extensions framework: I think we're in user | |
719 | * context, but a lock seems to be held by the time we get in | |
720 | * here so we're not safe to sleep here. */ | |
721 | hermes_inquire(hw, HERMES_INQ_TALLIES); | |
1da177e4 LT |
722 | |
723 | if (priv->iw_mode == IW_MODE_ADHOC) { | |
724 | memset(&wstats->qual, 0, sizeof(wstats->qual)); | |
725 | /* If a spy address is defined, we report stats of the | |
726 | * first spy address - Jean II */ | |
727 | if (SPY_NUMBER(priv)) { | |
728 | wstats->qual.qual = priv->spy_stat[0].qual; | |
729 | wstats->qual.level = priv->spy_stat[0].level; | |
730 | wstats->qual.noise = priv->spy_stat[0].noise; | |
731 | wstats->qual.updated = priv->spy_stat[0].updated; | |
732 | } | |
733 | } else { | |
734 | struct { | |
735 | u16 qual, signal, noise; | |
736 | } __attribute__ ((packed)) cq; | |
737 | ||
738 | err = HERMES_READ_RECORD(hw, USER_BAP, | |
739 | HERMES_RID_COMMSQUALITY, &cq); | |
e67d9d9d DG |
740 | |
741 | if (!err) { | |
742 | wstats->qual.qual = (int)le16_to_cpu(cq.qual); | |
743 | wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95; | |
744 | wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95; | |
745 | wstats->qual.updated = 7; | |
746 | } | |
1da177e4 LT |
747 | } |
748 | ||
1da177e4 | 749 | orinoco_unlock(priv, &flags); |
1da177e4 LT |
750 | return wstats; |
751 | } | |
752 | ||
753 | static void orinoco_set_multicast_list(struct net_device *dev) | |
754 | { | |
755 | struct orinoco_private *priv = netdev_priv(dev); | |
756 | unsigned long flags; | |
757 | ||
758 | if (orinoco_lock(priv, &flags) != 0) { | |
759 | printk(KERN_DEBUG "%s: orinoco_set_multicast_list() " | |
760 | "called when hw_unavailable\n", dev->name); | |
761 | return; | |
762 | } | |
763 | ||
764 | __orinoco_set_multicast_list(dev); | |
765 | orinoco_unlock(priv, &flags); | |
766 | } | |
767 | ||
768 | static int orinoco_change_mtu(struct net_device *dev, int new_mtu) | |
769 | { | |
770 | struct orinoco_private *priv = netdev_priv(dev); | |
771 | ||
772 | if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) ) | |
773 | return -EINVAL; | |
774 | ||
775 | if ( (new_mtu + ENCAPS_OVERHEAD + IEEE802_11_HLEN) > | |
776 | (priv->nicbuf_size - ETH_HLEN) ) | |
777 | return -EINVAL; | |
778 | ||
779 | dev->mtu = new_mtu; | |
780 | ||
781 | return 0; | |
782 | } | |
783 | ||
784 | /********************************************************************/ | |
785 | /* Tx path */ | |
786 | /********************************************************************/ | |
787 | ||
788 | static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev) | |
789 | { | |
790 | struct orinoco_private *priv = netdev_priv(dev); | |
791 | struct net_device_stats *stats = &priv->stats; | |
792 | hermes_t *hw = &priv->hw; | |
793 | int err = 0; | |
794 | u16 txfid = priv->txfid; | |
795 | char *p; | |
796 | struct ethhdr *eh; | |
797 | int len, data_len, data_off; | |
798 | struct hermes_tx_descriptor desc; | |
799 | unsigned long flags; | |
800 | ||
801 | TRACE_ENTER(dev->name); | |
802 | ||
803 | if (! netif_running(dev)) { | |
804 | printk(KERN_ERR "%s: Tx on stopped device!\n", | |
805 | dev->name); | |
806 | TRACE_EXIT(dev->name); | |
807 | return 1; | |
808 | } | |
809 | ||
810 | if (netif_queue_stopped(dev)) { | |
811 | printk(KERN_DEBUG "%s: Tx while transmitter busy!\n", | |
812 | dev->name); | |
813 | TRACE_EXIT(dev->name); | |
814 | return 1; | |
815 | } | |
816 | ||
817 | if (orinoco_lock(priv, &flags) != 0) { | |
818 | printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n", | |
819 | dev->name); | |
820 | TRACE_EXIT(dev->name); | |
821 | return 1; | |
822 | } | |
823 | ||
824 | if (! netif_carrier_ok(dev)) { | |
825 | /* Oops, the firmware hasn't established a connection, | |
826 | silently drop the packet (this seems to be the | |
827 | safest approach). */ | |
828 | stats->tx_errors++; | |
829 | orinoco_unlock(priv, &flags); | |
830 | dev_kfree_skb(skb); | |
831 | TRACE_EXIT(dev->name); | |
832 | return 0; | |
833 | } | |
834 | ||
835 | /* Length of the packet body */ | |
836 | /* FIXME: what if the skb is smaller than this? */ | |
837 | len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN); | |
838 | ||
839 | eh = (struct ethhdr *)skb->data; | |
840 | ||
841 | memset(&desc, 0, sizeof(desc)); | |
842 | desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX); | |
843 | err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0); | |
844 | if (err) { | |
845 | if (net_ratelimit()) | |
846 | printk(KERN_ERR "%s: Error %d writing Tx descriptor " | |
847 | "to BAP\n", dev->name, err); | |
848 | stats->tx_errors++; | |
849 | goto fail; | |
850 | } | |
851 | ||
852 | /* Clear the 802.11 header and data length fields - some | |
853 | * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused | |
854 | * if this isn't done. */ | |
855 | hermes_clear_words(hw, HERMES_DATA0, | |
856 | HERMES_802_3_OFFSET - HERMES_802_11_OFFSET); | |
857 | ||
858 | /* Encapsulate Ethernet-II frames */ | |
859 | if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */ | |
860 | struct header_struct hdr; | |
861 | data_len = len; | |
862 | data_off = HERMES_802_3_OFFSET + sizeof(hdr); | |
863 | p = skb->data + ETH_HLEN; | |
864 | ||
865 | /* 802.3 header */ | |
866 | memcpy(hdr.dest, eh->h_dest, ETH_ALEN); | |
867 | memcpy(hdr.src, eh->h_source, ETH_ALEN); | |
868 | hdr.len = htons(data_len + ENCAPS_OVERHEAD); | |
869 | ||
870 | /* 802.2 header */ | |
871 | memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr)); | |
872 | ||
873 | hdr.ethertype = eh->h_proto; | |
874 | err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr), | |
875 | txfid, HERMES_802_3_OFFSET); | |
876 | if (err) { | |
877 | if (net_ratelimit()) | |
878 | printk(KERN_ERR "%s: Error %d writing packet " | |
879 | "header to BAP\n", dev->name, err); | |
880 | stats->tx_errors++; | |
881 | goto fail; | |
882 | } | |
883 | } else { /* IEEE 802.3 frame */ | |
884 | data_len = len + ETH_HLEN; | |
885 | data_off = HERMES_802_3_OFFSET; | |
886 | p = skb->data; | |
887 | } | |
888 | ||
889 | /* Round up for odd length packets */ | |
890 | err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2), | |
891 | txfid, data_off); | |
892 | if (err) { | |
893 | printk(KERN_ERR "%s: Error %d writing packet to BAP\n", | |
894 | dev->name, err); | |
895 | stats->tx_errors++; | |
896 | goto fail; | |
897 | } | |
898 | ||
899 | /* Finally, we actually initiate the send */ | |
900 | netif_stop_queue(dev); | |
901 | ||
902 | err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL, | |
903 | txfid, NULL); | |
904 | if (err) { | |
905 | netif_start_queue(dev); | |
906 | printk(KERN_ERR "%s: Error %d transmitting packet\n", | |
907 | dev->name, err); | |
908 | stats->tx_errors++; | |
909 | goto fail; | |
910 | } | |
911 | ||
912 | dev->trans_start = jiffies; | |
913 | stats->tx_bytes += data_off + data_len; | |
914 | ||
915 | orinoco_unlock(priv, &flags); | |
916 | ||
917 | dev_kfree_skb(skb); | |
918 | ||
919 | TRACE_EXIT(dev->name); | |
920 | ||
921 | return 0; | |
922 | fail: | |
923 | TRACE_EXIT(dev->name); | |
924 | ||
925 | orinoco_unlock(priv, &flags); | |
926 | return err; | |
927 | } | |
928 | ||
929 | static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw) | |
930 | { | |
931 | struct orinoco_private *priv = netdev_priv(dev); | |
932 | u16 fid = hermes_read_regn(hw, ALLOCFID); | |
933 | ||
934 | if (fid != priv->txfid) { | |
935 | if (fid != DUMMY_FID) | |
936 | printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n", | |
937 | dev->name, fid); | |
938 | return; | |
939 | } | |
940 | ||
941 | hermes_write_regn(hw, ALLOCFID, DUMMY_FID); | |
942 | } | |
943 | ||
944 | static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw) | |
945 | { | |
946 | struct orinoco_private *priv = netdev_priv(dev); | |
947 | struct net_device_stats *stats = &priv->stats; | |
948 | ||
949 | stats->tx_packets++; | |
950 | ||
951 | netif_wake_queue(dev); | |
952 | ||
953 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); | |
954 | } | |
955 | ||
956 | static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw) | |
957 | { | |
958 | struct orinoco_private *priv = netdev_priv(dev); | |
959 | struct net_device_stats *stats = &priv->stats; | |
960 | u16 fid = hermes_read_regn(hw, TXCOMPLFID); | |
961 | struct hermes_tx_descriptor desc; | |
962 | int err = 0; | |
963 | ||
964 | if (fid == DUMMY_FID) | |
965 | return; /* Nothing's really happened */ | |
966 | ||
967 | err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), fid, 0); | |
968 | if (err) { | |
969 | printk(KERN_WARNING "%s: Unable to read descriptor on Tx error " | |
970 | "(FID=%04X error %d)\n", | |
971 | dev->name, fid, err); | |
972 | } else { | |
973 | DEBUG(1, "%s: Tx error, status %d\n", | |
974 | dev->name, le16_to_cpu(desc.status)); | |
975 | } | |
976 | ||
977 | stats->tx_errors++; | |
978 | ||
979 | netif_wake_queue(dev); | |
980 | hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID); | |
981 | } | |
982 | ||
983 | static void orinoco_tx_timeout(struct net_device *dev) | |
984 | { | |
985 | struct orinoco_private *priv = netdev_priv(dev); | |
986 | struct net_device_stats *stats = &priv->stats; | |
987 | struct hermes *hw = &priv->hw; | |
988 | ||
989 | printk(KERN_WARNING "%s: Tx timeout! " | |
990 | "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n", | |
991 | dev->name, hermes_read_regn(hw, ALLOCFID), | |
992 | hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT)); | |
993 | ||
994 | stats->tx_errors++; | |
995 | ||
996 | schedule_work(&priv->reset_work); | |
997 | } | |
998 | ||
999 | /********************************************************************/ | |
1000 | /* Rx path (data frames) */ | |
1001 | /********************************************************************/ | |
1002 | ||
1003 | /* Does the frame have a SNAP header indicating it should be | |
1004 | * de-encapsulated to Ethernet-II? */ | |
1005 | static inline int is_ethersnap(void *_hdr) | |
1006 | { | |
1007 | u8 *hdr = _hdr; | |
1008 | ||
1009 | /* We de-encapsulate all packets which, a) have SNAP headers | |
1010 | * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header | |
1011 | * and where b) the OUI of the SNAP header is 00:00:00 or | |
1012 | * 00:00:f8 - we need both because different APs appear to use | |
1013 | * different OUIs for some reason */ | |
1014 | return (memcmp(hdr, &encaps_hdr, 5) == 0) | |
1015 | && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) ); | |
1016 | } | |
1017 | ||
1018 | static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac, | |
1019 | int level, int noise) | |
1020 | { | |
1021 | struct orinoco_private *priv = netdev_priv(dev); | |
1022 | int i; | |
1023 | ||
1024 | /* Gather wireless spy statistics: for each packet, compare the | |
1025 | * source address with out list, and if match, get the stats... */ | |
1026 | for (i = 0; i < priv->spy_number; i++) | |
1027 | if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) { | |
1028 | priv->spy_stat[i].level = level - 0x95; | |
1029 | priv->spy_stat[i].noise = noise - 0x95; | |
1030 | priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0; | |
1031 | priv->spy_stat[i].updated = 7; | |
1032 | } | |
1033 | } | |
1034 | ||
1035 | static void orinoco_stat_gather(struct net_device *dev, | |
1036 | struct sk_buff *skb, | |
1037 | struct hermes_rx_descriptor *desc) | |
1038 | { | |
1039 | struct orinoco_private *priv = netdev_priv(dev); | |
1040 | ||
1041 | /* Using spy support with lots of Rx packets, like in an | |
1042 | * infrastructure (AP), will really slow down everything, because | |
1043 | * the MAC address must be compared to each entry of the spy list. | |
1044 | * If the user really asks for it (set some address in the | |
1045 | * spy list), we do it, but he will pay the price. | |
1046 | * Note that to get here, you need both WIRELESS_SPY | |
1047 | * compiled in AND some addresses in the list !!! | |
1048 | */ | |
1049 | /* Note : gcc will optimise the whole section away if | |
1050 | * WIRELESS_SPY is not defined... - Jean II */ | |
1051 | if (SPY_NUMBER(priv)) { | |
1052 | orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN, | |
1053 | desc->signal, desc->silence); | |
1054 | } | |
1055 | } | |
1056 | ||
1057 | static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw) | |
1058 | { | |
1059 | struct orinoco_private *priv = netdev_priv(dev); | |
1060 | struct net_device_stats *stats = &priv->stats; | |
1061 | struct iw_statistics *wstats = &priv->wstats; | |
1062 | struct sk_buff *skb = NULL; | |
1063 | u16 rxfid, status; | |
1064 | int length, data_len, data_off; | |
1065 | char *p; | |
1066 | struct hermes_rx_descriptor desc; | |
1067 | struct header_struct hdr; | |
1068 | struct ethhdr *eh; | |
1069 | int err; | |
1070 | ||
1071 | rxfid = hermes_read_regn(hw, RXFID); | |
1072 | ||
1073 | err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc), | |
1074 | rxfid, 0); | |
1075 | if (err) { | |
1076 | printk(KERN_ERR "%s: error %d reading Rx descriptor. " | |
1077 | "Frame dropped.\n", dev->name, err); | |
1078 | stats->rx_errors++; | |
1079 | goto drop; | |
1080 | } | |
1081 | ||
1082 | status = le16_to_cpu(desc.status); | |
1083 | ||
1084 | if (status & HERMES_RXSTAT_ERR) { | |
1085 | if (status & HERMES_RXSTAT_UNDECRYPTABLE) { | |
1086 | wstats->discard.code++; | |
1087 | DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n", | |
1088 | dev->name); | |
1089 | } else { | |
1090 | stats->rx_crc_errors++; | |
1091 | DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n", dev->name); | |
1092 | } | |
1093 | stats->rx_errors++; | |
1094 | goto drop; | |
1095 | } | |
1096 | ||
1097 | /* For now we ignore the 802.11 header completely, assuming | |
1098 | that the card's firmware has handled anything vital */ | |
1099 | ||
1100 | err = hermes_bap_pread(hw, IRQ_BAP, &hdr, sizeof(hdr), | |
1101 | rxfid, HERMES_802_3_OFFSET); | |
1102 | if (err) { | |
1103 | printk(KERN_ERR "%s: error %d reading frame header. " | |
1104 | "Frame dropped.\n", dev->name, err); | |
1105 | stats->rx_errors++; | |
1106 | goto drop; | |
1107 | } | |
1108 | ||
1109 | length = ntohs(hdr.len); | |
1110 | ||
1111 | /* Sanity checks */ | |
1112 | if (length < 3) { /* No for even an 802.2 LLC header */ | |
1113 | /* At least on Symbol firmware with PCF we get quite a | |
1114 | lot of these legitimately - Poll frames with no | |
1115 | data. */ | |
1116 | stats->rx_dropped++; | |
1117 | goto drop; | |
1118 | } | |
1119 | if (length > IEEE802_11_DATA_LEN) { | |
1120 | printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n", | |
1121 | dev->name, length); | |
1122 | stats->rx_length_errors++; | |
1123 | stats->rx_errors++; | |
1124 | goto drop; | |
1125 | } | |
1126 | ||
1127 | /* We need space for the packet data itself, plus an ethernet | |
1128 | header, plus 2 bytes so we can align the IP header on a | |
1129 | 32bit boundary, plus 1 byte so we can read in odd length | |
1130 | packets from the card, which has an IO granularity of 16 | |
1131 | bits */ | |
1132 | skb = dev_alloc_skb(length+ETH_HLEN+2+1); | |
1133 | if (!skb) { | |
1134 | printk(KERN_WARNING "%s: Can't allocate skb for Rx\n", | |
1135 | dev->name); | |
1136 | goto drop; | |
1137 | } | |
1138 | ||
1139 | skb_reserve(skb, 2); /* This way the IP header is aligned */ | |
1140 | ||
1141 | /* Handle decapsulation | |
1142 | * In most cases, the firmware tell us about SNAP frames. | |
1143 | * For some reason, the SNAP frames sent by LinkSys APs | |
1144 | * are not properly recognised by most firmwares. | |
1145 | * So, check ourselves */ | |
1146 | if (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) || | |
1147 | ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) || | |
1148 | is_ethersnap(&hdr)) { | |
1149 | /* These indicate a SNAP within 802.2 LLC within | |
1150 | 802.11 frame which we'll need to de-encapsulate to | |
1151 | the original EthernetII frame. */ | |
1152 | ||
1153 | if (length < ENCAPS_OVERHEAD) { /* No room for full LLC+SNAP */ | |
1154 | stats->rx_length_errors++; | |
1155 | goto drop; | |
1156 | } | |
1157 | ||
1158 | /* Remove SNAP header, reconstruct EthernetII frame */ | |
1159 | data_len = length - ENCAPS_OVERHEAD; | |
1160 | data_off = HERMES_802_3_OFFSET + sizeof(hdr); | |
1161 | ||
1162 | eh = (struct ethhdr *)skb_put(skb, ETH_HLEN); | |
1163 | ||
1164 | memcpy(eh, &hdr, 2 * ETH_ALEN); | |
1165 | eh->h_proto = hdr.ethertype; | |
1166 | } else { | |
1167 | /* All other cases indicate a genuine 802.3 frame. No | |
1168 | decapsulation needed. We just throw the whole | |
1169 | thing in, and hope the protocol layer can deal with | |
1170 | it as 802.3 */ | |
1171 | data_len = length; | |
1172 | data_off = HERMES_802_3_OFFSET; | |
1173 | /* FIXME: we re-read from the card data we already read here */ | |
1174 | } | |
1175 | ||
1176 | p = skb_put(skb, data_len); | |
1177 | err = hermes_bap_pread(hw, IRQ_BAP, p, ALIGN(data_len, 2), | |
1178 | rxfid, data_off); | |
1179 | if (err) { | |
1180 | printk(KERN_ERR "%s: error %d reading frame. " | |
1181 | "Frame dropped.\n", dev->name, err); | |
1182 | stats->rx_errors++; | |
1183 | goto drop; | |
1184 | } | |
1185 | ||
1186 | dev->last_rx = jiffies; | |
1187 | skb->dev = dev; | |
1188 | skb->protocol = eth_type_trans(skb, dev); | |
1189 | skb->ip_summed = CHECKSUM_NONE; | |
1190 | ||
1191 | /* Process the wireless stats if needed */ | |
1192 | orinoco_stat_gather(dev, skb, &desc); | |
1193 | ||
1194 | /* Pass the packet to the networking stack */ | |
1195 | netif_rx(skb); | |
1196 | stats->rx_packets++; | |
1197 | stats->rx_bytes += length; | |
1198 | ||
1199 | return; | |
1200 | ||
1201 | drop: | |
1202 | stats->rx_dropped++; | |
1203 | ||
1204 | if (skb) | |
1205 | dev_kfree_skb_irq(skb); | |
1206 | return; | |
1207 | } | |
1208 | ||
1209 | /********************************************************************/ | |
1210 | /* Rx path (info frames) */ | |
1211 | /********************************************************************/ | |
1212 | ||
1213 | static void print_linkstatus(struct net_device *dev, u16 status) | |
1214 | { | |
1215 | char * s; | |
1216 | ||
1217 | if (suppress_linkstatus) | |
1218 | return; | |
1219 | ||
1220 | switch (status) { | |
1221 | case HERMES_LINKSTATUS_NOT_CONNECTED: | |
1222 | s = "Not Connected"; | |
1223 | break; | |
1224 | case HERMES_LINKSTATUS_CONNECTED: | |
1225 | s = "Connected"; | |
1226 | break; | |
1227 | case HERMES_LINKSTATUS_DISCONNECTED: | |
1228 | s = "Disconnected"; | |
1229 | break; | |
1230 | case HERMES_LINKSTATUS_AP_CHANGE: | |
1231 | s = "AP Changed"; | |
1232 | break; | |
1233 | case HERMES_LINKSTATUS_AP_OUT_OF_RANGE: | |
1234 | s = "AP Out of Range"; | |
1235 | break; | |
1236 | case HERMES_LINKSTATUS_AP_IN_RANGE: | |
1237 | s = "AP In Range"; | |
1238 | break; | |
1239 | case HERMES_LINKSTATUS_ASSOC_FAILED: | |
1240 | s = "Association Failed"; | |
1241 | break; | |
1242 | default: | |
1243 | s = "UNKNOWN"; | |
1244 | } | |
1245 | ||
1246 | printk(KERN_INFO "%s: New link status: %s (%04x)\n", | |
1247 | dev->name, s, status); | |
1248 | } | |
1249 | ||
16739b06 CH |
1250 | /* Search scan results for requested BSSID, join it if found */ |
1251 | static void orinoco_join_ap(struct net_device *dev) | |
1252 | { | |
1253 | struct orinoco_private *priv = netdev_priv(dev); | |
1254 | struct hermes *hw = &priv->hw; | |
1255 | int err; | |
1256 | unsigned long flags; | |
1257 | struct join_req { | |
1258 | u8 bssid[ETH_ALEN]; | |
1259 | u16 channel; | |
1260 | } __attribute__ ((packed)) req; | |
1261 | const int atom_len = offsetof(struct prism2_scan_apinfo, atim); | |
1262 | struct prism2_scan_apinfo *atom; | |
1263 | int offset = 4; | |
1264 | u8 *buf; | |
1265 | u16 len; | |
1266 | ||
1267 | /* Allocate buffer for scan results */ | |
1268 | buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL); | |
1269 | if (! buf) | |
1270 | return; | |
1271 | ||
1272 | if (orinoco_lock(priv, &flags) != 0) | |
1273 | goto out; | |
1274 | ||
1275 | /* Sanity checks in case user changed something in the meantime */ | |
1276 | if (! priv->bssid_fixed) | |
1277 | goto out; | |
1278 | ||
1279 | if (strlen(priv->desired_essid) == 0) | |
1280 | goto out; | |
1281 | ||
1282 | /* Read scan results from the firmware */ | |
1283 | err = hermes_read_ltv(hw, USER_BAP, | |
1284 | HERMES_RID_SCANRESULTSTABLE, | |
1285 | MAX_SCAN_LEN, &len, buf); | |
1286 | if (err) { | |
1287 | printk(KERN_ERR "%s: Cannot read scan results\n", | |
1288 | dev->name); | |
1289 | goto out; | |
1290 | } | |
1291 | ||
1292 | len = HERMES_RECLEN_TO_BYTES(len); | |
1293 | ||
1294 | /* Go through the scan results looking for the channel of the AP | |
1295 | * we were requested to join */ | |
1296 | for (; offset + atom_len <= len; offset += atom_len) { | |
1297 | atom = (struct prism2_scan_apinfo *) (buf + offset); | |
1298 | if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) | |
1299 | goto found; | |
1300 | } | |
1301 | ||
1302 | DEBUG(1, "%s: Requested AP not found in scan results\n", | |
1303 | dev->name); | |
1304 | goto out; | |
1305 | ||
1306 | found: | |
1307 | memcpy(req.bssid, priv->desired_bssid, ETH_ALEN); | |
1308 | req.channel = atom->channel; /* both are little-endian */ | |
1309 | err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST, | |
1310 | &req); | |
1311 | if (err) | |
1312 | printk(KERN_ERR "%s: Error issuing join request\n", dev->name); | |
1313 | ||
1314 | out: | |
1315 | kfree(buf); | |
1316 | orinoco_unlock(priv, &flags); | |
1317 | } | |
1318 | ||
1da177e4 LT |
1319 | static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw) |
1320 | { | |
1321 | struct orinoco_private *priv = netdev_priv(dev); | |
1322 | u16 infofid; | |
1323 | struct { | |
1324 | u16 len; | |
1325 | u16 type; | |
1326 | } __attribute__ ((packed)) info; | |
1327 | int len, type; | |
1328 | int err; | |
1329 | ||
1330 | /* This is an answer to an INQUIRE command that we did earlier, | |
1331 | * or an information "event" generated by the card | |
1332 | * The controller return to us a pseudo frame containing | |
1333 | * the information in question - Jean II */ | |
1334 | infofid = hermes_read_regn(hw, INFOFID); | |
1335 | ||
1336 | /* Read the info frame header - don't try too hard */ | |
1337 | err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info), | |
1338 | infofid, 0); | |
1339 | if (err) { | |
1340 | printk(KERN_ERR "%s: error %d reading info frame. " | |
1341 | "Frame dropped.\n", dev->name, err); | |
1342 | return; | |
1343 | } | |
1344 | ||
1345 | len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len)); | |
1346 | type = le16_to_cpu(info.type); | |
1347 | ||
1348 | switch (type) { | |
1349 | case HERMES_INQ_TALLIES: { | |
1350 | struct hermes_tallies_frame tallies; | |
1351 | struct iw_statistics *wstats = &priv->wstats; | |
1352 | ||
1353 | if (len > sizeof(tallies)) { | |
1354 | printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n", | |
1355 | dev->name, len); | |
1356 | len = sizeof(tallies); | |
1357 | } | |
1358 | ||
84d8a2fb CH |
1359 | err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len, |
1360 | infofid, sizeof(info)); | |
1361 | if (err) | |
1362 | break; | |
1da177e4 LT |
1363 | |
1364 | /* Increment our various counters */ | |
1365 | /* wstats->discard.nwid - no wrong BSSID stuff */ | |
1366 | wstats->discard.code += | |
1367 | le16_to_cpu(tallies.RxWEPUndecryptable); | |
1368 | if (len == sizeof(tallies)) | |
1369 | wstats->discard.code += | |
1370 | le16_to_cpu(tallies.RxDiscards_WEPICVError) + | |
1371 | le16_to_cpu(tallies.RxDiscards_WEPExcluded); | |
1372 | wstats->discard.misc += | |
1373 | le16_to_cpu(tallies.TxDiscardsWrongSA); | |
1374 | wstats->discard.fragment += | |
1375 | le16_to_cpu(tallies.RxMsgInBadMsgFragments); | |
1376 | wstats->discard.retries += | |
1377 | le16_to_cpu(tallies.TxRetryLimitExceeded); | |
1378 | /* wstats->miss.beacon - no match */ | |
1379 | } | |
1380 | break; | |
1381 | case HERMES_INQ_LINKSTATUS: { | |
1382 | struct hermes_linkstatus linkstatus; | |
1383 | u16 newstatus; | |
1384 | int connected; | |
1385 | ||
1386 | if (len != sizeof(linkstatus)) { | |
1387 | printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n", | |
1388 | dev->name, len); | |
1389 | break; | |
1390 | } | |
1391 | ||
84d8a2fb CH |
1392 | err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len, |
1393 | infofid, sizeof(info)); | |
1394 | if (err) | |
1395 | break; | |
1da177e4 LT |
1396 | newstatus = le16_to_cpu(linkstatus.linkstatus); |
1397 | ||
1398 | connected = (newstatus == HERMES_LINKSTATUS_CONNECTED) | |
1399 | || (newstatus == HERMES_LINKSTATUS_AP_CHANGE) | |
1400 | || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE); | |
1401 | ||
1402 | if (connected) | |
1403 | netif_carrier_on(dev); | |
7bb7c3a3 | 1404 | else if (!ignore_disconnect) |
1da177e4 LT |
1405 | netif_carrier_off(dev); |
1406 | ||
1407 | if (newstatus != priv->last_linkstatus) | |
1408 | print_linkstatus(dev, newstatus); | |
1409 | ||
1410 | priv->last_linkstatus = newstatus; | |
1411 | } | |
1412 | break; | |
1413 | default: | |
1414 | printk(KERN_DEBUG "%s: Unknown information frame received: " | |
1415 | "type 0x%04x, length %d\n", dev->name, type, len); | |
1416 | /* We don't actually do anything about it */ | |
1417 | break; | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw) | |
1422 | { | |
1423 | if (net_ratelimit()) | |
1424 | printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name); | |
1425 | } | |
1426 | ||
1427 | /********************************************************************/ | |
1428 | /* Internal hardware control routines */ | |
1429 | /********************************************************************/ | |
1430 | ||
1431 | int __orinoco_up(struct net_device *dev) | |
1432 | { | |
1433 | struct orinoco_private *priv = netdev_priv(dev); | |
1434 | struct hermes *hw = &priv->hw; | |
1435 | int err; | |
1436 | ||
84d8a2fb CH |
1437 | netif_carrier_off(dev); /* just to make sure */ |
1438 | ||
1da177e4 LT |
1439 | err = __orinoco_program_rids(dev); |
1440 | if (err) { | |
1441 | printk(KERN_ERR "%s: Error %d configuring card\n", | |
1442 | dev->name, err); | |
1443 | return err; | |
1444 | } | |
1445 | ||
1446 | /* Fire things up again */ | |
1447 | hermes_set_irqmask(hw, ORINOCO_INTEN); | |
1448 | err = hermes_enable_port(hw, 0); | |
1449 | if (err) { | |
1450 | printk(KERN_ERR "%s: Error %d enabling MAC port\n", | |
1451 | dev->name, err); | |
1452 | return err; | |
1453 | } | |
1454 | ||
1455 | netif_start_queue(dev); | |
1456 | ||
1457 | return 0; | |
1458 | } | |
1459 | ||
1460 | int __orinoco_down(struct net_device *dev) | |
1461 | { | |
1462 | struct orinoco_private *priv = netdev_priv(dev); | |
1463 | struct hermes *hw = &priv->hw; | |
1464 | int err; | |
1465 | ||
1466 | netif_stop_queue(dev); | |
1467 | ||
1468 | if (! priv->hw_unavailable) { | |
1469 | if (! priv->broken_disableport) { | |
1470 | err = hermes_disable_port(hw, 0); | |
1471 | if (err) { | |
1472 | /* Some firmwares (e.g. Intersil 1.3.x) seem | |
1473 | * to have problems disabling the port, oh | |
1474 | * well, too bad. */ | |
1475 | printk(KERN_WARNING "%s: Error %d disabling MAC port\n", | |
1476 | dev->name, err); | |
1477 | priv->broken_disableport = 1; | |
1478 | } | |
1479 | } | |
1480 | hermes_set_irqmask(hw, 0); | |
1481 | hermes_write_regn(hw, EVACK, 0xffff); | |
1482 | } | |
1483 | ||
1484 | /* firmware will have to reassociate */ | |
1485 | netif_carrier_off(dev); | |
1486 | priv->last_linkstatus = 0xffff; | |
1487 | ||
1488 | return 0; | |
1489 | } | |
1490 | ||
1491 | int orinoco_reinit_firmware(struct net_device *dev) | |
1492 | { | |
1493 | struct orinoco_private *priv = netdev_priv(dev); | |
1494 | struct hermes *hw = &priv->hw; | |
1495 | int err; | |
1496 | ||
1497 | err = hermes_init(hw); | |
1498 | if (err) | |
1499 | return err; | |
1500 | ||
1501 | err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid); | |
b24d4582 | 1502 | if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) { |
1da177e4 LT |
1503 | /* Try workaround for old Symbol firmware bug */ |
1504 | printk(KERN_WARNING "%s: firmware ALLOC bug detected " | |
1505 | "(old Symbol firmware?). Trying to work around... ", | |
1506 | dev->name); | |
1507 | ||
1508 | priv->nicbuf_size = TX_NICBUF_SIZE_BUG; | |
1509 | err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid); | |
1510 | if (err) | |
1511 | printk("failed!\n"); | |
1512 | else | |
1513 | printk("ok.\n"); | |
1514 | } | |
1515 | ||
1516 | return err; | |
1517 | } | |
1518 | ||
1519 | static int __orinoco_hw_set_bitrate(struct orinoco_private *priv) | |
1520 | { | |
1521 | hermes_t *hw = &priv->hw; | |
1522 | int err = 0; | |
1523 | ||
1524 | if (priv->bitratemode >= BITRATE_TABLE_SIZE) { | |
1525 | printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n", | |
1526 | priv->ndev->name, priv->bitratemode); | |
1527 | return -EINVAL; | |
1528 | } | |
1529 | ||
1530 | switch (priv->firmware_type) { | |
1531 | case FIRMWARE_TYPE_AGERE: | |
1532 | err = hermes_write_wordrec(hw, USER_BAP, | |
1533 | HERMES_RID_CNFTXRATECONTROL, | |
1534 | bitrate_table[priv->bitratemode].agere_txratectrl); | |
1535 | break; | |
1536 | case FIRMWARE_TYPE_INTERSIL: | |
1537 | case FIRMWARE_TYPE_SYMBOL: | |
1538 | err = hermes_write_wordrec(hw, USER_BAP, | |
1539 | HERMES_RID_CNFTXRATECONTROL, | |
1540 | bitrate_table[priv->bitratemode].intersil_txratectrl); | |
1541 | break; | |
1542 | default: | |
1543 | BUG(); | |
1544 | } | |
1545 | ||
1546 | return err; | |
1547 | } | |
1548 | ||
16739b06 CH |
1549 | /* Set fixed AP address */ |
1550 | static int __orinoco_hw_set_wap(struct orinoco_private *priv) | |
1551 | { | |
1552 | int roaming_flag; | |
1553 | int err = 0; | |
1554 | hermes_t *hw = &priv->hw; | |
1555 | ||
1556 | switch (priv->firmware_type) { | |
1557 | case FIRMWARE_TYPE_AGERE: | |
1558 | /* not supported */ | |
1559 | break; | |
1560 | case FIRMWARE_TYPE_INTERSIL: | |
1561 | if (priv->bssid_fixed) | |
1562 | roaming_flag = 2; | |
1563 | else | |
1564 | roaming_flag = 1; | |
1565 | ||
1566 | err = hermes_write_wordrec(hw, USER_BAP, | |
1567 | HERMES_RID_CNFROAMINGMODE, | |
1568 | roaming_flag); | |
1569 | break; | |
1570 | case FIRMWARE_TYPE_SYMBOL: | |
1571 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
1572 | HERMES_RID_CNFMANDATORYBSSID_SYMBOL, | |
1573 | &priv->desired_bssid); | |
1574 | break; | |
1575 | } | |
1576 | return err; | |
1577 | } | |
1578 | ||
1da177e4 LT |
1579 | /* Change the WEP keys and/or the current keys. Can be called |
1580 | * either from __orinoco_hw_setup_wep() or directly from | |
1581 | * orinoco_ioctl_setiwencode(). In the later case the association | |
1582 | * with the AP is not broken (if the firmware can handle it), | |
1583 | * which is needed for 802.1x implementations. */ | |
1584 | static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv) | |
1585 | { | |
1586 | hermes_t *hw = &priv->hw; | |
1587 | int err = 0; | |
1588 | ||
1589 | switch (priv->firmware_type) { | |
1590 | case FIRMWARE_TYPE_AGERE: | |
1591 | err = HERMES_WRITE_RECORD(hw, USER_BAP, | |
1592 | HERMES_RID_CNFWEPKEYS_AGERE, | |
1593 | &priv->keys); | |
1594 | if (err) | |
1595 | return err; | |
1596 | err = hermes_write_wordrec(hw, USER_BAP, | |
1597 | HERMES_RID_CNFTXKEY_AGERE, | |
1598 | priv->tx_key); | |
1599 | if (err) | |
1600 | return err; | |
1601 | break; | |
1602 | case FIRMWARE_TYPE_INTERSIL: | |
1603 | case FIRMWARE_TYPE_SYMBOL: | |
1604 | { | |
1605 | int keylen; | |
1606 | int i; | |
1607 | ||
1608 | /* Force uniform key length to work around firmware bugs */ | |
1609 | keylen = le16_to_cpu(priv->keys[priv->tx_key].len); | |
1610 | ||
1611 | if (keylen > LARGE_KEY_SIZE) { | |
1612 | printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n", | |
1613 | priv->ndev->name, priv->tx_key, keylen); | |
1614 | return -E2BIG; | |
1615 | } | |
1616 | ||
1617 | /* Write all 4 keys */ | |
1618 | for(i = 0; i < ORINOCO_MAX_KEYS; i++) { | |
1619 | err = hermes_write_ltv(hw, USER_BAP, | |
1620 | HERMES_RID_CNFDEFAULTKEY0 + i, | |
1621 | HERMES_BYTES_TO_RECLEN(keylen), | |
1622 | priv->keys[i].data); | |
1623 | if (err) | |
1624 | return err; | |
1625 | } | |
1626 | ||
1627 | /* Write the index of the key used in transmission */ | |
1628 | err = hermes_write_wordrec(hw, USER_BAP, | |
1629 | HERMES_RID_CNFWEPDEFAULTKEYID, | |
1630 | priv->tx_key); | |
1631 | if (err) | |
1632 | return err; | |
1633 | } | |
1634 | break; | |
1635 | } | |
1636 | ||
1637 | return 0; | |
1638 | } | |
1639 | ||
1640 | static int __orinoco_hw_setup_wep(struct orinoco_private *priv) | |
1641 | { | |
1642 | hermes_t *hw = &priv->hw; | |
1643 | int err = 0; | |
1644 | int master_wep_flag; | |
1645 | int auth_flag; | |
1646 | ||
1647 | if (priv->wep_on) | |
1648 | __orinoco_hw_setup_wepkeys(priv); | |
1649 | ||
1650 | if (priv->wep_restrict) | |
1651 | auth_flag = HERMES_AUTH_SHARED_KEY; | |
1652 | else | |
1653 | auth_flag = HERMES_AUTH_OPEN; | |
1654 | ||
1655 | switch (priv->firmware_type) { | |
1656 | case FIRMWARE_TYPE_AGERE: /* Agere style WEP */ | |
1657 | if (priv->wep_on) { | |
1658 | /* Enable the shared-key authentication. */ | |
1659 | err = hermes_write_wordrec(hw, USER_BAP, | |
1660 | HERMES_RID_CNFAUTHENTICATION_AGERE, | |
1661 | auth_flag); | |
1662 | } | |
1663 | err = hermes_write_wordrec(hw, USER_BAP, | |
1664 | HERMES_RID_CNFWEPENABLED_AGERE, | |
1665 | priv->wep_on); | |
1666 | if (err) | |
1667 | return err; | |
1668 | break; | |
1669 | ||
1670 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */ | |
1671 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */ | |
1672 | if (priv->wep_on) { | |
1673 | if (priv->wep_restrict || | |
1674 | (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)) | |
1675 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED | | |
1676 | HERMES_WEP_EXCL_UNENCRYPTED; | |
1677 | else | |
1678 | master_wep_flag = HERMES_WEP_PRIVACY_INVOKED; | |
1679 | ||
1680 | err = hermes_write_wordrec(hw, USER_BAP, | |
1681 | HERMES_RID_CNFAUTHENTICATION, | |
1682 | auth_flag); | |
1683 | if (err) | |
1684 | return err; | |
1685 | } else | |
1686 | master_wep_flag = 0; | |
1687 | ||
1688 | if (priv->iw_mode == IW_MODE_MONITOR) | |
1689 | master_wep_flag |= HERMES_WEP_HOST_DECRYPT; | |
1690 | ||
1691 | /* Master WEP setting : on/off */ | |
1692 | err = hermes_write_wordrec(hw, USER_BAP, | |
1693 | HERMES_RID_CNFWEPFLAGS_INTERSIL, | |
1694 | master_wep_flag); | |
1695 | if (err) | |
1696 | return err; | |
1697 | ||
1698 | break; | |
1699 | } | |
1700 | ||
1701 | return 0; | |
1702 | } | |
1703 | ||
1704 | static int __orinoco_program_rids(struct net_device *dev) | |
1705 | { | |
1706 | struct orinoco_private *priv = netdev_priv(dev); | |
1707 | hermes_t *hw = &priv->hw; | |
1708 | int err; | |
1709 | struct hermes_idstring idbuf; | |
1710 | ||
1711 | /* Set the MAC address */ | |
1712 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, | |
1713 | HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr); | |
1714 | if (err) { | |
1715 | printk(KERN_ERR "%s: Error %d setting MAC address\n", | |
1716 | dev->name, err); | |
1717 | return err; | |
1718 | } | |
1719 | ||
1720 | /* Set up the link mode */ | |
1721 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE, | |
1722 | priv->port_type); | |
1723 | if (err) { | |
1724 | printk(KERN_ERR "%s: Error %d setting port type\n", | |
1725 | dev->name, err); | |
1726 | return err; | |
1727 | } | |
1728 | /* Set the channel/frequency */ | |
d51d8b1f DG |
1729 | if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) { |
1730 | err = hermes_write_wordrec(hw, USER_BAP, | |
1731 | HERMES_RID_CNFOWNCHANNEL, | |
1732 | priv->channel); | |
1733 | if (err) { | |
1734 | printk(KERN_ERR "%s: Error %d setting channel %d\n", | |
1735 | dev->name, err, priv->channel); | |
1736 | return err; | |
1737 | } | |
1da177e4 LT |
1738 | } |
1739 | ||
1740 | if (priv->has_ibss) { | |
1741 | u16 createibss; | |
1742 | ||
1743 | if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) { | |
1744 | printk(KERN_WARNING "%s: This firmware requires an " | |
1745 | "ESSID in IBSS-Ad-Hoc mode.\n", dev->name); | |
1746 | /* With wvlan_cs, in this case, we would crash. | |
1747 | * hopefully, this driver will behave better... | |
1748 | * Jean II */ | |
1749 | createibss = 0; | |
1750 | } else { | |
1751 | createibss = priv->createibss; | |
1752 | } | |
1753 | ||
1754 | err = hermes_write_wordrec(hw, USER_BAP, | |
1755 | HERMES_RID_CNFCREATEIBSS, | |
1756 | createibss); | |
1757 | if (err) { | |
1758 | printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n", | |
1759 | dev->name, err); | |
1760 | return err; | |
1761 | } | |
1762 | } | |
1763 | ||
16739b06 CH |
1764 | /* Set the desired BSSID */ |
1765 | err = __orinoco_hw_set_wap(priv); | |
1766 | if (err) { | |
1767 | printk(KERN_ERR "%s: Error %d setting AP address\n", | |
1768 | dev->name, err); | |
1769 | return err; | |
1770 | } | |
1da177e4 LT |
1771 | /* Set the desired ESSID */ |
1772 | idbuf.len = cpu_to_le16(strlen(priv->desired_essid)); | |
1773 | memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val)); | |
1774 | /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */ | |
1775 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID, | |
1776 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), | |
1777 | &idbuf); | |
1778 | if (err) { | |
1779 | printk(KERN_ERR "%s: Error %d setting OWNSSID\n", | |
1780 | dev->name, err); | |
1781 | return err; | |
1782 | } | |
1783 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID, | |
1784 | HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2), | |
1785 | &idbuf); | |
1786 | if (err) { | |
1787 | printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n", | |
1788 | dev->name, err); | |
1789 | return err; | |
1790 | } | |
1791 | ||
1792 | /* Set the station name */ | |
1793 | idbuf.len = cpu_to_le16(strlen(priv->nick)); | |
1794 | memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val)); | |
1795 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, | |
1796 | HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2), | |
1797 | &idbuf); | |
1798 | if (err) { | |
1799 | printk(KERN_ERR "%s: Error %d setting nickname\n", | |
1800 | dev->name, err); | |
1801 | return err; | |
1802 | } | |
1803 | ||
1804 | /* Set AP density */ | |
1805 | if (priv->has_sensitivity) { | |
1806 | err = hermes_write_wordrec(hw, USER_BAP, | |
1807 | HERMES_RID_CNFSYSTEMSCALE, | |
1808 | priv->ap_density); | |
1809 | if (err) { | |
1810 | printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. " | |
1811 | "Disabling sensitivity control\n", | |
1812 | dev->name, err); | |
1813 | ||
1814 | priv->has_sensitivity = 0; | |
1815 | } | |
1816 | } | |
1817 | ||
1818 | /* Set RTS threshold */ | |
1819 | err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, | |
1820 | priv->rts_thresh); | |
1821 | if (err) { | |
1822 | printk(KERN_ERR "%s: Error %d setting RTS threshold\n", | |
1823 | dev->name, err); | |
1824 | return err; | |
1825 | } | |
1826 | ||
1827 | /* Set fragmentation threshold or MWO robustness */ | |
1828 | if (priv->has_mwo) | |
1829 | err = hermes_write_wordrec(hw, USER_BAP, | |
1830 | HERMES_RID_CNFMWOROBUST_AGERE, | |
1831 | priv->mwo_robust); | |
1832 | else | |
1833 | err = hermes_write_wordrec(hw, USER_BAP, | |
1834 | HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
1835 | priv->frag_thresh); | |
1836 | if (err) { | |
1837 | printk(KERN_ERR "%s: Error %d setting fragmentation\n", | |
1838 | dev->name, err); | |
1839 | return err; | |
1840 | } | |
1841 | ||
1842 | /* Set bitrate */ | |
1843 | err = __orinoco_hw_set_bitrate(priv); | |
1844 | if (err) { | |
1845 | printk(KERN_ERR "%s: Error %d setting bitrate\n", | |
1846 | dev->name, err); | |
1847 | return err; | |
1848 | } | |
1849 | ||
1850 | /* Set power management */ | |
1851 | if (priv->has_pm) { | |
1852 | err = hermes_write_wordrec(hw, USER_BAP, | |
1853 | HERMES_RID_CNFPMENABLED, | |
1854 | priv->pm_on); | |
1855 | if (err) { | |
1856 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
1857 | dev->name, err); | |
1858 | return err; | |
1859 | } | |
1860 | ||
1861 | err = hermes_write_wordrec(hw, USER_BAP, | |
1862 | HERMES_RID_CNFMULTICASTRECEIVE, | |
1863 | priv->pm_mcast); | |
1864 | if (err) { | |
1865 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
1866 | dev->name, err); | |
1867 | return err; | |
1868 | } | |
1869 | err = hermes_write_wordrec(hw, USER_BAP, | |
1870 | HERMES_RID_CNFMAXSLEEPDURATION, | |
1871 | priv->pm_period); | |
1872 | if (err) { | |
1873 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
1874 | dev->name, err); | |
1875 | return err; | |
1876 | } | |
1877 | err = hermes_write_wordrec(hw, USER_BAP, | |
1878 | HERMES_RID_CNFPMHOLDOVERDURATION, | |
1879 | priv->pm_timeout); | |
1880 | if (err) { | |
1881 | printk(KERN_ERR "%s: Error %d setting up PM\n", | |
1882 | dev->name, err); | |
1883 | return err; | |
1884 | } | |
1885 | } | |
1886 | ||
1887 | /* Set preamble - only for Symbol so far... */ | |
1888 | if (priv->has_preamble) { | |
1889 | err = hermes_write_wordrec(hw, USER_BAP, | |
1890 | HERMES_RID_CNFPREAMBLE_SYMBOL, | |
1891 | priv->preamble); | |
1892 | if (err) { | |
1893 | printk(KERN_ERR "%s: Error %d setting preamble\n", | |
1894 | dev->name, err); | |
1895 | return err; | |
1896 | } | |
1897 | } | |
1898 | ||
1899 | /* Set up encryption */ | |
1900 | if (priv->has_wep) { | |
1901 | err = __orinoco_hw_setup_wep(priv); | |
1902 | if (err) { | |
1903 | printk(KERN_ERR "%s: Error %d activating WEP\n", | |
1904 | dev->name, err); | |
1905 | return err; | |
1906 | } | |
1907 | } | |
1908 | ||
1909 | /* Set promiscuity / multicast*/ | |
1910 | priv->promiscuous = 0; | |
1911 | priv->mc_count = 0; | |
1912 | __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */ | |
1913 | ||
1914 | return 0; | |
1915 | } | |
1916 | ||
1917 | /* FIXME: return int? */ | |
1918 | static void | |
1919 | __orinoco_set_multicast_list(struct net_device *dev) | |
1920 | { | |
1921 | struct orinoco_private *priv = netdev_priv(dev); | |
1922 | hermes_t *hw = &priv->hw; | |
1923 | int err = 0; | |
1924 | int promisc, mc_count; | |
1925 | ||
1926 | /* The Hermes doesn't seem to have an allmulti mode, so we go | |
1927 | * into promiscuous mode and let the upper levels deal. */ | |
1928 | if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) || | |
1929 | (dev->mc_count > MAX_MULTICAST(priv)) ) { | |
1930 | promisc = 1; | |
1931 | mc_count = 0; | |
1932 | } else { | |
1933 | promisc = 0; | |
1934 | mc_count = dev->mc_count; | |
1935 | } | |
1936 | ||
1937 | if (promisc != priv->promiscuous) { | |
1938 | err = hermes_write_wordrec(hw, USER_BAP, | |
1939 | HERMES_RID_CNFPROMISCUOUSMODE, | |
1940 | promisc); | |
1941 | if (err) { | |
1942 | printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n", | |
1943 | dev->name, err); | |
1944 | } else | |
1945 | priv->promiscuous = promisc; | |
1946 | } | |
1947 | ||
1948 | if (! promisc && (mc_count || priv->mc_count) ) { | |
1949 | struct dev_mc_list *p = dev->mc_list; | |
1950 | struct hermes_multicast mclist; | |
1951 | int i; | |
1952 | ||
1953 | for (i = 0; i < mc_count; i++) { | |
1954 | /* paranoia: is list shorter than mc_count? */ | |
1955 | BUG_ON(! p); | |
1956 | /* paranoia: bad address size in list? */ | |
1957 | BUG_ON(p->dmi_addrlen != ETH_ALEN); | |
1958 | ||
1959 | memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN); | |
1960 | p = p->next; | |
1961 | } | |
1962 | ||
1963 | if (p) | |
1964 | printk(KERN_WARNING "%s: Multicast list is " | |
1965 | "longer than mc_count\n", dev->name); | |
1966 | ||
1967 | err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES, | |
1968 | HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN), | |
1969 | &mclist); | |
1970 | if (err) | |
1971 | printk(KERN_ERR "%s: Error %d setting multicast list.\n", | |
1972 | dev->name, err); | |
1973 | else | |
1974 | priv->mc_count = mc_count; | |
1975 | } | |
1976 | ||
1977 | /* Since we can set the promiscuous flag when it wasn't asked | |
1978 | for, make sure the net_device knows about it. */ | |
1979 | if (priv->promiscuous) | |
1980 | dev->flags |= IFF_PROMISC; | |
1981 | else | |
1982 | dev->flags &= ~IFF_PROMISC; | |
1983 | } | |
1984 | ||
1da177e4 LT |
1985 | /* This must be called from user context, without locks held - use |
1986 | * schedule_work() */ | |
1987 | static void orinoco_reset(struct net_device *dev) | |
1988 | { | |
1989 | struct orinoco_private *priv = netdev_priv(dev); | |
1990 | struct hermes *hw = &priv->hw; | |
8551cb98 | 1991 | int err; |
1da177e4 LT |
1992 | unsigned long flags; |
1993 | ||
1994 | if (orinoco_lock(priv, &flags) != 0) | |
1995 | /* When the hardware becomes available again, whatever | |
1996 | * detects that is responsible for re-initializing | |
1997 | * it. So no need for anything further */ | |
1998 | return; | |
1999 | ||
2000 | netif_stop_queue(dev); | |
2001 | ||
2002 | /* Shut off interrupts. Depending on what state the hardware | |
2003 | * is in, this might not work, but we'll try anyway */ | |
2004 | hermes_set_irqmask(hw, 0); | |
2005 | hermes_write_regn(hw, EVACK, 0xffff); | |
2006 | ||
2007 | priv->hw_unavailable++; | |
2008 | priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */ | |
2009 | netif_carrier_off(dev); | |
2010 | ||
2011 | orinoco_unlock(priv, &flags); | |
2012 | ||
8551cb98 | 2013 | if (priv->hard_reset) { |
1da177e4 | 2014 | err = (*priv->hard_reset)(priv); |
8551cb98 CH |
2015 | if (err) { |
2016 | printk(KERN_ERR "%s: orinoco_reset: Error %d " | |
2017 | "performing hard reset\n", dev->name, err); | |
2018 | goto disable; | |
2019 | } | |
1da177e4 LT |
2020 | } |
2021 | ||
2022 | err = orinoco_reinit_firmware(dev); | |
2023 | if (err) { | |
2024 | printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n", | |
2025 | dev->name, err); | |
8551cb98 | 2026 | goto disable; |
1da177e4 LT |
2027 | } |
2028 | ||
2029 | spin_lock_irq(&priv->lock); /* This has to be called from user context */ | |
2030 | ||
2031 | priv->hw_unavailable--; | |
2032 | ||
2033 | /* priv->open or priv->hw_unavailable might have changed while | |
2034 | * we dropped the lock */ | |
2035 | if (priv->open && (! priv->hw_unavailable)) { | |
2036 | err = __orinoco_up(dev); | |
2037 | if (err) { | |
2038 | printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n", | |
2039 | dev->name, err); | |
2040 | } else | |
2041 | dev->trans_start = jiffies; | |
2042 | } | |
2043 | ||
2044 | spin_unlock_irq(&priv->lock); | |
2045 | ||
2046 | return; | |
8551cb98 CH |
2047 | disable: |
2048 | hermes_set_irqmask(hw, 0); | |
2049 | netif_device_detach(dev); | |
2050 | printk(KERN_ERR "%s: Device has been disabled!\n", dev->name); | |
1da177e4 LT |
2051 | } |
2052 | ||
2053 | /********************************************************************/ | |
2054 | /* Interrupt handler */ | |
2055 | /********************************************************************/ | |
2056 | ||
2057 | static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw) | |
2058 | { | |
2059 | printk(KERN_DEBUG "%s: TICK\n", dev->name); | |
2060 | } | |
2061 | ||
2062 | static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw) | |
2063 | { | |
2064 | /* This seems to happen a fair bit under load, but ignoring it | |
2065 | seems to work fine...*/ | |
2066 | printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n", | |
2067 | dev->name); | |
2068 | } | |
2069 | ||
2070 | irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs) | |
2071 | { | |
2072 | struct net_device *dev = (struct net_device *)dev_id; | |
2073 | struct orinoco_private *priv = netdev_priv(dev); | |
2074 | hermes_t *hw = &priv->hw; | |
2075 | int count = MAX_IRQLOOPS_PER_IRQ; | |
2076 | u16 evstat, events; | |
2077 | /* These are used to detect a runaway interrupt situation */ | |
2078 | /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy, | |
2079 | * we panic and shut down the hardware */ | |
2080 | static int last_irq_jiffy = 0; /* jiffies value the last time | |
2081 | * we were called */ | |
2082 | static int loops_this_jiffy = 0; | |
2083 | unsigned long flags; | |
2084 | ||
2085 | if (orinoco_lock(priv, &flags) != 0) { | |
2086 | /* If hw is unavailable - we don't know if the irq was | |
2087 | * for us or not */ | |
2088 | return IRQ_HANDLED; | |
2089 | } | |
2090 | ||
2091 | evstat = hermes_read_regn(hw, EVSTAT); | |
2092 | events = evstat & hw->inten; | |
2093 | if (! events) { | |
2094 | orinoco_unlock(priv, &flags); | |
2095 | return IRQ_NONE; | |
2096 | } | |
2097 | ||
2098 | if (jiffies != last_irq_jiffy) | |
2099 | loops_this_jiffy = 0; | |
2100 | last_irq_jiffy = jiffies; | |
2101 | ||
2102 | while (events && count--) { | |
2103 | if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) { | |
2104 | printk(KERN_WARNING "%s: IRQ handler is looping too " | |
2105 | "much! Resetting.\n", dev->name); | |
2106 | /* Disable interrupts for now */ | |
2107 | hermes_set_irqmask(hw, 0); | |
2108 | schedule_work(&priv->reset_work); | |
2109 | break; | |
2110 | } | |
2111 | ||
2112 | /* Check the card hasn't been removed */ | |
2113 | if (! hermes_present(hw)) { | |
2114 | DEBUG(0, "orinoco_interrupt(): card removed\n"); | |
2115 | break; | |
2116 | } | |
2117 | ||
2118 | if (events & HERMES_EV_TICK) | |
2119 | __orinoco_ev_tick(dev, hw); | |
2120 | if (events & HERMES_EV_WTERR) | |
2121 | __orinoco_ev_wterr(dev, hw); | |
2122 | if (events & HERMES_EV_INFDROP) | |
2123 | __orinoco_ev_infdrop(dev, hw); | |
2124 | if (events & HERMES_EV_INFO) | |
2125 | __orinoco_ev_info(dev, hw); | |
2126 | if (events & HERMES_EV_RX) | |
2127 | __orinoco_ev_rx(dev, hw); | |
2128 | if (events & HERMES_EV_TXEXC) | |
2129 | __orinoco_ev_txexc(dev, hw); | |
2130 | if (events & HERMES_EV_TX) | |
2131 | __orinoco_ev_tx(dev, hw); | |
2132 | if (events & HERMES_EV_ALLOC) | |
2133 | __orinoco_ev_alloc(dev, hw); | |
2134 | ||
84d8a2fb | 2135 | hermes_write_regn(hw, EVACK, evstat); |
1da177e4 LT |
2136 | |
2137 | evstat = hermes_read_regn(hw, EVSTAT); | |
2138 | events = evstat & hw->inten; | |
2139 | }; | |
2140 | ||
2141 | orinoco_unlock(priv, &flags); | |
2142 | return IRQ_HANDLED; | |
2143 | } | |
2144 | ||
2145 | /********************************************************************/ | |
2146 | /* Initialization */ | |
2147 | /********************************************************************/ | |
2148 | ||
2149 | struct comp_id { | |
2150 | u16 id, variant, major, minor; | |
2151 | } __attribute__ ((packed)); | |
2152 | ||
2153 | static inline fwtype_t determine_firmware_type(struct comp_id *nic_id) | |
2154 | { | |
2155 | if (nic_id->id < 0x8000) | |
2156 | return FIRMWARE_TYPE_AGERE; | |
2157 | else if (nic_id->id == 0x8000 && nic_id->major == 0) | |
2158 | return FIRMWARE_TYPE_SYMBOL; | |
2159 | else | |
2160 | return FIRMWARE_TYPE_INTERSIL; | |
2161 | } | |
2162 | ||
2163 | /* Set priv->firmware type, determine firmware properties */ | |
2164 | static int determine_firmware(struct net_device *dev) | |
2165 | { | |
2166 | struct orinoco_private *priv = netdev_priv(dev); | |
2167 | hermes_t *hw = &priv->hw; | |
2168 | int err; | |
2169 | struct comp_id nic_id, sta_id; | |
2170 | unsigned int firmver; | |
2171 | char tmp[SYMBOL_MAX_VER_LEN+1]; | |
2172 | ||
2173 | /* Get the hardware version */ | |
2174 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id); | |
2175 | if (err) { | |
2176 | printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n", | |
2177 | dev->name, err); | |
2178 | return err; | |
2179 | } | |
2180 | ||
2181 | le16_to_cpus(&nic_id.id); | |
2182 | le16_to_cpus(&nic_id.variant); | |
2183 | le16_to_cpus(&nic_id.major); | |
2184 | le16_to_cpus(&nic_id.minor); | |
2185 | printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n", | |
2186 | dev->name, nic_id.id, nic_id.variant, | |
2187 | nic_id.major, nic_id.minor); | |
2188 | ||
2189 | priv->firmware_type = determine_firmware_type(&nic_id); | |
2190 | ||
2191 | /* Get the firmware version */ | |
2192 | err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id); | |
2193 | if (err) { | |
2194 | printk(KERN_ERR "%s: Cannot read station identity: error %d\n", | |
2195 | dev->name, err); | |
2196 | return err; | |
2197 | } | |
2198 | ||
2199 | le16_to_cpus(&sta_id.id); | |
2200 | le16_to_cpus(&sta_id.variant); | |
2201 | le16_to_cpus(&sta_id.major); | |
2202 | le16_to_cpus(&sta_id.minor); | |
2203 | printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n", | |
2204 | dev->name, sta_id.id, sta_id.variant, | |
2205 | sta_id.major, sta_id.minor); | |
2206 | ||
2207 | switch (sta_id.id) { | |
2208 | case 0x15: | |
2209 | printk(KERN_ERR "%s: Primary firmware is active\n", | |
2210 | dev->name); | |
2211 | return -ENODEV; | |
2212 | case 0x14b: | |
2213 | printk(KERN_ERR "%s: Tertiary firmware is active\n", | |
2214 | dev->name); | |
2215 | return -ENODEV; | |
2216 | case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */ | |
2217 | case 0x21: /* Symbol Spectrum24 Trilogy */ | |
2218 | break; | |
2219 | default: | |
2220 | printk(KERN_NOTICE "%s: Unknown station ID, please report\n", | |
2221 | dev->name); | |
2222 | break; | |
2223 | } | |
2224 | ||
2225 | /* Default capabilities */ | |
2226 | priv->has_sensitivity = 1; | |
2227 | priv->has_mwo = 0; | |
2228 | priv->has_preamble = 0; | |
2229 | priv->has_port3 = 1; | |
2230 | priv->has_ibss = 1; | |
2231 | priv->has_wep = 0; | |
2232 | priv->has_big_wep = 0; | |
2233 | ||
2234 | /* Determine capabilities from the firmware version */ | |
2235 | switch (priv->firmware_type) { | |
2236 | case FIRMWARE_TYPE_AGERE: | |
2237 | /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout, | |
2238 | ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */ | |
2239 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
2240 | "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor); | |
2241 | ||
2242 | firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor; | |
2243 | ||
2244 | priv->has_ibss = (firmver >= 0x60006); | |
2245 | priv->has_wep = (firmver >= 0x40020); | |
2246 | priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell | |
2247 | Gold cards from the others? */ | |
2248 | priv->has_mwo = (firmver >= 0x60000); | |
2249 | priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */ | |
2250 | priv->ibss_port = 1; | |
2251 | ||
2252 | /* Tested with Agere firmware : | |
2253 | * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II | |
2254 | * Tested CableTron firmware : 4.32 => Anton */ | |
2255 | break; | |
2256 | case FIRMWARE_TYPE_SYMBOL: | |
2257 | /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */ | |
2258 | /* Intel MAC : 00:02:B3:* */ | |
2259 | /* 3Com MAC : 00:50:DA:* */ | |
2260 | memset(tmp, 0, sizeof(tmp)); | |
2261 | /* Get the Symbol firmware version */ | |
2262 | err = hermes_read_ltv(hw, USER_BAP, | |
2263 | HERMES_RID_SECONDARYVERSION_SYMBOL, | |
2264 | SYMBOL_MAX_VER_LEN, NULL, &tmp); | |
2265 | if (err) { | |
2266 | printk(KERN_WARNING | |
2267 | "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n", | |
2268 | dev->name, err); | |
2269 | firmver = 0; | |
2270 | tmp[0] = '\0'; | |
2271 | } else { | |
2272 | /* The firmware revision is a string, the format is | |
2273 | * something like : "V2.20-01". | |
2274 | * Quick and dirty parsing... - Jean II | |
2275 | */ | |
2276 | firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12) | |
2277 | | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4) | |
2278 | | (tmp[7] - '0'); | |
2279 | ||
2280 | tmp[SYMBOL_MAX_VER_LEN] = '\0'; | |
2281 | } | |
2282 | ||
2283 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
2284 | "Symbol %s", tmp); | |
2285 | ||
2286 | priv->has_ibss = (firmver >= 0x20000); | |
2287 | priv->has_wep = (firmver >= 0x15012); | |
2288 | priv->has_big_wep = (firmver >= 0x20000); | |
2289 | priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) || | |
2290 | (firmver >= 0x29000 && firmver < 0x30000) || | |
2291 | firmver >= 0x31000; | |
2292 | priv->has_preamble = (firmver >= 0x20000); | |
2293 | priv->ibss_port = 4; | |
649e59e6 CH |
2294 | priv->broken_disableport = (firmver == 0x25013) || |
2295 | (firmver >= 0x30000 && firmver <= 0x31000); | |
1da177e4 LT |
2296 | /* Tested with Intel firmware : 0x20015 => Jean II */ |
2297 | /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */ | |
2298 | break; | |
2299 | case FIRMWARE_TYPE_INTERSIL: | |
2300 | /* D-Link, Linksys, Adtron, ZoomAir, and many others... | |
2301 | * Samsung, Compaq 100/200 and Proxim are slightly | |
2302 | * different and less well tested */ | |
2303 | /* D-Link MAC : 00:40:05:* */ | |
2304 | /* Addtron MAC : 00:90:D1:* */ | |
2305 | snprintf(priv->fw_name, sizeof(priv->fw_name) - 1, | |
2306 | "Intersil %d.%d.%d", sta_id.major, sta_id.minor, | |
2307 | sta_id.variant); | |
2308 | ||
2309 | firmver = ((unsigned long)sta_id.major << 16) | | |
2310 | ((unsigned long)sta_id.minor << 8) | sta_id.variant; | |
2311 | ||
2312 | priv->has_ibss = (firmver >= 0x000700); /* FIXME */ | |
2313 | priv->has_big_wep = priv->has_wep = (firmver >= 0x000800); | |
2314 | priv->has_pm = (firmver >= 0x000700); | |
2315 | ||
2316 | if (firmver >= 0x000800) | |
2317 | priv->ibss_port = 0; | |
2318 | else { | |
2319 | printk(KERN_NOTICE "%s: Intersil firmware earlier " | |
2320 | "than v0.8.x - several features not supported\n", | |
2321 | dev->name); | |
2322 | priv->ibss_port = 1; | |
2323 | } | |
2324 | break; | |
2325 | } | |
2326 | printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name, | |
2327 | priv->fw_name); | |
2328 | ||
2329 | return 0; | |
2330 | } | |
2331 | ||
2332 | static int orinoco_init(struct net_device *dev) | |
2333 | { | |
2334 | struct orinoco_private *priv = netdev_priv(dev); | |
2335 | hermes_t *hw = &priv->hw; | |
2336 | int err = 0; | |
2337 | struct hermes_idstring nickbuf; | |
2338 | u16 reclen; | |
2339 | int len; | |
2340 | ||
2341 | TRACE_ENTER(dev->name); | |
2342 | ||
2343 | /* No need to lock, the hw_unavailable flag is already set in | |
2344 | * alloc_orinocodev() */ | |
2345 | priv->nicbuf_size = IEEE802_11_FRAME_LEN + ETH_HLEN; | |
2346 | ||
2347 | /* Initialize the firmware */ | |
b24d4582 | 2348 | err = orinoco_reinit_firmware(dev); |
1da177e4 LT |
2349 | if (err != 0) { |
2350 | printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n", | |
2351 | dev->name, err); | |
2352 | goto out; | |
2353 | } | |
2354 | ||
2355 | err = determine_firmware(dev); | |
2356 | if (err != 0) { | |
2357 | printk(KERN_ERR "%s: Incompatible firmware, aborting\n", | |
2358 | dev->name); | |
2359 | goto out; | |
2360 | } | |
2361 | ||
2362 | if (priv->has_port3) | |
2363 | printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name); | |
2364 | if (priv->has_ibss) | |
2365 | printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n", | |
2366 | dev->name); | |
2367 | if (priv->has_wep) { | |
2368 | printk(KERN_DEBUG "%s: WEP supported, ", dev->name); | |
2369 | if (priv->has_big_wep) | |
2370 | printk("104-bit key\n"); | |
2371 | else | |
2372 | printk("40-bit key\n"); | |
2373 | } | |
2374 | ||
2375 | /* Get the MAC address */ | |
2376 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, | |
2377 | ETH_ALEN, NULL, dev->dev_addr); | |
2378 | if (err) { | |
2379 | printk(KERN_WARNING "%s: failed to read MAC address!\n", | |
2380 | dev->name); | |
2381 | goto out; | |
2382 | } | |
2383 | ||
2384 | printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n", | |
2385 | dev->name, dev->dev_addr[0], dev->dev_addr[1], | |
2386 | dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4], | |
2387 | dev->dev_addr[5]); | |
2388 | ||
2389 | /* Get the station name */ | |
2390 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, | |
2391 | sizeof(nickbuf), &reclen, &nickbuf); | |
2392 | if (err) { | |
2393 | printk(KERN_ERR "%s: failed to read station name\n", | |
2394 | dev->name); | |
2395 | goto out; | |
2396 | } | |
2397 | if (nickbuf.len) | |
2398 | len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len)); | |
2399 | else | |
2400 | len = min(IW_ESSID_MAX_SIZE, 2 * reclen); | |
2401 | memcpy(priv->nick, &nickbuf.val, len); | |
2402 | priv->nick[len] = '\0'; | |
2403 | ||
2404 | printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick); | |
2405 | ||
2406 | /* Get allowed channels */ | |
2407 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST, | |
2408 | &priv->channel_mask); | |
2409 | if (err) { | |
2410 | printk(KERN_ERR "%s: failed to read channel list!\n", | |
2411 | dev->name); | |
2412 | goto out; | |
2413 | } | |
2414 | ||
2415 | /* Get initial AP density */ | |
2416 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, | |
2417 | &priv->ap_density); | |
2418 | if (err || priv->ap_density < 1 || priv->ap_density > 3) { | |
2419 | priv->has_sensitivity = 0; | |
2420 | } | |
2421 | ||
2422 | /* Get initial RTS threshold */ | |
2423 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, | |
2424 | &priv->rts_thresh); | |
2425 | if (err) { | |
2426 | printk(KERN_ERR "%s: failed to read RTS threshold!\n", | |
2427 | dev->name); | |
2428 | goto out; | |
2429 | } | |
2430 | ||
2431 | /* Get initial fragmentation settings */ | |
2432 | if (priv->has_mwo) | |
2433 | err = hermes_read_wordrec(hw, USER_BAP, | |
2434 | HERMES_RID_CNFMWOROBUST_AGERE, | |
2435 | &priv->mwo_robust); | |
2436 | else | |
2437 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
2438 | &priv->frag_thresh); | |
2439 | if (err) { | |
2440 | printk(KERN_ERR "%s: failed to read fragmentation settings!\n", | |
2441 | dev->name); | |
2442 | goto out; | |
2443 | } | |
2444 | ||
2445 | /* Power management setup */ | |
2446 | if (priv->has_pm) { | |
2447 | priv->pm_on = 0; | |
2448 | priv->pm_mcast = 1; | |
2449 | err = hermes_read_wordrec(hw, USER_BAP, | |
2450 | HERMES_RID_CNFMAXSLEEPDURATION, | |
2451 | &priv->pm_period); | |
2452 | if (err) { | |
2453 | printk(KERN_ERR "%s: failed to read power management period!\n", | |
2454 | dev->name); | |
2455 | goto out; | |
2456 | } | |
2457 | err = hermes_read_wordrec(hw, USER_BAP, | |
2458 | HERMES_RID_CNFPMHOLDOVERDURATION, | |
2459 | &priv->pm_timeout); | |
2460 | if (err) { | |
2461 | printk(KERN_ERR "%s: failed to read power management timeout!\n", | |
2462 | dev->name); | |
2463 | goto out; | |
2464 | } | |
2465 | } | |
2466 | ||
2467 | /* Preamble setup */ | |
2468 | if (priv->has_preamble) { | |
2469 | err = hermes_read_wordrec(hw, USER_BAP, | |
2470 | HERMES_RID_CNFPREAMBLE_SYMBOL, | |
2471 | &priv->preamble); | |
2472 | if (err) | |
2473 | goto out; | |
2474 | } | |
2475 | ||
2476 | /* Set up the default configuration */ | |
2477 | priv->iw_mode = IW_MODE_INFRA; | |
2478 | /* By default use IEEE/IBSS ad-hoc mode if we have it */ | |
2479 | priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss); | |
2480 | set_port_type(priv); | |
d51d8b1f | 2481 | priv->channel = 0; /* use firmware default */ |
1da177e4 LT |
2482 | |
2483 | priv->promiscuous = 0; | |
2484 | priv->wep_on = 0; | |
2485 | priv->tx_key = 0; | |
2486 | ||
1da177e4 LT |
2487 | /* Make the hardware available, as long as it hasn't been |
2488 | * removed elsewhere (e.g. by PCMCIA hot unplug) */ | |
2489 | spin_lock_irq(&priv->lock); | |
2490 | priv->hw_unavailable--; | |
2491 | spin_unlock_irq(&priv->lock); | |
2492 | ||
2493 | printk(KERN_DEBUG "%s: ready\n", dev->name); | |
2494 | ||
2495 | out: | |
2496 | TRACE_EXIT(dev->name); | |
2497 | return err; | |
2498 | } | |
2499 | ||
2500 | struct net_device *alloc_orinocodev(int sizeof_card, | |
2501 | int (*hard_reset)(struct orinoco_private *)) | |
2502 | { | |
2503 | struct net_device *dev; | |
2504 | struct orinoco_private *priv; | |
2505 | ||
2506 | dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card); | |
2507 | if (! dev) | |
2508 | return NULL; | |
2509 | priv = netdev_priv(dev); | |
2510 | priv->ndev = dev; | |
2511 | if (sizeof_card) | |
84d8a2fb | 2512 | priv->card = (void *)((unsigned long)priv |
1da177e4 LT |
2513 | + sizeof(struct orinoco_private)); |
2514 | else | |
2515 | priv->card = NULL; | |
2516 | ||
2517 | /* Setup / override net_device fields */ | |
2518 | dev->init = orinoco_init; | |
2519 | dev->hard_start_xmit = orinoco_xmit; | |
2520 | dev->tx_timeout = orinoco_tx_timeout; | |
2521 | dev->watchdog_timeo = HZ; /* 1 second timeout */ | |
2522 | dev->get_stats = orinoco_get_stats; | |
1fab2e8b | 2523 | dev->ethtool_ops = &orinoco_ethtool_ops; |
1da177e4 | 2524 | dev->get_wireless_stats = orinoco_get_wireless_stats; |
620554e4 | 2525 | dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def; |
1da177e4 LT |
2526 | dev->change_mtu = orinoco_change_mtu; |
2527 | dev->set_multicast_list = orinoco_set_multicast_list; | |
2528 | /* we use the default eth_mac_addr for setting the MAC addr */ | |
2529 | ||
2530 | /* Set up default callbacks */ | |
2531 | dev->open = orinoco_open; | |
2532 | dev->stop = orinoco_stop; | |
2533 | priv->hard_reset = hard_reset; | |
2534 | ||
2535 | spin_lock_init(&priv->lock); | |
2536 | priv->open = 0; | |
2537 | priv->hw_unavailable = 1; /* orinoco_init() must clear this | |
2538 | * before anything else touches the | |
2539 | * hardware */ | |
2540 | INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev); | |
16739b06 | 2541 | INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev); |
1da177e4 LT |
2542 | |
2543 | netif_carrier_off(dev); | |
2544 | priv->last_linkstatus = 0xffff; | |
2545 | ||
2546 | return dev; | |
2547 | ||
2548 | } | |
2549 | ||
2550 | void free_orinocodev(struct net_device *dev) | |
2551 | { | |
2552 | free_netdev(dev); | |
2553 | } | |
2554 | ||
2555 | /********************************************************************/ | |
2556 | /* Wireless extensions */ | |
2557 | /********************************************************************/ | |
2558 | ||
1da177e4 LT |
2559 | static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active, |
2560 | char buf[IW_ESSID_MAX_SIZE+1]) | |
2561 | { | |
2562 | hermes_t *hw = &priv->hw; | |
2563 | int err = 0; | |
2564 | struct hermes_idstring essidbuf; | |
2565 | char *p = (char *)(&essidbuf.val); | |
2566 | int len; | |
2567 | unsigned long flags; | |
2568 | ||
2569 | if (orinoco_lock(priv, &flags) != 0) | |
2570 | return -EBUSY; | |
2571 | ||
2572 | if (strlen(priv->desired_essid) > 0) { | |
2573 | /* We read the desired SSID from the hardware rather | |
2574 | than from priv->desired_essid, just in case the | |
2575 | firmware is allowed to change it on us. I'm not | |
2576 | sure about this */ | |
2577 | /* My guess is that the OWNSSID should always be whatever | |
2578 | * we set to the card, whereas CURRENT_SSID is the one that | |
2579 | * may change... - Jean II */ | |
2580 | u16 rid; | |
2581 | ||
2582 | *active = 1; | |
2583 | ||
2584 | rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID : | |
2585 | HERMES_RID_CNFDESIREDSSID; | |
2586 | ||
2587 | err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf), | |
2588 | NULL, &essidbuf); | |
2589 | if (err) | |
2590 | goto fail_unlock; | |
2591 | } else { | |
2592 | *active = 0; | |
2593 | ||
2594 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID, | |
2595 | sizeof(essidbuf), NULL, &essidbuf); | |
2596 | if (err) | |
2597 | goto fail_unlock; | |
2598 | } | |
2599 | ||
2600 | len = le16_to_cpu(essidbuf.len); | |
84d8a2fb | 2601 | BUG_ON(len > IW_ESSID_MAX_SIZE); |
1da177e4 LT |
2602 | |
2603 | memset(buf, 0, IW_ESSID_MAX_SIZE+1); | |
2604 | memcpy(buf, p, len); | |
2605 | buf[len] = '\0'; | |
2606 | ||
2607 | fail_unlock: | |
2608 | orinoco_unlock(priv, &flags); | |
2609 | ||
2610 | return err; | |
2611 | } | |
2612 | ||
2613 | static long orinoco_hw_get_freq(struct orinoco_private *priv) | |
2614 | { | |
2615 | ||
2616 | hermes_t *hw = &priv->hw; | |
2617 | int err = 0; | |
2618 | u16 channel; | |
2619 | long freq = 0; | |
2620 | unsigned long flags; | |
2621 | ||
2622 | if (orinoco_lock(priv, &flags) != 0) | |
2623 | return -EBUSY; | |
2624 | ||
2625 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel); | |
2626 | if (err) | |
2627 | goto out; | |
2628 | ||
2629 | /* Intersil firmware 1.3.5 returns 0 when the interface is down */ | |
2630 | if (channel == 0) { | |
2631 | err = -EBUSY; | |
2632 | goto out; | |
2633 | } | |
2634 | ||
2635 | if ( (channel < 1) || (channel > NUM_CHANNELS) ) { | |
2636 | printk(KERN_WARNING "%s: Channel out of range (%d)!\n", | |
2637 | priv->ndev->name, channel); | |
2638 | err = -EBUSY; | |
2639 | goto out; | |
2640 | ||
2641 | } | |
2642 | freq = channel_frequency[channel-1] * 100000; | |
2643 | ||
2644 | out: | |
2645 | orinoco_unlock(priv, &flags); | |
2646 | ||
2647 | if (err > 0) | |
2648 | err = -EBUSY; | |
2649 | return err ? err : freq; | |
2650 | } | |
2651 | ||
2652 | static int orinoco_hw_get_bitratelist(struct orinoco_private *priv, | |
2653 | int *numrates, s32 *rates, int max) | |
2654 | { | |
2655 | hermes_t *hw = &priv->hw; | |
2656 | struct hermes_idstring list; | |
2657 | unsigned char *p = (unsigned char *)&list.val; | |
2658 | int err = 0; | |
2659 | int num; | |
2660 | int i; | |
2661 | unsigned long flags; | |
2662 | ||
2663 | if (orinoco_lock(priv, &flags) != 0) | |
2664 | return -EBUSY; | |
2665 | ||
2666 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES, | |
2667 | sizeof(list), NULL, &list); | |
2668 | orinoco_unlock(priv, &flags); | |
2669 | ||
2670 | if (err) | |
2671 | return err; | |
2672 | ||
2673 | num = le16_to_cpu(list.len); | |
2674 | *numrates = num; | |
2675 | num = min(num, max); | |
2676 | ||
2677 | for (i = 0; i < num; i++) { | |
2678 | rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */ | |
2679 | } | |
2680 | ||
2681 | return 0; | |
2682 | } | |
2683 | ||
620554e4 CH |
2684 | static int orinoco_ioctl_getname(struct net_device *dev, |
2685 | struct iw_request_info *info, | |
2686 | char *name, | |
2687 | char *extra) | |
1da177e4 LT |
2688 | { |
2689 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 2690 | int numrates; |
620554e4 CH |
2691 | int err; |
2692 | ||
2693 | err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0); | |
2694 | ||
2695 | if (!err && (numrates > 2)) | |
2696 | strcpy(name, "IEEE 802.11b"); | |
2697 | else | |
2698 | strcpy(name, "IEEE 802.11-DS"); | |
2699 | ||
2700 | return 0; | |
2701 | } | |
2702 | ||
16739b06 CH |
2703 | static int orinoco_ioctl_setwap(struct net_device *dev, |
2704 | struct iw_request_info *info, | |
2705 | struct sockaddr *ap_addr, | |
2706 | char *extra) | |
2707 | { | |
2708 | struct orinoco_private *priv = netdev_priv(dev); | |
2709 | int err = -EINPROGRESS; /* Call commit handler */ | |
2710 | unsigned long flags; | |
2711 | static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; | |
2712 | static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; | |
2713 | ||
2714 | if (orinoco_lock(priv, &flags) != 0) | |
2715 | return -EBUSY; | |
2716 | ||
2717 | /* Enable automatic roaming - no sanity checks are needed */ | |
2718 | if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 || | |
2719 | memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) { | |
2720 | priv->bssid_fixed = 0; | |
2721 | memset(priv->desired_bssid, 0, ETH_ALEN); | |
2722 | ||
2723 | /* "off" means keep existing connection */ | |
2724 | if (ap_addr->sa_data[0] == 0) { | |
2725 | __orinoco_hw_set_wap(priv); | |
2726 | err = 0; | |
2727 | } | |
2728 | goto out; | |
2729 | } | |
2730 | ||
2731 | if (priv->firmware_type == FIRMWARE_TYPE_AGERE) { | |
2732 | printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't " | |
2733 | "support manual roaming\n", | |
2734 | dev->name); | |
2735 | err = -EOPNOTSUPP; | |
2736 | goto out; | |
2737 | } | |
2738 | ||
2739 | if (priv->iw_mode != IW_MODE_INFRA) { | |
2740 | printk(KERN_WARNING "%s: Manual roaming supported only in " | |
2741 | "managed mode\n", dev->name); | |
2742 | err = -EOPNOTSUPP; | |
2743 | goto out; | |
2744 | } | |
2745 | ||
2746 | /* Intersil firmware hangs without Desired ESSID */ | |
2747 | if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL && | |
2748 | strlen(priv->desired_essid) == 0) { | |
2749 | printk(KERN_WARNING "%s: Desired ESSID must be set for " | |
2750 | "manual roaming\n", dev->name); | |
2751 | err = -EOPNOTSUPP; | |
2752 | goto out; | |
2753 | } | |
2754 | ||
2755 | /* Finally, enable manual roaming */ | |
2756 | priv->bssid_fixed = 1; | |
2757 | memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN); | |
2758 | ||
2759 | out: | |
2760 | orinoco_unlock(priv, &flags); | |
2761 | return err; | |
2762 | } | |
2763 | ||
620554e4 CH |
2764 | static int orinoco_ioctl_getwap(struct net_device *dev, |
2765 | struct iw_request_info *info, | |
2766 | struct sockaddr *ap_addr, | |
2767 | char *extra) | |
2768 | { | |
2769 | struct orinoco_private *priv = netdev_priv(dev); | |
2770 | ||
2771 | hermes_t *hw = &priv->hw; | |
2772 | int err = 0; | |
1da177e4 LT |
2773 | unsigned long flags; |
2774 | ||
620554e4 CH |
2775 | if (orinoco_lock(priv, &flags) != 0) |
2776 | return -EBUSY; | |
1da177e4 | 2777 | |
620554e4 CH |
2778 | ap_addr->sa_family = ARPHRD_ETHER; |
2779 | err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID, | |
2780 | ETH_ALEN, NULL, ap_addr->sa_data); | |
1da177e4 | 2781 | |
620554e4 CH |
2782 | orinoco_unlock(priv, &flags); |
2783 | ||
2784 | return err; | |
2785 | } | |
2786 | ||
2787 | static int orinoco_ioctl_setmode(struct net_device *dev, | |
2788 | struct iw_request_info *info, | |
2789 | u32 *mode, | |
2790 | char *extra) | |
2791 | { | |
2792 | struct orinoco_private *priv = netdev_priv(dev); | |
2793 | int err = -EINPROGRESS; /* Call commit handler */ | |
2794 | unsigned long flags; | |
2795 | ||
2796 | if (priv->iw_mode == *mode) | |
2797 | return 0; | |
1da177e4 LT |
2798 | |
2799 | if (orinoco_lock(priv, &flags) != 0) | |
2800 | return -EBUSY; | |
2801 | ||
620554e4 CH |
2802 | switch (*mode) { |
2803 | case IW_MODE_ADHOC: | |
2804 | if (!priv->has_ibss && !priv->has_port3) | |
2805 | err = -EOPNOTSUPP; | |
2806 | break; | |
2807 | ||
2808 | case IW_MODE_INFRA: | |
2809 | break; | |
2810 | ||
2811 | default: | |
2812 | err = -EOPNOTSUPP; | |
2813 | break; | |
2814 | } | |
2815 | ||
2816 | if (err == -EINPROGRESS) { | |
2817 | priv->iw_mode = *mode; | |
2818 | set_port_type(priv); | |
2819 | } | |
2820 | ||
1da177e4 LT |
2821 | orinoco_unlock(priv, &flags); |
2822 | ||
620554e4 CH |
2823 | return err; |
2824 | } | |
2825 | ||
2826 | static int orinoco_ioctl_getmode(struct net_device *dev, | |
2827 | struct iw_request_info *info, | |
2828 | u32 *mode, | |
2829 | char *extra) | |
2830 | { | |
2831 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 2832 | |
620554e4 CH |
2833 | *mode = priv->iw_mode; |
2834 | return 0; | |
2835 | } | |
1da177e4 | 2836 | |
620554e4 CH |
2837 | static int orinoco_ioctl_getiwrange(struct net_device *dev, |
2838 | struct iw_request_info *info, | |
2839 | struct iw_point *rrq, | |
2840 | char *extra) | |
2841 | { | |
2842 | struct orinoco_private *priv = netdev_priv(dev); | |
2843 | int err = 0; | |
2844 | struct iw_range *range = (struct iw_range *) extra; | |
2845 | int numrates; | |
2846 | int i, k; | |
2847 | ||
2848 | TRACE_ENTER(dev->name); | |
2849 | ||
2850 | rrq->length = sizeof(struct iw_range); | |
2851 | memset(range, 0, sizeof(struct iw_range)); | |
2852 | ||
2853 | range->we_version_compiled = WIRELESS_EXT; | |
2854 | range->we_version_source = 14; | |
1da177e4 LT |
2855 | |
2856 | /* Set available channels/frequencies */ | |
620554e4 | 2857 | range->num_channels = NUM_CHANNELS; |
1da177e4 LT |
2858 | k = 0; |
2859 | for (i = 0; i < NUM_CHANNELS; i++) { | |
2860 | if (priv->channel_mask & (1 << i)) { | |
620554e4 CH |
2861 | range->freq[k].i = i + 1; |
2862 | range->freq[k].m = channel_frequency[i] * 100000; | |
2863 | range->freq[k].e = 1; | |
1da177e4 LT |
2864 | k++; |
2865 | } | |
2866 | ||
2867 | if (k >= IW_MAX_FREQUENCIES) | |
2868 | break; | |
2869 | } | |
620554e4 CH |
2870 | range->num_frequency = k; |
2871 | range->sensitivity = 3; | |
1da177e4 | 2872 | |
620554e4 CH |
2873 | if (priv->has_wep) { |
2874 | range->max_encoding_tokens = ORINOCO_MAX_KEYS; | |
2875 | range->encoding_size[0] = SMALL_KEY_SIZE; | |
2876 | range->num_encoding_sizes = 1; | |
1da177e4 | 2877 | |
620554e4 CH |
2878 | if (priv->has_big_wep) { |
2879 | range->encoding_size[1] = LARGE_KEY_SIZE; | |
2880 | range->num_encoding_sizes = 2; | |
2881 | } | |
2882 | } | |
2883 | ||
2884 | if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){ | |
1da177e4 | 2885 | /* Quality stats meaningless in ad-hoc mode */ |
1da177e4 | 2886 | } else { |
620554e4 CH |
2887 | range->max_qual.qual = 0x8b - 0x2f; |
2888 | range->max_qual.level = 0x2f - 0x95 - 1; | |
2889 | range->max_qual.noise = 0x2f - 0x95 - 1; | |
1da177e4 | 2890 | /* Need to get better values */ |
620554e4 CH |
2891 | range->avg_qual.qual = 0x24; |
2892 | range->avg_qual.level = 0xC2; | |
2893 | range->avg_qual.noise = 0x9E; | |
1da177e4 LT |
2894 | } |
2895 | ||
2896 | err = orinoco_hw_get_bitratelist(priv, &numrates, | |
620554e4 | 2897 | range->bitrate, IW_MAX_BITRATES); |
1da177e4 LT |
2898 | if (err) |
2899 | return err; | |
620554e4 CH |
2900 | range->num_bitrates = numrates; |
2901 | ||
1da177e4 LT |
2902 | /* Set an indication of the max TCP throughput in bit/s that we can |
2903 | * expect using this interface. May be use for QoS stuff... | |
2904 | * Jean II */ | |
620554e4 CH |
2905 | if (numrates > 2) |
2906 | range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */ | |
1da177e4 | 2907 | else |
620554e4 CH |
2908 | range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */ |
2909 | ||
2910 | range->min_rts = 0; | |
2911 | range->max_rts = 2347; | |
2912 | range->min_frag = 256; | |
2913 | range->max_frag = 2346; | |
2914 | ||
2915 | range->min_pmp = 0; | |
2916 | range->max_pmp = 65535000; | |
2917 | range->min_pmt = 0; | |
2918 | range->max_pmt = 65535 * 1000; /* ??? */ | |
2919 | range->pmp_flags = IW_POWER_PERIOD; | |
2920 | range->pmt_flags = IW_POWER_TIMEOUT; | |
2921 | range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R; | |
2922 | ||
2923 | range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME; | |
2924 | range->retry_flags = IW_RETRY_LIMIT; | |
2925 | range->r_time_flags = IW_RETRY_LIFETIME; | |
2926 | range->min_retry = 0; | |
2927 | range->max_retry = 65535; /* ??? */ | |
2928 | range->min_r_time = 0; | |
2929 | range->max_r_time = 65535 * 1000; /* ??? */ | |
1da177e4 LT |
2930 | |
2931 | TRACE_EXIT(dev->name); | |
2932 | ||
2933 | return 0; | |
2934 | } | |
2935 | ||
620554e4 CH |
2936 | static int orinoco_ioctl_setiwencode(struct net_device *dev, |
2937 | struct iw_request_info *info, | |
2938 | struct iw_point *erq, | |
2939 | char *keybuf) | |
1da177e4 LT |
2940 | { |
2941 | struct orinoco_private *priv = netdev_priv(dev); | |
2942 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; | |
2943 | int setindex = priv->tx_key; | |
2944 | int enable = priv->wep_on; | |
2945 | int restricted = priv->wep_restrict; | |
2946 | u16 xlen = 0; | |
620554e4 | 2947 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
2948 | unsigned long flags; |
2949 | ||
2950 | if (! priv->has_wep) | |
2951 | return -EOPNOTSUPP; | |
2952 | ||
2953 | if (erq->pointer) { | |
2954 | /* We actually have a key to set - check its length */ | |
2955 | if (erq->length > LARGE_KEY_SIZE) | |
2956 | return -E2BIG; | |
2957 | ||
2958 | if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep ) | |
2959 | return -E2BIG; | |
1da177e4 LT |
2960 | } |
2961 | ||
2962 | if (orinoco_lock(priv, &flags) != 0) | |
2963 | return -EBUSY; | |
2964 | ||
2965 | if (erq->pointer) { | |
2966 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) | |
2967 | index = priv->tx_key; | |
2968 | ||
2969 | /* Adjust key length to a supported value */ | |
2970 | if (erq->length > SMALL_KEY_SIZE) { | |
2971 | xlen = LARGE_KEY_SIZE; | |
2972 | } else if (erq->length > 0) { | |
2973 | xlen = SMALL_KEY_SIZE; | |
2974 | } else | |
2975 | xlen = 0; | |
2976 | ||
2977 | /* Switch on WEP if off */ | |
2978 | if ((!enable) && (xlen > 0)) { | |
2979 | setindex = index; | |
2980 | enable = 1; | |
2981 | } | |
2982 | } else { | |
2983 | /* Important note : if the user do "iwconfig eth0 enc off", | |
2984 | * we will arrive there with an index of -1. This is valid | |
2985 | * but need to be taken care off... Jean II */ | |
2986 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) { | |
2987 | if((index != -1) || (erq->flags == 0)) { | |
2988 | err = -EINVAL; | |
2989 | goto out; | |
2990 | } | |
2991 | } else { | |
2992 | /* Set the index : Check that the key is valid */ | |
2993 | if(priv->keys[index].len == 0) { | |
2994 | err = -EINVAL; | |
2995 | goto out; | |
2996 | } | |
2997 | setindex = index; | |
2998 | } | |
2999 | } | |
3000 | ||
3001 | if (erq->flags & IW_ENCODE_DISABLED) | |
3002 | enable = 0; | |
3003 | if (erq->flags & IW_ENCODE_OPEN) | |
3004 | restricted = 0; | |
3005 | if (erq->flags & IW_ENCODE_RESTRICTED) | |
3006 | restricted = 1; | |
3007 | ||
3008 | if (erq->pointer) { | |
3009 | priv->keys[index].len = cpu_to_le16(xlen); | |
3010 | memset(priv->keys[index].data, 0, | |
3011 | sizeof(priv->keys[index].data)); | |
3012 | memcpy(priv->keys[index].data, keybuf, erq->length); | |
3013 | } | |
3014 | priv->tx_key = setindex; | |
3015 | ||
3016 | /* Try fast key change if connected and only keys are changed */ | |
3017 | if (priv->wep_on && enable && (priv->wep_restrict == restricted) && | |
3018 | netif_carrier_ok(dev)) { | |
3019 | err = __orinoco_hw_setup_wepkeys(priv); | |
3020 | /* No need to commit if successful */ | |
3021 | goto out; | |
3022 | } | |
3023 | ||
3024 | priv->wep_on = enable; | |
3025 | priv->wep_restrict = restricted; | |
3026 | ||
3027 | out: | |
3028 | orinoco_unlock(priv, &flags); | |
3029 | ||
3030 | return err; | |
3031 | } | |
3032 | ||
620554e4 CH |
3033 | static int orinoco_ioctl_getiwencode(struct net_device *dev, |
3034 | struct iw_request_info *info, | |
3035 | struct iw_point *erq, | |
3036 | char *keybuf) | |
1da177e4 LT |
3037 | { |
3038 | struct orinoco_private *priv = netdev_priv(dev); | |
3039 | int index = (erq->flags & IW_ENCODE_INDEX) - 1; | |
3040 | u16 xlen = 0; | |
1da177e4 LT |
3041 | unsigned long flags; |
3042 | ||
3043 | if (! priv->has_wep) | |
3044 | return -EOPNOTSUPP; | |
3045 | ||
3046 | if (orinoco_lock(priv, &flags) != 0) | |
3047 | return -EBUSY; | |
3048 | ||
3049 | if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) | |
3050 | index = priv->tx_key; | |
3051 | ||
3052 | erq->flags = 0; | |
3053 | if (! priv->wep_on) | |
3054 | erq->flags |= IW_ENCODE_DISABLED; | |
3055 | erq->flags |= index + 1; | |
3056 | ||
3057 | if (priv->wep_restrict) | |
3058 | erq->flags |= IW_ENCODE_RESTRICTED; | |
3059 | else | |
3060 | erq->flags |= IW_ENCODE_OPEN; | |
3061 | ||
3062 | xlen = le16_to_cpu(priv->keys[index].len); | |
3063 | ||
3064 | erq->length = xlen; | |
3065 | ||
3066 | memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE); | |
3067 | ||
3068 | orinoco_unlock(priv, &flags); | |
1da177e4 LT |
3069 | return 0; |
3070 | } | |
3071 | ||
620554e4 CH |
3072 | static int orinoco_ioctl_setessid(struct net_device *dev, |
3073 | struct iw_request_info *info, | |
3074 | struct iw_point *erq, | |
3075 | char *essidbuf) | |
1da177e4 LT |
3076 | { |
3077 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
3078 | unsigned long flags; |
3079 | ||
3080 | /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it | |
3081 | * anyway... - Jean II */ | |
3082 | ||
620554e4 CH |
3083 | /* Hum... Should not use Wireless Extension constant (may change), |
3084 | * should use our own... - Jean II */ | |
3085 | if (erq->length > IW_ESSID_MAX_SIZE) | |
3086 | return -E2BIG; | |
1da177e4 LT |
3087 | |
3088 | if (orinoco_lock(priv, &flags) != 0) | |
3089 | return -EBUSY; | |
3090 | ||
620554e4 CH |
3091 | /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */ |
3092 | memset(priv->desired_essid, 0, sizeof(priv->desired_essid)); | |
3093 | ||
3094 | /* If not ANY, get the new ESSID */ | |
3095 | if (erq->flags) { | |
3096 | memcpy(priv->desired_essid, essidbuf, erq->length); | |
3097 | } | |
1da177e4 LT |
3098 | |
3099 | orinoco_unlock(priv, &flags); | |
3100 | ||
620554e4 | 3101 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3102 | } |
3103 | ||
620554e4 CH |
3104 | static int orinoco_ioctl_getessid(struct net_device *dev, |
3105 | struct iw_request_info *info, | |
3106 | struct iw_point *erq, | |
3107 | char *essidbuf) | |
1da177e4 LT |
3108 | { |
3109 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
3110 | int active; |
3111 | int err = 0; | |
3112 | unsigned long flags; | |
3113 | ||
3114 | TRACE_ENTER(dev->name); | |
3115 | ||
3116 | if (netif_running(dev)) { | |
3117 | err = orinoco_hw_get_essid(priv, &active, essidbuf); | |
3118 | if (err) | |
3119 | return err; | |
3120 | } else { | |
3121 | if (orinoco_lock(priv, &flags) != 0) | |
3122 | return -EBUSY; | |
620554e4 | 3123 | memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1); |
1da177e4 LT |
3124 | orinoco_unlock(priv, &flags); |
3125 | } | |
3126 | ||
3127 | erq->flags = 1; | |
3128 | erq->length = strlen(essidbuf) + 1; | |
1da177e4 LT |
3129 | |
3130 | TRACE_EXIT(dev->name); | |
3131 | ||
3132 | return 0; | |
3133 | } | |
3134 | ||
620554e4 CH |
3135 | static int orinoco_ioctl_setnick(struct net_device *dev, |
3136 | struct iw_request_info *info, | |
3137 | struct iw_point *nrq, | |
3138 | char *nickbuf) | |
1da177e4 LT |
3139 | { |
3140 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
3141 | unsigned long flags; |
3142 | ||
3143 | if (nrq->length > IW_ESSID_MAX_SIZE) | |
3144 | return -E2BIG; | |
3145 | ||
1da177e4 LT |
3146 | if (orinoco_lock(priv, &flags) != 0) |
3147 | return -EBUSY; | |
3148 | ||
620554e4 CH |
3149 | memset(priv->nick, 0, sizeof(priv->nick)); |
3150 | memcpy(priv->nick, nickbuf, nrq->length); | |
1da177e4 LT |
3151 | |
3152 | orinoco_unlock(priv, &flags); | |
3153 | ||
620554e4 | 3154 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3155 | } |
3156 | ||
620554e4 CH |
3157 | static int orinoco_ioctl_getnick(struct net_device *dev, |
3158 | struct iw_request_info *info, | |
3159 | struct iw_point *nrq, | |
3160 | char *nickbuf) | |
1da177e4 LT |
3161 | { |
3162 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
3163 | unsigned long flags; |
3164 | ||
3165 | if (orinoco_lock(priv, &flags) != 0) | |
3166 | return -EBUSY; | |
3167 | ||
3168 | memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1); | |
3169 | orinoco_unlock(priv, &flags); | |
3170 | ||
3171 | nrq->length = strlen(nickbuf)+1; | |
3172 | ||
1da177e4 LT |
3173 | return 0; |
3174 | } | |
3175 | ||
620554e4 CH |
3176 | static int orinoco_ioctl_setfreq(struct net_device *dev, |
3177 | struct iw_request_info *info, | |
3178 | struct iw_freq *frq, | |
3179 | char *extra) | |
1da177e4 LT |
3180 | { |
3181 | struct orinoco_private *priv = netdev_priv(dev); | |
3182 | int chan = -1; | |
3183 | unsigned long flags; | |
620554e4 | 3184 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3185 | |
3186 | /* We can only use this in Ad-Hoc demo mode to set the operating | |
3187 | * frequency, or in IBSS mode to set the frequency where the IBSS | |
3188 | * will be created - Jean II */ | |
3189 | if (priv->iw_mode != IW_MODE_ADHOC) | |
3190 | return -EOPNOTSUPP; | |
3191 | ||
3192 | if ( (frq->e == 0) && (frq->m <= 1000) ) { | |
3193 | /* Setting by channel number */ | |
3194 | chan = frq->m; | |
3195 | } else { | |
3196 | /* Setting by frequency - search the table */ | |
3197 | int mult = 1; | |
3198 | int i; | |
3199 | ||
3200 | for (i = 0; i < (6 - frq->e); i++) | |
3201 | mult *= 10; | |
3202 | ||
3203 | for (i = 0; i < NUM_CHANNELS; i++) | |
3204 | if (frq->m == (channel_frequency[i] * mult)) | |
3205 | chan = i+1; | |
3206 | } | |
3207 | ||
3208 | if ( (chan < 1) || (chan > NUM_CHANNELS) || | |
3209 | ! (priv->channel_mask & (1 << (chan-1)) ) ) | |
3210 | return -EINVAL; | |
3211 | ||
3212 | if (orinoco_lock(priv, &flags) != 0) | |
3213 | return -EBUSY; | |
3214 | priv->channel = chan; | |
3215 | orinoco_unlock(priv, &flags); | |
3216 | ||
620554e4 CH |
3217 | return err; |
3218 | } | |
3219 | ||
3220 | static int orinoco_ioctl_getfreq(struct net_device *dev, | |
3221 | struct iw_request_info *info, | |
3222 | struct iw_freq *frq, | |
3223 | char *extra) | |
3224 | { | |
3225 | struct orinoco_private *priv = netdev_priv(dev); | |
3226 | int tmp; | |
3227 | ||
3228 | /* Locking done in there */ | |
3229 | tmp = orinoco_hw_get_freq(priv); | |
3230 | if (tmp < 0) { | |
3231 | return tmp; | |
3232 | } | |
3233 | ||
3234 | frq->m = tmp; | |
3235 | frq->e = 1; | |
3236 | ||
1da177e4 LT |
3237 | return 0; |
3238 | } | |
3239 | ||
620554e4 CH |
3240 | static int orinoco_ioctl_getsens(struct net_device *dev, |
3241 | struct iw_request_info *info, | |
3242 | struct iw_param *srq, | |
3243 | char *extra) | |
1da177e4 LT |
3244 | { |
3245 | struct orinoco_private *priv = netdev_priv(dev); | |
3246 | hermes_t *hw = &priv->hw; | |
3247 | u16 val; | |
3248 | int err; | |
3249 | unsigned long flags; | |
3250 | ||
3251 | if (!priv->has_sensitivity) | |
3252 | return -EOPNOTSUPP; | |
3253 | ||
3254 | if (orinoco_lock(priv, &flags) != 0) | |
3255 | return -EBUSY; | |
3256 | err = hermes_read_wordrec(hw, USER_BAP, | |
3257 | HERMES_RID_CNFSYSTEMSCALE, &val); | |
3258 | orinoco_unlock(priv, &flags); | |
3259 | ||
3260 | if (err) | |
3261 | return err; | |
3262 | ||
3263 | srq->value = val; | |
3264 | srq->fixed = 0; /* auto */ | |
3265 | ||
3266 | return 0; | |
3267 | } | |
3268 | ||
620554e4 CH |
3269 | static int orinoco_ioctl_setsens(struct net_device *dev, |
3270 | struct iw_request_info *info, | |
3271 | struct iw_param *srq, | |
3272 | char *extra) | |
1da177e4 LT |
3273 | { |
3274 | struct orinoco_private *priv = netdev_priv(dev); | |
3275 | int val = srq->value; | |
3276 | unsigned long flags; | |
3277 | ||
3278 | if (!priv->has_sensitivity) | |
3279 | return -EOPNOTSUPP; | |
3280 | ||
3281 | if ((val < 1) || (val > 3)) | |
3282 | return -EINVAL; | |
3283 | ||
3284 | if (orinoco_lock(priv, &flags) != 0) | |
3285 | return -EBUSY; | |
3286 | priv->ap_density = val; | |
3287 | orinoco_unlock(priv, &flags); | |
3288 | ||
620554e4 | 3289 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3290 | } |
3291 | ||
620554e4 CH |
3292 | static int orinoco_ioctl_setrts(struct net_device *dev, |
3293 | struct iw_request_info *info, | |
3294 | struct iw_param *rrq, | |
3295 | char *extra) | |
1da177e4 LT |
3296 | { |
3297 | struct orinoco_private *priv = netdev_priv(dev); | |
3298 | int val = rrq->value; | |
3299 | unsigned long flags; | |
3300 | ||
3301 | if (rrq->disabled) | |
3302 | val = 2347; | |
3303 | ||
3304 | if ( (val < 0) || (val > 2347) ) | |
3305 | return -EINVAL; | |
3306 | ||
3307 | if (orinoco_lock(priv, &flags) != 0) | |
3308 | return -EBUSY; | |
3309 | ||
3310 | priv->rts_thresh = val; | |
3311 | orinoco_unlock(priv, &flags); | |
3312 | ||
620554e4 CH |
3313 | return -EINPROGRESS; /* Call commit handler */ |
3314 | } | |
3315 | ||
3316 | static int orinoco_ioctl_getrts(struct net_device *dev, | |
3317 | struct iw_request_info *info, | |
3318 | struct iw_param *rrq, | |
3319 | char *extra) | |
3320 | { | |
3321 | struct orinoco_private *priv = netdev_priv(dev); | |
3322 | ||
3323 | rrq->value = priv->rts_thresh; | |
3324 | rrq->disabled = (rrq->value == 2347); | |
3325 | rrq->fixed = 1; | |
3326 | ||
1da177e4 LT |
3327 | return 0; |
3328 | } | |
3329 | ||
620554e4 CH |
3330 | static int orinoco_ioctl_setfrag(struct net_device *dev, |
3331 | struct iw_request_info *info, | |
3332 | struct iw_param *frq, | |
3333 | char *extra) | |
1da177e4 LT |
3334 | { |
3335 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3336 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3337 | unsigned long flags; |
3338 | ||
3339 | if (orinoco_lock(priv, &flags) != 0) | |
3340 | return -EBUSY; | |
3341 | ||
3342 | if (priv->has_mwo) { | |
3343 | if (frq->disabled) | |
3344 | priv->mwo_robust = 0; | |
3345 | else { | |
3346 | if (frq->fixed) | |
3347 | printk(KERN_WARNING "%s: Fixed fragmentation is " | |
3348 | "not supported on this firmware. " | |
3349 | "Using MWO robust instead.\n", dev->name); | |
3350 | priv->mwo_robust = 1; | |
3351 | } | |
3352 | } else { | |
3353 | if (frq->disabled) | |
3354 | priv->frag_thresh = 2346; | |
3355 | else { | |
3356 | if ( (frq->value < 256) || (frq->value > 2346) ) | |
3357 | err = -EINVAL; | |
3358 | else | |
3359 | priv->frag_thresh = frq->value & ~0x1; /* must be even */ | |
3360 | } | |
3361 | } | |
3362 | ||
3363 | orinoco_unlock(priv, &flags); | |
3364 | ||
3365 | return err; | |
3366 | } | |
3367 | ||
620554e4 CH |
3368 | static int orinoco_ioctl_getfrag(struct net_device *dev, |
3369 | struct iw_request_info *info, | |
3370 | struct iw_param *frq, | |
3371 | char *extra) | |
1da177e4 LT |
3372 | { |
3373 | struct orinoco_private *priv = netdev_priv(dev); | |
3374 | hermes_t *hw = &priv->hw; | |
620554e4 | 3375 | int err; |
1da177e4 LT |
3376 | u16 val; |
3377 | unsigned long flags; | |
3378 | ||
3379 | if (orinoco_lock(priv, &flags) != 0) | |
3380 | return -EBUSY; | |
3381 | ||
3382 | if (priv->has_mwo) { | |
3383 | err = hermes_read_wordrec(hw, USER_BAP, | |
3384 | HERMES_RID_CNFMWOROBUST_AGERE, | |
3385 | &val); | |
3386 | if (err) | |
3387 | val = 0; | |
3388 | ||
3389 | frq->value = val ? 2347 : 0; | |
3390 | frq->disabled = ! val; | |
3391 | frq->fixed = 0; | |
3392 | } else { | |
3393 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, | |
3394 | &val); | |
3395 | if (err) | |
3396 | val = 0; | |
3397 | ||
3398 | frq->value = val; | |
3399 | frq->disabled = (val >= 2346); | |
3400 | frq->fixed = 1; | |
3401 | } | |
3402 | ||
3403 | orinoco_unlock(priv, &flags); | |
3404 | ||
3405 | return err; | |
3406 | } | |
3407 | ||
620554e4 CH |
3408 | static int orinoco_ioctl_setrate(struct net_device *dev, |
3409 | struct iw_request_info *info, | |
3410 | struct iw_param *rrq, | |
3411 | char *extra) | |
1da177e4 LT |
3412 | { |
3413 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 LT |
3414 | int ratemode = -1; |
3415 | int bitrate; /* 100s of kilobits */ | |
3416 | int i; | |
3417 | unsigned long flags; | |
3418 | ||
3419 | /* As the user space doesn't know our highest rate, it uses -1 | |
3420 | * to ask us to set the highest rate. Test it using "iwconfig | |
3421 | * ethX rate auto" - Jean II */ | |
3422 | if (rrq->value == -1) | |
3423 | bitrate = 110; | |
3424 | else { | |
3425 | if (rrq->value % 100000) | |
3426 | return -EINVAL; | |
3427 | bitrate = rrq->value / 100000; | |
3428 | } | |
3429 | ||
3430 | if ( (bitrate != 10) && (bitrate != 20) && | |
3431 | (bitrate != 55) && (bitrate != 110) ) | |
3432 | return -EINVAL; | |
3433 | ||
3434 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) | |
3435 | if ( (bitrate_table[i].bitrate == bitrate) && | |
3436 | (bitrate_table[i].automatic == ! rrq->fixed) ) { | |
3437 | ratemode = i; | |
3438 | break; | |
3439 | } | |
3440 | ||
3441 | if (ratemode == -1) | |
3442 | return -EINVAL; | |
3443 | ||
3444 | if (orinoco_lock(priv, &flags) != 0) | |
3445 | return -EBUSY; | |
3446 | priv->bitratemode = ratemode; | |
3447 | orinoco_unlock(priv, &flags); | |
3448 | ||
620554e4 | 3449 | return -EINPROGRESS; |
1da177e4 LT |
3450 | } |
3451 | ||
620554e4 CH |
3452 | static int orinoco_ioctl_getrate(struct net_device *dev, |
3453 | struct iw_request_info *info, | |
3454 | struct iw_param *rrq, | |
3455 | char *extra) | |
1da177e4 LT |
3456 | { |
3457 | struct orinoco_private *priv = netdev_priv(dev); | |
3458 | hermes_t *hw = &priv->hw; | |
3459 | int err = 0; | |
3460 | int ratemode; | |
3461 | int i; | |
3462 | u16 val; | |
3463 | unsigned long flags; | |
3464 | ||
3465 | if (orinoco_lock(priv, &flags) != 0) | |
3466 | return -EBUSY; | |
3467 | ||
3468 | ratemode = priv->bitratemode; | |
3469 | ||
3470 | BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE)); | |
3471 | ||
3472 | rrq->value = bitrate_table[ratemode].bitrate * 100000; | |
3473 | rrq->fixed = ! bitrate_table[ratemode].automatic; | |
3474 | rrq->disabled = 0; | |
3475 | ||
3476 | /* If the interface is running we try to find more about the | |
3477 | current mode */ | |
3478 | if (netif_running(dev)) { | |
3479 | err = hermes_read_wordrec(hw, USER_BAP, | |
3480 | HERMES_RID_CURRENTTXRATE, &val); | |
3481 | if (err) | |
3482 | goto out; | |
3483 | ||
3484 | switch (priv->firmware_type) { | |
3485 | case FIRMWARE_TYPE_AGERE: /* Lucent style rate */ | |
3486 | /* Note : in Lucent firmware, the return value of | |
3487 | * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s, | |
3488 | * and therefore is totally different from the | |
3489 | * encoding of HERMES_RID_CNFTXRATECONTROL. | |
3490 | * Don't forget that 6Mb/s is really 5.5Mb/s */ | |
3491 | if (val == 6) | |
3492 | rrq->value = 5500000; | |
3493 | else | |
3494 | rrq->value = val * 1000000; | |
3495 | break; | |
3496 | case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */ | |
3497 | case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */ | |
3498 | for (i = 0; i < BITRATE_TABLE_SIZE; i++) | |
3499 | if (bitrate_table[i].intersil_txratectrl == val) { | |
3500 | ratemode = i; | |
3501 | break; | |
3502 | } | |
3503 | if (i >= BITRATE_TABLE_SIZE) | |
3504 | printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n", | |
3505 | dev->name, val); | |
3506 | ||
3507 | rrq->value = bitrate_table[ratemode].bitrate * 100000; | |
3508 | break; | |
3509 | default: | |
3510 | BUG(); | |
3511 | } | |
3512 | } | |
3513 | ||
3514 | out: | |
3515 | orinoco_unlock(priv, &flags); | |
3516 | ||
3517 | return err; | |
3518 | } | |
3519 | ||
620554e4 CH |
3520 | static int orinoco_ioctl_setpower(struct net_device *dev, |
3521 | struct iw_request_info *info, | |
3522 | struct iw_param *prq, | |
3523 | char *extra) | |
1da177e4 LT |
3524 | { |
3525 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3526 | int err = -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3527 | unsigned long flags; |
3528 | ||
3529 | if (orinoco_lock(priv, &flags) != 0) | |
3530 | return -EBUSY; | |
3531 | ||
3532 | if (prq->disabled) { | |
3533 | priv->pm_on = 0; | |
3534 | } else { | |
3535 | switch (prq->flags & IW_POWER_MODE) { | |
3536 | case IW_POWER_UNICAST_R: | |
3537 | priv->pm_mcast = 0; | |
3538 | priv->pm_on = 1; | |
3539 | break; | |
3540 | case IW_POWER_ALL_R: | |
3541 | priv->pm_mcast = 1; | |
3542 | priv->pm_on = 1; | |
3543 | break; | |
3544 | case IW_POWER_ON: | |
3545 | /* No flags : but we may have a value - Jean II */ | |
3546 | break; | |
3547 | default: | |
3548 | err = -EINVAL; | |
3549 | } | |
3550 | if (err) | |
3551 | goto out; | |
3552 | ||
3553 | if (prq->flags & IW_POWER_TIMEOUT) { | |
3554 | priv->pm_on = 1; | |
3555 | priv->pm_timeout = prq->value / 1000; | |
3556 | } | |
3557 | if (prq->flags & IW_POWER_PERIOD) { | |
3558 | priv->pm_on = 1; | |
3559 | priv->pm_period = prq->value / 1000; | |
3560 | } | |
3561 | /* It's valid to not have a value if we are just toggling | |
3562 | * the flags... Jean II */ | |
3563 | if(!priv->pm_on) { | |
3564 | err = -EINVAL; | |
3565 | goto out; | |
3566 | } | |
3567 | } | |
3568 | ||
3569 | out: | |
3570 | orinoco_unlock(priv, &flags); | |
3571 | ||
3572 | return err; | |
3573 | } | |
3574 | ||
620554e4 CH |
3575 | static int orinoco_ioctl_getpower(struct net_device *dev, |
3576 | struct iw_request_info *info, | |
3577 | struct iw_param *prq, | |
3578 | char *extra) | |
1da177e4 LT |
3579 | { |
3580 | struct orinoco_private *priv = netdev_priv(dev); | |
3581 | hermes_t *hw = &priv->hw; | |
3582 | int err = 0; | |
3583 | u16 enable, period, timeout, mcast; | |
3584 | unsigned long flags; | |
3585 | ||
3586 | if (orinoco_lock(priv, &flags) != 0) | |
3587 | return -EBUSY; | |
3588 | ||
3589 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable); | |
3590 | if (err) | |
3591 | goto out; | |
3592 | ||
3593 | err = hermes_read_wordrec(hw, USER_BAP, | |
3594 | HERMES_RID_CNFMAXSLEEPDURATION, &period); | |
3595 | if (err) | |
3596 | goto out; | |
3597 | ||
3598 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout); | |
3599 | if (err) | |
3600 | goto out; | |
3601 | ||
3602 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast); | |
3603 | if (err) | |
3604 | goto out; | |
3605 | ||
3606 | prq->disabled = !enable; | |
3607 | /* Note : by default, display the period */ | |
3608 | if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
3609 | prq->flags = IW_POWER_TIMEOUT; | |
3610 | prq->value = timeout * 1000; | |
3611 | } else { | |
3612 | prq->flags = IW_POWER_PERIOD; | |
3613 | prq->value = period * 1000; | |
3614 | } | |
3615 | if (mcast) | |
3616 | prq->flags |= IW_POWER_ALL_R; | |
3617 | else | |
3618 | prq->flags |= IW_POWER_UNICAST_R; | |
3619 | ||
3620 | out: | |
3621 | orinoco_unlock(priv, &flags); | |
3622 | ||
3623 | return err; | |
3624 | } | |
3625 | ||
620554e4 CH |
3626 | static int orinoco_ioctl_getretry(struct net_device *dev, |
3627 | struct iw_request_info *info, | |
3628 | struct iw_param *rrq, | |
3629 | char *extra) | |
1da177e4 LT |
3630 | { |
3631 | struct orinoco_private *priv = netdev_priv(dev); | |
3632 | hermes_t *hw = &priv->hw; | |
3633 | int err = 0; | |
3634 | u16 short_limit, long_limit, lifetime; | |
3635 | unsigned long flags; | |
3636 | ||
3637 | if (orinoco_lock(priv, &flags) != 0) | |
3638 | return -EBUSY; | |
3639 | ||
3640 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, | |
3641 | &short_limit); | |
3642 | if (err) | |
3643 | goto out; | |
3644 | ||
3645 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, | |
3646 | &long_limit); | |
3647 | if (err) | |
3648 | goto out; | |
3649 | ||
3650 | err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, | |
3651 | &lifetime); | |
3652 | if (err) | |
3653 | goto out; | |
3654 | ||
3655 | rrq->disabled = 0; /* Can't be disabled */ | |
3656 | ||
3657 | /* Note : by default, display the retry number */ | |
3658 | if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) { | |
3659 | rrq->flags = IW_RETRY_LIFETIME; | |
3660 | rrq->value = lifetime * 1000; /* ??? */ | |
3661 | } else { | |
3662 | /* By default, display the min number */ | |
3663 | if ((rrq->flags & IW_RETRY_MAX)) { | |
3664 | rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
3665 | rrq->value = long_limit; | |
3666 | } else { | |
3667 | rrq->flags = IW_RETRY_LIMIT; | |
3668 | rrq->value = short_limit; | |
3669 | if(short_limit != long_limit) | |
3670 | rrq->flags |= IW_RETRY_MIN; | |
3671 | } | |
3672 | } | |
3673 | ||
3674 | out: | |
3675 | orinoco_unlock(priv, &flags); | |
3676 | ||
3677 | return err; | |
3678 | } | |
3679 | ||
620554e4 CH |
3680 | static int orinoco_ioctl_reset(struct net_device *dev, |
3681 | struct iw_request_info *info, | |
3682 | void *wrqu, | |
3683 | char *extra) | |
3684 | { | |
3685 | struct orinoco_private *priv = netdev_priv(dev); | |
3686 | ||
3687 | if (! capable(CAP_NET_ADMIN)) | |
3688 | return -EPERM; | |
3689 | ||
3690 | if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) { | |
3691 | printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name); | |
3692 | ||
3693 | /* Firmware reset */ | |
3694 | orinoco_reset(dev); | |
3695 | } else { | |
3696 | printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name); | |
3697 | ||
3698 | schedule_work(&priv->reset_work); | |
3699 | } | |
3700 | ||
3701 | return 0; | |
3702 | } | |
3703 | ||
3704 | static int orinoco_ioctl_setibssport(struct net_device *dev, | |
3705 | struct iw_request_info *info, | |
3706 | void *wrqu, | |
3707 | char *extra) | |
3708 | ||
1da177e4 LT |
3709 | { |
3710 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3711 | int val = *( (int *) extra ); |
1da177e4 LT |
3712 | unsigned long flags; |
3713 | ||
3714 | if (orinoco_lock(priv, &flags) != 0) | |
3715 | return -EBUSY; | |
3716 | ||
3717 | priv->ibss_port = val ; | |
3718 | ||
3719 | /* Actually update the mode we are using */ | |
3720 | set_port_type(priv); | |
3721 | ||
3722 | orinoco_unlock(priv, &flags); | |
620554e4 | 3723 | return -EINPROGRESS; /* Call commit handler */ |
1da177e4 LT |
3724 | } |
3725 | ||
620554e4 CH |
3726 | static int orinoco_ioctl_getibssport(struct net_device *dev, |
3727 | struct iw_request_info *info, | |
3728 | void *wrqu, | |
3729 | char *extra) | |
1da177e4 LT |
3730 | { |
3731 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3732 | int *val = (int *) extra; |
1da177e4 LT |
3733 | |
3734 | *val = priv->ibss_port; | |
1da177e4 LT |
3735 | return 0; |
3736 | } | |
3737 | ||
620554e4 CH |
3738 | static int orinoco_ioctl_setport3(struct net_device *dev, |
3739 | struct iw_request_info *info, | |
3740 | void *wrqu, | |
3741 | char *extra) | |
1da177e4 LT |
3742 | { |
3743 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3744 | int val = *( (int *) extra ); |
1da177e4 LT |
3745 | int err = 0; |
3746 | unsigned long flags; | |
3747 | ||
3748 | if (orinoco_lock(priv, &flags) != 0) | |
3749 | return -EBUSY; | |
3750 | ||
3751 | switch (val) { | |
3752 | case 0: /* Try to do IEEE ad-hoc mode */ | |
3753 | if (! priv->has_ibss) { | |
3754 | err = -EINVAL; | |
3755 | break; | |
3756 | } | |
3757 | priv->prefer_port3 = 0; | |
3758 | ||
3759 | break; | |
3760 | ||
3761 | case 1: /* Try to do Lucent proprietary ad-hoc mode */ | |
3762 | if (! priv->has_port3) { | |
3763 | err = -EINVAL; | |
3764 | break; | |
3765 | } | |
3766 | priv->prefer_port3 = 1; | |
3767 | break; | |
3768 | ||
3769 | default: | |
3770 | err = -EINVAL; | |
3771 | } | |
3772 | ||
620554e4 | 3773 | if (! err) { |
1da177e4 LT |
3774 | /* Actually update the mode we are using */ |
3775 | set_port_type(priv); | |
620554e4 CH |
3776 | err = -EINPROGRESS; |
3777 | } | |
1da177e4 LT |
3778 | |
3779 | orinoco_unlock(priv, &flags); | |
3780 | ||
3781 | return err; | |
3782 | } | |
3783 | ||
620554e4 CH |
3784 | static int orinoco_ioctl_getport3(struct net_device *dev, |
3785 | struct iw_request_info *info, | |
3786 | void *wrqu, | |
3787 | char *extra) | |
3788 | { | |
3789 | struct orinoco_private *priv = netdev_priv(dev); | |
3790 | int *val = (int *) extra; | |
3791 | ||
3792 | *val = priv->prefer_port3; | |
3793 | return 0; | |
3794 | } | |
3795 | ||
3796 | static int orinoco_ioctl_setpreamble(struct net_device *dev, | |
3797 | struct iw_request_info *info, | |
3798 | void *wrqu, | |
3799 | char *extra) | |
1da177e4 LT |
3800 | { |
3801 | struct orinoco_private *priv = netdev_priv(dev); | |
1da177e4 | 3802 | unsigned long flags; |
620554e4 CH |
3803 | int val; |
3804 | ||
3805 | if (! priv->has_preamble) | |
3806 | return -EOPNOTSUPP; | |
3807 | ||
3808 | /* 802.11b has recently defined some short preamble. | |
3809 | * Basically, the Phy header has been reduced in size. | |
3810 | * This increase performance, especially at high rates | |
3811 | * (the preamble is transmitted at 1Mb/s), unfortunately | |
3812 | * this give compatibility troubles... - Jean II */ | |
3813 | val = *( (int *) extra ); | |
1da177e4 LT |
3814 | |
3815 | if (orinoco_lock(priv, &flags) != 0) | |
3816 | return -EBUSY; | |
3817 | ||
620554e4 CH |
3818 | if (val) |
3819 | priv->preamble = 1; | |
3820 | else | |
3821 | priv->preamble = 0; | |
3822 | ||
1da177e4 | 3823 | orinoco_unlock(priv, &flags); |
620554e4 CH |
3824 | |
3825 | return -EINPROGRESS; /* Call commit handler */ | |
3826 | } | |
3827 | ||
3828 | static int orinoco_ioctl_getpreamble(struct net_device *dev, | |
3829 | struct iw_request_info *info, | |
3830 | void *wrqu, | |
3831 | char *extra) | |
3832 | { | |
3833 | struct orinoco_private *priv = netdev_priv(dev); | |
3834 | int *val = (int *) extra; | |
3835 | ||
3836 | if (! priv->has_preamble) | |
3837 | return -EOPNOTSUPP; | |
3838 | ||
3839 | *val = priv->preamble; | |
1da177e4 LT |
3840 | return 0; |
3841 | } | |
3842 | ||
620554e4 CH |
3843 | /* ioctl interface to hermes_read_ltv() |
3844 | * To use with iwpriv, pass the RID as the token argument, e.g. | |
3845 | * iwpriv get_rid [0xfc00] | |
3846 | * At least Wireless Tools 25 is required to use iwpriv. | |
3847 | * For Wireless Tools 25 and 26 append "dummy" are the end. */ | |
3848 | static int orinoco_ioctl_getrid(struct net_device *dev, | |
3849 | struct iw_request_info *info, | |
3850 | struct iw_point *data, | |
3851 | char *extra) | |
3852 | { | |
3853 | struct orinoco_private *priv = netdev_priv(dev); | |
3854 | hermes_t *hw = &priv->hw; | |
3855 | int rid = data->flags; | |
3856 | u16 length; | |
3857 | int err; | |
3858 | unsigned long flags; | |
3859 | ||
3860 | /* It's a "get" function, but we don't want users to access the | |
3861 | * WEP key and other raw firmware data */ | |
3862 | if (! capable(CAP_NET_ADMIN)) | |
3863 | return -EPERM; | |
3864 | ||
3865 | if (rid < 0xfc00 || rid > 0xffff) | |
3866 | return -EINVAL; | |
3867 | ||
3868 | if (orinoco_lock(priv, &flags) != 0) | |
3869 | return -EBUSY; | |
3870 | ||
3871 | err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length, | |
3872 | extra); | |
3873 | if (err) | |
3874 | goto out; | |
3875 | ||
3876 | data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length), | |
3877 | MAX_RID_LEN); | |
3878 | ||
3879 | out: | |
3880 | orinoco_unlock(priv, &flags); | |
3881 | return err; | |
3882 | } | |
3883 | ||
1da177e4 LT |
3884 | /* Spy is used for link quality/strength measurements in Ad-Hoc mode |
3885 | * Jean II */ | |
620554e4 CH |
3886 | static int orinoco_ioctl_setspy(struct net_device *dev, |
3887 | struct iw_request_info *info, | |
3888 | struct iw_point *srq, | |
3889 | char *extra) | |
3890 | ||
1da177e4 LT |
3891 | { |
3892 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3893 | struct sockaddr *address = (struct sockaddr *) extra; |
1da177e4 LT |
3894 | int number = srq->length; |
3895 | int i; | |
1da177e4 LT |
3896 | unsigned long flags; |
3897 | ||
1da177e4 LT |
3898 | /* Make sure nobody mess with the structure while we do */ |
3899 | if (orinoco_lock(priv, &flags) != 0) | |
3900 | return -EBUSY; | |
3901 | ||
3902 | /* orinoco_lock() doesn't disable interrupts, so make sure the | |
3903 | * interrupt rx path don't get confused while we copy */ | |
3904 | priv->spy_number = 0; | |
3905 | ||
3906 | if (number > 0) { | |
3907 | /* Extract the addresses */ | |
3908 | for (i = 0; i < number; i++) | |
3909 | memcpy(priv->spy_address[i], address[i].sa_data, | |
3910 | ETH_ALEN); | |
3911 | /* Reset stats */ | |
3912 | memset(priv->spy_stat, 0, | |
3913 | sizeof(struct iw_quality) * IW_MAX_SPY); | |
3914 | /* Set number of addresses */ | |
3915 | priv->spy_number = number; | |
3916 | } | |
3917 | ||
3918 | /* Now, let the others play */ | |
3919 | orinoco_unlock(priv, &flags); | |
3920 | ||
620554e4 CH |
3921 | /* Do NOT call commit handler */ |
3922 | return 0; | |
1da177e4 LT |
3923 | } |
3924 | ||
620554e4 CH |
3925 | static int orinoco_ioctl_getspy(struct net_device *dev, |
3926 | struct iw_request_info *info, | |
3927 | struct iw_point *srq, | |
3928 | char *extra) | |
1da177e4 LT |
3929 | { |
3930 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3931 | struct sockaddr *address = (struct sockaddr *) extra; |
1da177e4 LT |
3932 | int number; |
3933 | int i; | |
3934 | unsigned long flags; | |
3935 | ||
3936 | if (orinoco_lock(priv, &flags) != 0) | |
3937 | return -EBUSY; | |
3938 | ||
3939 | number = priv->spy_number; | |
620554e4 CH |
3940 | /* Create address struct */ |
3941 | for (i = 0; i < number; i++) { | |
3942 | memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN); | |
3943 | address[i].sa_family = AF_UNIX; | |
3944 | } | |
3945 | if (number > 0) { | |
1da177e4 LT |
3946 | /* Create address struct */ |
3947 | for (i = 0; i < number; i++) { | |
3948 | memcpy(address[i].sa_data, priv->spy_address[i], | |
3949 | ETH_ALEN); | |
3950 | address[i].sa_family = AF_UNIX; | |
3951 | } | |
3952 | /* Copy stats */ | |
3953 | /* In theory, we should disable irqs while copying the stats | |
3954 | * because the rx path might update it in the middle... | |
3955 | * Bah, who care ? - Jean II */ | |
620554e4 CH |
3956 | memcpy(extra + (sizeof(struct sockaddr) * number), |
3957 | priv->spy_stat, sizeof(struct iw_quality) * number); | |
1da177e4 | 3958 | } |
620554e4 CH |
3959 | /* Reset updated flags. */ |
3960 | for (i = 0; i < number; i++) | |
3961 | priv->spy_stat[i].updated = 0; | |
1da177e4 LT |
3962 | |
3963 | orinoco_unlock(priv, &flags); | |
3964 | ||
1da177e4 | 3965 | srq->length = number; |
1da177e4 LT |
3966 | |
3967 | return 0; | |
3968 | } | |
3969 | ||
620554e4 CH |
3970 | /* Commit handler, called after set operations */ |
3971 | static int orinoco_ioctl_commit(struct net_device *dev, | |
3972 | struct iw_request_info *info, | |
3973 | void *wrqu, | |
3974 | char *extra) | |
1da177e4 LT |
3975 | { |
3976 | struct orinoco_private *priv = netdev_priv(dev); | |
620554e4 | 3977 | struct hermes *hw = &priv->hw; |
1da177e4 | 3978 | unsigned long flags; |
620554e4 | 3979 | int err = 0; |
1da177e4 | 3980 | |
620554e4 CH |
3981 | if (!priv->open) |
3982 | return 0; | |
1da177e4 | 3983 | |
620554e4 CH |
3984 | if (priv->broken_disableport) { |
3985 | orinoco_reset(dev); | |
3986 | return 0; | |
3987 | } | |
1da177e4 | 3988 | |
620554e4 CH |
3989 | if (orinoco_lock(priv, &flags) != 0) |
3990 | return err; | |
1da177e4 | 3991 | |
620554e4 CH |
3992 | err = hermes_disable_port(hw, 0); |
3993 | if (err) { | |
3994 | printk(KERN_WARNING "%s: Unable to disable port " | |
3995 | "while reconfiguring card\n", dev->name); | |
3996 | priv->broken_disableport = 1; | |
3997 | goto out; | |
3998 | } | |
1da177e4 | 3999 | |
620554e4 CH |
4000 | err = __orinoco_program_rids(dev); |
4001 | if (err) { | |
4002 | printk(KERN_WARNING "%s: Unable to reconfigure card\n", | |
4003 | dev->name); | |
4004 | goto out; | |
4005 | } | |
1da177e4 | 4006 | |
620554e4 CH |
4007 | err = hermes_enable_port(hw, 0); |
4008 | if (err) { | |
4009 | printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n", | |
4010 | dev->name); | |
4011 | goto out; | |
4012 | } | |
1da177e4 | 4013 | |
620554e4 CH |
4014 | out: |
4015 | if (err) { | |
4016 | printk(KERN_WARNING "%s: Resetting instead...\n", dev->name); | |
1da177e4 | 4017 | schedule_work(&priv->reset_work); |
620554e4 CH |
4018 | err = 0; |
4019 | } | |
1da177e4 | 4020 | |
620554e4 CH |
4021 | orinoco_unlock(priv, &flags); |
4022 | return err; | |
4023 | } | |
1da177e4 | 4024 | |
620554e4 CH |
4025 | static const struct iw_priv_args orinoco_privtab[] = { |
4026 | { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" }, | |
4027 | { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" }, | |
4028 | { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4029 | 0, "set_port3" }, | |
4030 | { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4031 | "get_port3" }, | |
4032 | { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4033 | 0, "set_preamble" }, | |
4034 | { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4035 | "get_preamble" }, | |
4036 | { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4037 | 0, "set_ibssport" }, | |
4038 | { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, | |
4039 | "get_ibssport" }, | |
4040 | { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN, | |
4041 | "get_rid" }, | |
4042 | }; | |
1da177e4 | 4043 | |
1da177e4 | 4044 | |
620554e4 CH |
4045 | /* |
4046 | * Structures to export the Wireless Handlers | |
4047 | */ | |
1da177e4 | 4048 | |
620554e4 CH |
4049 | static const iw_handler orinoco_handler[] = { |
4050 | [SIOCSIWCOMMIT-SIOCIWFIRST] (iw_handler) orinoco_ioctl_commit, | |
4051 | [SIOCGIWNAME -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getname, | |
4052 | [SIOCSIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfreq, | |
4053 | [SIOCGIWFREQ -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfreq, | |
4054 | [SIOCSIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setmode, | |
4055 | [SIOCGIWMODE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getmode, | |
4056 | [SIOCSIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setsens, | |
4057 | [SIOCGIWSENS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getsens, | |
4058 | [SIOCGIWRANGE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwrange, | |
4059 | [SIOCSIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setspy, | |
4060 | [SIOCGIWSPY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getspy, | |
16739b06 | 4061 | [SIOCSIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setwap, |
620554e4 CH |
4062 | [SIOCGIWAP -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getwap, |
4063 | [SIOCSIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setessid, | |
4064 | [SIOCGIWESSID -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getessid, | |
4065 | [SIOCSIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setnick, | |
4066 | [SIOCGIWNICKN -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getnick, | |
4067 | [SIOCSIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrate, | |
4068 | [SIOCGIWRATE -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrate, | |
4069 | [SIOCSIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setrts, | |
4070 | [SIOCGIWRTS -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getrts, | |
4071 | [SIOCSIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setfrag, | |
4072 | [SIOCGIWFRAG -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getfrag, | |
4073 | [SIOCGIWRETRY -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getretry, | |
4074 | [SIOCSIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_setiwencode, | |
4075 | [SIOCGIWENCODE-SIOCIWFIRST] (iw_handler) orinoco_ioctl_getiwencode, | |
4076 | [SIOCSIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_setpower, | |
4077 | [SIOCGIWPOWER -SIOCIWFIRST] (iw_handler) orinoco_ioctl_getpower, | |
4078 | }; | |
1da177e4 | 4079 | |
1da177e4 | 4080 | |
620554e4 CH |
4081 | /* |
4082 | Added typecasting since we no longer use iwreq_data -- Moustafa | |
4083 | */ | |
4084 | static const iw_handler orinoco_private_handler[] = { | |
4085 | [0] (iw_handler) orinoco_ioctl_reset, | |
4086 | [1] (iw_handler) orinoco_ioctl_reset, | |
4087 | [2] (iw_handler) orinoco_ioctl_setport3, | |
4088 | [3] (iw_handler) orinoco_ioctl_getport3, | |
4089 | [4] (iw_handler) orinoco_ioctl_setpreamble, | |
4090 | [5] (iw_handler) orinoco_ioctl_getpreamble, | |
4091 | [6] (iw_handler) orinoco_ioctl_setibssport, | |
4092 | [7] (iw_handler) orinoco_ioctl_getibssport, | |
4093 | [9] (iw_handler) orinoco_ioctl_getrid, | |
4094 | }; | |
1da177e4 | 4095 | |
620554e4 CH |
4096 | static const struct iw_handler_def orinoco_handler_def = { |
4097 | .num_standard = ARRAY_SIZE(orinoco_handler), | |
4098 | .num_private = ARRAY_SIZE(orinoco_private_handler), | |
4099 | .num_private_args = ARRAY_SIZE(orinoco_privtab), | |
4100 | .standard = orinoco_handler, | |
4101 | .private = orinoco_private_handler, | |
4102 | .private_args = orinoco_privtab, | |
4103 | }; | |
1da177e4 | 4104 | |
1fab2e8b CH |
4105 | static void orinoco_get_drvinfo(struct net_device *dev, |
4106 | struct ethtool_drvinfo *info) | |
4107 | { | |
4108 | struct orinoco_private *priv = netdev_priv(dev); | |
4109 | ||
4110 | strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1); | |
4111 | strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1); | |
4112 | strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1); | |
4113 | if (dev->class_dev.dev) | |
4114 | strncpy(info->bus_info, dev->class_dev.dev->bus_id, | |
4115 | sizeof(info->bus_info) - 1); | |
4116 | else | |
4117 | snprintf(info->bus_info, sizeof(info->bus_info) - 1, | |
4118 | "PCMCIA %p", priv->hw.iobase); | |
4119 | } | |
4120 | ||
4121 | static struct ethtool_ops orinoco_ethtool_ops = { | |
4122 | .get_drvinfo = orinoco_get_drvinfo, | |
4123 | .get_link = ethtool_op_get_link, | |
4124 | }; | |
4125 | ||
1da177e4 LT |
4126 | /********************************************************************/ |
4127 | /* Debugging */ | |
4128 | /********************************************************************/ | |
4129 | ||
4130 | #if 0 | |
4131 | static void show_rx_frame(struct orinoco_rxframe_hdr *frame) | |
4132 | { | |
4133 | printk(KERN_DEBUG "RX descriptor:\n"); | |
4134 | printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status); | |
4135 | printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time); | |
4136 | printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence); | |
4137 | printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal); | |
4138 | printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate); | |
4139 | printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow); | |
4140 | printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved); | |
4141 | ||
4142 | printk(KERN_DEBUG "IEEE 802.11 header:\n"); | |
4143 | printk(KERN_DEBUG " frame_ctl = 0x%04x\n", | |
4144 | frame->p80211.frame_ctl); | |
4145 | printk(KERN_DEBUG " duration_id = 0x%04x\n", | |
4146 | frame->p80211.duration_id); | |
4147 | printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4148 | frame->p80211.addr1[0], frame->p80211.addr1[1], | |
4149 | frame->p80211.addr1[2], frame->p80211.addr1[3], | |
4150 | frame->p80211.addr1[4], frame->p80211.addr1[5]); | |
4151 | printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4152 | frame->p80211.addr2[0], frame->p80211.addr2[1], | |
4153 | frame->p80211.addr2[2], frame->p80211.addr2[3], | |
4154 | frame->p80211.addr2[4], frame->p80211.addr2[5]); | |
4155 | printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4156 | frame->p80211.addr3[0], frame->p80211.addr3[1], | |
4157 | frame->p80211.addr3[2], frame->p80211.addr3[3], | |
4158 | frame->p80211.addr3[4], frame->p80211.addr3[5]); | |
4159 | printk(KERN_DEBUG " seq_ctl = 0x%04x\n", | |
4160 | frame->p80211.seq_ctl); | |
4161 | printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4162 | frame->p80211.addr4[0], frame->p80211.addr4[1], | |
4163 | frame->p80211.addr4[2], frame->p80211.addr4[3], | |
4164 | frame->p80211.addr4[4], frame->p80211.addr4[5]); | |
4165 | printk(KERN_DEBUG " data_len = 0x%04x\n", | |
4166 | frame->p80211.data_len); | |
4167 | ||
4168 | printk(KERN_DEBUG "IEEE 802.3 header:\n"); | |
4169 | printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4170 | frame->p8023.h_dest[0], frame->p8023.h_dest[1], | |
4171 | frame->p8023.h_dest[2], frame->p8023.h_dest[3], | |
4172 | frame->p8023.h_dest[4], frame->p8023.h_dest[5]); | |
4173 | printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n", | |
4174 | frame->p8023.h_source[0], frame->p8023.h_source[1], | |
4175 | frame->p8023.h_source[2], frame->p8023.h_source[3], | |
4176 | frame->p8023.h_source[4], frame->p8023.h_source[5]); | |
4177 | printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto); | |
4178 | ||
4179 | printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n"); | |
4180 | printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap); | |
4181 | printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap); | |
4182 | printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl); | |
4183 | printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n", | |
4184 | frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]); | |
4185 | printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype); | |
4186 | } | |
4187 | #endif /* 0 */ | |
4188 | ||
4189 | /********************************************************************/ | |
4190 | /* Module initialization */ | |
4191 | /********************************************************************/ | |
4192 | ||
4193 | EXPORT_SYMBOL(alloc_orinocodev); | |
4194 | EXPORT_SYMBOL(free_orinocodev); | |
4195 | ||
4196 | EXPORT_SYMBOL(__orinoco_up); | |
4197 | EXPORT_SYMBOL(__orinoco_down); | |
1da177e4 LT |
4198 | EXPORT_SYMBOL(orinoco_reinit_firmware); |
4199 | ||
4200 | EXPORT_SYMBOL(orinoco_interrupt); | |
4201 | ||
4202 | /* Can't be declared "const" or the whole __initdata section will | |
4203 | * become const */ | |
4204 | static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION | |
4205 | " (David Gibson <hermes@gibson.dropbear.id.au>, " | |
4206 | "Pavel Roskin <proski@gnu.org>, et al)"; | |
4207 | ||
4208 | static int __init init_orinoco(void) | |
4209 | { | |
4210 | printk(KERN_DEBUG "%s\n", version); | |
4211 | return 0; | |
4212 | } | |
4213 | ||
4214 | static void __exit exit_orinoco(void) | |
4215 | { | |
4216 | } | |
4217 | ||
4218 | module_init(init_orinoco); | |
4219 | module_exit(exit_orinoco); |