blob: f0454440dd7b828466118ec9aabdcb3ec3f9e4c3 [file] [log] [blame]
David Kilroy47445cb2009-02-04 23:05:48 +00001/* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.c)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
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>
David Kilroyd03032a2008-08-21 23:28:02 +010082#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#include <linux/netdevice.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/etherdevice.h>
Christoph Hellwig1fab2e82005-06-19 01:27:40 +020085#include <linux/ethtool.h>
David Kilroy3994d502008-08-21 23:27:54 +010086#include <linux/firmware.h>
David Kilroy39d1ffe2008-11-22 10:37:28 +000087#include <linux/suspend.h>
Pavel Roskin9c974fb2006-08-15 20:45:03 -040088#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#include <linux/wireless.h>
Johannes Berg2c7060022008-10-30 22:09:54 +010090#include <linux/ieee80211.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020091#include <net/iw_handler.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010094#include "hermes_dld.h"
David Kilroyfb791b12009-02-04 23:05:50 +000095#include "scan.h"
David Kilroy4adb4742009-02-04 23:05:51 +000096#include "mic.h"
David Kilroyfb791b12009-02-04 23:05:50 +000097
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100/********************************************************************/
101/* Module information */
102/********************************************************************/
103
David Kilroyb2f30a02009-02-04 23:05:46 +0000104MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
105 "David Gibson <hermes@gibson.dropbear.id.au>");
106MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
107 "and similar wireless cards");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108MODULE_LICENSE("Dual MPL/GPL");
109
110/* Level of debugging. Used in the macros in orinoco.h */
111#ifdef ORINOCO_DEBUG
112int orinoco_debug = ORINOCO_DEBUG;
David Kilroy21312662009-02-04 23:05:47 +0000113EXPORT_SYMBOL(orinoco_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114module_param(orinoco_debug, int, 0644);
115MODULE_PARM_DESC(orinoco_debug, "Debug level");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#endif
117
118static int suppress_linkstatus; /* = 0 */
119module_param(suppress_linkstatus, bool, 0644);
120MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Kilroyb2f30a02009-02-04 23:05:46 +0000121
David Gibson7bb7c3a2005-05-12 20:02:10 -0400122static int ignore_disconnect; /* = 0 */
123module_param(ignore_disconnect, int, 0644);
David Kilroyb2f30a02009-02-04 23:05:46 +0000124MODULE_PARM_DESC(ignore_disconnect,
125 "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200127static int force_monitor; /* = 0 */
128module_param(force_monitor, int, 0644);
129MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/********************************************************************/
132/* Compile time configuration and compatibility stuff */
133/********************************************************************/
134
135/* We do this this way to avoid ifdefs in the actual code */
136#ifdef WIRELESS_SPY
Pavel Roskin343c6862005-09-09 18:43:02 -0400137#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#else
139#define SPY_NUMBER(priv) 0
140#endif /* WIRELESS_SPY */
141
142/********************************************************************/
143/* Internal constants */
144/********************************************************************/
145
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200146/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
147static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
148#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#define ORINOCO_MIN_MTU 256
Johannes Berg2c7060022008-10-30 22:09:54 +0100151#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153#define SYMBOL_MAX_VER_LEN (14)
154#define USER_BAP 0
155#define IRQ_BAP 1
156#define MAX_IRQLOOPS_PER_IRQ 10
157#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
158 * how many events the
159 * device could
160 * legitimately generate */
161#define SMALL_KEY_SIZE 5
162#define LARGE_KEY_SIZE 13
163#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
164
165#define DUMMY_FID 0xFFFF
166
167/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
168 HERMES_MAX_MULTICAST : 0)*/
169#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
170
171#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
172 | HERMES_EV_TX | HERMES_EV_TXEXC \
173 | HERMES_EV_WTERR | HERMES_EV_INFO \
David Kilroya94e8422009-02-04 23:05:44 +0000174 | HERMES_EV_INFDROP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Christoph Hellwig620554e2005-06-19 01:27:33 +0200176#define MAX_RID_LEN 1024
177
178static const struct iw_handler_def orinoco_handler_def;
Jeff Garzik7282d492006-09-13 14:30:00 -0400179static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200180
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181/********************************************************************/
182/* Data tables */
183/********************************************************************/
184
David Kilroy9ee677c2008-12-23 14:03:38 +0000185#define NUM_CHANNELS 14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187/* This tables gives the actual meanings of the bitrate IDs returned
188 * by the firmware. */
189static struct {
190 int bitrate; /* in 100s of kilobits */
191 int automatic;
192 u16 agere_txratectrl;
193 u16 intersil_txratectrl;
194} bitrate_table[] = {
195 {110, 1, 3, 15}, /* Entry 0 is the default */
196 {10, 0, 1, 1},
197 {10, 1, 1, 1},
198 {20, 0, 2, 2},
199 {20, 1, 6, 3},
200 {55, 0, 4, 4},
201 {55, 1, 7, 7},
202 {110, 0, 5, 8},
203};
204#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
205
206/********************************************************************/
207/* Data types */
208/********************************************************************/
209
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400210/* Beginning of the Tx descriptor, used in TxExc handling */
211struct hermes_txexc_data {
212 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400213 __le16 frame_ctl;
214 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200215 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216} __attribute__ ((packed));
217
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200218/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200220 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400221 __le16 status;
222 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 u8 silence;
224 u8 signal;
225 u8 rate;
226 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400227 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200228
229 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400230 __le16 frame_ctl;
231 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200232 u8 addr1[ETH_ALEN];
233 u8 addr2[ETH_ALEN];
234 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400235 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200236 u8 addr4[ETH_ALEN];
237
238 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400239 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240} __attribute__ ((packed));
241
David Kilroy47166792009-01-07 00:43:54 +0000242struct orinoco_rx_data {
243 struct hermes_rx_descriptor *desc;
244 struct sk_buff *skb;
245 struct list_head list;
246};
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/********************************************************************/
249/* Function prototypes */
250/********************************************************************/
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252static int __orinoco_program_rids(struct net_device *dev);
253static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255/********************************************************************/
256/* Internal helper functions */
257/********************************************************************/
258
259static inline void set_port_type(struct orinoco_private *priv)
260{
261 switch (priv->iw_mode) {
262 case IW_MODE_INFRA:
263 priv->port_type = 1;
264 priv->createibss = 0;
265 break;
266 case IW_MODE_ADHOC:
267 if (priv->prefer_port3) {
268 priv->port_type = 3;
269 priv->createibss = 0;
270 } else {
271 priv->port_type = priv->ibss_port;
272 priv->createibss = 1;
273 }
274 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200275 case IW_MODE_MONITOR:
276 priv->port_type = 3;
277 priv->createibss = 0;
278 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 default:
280 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
281 priv->ndev->name);
282 }
283}
284
David Kilroy01632fa2008-08-21 23:27:58 +0100285static inline u8 *orinoco_get_ie(u8 *data, size_t len,
Johannes Berg2c7060022008-10-30 22:09:54 +0100286 enum ieee80211_eid eid)
David Kilroy01632fa2008-08-21 23:27:58 +0100287{
288 u8 *p = data;
289 while ((p + 2) < (data + len)) {
290 if (p[0] == eid)
291 return p;
292 p += p[1] + 2;
293 }
294 return NULL;
295}
296
297#define WPA_OUI_TYPE "\x00\x50\xF2\x01"
298#define WPA_SELECTOR_LEN 4
299static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
300{
301 u8 *p = data;
302 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
Johannes Berg2c7060022008-10-30 22:09:54 +0100303 if ((p[0] == WLAN_EID_GENERIC) &&
David Kilroy01632fa2008-08-21 23:27:58 +0100304 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
305 return p;
306 p += p[1] + 2;
307 }
308 return NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -0400309}
310
David Kilroy3994d502008-08-21 23:27:54 +0100311
312/********************************************************************/
313/* Download functionality */
314/********************************************************************/
315
316struct fw_info {
317 char *pri_fw;
318 char *sta_fw;
319 char *ap_fw;
320 u32 pda_addr;
321 u16 pda_size;
322};
323
324const static struct fw_info orinoco_fw[] = {
David Kilroy74734312008-11-22 10:37:25 +0000325 { NULL, "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
326 { NULL, "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
327 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", NULL, 0x00003100, 512 }
David Kilroy3994d502008-08-21 23:27:54 +0100328};
329
330/* Structure used to access fields in FW
331 * Make sure LE decoding macros are used
332 */
333struct orinoco_fw_header {
334 char hdr_vers[6]; /* ASCII string for header version */
335 __le16 headersize; /* Total length of header */
336 __le32 entry_point; /* NIC entry point */
337 __le32 blocks; /* Number of blocks to program */
338 __le32 block_offset; /* Offset of block data from eof header */
339 __le32 pdr_offset; /* Offset to PDR data from eof header */
340 __le32 pri_offset; /* Offset to primary plug data */
341 __le32 compat_offset; /* Offset to compatibility data*/
342 char signature[0]; /* FW signature length headersize-20 */
343} __attribute__ ((packed));
344
345/* Download either STA or AP firmware into the card. */
346static int
347orinoco_dl_firmware(struct orinoco_private *priv,
348 const struct fw_info *fw,
349 int ap)
350{
351 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400352 __le16 *pda;
David Kilroy3994d502008-08-21 23:27:54 +0100353
354 hermes_t *hw = &priv->hw;
355 const struct firmware *fw_entry;
356 const struct orinoco_fw_header *hdr;
357 const unsigned char *first_block;
358 const unsigned char *end;
359 const char *firmware;
360 struct net_device *dev = priv->ndev;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400361 int err = 0;
362
363 pda = kzalloc(fw->pda_size, GFP_KERNEL);
364 if (!pda)
365 return -ENOMEM;
David Kilroy3994d502008-08-21 23:27:54 +0100366
367 if (ap)
368 firmware = fw->ap_fw;
369 else
370 firmware = fw->sta_fw;
371
372 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
373 dev->name, firmware);
374
375 /* Read current plug data */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400376 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
David Kilroy3994d502008-08-21 23:27:54 +0100377 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
378 if (err)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400379 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100380
David Kilroy74734312008-11-22 10:37:25 +0000381 if (!priv->cached_fw) {
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400382 err = request_firmware(&fw_entry, firmware, priv->dev);
David Kilroy74734312008-11-22 10:37:25 +0000383
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400384 if (err) {
385 printk(KERN_ERR "%s: Cannot find firmware %s\n",
386 dev->name, firmware);
387 err = -ENOENT;
388 goto free;
389 }
David Kilroy74734312008-11-22 10:37:25 +0000390 } else
391 fw_entry = priv->cached_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100392
393 hdr = (const struct orinoco_fw_header *) fw_entry->data;
394
395 /* Enable aux port to allow programming */
396 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
397 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
398 if (err != 0)
399 goto abort;
400
401 /* Program data */
402 first_block = (fw_entry->data +
403 le16_to_cpu(hdr->headersize) +
404 le32_to_cpu(hdr->block_offset));
405 end = fw_entry->data + fw_entry->size;
406
407 err = hermes_program(hw, first_block, end);
408 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
409 if (err != 0)
410 goto abort;
411
412 /* Update production data */
413 first_block = (fw_entry->data +
414 le16_to_cpu(hdr->headersize) +
415 le32_to_cpu(hdr->pdr_offset));
416
417 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
418 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
419 if (err)
420 goto abort;
421
422 /* Tell card we've finished */
423 err = hermesi_program_end(hw);
424 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
425 if (err != 0)
426 goto abort;
427
428 /* Check if we're running */
429 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
430 dev->name, hermes_present(hw));
431
432abort:
David Kilroy74734312008-11-22 10:37:25 +0000433 /* If we requested the firmware, release it. */
434 if (!priv->cached_fw)
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400435 release_firmware(fw_entry);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400436
437free:
438 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100439 return err;
440}
441
442/* End markers */
443#define TEXT_END 0x1A /* End of text header */
444
445/*
446 * Process a firmware image - stop the card, load the firmware, reset
447 * the card and make sure it responds. For the secondary firmware take
448 * care of the PDA - read it and then write it on top of the firmware.
449 */
450static int
451symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
452 const unsigned char *image, const unsigned char *end,
453 int secondary)
454{
455 hermes_t *hw = &priv->hw;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400456 int ret = 0;
David Kilroy3994d502008-08-21 23:27:54 +0100457 const unsigned char *ptr;
458 const unsigned char *first_block;
459
460 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400461 __le16 *pda = NULL;
David Kilroy3994d502008-08-21 23:27:54 +0100462
463 /* Binary block begins after the 0x1A marker */
464 ptr = image;
465 while (*ptr++ != TEXT_END);
466 first_block = ptr;
467
468 /* Read the PDA from EEPROM */
469 if (secondary) {
Andrey Borzenkov70458252008-10-10 21:26:30 +0400470 pda = kzalloc(fw->pda_size, GFP_KERNEL);
471 if (!pda)
472 return -ENOMEM;
473
474 ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
David Kilroy3994d502008-08-21 23:27:54 +0100475 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400476 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100477 }
478
479 /* Stop the firmware, so that it can be safely rewritten */
480 if (priv->stop_fw) {
481 ret = priv->stop_fw(priv, 1);
482 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400483 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100484 }
485
486 /* Program the adapter with new firmware */
487 ret = hermes_program(hw, first_block, end);
488 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400489 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100490
491 /* Write the PDA to the adapter */
492 if (secondary) {
493 size_t len = hermes_blocks_length(first_block);
494 ptr = first_block + len;
495 ret = hermes_apply_pda(hw, ptr, pda);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400496 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100497 if (ret)
498 return ret;
499 }
500
501 /* Run the firmware */
502 if (priv->stop_fw) {
503 ret = priv->stop_fw(priv, 0);
504 if (ret)
505 return ret;
506 }
507
508 /* Reset hermes chip and make sure it responds */
509 ret = hermes_init(hw);
510
511 /* hermes_reset() should return 0 with the secondary firmware */
512 if (secondary && ret != 0)
513 return -ENODEV;
514
515 /* And this should work with any firmware */
516 if (!hermes_present(hw))
517 return -ENODEV;
518
519 return 0;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400520
521free:
522 kfree(pda);
523 return ret;
David Kilroy3994d502008-08-21 23:27:54 +0100524}
525
526
527/*
528 * Download the firmware into the card, this also does a PCMCIA soft
529 * reset on the card, to make sure it's in a sane state.
530 */
531static int
532symbol_dl_firmware(struct orinoco_private *priv,
533 const struct fw_info *fw)
534{
535 struct net_device *dev = priv->ndev;
536 int ret;
537 const struct firmware *fw_entry;
538
David Kilroy2cea7b22008-11-22 10:37:26 +0000539 if (!priv->cached_pri_fw) {
540 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) {
541 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
542 dev->name, fw->pri_fw);
543 return -ENOENT;
544 }
545 } else
546 fw_entry = priv->cached_pri_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100547
548 /* Load primary firmware */
549 ret = symbol_dl_image(priv, fw, fw_entry->data,
550 fw_entry->data + fw_entry->size, 0);
David Kilroy2cea7b22008-11-22 10:37:26 +0000551
552 if (!priv->cached_pri_fw)
553 release_firmware(fw_entry);
David Kilroy3994d502008-08-21 23:27:54 +0100554 if (ret) {
555 printk(KERN_ERR "%s: Primary firmware download failed\n",
556 dev->name);
557 return ret;
558 }
559
David Kilroy2cea7b22008-11-22 10:37:26 +0000560 if (!priv->cached_fw) {
561 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) {
562 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
563 dev->name, fw->sta_fw);
564 return -ENOENT;
565 }
566 } else
567 fw_entry = priv->cached_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100568
569 /* Load secondary firmware */
570 ret = symbol_dl_image(priv, fw, fw_entry->data,
571 fw_entry->data + fw_entry->size, 1);
David Kilroy2cea7b22008-11-22 10:37:26 +0000572 if (!priv->cached_fw)
573 release_firmware(fw_entry);
David Kilroy3994d502008-08-21 23:27:54 +0100574 if (ret) {
575 printk(KERN_ERR "%s: Secondary firmware download failed\n",
576 dev->name);
577 }
578
579 return ret;
580}
581
582static int orinoco_download(struct orinoco_private *priv)
583{
584 int err = 0;
585 /* Reload firmware */
586 switch (priv->firmware_type) {
587 case FIRMWARE_TYPE_AGERE:
588 /* case FIRMWARE_TYPE_INTERSIL: */
589 err = orinoco_dl_firmware(priv,
590 &orinoco_fw[priv->firmware_type], 0);
591 break;
592
593 case FIRMWARE_TYPE_SYMBOL:
594 err = symbol_dl_firmware(priv,
595 &orinoco_fw[priv->firmware_type]);
596 break;
597 case FIRMWARE_TYPE_INTERSIL:
598 break;
599 }
600 /* TODO: if we fail we probably need to reinitialise
601 * the driver */
602
603 return err;
604}
605
David Kilroy39d1ffe2008-11-22 10:37:28 +0000606#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
David Kilroy74734312008-11-22 10:37:25 +0000607static void orinoco_cache_fw(struct orinoco_private *priv, int ap)
608{
609 const struct firmware *fw_entry = NULL;
David Kilroy2cea7b22008-11-22 10:37:26 +0000610 const char *pri_fw;
David Kilroy74734312008-11-22 10:37:25 +0000611 const char *fw;
612
David Kilroy2cea7b22008-11-22 10:37:26 +0000613 pri_fw = orinoco_fw[priv->firmware_type].pri_fw;
David Kilroy74734312008-11-22 10:37:25 +0000614 if (ap)
615 fw = orinoco_fw[priv->firmware_type].ap_fw;
616 else
617 fw = orinoco_fw[priv->firmware_type].sta_fw;
618
David Kilroy2cea7b22008-11-22 10:37:26 +0000619 if (pri_fw) {
620 if (request_firmware(&fw_entry, pri_fw, priv->dev) == 0)
621 priv->cached_pri_fw = fw_entry;
622 }
623
David Kilroy74734312008-11-22 10:37:25 +0000624 if (fw) {
625 if (request_firmware(&fw_entry, fw, priv->dev) == 0)
626 priv->cached_fw = fw_entry;
627 }
628}
629
630static void orinoco_uncache_fw(struct orinoco_private *priv)
631{
David Kilroy2cea7b22008-11-22 10:37:26 +0000632 if (priv->cached_pri_fw)
633 release_firmware(priv->cached_pri_fw);
David Kilroy74734312008-11-22 10:37:25 +0000634 if (priv->cached_fw)
635 release_firmware(priv->cached_fw);
636
David Kilroy2cea7b22008-11-22 10:37:26 +0000637 priv->cached_pri_fw = NULL;
David Kilroy74734312008-11-22 10:37:25 +0000638 priv->cached_fw = NULL;
639}
David Kilroy39d1ffe2008-11-22 10:37:28 +0000640#else
641#define orinoco_cache_fw(priv, ap)
642#define orinoco_uncache_fw(priv)
643#endif
David Kilroy74734312008-11-22 10:37:25 +0000644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645/********************************************************************/
646/* Device methods */
647/********************************************************************/
648
649static int orinoco_open(struct net_device *dev)
650{
651 struct orinoco_private *priv = netdev_priv(dev);
652 unsigned long flags;
653 int err;
654
655 if (orinoco_lock(priv, &flags) != 0)
656 return -EBUSY;
657
658 err = __orinoco_up(dev);
659
David Kilroya94e8422009-02-04 23:05:44 +0000660 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 priv->open = 1;
662
663 orinoco_unlock(priv, &flags);
664
665 return err;
666}
667
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200668static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
670 struct orinoco_private *priv = netdev_priv(dev);
671 int err = 0;
672
673 /* We mustn't use orinoco_lock() here, because we need to be
674 able to close the interface even if hw_unavailable is set
675 (e.g. as we're released after a PC Card removal) */
676 spin_lock_irq(&priv->lock);
677
678 priv->open = 0;
679
680 err = __orinoco_down(dev);
681
682 spin_unlock_irq(&priv->lock);
683
684 return err;
685}
686
687static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
688{
689 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 return &priv->stats;
692}
693
694static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
695{
696 struct orinoco_private *priv = netdev_priv(dev);
697 hermes_t *hw = &priv->hw;
698 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400699 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 unsigned long flags;
701
David Kilroya94e8422009-02-04 23:05:44 +0000702 if (!netif_device_present(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
704 dev->name);
705 return NULL; /* FIXME: Can we do better than this? */
706 }
707
David Gibsone67d9d92005-05-12 20:01:22 -0400708 /* If busy, return the old stats. Returning NULL may cause
709 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400711 return wstats;
712
713 /* We can't really wait for the tallies inquiry command to
714 * complete, so we just use the previous results and trigger
715 * a new tallies inquiry command for next time - Jean II */
716 /* FIXME: Really we should wait for the inquiry to come back -
717 * as it is the stats we give don't make a whole lot of sense.
718 * Unfortunately, it's not clear how to do that within the
719 * wireless extensions framework: I think we're in user
720 * context, but a lock seems to be held by the time we get in
721 * here so we're not safe to sleep here. */
722 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 if (priv->iw_mode == IW_MODE_ADHOC) {
725 memset(&wstats->qual, 0, sizeof(wstats->qual));
726 /* If a spy address is defined, we report stats of the
727 * first spy address - Jean II */
728 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400729 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
730 wstats->qual.level = priv->spy_data.spy_stat[0].level;
731 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
David Kilroyb2f30a02009-02-04 23:05:46 +0000732 wstats->qual.updated =
733 priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735 } else {
736 struct {
Pavel Roskina208c4e2006-04-07 04:10:26 -0400737 __le16 qual, signal, noise, unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 } __attribute__ ((packed)) cq;
739
740 err = HERMES_READ_RECORD(hw, USER_BAP,
741 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400742
743 if (!err) {
744 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
745 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
746 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
David Kilroyb2f30a02009-02-04 23:05:46 +0000747 wstats->qual.updated =
748 IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
David Gibsone67d9d92005-05-12 20:01:22 -0400749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 }
751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 return wstats;
754}
755
756static void orinoco_set_multicast_list(struct net_device *dev)
757{
758 struct orinoco_private *priv = netdev_priv(dev);
759 unsigned long flags;
760
761 if (orinoco_lock(priv, &flags) != 0) {
762 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
763 "called when hw_unavailable\n", dev->name);
764 return;
765 }
766
767 __orinoco_set_multicast_list(dev);
768 orinoco_unlock(priv, &flags);
769}
770
771static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
772{
773 struct orinoco_private *priv = netdev_priv(dev);
774
David Kilroya94e8422009-02-04 23:05:44 +0000775 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 return -EINVAL;
777
Johannes Berg2c7060022008-10-30 22:09:54 +0100778 /* MTU + encapsulation + header length */
David Kilroya94e8422009-02-04 23:05:44 +0000779 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
780 (priv->nicbuf_size - ETH_HLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 return -EINVAL;
782
783 dev->mtu = new_mtu;
784
785 return 0;
786}
787
788/********************************************************************/
789/* Tx path */
790/********************************************************************/
791
792static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
793{
794 struct orinoco_private *priv = netdev_priv(dev);
795 struct net_device_stats *stats = &priv->stats;
796 hermes_t *hw = &priv->hw;
797 int err = 0;
798 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100800 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 unsigned long flags;
802
David Kilroya94e8422009-02-04 23:05:44 +0000803 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 printk(KERN_ERR "%s: Tx on stopped device!\n",
805 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400806 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000808
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 if (netif_queue_stopped(dev)) {
David Kilroy6fe9deb2009-02-04 23:05:43 +0000810 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400812 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000814
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (orinoco_lock(priv, &flags) != 0) {
816 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
817 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400818 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
820
David Kilroya94e8422009-02-04 23:05:44 +0000821 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 /* Oops, the firmware hasn't established a connection,
David Kilroy6fe9deb2009-02-04 23:05:43 +0000823 silently drop the packet (this seems to be the
824 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400825 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 }
827
Pavel Roskin8d5be082006-04-07 04:10:41 -0400828 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400829 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400830 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
David Kilroy6eecad72008-08-21 23:27:56 +0100832 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
David Kilroy23edcc42008-08-21 23:28:05 +0100834 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
835 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
836 HERMES_TXCTRL_MIC;
837
David Kilroy6eecad72008-08-21 23:27:56 +0100838 if (priv->has_alt_txcntl) {
839 /* WPA enabled firmwares have tx_cntl at the end of
840 * the 802.11 header. So write zeroed descriptor and
841 * 802.11 header at the same time
842 */
843 char desc[HERMES_802_3_OFFSET];
844 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
845
846 memset(&desc, 0, sizeof(desc));
847
848 *txcntl = cpu_to_le16(tx_control);
849 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
850 txfid, 0);
851 if (err) {
852 if (net_ratelimit())
853 printk(KERN_ERR "%s: Error %d writing Tx "
854 "descriptor to BAP\n", dev->name, err);
855 goto busy;
856 }
857 } else {
858 struct hermes_tx_descriptor desc;
859
860 memset(&desc, 0, sizeof(desc));
861
862 desc.tx_control = cpu_to_le16(tx_control);
863 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
864 txfid, 0);
865 if (err) {
866 if (net_ratelimit())
867 printk(KERN_ERR "%s: Error %d writing Tx "
868 "descriptor to BAP\n", dev->name, err);
869 goto busy;
870 }
871
872 /* Clear the 802.11 header and data length fields - some
873 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
874 * if this isn't done. */
875 hermes_clear_words(hw, HERMES_DATA0,
876 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
877 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
David Kilroy23edcc42008-08-21 23:28:05 +0100879 eh = (struct ethhdr *)skb->data;
880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 /* Encapsulate Ethernet-II frames */
882 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400883 struct header_struct {
884 struct ethhdr eth; /* 802.3 header */
885 u8 encap[6]; /* 802.2 header */
886 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Pavel Roskina28dc812006-04-07 04:10:45 -0400888 /* Strip destination and source from the data */
889 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400890
891 /* And move them to a separate header */
892 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
893 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
894 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
895
David Kilroy23edcc42008-08-21 23:28:05 +0100896 /* Insert the SNAP header */
897 if (skb_headroom(skb) < sizeof(hdr)) {
898 printk(KERN_ERR
899 "%s: Not enough headroom for 802.2 headers %d\n",
900 dev->name, skb_headroom(skb));
901 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
David Kilroy23edcc42008-08-21 23:28:05 +0100903 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
904 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906
Pavel Roskina28dc812006-04-07 04:10:45 -0400907 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100908 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (err) {
910 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
911 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400912 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914
David Kilroy23edcc42008-08-21 23:28:05 +0100915 /* Calculate Michael MIC */
916 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
917 u8 mic_buf[MICHAEL_MIC_LEN + 1];
918 u8 *mic;
919 size_t offset;
920 size_t len;
921
922 if (skb->len % 2) {
923 /* MIC start is on an odd boundary */
924 mic_buf[0] = skb->data[skb->len - 1];
925 mic = &mic_buf[1];
926 offset = skb->len - 1;
927 len = MICHAEL_MIC_LEN + 1;
928 } else {
929 mic = &mic_buf[0];
930 offset = skb->len;
931 len = MICHAEL_MIC_LEN;
932 }
933
David Kilroy4adb4742009-02-04 23:05:51 +0000934 orinoco_mic(priv->tx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +0100935 priv->tkip_key[priv->tx_key].tx_mic,
936 eh->h_dest, eh->h_source, 0 /* priority */,
937 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
938
939 /* Write the MIC */
940 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
941 txfid, HERMES_802_3_OFFSET + offset);
942 if (err) {
943 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
944 dev->name, err);
945 goto busy;
946 }
947 }
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 /* Finally, we actually initiate the send */
950 netif_stop_queue(dev);
951
952 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
953 txfid, NULL);
954 if (err) {
955 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700956 if (net_ratelimit())
957 printk(KERN_ERR "%s: Error %d transmitting packet\n",
958 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400959 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 }
961
962 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +0100963 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400964 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400966 drop:
967 stats->tx_errors++;
968 stats->tx_dropped++;
969
970 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400973 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400975 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400976 if (err == -EIO)
977 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400979 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
982static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
983{
984 struct orinoco_private *priv = netdev_priv(dev);
985 u16 fid = hermes_read_regn(hw, ALLOCFID);
986
987 if (fid != priv->txfid) {
988 if (fid != DUMMY_FID)
989 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
990 dev->name, fid);
991 return;
992 }
993
994 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
995}
996
997static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
998{
999 struct orinoco_private *priv = netdev_priv(dev);
1000 struct net_device_stats *stats = &priv->stats;
1001
1002 stats->tx_packets++;
1003
1004 netif_wake_queue(dev);
1005
1006 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1007}
1008
1009static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1010{
1011 struct orinoco_private *priv = netdev_priv(dev);
1012 struct net_device_stats *stats = &priv->stats;
1013 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -04001014 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001015 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 int err = 0;
1017
1018 if (fid == DUMMY_FID)
1019 return; /* Nothing's really happened */
1020
Pavel Roskin48ca7032005-09-23 04:18:06 -04001021 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001022 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001023 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001024 fid, 0);
1025
1026 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1027 stats->tx_errors++;
1028
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if (err) {
1030 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1031 "(FID=%04X error %d)\n",
1032 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001033 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001035
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001036 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1037 err, fid);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001038
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001039 /* We produce a TXDROP event only for retry or lifetime
1040 * exceeded, because that's the only status that really mean
1041 * that this particular node went away.
1042 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001043 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -04001044 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001045 union iwreq_data wrqu;
1046
1047 /* Copy 802.11 dest address.
1048 * We use the 802.11 header because the frame may
1049 * not be 802.3 or may be mangled...
1050 * In Ad-Hoc mode, it will be the node address.
1051 * In managed mode, it will be most likely the AP addr
1052 * User space will figure out how to convert it to
1053 * whatever it needs (IP address or else).
1054 * - Jean II */
1055 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1056 wrqu.addr.sa_family = ARPHRD_ETHER;
1057
1058 /* Send event to user space */
1059 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063}
1064
1065static void orinoco_tx_timeout(struct net_device *dev)
1066{
1067 struct orinoco_private *priv = netdev_priv(dev);
1068 struct net_device_stats *stats = &priv->stats;
1069 struct hermes *hw = &priv->hw;
1070
1071 printk(KERN_WARNING "%s: Tx timeout! "
1072 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1073 dev->name, hermes_read_regn(hw, ALLOCFID),
1074 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1075
1076 stats->tx_errors++;
1077
1078 schedule_work(&priv->reset_work);
1079}
1080
1081/********************************************************************/
1082/* Rx path (data frames) */
1083/********************************************************************/
1084
1085/* Does the frame have a SNAP header indicating it should be
1086 * de-encapsulated to Ethernet-II? */
1087static inline int is_ethersnap(void *_hdr)
1088{
1089 u8 *hdr = _hdr;
1090
1091 /* We de-encapsulate all packets which, a) have SNAP headers
1092 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1093 * and where b) the OUI of the SNAP header is 00:00:00 or
1094 * 00:00:f8 - we need both because different APs appear to use
1095 * different OUIs for some reason */
1096 return (memcmp(hdr, &encaps_hdr, 5) == 0)
David Kilroya94e8422009-02-04 23:05:44 +00001097 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098}
1099
1100static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1101 int level, int noise)
1102{
Pavel Roskin343c6862005-09-09 18:43:02 -04001103 struct iw_quality wstats;
1104 wstats.level = level - 0x95;
1105 wstats.noise = noise - 0x95;
1106 wstats.qual = (level > noise) ? (level - noise) : 0;
Andrey Borzenkovf941f852008-11-15 17:15:09 +03001107 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Pavel Roskin343c6862005-09-09 18:43:02 -04001108 /* Update spy records */
1109 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110}
1111
1112static void orinoco_stat_gather(struct net_device *dev,
1113 struct sk_buff *skb,
1114 struct hermes_rx_descriptor *desc)
1115{
1116 struct orinoco_private *priv = netdev_priv(dev);
1117
1118 /* Using spy support with lots of Rx packets, like in an
1119 * infrastructure (AP), will really slow down everything, because
1120 * the MAC address must be compared to each entry of the spy list.
1121 * If the user really asks for it (set some address in the
1122 * spy list), we do it, but he will pay the price.
1123 * Note that to get here, you need both WIRELESS_SPY
1124 * compiled in AND some addresses in the list !!!
1125 */
1126 /* Note : gcc will optimise the whole section away if
1127 * WIRELESS_SPY is not defined... - Jean II */
1128 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07001129 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 desc->signal, desc->silence);
1131 }
1132}
1133
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001134/*
1135 * orinoco_rx_monitor - handle received monitor frames.
1136 *
1137 * Arguments:
1138 * dev network device
1139 * rxfid received FID
1140 * desc rx descriptor of the frame
1141 *
1142 * Call context: interrupt
1143 */
1144static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1145 struct hermes_rx_descriptor *desc)
1146{
1147 u32 hdrlen = 30; /* return full header by default */
1148 u32 datalen = 0;
1149 u16 fc;
1150 int err;
1151 int len;
1152 struct sk_buff *skb;
1153 struct orinoco_private *priv = netdev_priv(dev);
1154 struct net_device_stats *stats = &priv->stats;
1155 hermes_t *hw = &priv->hw;
1156
1157 len = le16_to_cpu(desc->data_len);
1158
1159 /* Determine the size of the header and the data */
1160 fc = le16_to_cpu(desc->frame_ctl);
1161 switch (fc & IEEE80211_FCTL_FTYPE) {
1162 case IEEE80211_FTYPE_DATA:
1163 if ((fc & IEEE80211_FCTL_TODS)
1164 && (fc & IEEE80211_FCTL_FROMDS))
1165 hdrlen = 30;
1166 else
1167 hdrlen = 24;
1168 datalen = len;
1169 break;
1170 case IEEE80211_FTYPE_MGMT:
1171 hdrlen = 24;
1172 datalen = len;
1173 break;
1174 case IEEE80211_FTYPE_CTL:
1175 switch (fc & IEEE80211_FCTL_STYPE) {
1176 case IEEE80211_STYPE_PSPOLL:
1177 case IEEE80211_STYPE_RTS:
1178 case IEEE80211_STYPE_CFEND:
1179 case IEEE80211_STYPE_CFENDACK:
1180 hdrlen = 16;
1181 break;
1182 case IEEE80211_STYPE_CTS:
1183 case IEEE80211_STYPE_ACK:
1184 hdrlen = 10;
1185 break;
1186 }
1187 break;
1188 default:
1189 /* Unknown frame type */
1190 break;
1191 }
1192
1193 /* sanity check the length */
Johannes Berg2c7060022008-10-30 22:09:54 +01001194 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001195 printk(KERN_DEBUG "%s: oversized monitor frame, "
1196 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001197 stats->rx_length_errors++;
1198 goto update_stats;
1199 }
1200
1201 skb = dev_alloc_skb(hdrlen + datalen);
1202 if (!skb) {
1203 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1204 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -07001205 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001206 }
1207
1208 /* Copy the 802.11 header to the skb */
1209 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001210 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001211
1212 /* If any, copy the data from the card to the skb */
1213 if (datalen > 0) {
1214 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1215 ALIGN(datalen, 2), rxfid,
1216 HERMES_802_2_OFFSET);
1217 if (err) {
1218 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1219 dev->name, err);
1220 goto drop;
1221 }
1222 }
1223
1224 skb->dev = dev;
1225 skb->ip_summed = CHECKSUM_NONE;
1226 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001227 skb->protocol = cpu_to_be16(ETH_P_802_2);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001228
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001229 stats->rx_packets++;
1230 stats->rx_bytes += skb->len;
1231
1232 netif_rx(skb);
1233 return;
1234
1235 drop:
1236 dev_kfree_skb_irq(skb);
1237 update_stats:
1238 stats->rx_errors++;
1239 stats->rx_dropped++;
1240}
1241
David Kilroy23edcc42008-08-21 23:28:05 +01001242/* Get tsc from the firmware */
1243static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1244 u8 *tsc)
1245{
1246 hermes_t *hw = &priv->hw;
1247 int err = 0;
1248 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1249
1250 if ((key < 0) || (key > 4))
1251 return -EINVAL;
1252
1253 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1254 sizeof(tsc_arr), NULL, &tsc_arr);
1255 if (!err)
1256 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1257
1258 return err;
1259}
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1262{
1263 struct orinoco_private *priv = netdev_priv(dev);
1264 struct net_device_stats *stats = &priv->stats;
1265 struct iw_statistics *wstats = &priv->wstats;
1266 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +01001267 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001268 int length;
David Kilroy31afcef2008-08-21 23:28:04 +01001269 struct hermes_rx_descriptor *desc;
1270 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 int err;
1272
David Kilroy31afcef2008-08-21 23:28:04 +01001273 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1274 if (!desc) {
1275 printk(KERN_WARNING
1276 "%s: Can't allocate space for RX descriptor\n",
1277 dev->name);
1278 goto update_stats;
1279 }
1280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 rxfid = hermes_read_regn(hw, RXFID);
1282
David Kilroy31afcef2008-08-21 23:28:04 +01001283 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 rxfid, 0);
1285 if (err) {
1286 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1287 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001288 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 }
1290
David Kilroy31afcef2008-08-21 23:28:04 +01001291 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001293 if (status & HERMES_RXSTAT_BADCRC) {
1294 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1295 dev->name);
1296 stats->rx_crc_errors++;
1297 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 }
1299
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001300 /* Handle frames in monitor mode */
1301 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +01001302 orinoco_rx_monitor(dev, rxfid, desc);
1303 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
1305
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001306 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1307 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1308 dev->name);
1309 wstats->discard.code++;
1310 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
David Kilroy31afcef2008-08-21 23:28:04 +01001313 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* Sanity checks */
1316 if (length < 3) { /* No for even an 802.2 LLC header */
1317 /* At least on Symbol firmware with PCF we get quite a
David Kilroy6fe9deb2009-02-04 23:05:43 +00001318 lot of these legitimately - Poll frames with no
1319 data. */
David Kilroy31afcef2008-08-21 23:28:04 +01001320 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
Johannes Berg2c7060022008-10-30 22:09:54 +01001322 if (length > IEEE80211_MAX_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1324 dev->name, length);
1325 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001326 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 }
1328
David Kilroy23edcc42008-08-21 23:28:05 +01001329 /* Payload size does not include Michael MIC. Increase payload
1330 * size to read it together with the data. */
1331 if (status & HERMES_RXSTAT_MIC)
1332 length += MICHAEL_MIC_LEN;
1333
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* We need space for the packet data itself, plus an ethernet
1335 header, plus 2 bytes so we can align the IP header on a
1336 32bit boundary, plus 1 byte so we can read in odd length
1337 packets from the card, which has an IO granularity of 16
David Kilroy6fe9deb2009-02-04 23:05:43 +00001338 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1340 if (!skb) {
1341 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1342 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001343 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
1345
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001346 /* We'll prepend the header, so reserve space for it. The worst
1347 case is no decapsulation, when 802.3 header is prepended and
1348 nothing is removed. 2 is for aligning the IP header. */
1349 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001351 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1352 ALIGN(length, 2), rxfid,
1353 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 if (err) {
1355 printk(KERN_ERR "%s: error %d reading frame. "
1356 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 goto drop;
1358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
David Kilroy31afcef2008-08-21 23:28:04 +01001360 /* Add desc and skb to rx queue */
1361 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1362 if (!rx_data) {
1363 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1364 dev->name);
1365 goto drop;
1366 }
1367 rx_data->desc = desc;
1368 rx_data->skb = skb;
1369 list_add_tail(&rx_data->list, &priv->rx_list);
1370 tasklet_schedule(&priv->rx_tasklet);
1371
1372 return;
1373
1374drop:
1375 dev_kfree_skb_irq(skb);
1376update_stats:
1377 stats->rx_errors++;
1378 stats->rx_dropped++;
1379out:
1380 kfree(desc);
1381}
1382
1383static void orinoco_rx(struct net_device *dev,
1384 struct hermes_rx_descriptor *desc,
1385 struct sk_buff *skb)
1386{
1387 struct orinoco_private *priv = netdev_priv(dev);
1388 struct net_device_stats *stats = &priv->stats;
1389 u16 status, fc;
1390 int length;
1391 struct ethhdr *hdr;
1392
1393 status = le16_to_cpu(desc->status);
1394 length = le16_to_cpu(desc->data_len);
1395 fc = le16_to_cpu(desc->frame_ctl);
1396
David Kilroy23edcc42008-08-21 23:28:05 +01001397 /* Calculate and check MIC */
1398 if (status & HERMES_RXSTAT_MIC) {
1399 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1400 HERMES_MIC_KEY_ID_SHIFT);
1401 u8 mic[MICHAEL_MIC_LEN];
1402 u8 *rxmic;
1403 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1404 desc->addr3 : desc->addr2;
1405
1406 /* Extract Michael MIC from payload */
1407 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1408
1409 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1410 length -= MICHAEL_MIC_LEN;
1411
David Kilroy4adb4742009-02-04 23:05:51 +00001412 orinoco_mic(priv->rx_tfm_mic,
David Kilroy23edcc42008-08-21 23:28:05 +01001413 priv->tkip_key[key_id].rx_mic,
1414 desc->addr1,
1415 src,
1416 0, /* priority or QoS? */
1417 skb->data,
1418 skb->len,
1419 &mic[0]);
1420
1421 if (memcmp(mic, rxmic,
1422 MICHAEL_MIC_LEN)) {
1423 union iwreq_data wrqu;
1424 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +01001425
1426 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -07001427 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +01001428 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -07001429 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +01001430
1431 /* TODO: update stats */
1432
1433 /* Notify userspace */
1434 memset(&wxmic, 0, sizeof(wxmic));
1435 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1436 wxmic.flags |= (desc->addr1[0] & 1) ?
1437 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1438 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1439 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1440
1441 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1442 &wxmic.tsc[0]);
1443
1444 memset(&wrqu, 0, sizeof(wrqu));
1445 wrqu.data.length = sizeof(wxmic);
1446 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1447 (char *) &wxmic);
1448
1449 goto drop;
1450 }
1451 }
1452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 /* Handle decapsulation
1454 * In most cases, the firmware tell us about SNAP frames.
1455 * For some reason, the SNAP frames sent by LinkSys APs
1456 * are not properly recognised by most firmwares.
1457 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001458 if (length >= ENCAPS_OVERHEAD &&
1459 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1460 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1461 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 /* These indicate a SNAP within 802.2 LLC within
1463 802.11 frame which we'll need to de-encapsulate to
1464 the original EthernetII frame. */
David Kilroyb2f30a02009-02-04 23:05:46 +00001465 hdr = (struct ethhdr *)skb_push(skb,
1466 ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001468 /* 802.3 frame - prepend 802.3 header as is */
1469 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1470 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 }
David Kilroy31afcef2008-08-21 23:28:04 +01001472 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001473 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +01001474 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001475 else
David Kilroy31afcef2008-08-21 23:28:04 +01001476 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 skb->protocol = eth_type_trans(skb, dev);
1479 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001480 if (fc & IEEE80211_FCTL_TODS)
1481 skb->pkt_type = PACKET_OTHERHOST;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001482
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001484 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* Pass the packet to the networking stack */
1487 netif_rx(skb);
1488 stats->rx_packets++;
1489 stats->rx_bytes += length;
1490
1491 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001492
1493 drop:
1494 dev_kfree_skb(skb);
1495 stats->rx_errors++;
1496 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001497}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
David Kilroy31afcef2008-08-21 23:28:04 +01001499static void orinoco_rx_isr_tasklet(unsigned long data)
1500{
1501 struct net_device *dev = (struct net_device *) data;
1502 struct orinoco_private *priv = netdev_priv(dev);
1503 struct orinoco_rx_data *rx_data, *temp;
1504 struct hermes_rx_descriptor *desc;
1505 struct sk_buff *skb;
David Kilroy20953ad2009-01-07 00:23:55 +00001506 unsigned long flags;
1507
1508 /* orinoco_rx requires the driver lock, and we also need to
1509 * protect priv->rx_list, so just hold the lock over the
1510 * lot.
1511 *
1512 * If orinoco_lock fails, we've unplugged the card. In this
1513 * case just abort. */
1514 if (orinoco_lock(priv, &flags) != 0)
1515 return;
David Kilroy31afcef2008-08-21 23:28:04 +01001516
1517 /* extract desc and skb from queue */
1518 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1519 desc = rx_data->desc;
1520 skb = rx_data->skb;
1521 list_del(&rx_data->list);
1522 kfree(rx_data);
1523
1524 orinoco_rx(dev, desc, skb);
1525
1526 kfree(desc);
1527 }
David Kilroy20953ad2009-01-07 00:23:55 +00001528
1529 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530}
1531
1532/********************************************************************/
1533/* Rx path (info frames) */
1534/********************************************************************/
1535
1536static void print_linkstatus(struct net_device *dev, u16 status)
1537{
David Kilroy21312662009-02-04 23:05:47 +00001538 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540 if (suppress_linkstatus)
1541 return;
1542
1543 switch (status) {
1544 case HERMES_LINKSTATUS_NOT_CONNECTED:
1545 s = "Not Connected";
1546 break;
1547 case HERMES_LINKSTATUS_CONNECTED:
1548 s = "Connected";
1549 break;
1550 case HERMES_LINKSTATUS_DISCONNECTED:
1551 s = "Disconnected";
1552 break;
1553 case HERMES_LINKSTATUS_AP_CHANGE:
1554 s = "AP Changed";
1555 break;
1556 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1557 s = "AP Out of Range";
1558 break;
1559 case HERMES_LINKSTATUS_AP_IN_RANGE:
1560 s = "AP In Range";
1561 break;
1562 case HERMES_LINKSTATUS_ASSOC_FAILED:
1563 s = "Association Failed";
1564 break;
1565 default:
1566 s = "UNKNOWN";
1567 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001568
Pavel Roskin11eaea42009-01-18 23:20:58 -05001569 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 dev->name, s, status);
1571}
1572
Christoph Hellwig16739b02005-06-19 01:27:51 +02001573/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001574static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001575{
David Howellsc4028952006-11-22 14:57:56 +00001576 struct orinoco_private *priv =
1577 container_of(work, struct orinoco_private, join_work);
1578 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001579 struct hermes *hw = &priv->hw;
1580 int err;
1581 unsigned long flags;
1582 struct join_req {
1583 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001584 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001585 } __attribute__ ((packed)) req;
1586 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001587 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001588 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001589 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001590 u8 *buf;
1591 u16 len;
1592
1593 /* Allocate buffer for scan results */
1594 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
David Kilroya94e8422009-02-04 23:05:44 +00001595 if (!buf)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001596 return;
1597
1598 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001599 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001600
1601 /* Sanity checks in case user changed something in the meantime */
David Kilroya94e8422009-02-04 23:05:44 +00001602 if (!priv->bssid_fixed)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001603 goto out;
1604
1605 if (strlen(priv->desired_essid) == 0)
1606 goto out;
1607
1608 /* Read scan results from the firmware */
1609 err = hermes_read_ltv(hw, USER_BAP,
1610 HERMES_RID_SCANRESULTSTABLE,
1611 MAX_SCAN_LEN, &len, buf);
1612 if (err) {
1613 printk(KERN_ERR "%s: Cannot read scan results\n",
1614 dev->name);
1615 goto out;
1616 }
1617
1618 len = HERMES_RECLEN_TO_BYTES(len);
1619
1620 /* Go through the scan results looking for the channel of the AP
1621 * we were requested to join */
1622 for (; offset + atom_len <= len; offset += atom_len) {
1623 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001624 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1625 found = 1;
1626 break;
1627 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001628 }
1629
David Kilroya94e8422009-02-04 23:05:44 +00001630 if (!found) {
Pavel Roskinc89cc222005-09-01 20:06:06 -04001631 DEBUG(1, "%s: Requested AP not found in scan results\n",
1632 dev->name);
1633 goto out;
1634 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001635
Christoph Hellwig16739b02005-06-19 01:27:51 +02001636 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1637 req.channel = atom->channel; /* both are little-endian */
1638 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1639 &req);
1640 if (err)
1641 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1642
1643 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001644 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001645
1646 fail_lock:
1647 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001648}
1649
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001650/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001651static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001652{
David Howellsc4028952006-11-22 14:57:56 +00001653 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001654 struct hermes *hw = &priv->hw;
1655 union iwreq_data wrqu;
1656 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001657
David Kilroy499b7022008-12-09 21:46:29 +00001658 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001659 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1660 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001661 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001662
1663 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1664
1665 /* Send event to user space */
1666 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001667}
1668
David Kilroy06009fd2008-08-21 23:28:03 +01001669static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1670{
1671 struct net_device *dev = priv->ndev;
1672 struct hermes *hw = &priv->hw;
1673 union iwreq_data wrqu;
1674 int err;
1675 u8 buf[88];
1676 u8 *ie;
1677
1678 if (!priv->has_wpa)
1679 return;
1680
David Kilroy499b7022008-12-09 21:46:29 +00001681 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001682 sizeof(buf), NULL, &buf);
1683 if (err != 0)
1684 return;
1685
1686 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1687 if (ie) {
1688 int rem = sizeof(buf) - (ie - &buf[0]);
1689 wrqu.data.length = ie[1] + 2;
1690 if (wrqu.data.length > rem)
1691 wrqu.data.length = rem;
1692
1693 if (wrqu.data.length)
1694 /* Send event to user space */
1695 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1696 }
1697}
1698
1699static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1700{
1701 struct net_device *dev = priv->ndev;
1702 struct hermes *hw = &priv->hw;
1703 union iwreq_data wrqu;
1704 int err;
1705 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1706 u8 *ie;
1707
1708 if (!priv->has_wpa)
1709 return;
1710
David Kilroy499b7022008-12-09 21:46:29 +00001711 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001712 sizeof(buf), NULL, &buf);
1713 if (err != 0)
1714 return;
1715
1716 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1717 if (ie) {
1718 int rem = sizeof(buf) - (ie - &buf[0]);
1719 wrqu.data.length = ie[1] + 2;
1720 if (wrqu.data.length > rem)
1721 wrqu.data.length = rem;
1722
1723 if (wrqu.data.length)
1724 /* Send event to user space */
1725 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1726 }
1727}
1728
David Kilroy6cd90b12008-08-21 23:28:00 +01001729static void orinoco_send_wevents(struct work_struct *work)
1730{
1731 struct orinoco_private *priv =
1732 container_of(work, struct orinoco_private, wevent_work);
1733 unsigned long flags;
1734
1735 if (orinoco_lock(priv, &flags) != 0)
1736 return;
1737
David Kilroy06009fd2008-08-21 23:28:03 +01001738 orinoco_send_assocreqie_wevent(priv);
1739 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001740 orinoco_send_bssid_wevent(priv);
1741
1742 orinoco_unlock(priv, &flags);
1743}
Dan Williams1e3428e2007-10-10 23:56:25 -04001744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1746{
1747 struct orinoco_private *priv = netdev_priv(dev);
1748 u16 infofid;
1749 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001750 __le16 len;
1751 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 } __attribute__ ((packed)) info;
1753 int len, type;
1754 int err;
1755
1756 /* This is an answer to an INQUIRE command that we did earlier,
1757 * or an information "event" generated by the card
1758 * The controller return to us a pseudo frame containing
1759 * the information in question - Jean II */
1760 infofid = hermes_read_regn(hw, INFOFID);
1761
1762 /* Read the info frame header - don't try too hard */
1763 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1764 infofid, 0);
1765 if (err) {
1766 printk(KERN_ERR "%s: error %d reading info frame. "
1767 "Frame dropped.\n", dev->name, err);
1768 return;
1769 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001770
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1772 type = le16_to_cpu(info.type);
1773
1774 switch (type) {
1775 case HERMES_INQ_TALLIES: {
1776 struct hermes_tallies_frame tallies;
1777 struct iw_statistics *wstats = &priv->wstats;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 if (len > sizeof(tallies)) {
1780 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1781 dev->name, len);
1782 len = sizeof(tallies);
1783 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001784
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001785 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1786 infofid, sizeof(info));
1787 if (err)
1788 break;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001789
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 /* Increment our various counters */
1791 /* wstats->discard.nwid - no wrong BSSID stuff */
1792 wstats->discard.code +=
1793 le16_to_cpu(tallies.RxWEPUndecryptable);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001794 if (len == sizeof(tallies))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 wstats->discard.code +=
1796 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1797 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1798 wstats->discard.misc +=
1799 le16_to_cpu(tallies.TxDiscardsWrongSA);
1800 wstats->discard.fragment +=
1801 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1802 wstats->discard.retries +=
1803 le16_to_cpu(tallies.TxRetryLimitExceeded);
1804 /* wstats->miss.beacon - no match */
1805 }
1806 break;
1807 case HERMES_INQ_LINKSTATUS: {
1808 struct hermes_linkstatus linkstatus;
1809 u16 newstatus;
1810 int connected;
1811
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001812 if (priv->iw_mode == IW_MODE_MONITOR)
1813 break;
1814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 if (len != sizeof(linkstatus)) {
1816 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1817 dev->name, len);
1818 break;
1819 }
1820
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001821 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1822 infofid, sizeof(info));
1823 if (err)
1824 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 newstatus = le16_to_cpu(linkstatus.linkstatus);
1826
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001827 /* Symbol firmware uses "out of range" to signal that
1828 * the hostscan frame can be requested. */
1829 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1830 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1831 priv->has_hostscan && priv->scan_inprogress) {
1832 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1833 break;
1834 }
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1837 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1838 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1839
1840 if (connected)
1841 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001842 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 netif_carrier_off(dev);
1844
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001845 if (newstatus != priv->last_linkstatus) {
1846 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001848 /* The info frame contains only one word which is the
1849 * status (see hermes.h). The status is pretty boring
1850 * in itself, that's why we export the new BSSID...
1851 * Jean II */
1852 schedule_work(&priv->wevent_work);
1853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 }
1855 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001856 case HERMES_INQ_SCAN:
1857 if (!priv->scan_inprogress && priv->bssid_fixed &&
1858 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1859 schedule_work(&priv->join_work);
1860 break;
1861 }
1862 /* fall through */
1863 case HERMES_INQ_HOSTSCAN:
1864 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1865 /* Result of a scanning. Contains information about
1866 * cells in the vicinity - Jean II */
1867 union iwreq_data wrqu;
1868 unsigned char *buf;
1869
Dan Williams1e3428e2007-10-10 23:56:25 -04001870 /* Scan is no longer in progress */
1871 priv->scan_inprogress = 0;
1872
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001873 /* Sanity check */
1874 if (len > 4096) {
1875 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1876 dev->name, len);
1877 break;
1878 }
1879
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001880 /* Allocate buffer for results */
1881 buf = kmalloc(len, GFP_ATOMIC);
1882 if (buf == NULL)
1883 /* No memory, so can't printk()... */
1884 break;
1885
1886 /* Read scan data */
1887 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1888 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001889 if (err) {
1890 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001891 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001892 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001893
1894#ifdef ORINOCO_DEBUG
1895 {
1896 int i;
1897 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
David Kilroya94e8422009-02-04 23:05:44 +00001898 for (i = 1; i < (len * 2); i++)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001899 printk(":%02X", buf[i]);
1900 printk("]\n");
1901 }
1902#endif /* ORINOCO_DEBUG */
1903
David Kilroyaea48b12009-02-04 23:05:49 +00001904 if (orinoco_process_scan_results(priv, buf, len) == 0) {
Dan Williams1e3428e2007-10-10 23:56:25 -04001905 /* Send an empty event to user space.
1906 * We don't send the received data on the event because
1907 * it would require us to do complex transcoding, and
1908 * we want to minimise the work done in the irq handler
1909 * Use a request to extract the data - Jean II */
1910 wrqu.data.length = 0;
1911 wrqu.data.flags = 0;
1912 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1913 }
1914 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001915 }
1916 break;
David Kilroy01632fa2008-08-21 23:27:58 +01001917 case HERMES_INQ_CHANNELINFO:
1918 {
1919 struct agere_ext_scan_info *bss;
1920
1921 if (!priv->scan_inprogress) {
1922 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1923 "len=%d\n", dev->name, len);
1924 break;
1925 }
1926
1927 /* An empty result indicates that the scan is complete */
1928 if (len == 0) {
1929 union iwreq_data wrqu;
1930
1931 /* Scan is no longer in progress */
1932 priv->scan_inprogress = 0;
1933
1934 wrqu.data.length = 0;
1935 wrqu.data.flags = 0;
1936 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1937 break;
1938 }
1939
1940 /* Sanity check */
1941 else if (len > sizeof(*bss)) {
1942 printk(KERN_WARNING
1943 "%s: Ext scan results too large (%d bytes). "
1944 "Truncating results to %zd bytes.\n",
1945 dev->name, len, sizeof(*bss));
1946 len = sizeof(*bss);
1947 } else if (len < (offsetof(struct agere_ext_scan_info,
1948 data) + 2)) {
1949 /* Drop this result now so we don't have to
1950 * keep checking later */
1951 printk(KERN_WARNING
1952 "%s: Ext scan results too short (%d bytes)\n",
1953 dev->name, len);
1954 break;
1955 }
1956
1957 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1958 if (bss == NULL)
1959 break;
1960
1961 /* Read scan data */
1962 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1963 infofid, sizeof(info));
1964 if (err) {
1965 kfree(bss);
1966 break;
1967 }
1968
1969 orinoco_add_ext_scan_result(priv, bss);
1970
1971 kfree(bss);
1972 break;
1973 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001974 case HERMES_INQ_SEC_STAT_AGERE:
1975 /* Security status (Agere specific) */
1976 /* Ignore this frame for now */
1977 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1978 break;
1979 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 default:
1981 printk(KERN_DEBUG "%s: Unknown information frame received: "
1982 "type 0x%04x, length %d\n", dev->name, type, len);
1983 /* We don't actually do anything about it */
1984 break;
1985 }
1986}
1987
1988static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1989{
1990 if (net_ratelimit())
1991 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1992}
1993
1994/********************************************************************/
1995/* Internal hardware control routines */
1996/********************************************************************/
1997
1998int __orinoco_up(struct net_device *dev)
1999{
2000 struct orinoco_private *priv = netdev_priv(dev);
2001 struct hermes *hw = &priv->hw;
2002 int err;
2003
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002004 netif_carrier_off(dev); /* just to make sure */
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 err = __orinoco_program_rids(dev);
2007 if (err) {
2008 printk(KERN_ERR "%s: Error %d configuring card\n",
2009 dev->name, err);
2010 return err;
2011 }
2012
2013 /* Fire things up again */
2014 hermes_set_irqmask(hw, ORINOCO_INTEN);
2015 err = hermes_enable_port(hw, 0);
2016 if (err) {
2017 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2018 dev->name, err);
2019 return err;
2020 }
2021
2022 netif_start_queue(dev);
2023
2024 return 0;
2025}
David Kilroy21312662009-02-04 23:05:47 +00002026EXPORT_SYMBOL(__orinoco_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
2028int __orinoco_down(struct net_device *dev)
2029{
2030 struct orinoco_private *priv = netdev_priv(dev);
2031 struct hermes *hw = &priv->hw;
2032 int err;
2033
2034 netif_stop_queue(dev);
2035
David Kilroya94e8422009-02-04 23:05:44 +00002036 if (!priv->hw_unavailable) {
2037 if (!priv->broken_disableport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 err = hermes_disable_port(hw, 0);
2039 if (err) {
2040 /* Some firmwares (e.g. Intersil 1.3.x) seem
2041 * to have problems disabling the port, oh
2042 * well, too bad. */
2043 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2044 dev->name, err);
2045 priv->broken_disableport = 1;
2046 }
2047 }
2048 hermes_set_irqmask(hw, 0);
2049 hermes_write_regn(hw, EVACK, 0xffff);
2050 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 /* firmware will have to reassociate */
2053 netif_carrier_off(dev);
2054 priv->last_linkstatus = 0xffff;
2055
2056 return 0;
2057}
David Kilroy21312662009-02-04 23:05:47 +00002058EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Pavel Roskin37a6c612006-04-07 04:10:49 -04002060static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
2062 struct orinoco_private *priv = netdev_priv(dev);
2063 struct hermes *hw = &priv->hw;
2064 int err;
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04002067 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 /* Try workaround for old Symbol firmware bug */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2070 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Kilroy21312662009-02-04 23:05:47 +00002071
2072 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2073 "(old Symbol firmware?). Work around %s\n",
2074 dev->name, err ? "failed!" : "ok.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 }
2076
2077 return err;
2078}
2079
Pavel Roskin37a6c612006-04-07 04:10:49 -04002080int orinoco_reinit_firmware(struct net_device *dev)
2081{
2082 struct orinoco_private *priv = netdev_priv(dev);
2083 struct hermes *hw = &priv->hw;
2084 int err;
2085
2086 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04002087 if (priv->do_fw_download && !err) {
2088 err = orinoco_download(priv);
2089 if (err)
2090 priv->do_fw_download = 0;
2091 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04002092 if (!err)
2093 err = orinoco_allocate_fid(dev);
2094
2095 return err;
2096}
David Kilroy21312662009-02-04 23:05:47 +00002097EXPORT_SYMBOL(orinoco_reinit_firmware);
Pavel Roskin37a6c612006-04-07 04:10:49 -04002098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2100{
2101 hermes_t *hw = &priv->hw;
David Kilroyb2f30a02009-02-04 23:05:46 +00002102 int ratemode = priv->bitratemode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 int err = 0;
2104
David Kilroyb2f30a02009-02-04 23:05:46 +00002105 if (ratemode >= BITRATE_TABLE_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
David Kilroyb2f30a02009-02-04 23:05:46 +00002107 priv->ndev->name, ratemode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 return -EINVAL;
2109 }
2110
2111 switch (priv->firmware_type) {
2112 case FIRMWARE_TYPE_AGERE:
2113 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002114 HERMES_RID_CNFTXRATECONTROL,
2115 bitrate_table[ratemode].agere_txratectrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 break;
2117 case FIRMWARE_TYPE_INTERSIL:
2118 case FIRMWARE_TYPE_SYMBOL:
2119 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002120 HERMES_RID_CNFTXRATECONTROL,
2121 bitrate_table[ratemode].intersil_txratectrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 break;
2123 default:
2124 BUG();
2125 }
2126
2127 return err;
2128}
2129
Christoph Hellwig16739b02005-06-19 01:27:51 +02002130/* Set fixed AP address */
2131static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2132{
2133 int roaming_flag;
2134 int err = 0;
2135 hermes_t *hw = &priv->hw;
2136
2137 switch (priv->firmware_type) {
2138 case FIRMWARE_TYPE_AGERE:
2139 /* not supported */
2140 break;
2141 case FIRMWARE_TYPE_INTERSIL:
2142 if (priv->bssid_fixed)
2143 roaming_flag = 2;
2144 else
2145 roaming_flag = 1;
2146
2147 err = hermes_write_wordrec(hw, USER_BAP,
2148 HERMES_RID_CNFROAMINGMODE,
2149 roaming_flag);
2150 break;
2151 case FIRMWARE_TYPE_SYMBOL:
2152 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2153 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2154 &priv->desired_bssid);
2155 break;
2156 }
2157 return err;
2158}
2159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160/* Change the WEP keys and/or the current keys. Can be called
David Kilroyd03032a2008-08-21 23:28:02 +01002161 * either from __orinoco_hw_setup_enc() or directly from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 * orinoco_ioctl_setiwencode(). In the later case the association
2163 * with the AP is not broken (if the firmware can handle it),
2164 * which is needed for 802.1x implementations. */
2165static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2166{
2167 hermes_t *hw = &priv->hw;
2168 int err = 0;
2169
2170 switch (priv->firmware_type) {
2171 case FIRMWARE_TYPE_AGERE:
2172 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2173 HERMES_RID_CNFWEPKEYS_AGERE,
2174 &priv->keys);
2175 if (err)
2176 return err;
2177 err = hermes_write_wordrec(hw, USER_BAP,
2178 HERMES_RID_CNFTXKEY_AGERE,
2179 priv->tx_key);
2180 if (err)
2181 return err;
2182 break;
2183 case FIRMWARE_TYPE_INTERSIL:
2184 case FIRMWARE_TYPE_SYMBOL:
2185 {
2186 int keylen;
2187 int i;
2188
David Kilroyb2f30a02009-02-04 23:05:46 +00002189 /* Force uniform key length to work around
2190 * firmware bugs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002192
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 if (keylen > LARGE_KEY_SIZE) {
2194 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2195 priv->ndev->name, priv->tx_key, keylen);
2196 return -E2BIG;
2197 }
2198
2199 /* Write all 4 keys */
David Kilroya94e8422009-02-04 23:05:44 +00002200 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 err = hermes_write_ltv(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002202 HERMES_RID_CNFDEFAULTKEY0 + i,
2203 HERMES_BYTES_TO_RECLEN(keylen),
2204 priv->keys[i].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 if (err)
2206 return err;
2207 }
2208
2209 /* Write the index of the key used in transmission */
2210 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002211 HERMES_RID_CNFWEPDEFAULTKEYID,
2212 priv->tx_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if (err)
2214 return err;
2215 }
2216 break;
2217 }
2218
2219 return 0;
2220}
2221
David Kilroyd03032a2008-08-21 23:28:02 +01002222static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
2224 hermes_t *hw = &priv->hw;
2225 int err = 0;
2226 int master_wep_flag;
2227 int auth_flag;
David Kilroy4ae6ee22008-08-21 23:27:59 +01002228 int enc_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
David Kilroyd03032a2008-08-21 23:28:02 +01002230 /* Setup WEP keys for WEP and WPA */
2231 if (priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 __orinoco_hw_setup_wepkeys(priv);
2233
2234 if (priv->wep_restrict)
2235 auth_flag = HERMES_AUTH_SHARED_KEY;
2236 else
2237 auth_flag = HERMES_AUTH_OPEN;
2238
David Kilroyd03032a2008-08-21 23:28:02 +01002239 if (priv->wpa_enabled)
2240 enc_flag = 2;
2241 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
David Kilroy4ae6ee22008-08-21 23:27:59 +01002242 enc_flag = 1;
2243 else
2244 enc_flag = 0;
2245
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 switch (priv->firmware_type) {
2247 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002248 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 /* Enable the shared-key authentication. */
2250 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002251 HERMES_RID_CNFAUTHENTICATION_AGERE,
2252 auth_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 }
2254 err = hermes_write_wordrec(hw, USER_BAP,
2255 HERMES_RID_CNFWEPENABLED_AGERE,
David Kilroy4ae6ee22008-08-21 23:27:59 +01002256 enc_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 if (err)
2258 return err;
David Kilroyd03032a2008-08-21 23:28:02 +01002259
2260 if (priv->has_wpa) {
2261 /* Set WPA key management */
2262 err = hermes_write_wordrec(hw, USER_BAP,
2263 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2264 priv->key_mgmt);
2265 if (err)
2266 return err;
2267 }
2268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 break;
2270
2271 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2272 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002273 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 if (priv->wep_restrict ||
2275 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2276 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2277 HERMES_WEP_EXCL_UNENCRYPTED;
2278 else
2279 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2280
2281 err = hermes_write_wordrec(hw, USER_BAP,
2282 HERMES_RID_CNFAUTHENTICATION,
2283 auth_flag);
2284 if (err)
2285 return err;
2286 } else
2287 master_wep_flag = 0;
2288
2289 if (priv->iw_mode == IW_MODE_MONITOR)
2290 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2291
2292 /* Master WEP setting : on/off */
2293 err = hermes_write_wordrec(hw, USER_BAP,
2294 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2295 master_wep_flag);
2296 if (err)
David Kilroy6fe9deb2009-02-04 23:05:43 +00002297 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 break;
2300 }
2301
2302 return 0;
2303}
2304
David Kilroyd03032a2008-08-21 23:28:02 +01002305/* key must be 32 bytes, including the tx and rx MIC keys.
2306 * rsc must be 8 bytes
2307 * tsc must be 8 bytes or NULL
2308 */
2309static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2310 u8 *key, u8 *rsc, u8 *tsc)
2311{
2312 struct {
2313 __le16 idx;
2314 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2315 u8 key[TKIP_KEYLEN];
2316 u8 tx_mic[MIC_KEYLEN];
2317 u8 rx_mic[MIC_KEYLEN];
2318 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2319 } __attribute__ ((packed)) buf;
2320 int ret;
2321 int err;
2322 int k;
2323 u16 xmitting;
2324
2325 key_idx &= 0x3;
2326
2327 if (set_tx)
2328 key_idx |= 0x8000;
2329
2330 buf.idx = cpu_to_le16(key_idx);
2331 memcpy(buf.key, key,
2332 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2333
2334 if (rsc == NULL)
2335 memset(buf.rsc, 0, sizeof(buf.rsc));
2336 else
2337 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2338
2339 if (tsc == NULL) {
2340 memset(buf.tsc, 0, sizeof(buf.tsc));
2341 buf.tsc[4] = 0x10;
2342 } else {
2343 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2344 }
2345
2346 /* Wait upto 100ms for tx queue to empty */
2347 k = 100;
2348 do {
2349 k--;
2350 udelay(1000);
2351 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2352 &xmitting);
2353 if (ret)
2354 break;
2355 } while ((k > 0) && xmitting);
2356
2357 if (k == 0)
2358 ret = -ETIMEDOUT;
2359
2360 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2361 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2362 &buf);
2363
2364 return ret ? ret : err;
2365}
2366
2367static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2368 int key_idx)
2369{
2370 hermes_t *hw = &priv->hw;
2371 int err;
2372
2373 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2374 err = hermes_write_wordrec(hw, USER_BAP,
2375 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2376 key_idx);
2377 if (err)
2378 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2379 priv->ndev->name, err, key_idx);
2380 return err;
2381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383static int __orinoco_program_rids(struct net_device *dev)
2384{
2385 struct orinoco_private *priv = netdev_priv(dev);
2386 hermes_t *hw = &priv->hw;
2387 int err;
2388 struct hermes_idstring idbuf;
2389
2390 /* Set the MAC address */
2391 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2392 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2393 if (err) {
2394 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2395 dev->name, err);
2396 return err;
2397 }
2398
2399 /* Set up the link mode */
2400 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2401 priv->port_type);
2402 if (err) {
2403 printk(KERN_ERR "%s: Error %d setting port type\n",
2404 dev->name, err);
2405 return err;
2406 }
2407 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04002408 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2409 err = hermes_write_wordrec(hw, USER_BAP,
2410 HERMES_RID_CNFOWNCHANNEL,
2411 priv->channel);
2412 if (err) {
2413 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2414 dev->name, err, priv->channel);
2415 return err;
2416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
2418
2419 if (priv->has_ibss) {
2420 u16 createibss;
2421
2422 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2423 printk(KERN_WARNING "%s: This firmware requires an "
2424 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2425 /* With wvlan_cs, in this case, we would crash.
2426 * hopefully, this driver will behave better...
2427 * Jean II */
2428 createibss = 0;
2429 } else {
2430 createibss = priv->createibss;
2431 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 err = hermes_write_wordrec(hw, USER_BAP,
2434 HERMES_RID_CNFCREATEIBSS,
2435 createibss);
2436 if (err) {
2437 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2438 dev->name, err);
2439 return err;
2440 }
2441 }
2442
Christoph Hellwig16739b02005-06-19 01:27:51 +02002443 /* Set the desired BSSID */
2444 err = __orinoco_hw_set_wap(priv);
2445 if (err) {
2446 printk(KERN_ERR "%s: Error %d setting AP address\n",
2447 dev->name, err);
2448 return err;
2449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 /* Set the desired ESSID */
2451 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2452 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2453 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2454 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00002455 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2456 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 if (err) {
2458 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2459 dev->name, err);
2460 return err;
2461 }
2462 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00002463 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2464 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 if (err) {
2466 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2467 dev->name, err);
2468 return err;
2469 }
2470
2471 /* Set the station name */
2472 idbuf.len = cpu_to_le16(strlen(priv->nick));
2473 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2474 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2475 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2476 &idbuf);
2477 if (err) {
2478 printk(KERN_ERR "%s: Error %d setting nickname\n",
2479 dev->name, err);
2480 return err;
2481 }
2482
2483 /* Set AP density */
2484 if (priv->has_sensitivity) {
2485 err = hermes_write_wordrec(hw, USER_BAP,
2486 HERMES_RID_CNFSYSTEMSCALE,
2487 priv->ap_density);
2488 if (err) {
David Kilroyb2f30a02009-02-04 23:05:46 +00002489 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 "Disabling sensitivity control\n",
2491 dev->name, err);
2492
2493 priv->has_sensitivity = 0;
2494 }
2495 }
2496
2497 /* Set RTS threshold */
2498 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2499 priv->rts_thresh);
2500 if (err) {
2501 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2502 dev->name, err);
2503 return err;
2504 }
2505
2506 /* Set fragmentation threshold or MWO robustness */
2507 if (priv->has_mwo)
2508 err = hermes_write_wordrec(hw, USER_BAP,
2509 HERMES_RID_CNFMWOROBUST_AGERE,
2510 priv->mwo_robust);
2511 else
2512 err = hermes_write_wordrec(hw, USER_BAP,
2513 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2514 priv->frag_thresh);
2515 if (err) {
2516 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2517 dev->name, err);
2518 return err;
2519 }
2520
2521 /* Set bitrate */
2522 err = __orinoco_hw_set_bitrate(priv);
2523 if (err) {
2524 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2525 dev->name, err);
2526 return err;
2527 }
2528
2529 /* Set power management */
2530 if (priv->has_pm) {
2531 err = hermes_write_wordrec(hw, USER_BAP,
2532 HERMES_RID_CNFPMENABLED,
2533 priv->pm_on);
2534 if (err) {
2535 printk(KERN_ERR "%s: Error %d setting up PM\n",
2536 dev->name, err);
2537 return err;
2538 }
2539
2540 err = hermes_write_wordrec(hw, USER_BAP,
2541 HERMES_RID_CNFMULTICASTRECEIVE,
2542 priv->pm_mcast);
2543 if (err) {
2544 printk(KERN_ERR "%s: Error %d setting up PM\n",
2545 dev->name, err);
2546 return err;
2547 }
2548 err = hermes_write_wordrec(hw, USER_BAP,
2549 HERMES_RID_CNFMAXSLEEPDURATION,
2550 priv->pm_period);
2551 if (err) {
2552 printk(KERN_ERR "%s: Error %d setting up PM\n",
2553 dev->name, err);
2554 return err;
2555 }
2556 err = hermes_write_wordrec(hw, USER_BAP,
2557 HERMES_RID_CNFPMHOLDOVERDURATION,
2558 priv->pm_timeout);
2559 if (err) {
2560 printk(KERN_ERR "%s: Error %d setting up PM\n",
2561 dev->name, err);
2562 return err;
2563 }
2564 }
2565
2566 /* Set preamble - only for Symbol so far... */
2567 if (priv->has_preamble) {
2568 err = hermes_write_wordrec(hw, USER_BAP,
2569 HERMES_RID_CNFPREAMBLE_SYMBOL,
2570 priv->preamble);
2571 if (err) {
2572 printk(KERN_ERR "%s: Error %d setting preamble\n",
2573 dev->name, err);
2574 return err;
2575 }
2576 }
2577
2578 /* Set up encryption */
David Kilroyd03032a2008-08-21 23:28:02 +01002579 if (priv->has_wep || priv->has_wpa) {
2580 err = __orinoco_hw_setup_enc(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 if (err) {
David Kilroyd03032a2008-08-21 23:28:02 +01002582 printk(KERN_ERR "%s: Error %d activating encryption\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 dev->name, err);
2584 return err;
2585 }
2586 }
2587
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002588 if (priv->iw_mode == IW_MODE_MONITOR) {
2589 /* Enable monitor mode */
2590 dev->type = ARPHRD_IEEE80211;
David Kilroy6fe9deb2009-02-04 23:05:43 +00002591 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002592 HERMES_TEST_MONITOR, 0, NULL);
2593 } else {
2594 /* Disable monitor mode */
2595 dev->type = ARPHRD_ETHER;
2596 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2597 HERMES_TEST_STOP, 0, NULL);
2598 }
2599 if (err)
2600 return err;
2601
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 /* Set promiscuity / multicast*/
2603 priv->promiscuous = 0;
2604 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07002605
2606 /* FIXME: what about netif_tx_lock */
2607 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608
2609 return 0;
2610}
2611
2612/* FIXME: return int? */
2613static void
2614__orinoco_set_multicast_list(struct net_device *dev)
2615{
2616 struct orinoco_private *priv = netdev_priv(dev);
2617 hermes_t *hw = &priv->hw;
2618 int err = 0;
2619 int promisc, mc_count;
2620
2621 /* The Hermes doesn't seem to have an allmulti mode, so we go
2622 * into promiscuous mode and let the upper levels deal. */
David Kilroya94e8422009-02-04 23:05:44 +00002623 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2624 (dev->mc_count > MAX_MULTICAST(priv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 promisc = 1;
2626 mc_count = 0;
2627 } else {
2628 promisc = 0;
2629 mc_count = dev->mc_count;
2630 }
2631
2632 if (promisc != priv->promiscuous) {
2633 err = hermes_write_wordrec(hw, USER_BAP,
2634 HERMES_RID_CNFPROMISCUOUSMODE,
2635 promisc);
2636 if (err) {
2637 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2638 dev->name, err);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002639 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 priv->promiscuous = promisc;
2641 }
2642
David Kilroy667d4102008-08-23 19:03:34 +01002643 /* If we're not in promiscuous mode, then we need to set the
2644 * group address if either we want to multicast, or if we were
2645 * multicasting and want to stop */
David Kilroya94e8422009-02-04 23:05:44 +00002646 if (!promisc && (mc_count || priv->mc_count)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 struct dev_mc_list *p = dev->mc_list;
2648 struct hermes_multicast mclist;
2649 int i;
2650
2651 for (i = 0; i < mc_count; i++) {
2652 /* paranoia: is list shorter than mc_count? */
David Kilroya94e8422009-02-04 23:05:44 +00002653 BUG_ON(!p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 /* paranoia: bad address size in list? */
2655 BUG_ON(p->dmi_addrlen != ETH_ALEN);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002656
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2658 p = p->next;
2659 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002660
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 if (p)
2662 printk(KERN_WARNING "%s: Multicast list is "
2663 "longer than mc_count\n", dev->name);
2664
David Kilroy667d4102008-08-23 19:03:34 +01002665 err = hermes_write_ltv(hw, USER_BAP,
2666 HERMES_RID_CNFGROUPADDRESSES,
2667 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2668 &mclist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 if (err)
2670 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2671 dev->name, err);
2672 else
2673 priv->mc_count = mc_count;
2674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675}
2676
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677/* This must be called from user context, without locks held - use
2678 * schedule_work() */
David Howellsc4028952006-11-22 14:57:56 +00002679static void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680{
David Howellsc4028952006-11-22 14:57:56 +00002681 struct orinoco_private *priv =
2682 container_of(work, struct orinoco_private, reset_work);
2683 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002685 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 unsigned long flags;
2687
2688 if (orinoco_lock(priv, &flags) != 0)
2689 /* When the hardware becomes available again, whatever
2690 * detects that is responsible for re-initializing
2691 * it. So no need for anything further */
2692 return;
2693
2694 netif_stop_queue(dev);
2695
2696 /* Shut off interrupts. Depending on what state the hardware
2697 * is in, this might not work, but we'll try anyway */
2698 hermes_set_irqmask(hw, 0);
2699 hermes_write_regn(hw, EVACK, 0xffff);
2700
2701 priv->hw_unavailable++;
2702 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2703 netif_carrier_off(dev);
2704
2705 orinoco_unlock(priv, &flags);
2706
David Kilroy6fe9deb2009-02-04 23:05:43 +00002707 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04002708 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002709 priv->scan_inprogress = 0;
2710
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002711 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002713 if (err) {
2714 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2715 "performing hard reset\n", dev->name, err);
2716 goto disable;
2717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
2719
2720 err = orinoco_reinit_firmware(dev);
2721 if (err) {
2722 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2723 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002724 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 }
2726
David Kilroyb2f30a02009-02-04 23:05:46 +00002727 /* This has to be called from user context */
2728 spin_lock_irq(&priv->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 priv->hw_unavailable--;
2731
2732 /* priv->open or priv->hw_unavailable might have changed while
2733 * we dropped the lock */
David Kilroya94e8422009-02-04 23:05:44 +00002734 if (priv->open && (!priv->hw_unavailable)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 err = __orinoco_up(dev);
2736 if (err) {
2737 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2738 dev->name, err);
2739 } else
2740 dev->trans_start = jiffies;
2741 }
2742
2743 spin_unlock_irq(&priv->lock);
2744
2745 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002746 disable:
2747 hermes_set_irqmask(hw, 0);
2748 netif_device_detach(dev);
2749 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750}
2751
2752/********************************************************************/
2753/* Interrupt handler */
2754/********************************************************************/
2755
2756static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2757{
2758 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2759}
2760
2761static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2762{
2763 /* This seems to happen a fair bit under load, but ignoring it
2764 seems to work fine...*/
2765 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2766 dev->name);
2767}
2768
David Howells7d12e782006-10-05 14:55:46 +01002769irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04002771 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 struct orinoco_private *priv = netdev_priv(dev);
2773 hermes_t *hw = &priv->hw;
2774 int count = MAX_IRQLOOPS_PER_IRQ;
2775 u16 evstat, events;
David Kilroy21312662009-02-04 23:05:47 +00002776 /* These are used to detect a runaway interrupt situation.
2777 *
2778 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2779 * we panic and shut down the hardware
2780 */
2781 /* jiffies value the last time we were called */
2782 static int last_irq_jiffy; /* = 0 */
2783 static int loops_this_jiffy; /* = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 unsigned long flags;
2785
2786 if (orinoco_lock(priv, &flags) != 0) {
2787 /* If hw is unavailable - we don't know if the irq was
2788 * for us or not */
2789 return IRQ_HANDLED;
2790 }
2791
2792 evstat = hermes_read_regn(hw, EVSTAT);
2793 events = evstat & hw->inten;
David Kilroya94e8422009-02-04 23:05:44 +00002794 if (!events) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 orinoco_unlock(priv, &flags);
2796 return IRQ_NONE;
2797 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002798
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 if (jiffies != last_irq_jiffy)
2800 loops_this_jiffy = 0;
2801 last_irq_jiffy = jiffies;
2802
2803 while (events && count--) {
2804 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2805 printk(KERN_WARNING "%s: IRQ handler is looping too "
2806 "much! Resetting.\n", dev->name);
2807 /* Disable interrupts for now */
2808 hermes_set_irqmask(hw, 0);
2809 schedule_work(&priv->reset_work);
2810 break;
2811 }
2812
2813 /* Check the card hasn't been removed */
David Kilroya94e8422009-02-04 23:05:44 +00002814 if (!hermes_present(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 DEBUG(0, "orinoco_interrupt(): card removed\n");
2816 break;
2817 }
2818
2819 if (events & HERMES_EV_TICK)
2820 __orinoco_ev_tick(dev, hw);
2821 if (events & HERMES_EV_WTERR)
2822 __orinoco_ev_wterr(dev, hw);
2823 if (events & HERMES_EV_INFDROP)
2824 __orinoco_ev_infdrop(dev, hw);
2825 if (events & HERMES_EV_INFO)
2826 __orinoco_ev_info(dev, hw);
2827 if (events & HERMES_EV_RX)
2828 __orinoco_ev_rx(dev, hw);
2829 if (events & HERMES_EV_TXEXC)
2830 __orinoco_ev_txexc(dev, hw);
2831 if (events & HERMES_EV_TX)
2832 __orinoco_ev_tx(dev, hw);
2833 if (events & HERMES_EV_ALLOC)
2834 __orinoco_ev_alloc(dev, hw);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002835
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002836 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 evstat = hermes_read_regn(hw, EVSTAT);
2839 events = evstat & hw->inten;
2840 };
2841
2842 orinoco_unlock(priv, &flags);
2843 return IRQ_HANDLED;
2844}
David Kilroy21312662009-02-04 23:05:47 +00002845EXPORT_SYMBOL(orinoco_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
2847/********************************************************************/
David Kilroy39d1ffe2008-11-22 10:37:28 +00002848/* Power management */
2849/********************************************************************/
2850#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2851static int orinoco_pm_notifier(struct notifier_block *notifier,
2852 unsigned long pm_event,
2853 void *unused)
2854{
2855 struct orinoco_private *priv = container_of(notifier,
2856 struct orinoco_private,
2857 pm_notifier);
2858
2859 /* All we need to do is cache the firmware before suspend, and
2860 * release it when we come out.
2861 *
2862 * Only need to do this if we're downloading firmware. */
2863 if (!priv->do_fw_download)
2864 return NOTIFY_DONE;
2865
2866 switch (pm_event) {
2867 case PM_HIBERNATION_PREPARE:
2868 case PM_SUSPEND_PREPARE:
2869 orinoco_cache_fw(priv, 0);
2870 break;
2871
2872 case PM_POST_RESTORE:
2873 /* Restore from hibernation failed. We need to clean
2874 * up in exactly the same way, so fall through. */
2875 case PM_POST_HIBERNATION:
2876 case PM_POST_SUSPEND:
2877 orinoco_uncache_fw(priv);
2878 break;
2879
2880 case PM_RESTORE_PREPARE:
2881 default:
2882 break;
2883 }
2884
2885 return NOTIFY_DONE;
2886}
2887#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2888#define orinoco_pm_notifier NULL
2889#endif
2890
2891/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892/* Initialization */
2893/********************************************************************/
2894
2895struct comp_id {
2896 u16 id, variant, major, minor;
2897} __attribute__ ((packed));
2898
2899static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2900{
2901 if (nic_id->id < 0x8000)
2902 return FIRMWARE_TYPE_AGERE;
2903 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2904 return FIRMWARE_TYPE_SYMBOL;
2905 else
2906 return FIRMWARE_TYPE_INTERSIL;
2907}
2908
2909/* Set priv->firmware type, determine firmware properties */
2910static int determine_firmware(struct net_device *dev)
2911{
2912 struct orinoco_private *priv = netdev_priv(dev);
2913 hermes_t *hw = &priv->hw;
2914 int err;
2915 struct comp_id nic_id, sta_id;
2916 unsigned int firmver;
Hennerich, Michaeldde6d432007-02-05 16:41:35 -08002917 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
2919 /* Get the hardware version */
2920 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2921 if (err) {
2922 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2923 dev->name, err);
2924 return err;
2925 }
2926
2927 le16_to_cpus(&nic_id.id);
2928 le16_to_cpus(&nic_id.variant);
2929 le16_to_cpus(&nic_id.major);
2930 le16_to_cpus(&nic_id.minor);
2931 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2932 dev->name, nic_id.id, nic_id.variant,
2933 nic_id.major, nic_id.minor);
2934
2935 priv->firmware_type = determine_firmware_type(&nic_id);
2936
2937 /* Get the firmware version */
2938 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2939 if (err) {
2940 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2941 dev->name, err);
2942 return err;
2943 }
2944
2945 le16_to_cpus(&sta_id.id);
2946 le16_to_cpus(&sta_id.variant);
2947 le16_to_cpus(&sta_id.major);
2948 le16_to_cpus(&sta_id.minor);
2949 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2950 dev->name, sta_id.id, sta_id.variant,
2951 sta_id.major, sta_id.minor);
2952
2953 switch (sta_id.id) {
2954 case 0x15:
2955 printk(KERN_ERR "%s: Primary firmware is active\n",
2956 dev->name);
2957 return -ENODEV;
2958 case 0x14b:
2959 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2960 dev->name);
2961 return -ENODEV;
2962 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2963 case 0x21: /* Symbol Spectrum24 Trilogy */
2964 break;
2965 default:
2966 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2967 dev->name);
2968 break;
2969 }
2970
2971 /* Default capabilities */
2972 priv->has_sensitivity = 1;
2973 priv->has_mwo = 0;
2974 priv->has_preamble = 0;
2975 priv->has_port3 = 1;
2976 priv->has_ibss = 1;
2977 priv->has_wep = 0;
2978 priv->has_big_wep = 0;
David Kilroy6eecad72008-08-21 23:27:56 +01002979 priv->has_alt_txcntl = 0;
David Kilroy01632fa2008-08-21 23:27:58 +01002980 priv->has_ext_scan = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01002981 priv->has_wpa = 0;
David Kilroy3994d502008-08-21 23:27:54 +01002982 priv->do_fw_download = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
2984 /* Determine capabilities from the firmware version */
2985 switch (priv->firmware_type) {
2986 case FIRMWARE_TYPE_AGERE:
2987 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2988 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2989 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2990 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2991
2992 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2993
2994 priv->has_ibss = (firmver >= 0x60006);
2995 priv->has_wep = (firmver >= 0x40020);
2996 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2997 Gold cards from the others? */
2998 priv->has_mwo = (firmver >= 0x60000);
2999 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3000 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003001 priv->has_hostscan = (firmver >= 0x8000a);
David Kilroy3994d502008-08-21 23:27:54 +01003002 priv->do_fw_download = 1;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003003 priv->broken_monitor = (firmver >= 0x80000);
David Kilroy6eecad72008-08-21 23:27:56 +01003004 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
David Kilroy01632fa2008-08-21 23:27:58 +01003005 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
David Kilroyd03032a2008-08-21 23:28:02 +01003006 priv->has_wpa = (firmver >= 0x9002a);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 /* Tested with Agere firmware :
3008 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3009 * Tested CableTron firmware : 4.32 => Anton */
3010 break;
3011 case FIRMWARE_TYPE_SYMBOL:
3012 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3013 /* Intel MAC : 00:02:B3:* */
3014 /* 3Com MAC : 00:50:DA:* */
3015 memset(tmp, 0, sizeof(tmp));
3016 /* Get the Symbol firmware version */
3017 err = hermes_read_ltv(hw, USER_BAP,
3018 HERMES_RID_SECONDARYVERSION_SYMBOL,
3019 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3020 if (err) {
3021 printk(KERN_WARNING
David Kilroyb2f30a02009-02-04 23:05:46 +00003022 "%s: Error %d reading Symbol firmware info. "
3023 "Wildly guessing capabilities...\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 dev->name, err);
3025 firmver = 0;
3026 tmp[0] = '\0';
3027 } else {
3028 /* The firmware revision is a string, the format is
3029 * something like : "V2.20-01".
3030 * Quick and dirty parsing... - Jean II
3031 */
David Kilroyb2f30a02009-02-04 23:05:46 +00003032 firmver = ((tmp[1] - '0') << 16)
3033 | ((tmp[3] - '0') << 12)
3034 | ((tmp[4] - '0') << 8)
3035 | ((tmp[6] - '0') << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 | (tmp[7] - '0');
3037
3038 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3039 }
3040
3041 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3042 "Symbol %s", tmp);
3043
3044 priv->has_ibss = (firmver >= 0x20000);
3045 priv->has_wep = (firmver >= 0x15012);
3046 priv->has_big_wep = (firmver >= 0x20000);
David Kilroy6fe9deb2009-02-04 23:05:43 +00003047 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048 (firmver >= 0x29000 && firmver < 0x30000) ||
3049 firmver >= 0x31000;
3050 priv->has_preamble = (firmver >= 0x20000);
3051 priv->ibss_port = 4;
David Kilroy3994d502008-08-21 23:27:54 +01003052
3053 /* Symbol firmware is found on various cards, but
3054 * there has been no attempt to check firmware
3055 * download on non-spectrum_cs based cards.
3056 *
3057 * Given that the Agere firmware download works
3058 * differently, we should avoid doing a firmware
3059 * download with the Symbol algorithm on non-spectrum
3060 * cards.
3061 *
3062 * For now we can identify a spectrum_cs based card
3063 * because it has a firmware reset function.
3064 */
3065 priv->do_fw_download = (priv->stop_fw != NULL);
3066
David Kilroy6fe9deb2009-02-04 23:05:43 +00003067 priv->broken_disableport = (firmver == 0x25013) ||
David Kilroyb2f30a02009-02-04 23:05:46 +00003068 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003069 priv->has_hostscan = (firmver >= 0x31001) ||
3070 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 /* Tested with Intel firmware : 0x20015 => Jean II */
3072 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3073 break;
3074 case FIRMWARE_TYPE_INTERSIL:
3075 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3076 * Samsung, Compaq 100/200 and Proxim are slightly
3077 * different and less well tested */
3078 /* D-Link MAC : 00:40:05:* */
3079 /* Addtron MAC : 00:90:D1:* */
3080 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3081 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3082 sta_id.variant);
3083
3084 firmver = ((unsigned long)sta_id.major << 16) |
3085 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3086
3087 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3088 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3089 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003090 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091
3092 if (firmver >= 0x000800)
3093 priv->ibss_port = 0;
3094 else {
3095 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3096 "than v0.8.x - several features not supported\n",
3097 dev->name);
3098 priv->ibss_port = 1;
3099 }
3100 break;
3101 }
3102 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3103 priv->fw_name);
3104
3105 return 0;
3106}
3107
3108static int orinoco_init(struct net_device *dev)
3109{
3110 struct orinoco_private *priv = netdev_priv(dev);
3111 hermes_t *hw = &priv->hw;
3112 int err = 0;
3113 struct hermes_idstring nickbuf;
3114 u16 reclen;
3115 int len;
3116
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 /* No need to lock, the hw_unavailable flag is already set in
3118 * alloc_orinocodev() */
Johannes Berg2c7060022008-10-30 22:09:54 +01003119 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120
3121 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04003122 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 if (err != 0) {
3124 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3125 dev->name, err);
3126 goto out;
3127 }
3128
3129 err = determine_firmware(dev);
3130 if (err != 0) {
3131 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3132 dev->name);
3133 goto out;
3134 }
3135
David Kilroy3994d502008-08-21 23:27:54 +01003136 if (priv->do_fw_download) {
David Kilroy39d1ffe2008-11-22 10:37:28 +00003137#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
David Kilroy74734312008-11-22 10:37:25 +00003138 orinoco_cache_fw(priv, 0);
David Kilroy39d1ffe2008-11-22 10:37:28 +00003139#endif
David Kilroy74734312008-11-22 10:37:25 +00003140
David Kilroy3994d502008-08-21 23:27:54 +01003141 err = orinoco_download(priv);
3142 if (err)
3143 priv->do_fw_download = 0;
3144
3145 /* Check firmware version again */
3146 err = determine_firmware(dev);
3147 if (err != 0) {
3148 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3149 dev->name);
3150 goto out;
3151 }
3152 }
3153
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 if (priv->has_port3)
David Kilroyb2f30a02009-02-04 23:05:46 +00003155 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
3156 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 if (priv->has_ibss)
3158 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3159 dev->name);
3160 if (priv->has_wep) {
David Kilroy21312662009-02-04 23:05:47 +00003161 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
3162 priv->has_big_wep ? "104" : "40");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 }
David Kilroy23edcc42008-08-21 23:28:05 +01003164 if (priv->has_wpa) {
David Kilroyd03032a2008-08-21 23:28:02 +01003165 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
David Kilroy23edcc42008-08-21 23:28:05 +01003166 if (orinoco_mic_init(priv)) {
3167 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3168 "algorithm. Disabling WPA support\n", dev->name);
3169 priv->has_wpa = 0;
3170 }
3171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172
David Kilroy01632fa2008-08-21 23:27:58 +01003173 /* Now we have the firmware capabilities, allocate appropiate
3174 * sized scan buffers */
3175 if (orinoco_bss_data_allocate(priv))
3176 goto out;
3177 orinoco_bss_data_init(priv);
3178
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 /* Get the MAC address */
3180 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3181 ETH_ALEN, NULL, dev->dev_addr);
3182 if (err) {
3183 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3184 dev->name);
3185 goto out;
3186 }
3187
Johannes Berge1749612008-10-27 15:59:26 -07003188 printk(KERN_DEBUG "%s: MAC address %pM\n",
3189 dev->name, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 /* Get the station name */
3192 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3193 sizeof(nickbuf), &reclen, &nickbuf);
3194 if (err) {
3195 printk(KERN_ERR "%s: failed to read station name\n",
3196 dev->name);
3197 goto out;
3198 }
3199 if (nickbuf.len)
3200 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3201 else
3202 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3203 memcpy(priv->nick, &nickbuf.val, len);
3204 priv->nick[len] = '\0';
3205
3206 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3207
Pavel Roskin37a6c612006-04-07 04:10:49 -04003208 err = orinoco_allocate_fid(dev);
3209 if (err) {
3210 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3211 dev->name);
3212 goto out;
3213 }
3214
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 /* Get allowed channels */
3216 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3217 &priv->channel_mask);
3218 if (err) {
3219 printk(KERN_ERR "%s: failed to read channel list!\n",
3220 dev->name);
3221 goto out;
3222 }
3223
3224 /* Get initial AP density */
3225 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3226 &priv->ap_density);
David Kilroy566f2d92009-02-04 23:05:45 +00003227 if (err || priv->ap_density < 1 || priv->ap_density > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 priv->has_sensitivity = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230 /* Get initial RTS threshold */
3231 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3232 &priv->rts_thresh);
3233 if (err) {
3234 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3235 dev->name);
3236 goto out;
3237 }
3238
3239 /* Get initial fragmentation settings */
3240 if (priv->has_mwo)
3241 err = hermes_read_wordrec(hw, USER_BAP,
3242 HERMES_RID_CNFMWOROBUST_AGERE,
3243 &priv->mwo_robust);
3244 else
David Kilroyb2f30a02009-02-04 23:05:46 +00003245 err = hermes_read_wordrec(hw, USER_BAP,
3246 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 &priv->frag_thresh);
3248 if (err) {
3249 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3250 dev->name);
3251 goto out;
3252 }
3253
3254 /* Power management setup */
3255 if (priv->has_pm) {
3256 priv->pm_on = 0;
3257 priv->pm_mcast = 1;
3258 err = hermes_read_wordrec(hw, USER_BAP,
3259 HERMES_RID_CNFMAXSLEEPDURATION,
3260 &priv->pm_period);
3261 if (err) {
3262 printk(KERN_ERR "%s: failed to read power management period!\n",
3263 dev->name);
3264 goto out;
3265 }
3266 err = hermes_read_wordrec(hw, USER_BAP,
3267 HERMES_RID_CNFPMHOLDOVERDURATION,
3268 &priv->pm_timeout);
3269 if (err) {
3270 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3271 dev->name);
3272 goto out;
3273 }
3274 }
3275
3276 /* Preamble setup */
3277 if (priv->has_preamble) {
3278 err = hermes_read_wordrec(hw, USER_BAP,
3279 HERMES_RID_CNFPREAMBLE_SYMBOL,
3280 &priv->preamble);
3281 if (err)
3282 goto out;
3283 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00003284
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 /* Set up the default configuration */
3286 priv->iw_mode = IW_MODE_INFRA;
3287 /* By default use IEEE/IBSS ad-hoc mode if we have it */
David Kilroya94e8422009-02-04 23:05:44 +00003288 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04003290 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
3292 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003293 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01003295 priv->wpa_enabled = 0;
3296 priv->tkip_cm_active = 0;
3297 priv->key_mgmt = 0;
3298 priv->wpa_ie_len = 0;
3299 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 /* Make the hardware available, as long as it hasn't been
3302 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3303 spin_lock_irq(&priv->lock);
3304 priv->hw_unavailable--;
3305 spin_unlock_irq(&priv->lock);
3306
3307 printk(KERN_DEBUG "%s: ready\n", dev->name);
3308
3309 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 return err;
3311}
3312
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03003313static const struct net_device_ops orinoco_netdev_ops = {
3314 .ndo_init = orinoco_init,
3315 .ndo_open = orinoco_open,
3316 .ndo_stop = orinoco_stop,
3317 .ndo_start_xmit = orinoco_xmit,
3318 .ndo_set_multicast_list = orinoco_set_multicast_list,
3319 .ndo_change_mtu = orinoco_change_mtu,
3320 .ndo_tx_timeout = orinoco_tx_timeout,
3321 .ndo_get_stats = orinoco_get_stats,
3322};
3323
David Kilroy3994d502008-08-21 23:27:54 +01003324struct net_device
3325*alloc_orinocodev(int sizeof_card,
3326 struct device *device,
3327 int (*hard_reset)(struct orinoco_private *),
3328 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329{
3330 struct net_device *dev;
3331 struct orinoco_private *priv;
3332
3333 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
Andrey Borzenkove129a942009-01-21 21:55:29 +03003334 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 return NULL;
3336 priv = netdev_priv(dev);
3337 priv->ndev = dev;
3338 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003339 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 + sizeof(struct orinoco_private));
3341 else
3342 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01003343 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344
3345 /* Setup / override net_device fields */
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03003346 dev->netdev_ops = &orinoco_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 dev->watchdog_timeo = HZ; /* 1 second timeout */
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02003348 dev->ethtool_ops = &orinoco_ethtool_ops;
Andrey Borzenkove129a942009-01-21 21:55:29 +03003349 dev->wireless_handlers = &orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04003350#ifdef WIRELESS_SPY
3351 priv->wireless_data.spy_data = &priv->spy_data;
3352 dev->wireless_data = &priv->wireless_data;
3353#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 /* we use the default eth_mac_addr for setting the MAC addr */
3355
David Kilroy23edcc42008-08-21 23:28:05 +01003356 /* Reserve space in skb for the SNAP header */
3357 dev->hard_header_len += ENCAPS_OVERHEAD;
3358
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 /* Set up default callbacks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01003361 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362
3363 spin_lock_init(&priv->lock);
3364 priv->open = 0;
3365 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3366 * before anything else touches the
3367 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00003368 INIT_WORK(&priv->reset_work, orinoco_reset);
3369 INIT_WORK(&priv->join_work, orinoco_join_ap);
3370 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371
David Kilroy31afcef2008-08-21 23:28:04 +01003372 INIT_LIST_HEAD(&priv->rx_list);
3373 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3374 (unsigned long) dev);
3375
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 netif_carrier_off(dev);
3377 priv->last_linkstatus = 0xffff;
3378
David Kilroy2cea7b22008-11-22 10:37:26 +00003379 priv->cached_pri_fw = NULL;
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04003380 priv->cached_fw = NULL;
3381
David Kilroy39d1ffe2008-11-22 10:37:28 +00003382 /* Register PM notifiers */
3383 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
3384 register_pm_notifier(&priv->pm_notifier);
3385
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387}
David Kilroy21312662009-02-04 23:05:47 +00003388EXPORT_SYMBOL(alloc_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
3390void free_orinocodev(struct net_device *dev)
3391{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003392 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy20953ad2009-01-07 00:23:55 +00003393 struct orinoco_rx_data *rx_data, *temp;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003394
David Kilroy20953ad2009-01-07 00:23:55 +00003395 /* If the tasklet is scheduled when we call tasklet_kill it
3396 * will run one final time. However the tasklet will only
3397 * drain priv->rx_list if the hw is still available. */
David Kilroy31afcef2008-08-21 23:28:04 +01003398 tasklet_kill(&priv->rx_tasklet);
David Kilroy74734312008-11-22 10:37:25 +00003399
David Kilroy20953ad2009-01-07 00:23:55 +00003400 /* Explicitly drain priv->rx_list */
3401 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
3402 list_del(&rx_data->list);
3403
3404 dev_kfree_skb(rx_data->skb);
3405 kfree(rx_data->desc);
3406 kfree(rx_data);
3407 }
3408
David Kilroy39d1ffe2008-11-22 10:37:28 +00003409 unregister_pm_notifier(&priv->pm_notifier);
David Kilroy74734312008-11-22 10:37:25 +00003410 orinoco_uncache_fw(priv);
3411
David Kilroyd03032a2008-08-21 23:28:02 +01003412 priv->wpa_ie_len = 0;
3413 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01003414 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04003415 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 free_netdev(dev);
3417}
David Kilroy21312662009-02-04 23:05:47 +00003418EXPORT_SYMBOL(free_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419
3420/********************************************************************/
3421/* Wireless extensions */
3422/********************************************************************/
3423
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003424/* Return : < 0 -> error code ; >= 0 -> length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3426 char buf[IW_ESSID_MAX_SIZE+1])
3427{
3428 hermes_t *hw = &priv->hw;
3429 int err = 0;
3430 struct hermes_idstring essidbuf;
3431 char *p = (char *)(&essidbuf.val);
3432 int len;
3433 unsigned long flags;
3434
3435 if (orinoco_lock(priv, &flags) != 0)
3436 return -EBUSY;
3437
3438 if (strlen(priv->desired_essid) > 0) {
3439 /* We read the desired SSID from the hardware rather
3440 than from priv->desired_essid, just in case the
3441 firmware is allowed to change it on us. I'm not
3442 sure about this */
3443 /* My guess is that the OWNSSID should always be whatever
3444 * we set to the card, whereas CURRENT_SSID is the one that
3445 * may change... - Jean II */
3446 u16 rid;
3447
3448 *active = 1;
3449
3450 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3451 HERMES_RID_CNFDESIREDSSID;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003452
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3454 NULL, &essidbuf);
3455 if (err)
3456 goto fail_unlock;
3457 } else {
3458 *active = 0;
3459
3460 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3461 sizeof(essidbuf), NULL, &essidbuf);
3462 if (err)
3463 goto fail_unlock;
3464 }
3465
3466 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003467 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003468
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003469 memset(buf, 0, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 memcpy(buf, p, len);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003471 err = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472
3473 fail_unlock:
3474 orinoco_unlock(priv, &flags);
3475
David Kilroy6fe9deb2009-02-04 23:05:43 +00003476 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
David Kilroy9ee677c2008-12-23 14:03:38 +00003479static int orinoco_hw_get_freq(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480{
David Kilroy6fe9deb2009-02-04 23:05:43 +00003481
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 hermes_t *hw = &priv->hw;
3483 int err = 0;
3484 u16 channel;
David Kilroy9ee677c2008-12-23 14:03:38 +00003485 int freq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 unsigned long flags;
3487
3488 if (orinoco_lock(priv, &flags) != 0)
3489 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003490
David Kilroyb2f30a02009-02-04 23:05:46 +00003491 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
3492 &channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 if (err)
3494 goto out;
3495
3496 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3497 if (channel == 0) {
3498 err = -EBUSY;
3499 goto out;
3500 }
3501
David Kilroya94e8422009-02-04 23:05:44 +00003502 if ((channel < 1) || (channel > NUM_CHANNELS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3504 priv->ndev->name, channel);
3505 err = -EBUSY;
3506 goto out;
3507
3508 }
David Kilroy9ee677c2008-12-23 14:03:38 +00003509 freq = ieee80211_dsss_chan_to_freq(channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510
3511 out:
3512 orinoco_unlock(priv, &flags);
3513
3514 if (err > 0)
3515 err = -EBUSY;
3516 return err ? err : freq;
3517}
3518
3519static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3520 int *numrates, s32 *rates, int max)
3521{
3522 hermes_t *hw = &priv->hw;
3523 struct hermes_idstring list;
3524 unsigned char *p = (unsigned char *)&list.val;
3525 int err = 0;
3526 int num;
3527 int i;
3528 unsigned long flags;
3529
3530 if (orinoco_lock(priv, &flags) != 0)
3531 return -EBUSY;
3532
3533 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3534 sizeof(list), NULL, &list);
3535 orinoco_unlock(priv, &flags);
3536
3537 if (err)
3538 return err;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003539
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 num = le16_to_cpu(list.len);
3541 *numrates = num;
3542 num = min(num, max);
3543
David Kilroy566f2d92009-02-04 23:05:45 +00003544 for (i = 0; i < num; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546
3547 return 0;
3548}
3549
Christoph Hellwig620554e2005-06-19 01:27:33 +02003550static int orinoco_ioctl_getname(struct net_device *dev,
3551 struct iw_request_info *info,
3552 char *name,
3553 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003554{
3555 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003557 int err;
3558
3559 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3560
3561 if (!err && (numrates > 2))
3562 strcpy(name, "IEEE 802.11b");
3563 else
3564 strcpy(name, "IEEE 802.11-DS");
3565
3566 return 0;
3567}
3568
Christoph Hellwig16739b02005-06-19 01:27:51 +02003569static int orinoco_ioctl_setwap(struct net_device *dev,
3570 struct iw_request_info *info,
3571 struct sockaddr *ap_addr,
3572 char *extra)
3573{
3574 struct orinoco_private *priv = netdev_priv(dev);
3575 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02003577 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3578 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579
3580 if (orinoco_lock(priv, &flags) != 0)
3581 return -EBUSY;
3582
Christoph Hellwig16739b02005-06-19 01:27:51 +02003583 /* Enable automatic roaming - no sanity checks are needed */
3584 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3585 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3586 priv->bssid_fixed = 0;
3587 memset(priv->desired_bssid, 0, ETH_ALEN);
3588
3589 /* "off" means keep existing connection */
3590 if (ap_addr->sa_data[0] == 0) {
3591 __orinoco_hw_set_wap(priv);
3592 err = 0;
3593 }
3594 goto out;
3595 }
3596
3597 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3598 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3599 "support manual roaming\n",
3600 dev->name);
3601 err = -EOPNOTSUPP;
3602 goto out;
3603 }
3604
3605 if (priv->iw_mode != IW_MODE_INFRA) {
3606 printk(KERN_WARNING "%s: Manual roaming supported only in "
3607 "managed mode\n", dev->name);
3608 err = -EOPNOTSUPP;
3609 goto out;
3610 }
3611
3612 /* Intersil firmware hangs without Desired ESSID */
3613 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3614 strlen(priv->desired_essid) == 0) {
3615 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3616 "manual roaming\n", dev->name);
3617 err = -EOPNOTSUPP;
3618 goto out;
3619 }
3620
3621 /* Finally, enable manual roaming */
3622 priv->bssid_fixed = 1;
3623 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3624
3625 out:
3626 orinoco_unlock(priv, &flags);
3627 return err;
3628}
3629
Christoph Hellwig620554e2005-06-19 01:27:33 +02003630static int orinoco_ioctl_getwap(struct net_device *dev,
3631 struct iw_request_info *info,
3632 struct sockaddr *ap_addr,
3633 char *extra)
3634{
3635 struct orinoco_private *priv = netdev_priv(dev);
3636
3637 hermes_t *hw = &priv->hw;
3638 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 unsigned long flags;
3640
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641 if (orinoco_lock(priv, &flags) != 0)
3642 return -EBUSY;
3643
Christoph Hellwig620554e2005-06-19 01:27:33 +02003644 ap_addr->sa_family = ARPHRD_ETHER;
3645 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3646 ETH_ALEN, NULL, ap_addr->sa_data);
3647
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 orinoco_unlock(priv, &flags);
3649
Christoph Hellwig620554e2005-06-19 01:27:33 +02003650 return err;
3651}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
Christoph Hellwig620554e2005-06-19 01:27:33 +02003653static int orinoco_ioctl_setmode(struct net_device *dev,
3654 struct iw_request_info *info,
3655 u32 *mode,
3656 char *extra)
3657{
3658 struct orinoco_private *priv = netdev_priv(dev);
3659 int err = -EINPROGRESS; /* Call commit handler */
3660 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003661
Christoph Hellwig620554e2005-06-19 01:27:33 +02003662 if (priv->iw_mode == *mode)
3663 return 0;
3664
3665 if (orinoco_lock(priv, &flags) != 0)
3666 return -EBUSY;
3667
3668 switch (*mode) {
3669 case IW_MODE_ADHOC:
3670 if (!priv->has_ibss && !priv->has_port3)
3671 err = -EOPNOTSUPP;
3672 break;
3673
3674 case IW_MODE_INFRA:
3675 break;
3676
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003677 case IW_MODE_MONITOR:
3678 if (priv->broken_monitor && !force_monitor) {
3679 printk(KERN_WARNING "%s: Monitor mode support is "
3680 "buggy in this firmware, not enabling\n",
3681 dev->name);
3682 err = -EOPNOTSUPP;
3683 }
3684 break;
3685
Christoph Hellwig620554e2005-06-19 01:27:33 +02003686 default:
3687 err = -EOPNOTSUPP;
3688 break;
3689 }
3690
3691 if (err == -EINPROGRESS) {
3692 priv->iw_mode = *mode;
3693 set_port_type(priv);
3694 }
3695
3696 orinoco_unlock(priv, &flags);
3697
3698 return err;
3699}
3700
3701static int orinoco_ioctl_getmode(struct net_device *dev,
3702 struct iw_request_info *info,
3703 u32 *mode,
3704 char *extra)
3705{
3706 struct orinoco_private *priv = netdev_priv(dev);
3707
3708 *mode = priv->iw_mode;
3709 return 0;
3710}
3711
3712static int orinoco_ioctl_getiwrange(struct net_device *dev,
3713 struct iw_request_info *info,
3714 struct iw_point *rrq,
3715 char *extra)
3716{
3717 struct orinoco_private *priv = netdev_priv(dev);
3718 int err = 0;
3719 struct iw_range *range = (struct iw_range *) extra;
3720 int numrates;
3721 int i, k;
3722
Christoph Hellwig620554e2005-06-19 01:27:33 +02003723 rrq->length = sizeof(struct iw_range);
3724 memset(range, 0, sizeof(struct iw_range));
3725
3726 range->we_version_compiled = WIRELESS_EXT;
David Kilroyd03032a2008-08-21 23:28:02 +01003727 range->we_version_source = 22;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728
3729 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003730 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 k = 0;
3732 for (i = 0; i < NUM_CHANNELS; i++) {
3733 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003734 range->freq[k].i = i + 1;
David Kilroy9ee677c2008-12-23 14:03:38 +00003735 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
3736 100000);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003737 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 k++;
3739 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00003740
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 if (k >= IW_MAX_FREQUENCIES)
3742 break;
3743 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02003744 range->num_frequency = k;
3745 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746
Christoph Hellwig620554e2005-06-19 01:27:33 +02003747 if (priv->has_wep) {
3748 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3749 range->encoding_size[0] = SMALL_KEY_SIZE;
3750 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003751
Christoph Hellwig620554e2005-06-19 01:27:33 +02003752 if (priv->has_big_wep) {
3753 range->encoding_size[1] = LARGE_KEY_SIZE;
3754 range->num_encoding_sizes = 2;
3755 }
3756 }
3757
David Kilroyd03032a2008-08-21 23:28:02 +01003758 if (priv->has_wpa)
3759 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
3760
David Kilroya94e8422009-02-04 23:05:44 +00003761 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003764 range->max_qual.qual = 0x8b - 0x2f;
3765 range->max_qual.level = 0x2f - 0x95 - 1;
3766 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003767 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003768 range->avg_qual.qual = 0x24;
3769 range->avg_qual.level = 0xC2;
3770 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 }
3772
3773 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02003774 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (err)
3776 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003777 range->num_bitrates = numrates;
3778
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 /* Set an indication of the max TCP throughput in bit/s that we can
3780 * expect using this interface. May be use for QoS stuff...
3781 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003782 if (numrates > 2)
3783 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02003785 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786
Christoph Hellwig620554e2005-06-19 01:27:33 +02003787 range->min_rts = 0;
3788 range->max_rts = 2347;
3789 range->min_frag = 256;
3790 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Christoph Hellwig620554e2005-06-19 01:27:33 +02003792 range->min_pmp = 0;
3793 range->max_pmp = 65535000;
3794 range->min_pmt = 0;
3795 range->max_pmt = 65535 * 1000; /* ??? */
3796 range->pmp_flags = IW_POWER_PERIOD;
3797 range->pmt_flags = IW_POWER_TIMEOUT;
David Kilroyb2f30a02009-02-04 23:05:46 +00003798 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
3799 IW_POWER_UNICAST_R);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
Christoph Hellwig620554e2005-06-19 01:27:33 +02003801 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3802 range->retry_flags = IW_RETRY_LIMIT;
3803 range->r_time_flags = IW_RETRY_LIFETIME;
3804 range->min_retry = 0;
3805 range->max_retry = 65535; /* ??? */
3806 range->min_r_time = 0;
3807 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
David Kilroy0753bba2008-08-21 23:27:46 +01003809 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3810 range->scan_capa = IW_SCAN_CAPA_ESSID;
3811 else
3812 range->scan_capa = IW_SCAN_CAPA_NONE;
3813
Pavel Roskin343c6862005-09-09 18:43:02 -04003814 /* Event capability (kernel) */
3815 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3816 /* Event capability (driver) */
3817 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3818 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3819 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3820 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3821
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 return 0;
3823}
3824
Christoph Hellwig620554e2005-06-19 01:27:33 +02003825static int orinoco_ioctl_setiwencode(struct net_device *dev,
3826 struct iw_request_info *info,
3827 struct iw_point *erq,
3828 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829{
3830 struct orinoco_private *priv = netdev_priv(dev);
3831 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3832 int setindex = priv->tx_key;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003833 int encode_alg = priv->encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 int restricted = priv->wep_restrict;
3835 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003836 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 unsigned long flags;
3838
David Kilroya94e8422009-02-04 23:05:44 +00003839 if (!priv->has_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003840 return -EOPNOTSUPP;
3841
3842 if (erq->pointer) {
3843 /* We actually have a key to set - check its length */
3844 if (erq->length > LARGE_KEY_SIZE)
3845 return -E2BIG;
3846
David Kilroya94e8422009-02-04 23:05:44 +00003847 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 }
3850
3851 if (orinoco_lock(priv, &flags) != 0)
3852 return -EBUSY;
3853
David Kilroyd03032a2008-08-21 23:28:02 +01003854 /* Clear any TKIP key we have */
3855 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3856 (void) orinoco_clear_tkip_key(priv, setindex);
3857
Dan Williamsfe397d42006-07-14 11:41:47 -04003858 if (erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003859 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3860 index = priv->tx_key;
3861
3862 /* Adjust key length to a supported value */
David Kilroy566f2d92009-02-04 23:05:45 +00003863 if (erq->length > SMALL_KEY_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 xlen = LARGE_KEY_SIZE;
David Kilroy566f2d92009-02-04 23:05:45 +00003865 else if (erq->length > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003866 xlen = SMALL_KEY_SIZE;
David Kilroy566f2d92009-02-04 23:05:45 +00003867 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003868 xlen = 0;
3869
3870 /* Switch on WEP if off */
David Kilroy4ae6ee22008-08-21 23:27:59 +01003871 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872 setindex = index;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003873 encode_alg = IW_ENCODE_ALG_WEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 }
3875 } else {
3876 /* Important note : if the user do "iwconfig eth0 enc off",
3877 * we will arrive there with an index of -1. This is valid
3878 * but need to be taken care off... Jean II */
3879 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
David Kilroya94e8422009-02-04 23:05:44 +00003880 if ((index != -1) || (erq->flags == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 err = -EINVAL;
3882 goto out;
3883 }
3884 } else {
3885 /* Set the index : Check that the key is valid */
David Kilroya94e8422009-02-04 23:05:44 +00003886 if (priv->keys[index].len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887 err = -EINVAL;
3888 goto out;
3889 }
3890 setindex = index;
3891 }
3892 }
3893
3894 if (erq->flags & IW_ENCODE_DISABLED)
David Kilroy4ae6ee22008-08-21 23:27:59 +01003895 encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896 if (erq->flags & IW_ENCODE_OPEN)
3897 restricted = 0;
3898 if (erq->flags & IW_ENCODE_RESTRICTED)
3899 restricted = 1;
3900
Dan Williamsfe397d42006-07-14 11:41:47 -04003901 if (erq->pointer && erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 priv->keys[index].len = cpu_to_le16(xlen);
3903 memset(priv->keys[index].data, 0,
3904 sizeof(priv->keys[index].data));
3905 memcpy(priv->keys[index].data, keybuf, erq->length);
3906 }
3907 priv->tx_key = setindex;
3908
3909 /* Try fast key change if connected and only keys are changed */
David Kilroy4ae6ee22008-08-21 23:27:59 +01003910 if ((priv->encode_alg == encode_alg) &&
3911 (priv->wep_restrict == restricted) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003912 netif_carrier_ok(dev)) {
3913 err = __orinoco_hw_setup_wepkeys(priv);
3914 /* No need to commit if successful */
3915 goto out;
3916 }
3917
David Kilroy4ae6ee22008-08-21 23:27:59 +01003918 priv->encode_alg = encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 priv->wep_restrict = restricted;
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_getiwencode(struct net_device *dev,
3928 struct iw_request_info *info,
3929 struct iw_point *erq,
3930 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931{
3932 struct orinoco_private *priv = netdev_priv(dev);
3933 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3934 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 unsigned long flags;
3936
David Kilroya94e8422009-02-04 23:05:44 +00003937 if (!priv->has_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 return -EOPNOTSUPP;
3939
3940 if (orinoco_lock(priv, &flags) != 0)
3941 return -EBUSY;
3942
3943 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3944 index = priv->tx_key;
3945
3946 erq->flags = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003947 if (!priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003948 erq->flags |= IW_ENCODE_DISABLED;
3949 erq->flags |= index + 1;
3950
3951 if (priv->wep_restrict)
3952 erq->flags |= IW_ENCODE_RESTRICTED;
3953 else
3954 erq->flags |= IW_ENCODE_OPEN;
3955
3956 xlen = le16_to_cpu(priv->keys[index].len);
3957
3958 erq->length = xlen;
3959
3960 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3961
3962 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963 return 0;
3964}
3965
Christoph Hellwig620554e2005-06-19 01:27:33 +02003966static int orinoco_ioctl_setessid(struct net_device *dev,
3967 struct iw_request_info *info,
3968 struct iw_point *erq,
3969 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970{
3971 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 unsigned long flags;
3973
3974 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3975 * anyway... - Jean II */
3976
Christoph Hellwig620554e2005-06-19 01:27:33 +02003977 /* Hum... Should not use Wireless Extension constant (may change),
3978 * should use our own... - Jean II */
3979 if (erq->length > IW_ESSID_MAX_SIZE)
3980 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981
3982 if (orinoco_lock(priv, &flags) != 0)
3983 return -EBUSY;
3984
Christoph Hellwig620554e2005-06-19 01:27:33 +02003985 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3986 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3987
3988 /* If not ANY, get the new ESSID */
David Kilroy566f2d92009-02-04 23:05:45 +00003989 if (erq->flags)
Christoph Hellwig620554e2005-06-19 01:27:33 +02003990 memcpy(priv->desired_essid, essidbuf, erq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991
3992 orinoco_unlock(priv, &flags);
3993
Christoph Hellwig620554e2005-06-19 01:27:33 +02003994 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995}
3996
Christoph Hellwig620554e2005-06-19 01:27:33 +02003997static int orinoco_ioctl_getessid(struct net_device *dev,
3998 struct iw_request_info *info,
3999 struct iw_point *erq,
4000 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001{
4002 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 int active;
4004 int err = 0;
4005 unsigned long flags;
4006
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 if (netif_running(dev)) {
4008 err = orinoco_hw_get_essid(priv, &active, essidbuf);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004009 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 return err;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004011 erq->length = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 } else {
4013 if (orinoco_lock(priv, &flags) != 0)
4014 return -EBUSY;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004015 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4016 erq->length = strlen(priv->desired_essid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004017 orinoco_unlock(priv, &flags);
4018 }
4019
4020 erq->flags = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004021
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 return 0;
4023}
4024
Christoph Hellwig620554e2005-06-19 01:27:33 +02004025static int orinoco_ioctl_setnick(struct net_device *dev,
4026 struct iw_request_info *info,
4027 struct iw_point *nrq,
4028 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029{
4030 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 unsigned long flags;
4032
4033 if (nrq->length > IW_ESSID_MAX_SIZE)
4034 return -E2BIG;
4035
Linus Torvalds1da177e2005-04-16 15:20:36 -07004036 if (orinoco_lock(priv, &flags) != 0)
4037 return -EBUSY;
4038
Christoph Hellwig620554e2005-06-19 01:27:33 +02004039 memset(priv->nick, 0, sizeof(priv->nick));
4040 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041
4042 orinoco_unlock(priv, &flags);
4043
Christoph Hellwig620554e2005-06-19 01:27:33 +02004044 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004045}
4046
Christoph Hellwig620554e2005-06-19 01:27:33 +02004047static int orinoco_ioctl_getnick(struct net_device *dev,
4048 struct iw_request_info *info,
4049 struct iw_point *nrq,
4050 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051{
4052 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 unsigned long flags;
4054
4055 if (orinoco_lock(priv, &flags) != 0)
4056 return -EBUSY;
4057
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004058 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 orinoco_unlock(priv, &flags);
4060
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004061 nrq->length = strlen(priv->nick);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 return 0;
4064}
4065
Christoph Hellwig620554e2005-06-19 01:27:33 +02004066static int orinoco_ioctl_setfreq(struct net_device *dev,
4067 struct iw_request_info *info,
4068 struct iw_freq *frq,
4069 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070{
4071 struct orinoco_private *priv = netdev_priv(dev);
4072 int chan = -1;
4073 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004074 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004076 /* In infrastructure mode the AP sets the channel */
4077 if (priv->iw_mode == IW_MODE_INFRA)
4078 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079
David Kilroya94e8422009-02-04 23:05:44 +00004080 if ((frq->e == 0) && (frq->m <= 1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 /* Setting by channel number */
4082 chan = frq->m;
4083 } else {
David Kilroy9ee677c2008-12-23 14:03:38 +00004084 /* Setting by frequency */
4085 int denom = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004086 int i;
4087
David Kilroy9ee677c2008-12-23 14:03:38 +00004088 /* Calculate denominator to rescale to MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004089 for (i = 0; i < (6 - frq->e); i++)
David Kilroy9ee677c2008-12-23 14:03:38 +00004090 denom *= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
David Kilroy9ee677c2008-12-23 14:03:38 +00004092 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004093 }
4094
David Kilroya94e8422009-02-04 23:05:44 +00004095 if ((chan < 1) || (chan > NUM_CHANNELS) ||
4096 !(priv->channel_mask & (1 << (chan-1))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097 return -EINVAL;
4098
4099 if (orinoco_lock(priv, &flags) != 0)
4100 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004101
Linus Torvalds1da177e2005-04-16 15:20:36 -07004102 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004103 if (priv->iw_mode == IW_MODE_MONITOR) {
4104 /* Fast channel change - no commit if successful */
4105 hermes_t *hw = &priv->hw;
4106 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4107 HERMES_TEST_SET_CHANNEL,
4108 chan, NULL);
4109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110 orinoco_unlock(priv, &flags);
4111
Christoph Hellwig620554e2005-06-19 01:27:33 +02004112 return err;
4113}
4114
4115static int orinoco_ioctl_getfreq(struct net_device *dev,
4116 struct iw_request_info *info,
4117 struct iw_freq *frq,
4118 char *extra)
4119{
4120 struct orinoco_private *priv = netdev_priv(dev);
4121 int tmp;
4122
4123 /* Locking done in there */
4124 tmp = orinoco_hw_get_freq(priv);
David Kilroy566f2d92009-02-04 23:05:45 +00004125 if (tmp < 0)
Christoph Hellwig620554e2005-06-19 01:27:33 +02004126 return tmp;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004127
David Kilroy9ee677c2008-12-23 14:03:38 +00004128 frq->m = tmp * 100000;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004129 frq->e = 1;
4130
Linus Torvalds1da177e2005-04-16 15:20:36 -07004131 return 0;
4132}
4133
Christoph Hellwig620554e2005-06-19 01:27:33 +02004134static int orinoco_ioctl_getsens(struct net_device *dev,
4135 struct iw_request_info *info,
4136 struct iw_param *srq,
4137 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138{
4139 struct orinoco_private *priv = netdev_priv(dev);
4140 hermes_t *hw = &priv->hw;
4141 u16 val;
4142 int err;
4143 unsigned long flags;
4144
4145 if (!priv->has_sensitivity)
4146 return -EOPNOTSUPP;
4147
4148 if (orinoco_lock(priv, &flags) != 0)
4149 return -EBUSY;
4150 err = hermes_read_wordrec(hw, USER_BAP,
4151 HERMES_RID_CNFSYSTEMSCALE, &val);
4152 orinoco_unlock(priv, &flags);
4153
4154 if (err)
4155 return err;
4156
4157 srq->value = val;
4158 srq->fixed = 0; /* auto */
4159
4160 return 0;
4161}
4162
Christoph Hellwig620554e2005-06-19 01:27:33 +02004163static int orinoco_ioctl_setsens(struct net_device *dev,
4164 struct iw_request_info *info,
4165 struct iw_param *srq,
4166 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167{
4168 struct orinoco_private *priv = netdev_priv(dev);
4169 int val = srq->value;
4170 unsigned long flags;
4171
4172 if (!priv->has_sensitivity)
4173 return -EOPNOTSUPP;
4174
4175 if ((val < 1) || (val > 3))
4176 return -EINVAL;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004177
Linus Torvalds1da177e2005-04-16 15:20:36 -07004178 if (orinoco_lock(priv, &flags) != 0)
4179 return -EBUSY;
4180 priv->ap_density = val;
4181 orinoco_unlock(priv, &flags);
4182
Christoph Hellwig620554e2005-06-19 01:27:33 +02004183 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004184}
4185
Christoph Hellwig620554e2005-06-19 01:27:33 +02004186static int orinoco_ioctl_setrts(struct net_device *dev,
4187 struct iw_request_info *info,
4188 struct iw_param *rrq,
4189 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190{
4191 struct orinoco_private *priv = netdev_priv(dev);
4192 int val = rrq->value;
4193 unsigned long flags;
4194
4195 if (rrq->disabled)
4196 val = 2347;
4197
David Kilroya94e8422009-02-04 23:05:44 +00004198 if ((val < 0) || (val > 2347))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 return -EINVAL;
4200
4201 if (orinoco_lock(priv, &flags) != 0)
4202 return -EBUSY;
4203
4204 priv->rts_thresh = val;
4205 orinoco_unlock(priv, &flags);
4206
Christoph Hellwig620554e2005-06-19 01:27:33 +02004207 return -EINPROGRESS; /* Call commit handler */
4208}
4209
4210static int orinoco_ioctl_getrts(struct net_device *dev,
4211 struct iw_request_info *info,
4212 struct iw_param *rrq,
4213 char *extra)
4214{
4215 struct orinoco_private *priv = netdev_priv(dev);
4216
4217 rrq->value = priv->rts_thresh;
4218 rrq->disabled = (rrq->value == 2347);
4219 rrq->fixed = 1;
4220
Linus Torvalds1da177e2005-04-16 15:20:36 -07004221 return 0;
4222}
4223
Christoph Hellwig620554e2005-06-19 01:27:33 +02004224static int orinoco_ioctl_setfrag(struct net_device *dev,
4225 struct iw_request_info *info,
4226 struct iw_param *frq,
4227 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228{
4229 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004230 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 unsigned long flags;
4232
4233 if (orinoco_lock(priv, &flags) != 0)
4234 return -EBUSY;
4235
4236 if (priv->has_mwo) {
4237 if (frq->disabled)
4238 priv->mwo_robust = 0;
4239 else {
4240 if (frq->fixed)
David Kilroyb2f30a02009-02-04 23:05:46 +00004241 printk(KERN_WARNING "%s: Fixed fragmentation "
4242 "is not supported on this firmware. "
4243 "Using MWO robust instead.\n",
4244 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 priv->mwo_robust = 1;
4246 }
4247 } else {
4248 if (frq->disabled)
4249 priv->frag_thresh = 2346;
4250 else {
David Kilroya94e8422009-02-04 23:05:44 +00004251 if ((frq->value < 256) || (frq->value > 2346))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 err = -EINVAL;
4253 else
David Kilroyb2f30a02009-02-04 23:05:46 +00004254 /* must be even */
4255 priv->frag_thresh = frq->value & ~0x1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 }
4257 }
4258
4259 orinoco_unlock(priv, &flags);
4260
4261 return err;
4262}
4263
Christoph Hellwig620554e2005-06-19 01:27:33 +02004264static int orinoco_ioctl_getfrag(struct net_device *dev,
4265 struct iw_request_info *info,
4266 struct iw_param *frq,
4267 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004268{
4269 struct orinoco_private *priv = netdev_priv(dev);
4270 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004271 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272 u16 val;
4273 unsigned long flags;
4274
4275 if (orinoco_lock(priv, &flags) != 0)
4276 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004277
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278 if (priv->has_mwo) {
4279 err = hermes_read_wordrec(hw, USER_BAP,
4280 HERMES_RID_CNFMWOROBUST_AGERE,
4281 &val);
4282 if (err)
4283 val = 0;
4284
4285 frq->value = val ? 2347 : 0;
David Kilroya94e8422009-02-04 23:05:44 +00004286 frq->disabled = !val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004287 frq->fixed = 0;
4288 } else {
David Kilroyb2f30a02009-02-04 23:05:46 +00004289 err = hermes_read_wordrec(hw, USER_BAP,
4290 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 &val);
4292 if (err)
4293 val = 0;
4294
4295 frq->value = val;
4296 frq->disabled = (val >= 2346);
4297 frq->fixed = 1;
4298 }
4299
4300 orinoco_unlock(priv, &flags);
David Kilroy6fe9deb2009-02-04 23:05:43 +00004301
Linus Torvalds1da177e2005-04-16 15:20:36 -07004302 return err;
4303}
4304
Christoph Hellwig620554e2005-06-19 01:27:33 +02004305static int orinoco_ioctl_setrate(struct net_device *dev,
4306 struct iw_request_info *info,
4307 struct iw_param *rrq,
4308 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309{
4310 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 int ratemode = -1;
4312 int bitrate; /* 100s of kilobits */
4313 int i;
4314 unsigned long flags;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004315
Linus Torvalds1da177e2005-04-16 15:20:36 -07004316 /* As the user space doesn't know our highest rate, it uses -1
4317 * to ask us to set the highest rate. Test it using "iwconfig
4318 * ethX rate auto" - Jean II */
4319 if (rrq->value == -1)
4320 bitrate = 110;
4321 else {
4322 if (rrq->value % 100000)
4323 return -EINVAL;
4324 bitrate = rrq->value / 100000;
4325 }
4326
David Kilroya94e8422009-02-04 23:05:44 +00004327 if ((bitrate != 10) && (bitrate != 20) &&
4328 (bitrate != 55) && (bitrate != 110))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004329 return -EINVAL;
4330
4331 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
David Kilroya94e8422009-02-04 23:05:44 +00004332 if ((bitrate_table[i].bitrate == bitrate) &&
4333 (bitrate_table[i].automatic == !rrq->fixed)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 ratemode = i;
4335 break;
4336 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00004337
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 if (ratemode == -1)
4339 return -EINVAL;
4340
4341 if (orinoco_lock(priv, &flags) != 0)
4342 return -EBUSY;
4343 priv->bitratemode = ratemode;
4344 orinoco_unlock(priv, &flags);
4345
Christoph Hellwig620554e2005-06-19 01:27:33 +02004346 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004347}
4348
Christoph Hellwig620554e2005-06-19 01:27:33 +02004349static int orinoco_ioctl_getrate(struct net_device *dev,
4350 struct iw_request_info *info,
4351 struct iw_param *rrq,
4352 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004353{
4354 struct orinoco_private *priv = netdev_priv(dev);
4355 hermes_t *hw = &priv->hw;
4356 int err = 0;
4357 int ratemode;
4358 int i;
4359 u16 val;
4360 unsigned long flags;
4361
4362 if (orinoco_lock(priv, &flags) != 0)
4363 return -EBUSY;
4364
4365 ratemode = priv->bitratemode;
4366
4367 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4368
4369 rrq->value = bitrate_table[ratemode].bitrate * 100000;
David Kilroya94e8422009-02-04 23:05:44 +00004370 rrq->fixed = !bitrate_table[ratemode].automatic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 rrq->disabled = 0;
4372
4373 /* If the interface is running we try to find more about the
4374 current mode */
4375 if (netif_running(dev)) {
4376 err = hermes_read_wordrec(hw, USER_BAP,
4377 HERMES_RID_CURRENTTXRATE, &val);
4378 if (err)
4379 goto out;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004380
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 switch (priv->firmware_type) {
4382 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4383 /* Note : in Lucent firmware, the return value of
4384 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4385 * and therefore is totally different from the
4386 * encoding of HERMES_RID_CNFTXRATECONTROL.
4387 * Don't forget that 6Mb/s is really 5.5Mb/s */
4388 if (val == 6)
4389 rrq->value = 5500000;
4390 else
4391 rrq->value = val * 1000000;
4392 break;
4393 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4394 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4395 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4396 if (bitrate_table[i].intersil_txratectrl == val) {
4397 ratemode = i;
4398 break;
4399 }
4400 if (i >= BITRATE_TABLE_SIZE)
4401 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4402 dev->name, val);
4403
4404 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4405 break;
4406 default:
4407 BUG();
4408 }
4409 }
4410
4411 out:
4412 orinoco_unlock(priv, &flags);
4413
4414 return err;
4415}
4416
Christoph Hellwig620554e2005-06-19 01:27:33 +02004417static int orinoco_ioctl_setpower(struct net_device *dev,
4418 struct iw_request_info *info,
4419 struct iw_param *prq,
4420 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004421{
4422 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004423 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004424 unsigned long flags;
4425
4426 if (orinoco_lock(priv, &flags) != 0)
4427 return -EBUSY;
4428
4429 if (prq->disabled) {
4430 priv->pm_on = 0;
4431 } else {
4432 switch (prq->flags & IW_POWER_MODE) {
4433 case IW_POWER_UNICAST_R:
4434 priv->pm_mcast = 0;
4435 priv->pm_on = 1;
4436 break;
4437 case IW_POWER_ALL_R:
4438 priv->pm_mcast = 1;
4439 priv->pm_on = 1;
4440 break;
4441 case IW_POWER_ON:
4442 /* No flags : but we may have a value - Jean II */
4443 break;
4444 default:
4445 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004446 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05004447 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00004448
Linus Torvalds1da177e2005-04-16 15:20:36 -07004449 if (prq->flags & IW_POWER_TIMEOUT) {
4450 priv->pm_on = 1;
4451 priv->pm_timeout = prq->value / 1000;
4452 }
4453 if (prq->flags & IW_POWER_PERIOD) {
4454 priv->pm_on = 1;
4455 priv->pm_period = prq->value / 1000;
4456 }
4457 /* It's valid to not have a value if we are just toggling
4458 * the flags... Jean II */
David Kilroya94e8422009-02-04 23:05:44 +00004459 if (!priv->pm_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004460 err = -EINVAL;
4461 goto out;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004463 }
4464
4465 out:
4466 orinoco_unlock(priv, &flags);
4467
4468 return err;
4469}
4470
Christoph Hellwig620554e2005-06-19 01:27:33 +02004471static int orinoco_ioctl_getpower(struct net_device *dev,
4472 struct iw_request_info *info,
4473 struct iw_param *prq,
4474 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004475{
4476 struct orinoco_private *priv = netdev_priv(dev);
4477 hermes_t *hw = &priv->hw;
4478 int err = 0;
4479 u16 enable, period, timeout, mcast;
4480 unsigned long flags;
4481
4482 if (orinoco_lock(priv, &flags) != 0)
4483 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004484
David Kilroyb2f30a02009-02-04 23:05:46 +00004485 err = hermes_read_wordrec(hw, USER_BAP,
4486 HERMES_RID_CNFPMENABLED, &enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004487 if (err)
4488 goto out;
4489
4490 err = hermes_read_wordrec(hw, USER_BAP,
4491 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4492 if (err)
4493 goto out;
4494
David Kilroyb2f30a02009-02-04 23:05:46 +00004495 err = hermes_read_wordrec(hw, USER_BAP,
4496 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004497 if (err)
4498 goto out;
4499
David Kilroyb2f30a02009-02-04 23:05:46 +00004500 err = hermes_read_wordrec(hw, USER_BAP,
4501 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004502 if (err)
4503 goto out;
4504
4505 prq->disabled = !enable;
4506 /* Note : by default, display the period */
4507 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4508 prq->flags = IW_POWER_TIMEOUT;
4509 prq->value = timeout * 1000;
4510 } else {
4511 prq->flags = IW_POWER_PERIOD;
4512 prq->value = period * 1000;
4513 }
4514 if (mcast)
4515 prq->flags |= IW_POWER_ALL_R;
4516 else
4517 prq->flags |= IW_POWER_UNICAST_R;
4518
4519 out:
4520 orinoco_unlock(priv, &flags);
4521
4522 return err;
4523}
4524
David Kilroyd03032a2008-08-21 23:28:02 +01004525static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4526 struct iw_request_info *info,
4527 union iwreq_data *wrqu,
4528 char *extra)
4529{
4530 struct orinoco_private *priv = netdev_priv(dev);
4531 struct iw_point *encoding = &wrqu->encoding;
4532 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4533 int idx, alg = ext->alg, set_key = 1;
4534 unsigned long flags;
4535 int err = -EINVAL;
4536 u16 key_len;
4537
4538 if (orinoco_lock(priv, &flags) != 0)
4539 return -EBUSY;
4540
4541 /* Determine and validate the key index */
4542 idx = encoding->flags & IW_ENCODE_INDEX;
4543 if (idx) {
Johannes Berg2c7060022008-10-30 22:09:54 +01004544 if ((idx < 1) || (idx > 4))
David Kilroyd03032a2008-08-21 23:28:02 +01004545 goto out;
4546 idx--;
4547 } else
4548 idx = priv->tx_key;
4549
4550 if (encoding->flags & IW_ENCODE_DISABLED)
David Kilroy6fe9deb2009-02-04 23:05:43 +00004551 alg = IW_ENCODE_ALG_NONE;
David Kilroyd03032a2008-08-21 23:28:02 +01004552
4553 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4554 /* Clear any TKIP TX key we had */
4555 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4556 }
4557
4558 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4559 priv->tx_key = idx;
4560 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4561 (ext->key_len > 0)) ? 1 : 0;
4562 }
4563
4564 if (set_key) {
4565 /* Set the requested key first */
4566 switch (alg) {
4567 case IW_ENCODE_ALG_NONE:
4568 priv->encode_alg = alg;
4569 priv->keys[idx].len = 0;
4570 break;
4571
4572 case IW_ENCODE_ALG_WEP:
4573 if (ext->key_len > SMALL_KEY_SIZE)
4574 key_len = LARGE_KEY_SIZE;
4575 else if (ext->key_len > 0)
4576 key_len = SMALL_KEY_SIZE;
4577 else
4578 goto out;
4579
4580 priv->encode_alg = alg;
4581 priv->keys[idx].len = cpu_to_le16(key_len);
4582
4583 key_len = min(ext->key_len, key_len);
4584
4585 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4586 memcpy(priv->keys[idx].data, ext->key, key_len);
4587 break;
4588
4589 case IW_ENCODE_ALG_TKIP:
4590 {
4591 hermes_t *hw = &priv->hw;
4592 u8 *tkip_iv = NULL;
4593
4594 if (!priv->has_wpa ||
4595 (ext->key_len > sizeof(priv->tkip_key[0])))
4596 goto out;
4597
4598 priv->encode_alg = alg;
4599 memset(&priv->tkip_key[idx], 0,
4600 sizeof(priv->tkip_key[idx]));
4601 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4602
4603 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4604 tkip_iv = &ext->rx_seq[0];
4605
4606 err = __orinoco_hw_set_tkip_key(hw, idx,
4607 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4608 (u8 *) &priv->tkip_key[idx],
4609 tkip_iv, NULL);
4610 if (err)
4611 printk(KERN_ERR "%s: Error %d setting TKIP key"
4612 "\n", dev->name, err);
4613
4614 goto out;
4615 }
4616 default:
4617 goto out;
4618 }
4619 }
4620 err = -EINPROGRESS;
4621 out:
4622 orinoco_unlock(priv, &flags);
4623
4624 return err;
4625}
4626
4627static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4628 struct iw_request_info *info,
4629 union iwreq_data *wrqu,
4630 char *extra)
4631{
4632 struct orinoco_private *priv = netdev_priv(dev);
4633 struct iw_point *encoding = &wrqu->encoding;
4634 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4635 int idx, max_key_len;
4636 unsigned long flags;
4637 int err;
4638
4639 if (orinoco_lock(priv, &flags) != 0)
4640 return -EBUSY;
4641
4642 err = -EINVAL;
4643 max_key_len = encoding->length - sizeof(*ext);
4644 if (max_key_len < 0)
4645 goto out;
4646
4647 idx = encoding->flags & IW_ENCODE_INDEX;
4648 if (idx) {
Johannes Berg2c7060022008-10-30 22:09:54 +01004649 if ((idx < 1) || (idx > 4))
David Kilroyd03032a2008-08-21 23:28:02 +01004650 goto out;
4651 idx--;
4652 } else
4653 idx = priv->tx_key;
4654
4655 encoding->flags = idx + 1;
4656 memset(ext, 0, sizeof(*ext));
4657
4658 ext->alg = priv->encode_alg;
4659 switch (priv->encode_alg) {
4660 case IW_ENCODE_ALG_NONE:
4661 ext->key_len = 0;
4662 encoding->flags |= IW_ENCODE_DISABLED;
4663 break;
4664 case IW_ENCODE_ALG_WEP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004665 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
4666 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004667 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4668 encoding->flags |= IW_ENCODE_ENABLED;
4669 break;
4670 case IW_ENCODE_ALG_TKIP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004671 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
4672 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004673 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4674 encoding->flags |= IW_ENCODE_ENABLED;
4675 break;
4676 }
4677
4678 err = 0;
4679 out:
4680 orinoco_unlock(priv, &flags);
4681
4682 return err;
4683}
4684
4685static int orinoco_ioctl_set_auth(struct net_device *dev,
4686 struct iw_request_info *info,
4687 union iwreq_data *wrqu, char *extra)
4688{
4689 struct orinoco_private *priv = netdev_priv(dev);
4690 hermes_t *hw = &priv->hw;
4691 struct iw_param *param = &wrqu->param;
4692 unsigned long flags;
4693 int ret = -EINPROGRESS;
4694
4695 if (orinoco_lock(priv, &flags) != 0)
4696 return -EBUSY;
4697
4698 switch (param->flags & IW_AUTH_INDEX) {
4699 case IW_AUTH_WPA_VERSION:
4700 case IW_AUTH_CIPHER_PAIRWISE:
4701 case IW_AUTH_CIPHER_GROUP:
4702 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4703 case IW_AUTH_PRIVACY_INVOKED:
4704 case IW_AUTH_DROP_UNENCRYPTED:
4705 /*
4706 * orinoco does not use these parameters
4707 */
4708 break;
4709
4710 case IW_AUTH_KEY_MGMT:
4711 /* wl_lkm implies value 2 == PSK for Hermes I
4712 * which ties in with WEXT
4713 * no other hints tho :(
4714 */
4715 priv->key_mgmt = param->value;
4716 break;
4717
4718 case IW_AUTH_TKIP_COUNTERMEASURES:
4719 /* When countermeasures are enabled, shut down the
4720 * card; when disabled, re-enable the card. This must
4721 * take effect immediately.
4722 *
4723 * TODO: Make sure that the EAPOL message is getting
4724 * out before card disabled
4725 */
4726 if (param->value) {
4727 priv->tkip_cm_active = 1;
4728 ret = hermes_enable_port(hw, 0);
4729 } else {
4730 priv->tkip_cm_active = 0;
4731 ret = hermes_disable_port(hw, 0);
4732 }
4733 break;
4734
4735 case IW_AUTH_80211_AUTH_ALG:
4736 if (param->value & IW_AUTH_ALG_SHARED_KEY)
4737 priv->wep_restrict = 1;
4738 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
4739 priv->wep_restrict = 0;
4740 else
4741 ret = -EINVAL;
4742 break;
4743
4744 case IW_AUTH_WPA_ENABLED:
4745 if (priv->has_wpa) {
4746 priv->wpa_enabled = param->value ? 1 : 0;
4747 } else {
4748 if (param->value)
4749 ret = -EOPNOTSUPP;
4750 /* else silently accept disable of WPA */
4751 priv->wpa_enabled = 0;
4752 }
4753 break;
4754
4755 default:
4756 ret = -EOPNOTSUPP;
4757 }
4758
4759 orinoco_unlock(priv, &flags);
4760 return ret;
4761}
4762
4763static int orinoco_ioctl_get_auth(struct net_device *dev,
4764 struct iw_request_info *info,
4765 union iwreq_data *wrqu, char *extra)
4766{
4767 struct orinoco_private *priv = netdev_priv(dev);
4768 struct iw_param *param = &wrqu->param;
4769 unsigned long flags;
4770 int ret = 0;
4771
4772 if (orinoco_lock(priv, &flags) != 0)
4773 return -EBUSY;
4774
4775 switch (param->flags & IW_AUTH_INDEX) {
4776 case IW_AUTH_KEY_MGMT:
4777 param->value = priv->key_mgmt;
4778 break;
4779
4780 case IW_AUTH_TKIP_COUNTERMEASURES:
4781 param->value = priv->tkip_cm_active;
4782 break;
4783
4784 case IW_AUTH_80211_AUTH_ALG:
4785 if (priv->wep_restrict)
4786 param->value = IW_AUTH_ALG_SHARED_KEY;
4787 else
4788 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
4789 break;
4790
4791 case IW_AUTH_WPA_ENABLED:
4792 param->value = priv->wpa_enabled;
4793 break;
4794
4795 default:
4796 ret = -EOPNOTSUPP;
4797 }
4798
4799 orinoco_unlock(priv, &flags);
4800 return ret;
4801}
4802
4803static int orinoco_ioctl_set_genie(struct net_device *dev,
4804 struct iw_request_info *info,
4805 union iwreq_data *wrqu, char *extra)
4806{
4807 struct orinoco_private *priv = netdev_priv(dev);
4808 u8 *buf;
4809 unsigned long flags;
David Kilroyd03032a2008-08-21 23:28:02 +01004810
Johannes Berg2c7060022008-10-30 22:09:54 +01004811 /* cut off at IEEE80211_MAX_DATA_LEN */
4812 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
David Kilroyd03032a2008-08-21 23:28:02 +01004813 (wrqu->data.length && (extra == NULL)))
4814 return -EINVAL;
4815
David Kilroyd03032a2008-08-21 23:28:02 +01004816 if (wrqu->data.length) {
4817 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004818 if (buf == NULL)
4819 return -ENOMEM;
David Kilroyd03032a2008-08-21 23:28:02 +01004820
4821 memcpy(buf, extra, wrqu->data.length);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004822 } else
4823 buf = NULL;
4824
4825 if (orinoco_lock(priv, &flags) != 0) {
4826 kfree(buf);
4827 return -EBUSY;
David Kilroyd03032a2008-08-21 23:28:02 +01004828 }
4829
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004830 kfree(priv->wpa_ie);
4831 priv->wpa_ie = buf;
4832 priv->wpa_ie_len = wrqu->data.length;
4833
David Kilroyd03032a2008-08-21 23:28:02 +01004834 if (priv->wpa_ie) {
4835 /* Looks like wl_lkm wants to check the auth alg, and
4836 * somehow pass it to the firmware.
4837 * Instead it just calls the key mgmt rid
4838 * - we do this in set auth.
4839 */
4840 }
4841
David Kilroyd03032a2008-08-21 23:28:02 +01004842 orinoco_unlock(priv, &flags);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004843 return 0;
David Kilroyd03032a2008-08-21 23:28:02 +01004844}
4845
4846static int orinoco_ioctl_get_genie(struct net_device *dev,
4847 struct iw_request_info *info,
4848 union iwreq_data *wrqu, char *extra)
4849{
4850 struct orinoco_private *priv = netdev_priv(dev);
4851 unsigned long flags;
4852 int err = 0;
4853
4854 if (orinoco_lock(priv, &flags) != 0)
4855 return -EBUSY;
4856
4857 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
4858 wrqu->data.length = 0;
4859 goto out;
4860 }
4861
4862 if (wrqu->data.length < priv->wpa_ie_len) {
4863 err = -E2BIG;
4864 goto out;
4865 }
4866
4867 wrqu->data.length = priv->wpa_ie_len;
4868 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
4869
4870out:
4871 orinoco_unlock(priv, &flags);
4872 return err;
4873}
4874
4875static int orinoco_ioctl_set_mlme(struct net_device *dev,
4876 struct iw_request_info *info,
4877 union iwreq_data *wrqu, char *extra)
4878{
4879 struct orinoco_private *priv = netdev_priv(dev);
4880 hermes_t *hw = &priv->hw;
4881 struct iw_mlme *mlme = (struct iw_mlme *)extra;
4882 unsigned long flags;
4883 int ret = 0;
4884
4885 if (orinoco_lock(priv, &flags) != 0)
4886 return -EBUSY;
4887
4888 switch (mlme->cmd) {
4889 case IW_MLME_DEAUTH:
4890 /* silently ignore */
4891 break;
4892
4893 case IW_MLME_DISASSOC:
4894 {
4895 struct {
4896 u8 addr[ETH_ALEN];
4897 __le16 reason_code;
4898 } __attribute__ ((packed)) buf;
4899
4900 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
4901 buf.reason_code = cpu_to_le16(mlme->reason_code);
4902 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
4903 HERMES_RID_CNFDISASSOCIATE,
4904 &buf);
4905 break;
4906 }
4907 default:
4908 ret = -EOPNOTSUPP;
4909 }
4910
4911 orinoco_unlock(priv, &flags);
4912 return ret;
4913}
4914
Christoph Hellwig620554e2005-06-19 01:27:33 +02004915static int orinoco_ioctl_getretry(struct net_device *dev,
4916 struct iw_request_info *info,
4917 struct iw_param *rrq,
4918 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004919{
4920 struct orinoco_private *priv = netdev_priv(dev);
4921 hermes_t *hw = &priv->hw;
4922 int err = 0;
4923 u16 short_limit, long_limit, lifetime;
4924 unsigned long flags;
4925
4926 if (orinoco_lock(priv, &flags) != 0)
4927 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004928
Linus Torvalds1da177e2005-04-16 15:20:36 -07004929 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4930 &short_limit);
4931 if (err)
4932 goto out;
4933
4934 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4935 &long_limit);
4936 if (err)
4937 goto out;
4938
4939 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4940 &lifetime);
4941 if (err)
4942 goto out;
4943
4944 rrq->disabled = 0; /* Can't be disabled */
4945
4946 /* Note : by default, display the retry number */
4947 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4948 rrq->flags = IW_RETRY_LIFETIME;
4949 rrq->value = lifetime * 1000; /* ??? */
4950 } else {
4951 /* By default, display the min number */
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004952 if ((rrq->flags & IW_RETRY_LONG)) {
4953 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004954 rrq->value = long_limit;
4955 } else {
4956 rrq->flags = IW_RETRY_LIMIT;
4957 rrq->value = short_limit;
David Kilroya94e8422009-02-04 23:05:44 +00004958 if (short_limit != long_limit)
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07004959 rrq->flags |= IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004960 }
4961 }
4962
4963 out:
4964 orinoco_unlock(priv, &flags);
4965
4966 return err;
4967}
4968
Christoph Hellwig620554e2005-06-19 01:27:33 +02004969static int orinoco_ioctl_reset(struct net_device *dev,
4970 struct iw_request_info *info,
4971 void *wrqu,
4972 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004973{
4974 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004975
David Kilroya94e8422009-02-04 23:05:44 +00004976 if (!capable(CAP_NET_ADMIN))
Christoph Hellwig620554e2005-06-19 01:27:33 +02004977 return -EPERM;
4978
4979 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4980 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4981
4982 /* Firmware reset */
David Howellsc4028952006-11-22 14:57:56 +00004983 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004984 } else {
4985 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4986
4987 schedule_work(&priv->reset_work);
4988 }
4989
4990 return 0;
4991}
4992
4993static int orinoco_ioctl_setibssport(struct net_device *dev,
4994 struct iw_request_info *info,
4995 void *wrqu,
4996 char *extra)
4997
4998{
4999 struct orinoco_private *priv = netdev_priv(dev);
David Kilroya94e8422009-02-04 23:05:44 +00005000 int val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 unsigned long flags;
5002
5003 if (orinoco_lock(priv, &flags) != 0)
5004 return -EBUSY;
5005
5006 priv->ibss_port = val ;
5007
5008 /* Actually update the mode we are using */
5009 set_port_type(priv);
5010
5011 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005012 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005013}
5014
Christoph Hellwig620554e2005-06-19 01:27:33 +02005015static int orinoco_ioctl_getibssport(struct net_device *dev,
5016 struct iw_request_info *info,
5017 void *wrqu,
5018 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005019{
5020 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005021 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005022
5023 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 return 0;
5025}
5026
Christoph Hellwig620554e2005-06-19 01:27:33 +02005027static int orinoco_ioctl_setport3(struct net_device *dev,
5028 struct iw_request_info *info,
5029 void *wrqu,
5030 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031{
5032 struct orinoco_private *priv = netdev_priv(dev);
David Kilroya94e8422009-02-04 23:05:44 +00005033 int val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005034 int err = 0;
5035 unsigned long flags;
5036
5037 if (orinoco_lock(priv, &flags) != 0)
5038 return -EBUSY;
5039
5040 switch (val) {
5041 case 0: /* Try to do IEEE ad-hoc mode */
David Kilroya94e8422009-02-04 23:05:44 +00005042 if (!priv->has_ibss) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043 err = -EINVAL;
5044 break;
5045 }
5046 priv->prefer_port3 = 0;
David Kilroy6fe9deb2009-02-04 23:05:43 +00005047
Linus Torvalds1da177e2005-04-16 15:20:36 -07005048 break;
5049
5050 case 1: /* Try to do Lucent proprietary ad-hoc mode */
David Kilroya94e8422009-02-04 23:05:44 +00005051 if (!priv->has_port3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005052 err = -EINVAL;
5053 break;
5054 }
5055 priv->prefer_port3 = 1;
5056 break;
5057
5058 default:
5059 err = -EINVAL;
5060 }
5061
David Kilroya94e8422009-02-04 23:05:44 +00005062 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005063 /* Actually update the mode we are using */
5064 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005065 err = -EINPROGRESS;
5066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005067
5068 orinoco_unlock(priv, &flags);
5069
5070 return err;
5071}
5072
Christoph Hellwig620554e2005-06-19 01:27:33 +02005073static int orinoco_ioctl_getport3(struct net_device *dev,
5074 struct iw_request_info *info,
5075 void *wrqu,
5076 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005077{
5078 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005079 int *val = (int *) extra;
5080
5081 *val = priv->prefer_port3;
5082 return 0;
5083}
5084
5085static int orinoco_ioctl_setpreamble(struct net_device *dev,
5086 struct iw_request_info *info,
5087 void *wrqu,
5088 char *extra)
5089{
5090 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005092 int val;
5093
David Kilroya94e8422009-02-04 23:05:44 +00005094 if (!priv->has_preamble)
Christoph Hellwig620554e2005-06-19 01:27:33 +02005095 return -EOPNOTSUPP;
5096
5097 /* 802.11b has recently defined some short preamble.
5098 * Basically, the Phy header has been reduced in size.
5099 * This increase performance, especially at high rates
5100 * (the preamble is transmitted at 1Mb/s), unfortunately
5101 * this give compatibility troubles... - Jean II */
David Kilroya94e8422009-02-04 23:05:44 +00005102 val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005103
5104 if (orinoco_lock(priv, &flags) != 0)
5105 return -EBUSY;
5106
Christoph Hellwig620554e2005-06-19 01:27:33 +02005107 if (val)
5108 priv->preamble = 1;
5109 else
5110 priv->preamble = 0;
5111
Linus Torvalds1da177e2005-04-16 15:20:36 -07005112 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005113
5114 return -EINPROGRESS; /* Call commit handler */
5115}
5116
5117static int orinoco_ioctl_getpreamble(struct net_device *dev,
5118 struct iw_request_info *info,
5119 void *wrqu,
5120 char *extra)
5121{
5122 struct orinoco_private *priv = netdev_priv(dev);
5123 int *val = (int *) extra;
5124
David Kilroya94e8422009-02-04 23:05:44 +00005125 if (!priv->has_preamble)
Christoph Hellwig620554e2005-06-19 01:27:33 +02005126 return -EOPNOTSUPP;
5127
5128 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005129 return 0;
5130}
5131
Christoph Hellwig620554e2005-06-19 01:27:33 +02005132/* ioctl interface to hermes_read_ltv()
5133 * To use with iwpriv, pass the RID as the token argument, e.g.
5134 * iwpriv get_rid [0xfc00]
5135 * At least Wireless Tools 25 is required to use iwpriv.
5136 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5137static int orinoco_ioctl_getrid(struct net_device *dev,
5138 struct iw_request_info *info,
5139 struct iw_point *data,
5140 char *extra)
5141{
5142 struct orinoco_private *priv = netdev_priv(dev);
5143 hermes_t *hw = &priv->hw;
5144 int rid = data->flags;
5145 u16 length;
5146 int err;
5147 unsigned long flags;
5148
5149 /* It's a "get" function, but we don't want users to access the
5150 * WEP key and other raw firmware data */
David Kilroya94e8422009-02-04 23:05:44 +00005151 if (!capable(CAP_NET_ADMIN))
Christoph Hellwig620554e2005-06-19 01:27:33 +02005152 return -EPERM;
5153
5154 if (rid < 0xfc00 || rid > 0xffff)
5155 return -EINVAL;
5156
5157 if (orinoco_lock(priv, &flags) != 0)
5158 return -EBUSY;
5159
5160 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5161 extra);
5162 if (err)
5163 goto out;
5164
5165 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5166 MAX_RID_LEN);
5167
5168 out:
5169 orinoco_unlock(priv, &flags);
5170 return err;
5171}
5172
David Kilroy17a1a882008-08-21 23:27:47 +01005173/* Trigger a scan (look for other cells in the vicinity) */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005174static int orinoco_ioctl_setscan(struct net_device *dev,
5175 struct iw_request_info *info,
David Kilroy9930cce2008-09-13 12:22:05 +01005176 struct iw_point *srq,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005177 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005178{
5179 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005180 hermes_t *hw = &priv->hw;
David Kilroy0753bba2008-08-21 23:27:46 +01005181 struct iw_scan_req *si = (struct iw_scan_req *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 unsigned long flags;
5184
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005185 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08005186 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005187 * perform scanning.
5188 * This is not an error, while the device perform scanning,
5189 * traffic doesn't flow, so it's a perfect DoS...
5190 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005191
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005192 if (orinoco_lock(priv, &flags) != 0)
5193 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005195 /* Scanning with port 0 disabled would fail */
5196 if (!netif_running(dev)) {
5197 err = -ENETDOWN;
5198 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005200
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005201 /* In monitor mode, the scan results are always empty.
5202 * Probe responses are passed to the driver as received
5203 * frames and could be processed in software. */
5204 if (priv->iw_mode == IW_MODE_MONITOR) {
5205 err = -EOPNOTSUPP;
5206 goto out;
5207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005209 /* Note : because we don't lock out the irq handler, the way
5210 * we access scan variables in priv is critical.
5211 * o scan_inprogress : not touched by irq handler
5212 * o scan_mode : not touched by irq handler
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005213 * Before modifying anything on those variables, please think hard !
5214 * Jean II */
5215
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005216 /* Save flags */
5217 priv->scan_mode = srq->flags;
5218
5219 /* Always trigger scanning, even if it's in progress.
5220 * This way, if the info frame get lost, we will recover somewhat
5221 * gracefully - Jean II */
5222
5223 if (priv->has_hostscan) {
5224 switch (priv->firmware_type) {
5225 case FIRMWARE_TYPE_SYMBOL:
5226 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00005227 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5228 HERMES_HOSTSCAN_SYMBOL_ONCE |
5229 HERMES_HOSTSCAN_SYMBOL_BCAST);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005230 break;
5231 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04005232 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005233
5234 req[0] = cpu_to_le16(0x3fff); /* All channels */
5235 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5236 req[2] = 0; /* Any ESSID */
5237 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5238 HERMES_RID_CNFHOSTSCAN, &req);
5239 }
5240 break;
5241 case FIRMWARE_TYPE_AGERE:
David Kilroy0753bba2008-08-21 23:27:46 +01005242 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5243 struct hermes_idstring idbuf;
5244 size_t len = min(sizeof(idbuf.val),
5245 (size_t) si->essid_len);
5246 idbuf.len = cpu_to_le16(len);
5247 memcpy(idbuf.val, si->essid, len);
5248
5249 err = hermes_write_ltv(hw, USER_BAP,
5250 HERMES_RID_CNFSCANSSID_AGERE,
5251 HERMES_BYTES_TO_RECLEN(len + 2),
5252 &idbuf);
5253 } else
5254 err = hermes_write_wordrec(hw, USER_BAP,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005255 HERMES_RID_CNFSCANSSID_AGERE,
5256 0); /* Any ESSID */
5257 if (err)
5258 break;
5259
David Kilroy01632fa2008-08-21 23:27:58 +01005260 if (priv->has_ext_scan) {
5261 /* Clear scan results at the start of
5262 * an extended scan */
5263 orinoco_clear_scan_results(priv,
5264 msecs_to_jiffies(15000));
5265
5266 /* TODO: Is this available on older firmware?
5267 * Can we use it to scan specific channels
5268 * for IW_SCAN_THIS_FREQ? */
5269 err = hermes_write_wordrec(hw, USER_BAP,
5270 HERMES_RID_CNFSCANCHANNELS2GHZ,
5271 0x7FFF);
5272 if (err)
5273 goto out;
5274
5275 err = hermes_inquire(hw,
5276 HERMES_INQ_CHANNELINFO);
5277 } else
5278 err = hermes_inquire(hw, HERMES_INQ_SCAN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005279 break;
5280 }
5281 } else
5282 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5283
5284 /* One more client */
David Kilroya94e8422009-02-04 23:05:44 +00005285 if (!err)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005286 priv->scan_inprogress = 1;
5287
5288 out:
5289 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005290 return err;
5291}
5292
Dan Williams1e3428e2007-10-10 23:56:25 -04005293#define MAX_CUSTOM_LEN 64
5294
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005295/* Translate scan data returned from the card to a card independant
David Kilroy17a1a882008-08-21 23:27:47 +01005296 * format that the Wireless Tools will understand - Jean II */
Dan Williams1e3428e2007-10-10 23:56:25 -04005297static inline char *orinoco_translate_scan(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07005298 struct iw_request_info *info,
Dan Williams1e3428e2007-10-10 23:56:25 -04005299 char *current_ev,
5300 char *end_buf,
5301 union hermes_scan_info *bss,
Pavel Roskindfe1baf2008-11-10 09:25:53 -05005302 unsigned long last_scanned)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005303{
5304 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005305 u16 capabilities;
5306 u16 channel;
5307 struct iw_event iwe; /* Temporary buffer */
Dan Williams1e3428e2007-10-10 23:56:25 -04005308 char custom[MAX_CUSTOM_LEN];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005309
David Kilroy17a1a882008-08-21 23:27:47 +01005310 memset(&iwe, 0, sizeof(iwe));
5311
Dan Williams1e3428e2007-10-10 23:56:25 -04005312 /* First entry *MUST* be the AP MAC address */
5313 iwe.cmd = SIOCGIWAP;
5314 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5315 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07005316 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5317 &iwe, IW_EV_ADDR_LEN);
Dan Williams1e3428e2007-10-10 23:56:25 -04005318
5319 /* Other entries will be displayed in the order we give them */
5320
5321 /* Add the ESSID */
5322 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5323 if (iwe.u.data.length > 32)
5324 iwe.u.data.length = 32;
5325 iwe.cmd = SIOCGIWESSID;
5326 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005327 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5328 &iwe, bss->a.essid);
Dan Williams1e3428e2007-10-10 23:56:25 -04005329
5330 /* Add mode */
5331 iwe.cmd = SIOCGIWMODE;
5332 capabilities = le16_to_cpu(bss->a.capabilities);
David Kilroy17a1a882008-08-21 23:27:47 +01005333 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5334 if (capabilities & WLAN_CAPABILITY_ESS)
Dan Williams1e3428e2007-10-10 23:56:25 -04005335 iwe.u.mode = IW_MODE_MASTER;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005336 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005337 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07005338 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5339 &iwe, IW_EV_UINT_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005340 }
5341
Dan Williams1e3428e2007-10-10 23:56:25 -04005342 channel = bss->s.channel;
5343 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
David Kilroy17a1a882008-08-21 23:27:47 +01005344 /* Add channel and frequency */
Dan Williams1e3428e2007-10-10 23:56:25 -04005345 iwe.cmd = SIOCGIWFREQ;
David Kilroy17a1a882008-08-21 23:27:47 +01005346 iwe.u.freq.m = channel;
5347 iwe.u.freq.e = 0;
5348 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5349 &iwe, IW_EV_FREQ_LEN);
5350
David Kilroy9ee677c2008-12-23 14:03:38 +00005351 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
Dan Williams1e3428e2007-10-10 23:56:25 -04005352 iwe.u.freq.e = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005353 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
Dan Williams1e3428e2007-10-10 23:56:25 -04005354 &iwe, IW_EV_FREQ_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005355 }
5356
David Kilroy17a1a882008-08-21 23:27:47 +01005357 /* Add quality statistics. level and noise in dB. No link quality */
Dan Williams1e3428e2007-10-10 23:56:25 -04005358 iwe.cmd = IWEVQUAL;
David Kilroy17a1a882008-08-21 23:27:47 +01005359 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
Dan Williams1e3428e2007-10-10 23:56:25 -04005360 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5361 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5362 /* Wireless tools prior to 27.pre22 will show link quality
5363 * anyway, so we provide a reasonable value. */
5364 if (iwe.u.qual.level > iwe.u.qual.noise)
5365 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5366 else
5367 iwe.u.qual.qual = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005368 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5369 &iwe, IW_EV_QUAL_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005370
Dan Williams1e3428e2007-10-10 23:56:25 -04005371 /* Add encryption capability */
5372 iwe.cmd = SIOCGIWENCODE;
David Kilroy17a1a882008-08-21 23:27:47 +01005373 if (capabilities & WLAN_CAPABILITY_PRIVACY)
Dan Williams1e3428e2007-10-10 23:56:25 -04005374 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5375 else
5376 iwe.u.data.flags = IW_ENCODE_DISABLED;
5377 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005378 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
David Kilroy17a1a882008-08-21 23:27:47 +01005379 &iwe, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005380
Dan Williams1e3428e2007-10-10 23:56:25 -04005381 /* Bit rate is not available in Lucent/Agere firmwares */
5382 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
David S. Millerccc58052008-06-16 18:50:49 -07005383 char *current_val = current_ev + iwe_stream_lcp_len(info);
Dan Williams1e3428e2007-10-10 23:56:25 -04005384 int i;
5385 int step;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005386
Dan Williams1e3428e2007-10-10 23:56:25 -04005387 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5388 step = 2;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005389 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005390 step = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005391
Dan Williams1e3428e2007-10-10 23:56:25 -04005392 iwe.cmd = SIOCGIWRATE;
5393 /* Those two flags are ignored... */
5394 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5395 /* Max 10 values */
5396 for (i = 0; i < 10; i += step) {
5397 /* NULL terminated */
5398 if (bss->p.rates[i] == 0x0)
5399 break;
5400 /* Bit rate given in 500 kb/s units (+ 0x80) */
David Kilroy17a1a882008-08-21 23:27:47 +01005401 iwe.u.bitrate.value =
5402 ((bss->p.rates[i] & 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07005403 current_val = iwe_stream_add_value(info, current_ev,
5404 current_val,
Dan Williams1e3428e2007-10-10 23:56:25 -04005405 end_buf, &iwe,
5406 IW_EV_PARAM_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005407 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005408 /* Check if we added any event */
David S. Millerccc58052008-06-16 18:50:49 -07005409 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
Dan Williams1e3428e2007-10-10 23:56:25 -04005410 current_ev = current_val;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005411 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005412
David Kilroy17a1a882008-08-21 23:27:47 +01005413 /* Beacon interval */
5414 iwe.cmd = IWEVCUSTOM;
5415 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5416 "bcn_int=%d",
5417 le16_to_cpu(bss->a.beacon_interv));
5418 if (iwe.u.data.length)
5419 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5420 &iwe, custom);
5421
5422 /* Capabilites */
5423 iwe.cmd = IWEVCUSTOM;
5424 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5425 "capab=0x%04x",
5426 capabilities);
5427 if (iwe.u.data.length)
5428 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5429 &iwe, custom);
5430
5431 /* Add EXTRA: Age to display seconds since last beacon/probe response
5432 * for given network. */
5433 iwe.cmd = IWEVCUSTOM;
5434 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5435 " Last beacon: %dms ago",
5436 jiffies_to_msecs(jiffies - last_scanned));
5437 if (iwe.u.data.length)
5438 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5439 &iwe, custom);
5440
Dan Williams1e3428e2007-10-10 23:56:25 -04005441 return current_ev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005442}
5443
David Kilroy01632fa2008-08-21 23:27:58 +01005444static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5445 struct iw_request_info *info,
5446 char *current_ev,
5447 char *end_buf,
5448 struct agere_ext_scan_info *bss,
Pavel Roskindfe1baf2008-11-10 09:25:53 -05005449 unsigned long last_scanned)
David Kilroy01632fa2008-08-21 23:27:58 +01005450{
5451 u16 capabilities;
5452 u16 channel;
5453 struct iw_event iwe; /* Temporary buffer */
5454 char custom[MAX_CUSTOM_LEN];
5455 u8 *ie;
5456
5457 memset(&iwe, 0, sizeof(iwe));
5458
5459 /* First entry *MUST* be the AP MAC address */
5460 iwe.cmd = SIOCGIWAP;
5461 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5462 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5463 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5464 &iwe, IW_EV_ADDR_LEN);
5465
5466 /* Other entries will be displayed in the order we give them */
5467
5468 /* Add the ESSID */
5469 ie = bss->data;
5470 iwe.u.data.length = ie[1];
5471 if (iwe.u.data.length) {
5472 if (iwe.u.data.length > 32)
5473 iwe.u.data.length = 32;
5474 iwe.cmd = SIOCGIWESSID;
5475 iwe.u.data.flags = 1;
5476 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5477 &iwe, &ie[2]);
5478 }
5479
5480 /* Add mode */
5481 capabilities = le16_to_cpu(bss->capabilities);
5482 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5483 iwe.cmd = SIOCGIWMODE;
5484 if (capabilities & WLAN_CAPABILITY_ESS)
5485 iwe.u.mode = IW_MODE_MASTER;
5486 else
5487 iwe.u.mode = IW_MODE_ADHOC;
5488 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5489 &iwe, IW_EV_UINT_LEN);
5490 }
5491
Johannes Berg2c7060022008-10-30 22:09:54 +01005492 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
David Kilroy01632fa2008-08-21 23:27:58 +01005493 channel = ie ? ie[2] : 0;
5494 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5495 /* Add channel and frequency */
5496 iwe.cmd = SIOCGIWFREQ;
5497 iwe.u.freq.m = channel;
5498 iwe.u.freq.e = 0;
5499 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5500 &iwe, IW_EV_FREQ_LEN);
5501
David Kilroy9ee677c2008-12-23 14:03:38 +00005502 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
David Kilroy01632fa2008-08-21 23:27:58 +01005503 iwe.u.freq.e = 1;
5504 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5505 &iwe, IW_EV_FREQ_LEN);
5506 }
5507
5508 /* Add quality statistics. level and noise in dB. No link quality */
5509 iwe.cmd = IWEVQUAL;
5510 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5511 iwe.u.qual.level = bss->level - 0x95;
5512 iwe.u.qual.noise = bss->noise - 0x95;
5513 /* Wireless tools prior to 27.pre22 will show link quality
5514 * anyway, so we provide a reasonable value. */
5515 if (iwe.u.qual.level > iwe.u.qual.noise)
5516 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5517 else
5518 iwe.u.qual.qual = 0;
5519 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5520 &iwe, IW_EV_QUAL_LEN);
5521
5522 /* Add encryption capability */
5523 iwe.cmd = SIOCGIWENCODE;
5524 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5525 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5526 else
5527 iwe.u.data.flags = IW_ENCODE_DISABLED;
5528 iwe.u.data.length = 0;
5529 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5530 &iwe, NULL);
5531
5532 /* WPA IE */
5533 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5534 if (ie) {
5535 iwe.cmd = IWEVGENIE;
5536 iwe.u.data.length = ie[1] + 2;
5537 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5538 &iwe, ie);
5539 }
5540
5541 /* RSN IE */
Johannes Berg2c7060022008-10-30 22:09:54 +01005542 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
David Kilroy01632fa2008-08-21 23:27:58 +01005543 if (ie) {
5544 iwe.cmd = IWEVGENIE;
5545 iwe.u.data.length = ie[1] + 2;
5546 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5547 &iwe, ie);
5548 }
5549
Johannes Berg2c7060022008-10-30 22:09:54 +01005550 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
David Kilroy01632fa2008-08-21 23:27:58 +01005551 if (ie) {
5552 char *p = current_ev + iwe_stream_lcp_len(info);
5553 int i;
5554
5555 iwe.cmd = SIOCGIWRATE;
5556 /* Those two flags are ignored... */
5557 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5558
5559 for (i = 2; i < (ie[1] + 2); i++) {
5560 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5561 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5562 &iwe, IW_EV_PARAM_LEN);
5563 }
5564 /* Check if we added any event */
5565 if (p > (current_ev + iwe_stream_lcp_len(info)))
5566 current_ev = p;
5567 }
5568
5569 /* Timestamp */
5570 iwe.cmd = IWEVCUSTOM;
David Kilroy75d31cf2008-09-12 22:28:18 +01005571 iwe.u.data.length =
5572 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
5573 (unsigned long long) le64_to_cpu(bss->timestamp));
David Kilroy01632fa2008-08-21 23:27:58 +01005574 if (iwe.u.data.length)
5575 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5576 &iwe, custom);
5577
5578 /* Beacon interval */
5579 iwe.cmd = IWEVCUSTOM;
5580 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5581 "bcn_int=%d",
5582 le16_to_cpu(bss->beacon_interval));
5583 if (iwe.u.data.length)
5584 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5585 &iwe, custom);
5586
5587 /* Capabilites */
5588 iwe.cmd = IWEVCUSTOM;
5589 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5590 "capab=0x%04x",
5591 capabilities);
5592 if (iwe.u.data.length)
5593 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5594 &iwe, custom);
5595
5596 /* Add EXTRA: Age to display seconds since last beacon/probe response
5597 * for given network. */
5598 iwe.cmd = IWEVCUSTOM;
5599 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5600 " Last beacon: %dms ago",
5601 jiffies_to_msecs(jiffies - last_scanned));
5602 if (iwe.u.data.length)
5603 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5604 &iwe, custom);
5605
5606 return current_ev;
5607}
5608
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005609/* Return results of a scan */
5610static int orinoco_ioctl_getscan(struct net_device *dev,
5611 struct iw_request_info *info,
5612 struct iw_point *srq,
5613 char *extra)
5614{
5615 struct orinoco_private *priv = netdev_priv(dev);
5616 int err = 0;
5617 unsigned long flags;
Dan Williams1e3428e2007-10-10 23:56:25 -04005618 char *current_ev = extra;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005619
5620 if (orinoco_lock(priv, &flags) != 0)
5621 return -EBUSY;
5622
Dan Williams1e3428e2007-10-10 23:56:25 -04005623 if (priv->scan_inprogress) {
5624 /* Important note : we don't want to block the caller
5625 * until results are ready for various reasons.
5626 * First, managing wait queues is complex and racy.
5627 * Second, we grab some rtnetlink lock before comming
5628 * here (in dev_ioctl()).
5629 * Third, we generate an Wireless Event, so the
5630 * caller can wait itself on that - Jean II */
5631 err = -EAGAIN;
5632 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005633 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005634
David Kilroy01632fa2008-08-21 23:27:58 +01005635 if (priv->has_ext_scan) {
5636 struct xbss_element *bss;
Dan Williams1e3428e2007-10-10 23:56:25 -04005637
David Kilroy01632fa2008-08-21 23:27:58 +01005638 list_for_each_entry(bss, &priv->bss_list, list) {
5639 /* Translate this entry to WE format */
5640 current_ev =
5641 orinoco_translate_ext_scan(dev, info,
5642 current_ev,
5643 extra + srq->length,
5644 &bss->bss,
5645 bss->last_scanned);
5646
5647 /* Check if there is space for one more entry */
5648 if ((extra + srq->length - current_ev)
5649 <= IW_EV_ADDR_LEN) {
5650 /* Ask user space to try again with a
5651 * bigger buffer */
5652 err = -E2BIG;
5653 goto out;
5654 }
5655 }
5656
5657 } else {
5658 struct bss_element *bss;
5659
5660 list_for_each_entry(bss, &priv->bss_list, list) {
5661 /* Translate this entry to WE format */
5662 current_ev = orinoco_translate_scan(dev, info,
5663 current_ev,
5664 extra + srq->length,
5665 &bss->bss,
5666 bss->last_scanned);
5667
5668 /* Check if there is space for one more entry */
5669 if ((extra + srq->length - current_ev)
5670 <= IW_EV_ADDR_LEN) {
5671 /* Ask user space to try again with a
5672 * bigger buffer */
5673 err = -E2BIG;
5674 goto out;
5675 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005676 }
5677 }
5678
5679 srq->length = (current_ev - extra);
5680 srq->flags = (__u16) priv->scan_mode;
5681
5682out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005683 orinoco_unlock(priv, &flags);
5684 return err;
5685}
5686
Christoph Hellwig620554e2005-06-19 01:27:33 +02005687/* Commit handler, called after set operations */
5688static int orinoco_ioctl_commit(struct net_device *dev,
5689 struct iw_request_info *info,
5690 void *wrqu,
5691 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005692{
5693 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005694 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005695 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005696 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005697
Christoph Hellwig620554e2005-06-19 01:27:33 +02005698 if (!priv->open)
5699 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005700
Christoph Hellwig620554e2005-06-19 01:27:33 +02005701 if (priv->broken_disableport) {
David Howellsc4028952006-11-22 14:57:56 +00005702 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005703 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005704 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005705
Christoph Hellwig620554e2005-06-19 01:27:33 +02005706 if (orinoco_lock(priv, &flags) != 0)
5707 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708
Christoph Hellwig620554e2005-06-19 01:27:33 +02005709 err = hermes_disable_port(hw, 0);
5710 if (err) {
5711 printk(KERN_WARNING "%s: Unable to disable port "
5712 "while reconfiguring card\n", dev->name);
5713 priv->broken_disableport = 1;
5714 goto out;
5715 }
5716
5717 err = __orinoco_program_rids(dev);
5718 if (err) {
5719 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5720 dev->name);
5721 goto out;
5722 }
5723
5724 err = hermes_enable_port(hw, 0);
5725 if (err) {
5726 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5727 dev->name);
5728 goto out;
5729 }
5730
5731 out:
5732 if (err) {
5733 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5734 schedule_work(&priv->reset_work);
5735 err = 0;
5736 }
5737
5738 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739 return err;
5740}
5741
Christoph Hellwig620554e2005-06-19 01:27:33 +02005742static const struct iw_priv_args orinoco_privtab[] = {
5743 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5744 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5745 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5746 0, "set_port3" },
5747 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5748 "get_port3" },
5749 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5750 0, "set_preamble" },
5751 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5752 "get_preamble" },
5753 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5754 0, "set_ibssport" },
5755 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5756 "get_ibssport" },
5757 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5758 "get_rid" },
5759};
5760
5761
5762/*
5763 * Structures to export the Wireless Handlers
5764 */
5765
David Kilroy409644a2008-08-21 23:28:01 +01005766#define STD_IW_HANDLER(id, func) \
5767 [IW_IOCTL_IDX(id)] = (iw_handler) func
Christoph Hellwig620554e2005-06-19 01:27:33 +02005768static const iw_handler orinoco_handler[] = {
David Kilroy409644a2008-08-21 23:28:01 +01005769 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
5770 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
5771 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
5772 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
5773 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
5774 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
5775 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
5776 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
5777 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
5778 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
5779 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
5780 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
5781 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
5782 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
5783 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
5784 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
5785 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
5786 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
5787 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
5788 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
5789 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
5790 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
5791 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
5792 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
5793 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
5794 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
5795 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
5796 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
5797 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
5798 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
5799 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
5800 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
David Kilroyd03032a2008-08-21 23:28:02 +01005801 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
5802 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
5803 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
5804 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
5805 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
5806 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
5807 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
Christoph Hellwig620554e2005-06-19 01:27:33 +02005808};
5809
5810
5811/*
5812 Added typecasting since we no longer use iwreq_data -- Moustafa
5813 */
5814static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07005815 [0] = (iw_handler) orinoco_ioctl_reset,
5816 [1] = (iw_handler) orinoco_ioctl_reset,
5817 [2] = (iw_handler) orinoco_ioctl_setport3,
5818 [3] = (iw_handler) orinoco_ioctl_getport3,
5819 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5820 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5821 [6] = (iw_handler) orinoco_ioctl_setibssport,
5822 [7] = (iw_handler) orinoco_ioctl_getibssport,
5823 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005824};
5825
5826static const struct iw_handler_def orinoco_handler_def = {
5827 .num_standard = ARRAY_SIZE(orinoco_handler),
5828 .num_private = ARRAY_SIZE(orinoco_private_handler),
5829 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5830 .standard = orinoco_handler,
5831 .private = orinoco_private_handler,
5832 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04005833 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005834};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005836static void orinoco_get_drvinfo(struct net_device *dev,
5837 struct ethtool_drvinfo *info)
5838{
5839 struct orinoco_private *priv = netdev_priv(dev);
5840
5841 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5842 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5843 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07005844 if (dev->dev.parent)
Kay Sieversfb28ad32008-11-10 13:55:14 -08005845 strncpy(info->bus_info, dev_name(dev->dev.parent),
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005846 sizeof(info->bus_info) - 1);
5847 else
5848 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5849 "PCMCIA %p", priv->hw.iobase);
5850}
5851
Jeff Garzik7282d492006-09-13 14:30:00 -04005852static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005853 .get_drvinfo = orinoco_get_drvinfo,
5854 .get_link = ethtool_op_get_link,
5855};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856
5857/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07005858/* Module initialization */
5859/********************************************************************/
5860
Linus Torvalds1da177e2005-04-16 15:20:36 -07005861/* Can't be declared "const" or the whole __initdata section will
5862 * become const */
5863static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
5864 " (David Gibson <hermes@gibson.dropbear.id.au>, "
5865 "Pavel Roskin <proski@gnu.org>, et al)";
5866
5867static int __init init_orinoco(void)
5868{
5869 printk(KERN_DEBUG "%s\n", version);
5870 return 0;
5871}
5872
5873static void __exit exit_orinoco(void)
5874{
5875}
5876
5877module_init(init_orinoco);
5878module_exit(exit_orinoco);