blob: 306697aa3330f9875328660369691e62cd3b3c27 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
2 *
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
5 *
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
9 *
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
15 *
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
17 *
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
26 *
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
31 *
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
35 * Reserved.
36 *
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
47
48/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
57 */
58
59/* Locking and synchronization:
60 *
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
66 *
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
75 */
76
77#define DRIVER_NAME "orinoco"
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <linux/module.h>
80#include <linux/kernel.h>
81#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <linux/etherdevice.h>
Christoph Hellwig1fab2e82005-06-19 01:27:40 +020084#include <linux/ethtool.h>
David Kilroy3994d502008-08-21 23:27:54 +010085#include <linux/firmware.h>
Pavel Roskin9c974fb2006-08-15 20:45:03 -040086#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#include <linux/wireless.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020088#include <net/iw_handler.h>
Christoph Hellwig5d558b72005-06-19 01:27:28 +020089#include <net/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010092#include "hermes_dld.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95/********************************************************************/
96/* Module information */
97/********************************************************************/
98
99MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
100MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
101MODULE_LICENSE("Dual MPL/GPL");
102
103/* Level of debugging. Used in the macros in orinoco.h */
104#ifdef ORINOCO_DEBUG
105int orinoco_debug = ORINOCO_DEBUG;
106module_param(orinoco_debug, int, 0644);
107MODULE_PARM_DESC(orinoco_debug, "Debug level");
108EXPORT_SYMBOL(orinoco_debug);
109#endif
110
111static int suppress_linkstatus; /* = 0 */
112module_param(suppress_linkstatus, bool, 0644);
113MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Gibson7bb7c3a2005-05-12 20:02:10 -0400114static int ignore_disconnect; /* = 0 */
115module_param(ignore_disconnect, int, 0644);
116MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200118static int force_monitor; /* = 0 */
119module_param(force_monitor, int, 0644);
120MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/********************************************************************/
123/* Compile time configuration and compatibility stuff */
124/********************************************************************/
125
126/* We do this this way to avoid ifdefs in the actual code */
127#ifdef WIRELESS_SPY
Pavel Roskin343c6862005-09-09 18:43:02 -0400128#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129#else
130#define SPY_NUMBER(priv) 0
131#endif /* WIRELESS_SPY */
132
133/********************************************************************/
134/* Internal constants */
135/********************************************************************/
136
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200137/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
138static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
139#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define ORINOCO_MIN_MTU 256
Jeff Garzikb4538722005-05-12 22:48:20 -0400142#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144#define SYMBOL_MAX_VER_LEN (14)
145#define USER_BAP 0
146#define IRQ_BAP 1
147#define MAX_IRQLOOPS_PER_IRQ 10
148#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
149 * how many events the
150 * device could
151 * legitimately generate */
152#define SMALL_KEY_SIZE 5
153#define LARGE_KEY_SIZE 13
154#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
155
156#define DUMMY_FID 0xFFFF
157
158/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
159 HERMES_MAX_MULTICAST : 0)*/
160#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
161
162#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
163 | HERMES_EV_TX | HERMES_EV_TXEXC \
164 | HERMES_EV_WTERR | HERMES_EV_INFO \
165 | HERMES_EV_INFDROP )
166
Christoph Hellwig620554e2005-06-19 01:27:33 +0200167#define MAX_RID_LEN 1024
168
169static const struct iw_handler_def orinoco_handler_def;
Jeff Garzik7282d492006-09-13 14:30:00 -0400170static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/********************************************************************/
173/* Data tables */
174/********************************************************************/
175
176/* The frequency of each channel in MHz */
177static const long channel_frequency[] = {
178 2412, 2417, 2422, 2427, 2432, 2437, 2442,
179 2447, 2452, 2457, 2462, 2467, 2472, 2484
180};
181#define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
182
183/* This tables gives the actual meanings of the bitrate IDs returned
184 * by the firmware. */
185static struct {
186 int bitrate; /* in 100s of kilobits */
187 int automatic;
188 u16 agere_txratectrl;
189 u16 intersil_txratectrl;
190} bitrate_table[] = {
191 {110, 1, 3, 15}, /* Entry 0 is the default */
192 {10, 0, 1, 1},
193 {10, 1, 1, 1},
194 {20, 0, 2, 2},
195 {20, 1, 6, 3},
196 {55, 0, 4, 4},
197 {55, 1, 7, 7},
198 {110, 0, 5, 8},
199};
200#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
201
202/********************************************************************/
203/* Data types */
204/********************************************************************/
205
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400206/* Beginning of the Tx descriptor, used in TxExc handling */
207struct hermes_txexc_data {
208 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400209 __le16 frame_ctl;
210 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200211 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212} __attribute__ ((packed));
213
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200214/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200216 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400217 __le16 status;
218 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 u8 silence;
220 u8 signal;
221 u8 rate;
222 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400223 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200224
225 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400226 __le16 frame_ctl;
227 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200228 u8 addr1[ETH_ALEN];
229 u8 addr2[ETH_ALEN];
230 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400231 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200232 u8 addr4[ETH_ALEN];
233
234 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400235 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236} __attribute__ ((packed));
237
238/********************************************************************/
239/* Function prototypes */
240/********************************************************************/
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242static int __orinoco_program_rids(struct net_device *dev);
243static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245/********************************************************************/
246/* Internal helper functions */
247/********************************************************************/
248
249static inline void set_port_type(struct orinoco_private *priv)
250{
251 switch (priv->iw_mode) {
252 case IW_MODE_INFRA:
253 priv->port_type = 1;
254 priv->createibss = 0;
255 break;
256 case IW_MODE_ADHOC:
257 if (priv->prefer_port3) {
258 priv->port_type = 3;
259 priv->createibss = 0;
260 } else {
261 priv->port_type = priv->ibss_port;
262 priv->createibss = 1;
263 }
264 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200265 case IW_MODE_MONITOR:
266 priv->port_type = 3;
267 priv->createibss = 0;
268 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 default:
270 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
271 priv->ndev->name);
272 }
273}
274
Dan Williams1e3428e2007-10-10 23:56:25 -0400275#define ORINOCO_MAX_BSS_COUNT 64
276static int orinoco_bss_data_allocate(struct orinoco_private *priv)
277{
278 if (priv->bss_data)
279 return 0;
280
281 priv->bss_data =
282 kzalloc(ORINOCO_MAX_BSS_COUNT * sizeof(bss_element), GFP_KERNEL);
283 if (!priv->bss_data) {
284 printk(KERN_WARNING "Out of memory allocating beacons");
285 return -ENOMEM;
286 }
287 return 0;
288}
289
290static void orinoco_bss_data_free(struct orinoco_private *priv)
291{
292 kfree(priv->bss_data);
293 priv->bss_data = NULL;
294}
295
296static void orinoco_bss_data_init(struct orinoco_private *priv)
297{
298 int i;
299
300 INIT_LIST_HEAD(&priv->bss_free_list);
301 INIT_LIST_HEAD(&priv->bss_list);
302 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
303 list_add_tail(&priv->bss_data[i].list, &priv->bss_free_list);
304}
305
David Kilroy3994d502008-08-21 23:27:54 +0100306
307/********************************************************************/
308/* Download functionality */
309/********************************************************************/
310
311struct fw_info {
312 char *pri_fw;
313 char *sta_fw;
314 char *ap_fw;
315 u32 pda_addr;
316 u16 pda_size;
317};
318
319const static struct fw_info orinoco_fw[] = {
320 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
321 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
322 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 0x100 }
323};
324
325/* Structure used to access fields in FW
326 * Make sure LE decoding macros are used
327 */
328struct orinoco_fw_header {
329 char hdr_vers[6]; /* ASCII string for header version */
330 __le16 headersize; /* Total length of header */
331 __le32 entry_point; /* NIC entry point */
332 __le32 blocks; /* Number of blocks to program */
333 __le32 block_offset; /* Offset of block data from eof header */
334 __le32 pdr_offset; /* Offset to PDR data from eof header */
335 __le32 pri_offset; /* Offset to primary plug data */
336 __le32 compat_offset; /* Offset to compatibility data*/
337 char signature[0]; /* FW signature length headersize-20 */
338} __attribute__ ((packed));
339
340/* Download either STA or AP firmware into the card. */
341static int
342orinoco_dl_firmware(struct orinoco_private *priv,
343 const struct fw_info *fw,
344 int ap)
345{
346 /* Plug Data Area (PDA) */
347 __le16 pda[512] = { 0 };
348
349 hermes_t *hw = &priv->hw;
350 const struct firmware *fw_entry;
351 const struct orinoco_fw_header *hdr;
352 const unsigned char *first_block;
353 const unsigned char *end;
354 const char *firmware;
355 struct net_device *dev = priv->ndev;
356 int err;
357
358 if (ap)
359 firmware = fw->ap_fw;
360 else
361 firmware = fw->sta_fw;
362
363 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
364 dev->name, firmware);
365
366 /* Read current plug data */
367 err = hermes_read_pda(hw, pda, fw->pda_addr,
368 min_t(u16, fw->pda_size, sizeof(pda)), 0);
369 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
370 if (err)
371 return err;
372
373 err = request_firmware(&fw_entry, firmware, priv->dev);
374 if (err) {
375 printk(KERN_ERR "%s: Cannot find firmware %s\n",
376 dev->name, firmware);
377 return -ENOENT;
378 }
379
380 hdr = (const struct orinoco_fw_header *) fw_entry->data;
381
382 /* Enable aux port to allow programming */
383 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
384 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
385 if (err != 0)
386 goto abort;
387
388 /* Program data */
389 first_block = (fw_entry->data +
390 le16_to_cpu(hdr->headersize) +
391 le32_to_cpu(hdr->block_offset));
392 end = fw_entry->data + fw_entry->size;
393
394 err = hermes_program(hw, first_block, end);
395 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
396 if (err != 0)
397 goto abort;
398
399 /* Update production data */
400 first_block = (fw_entry->data +
401 le16_to_cpu(hdr->headersize) +
402 le32_to_cpu(hdr->pdr_offset));
403
404 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
405 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
406 if (err)
407 goto abort;
408
409 /* Tell card we've finished */
410 err = hermesi_program_end(hw);
411 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
412 if (err != 0)
413 goto abort;
414
415 /* Check if we're running */
416 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
417 dev->name, hermes_present(hw));
418
419abort:
420 release_firmware(fw_entry);
421 return err;
422}
423
424/* End markers */
425#define TEXT_END 0x1A /* End of text header */
426
427/*
428 * Process a firmware image - stop the card, load the firmware, reset
429 * the card and make sure it responds. For the secondary firmware take
430 * care of the PDA - read it and then write it on top of the firmware.
431 */
432static int
433symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
434 const unsigned char *image, const unsigned char *end,
435 int secondary)
436{
437 hermes_t *hw = &priv->hw;
438 int ret;
439 const unsigned char *ptr;
440 const unsigned char *first_block;
441
442 /* Plug Data Area (PDA) */
443 __le16 pda[256];
444
445 /* Binary block begins after the 0x1A marker */
446 ptr = image;
447 while (*ptr++ != TEXT_END);
448 first_block = ptr;
449
450 /* Read the PDA from EEPROM */
451 if (secondary) {
452 ret = hermes_read_pda(hw, pda, fw->pda_addr, sizeof(pda), 1);
453 if (ret)
454 return ret;
455 }
456
457 /* Stop the firmware, so that it can be safely rewritten */
458 if (priv->stop_fw) {
459 ret = priv->stop_fw(priv, 1);
460 if (ret)
461 return ret;
462 }
463
464 /* Program the adapter with new firmware */
465 ret = hermes_program(hw, first_block, end);
466 if (ret)
467 return ret;
468
469 /* Write the PDA to the adapter */
470 if (secondary) {
471 size_t len = hermes_blocks_length(first_block);
472 ptr = first_block + len;
473 ret = hermes_apply_pda(hw, ptr, pda);
474 if (ret)
475 return ret;
476 }
477
478 /* Run the firmware */
479 if (priv->stop_fw) {
480 ret = priv->stop_fw(priv, 0);
481 if (ret)
482 return ret;
483 }
484
485 /* Reset hermes chip and make sure it responds */
486 ret = hermes_init(hw);
487
488 /* hermes_reset() should return 0 with the secondary firmware */
489 if (secondary && ret != 0)
490 return -ENODEV;
491
492 /* And this should work with any firmware */
493 if (!hermes_present(hw))
494 return -ENODEV;
495
496 return 0;
497}
498
499
500/*
501 * Download the firmware into the card, this also does a PCMCIA soft
502 * reset on the card, to make sure it's in a sane state.
503 */
504static int
505symbol_dl_firmware(struct orinoco_private *priv,
506 const struct fw_info *fw)
507{
508 struct net_device *dev = priv->ndev;
509 int ret;
510 const struct firmware *fw_entry;
511
512 if (request_firmware(&fw_entry, fw->pri_fw,
513 priv->dev) != 0) {
514 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
515 dev->name, fw->pri_fw);
516 return -ENOENT;
517 }
518
519 /* Load primary firmware */
520 ret = symbol_dl_image(priv, fw, fw_entry->data,
521 fw_entry->data + fw_entry->size, 0);
522 release_firmware(fw_entry);
523 if (ret) {
524 printk(KERN_ERR "%s: Primary firmware download failed\n",
525 dev->name);
526 return ret;
527 }
528
529 if (request_firmware(&fw_entry, fw->sta_fw,
530 priv->dev) != 0) {
531 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
532 dev->name, fw->sta_fw);
533 return -ENOENT;
534 }
535
536 /* Load secondary firmware */
537 ret = symbol_dl_image(priv, fw, fw_entry->data,
538 fw_entry->data + fw_entry->size, 1);
539 release_firmware(fw_entry);
540 if (ret) {
541 printk(KERN_ERR "%s: Secondary firmware download failed\n",
542 dev->name);
543 }
544
545 return ret;
546}
547
548static int orinoco_download(struct orinoco_private *priv)
549{
550 int err = 0;
551 /* Reload firmware */
552 switch (priv->firmware_type) {
553 case FIRMWARE_TYPE_AGERE:
554 /* case FIRMWARE_TYPE_INTERSIL: */
555 err = orinoco_dl_firmware(priv,
556 &orinoco_fw[priv->firmware_type], 0);
557 break;
558
559 case FIRMWARE_TYPE_SYMBOL:
560 err = symbol_dl_firmware(priv,
561 &orinoco_fw[priv->firmware_type]);
562 break;
563 case FIRMWARE_TYPE_INTERSIL:
564 break;
565 }
566 /* TODO: if we fail we probably need to reinitialise
567 * the driver */
568
569 return err;
570}
571
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572/********************************************************************/
573/* Device methods */
574/********************************************************************/
575
576static int orinoco_open(struct net_device *dev)
577{
578 struct orinoco_private *priv = netdev_priv(dev);
579 unsigned long flags;
580 int err;
581
582 if (orinoco_lock(priv, &flags) != 0)
583 return -EBUSY;
584
585 err = __orinoco_up(dev);
586
587 if (! err)
588 priv->open = 1;
589
590 orinoco_unlock(priv, &flags);
591
592 return err;
593}
594
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200595static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
597 struct orinoco_private *priv = netdev_priv(dev);
598 int err = 0;
599
600 /* We mustn't use orinoco_lock() here, because we need to be
601 able to close the interface even if hw_unavailable is set
602 (e.g. as we're released after a PC Card removal) */
603 spin_lock_irq(&priv->lock);
604
605 priv->open = 0;
606
607 err = __orinoco_down(dev);
608
609 spin_unlock_irq(&priv->lock);
610
611 return err;
612}
613
614static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
615{
616 struct orinoco_private *priv = netdev_priv(dev);
617
618 return &priv->stats;
619}
620
621static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
622{
623 struct orinoco_private *priv = netdev_priv(dev);
624 hermes_t *hw = &priv->hw;
625 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400626 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 unsigned long flags;
628
629 if (! netif_device_present(dev)) {
630 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
631 dev->name);
632 return NULL; /* FIXME: Can we do better than this? */
633 }
634
David Gibsone67d9d92005-05-12 20:01:22 -0400635 /* If busy, return the old stats. Returning NULL may cause
636 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400638 return wstats;
639
640 /* We can't really wait for the tallies inquiry command to
641 * complete, so we just use the previous results and trigger
642 * a new tallies inquiry command for next time - Jean II */
643 /* FIXME: Really we should wait for the inquiry to come back -
644 * as it is the stats we give don't make a whole lot of sense.
645 * Unfortunately, it's not clear how to do that within the
646 * wireless extensions framework: I think we're in user
647 * context, but a lock seems to be held by the time we get in
648 * here so we're not safe to sleep here. */
649 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 if (priv->iw_mode == IW_MODE_ADHOC) {
652 memset(&wstats->qual, 0, sizeof(wstats->qual));
653 /* If a spy address is defined, we report stats of the
654 * first spy address - Jean II */
655 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400656 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
657 wstats->qual.level = priv->spy_data.spy_stat[0].level;
658 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
659 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 }
661 } else {
662 struct {
Pavel Roskina208c4e2006-04-07 04:10:26 -0400663 __le16 qual, signal, noise, unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 } __attribute__ ((packed)) cq;
665
666 err = HERMES_READ_RECORD(hw, USER_BAP,
667 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400668
669 if (!err) {
670 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
671 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
672 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
673 wstats->qual.updated = 7;
674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 return wstats;
679}
680
681static void orinoco_set_multicast_list(struct net_device *dev)
682{
683 struct orinoco_private *priv = netdev_priv(dev);
684 unsigned long flags;
685
686 if (orinoco_lock(priv, &flags) != 0) {
687 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
688 "called when hw_unavailable\n", dev->name);
689 return;
690 }
691
692 __orinoco_set_multicast_list(dev);
693 orinoco_unlock(priv, &flags);
694}
695
696static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
697{
698 struct orinoco_private *priv = netdev_priv(dev);
699
700 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
701 return -EINVAL;
702
Jeff Garzikb4538722005-05-12 22:48:20 -0400703 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 (priv->nicbuf_size - ETH_HLEN) )
705 return -EINVAL;
706
707 dev->mtu = new_mtu;
708
709 return 0;
710}
711
712/********************************************************************/
713/* Tx path */
714/********************************************************************/
715
716static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
717{
718 struct orinoco_private *priv = netdev_priv(dev);
719 struct net_device_stats *stats = &priv->stats;
720 hermes_t *hw = &priv->hw;
721 int err = 0;
722 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 struct ethhdr *eh;
Pavel Roskina28dc812006-04-07 04:10:45 -0400724 int data_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 struct hermes_tx_descriptor desc;
726 unsigned long flags;
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 if (! netif_running(dev)) {
729 printk(KERN_ERR "%s: Tx on stopped device!\n",
730 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400731 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733
734 if (netif_queue_stopped(dev)) {
735 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
736 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400737 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739
740 if (orinoco_lock(priv, &flags) != 0) {
741 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
742 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400743 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200746 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 /* Oops, the firmware hasn't established a connection,
748 silently drop the packet (this seems to be the
749 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400750 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 }
752
Pavel Roskin8d5be082006-04-07 04:10:41 -0400753 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400754 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400755 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 eh = (struct ethhdr *)skb->data;
758
759 memset(&desc, 0, sizeof(desc));
760 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
761 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
762 if (err) {
763 if (net_ratelimit())
764 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
765 "to BAP\n", dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400766 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 }
768
769 /* Clear the 802.11 header and data length fields - some
770 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
771 * if this isn't done. */
772 hermes_clear_words(hw, HERMES_DATA0,
773 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
774
775 /* Encapsulate Ethernet-II frames */
776 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400777 struct header_struct {
778 struct ethhdr eth; /* 802.3 header */
779 u8 encap[6]; /* 802.2 header */
780 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Pavel Roskina28dc812006-04-07 04:10:45 -0400782 /* Strip destination and source from the data */
783 skb_pull(skb, 2 * ETH_ALEN);
784 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
785
786 /* And move them to a separate header */
787 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
788 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
789 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
790
791 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
792 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 if (err) {
794 if (net_ratelimit())
795 printk(KERN_ERR "%s: Error %d writing packet "
796 "header to BAP\n", dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400797 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
799 } else { /* IEEE 802.3 frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 data_off = HERMES_802_3_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
Pavel Roskina28dc812006-04-07 04:10:45 -0400803 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 txfid, data_off);
805 if (err) {
806 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
807 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400808 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 }
810
811 /* Finally, we actually initiate the send */
812 netif_stop_queue(dev);
813
814 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
815 txfid, NULL);
816 if (err) {
817 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700818 if (net_ratelimit())
819 printk(KERN_ERR "%s: Error %d transmitting packet\n",
820 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400821 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 }
823
824 dev->trans_start = jiffies;
Pavel Roskina28dc812006-04-07 04:10:45 -0400825 stats->tx_bytes += data_off + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400826 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400828 drop:
829 stats->tx_errors++;
830 stats->tx_dropped++;
831
832 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400835 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400837 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400838 if (err == -EIO)
839 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400841 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842}
843
844static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
845{
846 struct orinoco_private *priv = netdev_priv(dev);
847 u16 fid = hermes_read_regn(hw, ALLOCFID);
848
849 if (fid != priv->txfid) {
850 if (fid != DUMMY_FID)
851 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
852 dev->name, fid);
853 return;
854 }
855
856 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
857}
858
859static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
860{
861 struct orinoco_private *priv = netdev_priv(dev);
862 struct net_device_stats *stats = &priv->stats;
863
864 stats->tx_packets++;
865
866 netif_wake_queue(dev);
867
868 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
869}
870
871static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
872{
873 struct orinoco_private *priv = netdev_priv(dev);
874 struct net_device_stats *stats = &priv->stats;
875 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400876 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400877 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 int err = 0;
879
880 if (fid == DUMMY_FID)
881 return; /* Nothing's really happened */
882
Pavel Roskin48ca7032005-09-23 04:18:06 -0400883 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200884 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400885 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200886 fid, 0);
887
888 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
889 stats->tx_errors++;
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 if (err) {
892 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
893 "(FID=%04X error %d)\n",
894 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200895 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
897
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200898 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
899 err, fid);
900
901 /* We produce a TXDROP event only for retry or lifetime
902 * exceeded, because that's the only status that really mean
903 * that this particular node went away.
904 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400905 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400906 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200907 union iwreq_data wrqu;
908
909 /* Copy 802.11 dest address.
910 * We use the 802.11 header because the frame may
911 * not be 802.3 or may be mangled...
912 * In Ad-Hoc mode, it will be the node address.
913 * In managed mode, it will be most likely the AP addr
914 * User space will figure out how to convert it to
915 * whatever it needs (IP address or else).
916 * - Jean II */
917 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
918 wrqu.addr.sa_family = ARPHRD_ETHER;
919
920 /* Send event to user space */
921 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
927static void orinoco_tx_timeout(struct net_device *dev)
928{
929 struct orinoco_private *priv = netdev_priv(dev);
930 struct net_device_stats *stats = &priv->stats;
931 struct hermes *hw = &priv->hw;
932
933 printk(KERN_WARNING "%s: Tx timeout! "
934 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
935 dev->name, hermes_read_regn(hw, ALLOCFID),
936 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
937
938 stats->tx_errors++;
939
940 schedule_work(&priv->reset_work);
941}
942
943/********************************************************************/
944/* Rx path (data frames) */
945/********************************************************************/
946
947/* Does the frame have a SNAP header indicating it should be
948 * de-encapsulated to Ethernet-II? */
949static inline int is_ethersnap(void *_hdr)
950{
951 u8 *hdr = _hdr;
952
953 /* We de-encapsulate all packets which, a) have SNAP headers
954 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
955 * and where b) the OUI of the SNAP header is 00:00:00 or
956 * 00:00:f8 - we need both because different APs appear to use
957 * different OUIs for some reason */
958 return (memcmp(hdr, &encaps_hdr, 5) == 0)
959 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
960}
961
962static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
963 int level, int noise)
964{
Pavel Roskin343c6862005-09-09 18:43:02 -0400965 struct iw_quality wstats;
966 wstats.level = level - 0x95;
967 wstats.noise = noise - 0x95;
968 wstats.qual = (level > noise) ? (level - noise) : 0;
969 wstats.updated = 7;
970 /* Update spy records */
971 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972}
973
974static void orinoco_stat_gather(struct net_device *dev,
975 struct sk_buff *skb,
976 struct hermes_rx_descriptor *desc)
977{
978 struct orinoco_private *priv = netdev_priv(dev);
979
980 /* Using spy support with lots of Rx packets, like in an
981 * infrastructure (AP), will really slow down everything, because
982 * the MAC address must be compared to each entry of the spy list.
983 * If the user really asks for it (set some address in the
984 * spy list), we do it, but he will pay the price.
985 * Note that to get here, you need both WIRELESS_SPY
986 * compiled in AND some addresses in the list !!!
987 */
988 /* Note : gcc will optimise the whole section away if
989 * WIRELESS_SPY is not defined... - Jean II */
990 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -0700991 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 desc->signal, desc->silence);
993 }
994}
995
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200996/*
997 * orinoco_rx_monitor - handle received monitor frames.
998 *
999 * Arguments:
1000 * dev network device
1001 * rxfid received FID
1002 * desc rx descriptor of the frame
1003 *
1004 * Call context: interrupt
1005 */
1006static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1007 struct hermes_rx_descriptor *desc)
1008{
1009 u32 hdrlen = 30; /* return full header by default */
1010 u32 datalen = 0;
1011 u16 fc;
1012 int err;
1013 int len;
1014 struct sk_buff *skb;
1015 struct orinoco_private *priv = netdev_priv(dev);
1016 struct net_device_stats *stats = &priv->stats;
1017 hermes_t *hw = &priv->hw;
1018
1019 len = le16_to_cpu(desc->data_len);
1020
1021 /* Determine the size of the header and the data */
1022 fc = le16_to_cpu(desc->frame_ctl);
1023 switch (fc & IEEE80211_FCTL_FTYPE) {
1024 case IEEE80211_FTYPE_DATA:
1025 if ((fc & IEEE80211_FCTL_TODS)
1026 && (fc & IEEE80211_FCTL_FROMDS))
1027 hdrlen = 30;
1028 else
1029 hdrlen = 24;
1030 datalen = len;
1031 break;
1032 case IEEE80211_FTYPE_MGMT:
1033 hdrlen = 24;
1034 datalen = len;
1035 break;
1036 case IEEE80211_FTYPE_CTL:
1037 switch (fc & IEEE80211_FCTL_STYPE) {
1038 case IEEE80211_STYPE_PSPOLL:
1039 case IEEE80211_STYPE_RTS:
1040 case IEEE80211_STYPE_CFEND:
1041 case IEEE80211_STYPE_CFENDACK:
1042 hdrlen = 16;
1043 break;
1044 case IEEE80211_STYPE_CTS:
1045 case IEEE80211_STYPE_ACK:
1046 hdrlen = 10;
1047 break;
1048 }
1049 break;
1050 default:
1051 /* Unknown frame type */
1052 break;
1053 }
1054
1055 /* sanity check the length */
1056 if (datalen > IEEE80211_DATA_LEN + 12) {
1057 printk(KERN_DEBUG "%s: oversized monitor frame, "
1058 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001059 stats->rx_length_errors++;
1060 goto update_stats;
1061 }
1062
1063 skb = dev_alloc_skb(hdrlen + datalen);
1064 if (!skb) {
1065 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1066 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -07001067 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001068 }
1069
1070 /* Copy the 802.11 header to the skb */
1071 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001072 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001073
1074 /* If any, copy the data from the card to the skb */
1075 if (datalen > 0) {
1076 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1077 ALIGN(datalen, 2), rxfid,
1078 HERMES_802_2_OFFSET);
1079 if (err) {
1080 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1081 dev->name, err);
1082 goto drop;
1083 }
1084 }
1085
1086 skb->dev = dev;
1087 skb->ip_summed = CHECKSUM_NONE;
1088 skb->pkt_type = PACKET_OTHERHOST;
1089 skb->protocol = __constant_htons(ETH_P_802_2);
1090
1091 dev->last_rx = jiffies;
1092 stats->rx_packets++;
1093 stats->rx_bytes += skb->len;
1094
1095 netif_rx(skb);
1096 return;
1097
1098 drop:
1099 dev_kfree_skb_irq(skb);
1100 update_stats:
1101 stats->rx_errors++;
1102 stats->rx_dropped++;
1103}
1104
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1106{
1107 struct orinoco_private *priv = netdev_priv(dev);
1108 struct net_device_stats *stats = &priv->stats;
1109 struct iw_statistics *wstats = &priv->wstats;
1110 struct sk_buff *skb = NULL;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001111 u16 rxfid, status, fc;
1112 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 struct hermes_rx_descriptor desc;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001114 struct ethhdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 int err;
1116
1117 rxfid = hermes_read_regn(hw, RXFID);
1118
1119 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1120 rxfid, 0);
1121 if (err) {
1122 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1123 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001124 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 }
1126
1127 status = le16_to_cpu(desc.status);
1128
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001129 if (status & HERMES_RXSTAT_BADCRC) {
1130 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1131 dev->name);
1132 stats->rx_crc_errors++;
1133 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
1135
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001136 /* Handle frames in monitor mode */
1137 if (priv->iw_mode == IW_MODE_MONITOR) {
1138 orinoco_rx_monitor(dev, rxfid, &desc);
1139 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 }
1141
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001142 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1143 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1144 dev->name);
1145 wstats->discard.code++;
1146 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
1148
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001149 length = le16_to_cpu(desc.data_len);
1150 fc = le16_to_cpu(desc.frame_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* Sanity checks */
1153 if (length < 3) { /* No for even an 802.2 LLC header */
1154 /* At least on Symbol firmware with PCF we get quite a
1155 lot of these legitimately - Poll frames with no
1156 data. */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001157 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001159 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1161 dev->name, length);
1162 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001163 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
1165
1166 /* We need space for the packet data itself, plus an ethernet
1167 header, plus 2 bytes so we can align the IP header on a
1168 32bit boundary, plus 1 byte so we can read in odd length
1169 packets from the card, which has an IO granularity of 16
1170 bits */
1171 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1172 if (!skb) {
1173 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1174 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001175 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 }
1177
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001178 /* We'll prepend the header, so reserve space for it. The worst
1179 case is no decapsulation, when 802.3 header is prepended and
1180 nothing is removed. 2 is for aligning the IP header. */
1181 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001183 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1184 ALIGN(length, 2), rxfid,
1185 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 if (err) {
1187 printk(KERN_ERR "%s: error %d reading frame. "
1188 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 goto drop;
1190 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
1192 /* Handle decapsulation
1193 * In most cases, the firmware tell us about SNAP frames.
1194 * For some reason, the SNAP frames sent by LinkSys APs
1195 * are not properly recognised by most firmwares.
1196 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001197 if (length >= ENCAPS_OVERHEAD &&
1198 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1199 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1200 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 /* These indicate a SNAP within 802.2 LLC within
1202 802.11 frame which we'll need to de-encapsulate to
1203 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001204 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001206 /* 802.3 frame - prepend 802.3 header as is */
1207 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1208 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 }
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001210 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
1211 if (fc & IEEE80211_FCTL_FROMDS)
1212 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
1213 else
1214 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
1216 dev->last_rx = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 skb->protocol = eth_type_trans(skb, dev);
1218 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001219 if (fc & IEEE80211_FCTL_TODS)
1220 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 /* Process the wireless stats if needed */
1223 orinoco_stat_gather(dev, skb, &desc);
1224
1225 /* Pass the packet to the networking stack */
1226 netif_rx(skb);
1227 stats->rx_packets++;
1228 stats->rx_bytes += length;
1229
1230 return;
1231
1232 drop:
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001233 dev_kfree_skb_irq(skb);
1234 update_stats:
1235 stats->rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 stats->rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237}
1238
1239/********************************************************************/
1240/* Rx path (info frames) */
1241/********************************************************************/
1242
1243static void print_linkstatus(struct net_device *dev, u16 status)
1244{
1245 char * s;
1246
1247 if (suppress_linkstatus)
1248 return;
1249
1250 switch (status) {
1251 case HERMES_LINKSTATUS_NOT_CONNECTED:
1252 s = "Not Connected";
1253 break;
1254 case HERMES_LINKSTATUS_CONNECTED:
1255 s = "Connected";
1256 break;
1257 case HERMES_LINKSTATUS_DISCONNECTED:
1258 s = "Disconnected";
1259 break;
1260 case HERMES_LINKSTATUS_AP_CHANGE:
1261 s = "AP Changed";
1262 break;
1263 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1264 s = "AP Out of Range";
1265 break;
1266 case HERMES_LINKSTATUS_AP_IN_RANGE:
1267 s = "AP In Range";
1268 break;
1269 case HERMES_LINKSTATUS_ASSOC_FAILED:
1270 s = "Association Failed";
1271 break;
1272 default:
1273 s = "UNKNOWN";
1274 }
1275
1276 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1277 dev->name, s, status);
1278}
1279
Christoph Hellwig16739b02005-06-19 01:27:51 +02001280/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001281static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001282{
David Howellsc4028952006-11-22 14:57:56 +00001283 struct orinoco_private *priv =
1284 container_of(work, struct orinoco_private, join_work);
1285 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001286 struct hermes *hw = &priv->hw;
1287 int err;
1288 unsigned long flags;
1289 struct join_req {
1290 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001291 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001292 } __attribute__ ((packed)) req;
1293 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001294 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001295 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001296 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001297 u8 *buf;
1298 u16 len;
1299
1300 /* Allocate buffer for scan results */
1301 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1302 if (! buf)
1303 return;
1304
1305 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001306 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001307
1308 /* Sanity checks in case user changed something in the meantime */
1309 if (! priv->bssid_fixed)
1310 goto out;
1311
1312 if (strlen(priv->desired_essid) == 0)
1313 goto out;
1314
1315 /* Read scan results from the firmware */
1316 err = hermes_read_ltv(hw, USER_BAP,
1317 HERMES_RID_SCANRESULTSTABLE,
1318 MAX_SCAN_LEN, &len, buf);
1319 if (err) {
1320 printk(KERN_ERR "%s: Cannot read scan results\n",
1321 dev->name);
1322 goto out;
1323 }
1324
1325 len = HERMES_RECLEN_TO_BYTES(len);
1326
1327 /* Go through the scan results looking for the channel of the AP
1328 * we were requested to join */
1329 for (; offset + atom_len <= len; offset += atom_len) {
1330 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001331 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1332 found = 1;
1333 break;
1334 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001335 }
1336
Pavel Roskinc89cc222005-09-01 20:06:06 -04001337 if (! found) {
1338 DEBUG(1, "%s: Requested AP not found in scan results\n",
1339 dev->name);
1340 goto out;
1341 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001342
Christoph Hellwig16739b02005-06-19 01:27:51 +02001343 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1344 req.channel = atom->channel; /* both are little-endian */
1345 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1346 &req);
1347 if (err)
1348 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1349
1350 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001351 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001352
1353 fail_lock:
1354 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001355}
1356
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001357/* Send new BSSID to userspace */
David Howellsc4028952006-11-22 14:57:56 +00001358static void orinoco_send_wevents(struct work_struct *work)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001359{
David Howellsc4028952006-11-22 14:57:56 +00001360 struct orinoco_private *priv =
1361 container_of(work, struct orinoco_private, wevent_work);
1362 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001363 struct hermes *hw = &priv->hw;
1364 union iwreq_data wrqu;
1365 int err;
1366 unsigned long flags;
1367
1368 if (orinoco_lock(priv, &flags) != 0)
1369 return;
1370
1371 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1372 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1373 if (err != 0)
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001374 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001375
1376 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1377
1378 /* Send event to user space */
1379 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001380
1381 out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001382 orinoco_unlock(priv, &flags);
1383}
1384
Dan Williams1e3428e2007-10-10 23:56:25 -04001385
1386static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1387 unsigned long scan_age)
1388{
1389 bss_element *bss;
1390 bss_element *tmp_bss;
1391
1392 /* Blow away current list of scan results */
1393 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1394 if (!scan_age ||
1395 time_after(jiffies, bss->last_scanned + scan_age)) {
1396 list_move_tail(&bss->list, &priv->bss_free_list);
1397 /* Don't blow away ->list, just BSS data */
1398 memset(bss, 0, sizeof(bss->bss));
1399 bss->last_scanned = 0;
1400 }
1401 }
1402}
1403
1404static int orinoco_process_scan_results(struct net_device *dev,
1405 unsigned char *buf,
1406 int len)
1407{
1408 struct orinoco_private *priv = netdev_priv(dev);
1409 int offset; /* In the scan data */
1410 union hermes_scan_info *atom;
1411 int atom_len;
1412
1413 switch (priv->firmware_type) {
1414 case FIRMWARE_TYPE_AGERE:
1415 atom_len = sizeof(struct agere_scan_apinfo);
1416 offset = 0;
1417 break;
1418 case FIRMWARE_TYPE_SYMBOL:
1419 /* Lack of documentation necessitates this hack.
1420 * Different firmwares have 68 or 76 byte long atoms.
1421 * We try modulo first. If the length divides by both,
1422 * we check what would be the channel in the second
1423 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1424 * Valid channel cannot be 0. */
1425 if (len % 76)
1426 atom_len = 68;
1427 else if (len % 68)
1428 atom_len = 76;
1429 else if (len >= 1292 && buf[68] == 0)
1430 atom_len = 76;
1431 else
1432 atom_len = 68;
1433 offset = 0;
1434 break;
1435 case FIRMWARE_TYPE_INTERSIL:
1436 offset = 4;
1437 if (priv->has_hostscan) {
1438 atom_len = le16_to_cpup((__le16 *)buf);
1439 /* Sanity check for atom_len */
1440 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1441 printk(KERN_ERR "%s: Invalid atom_len in scan "
1442 "data: %d\n", dev->name, atom_len);
1443 return -EIO;
1444 }
1445 } else
1446 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1447 break;
1448 default:
1449 return -EOPNOTSUPP;
1450 }
1451
1452 /* Check that we got an whole number of atoms */
1453 if ((len - offset) % atom_len) {
1454 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1455 "atom_len %d, offset %d\n", dev->name, len,
1456 atom_len, offset);
1457 return -EIO;
1458 }
1459
1460 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1461
1462 /* Read the entries one by one */
1463 for (; offset + atom_len <= len; offset += atom_len) {
1464 int found = 0;
Dan Williams22367612007-12-05 11:01:23 -05001465 bss_element *bss = NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -04001466
1467 /* Get next atom */
1468 atom = (union hermes_scan_info *) (buf + offset);
1469
1470 /* Try to update an existing bss first */
1471 list_for_each_entry(bss, &priv->bss_list, list) {
1472 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1473 continue;
1474 if (le16_to_cpu(bss->bss.a.essid_len) !=
1475 le16_to_cpu(atom->a.essid_len))
1476 continue;
1477 if (memcmp(bss->bss.a.essid, atom->a.essid,
1478 le16_to_cpu(atom->a.essid_len)))
1479 continue;
Dan Williams1e3428e2007-10-10 23:56:25 -04001480 found = 1;
1481 break;
1482 }
1483
1484 /* Grab a bss off the free list */
1485 if (!found && !list_empty(&priv->bss_free_list)) {
1486 bss = list_entry(priv->bss_free_list.next,
1487 bss_element, list);
1488 list_del(priv->bss_free_list.next);
1489
Dan Williams1e3428e2007-10-10 23:56:25 -04001490 list_add_tail(&bss->list, &priv->bss_list);
1491 }
Dan Williams22367612007-12-05 11:01:23 -05001492
1493 if (bss) {
1494 /* Always update the BSS to get latest beacon info */
1495 memcpy(&bss->bss, atom, sizeof(bss->bss));
1496 bss->last_scanned = jiffies;
1497 }
Dan Williams1e3428e2007-10-10 23:56:25 -04001498 }
1499
1500 return 0;
1501}
1502
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1504{
1505 struct orinoco_private *priv = netdev_priv(dev);
1506 u16 infofid;
1507 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001508 __le16 len;
1509 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 } __attribute__ ((packed)) info;
1511 int len, type;
1512 int err;
1513
1514 /* This is an answer to an INQUIRE command that we did earlier,
1515 * or an information "event" generated by the card
1516 * The controller return to us a pseudo frame containing
1517 * the information in question - Jean II */
1518 infofid = hermes_read_regn(hw, INFOFID);
1519
1520 /* Read the info frame header - don't try too hard */
1521 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1522 infofid, 0);
1523 if (err) {
1524 printk(KERN_ERR "%s: error %d reading info frame. "
1525 "Frame dropped.\n", dev->name, err);
1526 return;
1527 }
1528
1529 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1530 type = le16_to_cpu(info.type);
1531
1532 switch (type) {
1533 case HERMES_INQ_TALLIES: {
1534 struct hermes_tallies_frame tallies;
1535 struct iw_statistics *wstats = &priv->wstats;
1536
1537 if (len > sizeof(tallies)) {
1538 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1539 dev->name, len);
1540 len = sizeof(tallies);
1541 }
1542
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001543 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1544 infofid, sizeof(info));
1545 if (err)
1546 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 /* Increment our various counters */
1549 /* wstats->discard.nwid - no wrong BSSID stuff */
1550 wstats->discard.code +=
1551 le16_to_cpu(tallies.RxWEPUndecryptable);
1552 if (len == sizeof(tallies))
1553 wstats->discard.code +=
1554 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1555 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1556 wstats->discard.misc +=
1557 le16_to_cpu(tallies.TxDiscardsWrongSA);
1558 wstats->discard.fragment +=
1559 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1560 wstats->discard.retries +=
1561 le16_to_cpu(tallies.TxRetryLimitExceeded);
1562 /* wstats->miss.beacon - no match */
1563 }
1564 break;
1565 case HERMES_INQ_LINKSTATUS: {
1566 struct hermes_linkstatus linkstatus;
1567 u16 newstatus;
1568 int connected;
1569
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001570 if (priv->iw_mode == IW_MODE_MONITOR)
1571 break;
1572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 if (len != sizeof(linkstatus)) {
1574 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1575 dev->name, len);
1576 break;
1577 }
1578
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001579 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1580 infofid, sizeof(info));
1581 if (err)
1582 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 newstatus = le16_to_cpu(linkstatus.linkstatus);
1584
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001585 /* Symbol firmware uses "out of range" to signal that
1586 * the hostscan frame can be requested. */
1587 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1588 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1589 priv->has_hostscan && priv->scan_inprogress) {
1590 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1591 break;
1592 }
1593
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1595 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1596 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1597
1598 if (connected)
1599 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001600 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 netif_carrier_off(dev);
1602
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001603 if (newstatus != priv->last_linkstatus) {
1604 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001606 /* The info frame contains only one word which is the
1607 * status (see hermes.h). The status is pretty boring
1608 * in itself, that's why we export the new BSSID...
1609 * Jean II */
1610 schedule_work(&priv->wevent_work);
1611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 }
1613 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001614 case HERMES_INQ_SCAN:
1615 if (!priv->scan_inprogress && priv->bssid_fixed &&
1616 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1617 schedule_work(&priv->join_work);
1618 break;
1619 }
1620 /* fall through */
1621 case HERMES_INQ_HOSTSCAN:
1622 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1623 /* Result of a scanning. Contains information about
1624 * cells in the vicinity - Jean II */
1625 union iwreq_data wrqu;
1626 unsigned char *buf;
1627
Dan Williams1e3428e2007-10-10 23:56:25 -04001628 /* Scan is no longer in progress */
1629 priv->scan_inprogress = 0;
1630
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001631 /* Sanity check */
1632 if (len > 4096) {
1633 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1634 dev->name, len);
1635 break;
1636 }
1637
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001638 /* Allocate buffer for results */
1639 buf = kmalloc(len, GFP_ATOMIC);
1640 if (buf == NULL)
1641 /* No memory, so can't printk()... */
1642 break;
1643
1644 /* Read scan data */
1645 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1646 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001647 if (err) {
1648 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001649 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001650 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001651
1652#ifdef ORINOCO_DEBUG
1653 {
1654 int i;
1655 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1656 for(i = 1; i < (len * 2); i++)
1657 printk(":%02X", buf[i]);
1658 printk("]\n");
1659 }
1660#endif /* ORINOCO_DEBUG */
1661
Dan Williams1e3428e2007-10-10 23:56:25 -04001662 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1663 /* Send an empty event to user space.
1664 * We don't send the received data on the event because
1665 * it would require us to do complex transcoding, and
1666 * we want to minimise the work done in the irq handler
1667 * Use a request to extract the data - Jean II */
1668 wrqu.data.length = 0;
1669 wrqu.data.flags = 0;
1670 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1671 }
1672 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001673 }
1674 break;
1675 case HERMES_INQ_SEC_STAT_AGERE:
1676 /* Security status (Agere specific) */
1677 /* Ignore this frame for now */
1678 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1679 break;
1680 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 default:
1682 printk(KERN_DEBUG "%s: Unknown information frame received: "
1683 "type 0x%04x, length %d\n", dev->name, type, len);
1684 /* We don't actually do anything about it */
1685 break;
1686 }
1687}
1688
1689static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1690{
1691 if (net_ratelimit())
1692 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1693}
1694
1695/********************************************************************/
1696/* Internal hardware control routines */
1697/********************************************************************/
1698
1699int __orinoco_up(struct net_device *dev)
1700{
1701 struct orinoco_private *priv = netdev_priv(dev);
1702 struct hermes *hw = &priv->hw;
1703 int err;
1704
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001705 netif_carrier_off(dev); /* just to make sure */
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 err = __orinoco_program_rids(dev);
1708 if (err) {
1709 printk(KERN_ERR "%s: Error %d configuring card\n",
1710 dev->name, err);
1711 return err;
1712 }
1713
1714 /* Fire things up again */
1715 hermes_set_irqmask(hw, ORINOCO_INTEN);
1716 err = hermes_enable_port(hw, 0);
1717 if (err) {
1718 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1719 dev->name, err);
1720 return err;
1721 }
1722
1723 netif_start_queue(dev);
1724
1725 return 0;
1726}
1727
1728int __orinoco_down(struct net_device *dev)
1729{
1730 struct orinoco_private *priv = netdev_priv(dev);
1731 struct hermes *hw = &priv->hw;
1732 int err;
1733
1734 netif_stop_queue(dev);
1735
1736 if (! priv->hw_unavailable) {
1737 if (! priv->broken_disableport) {
1738 err = hermes_disable_port(hw, 0);
1739 if (err) {
1740 /* Some firmwares (e.g. Intersil 1.3.x) seem
1741 * to have problems disabling the port, oh
1742 * well, too bad. */
1743 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1744 dev->name, err);
1745 priv->broken_disableport = 1;
1746 }
1747 }
1748 hermes_set_irqmask(hw, 0);
1749 hermes_write_regn(hw, EVACK, 0xffff);
1750 }
1751
1752 /* firmware will have to reassociate */
1753 netif_carrier_off(dev);
1754 priv->last_linkstatus = 0xffff;
1755
1756 return 0;
1757}
1758
Pavel Roskin37a6c612006-04-07 04:10:49 -04001759static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760{
1761 struct orinoco_private *priv = netdev_priv(dev);
1762 struct hermes *hw = &priv->hw;
1763 int err;
1764
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001766 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 /* Try workaround for old Symbol firmware bug */
1768 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1769 "(old Symbol firmware?). Trying to work around... ",
1770 dev->name);
1771
1772 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1773 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1774 if (err)
1775 printk("failed!\n");
1776 else
1777 printk("ok.\n");
1778 }
1779
1780 return err;
1781}
1782
Pavel Roskin37a6c612006-04-07 04:10:49 -04001783int orinoco_reinit_firmware(struct net_device *dev)
1784{
1785 struct orinoco_private *priv = netdev_priv(dev);
1786 struct hermes *hw = &priv->hw;
1787 int err;
1788
1789 err = hermes_init(hw);
1790 if (!err)
1791 err = orinoco_allocate_fid(dev);
1792
1793 return err;
1794}
1795
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1797{
1798 hermes_t *hw = &priv->hw;
1799 int err = 0;
1800
1801 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1802 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1803 priv->ndev->name, priv->bitratemode);
1804 return -EINVAL;
1805 }
1806
1807 switch (priv->firmware_type) {
1808 case FIRMWARE_TYPE_AGERE:
1809 err = hermes_write_wordrec(hw, USER_BAP,
1810 HERMES_RID_CNFTXRATECONTROL,
1811 bitrate_table[priv->bitratemode].agere_txratectrl);
1812 break;
1813 case FIRMWARE_TYPE_INTERSIL:
1814 case FIRMWARE_TYPE_SYMBOL:
1815 err = hermes_write_wordrec(hw, USER_BAP,
1816 HERMES_RID_CNFTXRATECONTROL,
1817 bitrate_table[priv->bitratemode].intersil_txratectrl);
1818 break;
1819 default:
1820 BUG();
1821 }
1822
1823 return err;
1824}
1825
Christoph Hellwig16739b02005-06-19 01:27:51 +02001826/* Set fixed AP address */
1827static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1828{
1829 int roaming_flag;
1830 int err = 0;
1831 hermes_t *hw = &priv->hw;
1832
1833 switch (priv->firmware_type) {
1834 case FIRMWARE_TYPE_AGERE:
1835 /* not supported */
1836 break;
1837 case FIRMWARE_TYPE_INTERSIL:
1838 if (priv->bssid_fixed)
1839 roaming_flag = 2;
1840 else
1841 roaming_flag = 1;
1842
1843 err = hermes_write_wordrec(hw, USER_BAP,
1844 HERMES_RID_CNFROAMINGMODE,
1845 roaming_flag);
1846 break;
1847 case FIRMWARE_TYPE_SYMBOL:
1848 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1849 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1850 &priv->desired_bssid);
1851 break;
1852 }
1853 return err;
1854}
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856/* Change the WEP keys and/or the current keys. Can be called
1857 * either from __orinoco_hw_setup_wep() or directly from
1858 * orinoco_ioctl_setiwencode(). In the later case the association
1859 * with the AP is not broken (if the firmware can handle it),
1860 * which is needed for 802.1x implementations. */
1861static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1862{
1863 hermes_t *hw = &priv->hw;
1864 int err = 0;
1865
1866 switch (priv->firmware_type) {
1867 case FIRMWARE_TYPE_AGERE:
1868 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1869 HERMES_RID_CNFWEPKEYS_AGERE,
1870 &priv->keys);
1871 if (err)
1872 return err;
1873 err = hermes_write_wordrec(hw, USER_BAP,
1874 HERMES_RID_CNFTXKEY_AGERE,
1875 priv->tx_key);
1876 if (err)
1877 return err;
1878 break;
1879 case FIRMWARE_TYPE_INTERSIL:
1880 case FIRMWARE_TYPE_SYMBOL:
1881 {
1882 int keylen;
1883 int i;
1884
1885 /* Force uniform key length to work around firmware bugs */
1886 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1887
1888 if (keylen > LARGE_KEY_SIZE) {
1889 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1890 priv->ndev->name, priv->tx_key, keylen);
1891 return -E2BIG;
1892 }
1893
1894 /* Write all 4 keys */
1895 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1896 err = hermes_write_ltv(hw, USER_BAP,
1897 HERMES_RID_CNFDEFAULTKEY0 + i,
1898 HERMES_BYTES_TO_RECLEN(keylen),
1899 priv->keys[i].data);
1900 if (err)
1901 return err;
1902 }
1903
1904 /* Write the index of the key used in transmission */
1905 err = hermes_write_wordrec(hw, USER_BAP,
1906 HERMES_RID_CNFWEPDEFAULTKEYID,
1907 priv->tx_key);
1908 if (err)
1909 return err;
1910 }
1911 break;
1912 }
1913
1914 return 0;
1915}
1916
1917static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1918{
1919 hermes_t *hw = &priv->hw;
1920 int err = 0;
1921 int master_wep_flag;
1922 int auth_flag;
1923
1924 if (priv->wep_on)
1925 __orinoco_hw_setup_wepkeys(priv);
1926
1927 if (priv->wep_restrict)
1928 auth_flag = HERMES_AUTH_SHARED_KEY;
1929 else
1930 auth_flag = HERMES_AUTH_OPEN;
1931
1932 switch (priv->firmware_type) {
1933 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1934 if (priv->wep_on) {
1935 /* Enable the shared-key authentication. */
1936 err = hermes_write_wordrec(hw, USER_BAP,
1937 HERMES_RID_CNFAUTHENTICATION_AGERE,
1938 auth_flag);
1939 }
1940 err = hermes_write_wordrec(hw, USER_BAP,
1941 HERMES_RID_CNFWEPENABLED_AGERE,
1942 priv->wep_on);
1943 if (err)
1944 return err;
1945 break;
1946
1947 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1948 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1949 if (priv->wep_on) {
1950 if (priv->wep_restrict ||
1951 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1952 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1953 HERMES_WEP_EXCL_UNENCRYPTED;
1954 else
1955 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1956
1957 err = hermes_write_wordrec(hw, USER_BAP,
1958 HERMES_RID_CNFAUTHENTICATION,
1959 auth_flag);
1960 if (err)
1961 return err;
1962 } else
1963 master_wep_flag = 0;
1964
1965 if (priv->iw_mode == IW_MODE_MONITOR)
1966 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1967
1968 /* Master WEP setting : on/off */
1969 err = hermes_write_wordrec(hw, USER_BAP,
1970 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1971 master_wep_flag);
1972 if (err)
1973 return err;
1974
1975 break;
1976 }
1977
1978 return 0;
1979}
1980
1981static int __orinoco_program_rids(struct net_device *dev)
1982{
1983 struct orinoco_private *priv = netdev_priv(dev);
1984 hermes_t *hw = &priv->hw;
1985 int err;
1986 struct hermes_idstring idbuf;
1987
1988 /* Set the MAC address */
1989 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1990 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1991 if (err) {
1992 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1993 dev->name, err);
1994 return err;
1995 }
1996
1997 /* Set up the link mode */
1998 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1999 priv->port_type);
2000 if (err) {
2001 printk(KERN_ERR "%s: Error %d setting port type\n",
2002 dev->name, err);
2003 return err;
2004 }
2005 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04002006 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2007 err = hermes_write_wordrec(hw, USER_BAP,
2008 HERMES_RID_CNFOWNCHANNEL,
2009 priv->channel);
2010 if (err) {
2011 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2012 dev->name, err, priv->channel);
2013 return err;
2014 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 }
2016
2017 if (priv->has_ibss) {
2018 u16 createibss;
2019
2020 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2021 printk(KERN_WARNING "%s: This firmware requires an "
2022 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2023 /* With wvlan_cs, in this case, we would crash.
2024 * hopefully, this driver will behave better...
2025 * Jean II */
2026 createibss = 0;
2027 } else {
2028 createibss = priv->createibss;
2029 }
2030
2031 err = hermes_write_wordrec(hw, USER_BAP,
2032 HERMES_RID_CNFCREATEIBSS,
2033 createibss);
2034 if (err) {
2035 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2036 dev->name, err);
2037 return err;
2038 }
2039 }
2040
Christoph Hellwig16739b02005-06-19 01:27:51 +02002041 /* Set the desired BSSID */
2042 err = __orinoco_hw_set_wap(priv);
2043 if (err) {
2044 printk(KERN_ERR "%s: Error %d setting AP address\n",
2045 dev->name, err);
2046 return err;
2047 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 /* Set the desired ESSID */
2049 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2050 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2051 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2052 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2053 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2054 &idbuf);
2055 if (err) {
2056 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2057 dev->name, err);
2058 return err;
2059 }
2060 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2061 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2062 &idbuf);
2063 if (err) {
2064 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2065 dev->name, err);
2066 return err;
2067 }
2068
2069 /* Set the station name */
2070 idbuf.len = cpu_to_le16(strlen(priv->nick));
2071 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2072 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2073 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2074 &idbuf);
2075 if (err) {
2076 printk(KERN_ERR "%s: Error %d setting nickname\n",
2077 dev->name, err);
2078 return err;
2079 }
2080
2081 /* Set AP density */
2082 if (priv->has_sensitivity) {
2083 err = hermes_write_wordrec(hw, USER_BAP,
2084 HERMES_RID_CNFSYSTEMSCALE,
2085 priv->ap_density);
2086 if (err) {
2087 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2088 "Disabling sensitivity control\n",
2089 dev->name, err);
2090
2091 priv->has_sensitivity = 0;
2092 }
2093 }
2094
2095 /* Set RTS threshold */
2096 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2097 priv->rts_thresh);
2098 if (err) {
2099 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2100 dev->name, err);
2101 return err;
2102 }
2103
2104 /* Set fragmentation threshold or MWO robustness */
2105 if (priv->has_mwo)
2106 err = hermes_write_wordrec(hw, USER_BAP,
2107 HERMES_RID_CNFMWOROBUST_AGERE,
2108 priv->mwo_robust);
2109 else
2110 err = hermes_write_wordrec(hw, USER_BAP,
2111 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2112 priv->frag_thresh);
2113 if (err) {
2114 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2115 dev->name, err);
2116 return err;
2117 }
2118
2119 /* Set bitrate */
2120 err = __orinoco_hw_set_bitrate(priv);
2121 if (err) {
2122 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2123 dev->name, err);
2124 return err;
2125 }
2126
2127 /* Set power management */
2128 if (priv->has_pm) {
2129 err = hermes_write_wordrec(hw, USER_BAP,
2130 HERMES_RID_CNFPMENABLED,
2131 priv->pm_on);
2132 if (err) {
2133 printk(KERN_ERR "%s: Error %d setting up PM\n",
2134 dev->name, err);
2135 return err;
2136 }
2137
2138 err = hermes_write_wordrec(hw, USER_BAP,
2139 HERMES_RID_CNFMULTICASTRECEIVE,
2140 priv->pm_mcast);
2141 if (err) {
2142 printk(KERN_ERR "%s: Error %d setting up PM\n",
2143 dev->name, err);
2144 return err;
2145 }
2146 err = hermes_write_wordrec(hw, USER_BAP,
2147 HERMES_RID_CNFMAXSLEEPDURATION,
2148 priv->pm_period);
2149 if (err) {
2150 printk(KERN_ERR "%s: Error %d setting up PM\n",
2151 dev->name, err);
2152 return err;
2153 }
2154 err = hermes_write_wordrec(hw, USER_BAP,
2155 HERMES_RID_CNFPMHOLDOVERDURATION,
2156 priv->pm_timeout);
2157 if (err) {
2158 printk(KERN_ERR "%s: Error %d setting up PM\n",
2159 dev->name, err);
2160 return err;
2161 }
2162 }
2163
2164 /* Set preamble - only for Symbol so far... */
2165 if (priv->has_preamble) {
2166 err = hermes_write_wordrec(hw, USER_BAP,
2167 HERMES_RID_CNFPREAMBLE_SYMBOL,
2168 priv->preamble);
2169 if (err) {
2170 printk(KERN_ERR "%s: Error %d setting preamble\n",
2171 dev->name, err);
2172 return err;
2173 }
2174 }
2175
2176 /* Set up encryption */
2177 if (priv->has_wep) {
2178 err = __orinoco_hw_setup_wep(priv);
2179 if (err) {
2180 printk(KERN_ERR "%s: Error %d activating WEP\n",
2181 dev->name, err);
2182 return err;
2183 }
2184 }
2185
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002186 if (priv->iw_mode == IW_MODE_MONITOR) {
2187 /* Enable monitor mode */
2188 dev->type = ARPHRD_IEEE80211;
2189 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2190 HERMES_TEST_MONITOR, 0, NULL);
2191 } else {
2192 /* Disable monitor mode */
2193 dev->type = ARPHRD_ETHER;
2194 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2195 HERMES_TEST_STOP, 0, NULL);
2196 }
2197 if (err)
2198 return err;
2199
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 /* Set promiscuity / multicast*/
2201 priv->promiscuous = 0;
2202 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07002203
2204 /* FIXME: what about netif_tx_lock */
2205 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
2207 return 0;
2208}
2209
2210/* FIXME: return int? */
2211static void
2212__orinoco_set_multicast_list(struct net_device *dev)
2213{
2214 struct orinoco_private *priv = netdev_priv(dev);
2215 hermes_t *hw = &priv->hw;
2216 int err = 0;
2217 int promisc, mc_count;
2218
2219 /* The Hermes doesn't seem to have an allmulti mode, so we go
2220 * into promiscuous mode and let the upper levels deal. */
2221 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2222 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2223 promisc = 1;
2224 mc_count = 0;
2225 } else {
2226 promisc = 0;
2227 mc_count = dev->mc_count;
2228 }
2229
2230 if (promisc != priv->promiscuous) {
2231 err = hermes_write_wordrec(hw, USER_BAP,
2232 HERMES_RID_CNFPROMISCUOUSMODE,
2233 promisc);
2234 if (err) {
2235 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2236 dev->name, err);
2237 } else
2238 priv->promiscuous = promisc;
2239 }
2240
2241 if (! promisc && (mc_count || priv->mc_count) ) {
2242 struct dev_mc_list *p = dev->mc_list;
2243 struct hermes_multicast mclist;
2244 int i;
2245
2246 for (i = 0; i < mc_count; i++) {
2247 /* paranoia: is list shorter than mc_count? */
2248 BUG_ON(! p);
2249 /* paranoia: bad address size in list? */
2250 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2251
2252 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2253 p = p->next;
2254 }
2255
2256 if (p)
2257 printk(KERN_WARNING "%s: Multicast list is "
2258 "longer than mc_count\n", dev->name);
2259
2260 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2261 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2262 &mclist);
2263 if (err)
2264 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2265 dev->name, err);
2266 else
2267 priv->mc_count = mc_count;
2268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269}
2270
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271/* This must be called from user context, without locks held - use
2272 * schedule_work() */
David Howellsc4028952006-11-22 14:57:56 +00002273static void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274{
David Howellsc4028952006-11-22 14:57:56 +00002275 struct orinoco_private *priv =
2276 container_of(work, struct orinoco_private, reset_work);
2277 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002279 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 unsigned long flags;
2281
2282 if (orinoco_lock(priv, &flags) != 0)
2283 /* When the hardware becomes available again, whatever
2284 * detects that is responsible for re-initializing
2285 * it. So no need for anything further */
2286 return;
2287
2288 netif_stop_queue(dev);
2289
2290 /* Shut off interrupts. Depending on what state the hardware
2291 * is in, this might not work, but we'll try anyway */
2292 hermes_set_irqmask(hw, 0);
2293 hermes_write_regn(hw, EVACK, 0xffff);
2294
2295 priv->hw_unavailable++;
2296 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2297 netif_carrier_off(dev);
2298
2299 orinoco_unlock(priv, &flags);
2300
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002301 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04002302 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002303 priv->scan_inprogress = 0;
2304
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002305 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002307 if (err) {
2308 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2309 "performing hard reset\n", dev->name, err);
2310 goto disable;
2311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313
David Kilroy3994d502008-08-21 23:27:54 +01002314 if (priv->do_fw_download) {
2315 err = orinoco_download(priv);
2316 if (err)
2317 priv->do_fw_download = 0;
2318 }
2319
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 err = orinoco_reinit_firmware(dev);
2321 if (err) {
2322 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2323 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002324 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
2326
2327 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2328
2329 priv->hw_unavailable--;
2330
2331 /* priv->open or priv->hw_unavailable might have changed while
2332 * we dropped the lock */
2333 if (priv->open && (! priv->hw_unavailable)) {
2334 err = __orinoco_up(dev);
2335 if (err) {
2336 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2337 dev->name, err);
2338 } else
2339 dev->trans_start = jiffies;
2340 }
2341
2342 spin_unlock_irq(&priv->lock);
2343
2344 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002345 disable:
2346 hermes_set_irqmask(hw, 0);
2347 netif_device_detach(dev);
2348 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349}
2350
2351/********************************************************************/
2352/* Interrupt handler */
2353/********************************************************************/
2354
2355static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2356{
2357 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2358}
2359
2360static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2361{
2362 /* This seems to happen a fair bit under load, but ignoring it
2363 seems to work fine...*/
2364 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2365 dev->name);
2366}
2367
David Howells7d12e782006-10-05 14:55:46 +01002368irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04002370 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 struct orinoco_private *priv = netdev_priv(dev);
2372 hermes_t *hw = &priv->hw;
2373 int count = MAX_IRQLOOPS_PER_IRQ;
2374 u16 evstat, events;
2375 /* These are used to detect a runaway interrupt situation */
2376 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2377 * we panic and shut down the hardware */
2378 static int last_irq_jiffy = 0; /* jiffies value the last time
2379 * we were called */
2380 static int loops_this_jiffy = 0;
2381 unsigned long flags;
2382
2383 if (orinoco_lock(priv, &flags) != 0) {
2384 /* If hw is unavailable - we don't know if the irq was
2385 * for us or not */
2386 return IRQ_HANDLED;
2387 }
2388
2389 evstat = hermes_read_regn(hw, EVSTAT);
2390 events = evstat & hw->inten;
2391 if (! events) {
2392 orinoco_unlock(priv, &flags);
2393 return IRQ_NONE;
2394 }
2395
2396 if (jiffies != last_irq_jiffy)
2397 loops_this_jiffy = 0;
2398 last_irq_jiffy = jiffies;
2399
2400 while (events && count--) {
2401 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2402 printk(KERN_WARNING "%s: IRQ handler is looping too "
2403 "much! Resetting.\n", dev->name);
2404 /* Disable interrupts for now */
2405 hermes_set_irqmask(hw, 0);
2406 schedule_work(&priv->reset_work);
2407 break;
2408 }
2409
2410 /* Check the card hasn't been removed */
2411 if (! hermes_present(hw)) {
2412 DEBUG(0, "orinoco_interrupt(): card removed\n");
2413 break;
2414 }
2415
2416 if (events & HERMES_EV_TICK)
2417 __orinoco_ev_tick(dev, hw);
2418 if (events & HERMES_EV_WTERR)
2419 __orinoco_ev_wterr(dev, hw);
2420 if (events & HERMES_EV_INFDROP)
2421 __orinoco_ev_infdrop(dev, hw);
2422 if (events & HERMES_EV_INFO)
2423 __orinoco_ev_info(dev, hw);
2424 if (events & HERMES_EV_RX)
2425 __orinoco_ev_rx(dev, hw);
2426 if (events & HERMES_EV_TXEXC)
2427 __orinoco_ev_txexc(dev, hw);
2428 if (events & HERMES_EV_TX)
2429 __orinoco_ev_tx(dev, hw);
2430 if (events & HERMES_EV_ALLOC)
2431 __orinoco_ev_alloc(dev, hw);
2432
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002433 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 evstat = hermes_read_regn(hw, EVSTAT);
2436 events = evstat & hw->inten;
2437 };
2438
2439 orinoco_unlock(priv, &flags);
2440 return IRQ_HANDLED;
2441}
2442
2443/********************************************************************/
2444/* Initialization */
2445/********************************************************************/
2446
2447struct comp_id {
2448 u16 id, variant, major, minor;
2449} __attribute__ ((packed));
2450
2451static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2452{
2453 if (nic_id->id < 0x8000)
2454 return FIRMWARE_TYPE_AGERE;
2455 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2456 return FIRMWARE_TYPE_SYMBOL;
2457 else
2458 return FIRMWARE_TYPE_INTERSIL;
2459}
2460
2461/* Set priv->firmware type, determine firmware properties */
2462static int determine_firmware(struct net_device *dev)
2463{
2464 struct orinoco_private *priv = netdev_priv(dev);
2465 hermes_t *hw = &priv->hw;
2466 int err;
2467 struct comp_id nic_id, sta_id;
2468 unsigned int firmver;
Hennerich, Michaeldde6d432007-02-05 16:41:35 -08002469 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 /* Get the hardware version */
2472 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2473 if (err) {
2474 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2475 dev->name, err);
2476 return err;
2477 }
2478
2479 le16_to_cpus(&nic_id.id);
2480 le16_to_cpus(&nic_id.variant);
2481 le16_to_cpus(&nic_id.major);
2482 le16_to_cpus(&nic_id.minor);
2483 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2484 dev->name, nic_id.id, nic_id.variant,
2485 nic_id.major, nic_id.minor);
2486
2487 priv->firmware_type = determine_firmware_type(&nic_id);
2488
2489 /* Get the firmware version */
2490 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2491 if (err) {
2492 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2493 dev->name, err);
2494 return err;
2495 }
2496
2497 le16_to_cpus(&sta_id.id);
2498 le16_to_cpus(&sta_id.variant);
2499 le16_to_cpus(&sta_id.major);
2500 le16_to_cpus(&sta_id.minor);
2501 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2502 dev->name, sta_id.id, sta_id.variant,
2503 sta_id.major, sta_id.minor);
2504
2505 switch (sta_id.id) {
2506 case 0x15:
2507 printk(KERN_ERR "%s: Primary firmware is active\n",
2508 dev->name);
2509 return -ENODEV;
2510 case 0x14b:
2511 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2512 dev->name);
2513 return -ENODEV;
2514 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2515 case 0x21: /* Symbol Spectrum24 Trilogy */
2516 break;
2517 default:
2518 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2519 dev->name);
2520 break;
2521 }
2522
2523 /* Default capabilities */
2524 priv->has_sensitivity = 1;
2525 priv->has_mwo = 0;
2526 priv->has_preamble = 0;
2527 priv->has_port3 = 1;
2528 priv->has_ibss = 1;
2529 priv->has_wep = 0;
2530 priv->has_big_wep = 0;
David Kilroy3994d502008-08-21 23:27:54 +01002531 priv->do_fw_download = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
2533 /* Determine capabilities from the firmware version */
2534 switch (priv->firmware_type) {
2535 case FIRMWARE_TYPE_AGERE:
2536 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2537 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2538 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2539 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2540
2541 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2542
2543 priv->has_ibss = (firmver >= 0x60006);
2544 priv->has_wep = (firmver >= 0x40020);
2545 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2546 Gold cards from the others? */
2547 priv->has_mwo = (firmver >= 0x60000);
2548 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2549 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002550 priv->has_hostscan = (firmver >= 0x8000a);
David Kilroy3994d502008-08-21 23:27:54 +01002551 priv->do_fw_download = 1;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002552 priv->broken_monitor = (firmver >= 0x80000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553
2554 /* Tested with Agere firmware :
2555 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2556 * Tested CableTron firmware : 4.32 => Anton */
2557 break;
2558 case FIRMWARE_TYPE_SYMBOL:
2559 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2560 /* Intel MAC : 00:02:B3:* */
2561 /* 3Com MAC : 00:50:DA:* */
2562 memset(tmp, 0, sizeof(tmp));
2563 /* Get the Symbol firmware version */
2564 err = hermes_read_ltv(hw, USER_BAP,
2565 HERMES_RID_SECONDARYVERSION_SYMBOL,
2566 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2567 if (err) {
2568 printk(KERN_WARNING
2569 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2570 dev->name, err);
2571 firmver = 0;
2572 tmp[0] = '\0';
2573 } else {
2574 /* The firmware revision is a string, the format is
2575 * something like : "V2.20-01".
2576 * Quick and dirty parsing... - Jean II
2577 */
2578 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2579 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2580 | (tmp[7] - '0');
2581
2582 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2583 }
2584
2585 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2586 "Symbol %s", tmp);
2587
2588 priv->has_ibss = (firmver >= 0x20000);
2589 priv->has_wep = (firmver >= 0x15012);
2590 priv->has_big_wep = (firmver >= 0x20000);
2591 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2592 (firmver >= 0x29000 && firmver < 0x30000) ||
2593 firmver >= 0x31000;
2594 priv->has_preamble = (firmver >= 0x20000);
2595 priv->ibss_port = 4;
David Kilroy3994d502008-08-21 23:27:54 +01002596
2597 /* Symbol firmware is found on various cards, but
2598 * there has been no attempt to check firmware
2599 * download on non-spectrum_cs based cards.
2600 *
2601 * Given that the Agere firmware download works
2602 * differently, we should avoid doing a firmware
2603 * download with the Symbol algorithm on non-spectrum
2604 * cards.
2605 *
2606 * For now we can identify a spectrum_cs based card
2607 * because it has a firmware reset function.
2608 */
2609 priv->do_fw_download = (priv->stop_fw != NULL);
2610
Christoph Hellwig649e59e2005-05-14 17:30:10 +02002611 priv->broken_disableport = (firmver == 0x25013) ||
2612 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002613 priv->has_hostscan = (firmver >= 0x31001) ||
2614 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 /* Tested with Intel firmware : 0x20015 => Jean II */
2616 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2617 break;
2618 case FIRMWARE_TYPE_INTERSIL:
2619 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2620 * Samsung, Compaq 100/200 and Proxim are slightly
2621 * different and less well tested */
2622 /* D-Link MAC : 00:40:05:* */
2623 /* Addtron MAC : 00:90:D1:* */
2624 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2625 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2626 sta_id.variant);
2627
2628 firmver = ((unsigned long)sta_id.major << 16) |
2629 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2630
2631 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2632 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2633 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002634 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 if (firmver >= 0x000800)
2637 priv->ibss_port = 0;
2638 else {
2639 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2640 "than v0.8.x - several features not supported\n",
2641 dev->name);
2642 priv->ibss_port = 1;
2643 }
2644 break;
2645 }
2646 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2647 priv->fw_name);
2648
2649 return 0;
2650}
2651
2652static int orinoco_init(struct net_device *dev)
2653{
2654 struct orinoco_private *priv = netdev_priv(dev);
2655 hermes_t *hw = &priv->hw;
2656 int err = 0;
2657 struct hermes_idstring nickbuf;
2658 u16 reclen;
2659 int len;
Joe Perches0795af52007-10-03 17:59:30 -07002660 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 /* No need to lock, the hw_unavailable flag is already set in
2663 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04002664 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04002667 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if (err != 0) {
2669 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2670 dev->name, err);
2671 goto out;
2672 }
2673
2674 err = determine_firmware(dev);
2675 if (err != 0) {
2676 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2677 dev->name);
2678 goto out;
2679 }
2680
David Kilroy3994d502008-08-21 23:27:54 +01002681 if (priv->do_fw_download) {
2682 err = orinoco_download(priv);
2683 if (err)
2684 priv->do_fw_download = 0;
2685
2686 /* Check firmware version again */
2687 err = determine_firmware(dev);
2688 if (err != 0) {
2689 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2690 dev->name);
2691 goto out;
2692 }
2693 }
2694
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 if (priv->has_port3)
2696 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2697 if (priv->has_ibss)
2698 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2699 dev->name);
2700 if (priv->has_wep) {
2701 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2702 if (priv->has_big_wep)
2703 printk("104-bit key\n");
2704 else
2705 printk("40-bit key\n");
2706 }
2707
2708 /* Get the MAC address */
2709 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2710 ETH_ALEN, NULL, dev->dev_addr);
2711 if (err) {
2712 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2713 dev->name);
2714 goto out;
2715 }
2716
Joe Perches0795af52007-10-03 17:59:30 -07002717 printk(KERN_DEBUG "%s: MAC address %s\n",
2718 dev->name, print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 /* Get the station name */
2721 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2722 sizeof(nickbuf), &reclen, &nickbuf);
2723 if (err) {
2724 printk(KERN_ERR "%s: failed to read station name\n",
2725 dev->name);
2726 goto out;
2727 }
2728 if (nickbuf.len)
2729 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2730 else
2731 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2732 memcpy(priv->nick, &nickbuf.val, len);
2733 priv->nick[len] = '\0';
2734
2735 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2736
Pavel Roskin37a6c612006-04-07 04:10:49 -04002737 err = orinoco_allocate_fid(dev);
2738 if (err) {
2739 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2740 dev->name);
2741 goto out;
2742 }
2743
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 /* Get allowed channels */
2745 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2746 &priv->channel_mask);
2747 if (err) {
2748 printk(KERN_ERR "%s: failed to read channel list!\n",
2749 dev->name);
2750 goto out;
2751 }
2752
2753 /* Get initial AP density */
2754 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2755 &priv->ap_density);
2756 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2757 priv->has_sensitivity = 0;
2758 }
2759
2760 /* Get initial RTS threshold */
2761 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2762 &priv->rts_thresh);
2763 if (err) {
2764 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2765 dev->name);
2766 goto out;
2767 }
2768
2769 /* Get initial fragmentation settings */
2770 if (priv->has_mwo)
2771 err = hermes_read_wordrec(hw, USER_BAP,
2772 HERMES_RID_CNFMWOROBUST_AGERE,
2773 &priv->mwo_robust);
2774 else
2775 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2776 &priv->frag_thresh);
2777 if (err) {
2778 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2779 dev->name);
2780 goto out;
2781 }
2782
2783 /* Power management setup */
2784 if (priv->has_pm) {
2785 priv->pm_on = 0;
2786 priv->pm_mcast = 1;
2787 err = hermes_read_wordrec(hw, USER_BAP,
2788 HERMES_RID_CNFMAXSLEEPDURATION,
2789 &priv->pm_period);
2790 if (err) {
2791 printk(KERN_ERR "%s: failed to read power management period!\n",
2792 dev->name);
2793 goto out;
2794 }
2795 err = hermes_read_wordrec(hw, USER_BAP,
2796 HERMES_RID_CNFPMHOLDOVERDURATION,
2797 &priv->pm_timeout);
2798 if (err) {
2799 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2800 dev->name);
2801 goto out;
2802 }
2803 }
2804
2805 /* Preamble setup */
2806 if (priv->has_preamble) {
2807 err = hermes_read_wordrec(hw, USER_BAP,
2808 HERMES_RID_CNFPREAMBLE_SYMBOL,
2809 &priv->preamble);
2810 if (err)
2811 goto out;
2812 }
2813
2814 /* Set up the default configuration */
2815 priv->iw_mode = IW_MODE_INFRA;
2816 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2817 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2818 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002819 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
2821 priv->promiscuous = 0;
2822 priv->wep_on = 0;
2823 priv->tx_key = 0;
2824
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 /* Make the hardware available, as long as it hasn't been
2826 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2827 spin_lock_irq(&priv->lock);
2828 priv->hw_unavailable--;
2829 spin_unlock_irq(&priv->lock);
2830
2831 printk(KERN_DEBUG "%s: ready\n", dev->name);
2832
2833 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 return err;
2835}
2836
David Kilroy3994d502008-08-21 23:27:54 +01002837struct net_device
2838*alloc_orinocodev(int sizeof_card,
2839 struct device *device,
2840 int (*hard_reset)(struct orinoco_private *),
2841 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842{
2843 struct net_device *dev;
2844 struct orinoco_private *priv;
2845
2846 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2847 if (! dev)
2848 return NULL;
2849 priv = netdev_priv(dev);
2850 priv->ndev = dev;
2851 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002852 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 + sizeof(struct orinoco_private));
2854 else
2855 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01002856 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Dan Williams1e3428e2007-10-10 23:56:25 -04002858 if (orinoco_bss_data_allocate(priv))
2859 goto err_out_free;
2860 orinoco_bss_data_init(priv);
2861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 /* Setup / override net_device fields */
2863 dev->init = orinoco_init;
2864 dev->hard_start_xmit = orinoco_xmit;
2865 dev->tx_timeout = orinoco_tx_timeout;
2866 dev->watchdog_timeo = HZ; /* 1 second timeout */
2867 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002868 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002869 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002870#ifdef WIRELESS_SPY
2871 priv->wireless_data.spy_data = &priv->spy_data;
2872 dev->wireless_data = &priv->wireless_data;
2873#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 dev->change_mtu = orinoco_change_mtu;
2875 dev->set_multicast_list = orinoco_set_multicast_list;
2876 /* we use the default eth_mac_addr for setting the MAC addr */
2877
2878 /* Set up default callbacks */
2879 dev->open = orinoco_open;
2880 dev->stop = orinoco_stop;
2881 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01002882 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
2884 spin_lock_init(&priv->lock);
2885 priv->open = 0;
2886 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2887 * before anything else touches the
2888 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00002889 INIT_WORK(&priv->reset_work, orinoco_reset);
2890 INIT_WORK(&priv->join_work, orinoco_join_ap);
2891 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892
2893 netif_carrier_off(dev);
2894 priv->last_linkstatus = 0xffff;
2895
2896 return dev;
2897
Dan Williams1e3428e2007-10-10 23:56:25 -04002898err_out_free:
2899 free_netdev(dev);
2900 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901}
2902
2903void free_orinocodev(struct net_device *dev)
2904{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002905 struct orinoco_private *priv = netdev_priv(dev);
2906
Dan Williams1e3428e2007-10-10 23:56:25 -04002907 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 free_netdev(dev);
2909}
2910
2911/********************************************************************/
2912/* Wireless extensions */
2913/********************************************************************/
2914
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002915/* Return : < 0 -> error code ; >= 0 -> length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2917 char buf[IW_ESSID_MAX_SIZE+1])
2918{
2919 hermes_t *hw = &priv->hw;
2920 int err = 0;
2921 struct hermes_idstring essidbuf;
2922 char *p = (char *)(&essidbuf.val);
2923 int len;
2924 unsigned long flags;
2925
2926 if (orinoco_lock(priv, &flags) != 0)
2927 return -EBUSY;
2928
2929 if (strlen(priv->desired_essid) > 0) {
2930 /* We read the desired SSID from the hardware rather
2931 than from priv->desired_essid, just in case the
2932 firmware is allowed to change it on us. I'm not
2933 sure about this */
2934 /* My guess is that the OWNSSID should always be whatever
2935 * we set to the card, whereas CURRENT_SSID is the one that
2936 * may change... - Jean II */
2937 u16 rid;
2938
2939 *active = 1;
2940
2941 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2942 HERMES_RID_CNFDESIREDSSID;
2943
2944 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2945 NULL, &essidbuf);
2946 if (err)
2947 goto fail_unlock;
2948 } else {
2949 *active = 0;
2950
2951 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2952 sizeof(essidbuf), NULL, &essidbuf);
2953 if (err)
2954 goto fail_unlock;
2955 }
2956
2957 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002958 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002960 memset(buf, 0, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 memcpy(buf, p, len);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002962 err = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963
2964 fail_unlock:
2965 orinoco_unlock(priv, &flags);
2966
2967 return err;
2968}
2969
2970static long orinoco_hw_get_freq(struct orinoco_private *priv)
2971{
2972
2973 hermes_t *hw = &priv->hw;
2974 int err = 0;
2975 u16 channel;
2976 long freq = 0;
2977 unsigned long flags;
2978
2979 if (orinoco_lock(priv, &flags) != 0)
2980 return -EBUSY;
2981
2982 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2983 if (err)
2984 goto out;
2985
2986 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2987 if (channel == 0) {
2988 err = -EBUSY;
2989 goto out;
2990 }
2991
2992 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2993 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2994 priv->ndev->name, channel);
2995 err = -EBUSY;
2996 goto out;
2997
2998 }
2999 freq = channel_frequency[channel-1] * 100000;
3000
3001 out:
3002 orinoco_unlock(priv, &flags);
3003
3004 if (err > 0)
3005 err = -EBUSY;
3006 return err ? err : freq;
3007}
3008
3009static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3010 int *numrates, s32 *rates, int max)
3011{
3012 hermes_t *hw = &priv->hw;
3013 struct hermes_idstring list;
3014 unsigned char *p = (unsigned char *)&list.val;
3015 int err = 0;
3016 int num;
3017 int i;
3018 unsigned long flags;
3019
3020 if (orinoco_lock(priv, &flags) != 0)
3021 return -EBUSY;
3022
3023 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3024 sizeof(list), NULL, &list);
3025 orinoco_unlock(priv, &flags);
3026
3027 if (err)
3028 return err;
3029
3030 num = le16_to_cpu(list.len);
3031 *numrates = num;
3032 num = min(num, max);
3033
3034 for (i = 0; i < num; i++) {
3035 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3036 }
3037
3038 return 0;
3039}
3040
Christoph Hellwig620554e2005-06-19 01:27:33 +02003041static int orinoco_ioctl_getname(struct net_device *dev,
3042 struct iw_request_info *info,
3043 char *name,
3044 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045{
3046 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003048 int err;
3049
3050 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3051
3052 if (!err && (numrates > 2))
3053 strcpy(name, "IEEE 802.11b");
3054 else
3055 strcpy(name, "IEEE 802.11-DS");
3056
3057 return 0;
3058}
3059
Christoph Hellwig16739b02005-06-19 01:27:51 +02003060static int orinoco_ioctl_setwap(struct net_device *dev,
3061 struct iw_request_info *info,
3062 struct sockaddr *ap_addr,
3063 char *extra)
3064{
3065 struct orinoco_private *priv = netdev_priv(dev);
3066 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02003068 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3069 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
3071 if (orinoco_lock(priv, &flags) != 0)
3072 return -EBUSY;
3073
Christoph Hellwig16739b02005-06-19 01:27:51 +02003074 /* Enable automatic roaming - no sanity checks are needed */
3075 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3076 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3077 priv->bssid_fixed = 0;
3078 memset(priv->desired_bssid, 0, ETH_ALEN);
3079
3080 /* "off" means keep existing connection */
3081 if (ap_addr->sa_data[0] == 0) {
3082 __orinoco_hw_set_wap(priv);
3083 err = 0;
3084 }
3085 goto out;
3086 }
3087
3088 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3089 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3090 "support manual roaming\n",
3091 dev->name);
3092 err = -EOPNOTSUPP;
3093 goto out;
3094 }
3095
3096 if (priv->iw_mode != IW_MODE_INFRA) {
3097 printk(KERN_WARNING "%s: Manual roaming supported only in "
3098 "managed mode\n", dev->name);
3099 err = -EOPNOTSUPP;
3100 goto out;
3101 }
3102
3103 /* Intersil firmware hangs without Desired ESSID */
3104 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3105 strlen(priv->desired_essid) == 0) {
3106 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3107 "manual roaming\n", dev->name);
3108 err = -EOPNOTSUPP;
3109 goto out;
3110 }
3111
3112 /* Finally, enable manual roaming */
3113 priv->bssid_fixed = 1;
3114 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3115
3116 out:
3117 orinoco_unlock(priv, &flags);
3118 return err;
3119}
3120
Christoph Hellwig620554e2005-06-19 01:27:33 +02003121static int orinoco_ioctl_getwap(struct net_device *dev,
3122 struct iw_request_info *info,
3123 struct sockaddr *ap_addr,
3124 char *extra)
3125{
3126 struct orinoco_private *priv = netdev_priv(dev);
3127
3128 hermes_t *hw = &priv->hw;
3129 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 unsigned long flags;
3131
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132 if (orinoco_lock(priv, &flags) != 0)
3133 return -EBUSY;
3134
Christoph Hellwig620554e2005-06-19 01:27:33 +02003135 ap_addr->sa_family = ARPHRD_ETHER;
3136 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3137 ETH_ALEN, NULL, ap_addr->sa_data);
3138
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 orinoco_unlock(priv, &flags);
3140
Christoph Hellwig620554e2005-06-19 01:27:33 +02003141 return err;
3142}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143
Christoph Hellwig620554e2005-06-19 01:27:33 +02003144static int orinoco_ioctl_setmode(struct net_device *dev,
3145 struct iw_request_info *info,
3146 u32 *mode,
3147 char *extra)
3148{
3149 struct orinoco_private *priv = netdev_priv(dev);
3150 int err = -EINPROGRESS; /* Call commit handler */
3151 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
Christoph Hellwig620554e2005-06-19 01:27:33 +02003153 if (priv->iw_mode == *mode)
3154 return 0;
3155
3156 if (orinoco_lock(priv, &flags) != 0)
3157 return -EBUSY;
3158
3159 switch (*mode) {
3160 case IW_MODE_ADHOC:
3161 if (!priv->has_ibss && !priv->has_port3)
3162 err = -EOPNOTSUPP;
3163 break;
3164
3165 case IW_MODE_INFRA:
3166 break;
3167
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003168 case IW_MODE_MONITOR:
3169 if (priv->broken_monitor && !force_monitor) {
3170 printk(KERN_WARNING "%s: Monitor mode support is "
3171 "buggy in this firmware, not enabling\n",
3172 dev->name);
3173 err = -EOPNOTSUPP;
3174 }
3175 break;
3176
Christoph Hellwig620554e2005-06-19 01:27:33 +02003177 default:
3178 err = -EOPNOTSUPP;
3179 break;
3180 }
3181
3182 if (err == -EINPROGRESS) {
3183 priv->iw_mode = *mode;
3184 set_port_type(priv);
3185 }
3186
3187 orinoco_unlock(priv, &flags);
3188
3189 return err;
3190}
3191
3192static int orinoco_ioctl_getmode(struct net_device *dev,
3193 struct iw_request_info *info,
3194 u32 *mode,
3195 char *extra)
3196{
3197 struct orinoco_private *priv = netdev_priv(dev);
3198
3199 *mode = priv->iw_mode;
3200 return 0;
3201}
3202
3203static int orinoco_ioctl_getiwrange(struct net_device *dev,
3204 struct iw_request_info *info,
3205 struct iw_point *rrq,
3206 char *extra)
3207{
3208 struct orinoco_private *priv = netdev_priv(dev);
3209 int err = 0;
3210 struct iw_range *range = (struct iw_range *) extra;
3211 int numrates;
3212 int i, k;
3213
Christoph Hellwig620554e2005-06-19 01:27:33 +02003214 rrq->length = sizeof(struct iw_range);
3215 memset(range, 0, sizeof(struct iw_range));
3216
3217 range->we_version_compiled = WIRELESS_EXT;
3218 range->we_version_source = 14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219
3220 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003221 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222 k = 0;
3223 for (i = 0; i < NUM_CHANNELS; i++) {
3224 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003225 range->freq[k].i = i + 1;
3226 range->freq[k].m = channel_frequency[i] * 100000;
3227 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 k++;
3229 }
3230
3231 if (k >= IW_MAX_FREQUENCIES)
3232 break;
3233 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02003234 range->num_frequency = k;
3235 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
Christoph Hellwig620554e2005-06-19 01:27:33 +02003237 if (priv->has_wep) {
3238 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3239 range->encoding_size[0] = SMALL_KEY_SIZE;
3240 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Christoph Hellwig620554e2005-06-19 01:27:33 +02003242 if (priv->has_big_wep) {
3243 range->encoding_size[1] = LARGE_KEY_SIZE;
3244 range->num_encoding_sizes = 2;
3245 }
3246 }
3247
Pavel Roskin343c6862005-09-09 18:43:02 -04003248 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003251 range->max_qual.qual = 0x8b - 0x2f;
3252 range->max_qual.level = 0x2f - 0x95 - 1;
3253 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003255 range->avg_qual.qual = 0x24;
3256 range->avg_qual.level = 0xC2;
3257 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 }
3259
3260 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02003261 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 if (err)
3263 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003264 range->num_bitrates = numrates;
3265
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 /* Set an indication of the max TCP throughput in bit/s that we can
3267 * expect using this interface. May be use for QoS stuff...
3268 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003269 if (numrates > 2)
3270 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02003272 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
Christoph Hellwig620554e2005-06-19 01:27:33 +02003274 range->min_rts = 0;
3275 range->max_rts = 2347;
3276 range->min_frag = 256;
3277 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
Christoph Hellwig620554e2005-06-19 01:27:33 +02003279 range->min_pmp = 0;
3280 range->max_pmp = 65535000;
3281 range->min_pmt = 0;
3282 range->max_pmt = 65535 * 1000; /* ??? */
3283 range->pmp_flags = IW_POWER_PERIOD;
3284 range->pmt_flags = IW_POWER_TIMEOUT;
3285 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286
Christoph Hellwig620554e2005-06-19 01:27:33 +02003287 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3288 range->retry_flags = IW_RETRY_LIMIT;
3289 range->r_time_flags = IW_RETRY_LIFETIME;
3290 range->min_retry = 0;
3291 range->max_retry = 65535; /* ??? */
3292 range->min_r_time = 0;
3293 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294
David Kilroy0753bba2008-08-21 23:27:46 +01003295 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3296 range->scan_capa = IW_SCAN_CAPA_ESSID;
3297 else
3298 range->scan_capa = IW_SCAN_CAPA_NONE;
3299
Pavel Roskin343c6862005-09-09 18:43:02 -04003300 /* Event capability (kernel) */
3301 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3302 /* Event capability (driver) */
3303 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3304 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3305 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3306 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3307
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308 return 0;
3309}
3310
Christoph Hellwig620554e2005-06-19 01:27:33 +02003311static int orinoco_ioctl_setiwencode(struct net_device *dev,
3312 struct iw_request_info *info,
3313 struct iw_point *erq,
3314 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315{
3316 struct orinoco_private *priv = netdev_priv(dev);
3317 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3318 int setindex = priv->tx_key;
3319 int enable = priv->wep_on;
3320 int restricted = priv->wep_restrict;
3321 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003322 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323 unsigned long flags;
3324
3325 if (! priv->has_wep)
3326 return -EOPNOTSUPP;
3327
3328 if (erq->pointer) {
3329 /* We actually have a key to set - check its length */
3330 if (erq->length > LARGE_KEY_SIZE)
3331 return -E2BIG;
3332
3333 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3334 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 }
3336
3337 if (orinoco_lock(priv, &flags) != 0)
3338 return -EBUSY;
3339
Dan Williamsfe397d42006-07-14 11:41:47 -04003340 if (erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3342 index = priv->tx_key;
3343
3344 /* Adjust key length to a supported value */
3345 if (erq->length > SMALL_KEY_SIZE) {
3346 xlen = LARGE_KEY_SIZE;
3347 } else if (erq->length > 0) {
3348 xlen = SMALL_KEY_SIZE;
3349 } else
3350 xlen = 0;
3351
3352 /* Switch on WEP if off */
3353 if ((!enable) && (xlen > 0)) {
3354 setindex = index;
3355 enable = 1;
3356 }
3357 } else {
3358 /* Important note : if the user do "iwconfig eth0 enc off",
3359 * we will arrive there with an index of -1. This is valid
3360 * but need to be taken care off... Jean II */
3361 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3362 if((index != -1) || (erq->flags == 0)) {
3363 err = -EINVAL;
3364 goto out;
3365 }
3366 } else {
3367 /* Set the index : Check that the key is valid */
3368 if(priv->keys[index].len == 0) {
3369 err = -EINVAL;
3370 goto out;
3371 }
3372 setindex = index;
3373 }
3374 }
3375
3376 if (erq->flags & IW_ENCODE_DISABLED)
3377 enable = 0;
3378 if (erq->flags & IW_ENCODE_OPEN)
3379 restricted = 0;
3380 if (erq->flags & IW_ENCODE_RESTRICTED)
3381 restricted = 1;
3382
Dan Williamsfe397d42006-07-14 11:41:47 -04003383 if (erq->pointer && erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 priv->keys[index].len = cpu_to_le16(xlen);
3385 memset(priv->keys[index].data, 0,
3386 sizeof(priv->keys[index].data));
3387 memcpy(priv->keys[index].data, keybuf, erq->length);
3388 }
3389 priv->tx_key = setindex;
3390
3391 /* Try fast key change if connected and only keys are changed */
3392 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
3393 netif_carrier_ok(dev)) {
3394 err = __orinoco_hw_setup_wepkeys(priv);
3395 /* No need to commit if successful */
3396 goto out;
3397 }
3398
3399 priv->wep_on = enable;
3400 priv->wep_restrict = restricted;
3401
3402 out:
3403 orinoco_unlock(priv, &flags);
3404
3405 return err;
3406}
3407
Christoph Hellwig620554e2005-06-19 01:27:33 +02003408static int orinoco_ioctl_getiwencode(struct net_device *dev,
3409 struct iw_request_info *info,
3410 struct iw_point *erq,
3411 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412{
3413 struct orinoco_private *priv = netdev_priv(dev);
3414 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3415 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 unsigned long flags;
3417
3418 if (! priv->has_wep)
3419 return -EOPNOTSUPP;
3420
3421 if (orinoco_lock(priv, &flags) != 0)
3422 return -EBUSY;
3423
3424 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3425 index = priv->tx_key;
3426
3427 erq->flags = 0;
3428 if (! priv->wep_on)
3429 erq->flags |= IW_ENCODE_DISABLED;
3430 erq->flags |= index + 1;
3431
3432 if (priv->wep_restrict)
3433 erq->flags |= IW_ENCODE_RESTRICTED;
3434 else
3435 erq->flags |= IW_ENCODE_OPEN;
3436
3437 xlen = le16_to_cpu(priv->keys[index].len);
3438
3439 erq->length = xlen;
3440
3441 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3442
3443 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 return 0;
3445}
3446
Christoph Hellwig620554e2005-06-19 01:27:33 +02003447static int orinoco_ioctl_setessid(struct net_device *dev,
3448 struct iw_request_info *info,
3449 struct iw_point *erq,
3450 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
3452 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 unsigned long flags;
3454
3455 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3456 * anyway... - Jean II */
3457
Christoph Hellwig620554e2005-06-19 01:27:33 +02003458 /* Hum... Should not use Wireless Extension constant (may change),
3459 * should use our own... - Jean II */
3460 if (erq->length > IW_ESSID_MAX_SIZE)
3461 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
3463 if (orinoco_lock(priv, &flags) != 0)
3464 return -EBUSY;
3465
Christoph Hellwig620554e2005-06-19 01:27:33 +02003466 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3467 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3468
3469 /* If not ANY, get the new ESSID */
3470 if (erq->flags) {
3471 memcpy(priv->desired_essid, essidbuf, erq->length);
3472 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473
3474 orinoco_unlock(priv, &flags);
3475
Christoph Hellwig620554e2005-06-19 01:27:33 +02003476 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
Christoph Hellwig620554e2005-06-19 01:27:33 +02003479static int orinoco_ioctl_getessid(struct net_device *dev,
3480 struct iw_request_info *info,
3481 struct iw_point *erq,
3482 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483{
3484 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 int active;
3486 int err = 0;
3487 unsigned long flags;
3488
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 if (netif_running(dev)) {
3490 err = orinoco_hw_get_essid(priv, &active, essidbuf);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003491 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 return err;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003493 erq->length = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 } else {
3495 if (orinoco_lock(priv, &flags) != 0)
3496 return -EBUSY;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003497 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3498 erq->length = strlen(priv->desired_essid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 orinoco_unlock(priv, &flags);
3500 }
3501
3502 erq->flags = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 return 0;
3505}
3506
Christoph Hellwig620554e2005-06-19 01:27:33 +02003507static int orinoco_ioctl_setnick(struct net_device *dev,
3508 struct iw_request_info *info,
3509 struct iw_point *nrq,
3510 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511{
3512 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 unsigned long flags;
3514
3515 if (nrq->length > IW_ESSID_MAX_SIZE)
3516 return -E2BIG;
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 if (orinoco_lock(priv, &flags) != 0)
3519 return -EBUSY;
3520
Christoph Hellwig620554e2005-06-19 01:27:33 +02003521 memset(priv->nick, 0, sizeof(priv->nick));
3522 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
3524 orinoco_unlock(priv, &flags);
3525
Christoph Hellwig620554e2005-06-19 01:27:33 +02003526 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527}
3528
Christoph Hellwig620554e2005-06-19 01:27:33 +02003529static int orinoco_ioctl_getnick(struct net_device *dev,
3530 struct iw_request_info *info,
3531 struct iw_point *nrq,
3532 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533{
3534 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 unsigned long flags;
3536
3537 if (orinoco_lock(priv, &flags) != 0)
3538 return -EBUSY;
3539
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003540 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 orinoco_unlock(priv, &flags);
3542
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003543 nrq->length = strlen(priv->nick);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 return 0;
3546}
3547
Christoph Hellwig620554e2005-06-19 01:27:33 +02003548static int orinoco_ioctl_setfreq(struct net_device *dev,
3549 struct iw_request_info *info,
3550 struct iw_freq *frq,
3551 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552{
3553 struct orinoco_private *priv = netdev_priv(dev);
3554 int chan = -1;
3555 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003556 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003558 /* In infrastructure mode the AP sets the channel */
3559 if (priv->iw_mode == IW_MODE_INFRA)
3560 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561
3562 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3563 /* Setting by channel number */
3564 chan = frq->m;
3565 } else {
3566 /* Setting by frequency - search the table */
3567 int mult = 1;
3568 int i;
3569
3570 for (i = 0; i < (6 - frq->e); i++)
3571 mult *= 10;
3572
3573 for (i = 0; i < NUM_CHANNELS; i++)
3574 if (frq->m == (channel_frequency[i] * mult))
3575 chan = i+1;
3576 }
3577
3578 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3579 ! (priv->channel_mask & (1 << (chan-1)) ) )
3580 return -EINVAL;
3581
3582 if (orinoco_lock(priv, &flags) != 0)
3583 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003584
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003586 if (priv->iw_mode == IW_MODE_MONITOR) {
3587 /* Fast channel change - no commit if successful */
3588 hermes_t *hw = &priv->hw;
3589 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3590 HERMES_TEST_SET_CHANNEL,
3591 chan, NULL);
3592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 orinoco_unlock(priv, &flags);
3594
Christoph Hellwig620554e2005-06-19 01:27:33 +02003595 return err;
3596}
3597
3598static int orinoco_ioctl_getfreq(struct net_device *dev,
3599 struct iw_request_info *info,
3600 struct iw_freq *frq,
3601 char *extra)
3602{
3603 struct orinoco_private *priv = netdev_priv(dev);
3604 int tmp;
3605
3606 /* Locking done in there */
3607 tmp = orinoco_hw_get_freq(priv);
3608 if (tmp < 0) {
3609 return tmp;
3610 }
3611
3612 frq->m = tmp;
3613 frq->e = 1;
3614
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 return 0;
3616}
3617
Christoph Hellwig620554e2005-06-19 01:27:33 +02003618static int orinoco_ioctl_getsens(struct net_device *dev,
3619 struct iw_request_info *info,
3620 struct iw_param *srq,
3621 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622{
3623 struct orinoco_private *priv = netdev_priv(dev);
3624 hermes_t *hw = &priv->hw;
3625 u16 val;
3626 int err;
3627 unsigned long flags;
3628
3629 if (!priv->has_sensitivity)
3630 return -EOPNOTSUPP;
3631
3632 if (orinoco_lock(priv, &flags) != 0)
3633 return -EBUSY;
3634 err = hermes_read_wordrec(hw, USER_BAP,
3635 HERMES_RID_CNFSYSTEMSCALE, &val);
3636 orinoco_unlock(priv, &flags);
3637
3638 if (err)
3639 return err;
3640
3641 srq->value = val;
3642 srq->fixed = 0; /* auto */
3643
3644 return 0;
3645}
3646
Christoph Hellwig620554e2005-06-19 01:27:33 +02003647static int orinoco_ioctl_setsens(struct net_device *dev,
3648 struct iw_request_info *info,
3649 struct iw_param *srq,
3650 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651{
3652 struct orinoco_private *priv = netdev_priv(dev);
3653 int val = srq->value;
3654 unsigned long flags;
3655
3656 if (!priv->has_sensitivity)
3657 return -EOPNOTSUPP;
3658
3659 if ((val < 1) || (val > 3))
3660 return -EINVAL;
3661
3662 if (orinoco_lock(priv, &flags) != 0)
3663 return -EBUSY;
3664 priv->ap_density = val;
3665 orinoco_unlock(priv, &flags);
3666
Christoph Hellwig620554e2005-06-19 01:27:33 +02003667 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003668}
3669
Christoph Hellwig620554e2005-06-19 01:27:33 +02003670static int orinoco_ioctl_setrts(struct net_device *dev,
3671 struct iw_request_info *info,
3672 struct iw_param *rrq,
3673 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674{
3675 struct orinoco_private *priv = netdev_priv(dev);
3676 int val = rrq->value;
3677 unsigned long flags;
3678
3679 if (rrq->disabled)
3680 val = 2347;
3681
3682 if ( (val < 0) || (val > 2347) )
3683 return -EINVAL;
3684
3685 if (orinoco_lock(priv, &flags) != 0)
3686 return -EBUSY;
3687
3688 priv->rts_thresh = val;
3689 orinoco_unlock(priv, &flags);
3690
Christoph Hellwig620554e2005-06-19 01:27:33 +02003691 return -EINPROGRESS; /* Call commit handler */
3692}
3693
3694static int orinoco_ioctl_getrts(struct net_device *dev,
3695 struct iw_request_info *info,
3696 struct iw_param *rrq,
3697 char *extra)
3698{
3699 struct orinoco_private *priv = netdev_priv(dev);
3700
3701 rrq->value = priv->rts_thresh;
3702 rrq->disabled = (rrq->value == 2347);
3703 rrq->fixed = 1;
3704
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705 return 0;
3706}
3707
Christoph Hellwig620554e2005-06-19 01:27:33 +02003708static int orinoco_ioctl_setfrag(struct net_device *dev,
3709 struct iw_request_info *info,
3710 struct iw_param *frq,
3711 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712{
3713 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003714 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 unsigned long flags;
3716
3717 if (orinoco_lock(priv, &flags) != 0)
3718 return -EBUSY;
3719
3720 if (priv->has_mwo) {
3721 if (frq->disabled)
3722 priv->mwo_robust = 0;
3723 else {
3724 if (frq->fixed)
3725 printk(KERN_WARNING "%s: Fixed fragmentation is "
3726 "not supported on this firmware. "
3727 "Using MWO robust instead.\n", dev->name);
3728 priv->mwo_robust = 1;
3729 }
3730 } else {
3731 if (frq->disabled)
3732 priv->frag_thresh = 2346;
3733 else {
3734 if ( (frq->value < 256) || (frq->value > 2346) )
3735 err = -EINVAL;
3736 else
3737 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3738 }
3739 }
3740
3741 orinoco_unlock(priv, &flags);
3742
3743 return err;
3744}
3745
Christoph Hellwig620554e2005-06-19 01:27:33 +02003746static int orinoco_ioctl_getfrag(struct net_device *dev,
3747 struct iw_request_info *info,
3748 struct iw_param *frq,
3749 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750{
3751 struct orinoco_private *priv = netdev_priv(dev);
3752 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003753 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 u16 val;
3755 unsigned long flags;
3756
3757 if (orinoco_lock(priv, &flags) != 0)
3758 return -EBUSY;
3759
3760 if (priv->has_mwo) {
3761 err = hermes_read_wordrec(hw, USER_BAP,
3762 HERMES_RID_CNFMWOROBUST_AGERE,
3763 &val);
3764 if (err)
3765 val = 0;
3766
3767 frq->value = val ? 2347 : 0;
3768 frq->disabled = ! val;
3769 frq->fixed = 0;
3770 } else {
3771 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3772 &val);
3773 if (err)
3774 val = 0;
3775
3776 frq->value = val;
3777 frq->disabled = (val >= 2346);
3778 frq->fixed = 1;
3779 }
3780
3781 orinoco_unlock(priv, &flags);
3782
3783 return err;
3784}
3785
Christoph Hellwig620554e2005-06-19 01:27:33 +02003786static int orinoco_ioctl_setrate(struct net_device *dev,
3787 struct iw_request_info *info,
3788 struct iw_param *rrq,
3789 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790{
3791 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 int ratemode = -1;
3793 int bitrate; /* 100s of kilobits */
3794 int i;
3795 unsigned long flags;
3796
3797 /* As the user space doesn't know our highest rate, it uses -1
3798 * to ask us to set the highest rate. Test it using "iwconfig
3799 * ethX rate auto" - Jean II */
3800 if (rrq->value == -1)
3801 bitrate = 110;
3802 else {
3803 if (rrq->value % 100000)
3804 return -EINVAL;
3805 bitrate = rrq->value / 100000;
3806 }
3807
3808 if ( (bitrate != 10) && (bitrate != 20) &&
3809 (bitrate != 55) && (bitrate != 110) )
3810 return -EINVAL;
3811
3812 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3813 if ( (bitrate_table[i].bitrate == bitrate) &&
3814 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3815 ratemode = i;
3816 break;
3817 }
3818
3819 if (ratemode == -1)
3820 return -EINVAL;
3821
3822 if (orinoco_lock(priv, &flags) != 0)
3823 return -EBUSY;
3824 priv->bitratemode = ratemode;
3825 orinoco_unlock(priv, &flags);
3826
Christoph Hellwig620554e2005-06-19 01:27:33 +02003827 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828}
3829
Christoph Hellwig620554e2005-06-19 01:27:33 +02003830static int orinoco_ioctl_getrate(struct net_device *dev,
3831 struct iw_request_info *info,
3832 struct iw_param *rrq,
3833 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834{
3835 struct orinoco_private *priv = netdev_priv(dev);
3836 hermes_t *hw = &priv->hw;
3837 int err = 0;
3838 int ratemode;
3839 int i;
3840 u16 val;
3841 unsigned long flags;
3842
3843 if (orinoco_lock(priv, &flags) != 0)
3844 return -EBUSY;
3845
3846 ratemode = priv->bitratemode;
3847
3848 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3849
3850 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3851 rrq->fixed = ! bitrate_table[ratemode].automatic;
3852 rrq->disabled = 0;
3853
3854 /* If the interface is running we try to find more about the
3855 current mode */
3856 if (netif_running(dev)) {
3857 err = hermes_read_wordrec(hw, USER_BAP,
3858 HERMES_RID_CURRENTTXRATE, &val);
3859 if (err)
3860 goto out;
3861
3862 switch (priv->firmware_type) {
3863 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3864 /* Note : in Lucent firmware, the return value of
3865 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3866 * and therefore is totally different from the
3867 * encoding of HERMES_RID_CNFTXRATECONTROL.
3868 * Don't forget that 6Mb/s is really 5.5Mb/s */
3869 if (val == 6)
3870 rrq->value = 5500000;
3871 else
3872 rrq->value = val * 1000000;
3873 break;
3874 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3875 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3876 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3877 if (bitrate_table[i].intersil_txratectrl == val) {
3878 ratemode = i;
3879 break;
3880 }
3881 if (i >= BITRATE_TABLE_SIZE)
3882 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3883 dev->name, val);
3884
3885 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3886 break;
3887 default:
3888 BUG();
3889 }
3890 }
3891
3892 out:
3893 orinoco_unlock(priv, &flags);
3894
3895 return err;
3896}
3897
Christoph Hellwig620554e2005-06-19 01:27:33 +02003898static int orinoco_ioctl_setpower(struct net_device *dev,
3899 struct iw_request_info *info,
3900 struct iw_param *prq,
3901 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902{
3903 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003904 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 unsigned long flags;
3906
3907 if (orinoco_lock(priv, &flags) != 0)
3908 return -EBUSY;
3909
3910 if (prq->disabled) {
3911 priv->pm_on = 0;
3912 } else {
3913 switch (prq->flags & IW_POWER_MODE) {
3914 case IW_POWER_UNICAST_R:
3915 priv->pm_mcast = 0;
3916 priv->pm_on = 1;
3917 break;
3918 case IW_POWER_ALL_R:
3919 priv->pm_mcast = 1;
3920 priv->pm_on = 1;
3921 break;
3922 case IW_POWER_ON:
3923 /* No flags : but we may have a value - Jean II */
3924 break;
3925 default:
3926 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003927 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05003928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929
3930 if (prq->flags & IW_POWER_TIMEOUT) {
3931 priv->pm_on = 1;
3932 priv->pm_timeout = prq->value / 1000;
3933 }
3934 if (prq->flags & IW_POWER_PERIOD) {
3935 priv->pm_on = 1;
3936 priv->pm_period = prq->value / 1000;
3937 }
3938 /* It's valid to not have a value if we are just toggling
3939 * the flags... Jean II */
3940 if(!priv->pm_on) {
3941 err = -EINVAL;
3942 goto out;
3943 }
3944 }
3945
3946 out:
3947 orinoco_unlock(priv, &flags);
3948
3949 return err;
3950}
3951
Christoph Hellwig620554e2005-06-19 01:27:33 +02003952static int orinoco_ioctl_getpower(struct net_device *dev,
3953 struct iw_request_info *info,
3954 struct iw_param *prq,
3955 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956{
3957 struct orinoco_private *priv = netdev_priv(dev);
3958 hermes_t *hw = &priv->hw;
3959 int err = 0;
3960 u16 enable, period, timeout, mcast;
3961 unsigned long flags;
3962
3963 if (orinoco_lock(priv, &flags) != 0)
3964 return -EBUSY;
3965
3966 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3967 if (err)
3968 goto out;
3969
3970 err = hermes_read_wordrec(hw, USER_BAP,
3971 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3972 if (err)
3973 goto out;
3974
3975 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3976 if (err)
3977 goto out;
3978
3979 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3980 if (err)
3981 goto out;
3982
3983 prq->disabled = !enable;
3984 /* Note : by default, display the period */
3985 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3986 prq->flags = IW_POWER_TIMEOUT;
3987 prq->value = timeout * 1000;
3988 } else {
3989 prq->flags = IW_POWER_PERIOD;
3990 prq->value = period * 1000;
3991 }
3992 if (mcast)
3993 prq->flags |= IW_POWER_ALL_R;
3994 else
3995 prq->flags |= IW_POWER_UNICAST_R;
3996
3997 out:
3998 orinoco_unlock(priv, &flags);
3999
4000 return err;
4001}
4002
Christoph Hellwig620554e2005-06-19 01:27:33 +02004003static int orinoco_ioctl_getretry(struct net_device *dev,
4004 struct iw_request_info *info,
4005 struct iw_param *rrq,
4006 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007{
4008 struct orinoco_private *priv = netdev_priv(dev);
4009 hermes_t *hw = &priv->hw;
4010 int err = 0;
4011 u16 short_limit, long_limit, lifetime;
4012 unsigned long flags;
4013
4014 if (orinoco_lock(priv, &flags) != 0)
4015 return -EBUSY;
4016
4017 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4018 &short_limit);
4019 if (err)
4020 goto out;
4021
4022 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4023 &long_limit);
4024 if (err)
4025 goto out;
4026
4027 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4028 &lifetime);
4029 if (err)
4030 goto out;
4031
4032 rrq->disabled = 0; /* Can't be disabled */
4033
4034 /* Note : by default, display the retry number */
4035 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4036 rrq->flags = IW_RETRY_LIFETIME;
4037 rrq->value = lifetime * 1000; /* ??? */
4038 } else {
4039 /* By default, display the min number */
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004040 if ((rrq->flags & IW_RETRY_LONG)) {
4041 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 rrq->value = long_limit;
4043 } else {
4044 rrq->flags = IW_RETRY_LIMIT;
4045 rrq->value = short_limit;
4046 if(short_limit != long_limit)
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004047 rrq->flags |= IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048 }
4049 }
4050
4051 out:
4052 orinoco_unlock(priv, &flags);
4053
4054 return err;
4055}
4056
Christoph Hellwig620554e2005-06-19 01:27:33 +02004057static int orinoco_ioctl_reset(struct net_device *dev,
4058 struct iw_request_info *info,
4059 void *wrqu,
4060 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061{
4062 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004063
4064 if (! capable(CAP_NET_ADMIN))
4065 return -EPERM;
4066
4067 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4068 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4069
4070 /* Firmware reset */
David Howellsc4028952006-11-22 14:57:56 +00004071 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004072 } else {
4073 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4074
4075 schedule_work(&priv->reset_work);
4076 }
4077
4078 return 0;
4079}
4080
4081static int orinoco_ioctl_setibssport(struct net_device *dev,
4082 struct iw_request_info *info,
4083 void *wrqu,
4084 char *extra)
4085
4086{
4087 struct orinoco_private *priv = netdev_priv(dev);
4088 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 unsigned long flags;
4090
4091 if (orinoco_lock(priv, &flags) != 0)
4092 return -EBUSY;
4093
4094 priv->ibss_port = val ;
4095
4096 /* Actually update the mode we are using */
4097 set_port_type(priv);
4098
4099 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004100 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101}
4102
Christoph Hellwig620554e2005-06-19 01:27:33 +02004103static int orinoco_ioctl_getibssport(struct net_device *dev,
4104 struct iw_request_info *info,
4105 void *wrqu,
4106 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107{
4108 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004109 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110
4111 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112 return 0;
4113}
4114
Christoph Hellwig620554e2005-06-19 01:27:33 +02004115static int orinoco_ioctl_setport3(struct net_device *dev,
4116 struct iw_request_info *info,
4117 void *wrqu,
4118 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119{
4120 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004121 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 int err = 0;
4123 unsigned long flags;
4124
4125 if (orinoco_lock(priv, &flags) != 0)
4126 return -EBUSY;
4127
4128 switch (val) {
4129 case 0: /* Try to do IEEE ad-hoc mode */
4130 if (! priv->has_ibss) {
4131 err = -EINVAL;
4132 break;
4133 }
4134 priv->prefer_port3 = 0;
4135
4136 break;
4137
4138 case 1: /* Try to do Lucent proprietary ad-hoc mode */
4139 if (! priv->has_port3) {
4140 err = -EINVAL;
4141 break;
4142 }
4143 priv->prefer_port3 = 1;
4144 break;
4145
4146 default:
4147 err = -EINVAL;
4148 }
4149
Christoph Hellwig620554e2005-06-19 01:27:33 +02004150 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 /* Actually update the mode we are using */
4152 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004153 err = -EINPROGRESS;
4154 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155
4156 orinoco_unlock(priv, &flags);
4157
4158 return err;
4159}
4160
Christoph Hellwig620554e2005-06-19 01:27:33 +02004161static int orinoco_ioctl_getport3(struct net_device *dev,
4162 struct iw_request_info *info,
4163 void *wrqu,
4164 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165{
4166 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004167 int *val = (int *) extra;
4168
4169 *val = priv->prefer_port3;
4170 return 0;
4171}
4172
4173static int orinoco_ioctl_setpreamble(struct net_device *dev,
4174 struct iw_request_info *info,
4175 void *wrqu,
4176 char *extra)
4177{
4178 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004180 int val;
4181
4182 if (! priv->has_preamble)
4183 return -EOPNOTSUPP;
4184
4185 /* 802.11b has recently defined some short preamble.
4186 * Basically, the Phy header has been reduced in size.
4187 * This increase performance, especially at high rates
4188 * (the preamble is transmitted at 1Mb/s), unfortunately
4189 * this give compatibility troubles... - Jean II */
4190 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191
4192 if (orinoco_lock(priv, &flags) != 0)
4193 return -EBUSY;
4194
Christoph Hellwig620554e2005-06-19 01:27:33 +02004195 if (val)
4196 priv->preamble = 1;
4197 else
4198 priv->preamble = 0;
4199
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004201
4202 return -EINPROGRESS; /* Call commit handler */
4203}
4204
4205static int orinoco_ioctl_getpreamble(struct net_device *dev,
4206 struct iw_request_info *info,
4207 void *wrqu,
4208 char *extra)
4209{
4210 struct orinoco_private *priv = netdev_priv(dev);
4211 int *val = (int *) extra;
4212
4213 if (! priv->has_preamble)
4214 return -EOPNOTSUPP;
4215
4216 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004217 return 0;
4218}
4219
Christoph Hellwig620554e2005-06-19 01:27:33 +02004220/* ioctl interface to hermes_read_ltv()
4221 * To use with iwpriv, pass the RID as the token argument, e.g.
4222 * iwpriv get_rid [0xfc00]
4223 * At least Wireless Tools 25 is required to use iwpriv.
4224 * For Wireless Tools 25 and 26 append "dummy" are the end. */
4225static int orinoco_ioctl_getrid(struct net_device *dev,
4226 struct iw_request_info *info,
4227 struct iw_point *data,
4228 char *extra)
4229{
4230 struct orinoco_private *priv = netdev_priv(dev);
4231 hermes_t *hw = &priv->hw;
4232 int rid = data->flags;
4233 u16 length;
4234 int err;
4235 unsigned long flags;
4236
4237 /* It's a "get" function, but we don't want users to access the
4238 * WEP key and other raw firmware data */
4239 if (! capable(CAP_NET_ADMIN))
4240 return -EPERM;
4241
4242 if (rid < 0xfc00 || rid > 0xffff)
4243 return -EINVAL;
4244
4245 if (orinoco_lock(priv, &flags) != 0)
4246 return -EBUSY;
4247
4248 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
4249 extra);
4250 if (err)
4251 goto out;
4252
4253 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
4254 MAX_RID_LEN);
4255
4256 out:
4257 orinoco_unlock(priv, &flags);
4258 return err;
4259}
4260
David Kilroy17a1a882008-08-21 23:27:47 +01004261/* Trigger a scan (look for other cells in the vicinity) */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004262static int orinoco_ioctl_setscan(struct net_device *dev,
4263 struct iw_request_info *info,
4264 struct iw_param *srq,
4265 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266{
4267 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004268 hermes_t *hw = &priv->hw;
David Kilroy0753bba2008-08-21 23:27:46 +01004269 struct iw_scan_req *si = (struct iw_scan_req *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004270 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004271 unsigned long flags;
4272
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004273 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08004274 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004275 * perform scanning.
4276 * This is not an error, while the device perform scanning,
4277 * traffic doesn't flow, so it's a perfect DoS...
4278 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004279
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004280 if (orinoco_lock(priv, &flags) != 0)
4281 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004282
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004283 /* Scanning with port 0 disabled would fail */
4284 if (!netif_running(dev)) {
4285 err = -ENETDOWN;
4286 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004288
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004289 /* In monitor mode, the scan results are always empty.
4290 * Probe responses are passed to the driver as received
4291 * frames and could be processed in software. */
4292 if (priv->iw_mode == IW_MODE_MONITOR) {
4293 err = -EOPNOTSUPP;
4294 goto out;
4295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004296
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004297 /* Note : because we don't lock out the irq handler, the way
4298 * we access scan variables in priv is critical.
4299 * o scan_inprogress : not touched by irq handler
4300 * o scan_mode : not touched by irq handler
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004301 * Before modifying anything on those variables, please think hard !
4302 * Jean II */
4303
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004304 /* Save flags */
4305 priv->scan_mode = srq->flags;
4306
4307 /* Always trigger scanning, even if it's in progress.
4308 * This way, if the info frame get lost, we will recover somewhat
4309 * gracefully - Jean II */
4310
4311 if (priv->has_hostscan) {
4312 switch (priv->firmware_type) {
4313 case FIRMWARE_TYPE_SYMBOL:
4314 err = hermes_write_wordrec(hw, USER_BAP,
4315 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4316 HERMES_HOSTSCAN_SYMBOL_ONCE |
4317 HERMES_HOSTSCAN_SYMBOL_BCAST);
4318 break;
4319 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04004320 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004321
4322 req[0] = cpu_to_le16(0x3fff); /* All channels */
4323 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4324 req[2] = 0; /* Any ESSID */
4325 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4326 HERMES_RID_CNFHOSTSCAN, &req);
4327 }
4328 break;
4329 case FIRMWARE_TYPE_AGERE:
David Kilroy0753bba2008-08-21 23:27:46 +01004330 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4331 struct hermes_idstring idbuf;
4332 size_t len = min(sizeof(idbuf.val),
4333 (size_t) si->essid_len);
4334 idbuf.len = cpu_to_le16(len);
4335 memcpy(idbuf.val, si->essid, len);
4336
4337 err = hermes_write_ltv(hw, USER_BAP,
4338 HERMES_RID_CNFSCANSSID_AGERE,
4339 HERMES_BYTES_TO_RECLEN(len + 2),
4340 &idbuf);
4341 } else
4342 err = hermes_write_wordrec(hw, USER_BAP,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004343 HERMES_RID_CNFSCANSSID_AGERE,
4344 0); /* Any ESSID */
4345 if (err)
4346 break;
4347
4348 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4349 break;
4350 }
4351 } else
4352 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4353
4354 /* One more client */
4355 if (! err)
4356 priv->scan_inprogress = 1;
4357
4358 out:
4359 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004360 return err;
4361}
4362
Dan Williams1e3428e2007-10-10 23:56:25 -04004363#define MAX_CUSTOM_LEN 64
4364
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004365/* Translate scan data returned from the card to a card independant
David Kilroy17a1a882008-08-21 23:27:47 +01004366 * format that the Wireless Tools will understand - Jean II */
Dan Williams1e3428e2007-10-10 23:56:25 -04004367static inline char *orinoco_translate_scan(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07004368 struct iw_request_info *info,
Dan Williams1e3428e2007-10-10 23:56:25 -04004369 char *current_ev,
4370 char *end_buf,
4371 union hermes_scan_info *bss,
4372 unsigned int last_scanned)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004373{
4374 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004375 u16 capabilities;
4376 u16 channel;
4377 struct iw_event iwe; /* Temporary buffer */
Dan Williams1e3428e2007-10-10 23:56:25 -04004378 char custom[MAX_CUSTOM_LEN];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004379
David Kilroy17a1a882008-08-21 23:27:47 +01004380 memset(&iwe, 0, sizeof(iwe));
4381
Dan Williams1e3428e2007-10-10 23:56:25 -04004382 /* First entry *MUST* be the AP MAC address */
4383 iwe.cmd = SIOCGIWAP;
4384 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4385 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07004386 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4387 &iwe, IW_EV_ADDR_LEN);
Dan Williams1e3428e2007-10-10 23:56:25 -04004388
4389 /* Other entries will be displayed in the order we give them */
4390
4391 /* Add the ESSID */
4392 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4393 if (iwe.u.data.length > 32)
4394 iwe.u.data.length = 32;
4395 iwe.cmd = SIOCGIWESSID;
4396 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004397 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4398 &iwe, bss->a.essid);
Dan Williams1e3428e2007-10-10 23:56:25 -04004399
4400 /* Add mode */
4401 iwe.cmd = SIOCGIWMODE;
4402 capabilities = le16_to_cpu(bss->a.capabilities);
David Kilroy17a1a882008-08-21 23:27:47 +01004403 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4404 if (capabilities & WLAN_CAPABILITY_ESS)
Dan Williams1e3428e2007-10-10 23:56:25 -04004405 iwe.u.mode = IW_MODE_MASTER;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004406 else
Dan Williams1e3428e2007-10-10 23:56:25 -04004407 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07004408 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4409 &iwe, IW_EV_UINT_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004410 }
4411
Dan Williams1e3428e2007-10-10 23:56:25 -04004412 channel = bss->s.channel;
4413 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
David Kilroy17a1a882008-08-21 23:27:47 +01004414 /* Add channel and frequency */
Dan Williams1e3428e2007-10-10 23:56:25 -04004415 iwe.cmd = SIOCGIWFREQ;
David Kilroy17a1a882008-08-21 23:27:47 +01004416 iwe.u.freq.m = channel;
4417 iwe.u.freq.e = 0;
4418 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4419 &iwe, IW_EV_FREQ_LEN);
4420
Dan Williams1e3428e2007-10-10 23:56:25 -04004421 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4422 iwe.u.freq.e = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004423 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
Dan Williams1e3428e2007-10-10 23:56:25 -04004424 &iwe, IW_EV_FREQ_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004425 }
4426
David Kilroy17a1a882008-08-21 23:27:47 +01004427 /* Add quality statistics. level and noise in dB. No link quality */
Dan Williams1e3428e2007-10-10 23:56:25 -04004428 iwe.cmd = IWEVQUAL;
David Kilroy17a1a882008-08-21 23:27:47 +01004429 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
Dan Williams1e3428e2007-10-10 23:56:25 -04004430 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4431 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4432 /* Wireless tools prior to 27.pre22 will show link quality
4433 * anyway, so we provide a reasonable value. */
4434 if (iwe.u.qual.level > iwe.u.qual.noise)
4435 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4436 else
4437 iwe.u.qual.qual = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004438 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4439 &iwe, IW_EV_QUAL_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004440
Dan Williams1e3428e2007-10-10 23:56:25 -04004441 /* Add encryption capability */
4442 iwe.cmd = SIOCGIWENCODE;
David Kilroy17a1a882008-08-21 23:27:47 +01004443 if (capabilities & WLAN_CAPABILITY_PRIVACY)
Dan Williams1e3428e2007-10-10 23:56:25 -04004444 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4445 else
4446 iwe.u.data.flags = IW_ENCODE_DISABLED;
4447 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004448 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
David Kilroy17a1a882008-08-21 23:27:47 +01004449 &iwe, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004450
Dan Williams1e3428e2007-10-10 23:56:25 -04004451 /* Bit rate is not available in Lucent/Agere firmwares */
4452 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
David S. Millerccc58052008-06-16 18:50:49 -07004453 char *current_val = current_ev + iwe_stream_lcp_len(info);
Dan Williams1e3428e2007-10-10 23:56:25 -04004454 int i;
4455 int step;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004456
Dan Williams1e3428e2007-10-10 23:56:25 -04004457 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4458 step = 2;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004459 else
Dan Williams1e3428e2007-10-10 23:56:25 -04004460 step = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004461
Dan Williams1e3428e2007-10-10 23:56:25 -04004462 iwe.cmd = SIOCGIWRATE;
4463 /* Those two flags are ignored... */
4464 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4465 /* Max 10 values */
4466 for (i = 0; i < 10; i += step) {
4467 /* NULL terminated */
4468 if (bss->p.rates[i] == 0x0)
4469 break;
4470 /* Bit rate given in 500 kb/s units (+ 0x80) */
David Kilroy17a1a882008-08-21 23:27:47 +01004471 iwe.u.bitrate.value =
4472 ((bss->p.rates[i] & 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07004473 current_val = iwe_stream_add_value(info, current_ev,
4474 current_val,
Dan Williams1e3428e2007-10-10 23:56:25 -04004475 end_buf, &iwe,
4476 IW_EV_PARAM_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004477 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004478 /* Check if we added any event */
David S. Millerccc58052008-06-16 18:50:49 -07004479 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
Dan Williams1e3428e2007-10-10 23:56:25 -04004480 current_ev = current_val;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004481 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004482
David Kilroy17a1a882008-08-21 23:27:47 +01004483 /* Beacon interval */
4484 iwe.cmd = IWEVCUSTOM;
4485 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4486 "bcn_int=%d",
4487 le16_to_cpu(bss->a.beacon_interv));
4488 if (iwe.u.data.length)
4489 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4490 &iwe, custom);
4491
4492 /* Capabilites */
4493 iwe.cmd = IWEVCUSTOM;
4494 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4495 "capab=0x%04x",
4496 capabilities);
4497 if (iwe.u.data.length)
4498 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4499 &iwe, custom);
4500
4501 /* Add EXTRA: Age to display seconds since last beacon/probe response
4502 * for given network. */
4503 iwe.cmd = IWEVCUSTOM;
4504 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4505 " Last beacon: %dms ago",
4506 jiffies_to_msecs(jiffies - last_scanned));
4507 if (iwe.u.data.length)
4508 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4509 &iwe, custom);
4510
Dan Williams1e3428e2007-10-10 23:56:25 -04004511 return current_ev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004512}
4513
4514/* Return results of a scan */
4515static int orinoco_ioctl_getscan(struct net_device *dev,
4516 struct iw_request_info *info,
4517 struct iw_point *srq,
4518 char *extra)
4519{
4520 struct orinoco_private *priv = netdev_priv(dev);
Dan Williams1e3428e2007-10-10 23:56:25 -04004521 bss_element *bss;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004522 int err = 0;
4523 unsigned long flags;
Dan Williams1e3428e2007-10-10 23:56:25 -04004524 char *current_ev = extra;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004525
4526 if (orinoco_lock(priv, &flags) != 0)
4527 return -EBUSY;
4528
Dan Williams1e3428e2007-10-10 23:56:25 -04004529 if (priv->scan_inprogress) {
4530 /* Important note : we don't want to block the caller
4531 * until results are ready for various reasons.
4532 * First, managing wait queues is complex and racy.
4533 * Second, we grab some rtnetlink lock before comming
4534 * here (in dev_ioctl()).
4535 * Third, we generate an Wireless Event, so the
4536 * caller can wait itself on that - Jean II */
4537 err = -EAGAIN;
4538 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004539 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004540
4541 list_for_each_entry(bss, &priv->bss_list, list) {
4542 /* Translate to WE format this entry */
David S. Millerccc58052008-06-16 18:50:49 -07004543 current_ev = orinoco_translate_scan(dev, info, current_ev,
Dan Williams1e3428e2007-10-10 23:56:25 -04004544 extra + srq->length,
4545 &bss->bss,
4546 bss->last_scanned);
4547
4548 /* Check if there is space for one more entry */
4549 if ((extra + srq->length - current_ev) <= IW_EV_ADDR_LEN) {
4550 /* Ask user space to try again with a bigger buffer */
4551 err = -E2BIG;
4552 goto out;
4553 }
4554 }
4555
4556 srq->length = (current_ev - extra);
4557 srq->flags = (__u16) priv->scan_mode;
4558
4559out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004560 orinoco_unlock(priv, &flags);
4561 return err;
4562}
4563
Christoph Hellwig620554e2005-06-19 01:27:33 +02004564/* Commit handler, called after set operations */
4565static int orinoco_ioctl_commit(struct net_device *dev,
4566 struct iw_request_info *info,
4567 void *wrqu,
4568 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004569{
4570 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004571 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004573 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004574
Christoph Hellwig620554e2005-06-19 01:27:33 +02004575 if (!priv->open)
4576 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577
Christoph Hellwig620554e2005-06-19 01:27:33 +02004578 if (priv->broken_disableport) {
David Howellsc4028952006-11-22 14:57:56 +00004579 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004580 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004582
Christoph Hellwig620554e2005-06-19 01:27:33 +02004583 if (orinoco_lock(priv, &flags) != 0)
4584 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004585
Christoph Hellwig620554e2005-06-19 01:27:33 +02004586 err = hermes_disable_port(hw, 0);
4587 if (err) {
4588 printk(KERN_WARNING "%s: Unable to disable port "
4589 "while reconfiguring card\n", dev->name);
4590 priv->broken_disableport = 1;
4591 goto out;
4592 }
4593
4594 err = __orinoco_program_rids(dev);
4595 if (err) {
4596 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4597 dev->name);
4598 goto out;
4599 }
4600
4601 err = hermes_enable_port(hw, 0);
4602 if (err) {
4603 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4604 dev->name);
4605 goto out;
4606 }
4607
4608 out:
4609 if (err) {
4610 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4611 schedule_work(&priv->reset_work);
4612 err = 0;
4613 }
4614
4615 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 return err;
4617}
4618
Christoph Hellwig620554e2005-06-19 01:27:33 +02004619static const struct iw_priv_args orinoco_privtab[] = {
4620 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4621 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4622 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4623 0, "set_port3" },
4624 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4625 "get_port3" },
4626 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4627 0, "set_preamble" },
4628 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4629 "get_preamble" },
4630 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4631 0, "set_ibssport" },
4632 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4633 "get_ibssport" },
4634 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4635 "get_rid" },
4636};
4637
4638
4639/*
4640 * Structures to export the Wireless Handlers
4641 */
4642
4643static const iw_handler orinoco_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004644 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4645 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4646 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4647 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4648 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4649 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4650 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4651 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4652 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
Pavel Roskin343c6862005-09-09 18:43:02 -04004653 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4654 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4655 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4656 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004657 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4658 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4659 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4660 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4661 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4662 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4663 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4664 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4665 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4666 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4667 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4668 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4669 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4670 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4671 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4672 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4673 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4674 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4675 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004676};
4677
4678
4679/*
4680 Added typecasting since we no longer use iwreq_data -- Moustafa
4681 */
4682static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004683 [0] = (iw_handler) orinoco_ioctl_reset,
4684 [1] = (iw_handler) orinoco_ioctl_reset,
4685 [2] = (iw_handler) orinoco_ioctl_setport3,
4686 [3] = (iw_handler) orinoco_ioctl_getport3,
4687 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4688 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4689 [6] = (iw_handler) orinoco_ioctl_setibssport,
4690 [7] = (iw_handler) orinoco_ioctl_getibssport,
4691 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004692};
4693
4694static const struct iw_handler_def orinoco_handler_def = {
4695 .num_standard = ARRAY_SIZE(orinoco_handler),
4696 .num_private = ARRAY_SIZE(orinoco_private_handler),
4697 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4698 .standard = orinoco_handler,
4699 .private = orinoco_private_handler,
4700 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04004701 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004702};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004703
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004704static void orinoco_get_drvinfo(struct net_device *dev,
4705 struct ethtool_drvinfo *info)
4706{
4707 struct orinoco_private *priv = netdev_priv(dev);
4708
4709 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4710 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4711 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07004712 if (dev->dev.parent)
4713 strncpy(info->bus_info, dev->dev.parent->bus_id,
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004714 sizeof(info->bus_info) - 1);
4715 else
4716 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4717 "PCMCIA %p", priv->hw.iobase);
4718}
4719
Jeff Garzik7282d492006-09-13 14:30:00 -04004720static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004721 .get_drvinfo = orinoco_get_drvinfo,
4722 .get_link = ethtool_op_get_link,
4723};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004724
4725/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07004726/* Module initialization */
4727/********************************************************************/
4728
4729EXPORT_SYMBOL(alloc_orinocodev);
4730EXPORT_SYMBOL(free_orinocodev);
4731
4732EXPORT_SYMBOL(__orinoco_up);
4733EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004734EXPORT_SYMBOL(orinoco_reinit_firmware);
4735
4736EXPORT_SYMBOL(orinoco_interrupt);
4737
4738/* Can't be declared "const" or the whole __initdata section will
4739 * become const */
4740static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4741 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4742 "Pavel Roskin <proski@gnu.org>, et al)";
4743
4744static int __init init_orinoco(void)
4745{
4746 printk(KERN_DEBUG "%s\n", version);
4747 return 0;
4748}
4749
4750static void __exit exit_orinoco(void)
4751{
4752}
4753
4754module_init(init_orinoco);
4755module_exit(exit_orinoco);