blob: b83415daa723ef069d915e6b85e5ae831e3daf74 [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;
David Kilroy6eecad72008-08-21 23:27:56 +0100725 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 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
David Kilroy6eecad72008-08-21 23:27:56 +0100759 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
David Kilroy6eecad72008-08-21 23:27:56 +0100761 if (priv->has_alt_txcntl) {
762 /* WPA enabled firmwares have tx_cntl at the end of
763 * the 802.11 header. So write zeroed descriptor and
764 * 802.11 header at the same time
765 */
766 char desc[HERMES_802_3_OFFSET];
767 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
768
769 memset(&desc, 0, sizeof(desc));
770
771 *txcntl = cpu_to_le16(tx_control);
772 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
773 txfid, 0);
774 if (err) {
775 if (net_ratelimit())
776 printk(KERN_ERR "%s: Error %d writing Tx "
777 "descriptor to BAP\n", dev->name, err);
778 goto busy;
779 }
780 } else {
781 struct hermes_tx_descriptor desc;
782
783 memset(&desc, 0, sizeof(desc));
784
785 desc.tx_control = cpu_to_le16(tx_control);
786 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
787 txfid, 0);
788 if (err) {
789 if (net_ratelimit())
790 printk(KERN_ERR "%s: Error %d writing Tx "
791 "descriptor to BAP\n", dev->name, err);
792 goto busy;
793 }
794
795 /* Clear the 802.11 header and data length fields - some
796 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
797 * if this isn't done. */
798 hermes_clear_words(hw, HERMES_DATA0,
799 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
802 /* Encapsulate Ethernet-II frames */
803 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400804 struct header_struct {
805 struct ethhdr eth; /* 802.3 header */
806 u8 encap[6]; /* 802.2 header */
807 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Pavel Roskina28dc812006-04-07 04:10:45 -0400809 /* Strip destination and source from the data */
810 skb_pull(skb, 2 * ETH_ALEN);
811 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
812
813 /* And move them to a separate header */
814 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
815 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
816 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
817
818 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
819 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (err) {
821 if (net_ratelimit())
822 printk(KERN_ERR "%s: Error %d writing packet "
823 "header to BAP\n", dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400824 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 }
826 } else { /* IEEE 802.3 frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 data_off = HERMES_802_3_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
Pavel Roskina28dc812006-04-07 04:10:45 -0400830 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 txfid, data_off);
832 if (err) {
833 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
834 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400835 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 }
837
838 /* Finally, we actually initiate the send */
839 netif_stop_queue(dev);
840
841 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
842 txfid, NULL);
843 if (err) {
844 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700845 if (net_ratelimit())
846 printk(KERN_ERR "%s: Error %d transmitting packet\n",
847 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400848 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 }
850
851 dev->trans_start = jiffies;
Pavel Roskina28dc812006-04-07 04:10:45 -0400852 stats->tx_bytes += data_off + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400853 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400855 drop:
856 stats->tx_errors++;
857 stats->tx_dropped++;
858
859 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400862 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400864 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400865 if (err == -EIO)
866 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400868 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869}
870
871static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
872{
873 struct orinoco_private *priv = netdev_priv(dev);
874 u16 fid = hermes_read_regn(hw, ALLOCFID);
875
876 if (fid != priv->txfid) {
877 if (fid != DUMMY_FID)
878 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
879 dev->name, fid);
880 return;
881 }
882
883 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
884}
885
886static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
887{
888 struct orinoco_private *priv = netdev_priv(dev);
889 struct net_device_stats *stats = &priv->stats;
890
891 stats->tx_packets++;
892
893 netif_wake_queue(dev);
894
895 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
896}
897
898static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
899{
900 struct orinoco_private *priv = netdev_priv(dev);
901 struct net_device_stats *stats = &priv->stats;
902 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400903 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400904 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 int err = 0;
906
907 if (fid == DUMMY_FID)
908 return; /* Nothing's really happened */
909
Pavel Roskin48ca7032005-09-23 04:18:06 -0400910 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200911 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400912 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200913 fid, 0);
914
915 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
916 stats->tx_errors++;
917
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (err) {
919 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
920 "(FID=%04X error %d)\n",
921 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200922 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 }
924
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200925 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
926 err, fid);
927
928 /* We produce a TXDROP event only for retry or lifetime
929 * exceeded, because that's the only status that really mean
930 * that this particular node went away.
931 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400932 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400933 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200934 union iwreq_data wrqu;
935
936 /* Copy 802.11 dest address.
937 * We use the 802.11 header because the frame may
938 * not be 802.3 or may be mangled...
939 * In Ad-Hoc mode, it will be the node address.
940 * In managed mode, it will be most likely the AP addr
941 * User space will figure out how to convert it to
942 * whatever it needs (IP address or else).
943 * - Jean II */
944 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
945 wrqu.addr.sa_family = ARPHRD_ETHER;
946
947 /* Send event to user space */
948 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
954static void orinoco_tx_timeout(struct net_device *dev)
955{
956 struct orinoco_private *priv = netdev_priv(dev);
957 struct net_device_stats *stats = &priv->stats;
958 struct hermes *hw = &priv->hw;
959
960 printk(KERN_WARNING "%s: Tx timeout! "
961 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
962 dev->name, hermes_read_regn(hw, ALLOCFID),
963 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
964
965 stats->tx_errors++;
966
967 schedule_work(&priv->reset_work);
968}
969
970/********************************************************************/
971/* Rx path (data frames) */
972/********************************************************************/
973
974/* Does the frame have a SNAP header indicating it should be
975 * de-encapsulated to Ethernet-II? */
976static inline int is_ethersnap(void *_hdr)
977{
978 u8 *hdr = _hdr;
979
980 /* We de-encapsulate all packets which, a) have SNAP headers
981 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
982 * and where b) the OUI of the SNAP header is 00:00:00 or
983 * 00:00:f8 - we need both because different APs appear to use
984 * different OUIs for some reason */
985 return (memcmp(hdr, &encaps_hdr, 5) == 0)
986 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
987}
988
989static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
990 int level, int noise)
991{
Pavel Roskin343c6862005-09-09 18:43:02 -0400992 struct iw_quality wstats;
993 wstats.level = level - 0x95;
994 wstats.noise = noise - 0x95;
995 wstats.qual = (level > noise) ? (level - noise) : 0;
996 wstats.updated = 7;
997 /* Update spy records */
998 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999}
1000
1001static void orinoco_stat_gather(struct net_device *dev,
1002 struct sk_buff *skb,
1003 struct hermes_rx_descriptor *desc)
1004{
1005 struct orinoco_private *priv = netdev_priv(dev);
1006
1007 /* Using spy support with lots of Rx packets, like in an
1008 * infrastructure (AP), will really slow down everything, because
1009 * the MAC address must be compared to each entry of the spy list.
1010 * If the user really asks for it (set some address in the
1011 * spy list), we do it, but he will pay the price.
1012 * Note that to get here, you need both WIRELESS_SPY
1013 * compiled in AND some addresses in the list !!!
1014 */
1015 /* Note : gcc will optimise the whole section away if
1016 * WIRELESS_SPY is not defined... - Jean II */
1017 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07001018 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 desc->signal, desc->silence);
1020 }
1021}
1022
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001023/*
1024 * orinoco_rx_monitor - handle received monitor frames.
1025 *
1026 * Arguments:
1027 * dev network device
1028 * rxfid received FID
1029 * desc rx descriptor of the frame
1030 *
1031 * Call context: interrupt
1032 */
1033static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1034 struct hermes_rx_descriptor *desc)
1035{
1036 u32 hdrlen = 30; /* return full header by default */
1037 u32 datalen = 0;
1038 u16 fc;
1039 int err;
1040 int len;
1041 struct sk_buff *skb;
1042 struct orinoco_private *priv = netdev_priv(dev);
1043 struct net_device_stats *stats = &priv->stats;
1044 hermes_t *hw = &priv->hw;
1045
1046 len = le16_to_cpu(desc->data_len);
1047
1048 /* Determine the size of the header and the data */
1049 fc = le16_to_cpu(desc->frame_ctl);
1050 switch (fc & IEEE80211_FCTL_FTYPE) {
1051 case IEEE80211_FTYPE_DATA:
1052 if ((fc & IEEE80211_FCTL_TODS)
1053 && (fc & IEEE80211_FCTL_FROMDS))
1054 hdrlen = 30;
1055 else
1056 hdrlen = 24;
1057 datalen = len;
1058 break;
1059 case IEEE80211_FTYPE_MGMT:
1060 hdrlen = 24;
1061 datalen = len;
1062 break;
1063 case IEEE80211_FTYPE_CTL:
1064 switch (fc & IEEE80211_FCTL_STYPE) {
1065 case IEEE80211_STYPE_PSPOLL:
1066 case IEEE80211_STYPE_RTS:
1067 case IEEE80211_STYPE_CFEND:
1068 case IEEE80211_STYPE_CFENDACK:
1069 hdrlen = 16;
1070 break;
1071 case IEEE80211_STYPE_CTS:
1072 case IEEE80211_STYPE_ACK:
1073 hdrlen = 10;
1074 break;
1075 }
1076 break;
1077 default:
1078 /* Unknown frame type */
1079 break;
1080 }
1081
1082 /* sanity check the length */
1083 if (datalen > IEEE80211_DATA_LEN + 12) {
1084 printk(KERN_DEBUG "%s: oversized monitor frame, "
1085 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001086 stats->rx_length_errors++;
1087 goto update_stats;
1088 }
1089
1090 skb = dev_alloc_skb(hdrlen + datalen);
1091 if (!skb) {
1092 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1093 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -07001094 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001095 }
1096
1097 /* Copy the 802.11 header to the skb */
1098 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001099 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001100
1101 /* If any, copy the data from the card to the skb */
1102 if (datalen > 0) {
1103 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1104 ALIGN(datalen, 2), rxfid,
1105 HERMES_802_2_OFFSET);
1106 if (err) {
1107 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1108 dev->name, err);
1109 goto drop;
1110 }
1111 }
1112
1113 skb->dev = dev;
1114 skb->ip_summed = CHECKSUM_NONE;
1115 skb->pkt_type = PACKET_OTHERHOST;
1116 skb->protocol = __constant_htons(ETH_P_802_2);
1117
1118 dev->last_rx = jiffies;
1119 stats->rx_packets++;
1120 stats->rx_bytes += skb->len;
1121
1122 netif_rx(skb);
1123 return;
1124
1125 drop:
1126 dev_kfree_skb_irq(skb);
1127 update_stats:
1128 stats->rx_errors++;
1129 stats->rx_dropped++;
1130}
1131
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1133{
1134 struct orinoco_private *priv = netdev_priv(dev);
1135 struct net_device_stats *stats = &priv->stats;
1136 struct iw_statistics *wstats = &priv->wstats;
1137 struct sk_buff *skb = NULL;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001138 u16 rxfid, status, fc;
1139 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 struct hermes_rx_descriptor desc;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001141 struct ethhdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 int err;
1143
1144 rxfid = hermes_read_regn(hw, RXFID);
1145
1146 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1147 rxfid, 0);
1148 if (err) {
1149 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1150 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001151 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 }
1153
1154 status = le16_to_cpu(desc.status);
1155
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001156 if (status & HERMES_RXSTAT_BADCRC) {
1157 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1158 dev->name);
1159 stats->rx_crc_errors++;
1160 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 }
1162
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001163 /* Handle frames in monitor mode */
1164 if (priv->iw_mode == IW_MODE_MONITOR) {
1165 orinoco_rx_monitor(dev, rxfid, &desc);
1166 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
1168
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001169 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1170 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1171 dev->name);
1172 wstats->discard.code++;
1173 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001176 length = le16_to_cpu(desc.data_len);
1177 fc = le16_to_cpu(desc.frame_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 /* Sanity checks */
1180 if (length < 3) { /* No for even an 802.2 LLC header */
1181 /* At least on Symbol firmware with PCF we get quite a
1182 lot of these legitimately - Poll frames with no
1183 data. */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001184 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001186 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1188 dev->name, length);
1189 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001190 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192
1193 /* We need space for the packet data itself, plus an ethernet
1194 header, plus 2 bytes so we can align the IP header on a
1195 32bit boundary, plus 1 byte so we can read in odd length
1196 packets from the card, which has an IO granularity of 16
1197 bits */
1198 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1199 if (!skb) {
1200 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1201 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001202 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
1204
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001205 /* We'll prepend the header, so reserve space for it. The worst
1206 case is no decapsulation, when 802.3 header is prepended and
1207 nothing is removed. 2 is for aligning the IP header. */
1208 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001210 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1211 ALIGN(length, 2), rxfid,
1212 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 if (err) {
1214 printk(KERN_ERR "%s: error %d reading frame. "
1215 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 goto drop;
1217 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 /* Handle decapsulation
1220 * In most cases, the firmware tell us about SNAP frames.
1221 * For some reason, the SNAP frames sent by LinkSys APs
1222 * are not properly recognised by most firmwares.
1223 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001224 if (length >= ENCAPS_OVERHEAD &&
1225 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1226 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1227 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 /* These indicate a SNAP within 802.2 LLC within
1229 802.11 frame which we'll need to de-encapsulate to
1230 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001231 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001233 /* 802.3 frame - prepend 802.3 header as is */
1234 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1235 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001237 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
1238 if (fc & IEEE80211_FCTL_FROMDS)
1239 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
1240 else
1241 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 dev->last_rx = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 skb->protocol = eth_type_trans(skb, dev);
1245 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001246 if (fc & IEEE80211_FCTL_TODS)
1247 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
1249 /* Process the wireless stats if needed */
1250 orinoco_stat_gather(dev, skb, &desc);
1251
1252 /* Pass the packet to the networking stack */
1253 netif_rx(skb);
1254 stats->rx_packets++;
1255 stats->rx_bytes += length;
1256
1257 return;
1258
1259 drop:
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001260 dev_kfree_skb_irq(skb);
1261 update_stats:
1262 stats->rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 stats->rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264}
1265
1266/********************************************************************/
1267/* Rx path (info frames) */
1268/********************************************************************/
1269
1270static void print_linkstatus(struct net_device *dev, u16 status)
1271{
1272 char * s;
1273
1274 if (suppress_linkstatus)
1275 return;
1276
1277 switch (status) {
1278 case HERMES_LINKSTATUS_NOT_CONNECTED:
1279 s = "Not Connected";
1280 break;
1281 case HERMES_LINKSTATUS_CONNECTED:
1282 s = "Connected";
1283 break;
1284 case HERMES_LINKSTATUS_DISCONNECTED:
1285 s = "Disconnected";
1286 break;
1287 case HERMES_LINKSTATUS_AP_CHANGE:
1288 s = "AP Changed";
1289 break;
1290 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1291 s = "AP Out of Range";
1292 break;
1293 case HERMES_LINKSTATUS_AP_IN_RANGE:
1294 s = "AP In Range";
1295 break;
1296 case HERMES_LINKSTATUS_ASSOC_FAILED:
1297 s = "Association Failed";
1298 break;
1299 default:
1300 s = "UNKNOWN";
1301 }
1302
1303 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1304 dev->name, s, status);
1305}
1306
Christoph Hellwig16739b02005-06-19 01:27:51 +02001307/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001308static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001309{
David Howellsc4028952006-11-22 14:57:56 +00001310 struct orinoco_private *priv =
1311 container_of(work, struct orinoco_private, join_work);
1312 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001313 struct hermes *hw = &priv->hw;
1314 int err;
1315 unsigned long flags;
1316 struct join_req {
1317 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001318 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001319 } __attribute__ ((packed)) req;
1320 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001321 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001322 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001323 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001324 u8 *buf;
1325 u16 len;
1326
1327 /* Allocate buffer for scan results */
1328 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1329 if (! buf)
1330 return;
1331
1332 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001333 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001334
1335 /* Sanity checks in case user changed something in the meantime */
1336 if (! priv->bssid_fixed)
1337 goto out;
1338
1339 if (strlen(priv->desired_essid) == 0)
1340 goto out;
1341
1342 /* Read scan results from the firmware */
1343 err = hermes_read_ltv(hw, USER_BAP,
1344 HERMES_RID_SCANRESULTSTABLE,
1345 MAX_SCAN_LEN, &len, buf);
1346 if (err) {
1347 printk(KERN_ERR "%s: Cannot read scan results\n",
1348 dev->name);
1349 goto out;
1350 }
1351
1352 len = HERMES_RECLEN_TO_BYTES(len);
1353
1354 /* Go through the scan results looking for the channel of the AP
1355 * we were requested to join */
1356 for (; offset + atom_len <= len; offset += atom_len) {
1357 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001358 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1359 found = 1;
1360 break;
1361 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001362 }
1363
Pavel Roskinc89cc222005-09-01 20:06:06 -04001364 if (! found) {
1365 DEBUG(1, "%s: Requested AP not found in scan results\n",
1366 dev->name);
1367 goto out;
1368 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001369
Christoph Hellwig16739b02005-06-19 01:27:51 +02001370 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1371 req.channel = atom->channel; /* both are little-endian */
1372 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1373 &req);
1374 if (err)
1375 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1376
1377 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001378 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001379
1380 fail_lock:
1381 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001382}
1383
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001384/* Send new BSSID to userspace */
David Howellsc4028952006-11-22 14:57:56 +00001385static void orinoco_send_wevents(struct work_struct *work)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001386{
David Howellsc4028952006-11-22 14:57:56 +00001387 struct orinoco_private *priv =
1388 container_of(work, struct orinoco_private, wevent_work);
1389 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001390 struct hermes *hw = &priv->hw;
1391 union iwreq_data wrqu;
1392 int err;
1393 unsigned long flags;
1394
1395 if (orinoco_lock(priv, &flags) != 0)
1396 return;
1397
1398 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1399 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1400 if (err != 0)
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001401 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001402
1403 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1404
1405 /* Send event to user space */
1406 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001407
1408 out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001409 orinoco_unlock(priv, &flags);
1410}
1411
Dan Williams1e3428e2007-10-10 23:56:25 -04001412
1413static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1414 unsigned long scan_age)
1415{
1416 bss_element *bss;
1417 bss_element *tmp_bss;
1418
1419 /* Blow away current list of scan results */
1420 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1421 if (!scan_age ||
1422 time_after(jiffies, bss->last_scanned + scan_age)) {
1423 list_move_tail(&bss->list, &priv->bss_free_list);
1424 /* Don't blow away ->list, just BSS data */
1425 memset(bss, 0, sizeof(bss->bss));
1426 bss->last_scanned = 0;
1427 }
1428 }
1429}
1430
1431static int orinoco_process_scan_results(struct net_device *dev,
1432 unsigned char *buf,
1433 int len)
1434{
1435 struct orinoco_private *priv = netdev_priv(dev);
1436 int offset; /* In the scan data */
1437 union hermes_scan_info *atom;
1438 int atom_len;
1439
1440 switch (priv->firmware_type) {
1441 case FIRMWARE_TYPE_AGERE:
1442 atom_len = sizeof(struct agere_scan_apinfo);
1443 offset = 0;
1444 break;
1445 case FIRMWARE_TYPE_SYMBOL:
1446 /* Lack of documentation necessitates this hack.
1447 * Different firmwares have 68 or 76 byte long atoms.
1448 * We try modulo first. If the length divides by both,
1449 * we check what would be the channel in the second
1450 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1451 * Valid channel cannot be 0. */
1452 if (len % 76)
1453 atom_len = 68;
1454 else if (len % 68)
1455 atom_len = 76;
1456 else if (len >= 1292 && buf[68] == 0)
1457 atom_len = 76;
1458 else
1459 atom_len = 68;
1460 offset = 0;
1461 break;
1462 case FIRMWARE_TYPE_INTERSIL:
1463 offset = 4;
1464 if (priv->has_hostscan) {
1465 atom_len = le16_to_cpup((__le16 *)buf);
1466 /* Sanity check for atom_len */
1467 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1468 printk(KERN_ERR "%s: Invalid atom_len in scan "
1469 "data: %d\n", dev->name, atom_len);
1470 return -EIO;
1471 }
1472 } else
1473 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1474 break;
1475 default:
1476 return -EOPNOTSUPP;
1477 }
1478
1479 /* Check that we got an whole number of atoms */
1480 if ((len - offset) % atom_len) {
1481 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1482 "atom_len %d, offset %d\n", dev->name, len,
1483 atom_len, offset);
1484 return -EIO;
1485 }
1486
1487 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1488
1489 /* Read the entries one by one */
1490 for (; offset + atom_len <= len; offset += atom_len) {
1491 int found = 0;
Dan Williams22367612007-12-05 11:01:23 -05001492 bss_element *bss = NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -04001493
1494 /* Get next atom */
1495 atom = (union hermes_scan_info *) (buf + offset);
1496
1497 /* Try to update an existing bss first */
1498 list_for_each_entry(bss, &priv->bss_list, list) {
1499 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1500 continue;
1501 if (le16_to_cpu(bss->bss.a.essid_len) !=
1502 le16_to_cpu(atom->a.essid_len))
1503 continue;
1504 if (memcmp(bss->bss.a.essid, atom->a.essid,
1505 le16_to_cpu(atom->a.essid_len)))
1506 continue;
Dan Williams1e3428e2007-10-10 23:56:25 -04001507 found = 1;
1508 break;
1509 }
1510
1511 /* Grab a bss off the free list */
1512 if (!found && !list_empty(&priv->bss_free_list)) {
1513 bss = list_entry(priv->bss_free_list.next,
1514 bss_element, list);
1515 list_del(priv->bss_free_list.next);
1516
Dan Williams1e3428e2007-10-10 23:56:25 -04001517 list_add_tail(&bss->list, &priv->bss_list);
1518 }
Dan Williams22367612007-12-05 11:01:23 -05001519
1520 if (bss) {
1521 /* Always update the BSS to get latest beacon info */
1522 memcpy(&bss->bss, atom, sizeof(bss->bss));
1523 bss->last_scanned = jiffies;
1524 }
Dan Williams1e3428e2007-10-10 23:56:25 -04001525 }
1526
1527 return 0;
1528}
1529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1531{
1532 struct orinoco_private *priv = netdev_priv(dev);
1533 u16 infofid;
1534 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001535 __le16 len;
1536 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 } __attribute__ ((packed)) info;
1538 int len, type;
1539 int err;
1540
1541 /* This is an answer to an INQUIRE command that we did earlier,
1542 * or an information "event" generated by the card
1543 * The controller return to us a pseudo frame containing
1544 * the information in question - Jean II */
1545 infofid = hermes_read_regn(hw, INFOFID);
1546
1547 /* Read the info frame header - don't try too hard */
1548 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1549 infofid, 0);
1550 if (err) {
1551 printk(KERN_ERR "%s: error %d reading info frame. "
1552 "Frame dropped.\n", dev->name, err);
1553 return;
1554 }
1555
1556 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1557 type = le16_to_cpu(info.type);
1558
1559 switch (type) {
1560 case HERMES_INQ_TALLIES: {
1561 struct hermes_tallies_frame tallies;
1562 struct iw_statistics *wstats = &priv->wstats;
1563
1564 if (len > sizeof(tallies)) {
1565 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1566 dev->name, len);
1567 len = sizeof(tallies);
1568 }
1569
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001570 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1571 infofid, sizeof(info));
1572 if (err)
1573 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
1575 /* Increment our various counters */
1576 /* wstats->discard.nwid - no wrong BSSID stuff */
1577 wstats->discard.code +=
1578 le16_to_cpu(tallies.RxWEPUndecryptable);
1579 if (len == sizeof(tallies))
1580 wstats->discard.code +=
1581 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1582 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1583 wstats->discard.misc +=
1584 le16_to_cpu(tallies.TxDiscardsWrongSA);
1585 wstats->discard.fragment +=
1586 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1587 wstats->discard.retries +=
1588 le16_to_cpu(tallies.TxRetryLimitExceeded);
1589 /* wstats->miss.beacon - no match */
1590 }
1591 break;
1592 case HERMES_INQ_LINKSTATUS: {
1593 struct hermes_linkstatus linkstatus;
1594 u16 newstatus;
1595 int connected;
1596
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001597 if (priv->iw_mode == IW_MODE_MONITOR)
1598 break;
1599
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 if (len != sizeof(linkstatus)) {
1601 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1602 dev->name, len);
1603 break;
1604 }
1605
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001606 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1607 infofid, sizeof(info));
1608 if (err)
1609 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 newstatus = le16_to_cpu(linkstatus.linkstatus);
1611
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001612 /* Symbol firmware uses "out of range" to signal that
1613 * the hostscan frame can be requested. */
1614 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1615 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1616 priv->has_hostscan && priv->scan_inprogress) {
1617 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1618 break;
1619 }
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1622 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1623 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1624
1625 if (connected)
1626 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001627 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 netif_carrier_off(dev);
1629
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001630 if (newstatus != priv->last_linkstatus) {
1631 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001633 /* The info frame contains only one word which is the
1634 * status (see hermes.h). The status is pretty boring
1635 * in itself, that's why we export the new BSSID...
1636 * Jean II */
1637 schedule_work(&priv->wevent_work);
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 }
1640 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001641 case HERMES_INQ_SCAN:
1642 if (!priv->scan_inprogress && priv->bssid_fixed &&
1643 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1644 schedule_work(&priv->join_work);
1645 break;
1646 }
1647 /* fall through */
1648 case HERMES_INQ_HOSTSCAN:
1649 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1650 /* Result of a scanning. Contains information about
1651 * cells in the vicinity - Jean II */
1652 union iwreq_data wrqu;
1653 unsigned char *buf;
1654
Dan Williams1e3428e2007-10-10 23:56:25 -04001655 /* Scan is no longer in progress */
1656 priv->scan_inprogress = 0;
1657
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001658 /* Sanity check */
1659 if (len > 4096) {
1660 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1661 dev->name, len);
1662 break;
1663 }
1664
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001665 /* Allocate buffer for results */
1666 buf = kmalloc(len, GFP_ATOMIC);
1667 if (buf == NULL)
1668 /* No memory, so can't printk()... */
1669 break;
1670
1671 /* Read scan data */
1672 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1673 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001674 if (err) {
1675 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001676 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001677 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001678
1679#ifdef ORINOCO_DEBUG
1680 {
1681 int i;
1682 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1683 for(i = 1; i < (len * 2); i++)
1684 printk(":%02X", buf[i]);
1685 printk("]\n");
1686 }
1687#endif /* ORINOCO_DEBUG */
1688
Dan Williams1e3428e2007-10-10 23:56:25 -04001689 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1690 /* Send an empty event to user space.
1691 * We don't send the received data on the event because
1692 * it would require us to do complex transcoding, and
1693 * we want to minimise the work done in the irq handler
1694 * Use a request to extract the data - Jean II */
1695 wrqu.data.length = 0;
1696 wrqu.data.flags = 0;
1697 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1698 }
1699 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001700 }
1701 break;
1702 case HERMES_INQ_SEC_STAT_AGERE:
1703 /* Security status (Agere specific) */
1704 /* Ignore this frame for now */
1705 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1706 break;
1707 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 default:
1709 printk(KERN_DEBUG "%s: Unknown information frame received: "
1710 "type 0x%04x, length %d\n", dev->name, type, len);
1711 /* We don't actually do anything about it */
1712 break;
1713 }
1714}
1715
1716static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1717{
1718 if (net_ratelimit())
1719 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1720}
1721
1722/********************************************************************/
1723/* Internal hardware control routines */
1724/********************************************************************/
1725
1726int __orinoco_up(struct net_device *dev)
1727{
1728 struct orinoco_private *priv = netdev_priv(dev);
1729 struct hermes *hw = &priv->hw;
1730 int err;
1731
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001732 netif_carrier_off(dev); /* just to make sure */
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 err = __orinoco_program_rids(dev);
1735 if (err) {
1736 printk(KERN_ERR "%s: Error %d configuring card\n",
1737 dev->name, err);
1738 return err;
1739 }
1740
1741 /* Fire things up again */
1742 hermes_set_irqmask(hw, ORINOCO_INTEN);
1743 err = hermes_enable_port(hw, 0);
1744 if (err) {
1745 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1746 dev->name, err);
1747 return err;
1748 }
1749
1750 netif_start_queue(dev);
1751
1752 return 0;
1753}
1754
1755int __orinoco_down(struct net_device *dev)
1756{
1757 struct orinoco_private *priv = netdev_priv(dev);
1758 struct hermes *hw = &priv->hw;
1759 int err;
1760
1761 netif_stop_queue(dev);
1762
1763 if (! priv->hw_unavailable) {
1764 if (! priv->broken_disableport) {
1765 err = hermes_disable_port(hw, 0);
1766 if (err) {
1767 /* Some firmwares (e.g. Intersil 1.3.x) seem
1768 * to have problems disabling the port, oh
1769 * well, too bad. */
1770 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1771 dev->name, err);
1772 priv->broken_disableport = 1;
1773 }
1774 }
1775 hermes_set_irqmask(hw, 0);
1776 hermes_write_regn(hw, EVACK, 0xffff);
1777 }
1778
1779 /* firmware will have to reassociate */
1780 netif_carrier_off(dev);
1781 priv->last_linkstatus = 0xffff;
1782
1783 return 0;
1784}
1785
Pavel Roskin37a6c612006-04-07 04:10:49 -04001786static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787{
1788 struct orinoco_private *priv = netdev_priv(dev);
1789 struct hermes *hw = &priv->hw;
1790 int err;
1791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001793 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 /* Try workaround for old Symbol firmware bug */
1795 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1796 "(old Symbol firmware?). Trying to work around... ",
1797 dev->name);
1798
1799 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1800 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1801 if (err)
1802 printk("failed!\n");
1803 else
1804 printk("ok.\n");
1805 }
1806
1807 return err;
1808}
1809
Pavel Roskin37a6c612006-04-07 04:10:49 -04001810int orinoco_reinit_firmware(struct net_device *dev)
1811{
1812 struct orinoco_private *priv = netdev_priv(dev);
1813 struct hermes *hw = &priv->hw;
1814 int err;
1815
1816 err = hermes_init(hw);
1817 if (!err)
1818 err = orinoco_allocate_fid(dev);
1819
1820 return err;
1821}
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1824{
1825 hermes_t *hw = &priv->hw;
1826 int err = 0;
1827
1828 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1829 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1830 priv->ndev->name, priv->bitratemode);
1831 return -EINVAL;
1832 }
1833
1834 switch (priv->firmware_type) {
1835 case FIRMWARE_TYPE_AGERE:
1836 err = hermes_write_wordrec(hw, USER_BAP,
1837 HERMES_RID_CNFTXRATECONTROL,
1838 bitrate_table[priv->bitratemode].agere_txratectrl);
1839 break;
1840 case FIRMWARE_TYPE_INTERSIL:
1841 case FIRMWARE_TYPE_SYMBOL:
1842 err = hermes_write_wordrec(hw, USER_BAP,
1843 HERMES_RID_CNFTXRATECONTROL,
1844 bitrate_table[priv->bitratemode].intersil_txratectrl);
1845 break;
1846 default:
1847 BUG();
1848 }
1849
1850 return err;
1851}
1852
Christoph Hellwig16739b02005-06-19 01:27:51 +02001853/* Set fixed AP address */
1854static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1855{
1856 int roaming_flag;
1857 int err = 0;
1858 hermes_t *hw = &priv->hw;
1859
1860 switch (priv->firmware_type) {
1861 case FIRMWARE_TYPE_AGERE:
1862 /* not supported */
1863 break;
1864 case FIRMWARE_TYPE_INTERSIL:
1865 if (priv->bssid_fixed)
1866 roaming_flag = 2;
1867 else
1868 roaming_flag = 1;
1869
1870 err = hermes_write_wordrec(hw, USER_BAP,
1871 HERMES_RID_CNFROAMINGMODE,
1872 roaming_flag);
1873 break;
1874 case FIRMWARE_TYPE_SYMBOL:
1875 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1876 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1877 &priv->desired_bssid);
1878 break;
1879 }
1880 return err;
1881}
1882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883/* Change the WEP keys and/or the current keys. Can be called
1884 * either from __orinoco_hw_setup_wep() or directly from
1885 * orinoco_ioctl_setiwencode(). In the later case the association
1886 * with the AP is not broken (if the firmware can handle it),
1887 * which is needed for 802.1x implementations. */
1888static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1889{
1890 hermes_t *hw = &priv->hw;
1891 int err = 0;
1892
1893 switch (priv->firmware_type) {
1894 case FIRMWARE_TYPE_AGERE:
1895 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1896 HERMES_RID_CNFWEPKEYS_AGERE,
1897 &priv->keys);
1898 if (err)
1899 return err;
1900 err = hermes_write_wordrec(hw, USER_BAP,
1901 HERMES_RID_CNFTXKEY_AGERE,
1902 priv->tx_key);
1903 if (err)
1904 return err;
1905 break;
1906 case FIRMWARE_TYPE_INTERSIL:
1907 case FIRMWARE_TYPE_SYMBOL:
1908 {
1909 int keylen;
1910 int i;
1911
1912 /* Force uniform key length to work around firmware bugs */
1913 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1914
1915 if (keylen > LARGE_KEY_SIZE) {
1916 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1917 priv->ndev->name, priv->tx_key, keylen);
1918 return -E2BIG;
1919 }
1920
1921 /* Write all 4 keys */
1922 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1923 err = hermes_write_ltv(hw, USER_BAP,
1924 HERMES_RID_CNFDEFAULTKEY0 + i,
1925 HERMES_BYTES_TO_RECLEN(keylen),
1926 priv->keys[i].data);
1927 if (err)
1928 return err;
1929 }
1930
1931 /* Write the index of the key used in transmission */
1932 err = hermes_write_wordrec(hw, USER_BAP,
1933 HERMES_RID_CNFWEPDEFAULTKEYID,
1934 priv->tx_key);
1935 if (err)
1936 return err;
1937 }
1938 break;
1939 }
1940
1941 return 0;
1942}
1943
1944static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1945{
1946 hermes_t *hw = &priv->hw;
1947 int err = 0;
1948 int master_wep_flag;
1949 int auth_flag;
1950
1951 if (priv->wep_on)
1952 __orinoco_hw_setup_wepkeys(priv);
1953
1954 if (priv->wep_restrict)
1955 auth_flag = HERMES_AUTH_SHARED_KEY;
1956 else
1957 auth_flag = HERMES_AUTH_OPEN;
1958
1959 switch (priv->firmware_type) {
1960 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1961 if (priv->wep_on) {
1962 /* Enable the shared-key authentication. */
1963 err = hermes_write_wordrec(hw, USER_BAP,
1964 HERMES_RID_CNFAUTHENTICATION_AGERE,
1965 auth_flag);
1966 }
1967 err = hermes_write_wordrec(hw, USER_BAP,
1968 HERMES_RID_CNFWEPENABLED_AGERE,
1969 priv->wep_on);
1970 if (err)
1971 return err;
1972 break;
1973
1974 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1975 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1976 if (priv->wep_on) {
1977 if (priv->wep_restrict ||
1978 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1979 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1980 HERMES_WEP_EXCL_UNENCRYPTED;
1981 else
1982 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1983
1984 err = hermes_write_wordrec(hw, USER_BAP,
1985 HERMES_RID_CNFAUTHENTICATION,
1986 auth_flag);
1987 if (err)
1988 return err;
1989 } else
1990 master_wep_flag = 0;
1991
1992 if (priv->iw_mode == IW_MODE_MONITOR)
1993 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1994
1995 /* Master WEP setting : on/off */
1996 err = hermes_write_wordrec(hw, USER_BAP,
1997 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1998 master_wep_flag);
1999 if (err)
2000 return err;
2001
2002 break;
2003 }
2004
2005 return 0;
2006}
2007
2008static int __orinoco_program_rids(struct net_device *dev)
2009{
2010 struct orinoco_private *priv = netdev_priv(dev);
2011 hermes_t *hw = &priv->hw;
2012 int err;
2013 struct hermes_idstring idbuf;
2014
2015 /* Set the MAC address */
2016 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2017 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2018 if (err) {
2019 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2020 dev->name, err);
2021 return err;
2022 }
2023
2024 /* Set up the link mode */
2025 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2026 priv->port_type);
2027 if (err) {
2028 printk(KERN_ERR "%s: Error %d setting port type\n",
2029 dev->name, err);
2030 return err;
2031 }
2032 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04002033 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2034 err = hermes_write_wordrec(hw, USER_BAP,
2035 HERMES_RID_CNFOWNCHANNEL,
2036 priv->channel);
2037 if (err) {
2038 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2039 dev->name, err, priv->channel);
2040 return err;
2041 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 }
2043
2044 if (priv->has_ibss) {
2045 u16 createibss;
2046
2047 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2048 printk(KERN_WARNING "%s: This firmware requires an "
2049 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2050 /* With wvlan_cs, in this case, we would crash.
2051 * hopefully, this driver will behave better...
2052 * Jean II */
2053 createibss = 0;
2054 } else {
2055 createibss = priv->createibss;
2056 }
2057
2058 err = hermes_write_wordrec(hw, USER_BAP,
2059 HERMES_RID_CNFCREATEIBSS,
2060 createibss);
2061 if (err) {
2062 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2063 dev->name, err);
2064 return err;
2065 }
2066 }
2067
Christoph Hellwig16739b02005-06-19 01:27:51 +02002068 /* Set the desired BSSID */
2069 err = __orinoco_hw_set_wap(priv);
2070 if (err) {
2071 printk(KERN_ERR "%s: Error %d setting AP address\n",
2072 dev->name, err);
2073 return err;
2074 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 /* Set the desired ESSID */
2076 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2077 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2078 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2079 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2080 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2081 &idbuf);
2082 if (err) {
2083 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2084 dev->name, err);
2085 return err;
2086 }
2087 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2088 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2089 &idbuf);
2090 if (err) {
2091 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2092 dev->name, err);
2093 return err;
2094 }
2095
2096 /* Set the station name */
2097 idbuf.len = cpu_to_le16(strlen(priv->nick));
2098 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2099 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2100 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2101 &idbuf);
2102 if (err) {
2103 printk(KERN_ERR "%s: Error %d setting nickname\n",
2104 dev->name, err);
2105 return err;
2106 }
2107
2108 /* Set AP density */
2109 if (priv->has_sensitivity) {
2110 err = hermes_write_wordrec(hw, USER_BAP,
2111 HERMES_RID_CNFSYSTEMSCALE,
2112 priv->ap_density);
2113 if (err) {
2114 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2115 "Disabling sensitivity control\n",
2116 dev->name, err);
2117
2118 priv->has_sensitivity = 0;
2119 }
2120 }
2121
2122 /* Set RTS threshold */
2123 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2124 priv->rts_thresh);
2125 if (err) {
2126 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2127 dev->name, err);
2128 return err;
2129 }
2130
2131 /* Set fragmentation threshold or MWO robustness */
2132 if (priv->has_mwo)
2133 err = hermes_write_wordrec(hw, USER_BAP,
2134 HERMES_RID_CNFMWOROBUST_AGERE,
2135 priv->mwo_robust);
2136 else
2137 err = hermes_write_wordrec(hw, USER_BAP,
2138 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2139 priv->frag_thresh);
2140 if (err) {
2141 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2142 dev->name, err);
2143 return err;
2144 }
2145
2146 /* Set bitrate */
2147 err = __orinoco_hw_set_bitrate(priv);
2148 if (err) {
2149 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2150 dev->name, err);
2151 return err;
2152 }
2153
2154 /* Set power management */
2155 if (priv->has_pm) {
2156 err = hermes_write_wordrec(hw, USER_BAP,
2157 HERMES_RID_CNFPMENABLED,
2158 priv->pm_on);
2159 if (err) {
2160 printk(KERN_ERR "%s: Error %d setting up PM\n",
2161 dev->name, err);
2162 return err;
2163 }
2164
2165 err = hermes_write_wordrec(hw, USER_BAP,
2166 HERMES_RID_CNFMULTICASTRECEIVE,
2167 priv->pm_mcast);
2168 if (err) {
2169 printk(KERN_ERR "%s: Error %d setting up PM\n",
2170 dev->name, err);
2171 return err;
2172 }
2173 err = hermes_write_wordrec(hw, USER_BAP,
2174 HERMES_RID_CNFMAXSLEEPDURATION,
2175 priv->pm_period);
2176 if (err) {
2177 printk(KERN_ERR "%s: Error %d setting up PM\n",
2178 dev->name, err);
2179 return err;
2180 }
2181 err = hermes_write_wordrec(hw, USER_BAP,
2182 HERMES_RID_CNFPMHOLDOVERDURATION,
2183 priv->pm_timeout);
2184 if (err) {
2185 printk(KERN_ERR "%s: Error %d setting up PM\n",
2186 dev->name, err);
2187 return err;
2188 }
2189 }
2190
2191 /* Set preamble - only for Symbol so far... */
2192 if (priv->has_preamble) {
2193 err = hermes_write_wordrec(hw, USER_BAP,
2194 HERMES_RID_CNFPREAMBLE_SYMBOL,
2195 priv->preamble);
2196 if (err) {
2197 printk(KERN_ERR "%s: Error %d setting preamble\n",
2198 dev->name, err);
2199 return err;
2200 }
2201 }
2202
2203 /* Set up encryption */
2204 if (priv->has_wep) {
2205 err = __orinoco_hw_setup_wep(priv);
2206 if (err) {
2207 printk(KERN_ERR "%s: Error %d activating WEP\n",
2208 dev->name, err);
2209 return err;
2210 }
2211 }
2212
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002213 if (priv->iw_mode == IW_MODE_MONITOR) {
2214 /* Enable monitor mode */
2215 dev->type = ARPHRD_IEEE80211;
2216 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2217 HERMES_TEST_MONITOR, 0, NULL);
2218 } else {
2219 /* Disable monitor mode */
2220 dev->type = ARPHRD_ETHER;
2221 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2222 HERMES_TEST_STOP, 0, NULL);
2223 }
2224 if (err)
2225 return err;
2226
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 /* Set promiscuity / multicast*/
2228 priv->promiscuous = 0;
2229 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07002230
2231 /* FIXME: what about netif_tx_lock */
2232 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 return 0;
2235}
2236
2237/* FIXME: return int? */
2238static void
2239__orinoco_set_multicast_list(struct net_device *dev)
2240{
2241 struct orinoco_private *priv = netdev_priv(dev);
2242 hermes_t *hw = &priv->hw;
2243 int err = 0;
2244 int promisc, mc_count;
2245
2246 /* The Hermes doesn't seem to have an allmulti mode, so we go
2247 * into promiscuous mode and let the upper levels deal. */
2248 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2249 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2250 promisc = 1;
2251 mc_count = 0;
2252 } else {
2253 promisc = 0;
2254 mc_count = dev->mc_count;
2255 }
2256
2257 if (promisc != priv->promiscuous) {
2258 err = hermes_write_wordrec(hw, USER_BAP,
2259 HERMES_RID_CNFPROMISCUOUSMODE,
2260 promisc);
2261 if (err) {
2262 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2263 dev->name, err);
2264 } else
2265 priv->promiscuous = promisc;
2266 }
2267
2268 if (! promisc && (mc_count || priv->mc_count) ) {
2269 struct dev_mc_list *p = dev->mc_list;
2270 struct hermes_multicast mclist;
2271 int i;
2272
2273 for (i = 0; i < mc_count; i++) {
2274 /* paranoia: is list shorter than mc_count? */
2275 BUG_ON(! p);
2276 /* paranoia: bad address size in list? */
2277 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2278
2279 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2280 p = p->next;
2281 }
2282
2283 if (p)
2284 printk(KERN_WARNING "%s: Multicast list is "
2285 "longer than mc_count\n", dev->name);
2286
2287 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2288 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2289 &mclist);
2290 if (err)
2291 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2292 dev->name, err);
2293 else
2294 priv->mc_count = mc_count;
2295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296}
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298/* This must be called from user context, without locks held - use
2299 * schedule_work() */
David Howellsc4028952006-11-22 14:57:56 +00002300static void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301{
David Howellsc4028952006-11-22 14:57:56 +00002302 struct orinoco_private *priv =
2303 container_of(work, struct orinoco_private, reset_work);
2304 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002306 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 unsigned long flags;
2308
2309 if (orinoco_lock(priv, &flags) != 0)
2310 /* When the hardware becomes available again, whatever
2311 * detects that is responsible for re-initializing
2312 * it. So no need for anything further */
2313 return;
2314
2315 netif_stop_queue(dev);
2316
2317 /* Shut off interrupts. Depending on what state the hardware
2318 * is in, this might not work, but we'll try anyway */
2319 hermes_set_irqmask(hw, 0);
2320 hermes_write_regn(hw, EVACK, 0xffff);
2321
2322 priv->hw_unavailable++;
2323 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2324 netif_carrier_off(dev);
2325
2326 orinoco_unlock(priv, &flags);
2327
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002328 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04002329 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002330 priv->scan_inprogress = 0;
2331
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002332 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002334 if (err) {
2335 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2336 "performing hard reset\n", dev->name, err);
2337 goto disable;
2338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 }
2340
David Kilroy3994d502008-08-21 23:27:54 +01002341 if (priv->do_fw_download) {
2342 err = orinoco_download(priv);
2343 if (err)
2344 priv->do_fw_download = 0;
2345 }
2346
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 err = orinoco_reinit_firmware(dev);
2348 if (err) {
2349 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2350 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002351 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
2354 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2355
2356 priv->hw_unavailable--;
2357
2358 /* priv->open or priv->hw_unavailable might have changed while
2359 * we dropped the lock */
2360 if (priv->open && (! priv->hw_unavailable)) {
2361 err = __orinoco_up(dev);
2362 if (err) {
2363 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2364 dev->name, err);
2365 } else
2366 dev->trans_start = jiffies;
2367 }
2368
2369 spin_unlock_irq(&priv->lock);
2370
2371 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002372 disable:
2373 hermes_set_irqmask(hw, 0);
2374 netif_device_detach(dev);
2375 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376}
2377
2378/********************************************************************/
2379/* Interrupt handler */
2380/********************************************************************/
2381
2382static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2383{
2384 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2385}
2386
2387static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2388{
2389 /* This seems to happen a fair bit under load, but ignoring it
2390 seems to work fine...*/
2391 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2392 dev->name);
2393}
2394
David Howells7d12e782006-10-05 14:55:46 +01002395irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04002397 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 struct orinoco_private *priv = netdev_priv(dev);
2399 hermes_t *hw = &priv->hw;
2400 int count = MAX_IRQLOOPS_PER_IRQ;
2401 u16 evstat, events;
2402 /* These are used to detect a runaway interrupt situation */
2403 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2404 * we panic and shut down the hardware */
2405 static int last_irq_jiffy = 0; /* jiffies value the last time
2406 * we were called */
2407 static int loops_this_jiffy = 0;
2408 unsigned long flags;
2409
2410 if (orinoco_lock(priv, &flags) != 0) {
2411 /* If hw is unavailable - we don't know if the irq was
2412 * for us or not */
2413 return IRQ_HANDLED;
2414 }
2415
2416 evstat = hermes_read_regn(hw, EVSTAT);
2417 events = evstat & hw->inten;
2418 if (! events) {
2419 orinoco_unlock(priv, &flags);
2420 return IRQ_NONE;
2421 }
2422
2423 if (jiffies != last_irq_jiffy)
2424 loops_this_jiffy = 0;
2425 last_irq_jiffy = jiffies;
2426
2427 while (events && count--) {
2428 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2429 printk(KERN_WARNING "%s: IRQ handler is looping too "
2430 "much! Resetting.\n", dev->name);
2431 /* Disable interrupts for now */
2432 hermes_set_irqmask(hw, 0);
2433 schedule_work(&priv->reset_work);
2434 break;
2435 }
2436
2437 /* Check the card hasn't been removed */
2438 if (! hermes_present(hw)) {
2439 DEBUG(0, "orinoco_interrupt(): card removed\n");
2440 break;
2441 }
2442
2443 if (events & HERMES_EV_TICK)
2444 __orinoco_ev_tick(dev, hw);
2445 if (events & HERMES_EV_WTERR)
2446 __orinoco_ev_wterr(dev, hw);
2447 if (events & HERMES_EV_INFDROP)
2448 __orinoco_ev_infdrop(dev, hw);
2449 if (events & HERMES_EV_INFO)
2450 __orinoco_ev_info(dev, hw);
2451 if (events & HERMES_EV_RX)
2452 __orinoco_ev_rx(dev, hw);
2453 if (events & HERMES_EV_TXEXC)
2454 __orinoco_ev_txexc(dev, hw);
2455 if (events & HERMES_EV_TX)
2456 __orinoco_ev_tx(dev, hw);
2457 if (events & HERMES_EV_ALLOC)
2458 __orinoco_ev_alloc(dev, hw);
2459
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002460 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
2462 evstat = hermes_read_regn(hw, EVSTAT);
2463 events = evstat & hw->inten;
2464 };
2465
2466 orinoco_unlock(priv, &flags);
2467 return IRQ_HANDLED;
2468}
2469
2470/********************************************************************/
2471/* Initialization */
2472/********************************************************************/
2473
2474struct comp_id {
2475 u16 id, variant, major, minor;
2476} __attribute__ ((packed));
2477
2478static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2479{
2480 if (nic_id->id < 0x8000)
2481 return FIRMWARE_TYPE_AGERE;
2482 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2483 return FIRMWARE_TYPE_SYMBOL;
2484 else
2485 return FIRMWARE_TYPE_INTERSIL;
2486}
2487
2488/* Set priv->firmware type, determine firmware properties */
2489static int determine_firmware(struct net_device *dev)
2490{
2491 struct orinoco_private *priv = netdev_priv(dev);
2492 hermes_t *hw = &priv->hw;
2493 int err;
2494 struct comp_id nic_id, sta_id;
2495 unsigned int firmver;
Hennerich, Michaeldde6d432007-02-05 16:41:35 -08002496 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497
2498 /* Get the hardware version */
2499 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2500 if (err) {
2501 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2502 dev->name, err);
2503 return err;
2504 }
2505
2506 le16_to_cpus(&nic_id.id);
2507 le16_to_cpus(&nic_id.variant);
2508 le16_to_cpus(&nic_id.major);
2509 le16_to_cpus(&nic_id.minor);
2510 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2511 dev->name, nic_id.id, nic_id.variant,
2512 nic_id.major, nic_id.minor);
2513
2514 priv->firmware_type = determine_firmware_type(&nic_id);
2515
2516 /* Get the firmware version */
2517 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2518 if (err) {
2519 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2520 dev->name, err);
2521 return err;
2522 }
2523
2524 le16_to_cpus(&sta_id.id);
2525 le16_to_cpus(&sta_id.variant);
2526 le16_to_cpus(&sta_id.major);
2527 le16_to_cpus(&sta_id.minor);
2528 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2529 dev->name, sta_id.id, sta_id.variant,
2530 sta_id.major, sta_id.minor);
2531
2532 switch (sta_id.id) {
2533 case 0x15:
2534 printk(KERN_ERR "%s: Primary firmware is active\n",
2535 dev->name);
2536 return -ENODEV;
2537 case 0x14b:
2538 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2539 dev->name);
2540 return -ENODEV;
2541 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2542 case 0x21: /* Symbol Spectrum24 Trilogy */
2543 break;
2544 default:
2545 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2546 dev->name);
2547 break;
2548 }
2549
2550 /* Default capabilities */
2551 priv->has_sensitivity = 1;
2552 priv->has_mwo = 0;
2553 priv->has_preamble = 0;
2554 priv->has_port3 = 1;
2555 priv->has_ibss = 1;
2556 priv->has_wep = 0;
2557 priv->has_big_wep = 0;
David Kilroy6eecad72008-08-21 23:27:56 +01002558 priv->has_alt_txcntl = 0;
David Kilroy3994d502008-08-21 23:27:54 +01002559 priv->do_fw_download = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 /* Determine capabilities from the firmware version */
2562 switch (priv->firmware_type) {
2563 case FIRMWARE_TYPE_AGERE:
2564 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2565 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2566 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2567 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2568
2569 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2570
2571 priv->has_ibss = (firmver >= 0x60006);
2572 priv->has_wep = (firmver >= 0x40020);
2573 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2574 Gold cards from the others? */
2575 priv->has_mwo = (firmver >= 0x60000);
2576 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2577 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002578 priv->has_hostscan = (firmver >= 0x8000a);
David Kilroy3994d502008-08-21 23:27:54 +01002579 priv->do_fw_download = 1;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002580 priv->broken_monitor = (firmver >= 0x80000);
David Kilroy6eecad72008-08-21 23:27:56 +01002581 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
2583 /* Tested with Agere firmware :
2584 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2585 * Tested CableTron firmware : 4.32 => Anton */
2586 break;
2587 case FIRMWARE_TYPE_SYMBOL:
2588 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2589 /* Intel MAC : 00:02:B3:* */
2590 /* 3Com MAC : 00:50:DA:* */
2591 memset(tmp, 0, sizeof(tmp));
2592 /* Get the Symbol firmware version */
2593 err = hermes_read_ltv(hw, USER_BAP,
2594 HERMES_RID_SECONDARYVERSION_SYMBOL,
2595 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2596 if (err) {
2597 printk(KERN_WARNING
2598 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2599 dev->name, err);
2600 firmver = 0;
2601 tmp[0] = '\0';
2602 } else {
2603 /* The firmware revision is a string, the format is
2604 * something like : "V2.20-01".
2605 * Quick and dirty parsing... - Jean II
2606 */
2607 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2608 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2609 | (tmp[7] - '0');
2610
2611 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2612 }
2613
2614 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2615 "Symbol %s", tmp);
2616
2617 priv->has_ibss = (firmver >= 0x20000);
2618 priv->has_wep = (firmver >= 0x15012);
2619 priv->has_big_wep = (firmver >= 0x20000);
2620 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2621 (firmver >= 0x29000 && firmver < 0x30000) ||
2622 firmver >= 0x31000;
2623 priv->has_preamble = (firmver >= 0x20000);
2624 priv->ibss_port = 4;
David Kilroy3994d502008-08-21 23:27:54 +01002625
2626 /* Symbol firmware is found on various cards, but
2627 * there has been no attempt to check firmware
2628 * download on non-spectrum_cs based cards.
2629 *
2630 * Given that the Agere firmware download works
2631 * differently, we should avoid doing a firmware
2632 * download with the Symbol algorithm on non-spectrum
2633 * cards.
2634 *
2635 * For now we can identify a spectrum_cs based card
2636 * because it has a firmware reset function.
2637 */
2638 priv->do_fw_download = (priv->stop_fw != NULL);
2639
Christoph Hellwig649e59e2005-05-14 17:30:10 +02002640 priv->broken_disableport = (firmver == 0x25013) ||
2641 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002642 priv->has_hostscan = (firmver >= 0x31001) ||
2643 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 /* Tested with Intel firmware : 0x20015 => Jean II */
2645 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2646 break;
2647 case FIRMWARE_TYPE_INTERSIL:
2648 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2649 * Samsung, Compaq 100/200 and Proxim are slightly
2650 * different and less well tested */
2651 /* D-Link MAC : 00:40:05:* */
2652 /* Addtron MAC : 00:90:D1:* */
2653 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2654 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2655 sta_id.variant);
2656
2657 firmver = ((unsigned long)sta_id.major << 16) |
2658 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2659
2660 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2661 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2662 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002663 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 if (firmver >= 0x000800)
2666 priv->ibss_port = 0;
2667 else {
2668 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2669 "than v0.8.x - several features not supported\n",
2670 dev->name);
2671 priv->ibss_port = 1;
2672 }
2673 break;
2674 }
2675 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2676 priv->fw_name);
2677
2678 return 0;
2679}
2680
2681static int orinoco_init(struct net_device *dev)
2682{
2683 struct orinoco_private *priv = netdev_priv(dev);
2684 hermes_t *hw = &priv->hw;
2685 int err = 0;
2686 struct hermes_idstring nickbuf;
2687 u16 reclen;
2688 int len;
Joe Perches0795af52007-10-03 17:59:30 -07002689 DECLARE_MAC_BUF(mac);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 /* No need to lock, the hw_unavailable flag is already set in
2692 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04002693 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
2695 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04002696 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 if (err != 0) {
2698 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2699 dev->name, err);
2700 goto out;
2701 }
2702
2703 err = determine_firmware(dev);
2704 if (err != 0) {
2705 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2706 dev->name);
2707 goto out;
2708 }
2709
David Kilroy3994d502008-08-21 23:27:54 +01002710 if (priv->do_fw_download) {
2711 err = orinoco_download(priv);
2712 if (err)
2713 priv->do_fw_download = 0;
2714
2715 /* Check firmware version again */
2716 err = determine_firmware(dev);
2717 if (err != 0) {
2718 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2719 dev->name);
2720 goto out;
2721 }
2722 }
2723
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 if (priv->has_port3)
2725 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2726 if (priv->has_ibss)
2727 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2728 dev->name);
2729 if (priv->has_wep) {
2730 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2731 if (priv->has_big_wep)
2732 printk("104-bit key\n");
2733 else
2734 printk("40-bit key\n");
2735 }
2736
2737 /* Get the MAC address */
2738 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2739 ETH_ALEN, NULL, dev->dev_addr);
2740 if (err) {
2741 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2742 dev->name);
2743 goto out;
2744 }
2745
Joe Perches0795af52007-10-03 17:59:30 -07002746 printk(KERN_DEBUG "%s: MAC address %s\n",
2747 dev->name, print_mac(mac, dev->dev_addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748
2749 /* Get the station name */
2750 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2751 sizeof(nickbuf), &reclen, &nickbuf);
2752 if (err) {
2753 printk(KERN_ERR "%s: failed to read station name\n",
2754 dev->name);
2755 goto out;
2756 }
2757 if (nickbuf.len)
2758 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2759 else
2760 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2761 memcpy(priv->nick, &nickbuf.val, len);
2762 priv->nick[len] = '\0';
2763
2764 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2765
Pavel Roskin37a6c612006-04-07 04:10:49 -04002766 err = orinoco_allocate_fid(dev);
2767 if (err) {
2768 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2769 dev->name);
2770 goto out;
2771 }
2772
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 /* Get allowed channels */
2774 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2775 &priv->channel_mask);
2776 if (err) {
2777 printk(KERN_ERR "%s: failed to read channel list!\n",
2778 dev->name);
2779 goto out;
2780 }
2781
2782 /* Get initial AP density */
2783 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2784 &priv->ap_density);
2785 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2786 priv->has_sensitivity = 0;
2787 }
2788
2789 /* Get initial RTS threshold */
2790 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2791 &priv->rts_thresh);
2792 if (err) {
2793 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2794 dev->name);
2795 goto out;
2796 }
2797
2798 /* Get initial fragmentation settings */
2799 if (priv->has_mwo)
2800 err = hermes_read_wordrec(hw, USER_BAP,
2801 HERMES_RID_CNFMWOROBUST_AGERE,
2802 &priv->mwo_robust);
2803 else
2804 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2805 &priv->frag_thresh);
2806 if (err) {
2807 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2808 dev->name);
2809 goto out;
2810 }
2811
2812 /* Power management setup */
2813 if (priv->has_pm) {
2814 priv->pm_on = 0;
2815 priv->pm_mcast = 1;
2816 err = hermes_read_wordrec(hw, USER_BAP,
2817 HERMES_RID_CNFMAXSLEEPDURATION,
2818 &priv->pm_period);
2819 if (err) {
2820 printk(KERN_ERR "%s: failed to read power management period!\n",
2821 dev->name);
2822 goto out;
2823 }
2824 err = hermes_read_wordrec(hw, USER_BAP,
2825 HERMES_RID_CNFPMHOLDOVERDURATION,
2826 &priv->pm_timeout);
2827 if (err) {
2828 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2829 dev->name);
2830 goto out;
2831 }
2832 }
2833
2834 /* Preamble setup */
2835 if (priv->has_preamble) {
2836 err = hermes_read_wordrec(hw, USER_BAP,
2837 HERMES_RID_CNFPREAMBLE_SYMBOL,
2838 &priv->preamble);
2839 if (err)
2840 goto out;
2841 }
2842
2843 /* Set up the default configuration */
2844 priv->iw_mode = IW_MODE_INFRA;
2845 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2846 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2847 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002848 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 priv->promiscuous = 0;
2851 priv->wep_on = 0;
2852 priv->tx_key = 0;
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 /* Make the hardware available, as long as it hasn't been
2855 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2856 spin_lock_irq(&priv->lock);
2857 priv->hw_unavailable--;
2858 spin_unlock_irq(&priv->lock);
2859
2860 printk(KERN_DEBUG "%s: ready\n", dev->name);
2861
2862 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 return err;
2864}
2865
David Kilroy3994d502008-08-21 23:27:54 +01002866struct net_device
2867*alloc_orinocodev(int sizeof_card,
2868 struct device *device,
2869 int (*hard_reset)(struct orinoco_private *),
2870 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871{
2872 struct net_device *dev;
2873 struct orinoco_private *priv;
2874
2875 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2876 if (! dev)
2877 return NULL;
2878 priv = netdev_priv(dev);
2879 priv->ndev = dev;
2880 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002881 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 + sizeof(struct orinoco_private));
2883 else
2884 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01002885 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
Dan Williams1e3428e2007-10-10 23:56:25 -04002887 if (orinoco_bss_data_allocate(priv))
2888 goto err_out_free;
2889 orinoco_bss_data_init(priv);
2890
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 /* Setup / override net_device fields */
2892 dev->init = orinoco_init;
2893 dev->hard_start_xmit = orinoco_xmit;
2894 dev->tx_timeout = orinoco_tx_timeout;
2895 dev->watchdog_timeo = HZ; /* 1 second timeout */
2896 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002897 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002898 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002899#ifdef WIRELESS_SPY
2900 priv->wireless_data.spy_data = &priv->spy_data;
2901 dev->wireless_data = &priv->wireless_data;
2902#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 dev->change_mtu = orinoco_change_mtu;
2904 dev->set_multicast_list = orinoco_set_multicast_list;
2905 /* we use the default eth_mac_addr for setting the MAC addr */
2906
2907 /* Set up default callbacks */
2908 dev->open = orinoco_open;
2909 dev->stop = orinoco_stop;
2910 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01002911 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
2913 spin_lock_init(&priv->lock);
2914 priv->open = 0;
2915 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2916 * before anything else touches the
2917 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00002918 INIT_WORK(&priv->reset_work, orinoco_reset);
2919 INIT_WORK(&priv->join_work, orinoco_join_ap);
2920 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921
2922 netif_carrier_off(dev);
2923 priv->last_linkstatus = 0xffff;
2924
2925 return dev;
2926
Dan Williams1e3428e2007-10-10 23:56:25 -04002927err_out_free:
2928 free_netdev(dev);
2929 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930}
2931
2932void free_orinocodev(struct net_device *dev)
2933{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002934 struct orinoco_private *priv = netdev_priv(dev);
2935
Dan Williams1e3428e2007-10-10 23:56:25 -04002936 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 free_netdev(dev);
2938}
2939
2940/********************************************************************/
2941/* Wireless extensions */
2942/********************************************************************/
2943
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002944/* Return : < 0 -> error code ; >= 0 -> length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2946 char buf[IW_ESSID_MAX_SIZE+1])
2947{
2948 hermes_t *hw = &priv->hw;
2949 int err = 0;
2950 struct hermes_idstring essidbuf;
2951 char *p = (char *)(&essidbuf.val);
2952 int len;
2953 unsigned long flags;
2954
2955 if (orinoco_lock(priv, &flags) != 0)
2956 return -EBUSY;
2957
2958 if (strlen(priv->desired_essid) > 0) {
2959 /* We read the desired SSID from the hardware rather
2960 than from priv->desired_essid, just in case the
2961 firmware is allowed to change it on us. I'm not
2962 sure about this */
2963 /* My guess is that the OWNSSID should always be whatever
2964 * we set to the card, whereas CURRENT_SSID is the one that
2965 * may change... - Jean II */
2966 u16 rid;
2967
2968 *active = 1;
2969
2970 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2971 HERMES_RID_CNFDESIREDSSID;
2972
2973 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2974 NULL, &essidbuf);
2975 if (err)
2976 goto fail_unlock;
2977 } else {
2978 *active = 0;
2979
2980 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2981 sizeof(essidbuf), NULL, &essidbuf);
2982 if (err)
2983 goto fail_unlock;
2984 }
2985
2986 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002987 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002989 memset(buf, 0, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 memcpy(buf, p, len);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07002991 err = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992
2993 fail_unlock:
2994 orinoco_unlock(priv, &flags);
2995
2996 return err;
2997}
2998
2999static long orinoco_hw_get_freq(struct orinoco_private *priv)
3000{
3001
3002 hermes_t *hw = &priv->hw;
3003 int err = 0;
3004 u16 channel;
3005 long freq = 0;
3006 unsigned long flags;
3007
3008 if (orinoco_lock(priv, &flags) != 0)
3009 return -EBUSY;
3010
3011 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3012 if (err)
3013 goto out;
3014
3015 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3016 if (channel == 0) {
3017 err = -EBUSY;
3018 goto out;
3019 }
3020
3021 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3022 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3023 priv->ndev->name, channel);
3024 err = -EBUSY;
3025 goto out;
3026
3027 }
3028 freq = channel_frequency[channel-1] * 100000;
3029
3030 out:
3031 orinoco_unlock(priv, &flags);
3032
3033 if (err > 0)
3034 err = -EBUSY;
3035 return err ? err : freq;
3036}
3037
3038static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3039 int *numrates, s32 *rates, int max)
3040{
3041 hermes_t *hw = &priv->hw;
3042 struct hermes_idstring list;
3043 unsigned char *p = (unsigned char *)&list.val;
3044 int err = 0;
3045 int num;
3046 int i;
3047 unsigned long flags;
3048
3049 if (orinoco_lock(priv, &flags) != 0)
3050 return -EBUSY;
3051
3052 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3053 sizeof(list), NULL, &list);
3054 orinoco_unlock(priv, &flags);
3055
3056 if (err)
3057 return err;
3058
3059 num = le16_to_cpu(list.len);
3060 *numrates = num;
3061 num = min(num, max);
3062
3063 for (i = 0; i < num; i++) {
3064 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3065 }
3066
3067 return 0;
3068}
3069
Christoph Hellwig620554e2005-06-19 01:27:33 +02003070static int orinoco_ioctl_getname(struct net_device *dev,
3071 struct iw_request_info *info,
3072 char *name,
3073 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074{
3075 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003077 int err;
3078
3079 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3080
3081 if (!err && (numrates > 2))
3082 strcpy(name, "IEEE 802.11b");
3083 else
3084 strcpy(name, "IEEE 802.11-DS");
3085
3086 return 0;
3087}
3088
Christoph Hellwig16739b02005-06-19 01:27:51 +02003089static int orinoco_ioctl_setwap(struct net_device *dev,
3090 struct iw_request_info *info,
3091 struct sockaddr *ap_addr,
3092 char *extra)
3093{
3094 struct orinoco_private *priv = netdev_priv(dev);
3095 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02003097 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3098 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099
3100 if (orinoco_lock(priv, &flags) != 0)
3101 return -EBUSY;
3102
Christoph Hellwig16739b02005-06-19 01:27:51 +02003103 /* Enable automatic roaming - no sanity checks are needed */
3104 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3105 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3106 priv->bssid_fixed = 0;
3107 memset(priv->desired_bssid, 0, ETH_ALEN);
3108
3109 /* "off" means keep existing connection */
3110 if (ap_addr->sa_data[0] == 0) {
3111 __orinoco_hw_set_wap(priv);
3112 err = 0;
3113 }
3114 goto out;
3115 }
3116
3117 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3118 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3119 "support manual roaming\n",
3120 dev->name);
3121 err = -EOPNOTSUPP;
3122 goto out;
3123 }
3124
3125 if (priv->iw_mode != IW_MODE_INFRA) {
3126 printk(KERN_WARNING "%s: Manual roaming supported only in "
3127 "managed mode\n", dev->name);
3128 err = -EOPNOTSUPP;
3129 goto out;
3130 }
3131
3132 /* Intersil firmware hangs without Desired ESSID */
3133 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3134 strlen(priv->desired_essid) == 0) {
3135 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3136 "manual roaming\n", dev->name);
3137 err = -EOPNOTSUPP;
3138 goto out;
3139 }
3140
3141 /* Finally, enable manual roaming */
3142 priv->bssid_fixed = 1;
3143 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3144
3145 out:
3146 orinoco_unlock(priv, &flags);
3147 return err;
3148}
3149
Christoph Hellwig620554e2005-06-19 01:27:33 +02003150static int orinoco_ioctl_getwap(struct net_device *dev,
3151 struct iw_request_info *info,
3152 struct sockaddr *ap_addr,
3153 char *extra)
3154{
3155 struct orinoco_private *priv = netdev_priv(dev);
3156
3157 hermes_t *hw = &priv->hw;
3158 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159 unsigned long flags;
3160
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 if (orinoco_lock(priv, &flags) != 0)
3162 return -EBUSY;
3163
Christoph Hellwig620554e2005-06-19 01:27:33 +02003164 ap_addr->sa_family = ARPHRD_ETHER;
3165 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3166 ETH_ALEN, NULL, ap_addr->sa_data);
3167
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 orinoco_unlock(priv, &flags);
3169
Christoph Hellwig620554e2005-06-19 01:27:33 +02003170 return err;
3171}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
Christoph Hellwig620554e2005-06-19 01:27:33 +02003173static int orinoco_ioctl_setmode(struct net_device *dev,
3174 struct iw_request_info *info,
3175 u32 *mode,
3176 char *extra)
3177{
3178 struct orinoco_private *priv = netdev_priv(dev);
3179 int err = -EINPROGRESS; /* Call commit handler */
3180 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181
Christoph Hellwig620554e2005-06-19 01:27:33 +02003182 if (priv->iw_mode == *mode)
3183 return 0;
3184
3185 if (orinoco_lock(priv, &flags) != 0)
3186 return -EBUSY;
3187
3188 switch (*mode) {
3189 case IW_MODE_ADHOC:
3190 if (!priv->has_ibss && !priv->has_port3)
3191 err = -EOPNOTSUPP;
3192 break;
3193
3194 case IW_MODE_INFRA:
3195 break;
3196
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003197 case IW_MODE_MONITOR:
3198 if (priv->broken_monitor && !force_monitor) {
3199 printk(KERN_WARNING "%s: Monitor mode support is "
3200 "buggy in this firmware, not enabling\n",
3201 dev->name);
3202 err = -EOPNOTSUPP;
3203 }
3204 break;
3205
Christoph Hellwig620554e2005-06-19 01:27:33 +02003206 default:
3207 err = -EOPNOTSUPP;
3208 break;
3209 }
3210
3211 if (err == -EINPROGRESS) {
3212 priv->iw_mode = *mode;
3213 set_port_type(priv);
3214 }
3215
3216 orinoco_unlock(priv, &flags);
3217
3218 return err;
3219}
3220
3221static int orinoco_ioctl_getmode(struct net_device *dev,
3222 struct iw_request_info *info,
3223 u32 *mode,
3224 char *extra)
3225{
3226 struct orinoco_private *priv = netdev_priv(dev);
3227
3228 *mode = priv->iw_mode;
3229 return 0;
3230}
3231
3232static int orinoco_ioctl_getiwrange(struct net_device *dev,
3233 struct iw_request_info *info,
3234 struct iw_point *rrq,
3235 char *extra)
3236{
3237 struct orinoco_private *priv = netdev_priv(dev);
3238 int err = 0;
3239 struct iw_range *range = (struct iw_range *) extra;
3240 int numrates;
3241 int i, k;
3242
Christoph Hellwig620554e2005-06-19 01:27:33 +02003243 rrq->length = sizeof(struct iw_range);
3244 memset(range, 0, sizeof(struct iw_range));
3245
3246 range->we_version_compiled = WIRELESS_EXT;
3247 range->we_version_source = 14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248
3249 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003250 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 k = 0;
3252 for (i = 0; i < NUM_CHANNELS; i++) {
3253 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003254 range->freq[k].i = i + 1;
3255 range->freq[k].m = channel_frequency[i] * 100000;
3256 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 k++;
3258 }
3259
3260 if (k >= IW_MAX_FREQUENCIES)
3261 break;
3262 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02003263 range->num_frequency = k;
3264 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265
Christoph Hellwig620554e2005-06-19 01:27:33 +02003266 if (priv->has_wep) {
3267 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3268 range->encoding_size[0] = SMALL_KEY_SIZE;
3269 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
Christoph Hellwig620554e2005-06-19 01:27:33 +02003271 if (priv->has_big_wep) {
3272 range->encoding_size[1] = LARGE_KEY_SIZE;
3273 range->num_encoding_sizes = 2;
3274 }
3275 }
3276
Pavel Roskin343c6862005-09-09 18:43:02 -04003277 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003280 range->max_qual.qual = 0x8b - 0x2f;
3281 range->max_qual.level = 0x2f - 0x95 - 1;
3282 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003284 range->avg_qual.qual = 0x24;
3285 range->avg_qual.level = 0xC2;
3286 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 }
3288
3289 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02003290 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 if (err)
3292 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003293 range->num_bitrates = numrates;
3294
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 /* Set an indication of the max TCP throughput in bit/s that we can
3296 * expect using this interface. May be use for QoS stuff...
3297 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003298 if (numrates > 2)
3299 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02003301 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302
Christoph Hellwig620554e2005-06-19 01:27:33 +02003303 range->min_rts = 0;
3304 range->max_rts = 2347;
3305 range->min_frag = 256;
3306 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
Christoph Hellwig620554e2005-06-19 01:27:33 +02003308 range->min_pmp = 0;
3309 range->max_pmp = 65535000;
3310 range->min_pmt = 0;
3311 range->max_pmt = 65535 * 1000; /* ??? */
3312 range->pmp_flags = IW_POWER_PERIOD;
3313 range->pmt_flags = IW_POWER_TIMEOUT;
3314 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315
Christoph Hellwig620554e2005-06-19 01:27:33 +02003316 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3317 range->retry_flags = IW_RETRY_LIMIT;
3318 range->r_time_flags = IW_RETRY_LIFETIME;
3319 range->min_retry = 0;
3320 range->max_retry = 65535; /* ??? */
3321 range->min_r_time = 0;
3322 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
David Kilroy0753bba2008-08-21 23:27:46 +01003324 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3325 range->scan_capa = IW_SCAN_CAPA_ESSID;
3326 else
3327 range->scan_capa = IW_SCAN_CAPA_NONE;
3328
Pavel Roskin343c6862005-09-09 18:43:02 -04003329 /* Event capability (kernel) */
3330 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3331 /* Event capability (driver) */
3332 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3333 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3334 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3335 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3336
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 return 0;
3338}
3339
Christoph Hellwig620554e2005-06-19 01:27:33 +02003340static int orinoco_ioctl_setiwencode(struct net_device *dev,
3341 struct iw_request_info *info,
3342 struct iw_point *erq,
3343 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344{
3345 struct orinoco_private *priv = netdev_priv(dev);
3346 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3347 int setindex = priv->tx_key;
3348 int enable = priv->wep_on;
3349 int restricted = priv->wep_restrict;
3350 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003351 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 unsigned long flags;
3353
3354 if (! priv->has_wep)
3355 return -EOPNOTSUPP;
3356
3357 if (erq->pointer) {
3358 /* We actually have a key to set - check its length */
3359 if (erq->length > LARGE_KEY_SIZE)
3360 return -E2BIG;
3361
3362 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3363 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 }
3365
3366 if (orinoco_lock(priv, &flags) != 0)
3367 return -EBUSY;
3368
Dan Williamsfe397d42006-07-14 11:41:47 -04003369 if (erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3371 index = priv->tx_key;
3372
3373 /* Adjust key length to a supported value */
3374 if (erq->length > SMALL_KEY_SIZE) {
3375 xlen = LARGE_KEY_SIZE;
3376 } else if (erq->length > 0) {
3377 xlen = SMALL_KEY_SIZE;
3378 } else
3379 xlen = 0;
3380
3381 /* Switch on WEP if off */
3382 if ((!enable) && (xlen > 0)) {
3383 setindex = index;
3384 enable = 1;
3385 }
3386 } else {
3387 /* Important note : if the user do "iwconfig eth0 enc off",
3388 * we will arrive there with an index of -1. This is valid
3389 * but need to be taken care off... Jean II */
3390 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3391 if((index != -1) || (erq->flags == 0)) {
3392 err = -EINVAL;
3393 goto out;
3394 }
3395 } else {
3396 /* Set the index : Check that the key is valid */
3397 if(priv->keys[index].len == 0) {
3398 err = -EINVAL;
3399 goto out;
3400 }
3401 setindex = index;
3402 }
3403 }
3404
3405 if (erq->flags & IW_ENCODE_DISABLED)
3406 enable = 0;
3407 if (erq->flags & IW_ENCODE_OPEN)
3408 restricted = 0;
3409 if (erq->flags & IW_ENCODE_RESTRICTED)
3410 restricted = 1;
3411
Dan Williamsfe397d42006-07-14 11:41:47 -04003412 if (erq->pointer && erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 priv->keys[index].len = cpu_to_le16(xlen);
3414 memset(priv->keys[index].data, 0,
3415 sizeof(priv->keys[index].data));
3416 memcpy(priv->keys[index].data, keybuf, erq->length);
3417 }
3418 priv->tx_key = setindex;
3419
3420 /* Try fast key change if connected and only keys are changed */
3421 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
3422 netif_carrier_ok(dev)) {
3423 err = __orinoco_hw_setup_wepkeys(priv);
3424 /* No need to commit if successful */
3425 goto out;
3426 }
3427
3428 priv->wep_on = enable;
3429 priv->wep_restrict = restricted;
3430
3431 out:
3432 orinoco_unlock(priv, &flags);
3433
3434 return err;
3435}
3436
Christoph Hellwig620554e2005-06-19 01:27:33 +02003437static int orinoco_ioctl_getiwencode(struct net_device *dev,
3438 struct iw_request_info *info,
3439 struct iw_point *erq,
3440 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441{
3442 struct orinoco_private *priv = netdev_priv(dev);
3443 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3444 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 unsigned long flags;
3446
3447 if (! priv->has_wep)
3448 return -EOPNOTSUPP;
3449
3450 if (orinoco_lock(priv, &flags) != 0)
3451 return -EBUSY;
3452
3453 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3454 index = priv->tx_key;
3455
3456 erq->flags = 0;
3457 if (! priv->wep_on)
3458 erq->flags |= IW_ENCODE_DISABLED;
3459 erq->flags |= index + 1;
3460
3461 if (priv->wep_restrict)
3462 erq->flags |= IW_ENCODE_RESTRICTED;
3463 else
3464 erq->flags |= IW_ENCODE_OPEN;
3465
3466 xlen = le16_to_cpu(priv->keys[index].len);
3467
3468 erq->length = xlen;
3469
3470 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3471
3472 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 return 0;
3474}
3475
Christoph Hellwig620554e2005-06-19 01:27:33 +02003476static int orinoco_ioctl_setessid(struct net_device *dev,
3477 struct iw_request_info *info,
3478 struct iw_point *erq,
3479 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480{
3481 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 unsigned long flags;
3483
3484 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3485 * anyway... - Jean II */
3486
Christoph Hellwig620554e2005-06-19 01:27:33 +02003487 /* Hum... Should not use Wireless Extension constant (may change),
3488 * should use our own... - Jean II */
3489 if (erq->length > IW_ESSID_MAX_SIZE)
3490 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491
3492 if (orinoco_lock(priv, &flags) != 0)
3493 return -EBUSY;
3494
Christoph Hellwig620554e2005-06-19 01:27:33 +02003495 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3496 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3497
3498 /* If not ANY, get the new ESSID */
3499 if (erq->flags) {
3500 memcpy(priv->desired_essid, essidbuf, erq->length);
3501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502
3503 orinoco_unlock(priv, &flags);
3504
Christoph Hellwig620554e2005-06-19 01:27:33 +02003505 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506}
3507
Christoph Hellwig620554e2005-06-19 01:27:33 +02003508static int orinoco_ioctl_getessid(struct net_device *dev,
3509 struct iw_request_info *info,
3510 struct iw_point *erq,
3511 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512{
3513 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 int active;
3515 int err = 0;
3516 unsigned long flags;
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 if (netif_running(dev)) {
3519 err = orinoco_hw_get_essid(priv, &active, essidbuf);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003520 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 return err;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003522 erq->length = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 } else {
3524 if (orinoco_lock(priv, &flags) != 0)
3525 return -EBUSY;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003526 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3527 erq->length = strlen(priv->desired_essid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003528 orinoco_unlock(priv, &flags);
3529 }
3530
3531 erq->flags = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 return 0;
3534}
3535
Christoph Hellwig620554e2005-06-19 01:27:33 +02003536static int orinoco_ioctl_setnick(struct net_device *dev,
3537 struct iw_request_info *info,
3538 struct iw_point *nrq,
3539 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540{
3541 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 unsigned long flags;
3543
3544 if (nrq->length > IW_ESSID_MAX_SIZE)
3545 return -E2BIG;
3546
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 if (orinoco_lock(priv, &flags) != 0)
3548 return -EBUSY;
3549
Christoph Hellwig620554e2005-06-19 01:27:33 +02003550 memset(priv->nick, 0, sizeof(priv->nick));
3551 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552
3553 orinoco_unlock(priv, &flags);
3554
Christoph Hellwig620554e2005-06-19 01:27:33 +02003555 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556}
3557
Christoph Hellwig620554e2005-06-19 01:27:33 +02003558static int orinoco_ioctl_getnick(struct net_device *dev,
3559 struct iw_request_info *info,
3560 struct iw_point *nrq,
3561 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562{
3563 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 unsigned long flags;
3565
3566 if (orinoco_lock(priv, &flags) != 0)
3567 return -EBUSY;
3568
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003569 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 orinoco_unlock(priv, &flags);
3571
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003572 nrq->length = strlen(priv->nick);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 return 0;
3575}
3576
Christoph Hellwig620554e2005-06-19 01:27:33 +02003577static int orinoco_ioctl_setfreq(struct net_device *dev,
3578 struct iw_request_info *info,
3579 struct iw_freq *frq,
3580 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003581{
3582 struct orinoco_private *priv = netdev_priv(dev);
3583 int chan = -1;
3584 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003585 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003587 /* In infrastructure mode the AP sets the channel */
3588 if (priv->iw_mode == IW_MODE_INFRA)
3589 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003590
3591 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3592 /* Setting by channel number */
3593 chan = frq->m;
3594 } else {
3595 /* Setting by frequency - search the table */
3596 int mult = 1;
3597 int i;
3598
3599 for (i = 0; i < (6 - frq->e); i++)
3600 mult *= 10;
3601
3602 for (i = 0; i < NUM_CHANNELS; i++)
3603 if (frq->m == (channel_frequency[i] * mult))
3604 chan = i+1;
3605 }
3606
3607 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3608 ! (priv->channel_mask & (1 << (chan-1)) ) )
3609 return -EINVAL;
3610
3611 if (orinoco_lock(priv, &flags) != 0)
3612 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003613
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003615 if (priv->iw_mode == IW_MODE_MONITOR) {
3616 /* Fast channel change - no commit if successful */
3617 hermes_t *hw = &priv->hw;
3618 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3619 HERMES_TEST_SET_CHANNEL,
3620 chan, NULL);
3621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622 orinoco_unlock(priv, &flags);
3623
Christoph Hellwig620554e2005-06-19 01:27:33 +02003624 return err;
3625}
3626
3627static int orinoco_ioctl_getfreq(struct net_device *dev,
3628 struct iw_request_info *info,
3629 struct iw_freq *frq,
3630 char *extra)
3631{
3632 struct orinoco_private *priv = netdev_priv(dev);
3633 int tmp;
3634
3635 /* Locking done in there */
3636 tmp = orinoco_hw_get_freq(priv);
3637 if (tmp < 0) {
3638 return tmp;
3639 }
3640
3641 frq->m = tmp;
3642 frq->e = 1;
3643
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 return 0;
3645}
3646
Christoph Hellwig620554e2005-06-19 01:27:33 +02003647static int orinoco_ioctl_getsens(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 hermes_t *hw = &priv->hw;
3654 u16 val;
3655 int err;
3656 unsigned long flags;
3657
3658 if (!priv->has_sensitivity)
3659 return -EOPNOTSUPP;
3660
3661 if (orinoco_lock(priv, &flags) != 0)
3662 return -EBUSY;
3663 err = hermes_read_wordrec(hw, USER_BAP,
3664 HERMES_RID_CNFSYSTEMSCALE, &val);
3665 orinoco_unlock(priv, &flags);
3666
3667 if (err)
3668 return err;
3669
3670 srq->value = val;
3671 srq->fixed = 0; /* auto */
3672
3673 return 0;
3674}
3675
Christoph Hellwig620554e2005-06-19 01:27:33 +02003676static int orinoco_ioctl_setsens(struct net_device *dev,
3677 struct iw_request_info *info,
3678 struct iw_param *srq,
3679 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680{
3681 struct orinoco_private *priv = netdev_priv(dev);
3682 int val = srq->value;
3683 unsigned long flags;
3684
3685 if (!priv->has_sensitivity)
3686 return -EOPNOTSUPP;
3687
3688 if ((val < 1) || (val > 3))
3689 return -EINVAL;
3690
3691 if (orinoco_lock(priv, &flags) != 0)
3692 return -EBUSY;
3693 priv->ap_density = val;
3694 orinoco_unlock(priv, &flags);
3695
Christoph Hellwig620554e2005-06-19 01:27:33 +02003696 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003697}
3698
Christoph Hellwig620554e2005-06-19 01:27:33 +02003699static int orinoco_ioctl_setrts(struct net_device *dev,
3700 struct iw_request_info *info,
3701 struct iw_param *rrq,
3702 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703{
3704 struct orinoco_private *priv = netdev_priv(dev);
3705 int val = rrq->value;
3706 unsigned long flags;
3707
3708 if (rrq->disabled)
3709 val = 2347;
3710
3711 if ( (val < 0) || (val > 2347) )
3712 return -EINVAL;
3713
3714 if (orinoco_lock(priv, &flags) != 0)
3715 return -EBUSY;
3716
3717 priv->rts_thresh = val;
3718 orinoco_unlock(priv, &flags);
3719
Christoph Hellwig620554e2005-06-19 01:27:33 +02003720 return -EINPROGRESS; /* Call commit handler */
3721}
3722
3723static int orinoco_ioctl_getrts(struct net_device *dev,
3724 struct iw_request_info *info,
3725 struct iw_param *rrq,
3726 char *extra)
3727{
3728 struct orinoco_private *priv = netdev_priv(dev);
3729
3730 rrq->value = priv->rts_thresh;
3731 rrq->disabled = (rrq->value == 2347);
3732 rrq->fixed = 1;
3733
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 return 0;
3735}
3736
Christoph Hellwig620554e2005-06-19 01:27:33 +02003737static int orinoco_ioctl_setfrag(struct net_device *dev,
3738 struct iw_request_info *info,
3739 struct iw_param *frq,
3740 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741{
3742 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003743 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 unsigned long flags;
3745
3746 if (orinoco_lock(priv, &flags) != 0)
3747 return -EBUSY;
3748
3749 if (priv->has_mwo) {
3750 if (frq->disabled)
3751 priv->mwo_robust = 0;
3752 else {
3753 if (frq->fixed)
3754 printk(KERN_WARNING "%s: Fixed fragmentation is "
3755 "not supported on this firmware. "
3756 "Using MWO robust instead.\n", dev->name);
3757 priv->mwo_robust = 1;
3758 }
3759 } else {
3760 if (frq->disabled)
3761 priv->frag_thresh = 2346;
3762 else {
3763 if ( (frq->value < 256) || (frq->value > 2346) )
3764 err = -EINVAL;
3765 else
3766 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3767 }
3768 }
3769
3770 orinoco_unlock(priv, &flags);
3771
3772 return err;
3773}
3774
Christoph Hellwig620554e2005-06-19 01:27:33 +02003775static int orinoco_ioctl_getfrag(struct net_device *dev,
3776 struct iw_request_info *info,
3777 struct iw_param *frq,
3778 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779{
3780 struct orinoco_private *priv = netdev_priv(dev);
3781 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003782 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783 u16 val;
3784 unsigned long flags;
3785
3786 if (orinoco_lock(priv, &flags) != 0)
3787 return -EBUSY;
3788
3789 if (priv->has_mwo) {
3790 err = hermes_read_wordrec(hw, USER_BAP,
3791 HERMES_RID_CNFMWOROBUST_AGERE,
3792 &val);
3793 if (err)
3794 val = 0;
3795
3796 frq->value = val ? 2347 : 0;
3797 frq->disabled = ! val;
3798 frq->fixed = 0;
3799 } else {
3800 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3801 &val);
3802 if (err)
3803 val = 0;
3804
3805 frq->value = val;
3806 frq->disabled = (val >= 2346);
3807 frq->fixed = 1;
3808 }
3809
3810 orinoco_unlock(priv, &flags);
3811
3812 return err;
3813}
3814
Christoph Hellwig620554e2005-06-19 01:27:33 +02003815static int orinoco_ioctl_setrate(struct net_device *dev,
3816 struct iw_request_info *info,
3817 struct iw_param *rrq,
3818 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819{
3820 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821 int ratemode = -1;
3822 int bitrate; /* 100s of kilobits */
3823 int i;
3824 unsigned long flags;
3825
3826 /* As the user space doesn't know our highest rate, it uses -1
3827 * to ask us to set the highest rate. Test it using "iwconfig
3828 * ethX rate auto" - Jean II */
3829 if (rrq->value == -1)
3830 bitrate = 110;
3831 else {
3832 if (rrq->value % 100000)
3833 return -EINVAL;
3834 bitrate = rrq->value / 100000;
3835 }
3836
3837 if ( (bitrate != 10) && (bitrate != 20) &&
3838 (bitrate != 55) && (bitrate != 110) )
3839 return -EINVAL;
3840
3841 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3842 if ( (bitrate_table[i].bitrate == bitrate) &&
3843 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3844 ratemode = i;
3845 break;
3846 }
3847
3848 if (ratemode == -1)
3849 return -EINVAL;
3850
3851 if (orinoco_lock(priv, &flags) != 0)
3852 return -EBUSY;
3853 priv->bitratemode = ratemode;
3854 orinoco_unlock(priv, &flags);
3855
Christoph Hellwig620554e2005-06-19 01:27:33 +02003856 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857}
3858
Christoph Hellwig620554e2005-06-19 01:27:33 +02003859static int orinoco_ioctl_getrate(struct net_device *dev,
3860 struct iw_request_info *info,
3861 struct iw_param *rrq,
3862 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003863{
3864 struct orinoco_private *priv = netdev_priv(dev);
3865 hermes_t *hw = &priv->hw;
3866 int err = 0;
3867 int ratemode;
3868 int i;
3869 u16 val;
3870 unsigned long flags;
3871
3872 if (orinoco_lock(priv, &flags) != 0)
3873 return -EBUSY;
3874
3875 ratemode = priv->bitratemode;
3876
3877 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3878
3879 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3880 rrq->fixed = ! bitrate_table[ratemode].automatic;
3881 rrq->disabled = 0;
3882
3883 /* If the interface is running we try to find more about the
3884 current mode */
3885 if (netif_running(dev)) {
3886 err = hermes_read_wordrec(hw, USER_BAP,
3887 HERMES_RID_CURRENTTXRATE, &val);
3888 if (err)
3889 goto out;
3890
3891 switch (priv->firmware_type) {
3892 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3893 /* Note : in Lucent firmware, the return value of
3894 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3895 * and therefore is totally different from the
3896 * encoding of HERMES_RID_CNFTXRATECONTROL.
3897 * Don't forget that 6Mb/s is really 5.5Mb/s */
3898 if (val == 6)
3899 rrq->value = 5500000;
3900 else
3901 rrq->value = val * 1000000;
3902 break;
3903 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3904 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3905 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3906 if (bitrate_table[i].intersil_txratectrl == val) {
3907 ratemode = i;
3908 break;
3909 }
3910 if (i >= BITRATE_TABLE_SIZE)
3911 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3912 dev->name, val);
3913
3914 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3915 break;
3916 default:
3917 BUG();
3918 }
3919 }
3920
3921 out:
3922 orinoco_unlock(priv, &flags);
3923
3924 return err;
3925}
3926
Christoph Hellwig620554e2005-06-19 01:27:33 +02003927static int orinoco_ioctl_setpower(struct net_device *dev,
3928 struct iw_request_info *info,
3929 struct iw_param *prq,
3930 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931{
3932 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003933 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 unsigned long flags;
3935
3936 if (orinoco_lock(priv, &flags) != 0)
3937 return -EBUSY;
3938
3939 if (prq->disabled) {
3940 priv->pm_on = 0;
3941 } else {
3942 switch (prq->flags & IW_POWER_MODE) {
3943 case IW_POWER_UNICAST_R:
3944 priv->pm_mcast = 0;
3945 priv->pm_on = 1;
3946 break;
3947 case IW_POWER_ALL_R:
3948 priv->pm_mcast = 1;
3949 priv->pm_on = 1;
3950 break;
3951 case IW_POWER_ON:
3952 /* No flags : but we may have a value - Jean II */
3953 break;
3954 default:
3955 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003956 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05003957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003958
3959 if (prq->flags & IW_POWER_TIMEOUT) {
3960 priv->pm_on = 1;
3961 priv->pm_timeout = prq->value / 1000;
3962 }
3963 if (prq->flags & IW_POWER_PERIOD) {
3964 priv->pm_on = 1;
3965 priv->pm_period = prq->value / 1000;
3966 }
3967 /* It's valid to not have a value if we are just toggling
3968 * the flags... Jean II */
3969 if(!priv->pm_on) {
3970 err = -EINVAL;
3971 goto out;
3972 }
3973 }
3974
3975 out:
3976 orinoco_unlock(priv, &flags);
3977
3978 return err;
3979}
3980
Christoph Hellwig620554e2005-06-19 01:27:33 +02003981static int orinoco_ioctl_getpower(struct net_device *dev,
3982 struct iw_request_info *info,
3983 struct iw_param *prq,
3984 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985{
3986 struct orinoco_private *priv = netdev_priv(dev);
3987 hermes_t *hw = &priv->hw;
3988 int err = 0;
3989 u16 enable, period, timeout, mcast;
3990 unsigned long flags;
3991
3992 if (orinoco_lock(priv, &flags) != 0)
3993 return -EBUSY;
3994
3995 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3996 if (err)
3997 goto out;
3998
3999 err = hermes_read_wordrec(hw, USER_BAP,
4000 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4001 if (err)
4002 goto out;
4003
4004 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4005 if (err)
4006 goto out;
4007
4008 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4009 if (err)
4010 goto out;
4011
4012 prq->disabled = !enable;
4013 /* Note : by default, display the period */
4014 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4015 prq->flags = IW_POWER_TIMEOUT;
4016 prq->value = timeout * 1000;
4017 } else {
4018 prq->flags = IW_POWER_PERIOD;
4019 prq->value = period * 1000;
4020 }
4021 if (mcast)
4022 prq->flags |= IW_POWER_ALL_R;
4023 else
4024 prq->flags |= IW_POWER_UNICAST_R;
4025
4026 out:
4027 orinoco_unlock(priv, &flags);
4028
4029 return err;
4030}
4031
Christoph Hellwig620554e2005-06-19 01:27:33 +02004032static int orinoco_ioctl_getretry(struct net_device *dev,
4033 struct iw_request_info *info,
4034 struct iw_param *rrq,
4035 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036{
4037 struct orinoco_private *priv = netdev_priv(dev);
4038 hermes_t *hw = &priv->hw;
4039 int err = 0;
4040 u16 short_limit, long_limit, lifetime;
4041 unsigned long flags;
4042
4043 if (orinoco_lock(priv, &flags) != 0)
4044 return -EBUSY;
4045
4046 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4047 &short_limit);
4048 if (err)
4049 goto out;
4050
4051 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4052 &long_limit);
4053 if (err)
4054 goto out;
4055
4056 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4057 &lifetime);
4058 if (err)
4059 goto out;
4060
4061 rrq->disabled = 0; /* Can't be disabled */
4062
4063 /* Note : by default, display the retry number */
4064 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4065 rrq->flags = IW_RETRY_LIFETIME;
4066 rrq->value = lifetime * 1000; /* ??? */
4067 } else {
4068 /* By default, display the min number */
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004069 if ((rrq->flags & IW_RETRY_LONG)) {
4070 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 rrq->value = long_limit;
4072 } else {
4073 rrq->flags = IW_RETRY_LIMIT;
4074 rrq->value = short_limit;
4075 if(short_limit != long_limit)
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004076 rrq->flags |= IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 }
4078 }
4079
4080 out:
4081 orinoco_unlock(priv, &flags);
4082
4083 return err;
4084}
4085
Christoph Hellwig620554e2005-06-19 01:27:33 +02004086static int orinoco_ioctl_reset(struct net_device *dev,
4087 struct iw_request_info *info,
4088 void *wrqu,
4089 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090{
4091 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004092
4093 if (! capable(CAP_NET_ADMIN))
4094 return -EPERM;
4095
4096 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4097 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4098
4099 /* Firmware reset */
David Howellsc4028952006-11-22 14:57:56 +00004100 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004101 } else {
4102 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4103
4104 schedule_work(&priv->reset_work);
4105 }
4106
4107 return 0;
4108}
4109
4110static int orinoco_ioctl_setibssport(struct net_device *dev,
4111 struct iw_request_info *info,
4112 void *wrqu,
4113 char *extra)
4114
4115{
4116 struct orinoco_private *priv = netdev_priv(dev);
4117 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004118 unsigned long flags;
4119
4120 if (orinoco_lock(priv, &flags) != 0)
4121 return -EBUSY;
4122
4123 priv->ibss_port = val ;
4124
4125 /* Actually update the mode we are using */
4126 set_port_type(priv);
4127
4128 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004129 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130}
4131
Christoph Hellwig620554e2005-06-19 01:27:33 +02004132static int orinoco_ioctl_getibssport(struct net_device *dev,
4133 struct iw_request_info *info,
4134 void *wrqu,
4135 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136{
4137 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004138 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
4140 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 return 0;
4142}
4143
Christoph Hellwig620554e2005-06-19 01:27:33 +02004144static int orinoco_ioctl_setport3(struct net_device *dev,
4145 struct iw_request_info *info,
4146 void *wrqu,
4147 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148{
4149 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004150 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 int err = 0;
4152 unsigned long flags;
4153
4154 if (orinoco_lock(priv, &flags) != 0)
4155 return -EBUSY;
4156
4157 switch (val) {
4158 case 0: /* Try to do IEEE ad-hoc mode */
4159 if (! priv->has_ibss) {
4160 err = -EINVAL;
4161 break;
4162 }
4163 priv->prefer_port3 = 0;
4164
4165 break;
4166
4167 case 1: /* Try to do Lucent proprietary ad-hoc mode */
4168 if (! priv->has_port3) {
4169 err = -EINVAL;
4170 break;
4171 }
4172 priv->prefer_port3 = 1;
4173 break;
4174
4175 default:
4176 err = -EINVAL;
4177 }
4178
Christoph Hellwig620554e2005-06-19 01:27:33 +02004179 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 /* Actually update the mode we are using */
4181 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004182 err = -EINPROGRESS;
4183 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184
4185 orinoco_unlock(priv, &flags);
4186
4187 return err;
4188}
4189
Christoph Hellwig620554e2005-06-19 01:27:33 +02004190static int orinoco_ioctl_getport3(struct net_device *dev,
4191 struct iw_request_info *info,
4192 void *wrqu,
4193 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194{
4195 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004196 int *val = (int *) extra;
4197
4198 *val = priv->prefer_port3;
4199 return 0;
4200}
4201
4202static int orinoco_ioctl_setpreamble(struct net_device *dev,
4203 struct iw_request_info *info,
4204 void *wrqu,
4205 char *extra)
4206{
4207 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004209 int val;
4210
4211 if (! priv->has_preamble)
4212 return -EOPNOTSUPP;
4213
4214 /* 802.11b has recently defined some short preamble.
4215 * Basically, the Phy header has been reduced in size.
4216 * This increase performance, especially at high rates
4217 * (the preamble is transmitted at 1Mb/s), unfortunately
4218 * this give compatibility troubles... - Jean II */
4219 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220
4221 if (orinoco_lock(priv, &flags) != 0)
4222 return -EBUSY;
4223
Christoph Hellwig620554e2005-06-19 01:27:33 +02004224 if (val)
4225 priv->preamble = 1;
4226 else
4227 priv->preamble = 0;
4228
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004230
4231 return -EINPROGRESS; /* Call commit handler */
4232}
4233
4234static int orinoco_ioctl_getpreamble(struct net_device *dev,
4235 struct iw_request_info *info,
4236 void *wrqu,
4237 char *extra)
4238{
4239 struct orinoco_private *priv = netdev_priv(dev);
4240 int *val = (int *) extra;
4241
4242 if (! priv->has_preamble)
4243 return -EOPNOTSUPP;
4244
4245 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 return 0;
4247}
4248
Christoph Hellwig620554e2005-06-19 01:27:33 +02004249/* ioctl interface to hermes_read_ltv()
4250 * To use with iwpriv, pass the RID as the token argument, e.g.
4251 * iwpriv get_rid [0xfc00]
4252 * At least Wireless Tools 25 is required to use iwpriv.
4253 * For Wireless Tools 25 and 26 append "dummy" are the end. */
4254static int orinoco_ioctl_getrid(struct net_device *dev,
4255 struct iw_request_info *info,
4256 struct iw_point *data,
4257 char *extra)
4258{
4259 struct orinoco_private *priv = netdev_priv(dev);
4260 hermes_t *hw = &priv->hw;
4261 int rid = data->flags;
4262 u16 length;
4263 int err;
4264 unsigned long flags;
4265
4266 /* It's a "get" function, but we don't want users to access the
4267 * WEP key and other raw firmware data */
4268 if (! capable(CAP_NET_ADMIN))
4269 return -EPERM;
4270
4271 if (rid < 0xfc00 || rid > 0xffff)
4272 return -EINVAL;
4273
4274 if (orinoco_lock(priv, &flags) != 0)
4275 return -EBUSY;
4276
4277 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
4278 extra);
4279 if (err)
4280 goto out;
4281
4282 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
4283 MAX_RID_LEN);
4284
4285 out:
4286 orinoco_unlock(priv, &flags);
4287 return err;
4288}
4289
David Kilroy17a1a882008-08-21 23:27:47 +01004290/* Trigger a scan (look for other cells in the vicinity) */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004291static int orinoco_ioctl_setscan(struct net_device *dev,
4292 struct iw_request_info *info,
4293 struct iw_param *srq,
4294 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295{
4296 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004297 hermes_t *hw = &priv->hw;
David Kilroy0753bba2008-08-21 23:27:46 +01004298 struct iw_scan_req *si = (struct iw_scan_req *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004299 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004300 unsigned long flags;
4301
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004302 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08004303 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004304 * perform scanning.
4305 * This is not an error, while the device perform scanning,
4306 * traffic doesn't flow, so it's a perfect DoS...
4307 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004309 if (orinoco_lock(priv, &flags) != 0)
4310 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004312 /* Scanning with port 0 disabled would fail */
4313 if (!netif_running(dev)) {
4314 err = -ENETDOWN;
4315 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004317
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004318 /* In monitor mode, the scan results are always empty.
4319 * Probe responses are passed to the driver as received
4320 * frames and could be processed in software. */
4321 if (priv->iw_mode == IW_MODE_MONITOR) {
4322 err = -EOPNOTSUPP;
4323 goto out;
4324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004325
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004326 /* Note : because we don't lock out the irq handler, the way
4327 * we access scan variables in priv is critical.
4328 * o scan_inprogress : not touched by irq handler
4329 * o scan_mode : not touched by irq handler
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004330 * Before modifying anything on those variables, please think hard !
4331 * Jean II */
4332
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004333 /* Save flags */
4334 priv->scan_mode = srq->flags;
4335
4336 /* Always trigger scanning, even if it's in progress.
4337 * This way, if the info frame get lost, we will recover somewhat
4338 * gracefully - Jean II */
4339
4340 if (priv->has_hostscan) {
4341 switch (priv->firmware_type) {
4342 case FIRMWARE_TYPE_SYMBOL:
4343 err = hermes_write_wordrec(hw, USER_BAP,
4344 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4345 HERMES_HOSTSCAN_SYMBOL_ONCE |
4346 HERMES_HOSTSCAN_SYMBOL_BCAST);
4347 break;
4348 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04004349 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004350
4351 req[0] = cpu_to_le16(0x3fff); /* All channels */
4352 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4353 req[2] = 0; /* Any ESSID */
4354 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4355 HERMES_RID_CNFHOSTSCAN, &req);
4356 }
4357 break;
4358 case FIRMWARE_TYPE_AGERE:
David Kilroy0753bba2008-08-21 23:27:46 +01004359 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4360 struct hermes_idstring idbuf;
4361 size_t len = min(sizeof(idbuf.val),
4362 (size_t) si->essid_len);
4363 idbuf.len = cpu_to_le16(len);
4364 memcpy(idbuf.val, si->essid, len);
4365
4366 err = hermes_write_ltv(hw, USER_BAP,
4367 HERMES_RID_CNFSCANSSID_AGERE,
4368 HERMES_BYTES_TO_RECLEN(len + 2),
4369 &idbuf);
4370 } else
4371 err = hermes_write_wordrec(hw, USER_BAP,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004372 HERMES_RID_CNFSCANSSID_AGERE,
4373 0); /* Any ESSID */
4374 if (err)
4375 break;
4376
4377 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4378 break;
4379 }
4380 } else
4381 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4382
4383 /* One more client */
4384 if (! err)
4385 priv->scan_inprogress = 1;
4386
4387 out:
4388 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 return err;
4390}
4391
Dan Williams1e3428e2007-10-10 23:56:25 -04004392#define MAX_CUSTOM_LEN 64
4393
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004394/* Translate scan data returned from the card to a card independant
David Kilroy17a1a882008-08-21 23:27:47 +01004395 * format that the Wireless Tools will understand - Jean II */
Dan Williams1e3428e2007-10-10 23:56:25 -04004396static inline char *orinoco_translate_scan(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07004397 struct iw_request_info *info,
Dan Williams1e3428e2007-10-10 23:56:25 -04004398 char *current_ev,
4399 char *end_buf,
4400 union hermes_scan_info *bss,
4401 unsigned int last_scanned)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004402{
4403 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004404 u16 capabilities;
4405 u16 channel;
4406 struct iw_event iwe; /* Temporary buffer */
Dan Williams1e3428e2007-10-10 23:56:25 -04004407 char custom[MAX_CUSTOM_LEN];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004408
David Kilroy17a1a882008-08-21 23:27:47 +01004409 memset(&iwe, 0, sizeof(iwe));
4410
Dan Williams1e3428e2007-10-10 23:56:25 -04004411 /* First entry *MUST* be the AP MAC address */
4412 iwe.cmd = SIOCGIWAP;
4413 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4414 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07004415 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4416 &iwe, IW_EV_ADDR_LEN);
Dan Williams1e3428e2007-10-10 23:56:25 -04004417
4418 /* Other entries will be displayed in the order we give them */
4419
4420 /* Add the ESSID */
4421 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4422 if (iwe.u.data.length > 32)
4423 iwe.u.data.length = 32;
4424 iwe.cmd = SIOCGIWESSID;
4425 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004426 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4427 &iwe, bss->a.essid);
Dan Williams1e3428e2007-10-10 23:56:25 -04004428
4429 /* Add mode */
4430 iwe.cmd = SIOCGIWMODE;
4431 capabilities = le16_to_cpu(bss->a.capabilities);
David Kilroy17a1a882008-08-21 23:27:47 +01004432 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4433 if (capabilities & WLAN_CAPABILITY_ESS)
Dan Williams1e3428e2007-10-10 23:56:25 -04004434 iwe.u.mode = IW_MODE_MASTER;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004435 else
Dan Williams1e3428e2007-10-10 23:56:25 -04004436 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07004437 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4438 &iwe, IW_EV_UINT_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004439 }
4440
Dan Williams1e3428e2007-10-10 23:56:25 -04004441 channel = bss->s.channel;
4442 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
David Kilroy17a1a882008-08-21 23:27:47 +01004443 /* Add channel and frequency */
Dan Williams1e3428e2007-10-10 23:56:25 -04004444 iwe.cmd = SIOCGIWFREQ;
David Kilroy17a1a882008-08-21 23:27:47 +01004445 iwe.u.freq.m = channel;
4446 iwe.u.freq.e = 0;
4447 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4448 &iwe, IW_EV_FREQ_LEN);
4449
Dan Williams1e3428e2007-10-10 23:56:25 -04004450 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4451 iwe.u.freq.e = 1;
David S. Millerccc58052008-06-16 18:50:49 -07004452 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
Dan Williams1e3428e2007-10-10 23:56:25 -04004453 &iwe, IW_EV_FREQ_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004454 }
4455
David Kilroy17a1a882008-08-21 23:27:47 +01004456 /* Add quality statistics. level and noise in dB. No link quality */
Dan Williams1e3428e2007-10-10 23:56:25 -04004457 iwe.cmd = IWEVQUAL;
David Kilroy17a1a882008-08-21 23:27:47 +01004458 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
Dan Williams1e3428e2007-10-10 23:56:25 -04004459 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4460 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4461 /* Wireless tools prior to 27.pre22 will show link quality
4462 * anyway, so we provide a reasonable value. */
4463 if (iwe.u.qual.level > iwe.u.qual.noise)
4464 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4465 else
4466 iwe.u.qual.qual = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004467 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4468 &iwe, IW_EV_QUAL_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004469
Dan Williams1e3428e2007-10-10 23:56:25 -04004470 /* Add encryption capability */
4471 iwe.cmd = SIOCGIWENCODE;
David Kilroy17a1a882008-08-21 23:27:47 +01004472 if (capabilities & WLAN_CAPABILITY_PRIVACY)
Dan Williams1e3428e2007-10-10 23:56:25 -04004473 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4474 else
4475 iwe.u.data.flags = IW_ENCODE_DISABLED;
4476 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07004477 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
David Kilroy17a1a882008-08-21 23:27:47 +01004478 &iwe, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004479
Dan Williams1e3428e2007-10-10 23:56:25 -04004480 /* Bit rate is not available in Lucent/Agere firmwares */
4481 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
David S. Millerccc58052008-06-16 18:50:49 -07004482 char *current_val = current_ev + iwe_stream_lcp_len(info);
Dan Williams1e3428e2007-10-10 23:56:25 -04004483 int i;
4484 int step;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004485
Dan Williams1e3428e2007-10-10 23:56:25 -04004486 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4487 step = 2;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004488 else
Dan Williams1e3428e2007-10-10 23:56:25 -04004489 step = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004490
Dan Williams1e3428e2007-10-10 23:56:25 -04004491 iwe.cmd = SIOCGIWRATE;
4492 /* Those two flags are ignored... */
4493 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4494 /* Max 10 values */
4495 for (i = 0; i < 10; i += step) {
4496 /* NULL terminated */
4497 if (bss->p.rates[i] == 0x0)
4498 break;
4499 /* Bit rate given in 500 kb/s units (+ 0x80) */
David Kilroy17a1a882008-08-21 23:27:47 +01004500 iwe.u.bitrate.value =
4501 ((bss->p.rates[i] & 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07004502 current_val = iwe_stream_add_value(info, current_ev,
4503 current_val,
Dan Williams1e3428e2007-10-10 23:56:25 -04004504 end_buf, &iwe,
4505 IW_EV_PARAM_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004506 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004507 /* Check if we added any event */
David S. Millerccc58052008-06-16 18:50:49 -07004508 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
Dan Williams1e3428e2007-10-10 23:56:25 -04004509 current_ev = current_val;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004510 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004511
David Kilroy17a1a882008-08-21 23:27:47 +01004512 /* Beacon interval */
4513 iwe.cmd = IWEVCUSTOM;
4514 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4515 "bcn_int=%d",
4516 le16_to_cpu(bss->a.beacon_interv));
4517 if (iwe.u.data.length)
4518 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4519 &iwe, custom);
4520
4521 /* Capabilites */
4522 iwe.cmd = IWEVCUSTOM;
4523 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4524 "capab=0x%04x",
4525 capabilities);
4526 if (iwe.u.data.length)
4527 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4528 &iwe, custom);
4529
4530 /* Add EXTRA: Age to display seconds since last beacon/probe response
4531 * for given network. */
4532 iwe.cmd = IWEVCUSTOM;
4533 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4534 " Last beacon: %dms ago",
4535 jiffies_to_msecs(jiffies - last_scanned));
4536 if (iwe.u.data.length)
4537 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4538 &iwe, custom);
4539
Dan Williams1e3428e2007-10-10 23:56:25 -04004540 return current_ev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004541}
4542
4543/* Return results of a scan */
4544static int orinoco_ioctl_getscan(struct net_device *dev,
4545 struct iw_request_info *info,
4546 struct iw_point *srq,
4547 char *extra)
4548{
4549 struct orinoco_private *priv = netdev_priv(dev);
Dan Williams1e3428e2007-10-10 23:56:25 -04004550 bss_element *bss;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004551 int err = 0;
4552 unsigned long flags;
Dan Williams1e3428e2007-10-10 23:56:25 -04004553 char *current_ev = extra;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004554
4555 if (orinoco_lock(priv, &flags) != 0)
4556 return -EBUSY;
4557
Dan Williams1e3428e2007-10-10 23:56:25 -04004558 if (priv->scan_inprogress) {
4559 /* Important note : we don't want to block the caller
4560 * until results are ready for various reasons.
4561 * First, managing wait queues is complex and racy.
4562 * Second, we grab some rtnetlink lock before comming
4563 * here (in dev_ioctl()).
4564 * Third, we generate an Wireless Event, so the
4565 * caller can wait itself on that - Jean II */
4566 err = -EAGAIN;
4567 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004568 }
Dan Williams1e3428e2007-10-10 23:56:25 -04004569
4570 list_for_each_entry(bss, &priv->bss_list, list) {
4571 /* Translate to WE format this entry */
David S. Millerccc58052008-06-16 18:50:49 -07004572 current_ev = orinoco_translate_scan(dev, info, current_ev,
Dan Williams1e3428e2007-10-10 23:56:25 -04004573 extra + srq->length,
4574 &bss->bss,
4575 bss->last_scanned);
4576
4577 /* Check if there is space for one more entry */
4578 if ((extra + srq->length - current_ev) <= IW_EV_ADDR_LEN) {
4579 /* Ask user space to try again with a bigger buffer */
4580 err = -E2BIG;
4581 goto out;
4582 }
4583 }
4584
4585 srq->length = (current_ev - extra);
4586 srq->flags = (__u16) priv->scan_mode;
4587
4588out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004589 orinoco_unlock(priv, &flags);
4590 return err;
4591}
4592
Christoph Hellwig620554e2005-06-19 01:27:33 +02004593/* Commit handler, called after set operations */
4594static int orinoco_ioctl_commit(struct net_device *dev,
4595 struct iw_request_info *info,
4596 void *wrqu,
4597 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004598{
4599 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004600 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004601 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004602 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004603
Christoph Hellwig620554e2005-06-19 01:27:33 +02004604 if (!priv->open)
4605 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606
Christoph Hellwig620554e2005-06-19 01:27:33 +02004607 if (priv->broken_disableport) {
David Howellsc4028952006-11-22 14:57:56 +00004608 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004609 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004611
Christoph Hellwig620554e2005-06-19 01:27:33 +02004612 if (orinoco_lock(priv, &flags) != 0)
4613 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004614
Christoph Hellwig620554e2005-06-19 01:27:33 +02004615 err = hermes_disable_port(hw, 0);
4616 if (err) {
4617 printk(KERN_WARNING "%s: Unable to disable port "
4618 "while reconfiguring card\n", dev->name);
4619 priv->broken_disableport = 1;
4620 goto out;
4621 }
4622
4623 err = __orinoco_program_rids(dev);
4624 if (err) {
4625 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4626 dev->name);
4627 goto out;
4628 }
4629
4630 err = hermes_enable_port(hw, 0);
4631 if (err) {
4632 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4633 dev->name);
4634 goto out;
4635 }
4636
4637 out:
4638 if (err) {
4639 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4640 schedule_work(&priv->reset_work);
4641 err = 0;
4642 }
4643
4644 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004645 return err;
4646}
4647
Christoph Hellwig620554e2005-06-19 01:27:33 +02004648static const struct iw_priv_args orinoco_privtab[] = {
4649 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4650 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4651 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4652 0, "set_port3" },
4653 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4654 "get_port3" },
4655 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4656 0, "set_preamble" },
4657 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4658 "get_preamble" },
4659 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4660 0, "set_ibssport" },
4661 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4662 "get_ibssport" },
4663 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4664 "get_rid" },
4665};
4666
4667
4668/*
4669 * Structures to export the Wireless Handlers
4670 */
4671
4672static const iw_handler orinoco_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004673 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4674 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4675 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4676 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4677 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4678 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4679 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4680 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4681 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
Pavel Roskin343c6862005-09-09 18:43:02 -04004682 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4683 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4684 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4685 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004686 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4687 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4688 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4689 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4690 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4691 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4692 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4693 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4694 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4695 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4696 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4697 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4698 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4699 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4700 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4701 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4702 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4703 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4704 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004705};
4706
4707
4708/*
4709 Added typecasting since we no longer use iwreq_data -- Moustafa
4710 */
4711static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004712 [0] = (iw_handler) orinoco_ioctl_reset,
4713 [1] = (iw_handler) orinoco_ioctl_reset,
4714 [2] = (iw_handler) orinoco_ioctl_setport3,
4715 [3] = (iw_handler) orinoco_ioctl_getport3,
4716 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4717 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4718 [6] = (iw_handler) orinoco_ioctl_setibssport,
4719 [7] = (iw_handler) orinoco_ioctl_getibssport,
4720 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004721};
4722
4723static const struct iw_handler_def orinoco_handler_def = {
4724 .num_standard = ARRAY_SIZE(orinoco_handler),
4725 .num_private = ARRAY_SIZE(orinoco_private_handler),
4726 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4727 .standard = orinoco_handler,
4728 .private = orinoco_private_handler,
4729 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04004730 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004731};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004732
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004733static void orinoco_get_drvinfo(struct net_device *dev,
4734 struct ethtool_drvinfo *info)
4735{
4736 struct orinoco_private *priv = netdev_priv(dev);
4737
4738 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4739 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4740 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07004741 if (dev->dev.parent)
4742 strncpy(info->bus_info, dev->dev.parent->bus_id,
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004743 sizeof(info->bus_info) - 1);
4744 else
4745 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4746 "PCMCIA %p", priv->hw.iobase);
4747}
4748
Jeff Garzik7282d492006-09-13 14:30:00 -04004749static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004750 .get_drvinfo = orinoco_get_drvinfo,
4751 .get_link = ethtool_op_get_link,
4752};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004753
4754/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07004755/* Module initialization */
4756/********************************************************************/
4757
4758EXPORT_SYMBOL(alloc_orinocodev);
4759EXPORT_SYMBOL(free_orinocodev);
4760
4761EXPORT_SYMBOL(__orinoco_up);
4762EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004763EXPORT_SYMBOL(orinoco_reinit_firmware);
4764
4765EXPORT_SYMBOL(orinoco_interrupt);
4766
4767/* Can't be declared "const" or the whole __initdata section will
4768 * become const */
4769static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4770 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4771 "Pavel Roskin <proski@gnu.org>, et al)";
4772
4773static int __init init_orinoco(void)
4774{
4775 printk(KERN_DEBUG "%s\n", version);
4776 return 0;
4777}
4778
4779static void __exit exit_orinoco(void)
4780{
4781}
4782
4783module_init(init_orinoco);
4784module_exit(exit_orinoco);