blob: 1063f8cc84e60e0586c4e3548215e053e1216401 [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
David Kilroy23edcc42008-08-21 23:28:05 +010093#include <linux/scatterlist.h>
94#include <linux/crypto.h>
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010097#include "hermes_dld.h"
David Kilroyfb791b12009-02-04 23:05:50 +000098#include "scan.h"
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102/********************************************************************/
103/* Module information */
104/********************************************************************/
105
David Kilroyb2f30a02009-02-04 23:05:46 +0000106MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
107 "David Gibson <hermes@gibson.dropbear.id.au>");
108MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
109 "and similar wireless cards");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110MODULE_LICENSE("Dual MPL/GPL");
111
112/* Level of debugging. Used in the macros in orinoco.h */
113#ifdef ORINOCO_DEBUG
114int orinoco_debug = ORINOCO_DEBUG;
David Kilroy21312662009-02-04 23:05:47 +0000115EXPORT_SYMBOL(orinoco_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116module_param(orinoco_debug, int, 0644);
117MODULE_PARM_DESC(orinoco_debug, "Debug level");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#endif
119
120static int suppress_linkstatus; /* = 0 */
121module_param(suppress_linkstatus, bool, 0644);
122MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Kilroyb2f30a02009-02-04 23:05:46 +0000123
David Gibson7bb7c3a2005-05-12 20:02:10 -0400124static int ignore_disconnect; /* = 0 */
125module_param(ignore_disconnect, int, 0644);
David Kilroyb2f30a02009-02-04 23:05:46 +0000126MODULE_PARM_DESC(ignore_disconnect,
127 "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200129static int force_monitor; /* = 0 */
130module_param(force_monitor, int, 0644);
131MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/********************************************************************/
134/* Compile time configuration and compatibility stuff */
135/********************************************************************/
136
137/* We do this this way to avoid ifdefs in the actual code */
138#ifdef WIRELESS_SPY
Pavel Roskin343c6862005-09-09 18:43:02 -0400139#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#else
141#define SPY_NUMBER(priv) 0
142#endif /* WIRELESS_SPY */
143
144/********************************************************************/
145/* Internal constants */
146/********************************************************************/
147
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200148/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
149static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
150#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152#define ORINOCO_MIN_MTU 256
Johannes Berg2c7060022008-10-30 22:09:54 +0100153#define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155#define SYMBOL_MAX_VER_LEN (14)
156#define USER_BAP 0
157#define IRQ_BAP 1
158#define MAX_IRQLOOPS_PER_IRQ 10
159#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
160 * how many events the
161 * device could
162 * legitimately generate */
163#define SMALL_KEY_SIZE 5
164#define LARGE_KEY_SIZE 13
165#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
166
167#define DUMMY_FID 0xFFFF
168
169/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
170 HERMES_MAX_MULTICAST : 0)*/
171#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
172
173#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
174 | HERMES_EV_TX | HERMES_EV_TXEXC \
175 | HERMES_EV_WTERR | HERMES_EV_INFO \
David Kilroya94e8422009-02-04 23:05:44 +0000176 | HERMES_EV_INFDROP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Christoph Hellwig620554e2005-06-19 01:27:33 +0200178#define MAX_RID_LEN 1024
179
180static const struct iw_handler_def orinoco_handler_def;
Jeff Garzik7282d492006-09-13 14:30:00 -0400181static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/********************************************************************/
184/* Data tables */
185/********************************************************************/
186
David Kilroy9ee677c2008-12-23 14:03:38 +0000187#define NUM_CHANNELS 14
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189/* This tables gives the actual meanings of the bitrate IDs returned
190 * by the firmware. */
191static struct {
192 int bitrate; /* in 100s of kilobits */
193 int automatic;
194 u16 agere_txratectrl;
195 u16 intersil_txratectrl;
196} bitrate_table[] = {
197 {110, 1, 3, 15}, /* Entry 0 is the default */
198 {10, 0, 1, 1},
199 {10, 1, 1, 1},
200 {20, 0, 2, 2},
201 {20, 1, 6, 3},
202 {55, 0, 4, 4},
203 {55, 1, 7, 7},
204 {110, 0, 5, 8},
205};
206#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
207
208/********************************************************************/
209/* Data types */
210/********************************************************************/
211
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400212/* Beginning of the Tx descriptor, used in TxExc handling */
213struct hermes_txexc_data {
214 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400215 __le16 frame_ctl;
216 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200217 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218} __attribute__ ((packed));
219
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200220/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200222 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400223 __le16 status;
224 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 u8 silence;
226 u8 signal;
227 u8 rate;
228 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400229 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200230
231 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400232 __le16 frame_ctl;
233 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200234 u8 addr1[ETH_ALEN];
235 u8 addr2[ETH_ALEN];
236 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400237 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200238 u8 addr4[ETH_ALEN];
239
240 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400241 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242} __attribute__ ((packed));
243
David Kilroy47166792009-01-07 00:43:54 +0000244struct orinoco_rx_data {
245 struct hermes_rx_descriptor *desc;
246 struct sk_buff *skb;
247 struct list_head list;
248};
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/********************************************************************/
251/* Function prototypes */
252/********************************************************************/
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254static int __orinoco_program_rids(struct net_device *dev);
255static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257/********************************************************************/
David Kilroy23edcc42008-08-21 23:28:05 +0100258/* Michael MIC crypto setup */
259/********************************************************************/
260#define MICHAEL_MIC_LEN 8
261static int orinoco_mic_init(struct orinoco_private *priv)
262{
263 priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
264 if (IS_ERR(priv->tx_tfm_mic)) {
265 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
266 "crypto API michael_mic\n");
267 priv->tx_tfm_mic = NULL;
268 return -ENOMEM;
269 }
270
271 priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
272 if (IS_ERR(priv->rx_tfm_mic)) {
273 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
274 "crypto API michael_mic\n");
275 priv->rx_tfm_mic = NULL;
276 return -ENOMEM;
277 }
278
279 return 0;
280}
281
282static void orinoco_mic_free(struct orinoco_private *priv)
283{
284 if (priv->tx_tfm_mic)
285 crypto_free_hash(priv->tx_tfm_mic);
286 if (priv->rx_tfm_mic)
287 crypto_free_hash(priv->rx_tfm_mic);
288}
289
290static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
291 u8 *da, u8 *sa, u8 priority,
292 u8 *data, size_t data_len, u8 *mic)
293{
294 struct hash_desc desc;
295 struct scatterlist sg[2];
296 u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
297
298 if (tfm_michael == NULL) {
299 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
300 return -1;
301 }
302
303 /* Copy header into buffer. We need the padding on the end zeroed */
304 memcpy(&hdr[0], da, ETH_ALEN);
305 memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
306 hdr[ETH_ALEN*2] = priority;
307 hdr[ETH_ALEN*2+1] = 0;
308 hdr[ETH_ALEN*2+2] = 0;
309 hdr[ETH_ALEN*2+3] = 0;
310
311 /* Use scatter gather to MIC header and data in one go */
312 sg_init_table(sg, 2);
313 sg_set_buf(&sg[0], hdr, sizeof(hdr));
314 sg_set_buf(&sg[1], data, data_len);
315
316 if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
317 return -1;
318
319 desc.tfm = tfm_michael;
320 desc.flags = 0;
321 return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
322 mic);
323}
324
325/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326/* Internal helper functions */
327/********************************************************************/
328
329static inline void set_port_type(struct orinoco_private *priv)
330{
331 switch (priv->iw_mode) {
332 case IW_MODE_INFRA:
333 priv->port_type = 1;
334 priv->createibss = 0;
335 break;
336 case IW_MODE_ADHOC:
337 if (priv->prefer_port3) {
338 priv->port_type = 3;
339 priv->createibss = 0;
340 } else {
341 priv->port_type = priv->ibss_port;
342 priv->createibss = 1;
343 }
344 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200345 case IW_MODE_MONITOR:
346 priv->port_type = 3;
347 priv->createibss = 0;
348 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 default:
350 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
351 priv->ndev->name);
352 }
353}
354
David Kilroy01632fa2008-08-21 23:27:58 +0100355static inline u8 *orinoco_get_ie(u8 *data, size_t len,
Johannes Berg2c7060022008-10-30 22:09:54 +0100356 enum ieee80211_eid eid)
David Kilroy01632fa2008-08-21 23:27:58 +0100357{
358 u8 *p = data;
359 while ((p + 2) < (data + len)) {
360 if (p[0] == eid)
361 return p;
362 p += p[1] + 2;
363 }
364 return NULL;
365}
366
367#define WPA_OUI_TYPE "\x00\x50\xF2\x01"
368#define WPA_SELECTOR_LEN 4
369static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
370{
371 u8 *p = data;
372 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
Johannes Berg2c7060022008-10-30 22:09:54 +0100373 if ((p[0] == WLAN_EID_GENERIC) &&
David Kilroy01632fa2008-08-21 23:27:58 +0100374 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
375 return p;
376 p += p[1] + 2;
377 }
378 return NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -0400379}
380
David Kilroy3994d502008-08-21 23:27:54 +0100381
382/********************************************************************/
383/* Download functionality */
384/********************************************************************/
385
386struct fw_info {
387 char *pri_fw;
388 char *sta_fw;
389 char *ap_fw;
390 u32 pda_addr;
391 u16 pda_size;
392};
393
394const static struct fw_info orinoco_fw[] = {
David Kilroy74734312008-11-22 10:37:25 +0000395 { NULL, "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
396 { NULL, "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
397 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", NULL, 0x00003100, 512 }
David Kilroy3994d502008-08-21 23:27:54 +0100398};
399
400/* Structure used to access fields in FW
401 * Make sure LE decoding macros are used
402 */
403struct orinoco_fw_header {
404 char hdr_vers[6]; /* ASCII string for header version */
405 __le16 headersize; /* Total length of header */
406 __le32 entry_point; /* NIC entry point */
407 __le32 blocks; /* Number of blocks to program */
408 __le32 block_offset; /* Offset of block data from eof header */
409 __le32 pdr_offset; /* Offset to PDR data from eof header */
410 __le32 pri_offset; /* Offset to primary plug data */
411 __le32 compat_offset; /* Offset to compatibility data*/
412 char signature[0]; /* FW signature length headersize-20 */
413} __attribute__ ((packed));
414
415/* Download either STA or AP firmware into the card. */
416static int
417orinoco_dl_firmware(struct orinoco_private *priv,
418 const struct fw_info *fw,
419 int ap)
420{
421 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400422 __le16 *pda;
David Kilroy3994d502008-08-21 23:27:54 +0100423
424 hermes_t *hw = &priv->hw;
425 const struct firmware *fw_entry;
426 const struct orinoco_fw_header *hdr;
427 const unsigned char *first_block;
428 const unsigned char *end;
429 const char *firmware;
430 struct net_device *dev = priv->ndev;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400431 int err = 0;
432
433 pda = kzalloc(fw->pda_size, GFP_KERNEL);
434 if (!pda)
435 return -ENOMEM;
David Kilroy3994d502008-08-21 23:27:54 +0100436
437 if (ap)
438 firmware = fw->ap_fw;
439 else
440 firmware = fw->sta_fw;
441
442 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
443 dev->name, firmware);
444
445 /* Read current plug data */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400446 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
David Kilroy3994d502008-08-21 23:27:54 +0100447 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
448 if (err)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400449 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100450
David Kilroy74734312008-11-22 10:37:25 +0000451 if (!priv->cached_fw) {
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400452 err = request_firmware(&fw_entry, firmware, priv->dev);
David Kilroy74734312008-11-22 10:37:25 +0000453
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400454 if (err) {
455 printk(KERN_ERR "%s: Cannot find firmware %s\n",
456 dev->name, firmware);
457 err = -ENOENT;
458 goto free;
459 }
David Kilroy74734312008-11-22 10:37:25 +0000460 } else
461 fw_entry = priv->cached_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100462
463 hdr = (const struct orinoco_fw_header *) fw_entry->data;
464
465 /* Enable aux port to allow programming */
466 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
467 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
468 if (err != 0)
469 goto abort;
470
471 /* Program data */
472 first_block = (fw_entry->data +
473 le16_to_cpu(hdr->headersize) +
474 le32_to_cpu(hdr->block_offset));
475 end = fw_entry->data + fw_entry->size;
476
477 err = hermes_program(hw, first_block, end);
478 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
479 if (err != 0)
480 goto abort;
481
482 /* Update production data */
483 first_block = (fw_entry->data +
484 le16_to_cpu(hdr->headersize) +
485 le32_to_cpu(hdr->pdr_offset));
486
487 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
488 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
489 if (err)
490 goto abort;
491
492 /* Tell card we've finished */
493 err = hermesi_program_end(hw);
494 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
495 if (err != 0)
496 goto abort;
497
498 /* Check if we're running */
499 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
500 dev->name, hermes_present(hw));
501
502abort:
David Kilroy74734312008-11-22 10:37:25 +0000503 /* If we requested the firmware, release it. */
504 if (!priv->cached_fw)
Andrey Borzenkov4fb30782008-10-19 12:06:11 +0400505 release_firmware(fw_entry);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400506
507free:
508 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100509 return err;
510}
511
512/* End markers */
513#define TEXT_END 0x1A /* End of text header */
514
515/*
516 * Process a firmware image - stop the card, load the firmware, reset
517 * the card and make sure it responds. For the secondary firmware take
518 * care of the PDA - read it and then write it on top of the firmware.
519 */
520static int
521symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
522 const unsigned char *image, const unsigned char *end,
523 int secondary)
524{
525 hermes_t *hw = &priv->hw;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400526 int ret = 0;
David Kilroy3994d502008-08-21 23:27:54 +0100527 const unsigned char *ptr;
528 const unsigned char *first_block;
529
530 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400531 __le16 *pda = NULL;
David Kilroy3994d502008-08-21 23:27:54 +0100532
533 /* Binary block begins after the 0x1A marker */
534 ptr = image;
535 while (*ptr++ != TEXT_END);
536 first_block = ptr;
537
538 /* Read the PDA from EEPROM */
539 if (secondary) {
Andrey Borzenkov70458252008-10-10 21:26:30 +0400540 pda = kzalloc(fw->pda_size, GFP_KERNEL);
541 if (!pda)
542 return -ENOMEM;
543
544 ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
David Kilroy3994d502008-08-21 23:27:54 +0100545 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400546 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100547 }
548
549 /* Stop the firmware, so that it can be safely rewritten */
550 if (priv->stop_fw) {
551 ret = priv->stop_fw(priv, 1);
552 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400553 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100554 }
555
556 /* Program the adapter with new firmware */
557 ret = hermes_program(hw, first_block, end);
558 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400559 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100560
561 /* Write the PDA to the adapter */
562 if (secondary) {
563 size_t len = hermes_blocks_length(first_block);
564 ptr = first_block + len;
565 ret = hermes_apply_pda(hw, ptr, pda);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400566 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100567 if (ret)
568 return ret;
569 }
570
571 /* Run the firmware */
572 if (priv->stop_fw) {
573 ret = priv->stop_fw(priv, 0);
574 if (ret)
575 return ret;
576 }
577
578 /* Reset hermes chip and make sure it responds */
579 ret = hermes_init(hw);
580
581 /* hermes_reset() should return 0 with the secondary firmware */
582 if (secondary && ret != 0)
583 return -ENODEV;
584
585 /* And this should work with any firmware */
586 if (!hermes_present(hw))
587 return -ENODEV;
588
589 return 0;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400590
591free:
592 kfree(pda);
593 return ret;
David Kilroy3994d502008-08-21 23:27:54 +0100594}
595
596
597/*
598 * Download the firmware into the card, this also does a PCMCIA soft
599 * reset on the card, to make sure it's in a sane state.
600 */
601static int
602symbol_dl_firmware(struct orinoco_private *priv,
603 const struct fw_info *fw)
604{
605 struct net_device *dev = priv->ndev;
606 int ret;
607 const struct firmware *fw_entry;
608
David Kilroy2cea7b22008-11-22 10:37:26 +0000609 if (!priv->cached_pri_fw) {
610 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) {
611 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
612 dev->name, fw->pri_fw);
613 return -ENOENT;
614 }
615 } else
616 fw_entry = priv->cached_pri_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100617
618 /* Load primary firmware */
619 ret = symbol_dl_image(priv, fw, fw_entry->data,
620 fw_entry->data + fw_entry->size, 0);
David Kilroy2cea7b22008-11-22 10:37:26 +0000621
622 if (!priv->cached_pri_fw)
623 release_firmware(fw_entry);
David Kilroy3994d502008-08-21 23:27:54 +0100624 if (ret) {
625 printk(KERN_ERR "%s: Primary firmware download failed\n",
626 dev->name);
627 return ret;
628 }
629
David Kilroy2cea7b22008-11-22 10:37:26 +0000630 if (!priv->cached_fw) {
631 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) {
632 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
633 dev->name, fw->sta_fw);
634 return -ENOENT;
635 }
636 } else
637 fw_entry = priv->cached_fw;
David Kilroy3994d502008-08-21 23:27:54 +0100638
639 /* Load secondary firmware */
640 ret = symbol_dl_image(priv, fw, fw_entry->data,
641 fw_entry->data + fw_entry->size, 1);
David Kilroy2cea7b22008-11-22 10:37:26 +0000642 if (!priv->cached_fw)
643 release_firmware(fw_entry);
David Kilroy3994d502008-08-21 23:27:54 +0100644 if (ret) {
645 printk(KERN_ERR "%s: Secondary firmware download failed\n",
646 dev->name);
647 }
648
649 return ret;
650}
651
652static int orinoco_download(struct orinoco_private *priv)
653{
654 int err = 0;
655 /* Reload firmware */
656 switch (priv->firmware_type) {
657 case FIRMWARE_TYPE_AGERE:
658 /* case FIRMWARE_TYPE_INTERSIL: */
659 err = orinoco_dl_firmware(priv,
660 &orinoco_fw[priv->firmware_type], 0);
661 break;
662
663 case FIRMWARE_TYPE_SYMBOL:
664 err = symbol_dl_firmware(priv,
665 &orinoco_fw[priv->firmware_type]);
666 break;
667 case FIRMWARE_TYPE_INTERSIL:
668 break;
669 }
670 /* TODO: if we fail we probably need to reinitialise
671 * the driver */
672
673 return err;
674}
675
David Kilroy39d1ffe2008-11-22 10:37:28 +0000676#if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
David Kilroy74734312008-11-22 10:37:25 +0000677static void orinoco_cache_fw(struct orinoco_private *priv, int ap)
678{
679 const struct firmware *fw_entry = NULL;
David Kilroy2cea7b22008-11-22 10:37:26 +0000680 const char *pri_fw;
David Kilroy74734312008-11-22 10:37:25 +0000681 const char *fw;
682
David Kilroy2cea7b22008-11-22 10:37:26 +0000683 pri_fw = orinoco_fw[priv->firmware_type].pri_fw;
David Kilroy74734312008-11-22 10:37:25 +0000684 if (ap)
685 fw = orinoco_fw[priv->firmware_type].ap_fw;
686 else
687 fw = orinoco_fw[priv->firmware_type].sta_fw;
688
David Kilroy2cea7b22008-11-22 10:37:26 +0000689 if (pri_fw) {
690 if (request_firmware(&fw_entry, pri_fw, priv->dev) == 0)
691 priv->cached_pri_fw = fw_entry;
692 }
693
David Kilroy74734312008-11-22 10:37:25 +0000694 if (fw) {
695 if (request_firmware(&fw_entry, fw, priv->dev) == 0)
696 priv->cached_fw = fw_entry;
697 }
698}
699
700static void orinoco_uncache_fw(struct orinoco_private *priv)
701{
David Kilroy2cea7b22008-11-22 10:37:26 +0000702 if (priv->cached_pri_fw)
703 release_firmware(priv->cached_pri_fw);
David Kilroy74734312008-11-22 10:37:25 +0000704 if (priv->cached_fw)
705 release_firmware(priv->cached_fw);
706
David Kilroy2cea7b22008-11-22 10:37:26 +0000707 priv->cached_pri_fw = NULL;
David Kilroy74734312008-11-22 10:37:25 +0000708 priv->cached_fw = NULL;
709}
David Kilroy39d1ffe2008-11-22 10:37:28 +0000710#else
711#define orinoco_cache_fw(priv, ap)
712#define orinoco_uncache_fw(priv)
713#endif
David Kilroy74734312008-11-22 10:37:25 +0000714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715/********************************************************************/
716/* Device methods */
717/********************************************************************/
718
719static int orinoco_open(struct net_device *dev)
720{
721 struct orinoco_private *priv = netdev_priv(dev);
722 unsigned long flags;
723 int err;
724
725 if (orinoco_lock(priv, &flags) != 0)
726 return -EBUSY;
727
728 err = __orinoco_up(dev);
729
David Kilroya94e8422009-02-04 23:05:44 +0000730 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 priv->open = 1;
732
733 orinoco_unlock(priv, &flags);
734
735 return err;
736}
737
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200738static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739{
740 struct orinoco_private *priv = netdev_priv(dev);
741 int err = 0;
742
743 /* We mustn't use orinoco_lock() here, because we need to be
744 able to close the interface even if hw_unavailable is set
745 (e.g. as we're released after a PC Card removal) */
746 spin_lock_irq(&priv->lock);
747
748 priv->open = 0;
749
750 err = __orinoco_down(dev);
751
752 spin_unlock_irq(&priv->lock);
753
754 return err;
755}
756
757static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
758{
759 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy6fe9deb2009-02-04 23:05:43 +0000760
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 return &priv->stats;
762}
763
764static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
765{
766 struct orinoco_private *priv = netdev_priv(dev);
767 hermes_t *hw = &priv->hw;
768 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400769 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 unsigned long flags;
771
David Kilroya94e8422009-02-04 23:05:44 +0000772 if (!netif_device_present(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
774 dev->name);
775 return NULL; /* FIXME: Can we do better than this? */
776 }
777
David Gibsone67d9d92005-05-12 20:01:22 -0400778 /* If busy, return the old stats. Returning NULL may cause
779 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400781 return wstats;
782
783 /* We can't really wait for the tallies inquiry command to
784 * complete, so we just use the previous results and trigger
785 * a new tallies inquiry command for next time - Jean II */
786 /* FIXME: Really we should wait for the inquiry to come back -
787 * as it is the stats we give don't make a whole lot of sense.
788 * Unfortunately, it's not clear how to do that within the
789 * wireless extensions framework: I think we're in user
790 * context, but a lock seems to be held by the time we get in
791 * here so we're not safe to sleep here. */
792 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (priv->iw_mode == IW_MODE_ADHOC) {
795 memset(&wstats->qual, 0, sizeof(wstats->qual));
796 /* If a spy address is defined, we report stats of the
797 * first spy address - Jean II */
798 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400799 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
800 wstats->qual.level = priv->spy_data.spy_stat[0].level;
801 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
David Kilroyb2f30a02009-02-04 23:05:46 +0000802 wstats->qual.updated =
803 priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 }
805 } else {
806 struct {
Pavel Roskina208c4e2006-04-07 04:10:26 -0400807 __le16 qual, signal, noise, unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 } __attribute__ ((packed)) cq;
809
810 err = HERMES_READ_RECORD(hw, USER_BAP,
811 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400812
813 if (!err) {
814 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
815 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
816 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
David Kilroyb2f30a02009-02-04 23:05:46 +0000817 wstats->qual.updated =
818 IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
David Gibsone67d9d92005-05-12 20:01:22 -0400819 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 }
821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 return wstats;
824}
825
826static void orinoco_set_multicast_list(struct net_device *dev)
827{
828 struct orinoco_private *priv = netdev_priv(dev);
829 unsigned long flags;
830
831 if (orinoco_lock(priv, &flags) != 0) {
832 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
833 "called when hw_unavailable\n", dev->name);
834 return;
835 }
836
837 __orinoco_set_multicast_list(dev);
838 orinoco_unlock(priv, &flags);
839}
840
841static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
842{
843 struct orinoco_private *priv = netdev_priv(dev);
844
David Kilroya94e8422009-02-04 23:05:44 +0000845 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return -EINVAL;
847
Johannes Berg2c7060022008-10-30 22:09:54 +0100848 /* MTU + encapsulation + header length */
David Kilroya94e8422009-02-04 23:05:44 +0000849 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
850 (priv->nicbuf_size - ETH_HLEN))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 return -EINVAL;
852
853 dev->mtu = new_mtu;
854
855 return 0;
856}
857
858/********************************************************************/
859/* Tx path */
860/********************************************************************/
861
862static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
863{
864 struct orinoco_private *priv = netdev_priv(dev);
865 struct net_device_stats *stats = &priv->stats;
866 hermes_t *hw = &priv->hw;
867 int err = 0;
868 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100870 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 unsigned long flags;
872
David Kilroya94e8422009-02-04 23:05:44 +0000873 if (!netif_running(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 printk(KERN_ERR "%s: Tx on stopped device!\n",
875 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400876 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (netif_queue_stopped(dev)) {
David Kilroy6fe9deb2009-02-04 23:05:43 +0000880 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400882 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
David Kilroy6fe9deb2009-02-04 23:05:43 +0000884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 if (orinoco_lock(priv, &flags) != 0) {
886 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
887 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400888 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
David Kilroya94e8422009-02-04 23:05:44 +0000891 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 /* Oops, the firmware hasn't established a connection,
David Kilroy6fe9deb2009-02-04 23:05:43 +0000893 silently drop the packet (this seems to be the
894 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400895 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
897
Pavel Roskin8d5be082006-04-07 04:10:41 -0400898 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400899 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400900 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
David Kilroy6eecad72008-08-21 23:27:56 +0100902 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
David Kilroy23edcc42008-08-21 23:28:05 +0100904 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
905 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
906 HERMES_TXCTRL_MIC;
907
David Kilroy6eecad72008-08-21 23:27:56 +0100908 if (priv->has_alt_txcntl) {
909 /* WPA enabled firmwares have tx_cntl at the end of
910 * the 802.11 header. So write zeroed descriptor and
911 * 802.11 header at the same time
912 */
913 char desc[HERMES_802_3_OFFSET];
914 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
915
916 memset(&desc, 0, sizeof(desc));
917
918 *txcntl = cpu_to_le16(tx_control);
919 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
920 txfid, 0);
921 if (err) {
922 if (net_ratelimit())
923 printk(KERN_ERR "%s: Error %d writing Tx "
924 "descriptor to BAP\n", dev->name, err);
925 goto busy;
926 }
927 } else {
928 struct hermes_tx_descriptor desc;
929
930 memset(&desc, 0, sizeof(desc));
931
932 desc.tx_control = cpu_to_le16(tx_control);
933 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
934 txfid, 0);
935 if (err) {
936 if (net_ratelimit())
937 printk(KERN_ERR "%s: Error %d writing Tx "
938 "descriptor to BAP\n", dev->name, err);
939 goto busy;
940 }
941
942 /* Clear the 802.11 header and data length fields - some
943 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
944 * if this isn't done. */
945 hermes_clear_words(hw, HERMES_DATA0,
946 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
David Kilroy23edcc42008-08-21 23:28:05 +0100949 eh = (struct ethhdr *)skb->data;
950
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 /* Encapsulate Ethernet-II frames */
952 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400953 struct header_struct {
954 struct ethhdr eth; /* 802.3 header */
955 u8 encap[6]; /* 802.2 header */
956 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Pavel Roskina28dc812006-04-07 04:10:45 -0400958 /* Strip destination and source from the data */
959 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400960
961 /* And move them to a separate header */
962 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
963 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
964 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
965
David Kilroy23edcc42008-08-21 23:28:05 +0100966 /* Insert the SNAP header */
967 if (skb_headroom(skb) < sizeof(hdr)) {
968 printk(KERN_ERR
969 "%s: Not enough headroom for 802.2 headers %d\n",
970 dev->name, skb_headroom(skb));
971 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 }
David Kilroy23edcc42008-08-21 23:28:05 +0100973 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
974 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 }
976
Pavel Roskina28dc812006-04-07 04:10:45 -0400977 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100978 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 if (err) {
980 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
981 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400982 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 }
984
David Kilroy23edcc42008-08-21 23:28:05 +0100985 /* Calculate Michael MIC */
986 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
987 u8 mic_buf[MICHAEL_MIC_LEN + 1];
988 u8 *mic;
989 size_t offset;
990 size_t len;
991
992 if (skb->len % 2) {
993 /* MIC start is on an odd boundary */
994 mic_buf[0] = skb->data[skb->len - 1];
995 mic = &mic_buf[1];
996 offset = skb->len - 1;
997 len = MICHAEL_MIC_LEN + 1;
998 } else {
999 mic = &mic_buf[0];
1000 offset = skb->len;
1001 len = MICHAEL_MIC_LEN;
1002 }
1003
1004 michael_mic(priv->tx_tfm_mic,
1005 priv->tkip_key[priv->tx_key].tx_mic,
1006 eh->h_dest, eh->h_source, 0 /* priority */,
1007 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
1008
1009 /* Write the MIC */
1010 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
1011 txfid, HERMES_802_3_OFFSET + offset);
1012 if (err) {
1013 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
1014 dev->name, err);
1015 goto busy;
1016 }
1017 }
1018
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 /* Finally, we actually initiate the send */
1020 netif_stop_queue(dev);
1021
1022 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
1023 txfid, NULL);
1024 if (err) {
1025 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -07001026 if (net_ratelimit())
1027 printk(KERN_ERR "%s: Error %d transmitting packet\n",
1028 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001029 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
1032 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +01001033 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001034 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001036 drop:
1037 stats->tx_errors++;
1038 stats->tx_dropped++;
1039
1040 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -04001043 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001045 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -04001046 if (err == -EIO)
1047 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -04001049 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
1052static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1053{
1054 struct orinoco_private *priv = netdev_priv(dev);
1055 u16 fid = hermes_read_regn(hw, ALLOCFID);
1056
1057 if (fid != priv->txfid) {
1058 if (fid != DUMMY_FID)
1059 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1060 dev->name, fid);
1061 return;
1062 }
1063
1064 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1065}
1066
1067static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1068{
1069 struct orinoco_private *priv = netdev_priv(dev);
1070 struct net_device_stats *stats = &priv->stats;
1071
1072 stats->tx_packets++;
1073
1074 netif_wake_queue(dev);
1075
1076 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1077}
1078
1079static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1080{
1081 struct orinoco_private *priv = netdev_priv(dev);
1082 struct net_device_stats *stats = &priv->stats;
1083 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -04001084 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001085 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 int err = 0;
1087
1088 if (fid == DUMMY_FID)
1089 return; /* Nothing's really happened */
1090
Pavel Roskin48ca7032005-09-23 04:18:06 -04001091 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001092 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001093 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001094 fid, 0);
1095
1096 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1097 stats->tx_errors++;
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 if (err) {
1100 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1101 "(FID=%04X error %d)\n",
1102 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001103 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001105
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001106 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1107 err, fid);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001108
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001109 /* We produce a TXDROP event only for retry or lifetime
1110 * exceeded, because that's the only status that really mean
1111 * that this particular node went away.
1112 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001113 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -04001114 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001115 union iwreq_data wrqu;
1116
1117 /* Copy 802.11 dest address.
1118 * We use the 802.11 header because the frame may
1119 * not be 802.3 or may be mangled...
1120 * In Ad-Hoc mode, it will be the node address.
1121 * In managed mode, it will be most likely the AP addr
1122 * User space will figure out how to convert it to
1123 * whatever it needs (IP address or else).
1124 * - Jean II */
1125 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1126 wrqu.addr.sa_family = ARPHRD_ETHER;
1127
1128 /* Send event to user space */
1129 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133}
1134
1135static void orinoco_tx_timeout(struct net_device *dev)
1136{
1137 struct orinoco_private *priv = netdev_priv(dev);
1138 struct net_device_stats *stats = &priv->stats;
1139 struct hermes *hw = &priv->hw;
1140
1141 printk(KERN_WARNING "%s: Tx timeout! "
1142 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1143 dev->name, hermes_read_regn(hw, ALLOCFID),
1144 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1145
1146 stats->tx_errors++;
1147
1148 schedule_work(&priv->reset_work);
1149}
1150
1151/********************************************************************/
1152/* Rx path (data frames) */
1153/********************************************************************/
1154
1155/* Does the frame have a SNAP header indicating it should be
1156 * de-encapsulated to Ethernet-II? */
1157static inline int is_ethersnap(void *_hdr)
1158{
1159 u8 *hdr = _hdr;
1160
1161 /* We de-encapsulate all packets which, a) have SNAP headers
1162 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1163 * and where b) the OUI of the SNAP header is 00:00:00 or
1164 * 00:00:f8 - we need both because different APs appear to use
1165 * different OUIs for some reason */
1166 return (memcmp(hdr, &encaps_hdr, 5) == 0)
David Kilroya94e8422009-02-04 23:05:44 +00001167 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
1170static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1171 int level, int noise)
1172{
Pavel Roskin343c6862005-09-09 18:43:02 -04001173 struct iw_quality wstats;
1174 wstats.level = level - 0x95;
1175 wstats.noise = noise - 0x95;
1176 wstats.qual = (level > noise) ? (level - noise) : 0;
Andrey Borzenkovf941f852008-11-15 17:15:09 +03001177 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Pavel Roskin343c6862005-09-09 18:43:02 -04001178 /* Update spy records */
1179 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180}
1181
1182static void orinoco_stat_gather(struct net_device *dev,
1183 struct sk_buff *skb,
1184 struct hermes_rx_descriptor *desc)
1185{
1186 struct orinoco_private *priv = netdev_priv(dev);
1187
1188 /* Using spy support with lots of Rx packets, like in an
1189 * infrastructure (AP), will really slow down everything, because
1190 * the MAC address must be compared to each entry of the spy list.
1191 * If the user really asks for it (set some address in the
1192 * spy list), we do it, but he will pay the price.
1193 * Note that to get here, you need both WIRELESS_SPY
1194 * compiled in AND some addresses in the list !!!
1195 */
1196 /* Note : gcc will optimise the whole section away if
1197 * WIRELESS_SPY is not defined... - Jean II */
1198 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07001199 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 desc->signal, desc->silence);
1201 }
1202}
1203
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001204/*
1205 * orinoco_rx_monitor - handle received monitor frames.
1206 *
1207 * Arguments:
1208 * dev network device
1209 * rxfid received FID
1210 * desc rx descriptor of the frame
1211 *
1212 * Call context: interrupt
1213 */
1214static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1215 struct hermes_rx_descriptor *desc)
1216{
1217 u32 hdrlen = 30; /* return full header by default */
1218 u32 datalen = 0;
1219 u16 fc;
1220 int err;
1221 int len;
1222 struct sk_buff *skb;
1223 struct orinoco_private *priv = netdev_priv(dev);
1224 struct net_device_stats *stats = &priv->stats;
1225 hermes_t *hw = &priv->hw;
1226
1227 len = le16_to_cpu(desc->data_len);
1228
1229 /* Determine the size of the header and the data */
1230 fc = le16_to_cpu(desc->frame_ctl);
1231 switch (fc & IEEE80211_FCTL_FTYPE) {
1232 case IEEE80211_FTYPE_DATA:
1233 if ((fc & IEEE80211_FCTL_TODS)
1234 && (fc & IEEE80211_FCTL_FROMDS))
1235 hdrlen = 30;
1236 else
1237 hdrlen = 24;
1238 datalen = len;
1239 break;
1240 case IEEE80211_FTYPE_MGMT:
1241 hdrlen = 24;
1242 datalen = len;
1243 break;
1244 case IEEE80211_FTYPE_CTL:
1245 switch (fc & IEEE80211_FCTL_STYPE) {
1246 case IEEE80211_STYPE_PSPOLL:
1247 case IEEE80211_STYPE_RTS:
1248 case IEEE80211_STYPE_CFEND:
1249 case IEEE80211_STYPE_CFENDACK:
1250 hdrlen = 16;
1251 break;
1252 case IEEE80211_STYPE_CTS:
1253 case IEEE80211_STYPE_ACK:
1254 hdrlen = 10;
1255 break;
1256 }
1257 break;
1258 default:
1259 /* Unknown frame type */
1260 break;
1261 }
1262
1263 /* sanity check the length */
Johannes Berg2c7060022008-10-30 22:09:54 +01001264 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001265 printk(KERN_DEBUG "%s: oversized monitor frame, "
1266 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001267 stats->rx_length_errors++;
1268 goto update_stats;
1269 }
1270
1271 skb = dev_alloc_skb(hdrlen + datalen);
1272 if (!skb) {
1273 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1274 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -07001275 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001276 }
1277
1278 /* Copy the 802.11 header to the skb */
1279 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001280 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001281
1282 /* If any, copy the data from the card to the skb */
1283 if (datalen > 0) {
1284 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1285 ALIGN(datalen, 2), rxfid,
1286 HERMES_802_2_OFFSET);
1287 if (err) {
1288 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1289 dev->name, err);
1290 goto drop;
1291 }
1292 }
1293
1294 skb->dev = dev;
1295 skb->ip_summed = CHECKSUM_NONE;
1296 skb->pkt_type = PACKET_OTHERHOST;
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001297 skb->protocol = cpu_to_be16(ETH_P_802_2);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001298
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001299 stats->rx_packets++;
1300 stats->rx_bytes += skb->len;
1301
1302 netif_rx(skb);
1303 return;
1304
1305 drop:
1306 dev_kfree_skb_irq(skb);
1307 update_stats:
1308 stats->rx_errors++;
1309 stats->rx_dropped++;
1310}
1311
David Kilroy23edcc42008-08-21 23:28:05 +01001312/* Get tsc from the firmware */
1313static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1314 u8 *tsc)
1315{
1316 hermes_t *hw = &priv->hw;
1317 int err = 0;
1318 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1319
1320 if ((key < 0) || (key > 4))
1321 return -EINVAL;
1322
1323 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1324 sizeof(tsc_arr), NULL, &tsc_arr);
1325 if (!err)
1326 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1327
1328 return err;
1329}
1330
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1332{
1333 struct orinoco_private *priv = netdev_priv(dev);
1334 struct net_device_stats *stats = &priv->stats;
1335 struct iw_statistics *wstats = &priv->wstats;
1336 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +01001337 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001338 int length;
David Kilroy31afcef2008-08-21 23:28:04 +01001339 struct hermes_rx_descriptor *desc;
1340 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 int err;
1342
David Kilroy31afcef2008-08-21 23:28:04 +01001343 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1344 if (!desc) {
1345 printk(KERN_WARNING
1346 "%s: Can't allocate space for RX descriptor\n",
1347 dev->name);
1348 goto update_stats;
1349 }
1350
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 rxfid = hermes_read_regn(hw, RXFID);
1352
David Kilroy31afcef2008-08-21 23:28:04 +01001353 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 rxfid, 0);
1355 if (err) {
1356 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1357 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001358 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360
David Kilroy31afcef2008-08-21 23:28:04 +01001361 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001363 if (status & HERMES_RXSTAT_BADCRC) {
1364 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1365 dev->name);
1366 stats->rx_crc_errors++;
1367 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001370 /* Handle frames in monitor mode */
1371 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +01001372 orinoco_rx_monitor(dev, rxfid, desc);
1373 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
1375
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001376 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1377 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1378 dev->name);
1379 wstats->discard.code++;
1380 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382
David Kilroy31afcef2008-08-21 23:28:04 +01001383 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /* Sanity checks */
1386 if (length < 3) { /* No for even an 802.2 LLC header */
1387 /* At least on Symbol firmware with PCF we get quite a
David Kilroy6fe9deb2009-02-04 23:05:43 +00001388 lot of these legitimately - Poll frames with no
1389 data. */
David Kilroy31afcef2008-08-21 23:28:04 +01001390 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
Johannes Berg2c7060022008-10-30 22:09:54 +01001392 if (length > IEEE80211_MAX_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1394 dev->name, length);
1395 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001396 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 }
1398
David Kilroy23edcc42008-08-21 23:28:05 +01001399 /* Payload size does not include Michael MIC. Increase payload
1400 * size to read it together with the data. */
1401 if (status & HERMES_RXSTAT_MIC)
1402 length += MICHAEL_MIC_LEN;
1403
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 /* We need space for the packet data itself, plus an ethernet
1405 header, plus 2 bytes so we can align the IP header on a
1406 32bit boundary, plus 1 byte so we can read in odd length
1407 packets from the card, which has an IO granularity of 16
David Kilroy6fe9deb2009-02-04 23:05:43 +00001408 bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1410 if (!skb) {
1411 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1412 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001413 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 }
1415
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001416 /* We'll prepend the header, so reserve space for it. The worst
1417 case is no decapsulation, when 802.3 header is prepended and
1418 nothing is removed. 2 is for aligning the IP header. */
1419 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001421 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1422 ALIGN(length, 2), rxfid,
1423 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 if (err) {
1425 printk(KERN_ERR "%s: error %d reading frame. "
1426 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 goto drop;
1428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
David Kilroy31afcef2008-08-21 23:28:04 +01001430 /* Add desc and skb to rx queue */
1431 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1432 if (!rx_data) {
1433 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1434 dev->name);
1435 goto drop;
1436 }
1437 rx_data->desc = desc;
1438 rx_data->skb = skb;
1439 list_add_tail(&rx_data->list, &priv->rx_list);
1440 tasklet_schedule(&priv->rx_tasklet);
1441
1442 return;
1443
1444drop:
1445 dev_kfree_skb_irq(skb);
1446update_stats:
1447 stats->rx_errors++;
1448 stats->rx_dropped++;
1449out:
1450 kfree(desc);
1451}
1452
1453static void orinoco_rx(struct net_device *dev,
1454 struct hermes_rx_descriptor *desc,
1455 struct sk_buff *skb)
1456{
1457 struct orinoco_private *priv = netdev_priv(dev);
1458 struct net_device_stats *stats = &priv->stats;
1459 u16 status, fc;
1460 int length;
1461 struct ethhdr *hdr;
1462
1463 status = le16_to_cpu(desc->status);
1464 length = le16_to_cpu(desc->data_len);
1465 fc = le16_to_cpu(desc->frame_ctl);
1466
David Kilroy23edcc42008-08-21 23:28:05 +01001467 /* Calculate and check MIC */
1468 if (status & HERMES_RXSTAT_MIC) {
1469 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1470 HERMES_MIC_KEY_ID_SHIFT);
1471 u8 mic[MICHAEL_MIC_LEN];
1472 u8 *rxmic;
1473 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1474 desc->addr3 : desc->addr2;
1475
1476 /* Extract Michael MIC from payload */
1477 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1478
1479 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1480 length -= MICHAEL_MIC_LEN;
1481
1482 michael_mic(priv->rx_tfm_mic,
1483 priv->tkip_key[key_id].rx_mic,
1484 desc->addr1,
1485 src,
1486 0, /* priority or QoS? */
1487 skb->data,
1488 skb->len,
1489 &mic[0]);
1490
1491 if (memcmp(mic, rxmic,
1492 MICHAEL_MIC_LEN)) {
1493 union iwreq_data wrqu;
1494 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +01001495
1496 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -07001497 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +01001498 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -07001499 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +01001500
1501 /* TODO: update stats */
1502
1503 /* Notify userspace */
1504 memset(&wxmic, 0, sizeof(wxmic));
1505 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1506 wxmic.flags |= (desc->addr1[0] & 1) ?
1507 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1508 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1509 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1510
1511 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1512 &wxmic.tsc[0]);
1513
1514 memset(&wrqu, 0, sizeof(wrqu));
1515 wrqu.data.length = sizeof(wxmic);
1516 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1517 (char *) &wxmic);
1518
1519 goto drop;
1520 }
1521 }
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 /* Handle decapsulation
1524 * In most cases, the firmware tell us about SNAP frames.
1525 * For some reason, the SNAP frames sent by LinkSys APs
1526 * are not properly recognised by most firmwares.
1527 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001528 if (length >= ENCAPS_OVERHEAD &&
1529 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1530 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1531 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 /* These indicate a SNAP within 802.2 LLC within
1533 802.11 frame which we'll need to de-encapsulate to
1534 the original EthernetII frame. */
David Kilroyb2f30a02009-02-04 23:05:46 +00001535 hdr = (struct ethhdr *)skb_push(skb,
1536 ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001538 /* 802.3 frame - prepend 802.3 header as is */
1539 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1540 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 }
David Kilroy31afcef2008-08-21 23:28:04 +01001542 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001543 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +01001544 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001545 else
David Kilroy31afcef2008-08-21 23:28:04 +01001546 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 skb->protocol = eth_type_trans(skb, dev);
1549 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001550 if (fc & IEEE80211_FCTL_TODS)
1551 skb->pkt_type = PACKET_OTHERHOST;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001552
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001554 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 /* Pass the packet to the networking stack */
1557 netif_rx(skb);
1558 stats->rx_packets++;
1559 stats->rx_bytes += length;
1560
1561 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001562
1563 drop:
1564 dev_kfree_skb(skb);
1565 stats->rx_errors++;
1566 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001567}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
David Kilroy31afcef2008-08-21 23:28:04 +01001569static void orinoco_rx_isr_tasklet(unsigned long data)
1570{
1571 struct net_device *dev = (struct net_device *) data;
1572 struct orinoco_private *priv = netdev_priv(dev);
1573 struct orinoco_rx_data *rx_data, *temp;
1574 struct hermes_rx_descriptor *desc;
1575 struct sk_buff *skb;
David Kilroy20953ad2009-01-07 00:23:55 +00001576 unsigned long flags;
1577
1578 /* orinoco_rx requires the driver lock, and we also need to
1579 * protect priv->rx_list, so just hold the lock over the
1580 * lot.
1581 *
1582 * If orinoco_lock fails, we've unplugged the card. In this
1583 * case just abort. */
1584 if (orinoco_lock(priv, &flags) != 0)
1585 return;
David Kilroy31afcef2008-08-21 23:28:04 +01001586
1587 /* extract desc and skb from queue */
1588 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1589 desc = rx_data->desc;
1590 skb = rx_data->skb;
1591 list_del(&rx_data->list);
1592 kfree(rx_data);
1593
1594 orinoco_rx(dev, desc, skb);
1595
1596 kfree(desc);
1597 }
David Kilroy20953ad2009-01-07 00:23:55 +00001598
1599 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600}
1601
1602/********************************************************************/
1603/* Rx path (info frames) */
1604/********************************************************************/
1605
1606static void print_linkstatus(struct net_device *dev, u16 status)
1607{
David Kilroy21312662009-02-04 23:05:47 +00001608 char *s;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 if (suppress_linkstatus)
1611 return;
1612
1613 switch (status) {
1614 case HERMES_LINKSTATUS_NOT_CONNECTED:
1615 s = "Not Connected";
1616 break;
1617 case HERMES_LINKSTATUS_CONNECTED:
1618 s = "Connected";
1619 break;
1620 case HERMES_LINKSTATUS_DISCONNECTED:
1621 s = "Disconnected";
1622 break;
1623 case HERMES_LINKSTATUS_AP_CHANGE:
1624 s = "AP Changed";
1625 break;
1626 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1627 s = "AP Out of Range";
1628 break;
1629 case HERMES_LINKSTATUS_AP_IN_RANGE:
1630 s = "AP In Range";
1631 break;
1632 case HERMES_LINKSTATUS_ASSOC_FAILED:
1633 s = "Association Failed";
1634 break;
1635 default:
1636 s = "UNKNOWN";
1637 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001638
Pavel Roskin11eaea42009-01-18 23:20:58 -05001639 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 dev->name, s, status);
1641}
1642
Christoph Hellwig16739b02005-06-19 01:27:51 +02001643/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001644static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001645{
David Howellsc4028952006-11-22 14:57:56 +00001646 struct orinoco_private *priv =
1647 container_of(work, struct orinoco_private, join_work);
1648 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001649 struct hermes *hw = &priv->hw;
1650 int err;
1651 unsigned long flags;
1652 struct join_req {
1653 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001654 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001655 } __attribute__ ((packed)) req;
1656 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001657 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001658 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001659 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001660 u8 *buf;
1661 u16 len;
1662
1663 /* Allocate buffer for scan results */
1664 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
David Kilroya94e8422009-02-04 23:05:44 +00001665 if (!buf)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001666 return;
1667
1668 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001669 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001670
1671 /* Sanity checks in case user changed something in the meantime */
David Kilroya94e8422009-02-04 23:05:44 +00001672 if (!priv->bssid_fixed)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001673 goto out;
1674
1675 if (strlen(priv->desired_essid) == 0)
1676 goto out;
1677
1678 /* Read scan results from the firmware */
1679 err = hermes_read_ltv(hw, USER_BAP,
1680 HERMES_RID_SCANRESULTSTABLE,
1681 MAX_SCAN_LEN, &len, buf);
1682 if (err) {
1683 printk(KERN_ERR "%s: Cannot read scan results\n",
1684 dev->name);
1685 goto out;
1686 }
1687
1688 len = HERMES_RECLEN_TO_BYTES(len);
1689
1690 /* Go through the scan results looking for the channel of the AP
1691 * we were requested to join */
1692 for (; offset + atom_len <= len; offset += atom_len) {
1693 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001694 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1695 found = 1;
1696 break;
1697 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001698 }
1699
David Kilroya94e8422009-02-04 23:05:44 +00001700 if (!found) {
Pavel Roskinc89cc222005-09-01 20:06:06 -04001701 DEBUG(1, "%s: Requested AP not found in scan results\n",
1702 dev->name);
1703 goto out;
1704 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001705
Christoph Hellwig16739b02005-06-19 01:27:51 +02001706 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1707 req.channel = atom->channel; /* both are little-endian */
1708 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1709 &req);
1710 if (err)
1711 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1712
1713 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001714 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001715
1716 fail_lock:
1717 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001718}
1719
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001720/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001721static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001722{
David Howellsc4028952006-11-22 14:57:56 +00001723 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001724 struct hermes *hw = &priv->hw;
1725 union iwreq_data wrqu;
1726 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001727
David Kilroy499b7022008-12-09 21:46:29 +00001728 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001729 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1730 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001731 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001732
1733 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1734
1735 /* Send event to user space */
1736 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001737}
1738
David Kilroy06009fd2008-08-21 23:28:03 +01001739static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1740{
1741 struct net_device *dev = priv->ndev;
1742 struct hermes *hw = &priv->hw;
1743 union iwreq_data wrqu;
1744 int err;
1745 u8 buf[88];
1746 u8 *ie;
1747
1748 if (!priv->has_wpa)
1749 return;
1750
David Kilroy499b7022008-12-09 21:46:29 +00001751 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001752 sizeof(buf), NULL, &buf);
1753 if (err != 0)
1754 return;
1755
1756 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1757 if (ie) {
1758 int rem = sizeof(buf) - (ie - &buf[0]);
1759 wrqu.data.length = ie[1] + 2;
1760 if (wrqu.data.length > rem)
1761 wrqu.data.length = rem;
1762
1763 if (wrqu.data.length)
1764 /* Send event to user space */
1765 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1766 }
1767}
1768
1769static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1770{
1771 struct net_device *dev = priv->ndev;
1772 struct hermes *hw = &priv->hw;
1773 union iwreq_data wrqu;
1774 int err;
1775 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1776 u8 *ie;
1777
1778 if (!priv->has_wpa)
1779 return;
1780
David Kilroy499b7022008-12-09 21:46:29 +00001781 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
David Kilroy06009fd2008-08-21 23:28:03 +01001782 sizeof(buf), NULL, &buf);
1783 if (err != 0)
1784 return;
1785
1786 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1787 if (ie) {
1788 int rem = sizeof(buf) - (ie - &buf[0]);
1789 wrqu.data.length = ie[1] + 2;
1790 if (wrqu.data.length > rem)
1791 wrqu.data.length = rem;
1792
1793 if (wrqu.data.length)
1794 /* Send event to user space */
1795 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1796 }
1797}
1798
David Kilroy6cd90b12008-08-21 23:28:00 +01001799static void orinoco_send_wevents(struct work_struct *work)
1800{
1801 struct orinoco_private *priv =
1802 container_of(work, struct orinoco_private, wevent_work);
1803 unsigned long flags;
1804
1805 if (orinoco_lock(priv, &flags) != 0)
1806 return;
1807
David Kilroy06009fd2008-08-21 23:28:03 +01001808 orinoco_send_assocreqie_wevent(priv);
1809 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001810 orinoco_send_bssid_wevent(priv);
1811
1812 orinoco_unlock(priv, &flags);
1813}
Dan Williams1e3428e2007-10-10 23:56:25 -04001814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1816{
1817 struct orinoco_private *priv = netdev_priv(dev);
1818 u16 infofid;
1819 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001820 __le16 len;
1821 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 } __attribute__ ((packed)) info;
1823 int len, type;
1824 int err;
1825
1826 /* This is an answer to an INQUIRE command that we did earlier,
1827 * or an information "event" generated by the card
1828 * The controller return to us a pseudo frame containing
1829 * the information in question - Jean II */
1830 infofid = hermes_read_regn(hw, INFOFID);
1831
1832 /* Read the info frame header - don't try too hard */
1833 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1834 infofid, 0);
1835 if (err) {
1836 printk(KERN_ERR "%s: error %d reading info frame. "
1837 "Frame dropped.\n", dev->name, err);
1838 return;
1839 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1842 type = le16_to_cpu(info.type);
1843
1844 switch (type) {
1845 case HERMES_INQ_TALLIES: {
1846 struct hermes_tallies_frame tallies;
1847 struct iw_statistics *wstats = &priv->wstats;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (len > sizeof(tallies)) {
1850 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1851 dev->name, len);
1852 len = sizeof(tallies);
1853 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00001854
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001855 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1856 infofid, sizeof(info));
1857 if (err)
1858 break;
David Kilroy6fe9deb2009-02-04 23:05:43 +00001859
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 /* Increment our various counters */
1861 /* wstats->discard.nwid - no wrong BSSID stuff */
1862 wstats->discard.code +=
1863 le16_to_cpu(tallies.RxWEPUndecryptable);
David Kilroy6fe9deb2009-02-04 23:05:43 +00001864 if (len == sizeof(tallies))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 wstats->discard.code +=
1866 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1867 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1868 wstats->discard.misc +=
1869 le16_to_cpu(tallies.TxDiscardsWrongSA);
1870 wstats->discard.fragment +=
1871 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1872 wstats->discard.retries +=
1873 le16_to_cpu(tallies.TxRetryLimitExceeded);
1874 /* wstats->miss.beacon - no match */
1875 }
1876 break;
1877 case HERMES_INQ_LINKSTATUS: {
1878 struct hermes_linkstatus linkstatus;
1879 u16 newstatus;
1880 int connected;
1881
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001882 if (priv->iw_mode == IW_MODE_MONITOR)
1883 break;
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 if (len != sizeof(linkstatus)) {
1886 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1887 dev->name, len);
1888 break;
1889 }
1890
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001891 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1892 infofid, sizeof(info));
1893 if (err)
1894 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 newstatus = le16_to_cpu(linkstatus.linkstatus);
1896
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001897 /* Symbol firmware uses "out of range" to signal that
1898 * the hostscan frame can be requested. */
1899 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1900 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1901 priv->has_hostscan && priv->scan_inprogress) {
1902 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1903 break;
1904 }
1905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1907 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1908 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1909
1910 if (connected)
1911 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001912 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 netif_carrier_off(dev);
1914
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001915 if (newstatus != priv->last_linkstatus) {
1916 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001918 /* The info frame contains only one word which is the
1919 * status (see hermes.h). The status is pretty boring
1920 * in itself, that's why we export the new BSSID...
1921 * Jean II */
1922 schedule_work(&priv->wevent_work);
1923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
1925 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001926 case HERMES_INQ_SCAN:
1927 if (!priv->scan_inprogress && priv->bssid_fixed &&
1928 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1929 schedule_work(&priv->join_work);
1930 break;
1931 }
1932 /* fall through */
1933 case HERMES_INQ_HOSTSCAN:
1934 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1935 /* Result of a scanning. Contains information about
1936 * cells in the vicinity - Jean II */
1937 union iwreq_data wrqu;
1938 unsigned char *buf;
1939
Dan Williams1e3428e2007-10-10 23:56:25 -04001940 /* Scan is no longer in progress */
1941 priv->scan_inprogress = 0;
1942
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001943 /* Sanity check */
1944 if (len > 4096) {
1945 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1946 dev->name, len);
1947 break;
1948 }
1949
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001950 /* Allocate buffer for results */
1951 buf = kmalloc(len, GFP_ATOMIC);
1952 if (buf == NULL)
1953 /* No memory, so can't printk()... */
1954 break;
1955
1956 /* Read scan data */
1957 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1958 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001959 if (err) {
1960 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001961 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001962 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001963
1964#ifdef ORINOCO_DEBUG
1965 {
1966 int i;
1967 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
David Kilroya94e8422009-02-04 23:05:44 +00001968 for (i = 1; i < (len * 2); i++)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001969 printk(":%02X", buf[i]);
1970 printk("]\n");
1971 }
1972#endif /* ORINOCO_DEBUG */
1973
David Kilroyaea48b12009-02-04 23:05:49 +00001974 if (orinoco_process_scan_results(priv, buf, len) == 0) {
Dan Williams1e3428e2007-10-10 23:56:25 -04001975 /* Send an empty event to user space.
1976 * We don't send the received data on the event because
1977 * it would require us to do complex transcoding, and
1978 * we want to minimise the work done in the irq handler
1979 * Use a request to extract the data - Jean II */
1980 wrqu.data.length = 0;
1981 wrqu.data.flags = 0;
1982 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1983 }
1984 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001985 }
1986 break;
David Kilroy01632fa2008-08-21 23:27:58 +01001987 case HERMES_INQ_CHANNELINFO:
1988 {
1989 struct agere_ext_scan_info *bss;
1990
1991 if (!priv->scan_inprogress) {
1992 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1993 "len=%d\n", dev->name, len);
1994 break;
1995 }
1996
1997 /* An empty result indicates that the scan is complete */
1998 if (len == 0) {
1999 union iwreq_data wrqu;
2000
2001 /* Scan is no longer in progress */
2002 priv->scan_inprogress = 0;
2003
2004 wrqu.data.length = 0;
2005 wrqu.data.flags = 0;
2006 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2007 break;
2008 }
2009
2010 /* Sanity check */
2011 else if (len > sizeof(*bss)) {
2012 printk(KERN_WARNING
2013 "%s: Ext scan results too large (%d bytes). "
2014 "Truncating results to %zd bytes.\n",
2015 dev->name, len, sizeof(*bss));
2016 len = sizeof(*bss);
2017 } else if (len < (offsetof(struct agere_ext_scan_info,
2018 data) + 2)) {
2019 /* Drop this result now so we don't have to
2020 * keep checking later */
2021 printk(KERN_WARNING
2022 "%s: Ext scan results too short (%d bytes)\n",
2023 dev->name, len);
2024 break;
2025 }
2026
2027 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
2028 if (bss == NULL)
2029 break;
2030
2031 /* Read scan data */
2032 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
2033 infofid, sizeof(info));
2034 if (err) {
2035 kfree(bss);
2036 break;
2037 }
2038
2039 orinoco_add_ext_scan_result(priv, bss);
2040
2041 kfree(bss);
2042 break;
2043 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002044 case HERMES_INQ_SEC_STAT_AGERE:
2045 /* Security status (Agere specific) */
2046 /* Ignore this frame for now */
2047 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2048 break;
2049 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 default:
2051 printk(KERN_DEBUG "%s: Unknown information frame received: "
2052 "type 0x%04x, length %d\n", dev->name, type, len);
2053 /* We don't actually do anything about it */
2054 break;
2055 }
2056}
2057
2058static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
2059{
2060 if (net_ratelimit())
2061 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
2062}
2063
2064/********************************************************************/
2065/* Internal hardware control routines */
2066/********************************************************************/
2067
2068int __orinoco_up(struct net_device *dev)
2069{
2070 struct orinoco_private *priv = netdev_priv(dev);
2071 struct hermes *hw = &priv->hw;
2072 int err;
2073
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002074 netif_carrier_off(dev); /* just to make sure */
2075
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 err = __orinoco_program_rids(dev);
2077 if (err) {
2078 printk(KERN_ERR "%s: Error %d configuring card\n",
2079 dev->name, err);
2080 return err;
2081 }
2082
2083 /* Fire things up again */
2084 hermes_set_irqmask(hw, ORINOCO_INTEN);
2085 err = hermes_enable_port(hw, 0);
2086 if (err) {
2087 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2088 dev->name, err);
2089 return err;
2090 }
2091
2092 netif_start_queue(dev);
2093
2094 return 0;
2095}
David Kilroy21312662009-02-04 23:05:47 +00002096EXPORT_SYMBOL(__orinoco_up);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098int __orinoco_down(struct net_device *dev)
2099{
2100 struct orinoco_private *priv = netdev_priv(dev);
2101 struct hermes *hw = &priv->hw;
2102 int err;
2103
2104 netif_stop_queue(dev);
2105
David Kilroya94e8422009-02-04 23:05:44 +00002106 if (!priv->hw_unavailable) {
2107 if (!priv->broken_disableport) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 err = hermes_disable_port(hw, 0);
2109 if (err) {
2110 /* Some firmwares (e.g. Intersil 1.3.x) seem
2111 * to have problems disabling the port, oh
2112 * well, too bad. */
2113 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2114 dev->name, err);
2115 priv->broken_disableport = 1;
2116 }
2117 }
2118 hermes_set_irqmask(hw, 0);
2119 hermes_write_regn(hw, EVACK, 0xffff);
2120 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 /* firmware will have to reassociate */
2123 netif_carrier_off(dev);
2124 priv->last_linkstatus = 0xffff;
2125
2126 return 0;
2127}
David Kilroy21312662009-02-04 23:05:47 +00002128EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Pavel Roskin37a6c612006-04-07 04:10:49 -04002130static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
2132 struct orinoco_private *priv = netdev_priv(dev);
2133 struct hermes *hw = &priv->hw;
2134 int err;
2135
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04002137 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 /* Try workaround for old Symbol firmware bug */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2140 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Kilroy21312662009-02-04 23:05:47 +00002141
2142 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2143 "(old Symbol firmware?). Work around %s\n",
2144 dev->name, err ? "failed!" : "ok.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 }
2146
2147 return err;
2148}
2149
Pavel Roskin37a6c612006-04-07 04:10:49 -04002150int orinoco_reinit_firmware(struct net_device *dev)
2151{
2152 struct orinoco_private *priv = netdev_priv(dev);
2153 struct hermes *hw = &priv->hw;
2154 int err;
2155
2156 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04002157 if (priv->do_fw_download && !err) {
2158 err = orinoco_download(priv);
2159 if (err)
2160 priv->do_fw_download = 0;
2161 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04002162 if (!err)
2163 err = orinoco_allocate_fid(dev);
2164
2165 return err;
2166}
David Kilroy21312662009-02-04 23:05:47 +00002167EXPORT_SYMBOL(orinoco_reinit_firmware);
Pavel Roskin37a6c612006-04-07 04:10:49 -04002168
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2170{
2171 hermes_t *hw = &priv->hw;
David Kilroyb2f30a02009-02-04 23:05:46 +00002172 int ratemode = priv->bitratemode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 int err = 0;
2174
David Kilroyb2f30a02009-02-04 23:05:46 +00002175 if (ratemode >= BITRATE_TABLE_SIZE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
David Kilroyb2f30a02009-02-04 23:05:46 +00002177 priv->ndev->name, ratemode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 return -EINVAL;
2179 }
2180
2181 switch (priv->firmware_type) {
2182 case FIRMWARE_TYPE_AGERE:
2183 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002184 HERMES_RID_CNFTXRATECONTROL,
2185 bitrate_table[ratemode].agere_txratectrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 break;
2187 case FIRMWARE_TYPE_INTERSIL:
2188 case FIRMWARE_TYPE_SYMBOL:
2189 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002190 HERMES_RID_CNFTXRATECONTROL,
2191 bitrate_table[ratemode].intersil_txratectrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 break;
2193 default:
2194 BUG();
2195 }
2196
2197 return err;
2198}
2199
Christoph Hellwig16739b02005-06-19 01:27:51 +02002200/* Set fixed AP address */
2201static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2202{
2203 int roaming_flag;
2204 int err = 0;
2205 hermes_t *hw = &priv->hw;
2206
2207 switch (priv->firmware_type) {
2208 case FIRMWARE_TYPE_AGERE:
2209 /* not supported */
2210 break;
2211 case FIRMWARE_TYPE_INTERSIL:
2212 if (priv->bssid_fixed)
2213 roaming_flag = 2;
2214 else
2215 roaming_flag = 1;
2216
2217 err = hermes_write_wordrec(hw, USER_BAP,
2218 HERMES_RID_CNFROAMINGMODE,
2219 roaming_flag);
2220 break;
2221 case FIRMWARE_TYPE_SYMBOL:
2222 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2223 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2224 &priv->desired_bssid);
2225 break;
2226 }
2227 return err;
2228}
2229
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230/* Change the WEP keys and/or the current keys. Can be called
David Kilroyd03032a2008-08-21 23:28:02 +01002231 * either from __orinoco_hw_setup_enc() or directly from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 * orinoco_ioctl_setiwencode(). In the later case the association
2233 * with the AP is not broken (if the firmware can handle it),
2234 * which is needed for 802.1x implementations. */
2235static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2236{
2237 hermes_t *hw = &priv->hw;
2238 int err = 0;
2239
2240 switch (priv->firmware_type) {
2241 case FIRMWARE_TYPE_AGERE:
2242 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2243 HERMES_RID_CNFWEPKEYS_AGERE,
2244 &priv->keys);
2245 if (err)
2246 return err;
2247 err = hermes_write_wordrec(hw, USER_BAP,
2248 HERMES_RID_CNFTXKEY_AGERE,
2249 priv->tx_key);
2250 if (err)
2251 return err;
2252 break;
2253 case FIRMWARE_TYPE_INTERSIL:
2254 case FIRMWARE_TYPE_SYMBOL:
2255 {
2256 int keylen;
2257 int i;
2258
David Kilroyb2f30a02009-02-04 23:05:46 +00002259 /* Force uniform key length to work around
2260 * firmware bugs */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 if (keylen > LARGE_KEY_SIZE) {
2264 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2265 priv->ndev->name, priv->tx_key, keylen);
2266 return -E2BIG;
2267 }
2268
2269 /* Write all 4 keys */
David Kilroya94e8422009-02-04 23:05:44 +00002270 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 err = hermes_write_ltv(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002272 HERMES_RID_CNFDEFAULTKEY0 + i,
2273 HERMES_BYTES_TO_RECLEN(keylen),
2274 priv->keys[i].data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 if (err)
2276 return err;
2277 }
2278
2279 /* Write the index of the key used in transmission */
2280 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002281 HERMES_RID_CNFWEPDEFAULTKEYID,
2282 priv->tx_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 if (err)
2284 return err;
2285 }
2286 break;
2287 }
2288
2289 return 0;
2290}
2291
David Kilroyd03032a2008-08-21 23:28:02 +01002292static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293{
2294 hermes_t *hw = &priv->hw;
2295 int err = 0;
2296 int master_wep_flag;
2297 int auth_flag;
David Kilroy4ae6ee22008-08-21 23:27:59 +01002298 int enc_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299
David Kilroyd03032a2008-08-21 23:28:02 +01002300 /* Setup WEP keys for WEP and WPA */
2301 if (priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 __orinoco_hw_setup_wepkeys(priv);
2303
2304 if (priv->wep_restrict)
2305 auth_flag = HERMES_AUTH_SHARED_KEY;
2306 else
2307 auth_flag = HERMES_AUTH_OPEN;
2308
David Kilroyd03032a2008-08-21 23:28:02 +01002309 if (priv->wpa_enabled)
2310 enc_flag = 2;
2311 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
David Kilroy4ae6ee22008-08-21 23:27:59 +01002312 enc_flag = 1;
2313 else
2314 enc_flag = 0;
2315
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 switch (priv->firmware_type) {
2317 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002318 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 /* Enable the shared-key authentication. */
2320 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00002321 HERMES_RID_CNFAUTHENTICATION_AGERE,
2322 auth_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 }
2324 err = hermes_write_wordrec(hw, USER_BAP,
2325 HERMES_RID_CNFWEPENABLED_AGERE,
David Kilroy4ae6ee22008-08-21 23:27:59 +01002326 enc_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 if (err)
2328 return err;
David Kilroyd03032a2008-08-21 23:28:02 +01002329
2330 if (priv->has_wpa) {
2331 /* Set WPA key management */
2332 err = hermes_write_wordrec(hw, USER_BAP,
2333 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2334 priv->key_mgmt);
2335 if (err)
2336 return err;
2337 }
2338
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 break;
2340
2341 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2342 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002343 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 if (priv->wep_restrict ||
2345 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2346 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2347 HERMES_WEP_EXCL_UNENCRYPTED;
2348 else
2349 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2350
2351 err = hermes_write_wordrec(hw, USER_BAP,
2352 HERMES_RID_CNFAUTHENTICATION,
2353 auth_flag);
2354 if (err)
2355 return err;
2356 } else
2357 master_wep_flag = 0;
2358
2359 if (priv->iw_mode == IW_MODE_MONITOR)
2360 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2361
2362 /* Master WEP setting : on/off */
2363 err = hermes_write_wordrec(hw, USER_BAP,
2364 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2365 master_wep_flag);
2366 if (err)
David Kilroy6fe9deb2009-02-04 23:05:43 +00002367 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369 break;
2370 }
2371
2372 return 0;
2373}
2374
David Kilroyd03032a2008-08-21 23:28:02 +01002375/* key must be 32 bytes, including the tx and rx MIC keys.
2376 * rsc must be 8 bytes
2377 * tsc must be 8 bytes or NULL
2378 */
2379static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2380 u8 *key, u8 *rsc, u8 *tsc)
2381{
2382 struct {
2383 __le16 idx;
2384 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2385 u8 key[TKIP_KEYLEN];
2386 u8 tx_mic[MIC_KEYLEN];
2387 u8 rx_mic[MIC_KEYLEN];
2388 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2389 } __attribute__ ((packed)) buf;
2390 int ret;
2391 int err;
2392 int k;
2393 u16 xmitting;
2394
2395 key_idx &= 0x3;
2396
2397 if (set_tx)
2398 key_idx |= 0x8000;
2399
2400 buf.idx = cpu_to_le16(key_idx);
2401 memcpy(buf.key, key,
2402 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2403
2404 if (rsc == NULL)
2405 memset(buf.rsc, 0, sizeof(buf.rsc));
2406 else
2407 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2408
2409 if (tsc == NULL) {
2410 memset(buf.tsc, 0, sizeof(buf.tsc));
2411 buf.tsc[4] = 0x10;
2412 } else {
2413 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2414 }
2415
2416 /* Wait upto 100ms for tx queue to empty */
2417 k = 100;
2418 do {
2419 k--;
2420 udelay(1000);
2421 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2422 &xmitting);
2423 if (ret)
2424 break;
2425 } while ((k > 0) && xmitting);
2426
2427 if (k == 0)
2428 ret = -ETIMEDOUT;
2429
2430 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2431 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2432 &buf);
2433
2434 return ret ? ret : err;
2435}
2436
2437static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2438 int key_idx)
2439{
2440 hermes_t *hw = &priv->hw;
2441 int err;
2442
2443 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2444 err = hermes_write_wordrec(hw, USER_BAP,
2445 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2446 key_idx);
2447 if (err)
2448 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2449 priv->ndev->name, err, key_idx);
2450 return err;
2451}
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453static int __orinoco_program_rids(struct net_device *dev)
2454{
2455 struct orinoco_private *priv = netdev_priv(dev);
2456 hermes_t *hw = &priv->hw;
2457 int err;
2458 struct hermes_idstring idbuf;
2459
2460 /* Set the MAC address */
2461 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2462 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2463 if (err) {
2464 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2465 dev->name, err);
2466 return err;
2467 }
2468
2469 /* Set up the link mode */
2470 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2471 priv->port_type);
2472 if (err) {
2473 printk(KERN_ERR "%s: Error %d setting port type\n",
2474 dev->name, err);
2475 return err;
2476 }
2477 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04002478 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2479 err = hermes_write_wordrec(hw, USER_BAP,
2480 HERMES_RID_CNFOWNCHANNEL,
2481 priv->channel);
2482 if (err) {
2483 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2484 dev->name, err, priv->channel);
2485 return err;
2486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 }
2488
2489 if (priv->has_ibss) {
2490 u16 createibss;
2491
2492 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2493 printk(KERN_WARNING "%s: This firmware requires an "
2494 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2495 /* With wvlan_cs, in this case, we would crash.
2496 * hopefully, this driver will behave better...
2497 * Jean II */
2498 createibss = 0;
2499 } else {
2500 createibss = priv->createibss;
2501 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002502
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 err = hermes_write_wordrec(hw, USER_BAP,
2504 HERMES_RID_CNFCREATEIBSS,
2505 createibss);
2506 if (err) {
2507 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2508 dev->name, err);
2509 return err;
2510 }
2511 }
2512
Christoph Hellwig16739b02005-06-19 01:27:51 +02002513 /* Set the desired BSSID */
2514 err = __orinoco_hw_set_wap(priv);
2515 if (err) {
2516 printk(KERN_ERR "%s: Error %d setting AP address\n",
2517 dev->name, err);
2518 return err;
2519 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 /* Set the desired ESSID */
2521 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2522 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2523 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2524 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00002525 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2526 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 if (err) {
2528 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2529 dev->name, err);
2530 return err;
2531 }
2532 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
David Kilroyb2f30a02009-02-04 23:05:46 +00002533 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2534 &idbuf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 if (err) {
2536 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2537 dev->name, err);
2538 return err;
2539 }
2540
2541 /* Set the station name */
2542 idbuf.len = cpu_to_le16(strlen(priv->nick));
2543 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2544 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2545 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2546 &idbuf);
2547 if (err) {
2548 printk(KERN_ERR "%s: Error %d setting nickname\n",
2549 dev->name, err);
2550 return err;
2551 }
2552
2553 /* Set AP density */
2554 if (priv->has_sensitivity) {
2555 err = hermes_write_wordrec(hw, USER_BAP,
2556 HERMES_RID_CNFSYSTEMSCALE,
2557 priv->ap_density);
2558 if (err) {
David Kilroyb2f30a02009-02-04 23:05:46 +00002559 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 "Disabling sensitivity control\n",
2561 dev->name, err);
2562
2563 priv->has_sensitivity = 0;
2564 }
2565 }
2566
2567 /* Set RTS threshold */
2568 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2569 priv->rts_thresh);
2570 if (err) {
2571 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2572 dev->name, err);
2573 return err;
2574 }
2575
2576 /* Set fragmentation threshold or MWO robustness */
2577 if (priv->has_mwo)
2578 err = hermes_write_wordrec(hw, USER_BAP,
2579 HERMES_RID_CNFMWOROBUST_AGERE,
2580 priv->mwo_robust);
2581 else
2582 err = hermes_write_wordrec(hw, USER_BAP,
2583 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2584 priv->frag_thresh);
2585 if (err) {
2586 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2587 dev->name, err);
2588 return err;
2589 }
2590
2591 /* Set bitrate */
2592 err = __orinoco_hw_set_bitrate(priv);
2593 if (err) {
2594 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2595 dev->name, err);
2596 return err;
2597 }
2598
2599 /* Set power management */
2600 if (priv->has_pm) {
2601 err = hermes_write_wordrec(hw, USER_BAP,
2602 HERMES_RID_CNFPMENABLED,
2603 priv->pm_on);
2604 if (err) {
2605 printk(KERN_ERR "%s: Error %d setting up PM\n",
2606 dev->name, err);
2607 return err;
2608 }
2609
2610 err = hermes_write_wordrec(hw, USER_BAP,
2611 HERMES_RID_CNFMULTICASTRECEIVE,
2612 priv->pm_mcast);
2613 if (err) {
2614 printk(KERN_ERR "%s: Error %d setting up PM\n",
2615 dev->name, err);
2616 return err;
2617 }
2618 err = hermes_write_wordrec(hw, USER_BAP,
2619 HERMES_RID_CNFMAXSLEEPDURATION,
2620 priv->pm_period);
2621 if (err) {
2622 printk(KERN_ERR "%s: Error %d setting up PM\n",
2623 dev->name, err);
2624 return err;
2625 }
2626 err = hermes_write_wordrec(hw, USER_BAP,
2627 HERMES_RID_CNFPMHOLDOVERDURATION,
2628 priv->pm_timeout);
2629 if (err) {
2630 printk(KERN_ERR "%s: Error %d setting up PM\n",
2631 dev->name, err);
2632 return err;
2633 }
2634 }
2635
2636 /* Set preamble - only for Symbol so far... */
2637 if (priv->has_preamble) {
2638 err = hermes_write_wordrec(hw, USER_BAP,
2639 HERMES_RID_CNFPREAMBLE_SYMBOL,
2640 priv->preamble);
2641 if (err) {
2642 printk(KERN_ERR "%s: Error %d setting preamble\n",
2643 dev->name, err);
2644 return err;
2645 }
2646 }
2647
2648 /* Set up encryption */
David Kilroyd03032a2008-08-21 23:28:02 +01002649 if (priv->has_wep || priv->has_wpa) {
2650 err = __orinoco_hw_setup_enc(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 if (err) {
David Kilroyd03032a2008-08-21 23:28:02 +01002652 printk(KERN_ERR "%s: Error %d activating encryption\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 dev->name, err);
2654 return err;
2655 }
2656 }
2657
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002658 if (priv->iw_mode == IW_MODE_MONITOR) {
2659 /* Enable monitor mode */
2660 dev->type = ARPHRD_IEEE80211;
David Kilroy6fe9deb2009-02-04 23:05:43 +00002661 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002662 HERMES_TEST_MONITOR, 0, NULL);
2663 } else {
2664 /* Disable monitor mode */
2665 dev->type = ARPHRD_ETHER;
2666 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2667 HERMES_TEST_STOP, 0, NULL);
2668 }
2669 if (err)
2670 return err;
2671
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 /* Set promiscuity / multicast*/
2673 priv->promiscuous = 0;
2674 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07002675
2676 /* FIXME: what about netif_tx_lock */
2677 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
2679 return 0;
2680}
2681
2682/* FIXME: return int? */
2683static void
2684__orinoco_set_multicast_list(struct net_device *dev)
2685{
2686 struct orinoco_private *priv = netdev_priv(dev);
2687 hermes_t *hw = &priv->hw;
2688 int err = 0;
2689 int promisc, mc_count;
2690
2691 /* The Hermes doesn't seem to have an allmulti mode, so we go
2692 * into promiscuous mode and let the upper levels deal. */
David Kilroya94e8422009-02-04 23:05:44 +00002693 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2694 (dev->mc_count > MAX_MULTICAST(priv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 promisc = 1;
2696 mc_count = 0;
2697 } else {
2698 promisc = 0;
2699 mc_count = dev->mc_count;
2700 }
2701
2702 if (promisc != priv->promiscuous) {
2703 err = hermes_write_wordrec(hw, USER_BAP,
2704 HERMES_RID_CNFPROMISCUOUSMODE,
2705 promisc);
2706 if (err) {
2707 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2708 dev->name, err);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002709 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 priv->promiscuous = promisc;
2711 }
2712
David Kilroy667d4102008-08-23 19:03:34 +01002713 /* If we're not in promiscuous mode, then we need to set the
2714 * group address if either we want to multicast, or if we were
2715 * multicasting and want to stop */
David Kilroya94e8422009-02-04 23:05:44 +00002716 if (!promisc && (mc_count || priv->mc_count)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 struct dev_mc_list *p = dev->mc_list;
2718 struct hermes_multicast mclist;
2719 int i;
2720
2721 for (i = 0; i < mc_count; i++) {
2722 /* paranoia: is list shorter than mc_count? */
David Kilroya94e8422009-02-04 23:05:44 +00002723 BUG_ON(!p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 /* paranoia: bad address size in list? */
2725 BUG_ON(p->dmi_addrlen != ETH_ALEN);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002726
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2728 p = p->next;
2729 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002730
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 if (p)
2732 printk(KERN_WARNING "%s: Multicast list is "
2733 "longer than mc_count\n", dev->name);
2734
David Kilroy667d4102008-08-23 19:03:34 +01002735 err = hermes_write_ltv(hw, USER_BAP,
2736 HERMES_RID_CNFGROUPADDRESSES,
2737 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2738 &mclist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 if (err)
2740 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2741 dev->name, err);
2742 else
2743 priv->mc_count = mc_count;
2744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745}
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747/* This must be called from user context, without locks held - use
2748 * schedule_work() */
David Howellsc4028952006-11-22 14:57:56 +00002749static void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750{
David Howellsc4028952006-11-22 14:57:56 +00002751 struct orinoco_private *priv =
2752 container_of(work, struct orinoco_private, reset_work);
2753 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002755 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 unsigned long flags;
2757
2758 if (orinoco_lock(priv, &flags) != 0)
2759 /* When the hardware becomes available again, whatever
2760 * detects that is responsible for re-initializing
2761 * it. So no need for anything further */
2762 return;
2763
2764 netif_stop_queue(dev);
2765
2766 /* Shut off interrupts. Depending on what state the hardware
2767 * is in, this might not work, but we'll try anyway */
2768 hermes_set_irqmask(hw, 0);
2769 hermes_write_regn(hw, EVACK, 0xffff);
2770
2771 priv->hw_unavailable++;
2772 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2773 netif_carrier_off(dev);
2774
2775 orinoco_unlock(priv, &flags);
2776
David Kilroy6fe9deb2009-02-04 23:05:43 +00002777 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04002778 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002779 priv->scan_inprogress = 0;
2780
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002781 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002783 if (err) {
2784 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2785 "performing hard reset\n", dev->name, err);
2786 goto disable;
2787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 }
2789
2790 err = orinoco_reinit_firmware(dev);
2791 if (err) {
2792 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2793 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002794 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
2796
David Kilroyb2f30a02009-02-04 23:05:46 +00002797 /* This has to be called from user context */
2798 spin_lock_irq(&priv->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799
2800 priv->hw_unavailable--;
2801
2802 /* priv->open or priv->hw_unavailable might have changed while
2803 * we dropped the lock */
David Kilroya94e8422009-02-04 23:05:44 +00002804 if (priv->open && (!priv->hw_unavailable)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 err = __orinoco_up(dev);
2806 if (err) {
2807 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2808 dev->name, err);
2809 } else
2810 dev->trans_start = jiffies;
2811 }
2812
2813 spin_unlock_irq(&priv->lock);
2814
2815 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002816 disable:
2817 hermes_set_irqmask(hw, 0);
2818 netif_device_detach(dev);
2819 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820}
2821
2822/********************************************************************/
2823/* Interrupt handler */
2824/********************************************************************/
2825
2826static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2827{
2828 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2829}
2830
2831static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2832{
2833 /* This seems to happen a fair bit under load, but ignoring it
2834 seems to work fine...*/
2835 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2836 dev->name);
2837}
2838
David Howells7d12e782006-10-05 14:55:46 +01002839irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04002841 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 struct orinoco_private *priv = netdev_priv(dev);
2843 hermes_t *hw = &priv->hw;
2844 int count = MAX_IRQLOOPS_PER_IRQ;
2845 u16 evstat, events;
David Kilroy21312662009-02-04 23:05:47 +00002846 /* These are used to detect a runaway interrupt situation.
2847 *
2848 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2849 * we panic and shut down the hardware
2850 */
2851 /* jiffies value the last time we were called */
2852 static int last_irq_jiffy; /* = 0 */
2853 static int loops_this_jiffy; /* = 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 unsigned long flags;
2855
2856 if (orinoco_lock(priv, &flags) != 0) {
2857 /* If hw is unavailable - we don't know if the irq was
2858 * for us or not */
2859 return IRQ_HANDLED;
2860 }
2861
2862 evstat = hermes_read_regn(hw, EVSTAT);
2863 events = evstat & hw->inten;
David Kilroya94e8422009-02-04 23:05:44 +00002864 if (!events) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 orinoco_unlock(priv, &flags);
2866 return IRQ_NONE;
2867 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00002868
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 if (jiffies != last_irq_jiffy)
2870 loops_this_jiffy = 0;
2871 last_irq_jiffy = jiffies;
2872
2873 while (events && count--) {
2874 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2875 printk(KERN_WARNING "%s: IRQ handler is looping too "
2876 "much! Resetting.\n", dev->name);
2877 /* Disable interrupts for now */
2878 hermes_set_irqmask(hw, 0);
2879 schedule_work(&priv->reset_work);
2880 break;
2881 }
2882
2883 /* Check the card hasn't been removed */
David Kilroya94e8422009-02-04 23:05:44 +00002884 if (!hermes_present(hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 DEBUG(0, "orinoco_interrupt(): card removed\n");
2886 break;
2887 }
2888
2889 if (events & HERMES_EV_TICK)
2890 __orinoco_ev_tick(dev, hw);
2891 if (events & HERMES_EV_WTERR)
2892 __orinoco_ev_wterr(dev, hw);
2893 if (events & HERMES_EV_INFDROP)
2894 __orinoco_ev_infdrop(dev, hw);
2895 if (events & HERMES_EV_INFO)
2896 __orinoco_ev_info(dev, hw);
2897 if (events & HERMES_EV_RX)
2898 __orinoco_ev_rx(dev, hw);
2899 if (events & HERMES_EV_TXEXC)
2900 __orinoco_ev_txexc(dev, hw);
2901 if (events & HERMES_EV_TX)
2902 __orinoco_ev_tx(dev, hw);
2903 if (events & HERMES_EV_ALLOC)
2904 __orinoco_ev_alloc(dev, hw);
David Kilroy6fe9deb2009-02-04 23:05:43 +00002905
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002906 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907
2908 evstat = hermes_read_regn(hw, EVSTAT);
2909 events = evstat & hw->inten;
2910 };
2911
2912 orinoco_unlock(priv, &flags);
2913 return IRQ_HANDLED;
2914}
David Kilroy21312662009-02-04 23:05:47 +00002915EXPORT_SYMBOL(orinoco_interrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
2917/********************************************************************/
David Kilroy39d1ffe2008-11-22 10:37:28 +00002918/* Power management */
2919/********************************************************************/
2920#if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2921static int orinoco_pm_notifier(struct notifier_block *notifier,
2922 unsigned long pm_event,
2923 void *unused)
2924{
2925 struct orinoco_private *priv = container_of(notifier,
2926 struct orinoco_private,
2927 pm_notifier);
2928
2929 /* All we need to do is cache the firmware before suspend, and
2930 * release it when we come out.
2931 *
2932 * Only need to do this if we're downloading firmware. */
2933 if (!priv->do_fw_download)
2934 return NOTIFY_DONE;
2935
2936 switch (pm_event) {
2937 case PM_HIBERNATION_PREPARE:
2938 case PM_SUSPEND_PREPARE:
2939 orinoco_cache_fw(priv, 0);
2940 break;
2941
2942 case PM_POST_RESTORE:
2943 /* Restore from hibernation failed. We need to clean
2944 * up in exactly the same way, so fall through. */
2945 case PM_POST_HIBERNATION:
2946 case PM_POST_SUSPEND:
2947 orinoco_uncache_fw(priv);
2948 break;
2949
2950 case PM_RESTORE_PREPARE:
2951 default:
2952 break;
2953 }
2954
2955 return NOTIFY_DONE;
2956}
2957#else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2958#define orinoco_pm_notifier NULL
2959#endif
2960
2961/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962/* Initialization */
2963/********************************************************************/
2964
2965struct comp_id {
2966 u16 id, variant, major, minor;
2967} __attribute__ ((packed));
2968
2969static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2970{
2971 if (nic_id->id < 0x8000)
2972 return FIRMWARE_TYPE_AGERE;
2973 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2974 return FIRMWARE_TYPE_SYMBOL;
2975 else
2976 return FIRMWARE_TYPE_INTERSIL;
2977}
2978
2979/* Set priv->firmware type, determine firmware properties */
2980static int determine_firmware(struct net_device *dev)
2981{
2982 struct orinoco_private *priv = netdev_priv(dev);
2983 hermes_t *hw = &priv->hw;
2984 int err;
2985 struct comp_id nic_id, sta_id;
2986 unsigned int firmver;
Hennerich, Michaeldde6d432007-02-05 16:41:35 -08002987 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
2989 /* Get the hardware version */
2990 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2991 if (err) {
2992 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2993 dev->name, err);
2994 return err;
2995 }
2996
2997 le16_to_cpus(&nic_id.id);
2998 le16_to_cpus(&nic_id.variant);
2999 le16_to_cpus(&nic_id.major);
3000 le16_to_cpus(&nic_id.minor);
3001 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
3002 dev->name, nic_id.id, nic_id.variant,
3003 nic_id.major, nic_id.minor);
3004
3005 priv->firmware_type = determine_firmware_type(&nic_id);
3006
3007 /* Get the firmware version */
3008 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
3009 if (err) {
3010 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
3011 dev->name, err);
3012 return err;
3013 }
3014
3015 le16_to_cpus(&sta_id.id);
3016 le16_to_cpus(&sta_id.variant);
3017 le16_to_cpus(&sta_id.major);
3018 le16_to_cpus(&sta_id.minor);
3019 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
3020 dev->name, sta_id.id, sta_id.variant,
3021 sta_id.major, sta_id.minor);
3022
3023 switch (sta_id.id) {
3024 case 0x15:
3025 printk(KERN_ERR "%s: Primary firmware is active\n",
3026 dev->name);
3027 return -ENODEV;
3028 case 0x14b:
3029 printk(KERN_ERR "%s: Tertiary firmware is active\n",
3030 dev->name);
3031 return -ENODEV;
3032 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3033 case 0x21: /* Symbol Spectrum24 Trilogy */
3034 break;
3035 default:
3036 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
3037 dev->name);
3038 break;
3039 }
3040
3041 /* Default capabilities */
3042 priv->has_sensitivity = 1;
3043 priv->has_mwo = 0;
3044 priv->has_preamble = 0;
3045 priv->has_port3 = 1;
3046 priv->has_ibss = 1;
3047 priv->has_wep = 0;
3048 priv->has_big_wep = 0;
David Kilroy6eecad72008-08-21 23:27:56 +01003049 priv->has_alt_txcntl = 0;
David Kilroy01632fa2008-08-21 23:27:58 +01003050 priv->has_ext_scan = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01003051 priv->has_wpa = 0;
David Kilroy3994d502008-08-21 23:27:54 +01003052 priv->do_fw_download = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053
3054 /* Determine capabilities from the firmware version */
3055 switch (priv->firmware_type) {
3056 case FIRMWARE_TYPE_AGERE:
3057 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3058 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3059 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3060 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
3061
3062 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
3063
3064 priv->has_ibss = (firmver >= 0x60006);
3065 priv->has_wep = (firmver >= 0x40020);
3066 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
3067 Gold cards from the others? */
3068 priv->has_mwo = (firmver >= 0x60000);
3069 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3070 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003071 priv->has_hostscan = (firmver >= 0x8000a);
David Kilroy3994d502008-08-21 23:27:54 +01003072 priv->do_fw_download = 1;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003073 priv->broken_monitor = (firmver >= 0x80000);
David Kilroy6eecad72008-08-21 23:27:56 +01003074 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
David Kilroy01632fa2008-08-21 23:27:58 +01003075 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
David Kilroyd03032a2008-08-21 23:28:02 +01003076 priv->has_wpa = (firmver >= 0x9002a);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 /* Tested with Agere firmware :
3078 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3079 * Tested CableTron firmware : 4.32 => Anton */
3080 break;
3081 case FIRMWARE_TYPE_SYMBOL:
3082 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3083 /* Intel MAC : 00:02:B3:* */
3084 /* 3Com MAC : 00:50:DA:* */
3085 memset(tmp, 0, sizeof(tmp));
3086 /* Get the Symbol firmware version */
3087 err = hermes_read_ltv(hw, USER_BAP,
3088 HERMES_RID_SECONDARYVERSION_SYMBOL,
3089 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3090 if (err) {
3091 printk(KERN_WARNING
David Kilroyb2f30a02009-02-04 23:05:46 +00003092 "%s: Error %d reading Symbol firmware info. "
3093 "Wildly guessing capabilities...\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 dev->name, err);
3095 firmver = 0;
3096 tmp[0] = '\0';
3097 } else {
3098 /* The firmware revision is a string, the format is
3099 * something like : "V2.20-01".
3100 * Quick and dirty parsing... - Jean II
3101 */
David Kilroyb2f30a02009-02-04 23:05:46 +00003102 firmver = ((tmp[1] - '0') << 16)
3103 | ((tmp[3] - '0') << 12)
3104 | ((tmp[4] - '0') << 8)
3105 | ((tmp[6] - '0') << 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 | (tmp[7] - '0');
3107
3108 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3109 }
3110
3111 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3112 "Symbol %s", tmp);
3113
3114 priv->has_ibss = (firmver >= 0x20000);
3115 priv->has_wep = (firmver >= 0x15012);
3116 priv->has_big_wep = (firmver >= 0x20000);
David Kilroy6fe9deb2009-02-04 23:05:43 +00003117 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 (firmver >= 0x29000 && firmver < 0x30000) ||
3119 firmver >= 0x31000;
3120 priv->has_preamble = (firmver >= 0x20000);
3121 priv->ibss_port = 4;
David Kilroy3994d502008-08-21 23:27:54 +01003122
3123 /* Symbol firmware is found on various cards, but
3124 * there has been no attempt to check firmware
3125 * download on non-spectrum_cs based cards.
3126 *
3127 * Given that the Agere firmware download works
3128 * differently, we should avoid doing a firmware
3129 * download with the Symbol algorithm on non-spectrum
3130 * cards.
3131 *
3132 * For now we can identify a spectrum_cs based card
3133 * because it has a firmware reset function.
3134 */
3135 priv->do_fw_download = (priv->stop_fw != NULL);
3136
David Kilroy6fe9deb2009-02-04 23:05:43 +00003137 priv->broken_disableport = (firmver == 0x25013) ||
David Kilroyb2f30a02009-02-04 23:05:46 +00003138 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003139 priv->has_hostscan = (firmver >= 0x31001) ||
3140 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 /* Tested with Intel firmware : 0x20015 => Jean II */
3142 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3143 break;
3144 case FIRMWARE_TYPE_INTERSIL:
3145 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3146 * Samsung, Compaq 100/200 and Proxim are slightly
3147 * different and less well tested */
3148 /* D-Link MAC : 00:40:05:* */
3149 /* Addtron MAC : 00:90:D1:* */
3150 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3151 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3152 sta_id.variant);
3153
3154 firmver = ((unsigned long)sta_id.major << 16) |
3155 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3156
3157 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3158 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3159 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003160 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 if (firmver >= 0x000800)
3163 priv->ibss_port = 0;
3164 else {
3165 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3166 "than v0.8.x - several features not supported\n",
3167 dev->name);
3168 priv->ibss_port = 1;
3169 }
3170 break;
3171 }
3172 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3173 priv->fw_name);
3174
3175 return 0;
3176}
3177
3178static int orinoco_init(struct net_device *dev)
3179{
3180 struct orinoco_private *priv = netdev_priv(dev);
3181 hermes_t *hw = &priv->hw;
3182 int err = 0;
3183 struct hermes_idstring nickbuf;
3184 u16 reclen;
3185 int len;
3186
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 /* No need to lock, the hw_unavailable flag is already set in
3188 * alloc_orinocodev() */
Johannes Berg2c7060022008-10-30 22:09:54 +01003189 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04003192 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 if (err != 0) {
3194 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3195 dev->name, err);
3196 goto out;
3197 }
3198
3199 err = determine_firmware(dev);
3200 if (err != 0) {
3201 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3202 dev->name);
3203 goto out;
3204 }
3205
David Kilroy3994d502008-08-21 23:27:54 +01003206 if (priv->do_fw_download) {
David Kilroy39d1ffe2008-11-22 10:37:28 +00003207#ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
David Kilroy74734312008-11-22 10:37:25 +00003208 orinoco_cache_fw(priv, 0);
David Kilroy39d1ffe2008-11-22 10:37:28 +00003209#endif
David Kilroy74734312008-11-22 10:37:25 +00003210
David Kilroy3994d502008-08-21 23:27:54 +01003211 err = orinoco_download(priv);
3212 if (err)
3213 priv->do_fw_download = 0;
3214
3215 /* Check firmware version again */
3216 err = determine_firmware(dev);
3217 if (err != 0) {
3218 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3219 dev->name);
3220 goto out;
3221 }
3222 }
3223
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 if (priv->has_port3)
David Kilroyb2f30a02009-02-04 23:05:46 +00003225 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
3226 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 if (priv->has_ibss)
3228 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3229 dev->name);
3230 if (priv->has_wep) {
David Kilroy21312662009-02-04 23:05:47 +00003231 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
3232 priv->has_big_wep ? "104" : "40");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 }
David Kilroy23edcc42008-08-21 23:28:05 +01003234 if (priv->has_wpa) {
David Kilroyd03032a2008-08-21 23:28:02 +01003235 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
David Kilroy23edcc42008-08-21 23:28:05 +01003236 if (orinoco_mic_init(priv)) {
3237 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3238 "algorithm. Disabling WPA support\n", dev->name);
3239 priv->has_wpa = 0;
3240 }
3241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
David Kilroy01632fa2008-08-21 23:27:58 +01003243 /* Now we have the firmware capabilities, allocate appropiate
3244 * sized scan buffers */
3245 if (orinoco_bss_data_allocate(priv))
3246 goto out;
3247 orinoco_bss_data_init(priv);
3248
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 /* Get the MAC address */
3250 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3251 ETH_ALEN, NULL, dev->dev_addr);
3252 if (err) {
3253 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3254 dev->name);
3255 goto out;
3256 }
3257
Johannes Berge1749612008-10-27 15:59:26 -07003258 printk(KERN_DEBUG "%s: MAC address %pM\n",
3259 dev->name, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260
3261 /* Get the station name */
3262 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3263 sizeof(nickbuf), &reclen, &nickbuf);
3264 if (err) {
3265 printk(KERN_ERR "%s: failed to read station name\n",
3266 dev->name);
3267 goto out;
3268 }
3269 if (nickbuf.len)
3270 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3271 else
3272 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3273 memcpy(priv->nick, &nickbuf.val, len);
3274 priv->nick[len] = '\0';
3275
3276 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3277
Pavel Roskin37a6c612006-04-07 04:10:49 -04003278 err = orinoco_allocate_fid(dev);
3279 if (err) {
3280 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3281 dev->name);
3282 goto out;
3283 }
3284
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 /* Get allowed channels */
3286 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3287 &priv->channel_mask);
3288 if (err) {
3289 printk(KERN_ERR "%s: failed to read channel list!\n",
3290 dev->name);
3291 goto out;
3292 }
3293
3294 /* Get initial AP density */
3295 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3296 &priv->ap_density);
David Kilroy566f2d92009-02-04 23:05:45 +00003297 if (err || priv->ap_density < 1 || priv->ap_density > 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 priv->has_sensitivity = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
3300 /* Get initial RTS threshold */
3301 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3302 &priv->rts_thresh);
3303 if (err) {
3304 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3305 dev->name);
3306 goto out;
3307 }
3308
3309 /* Get initial fragmentation settings */
3310 if (priv->has_mwo)
3311 err = hermes_read_wordrec(hw, USER_BAP,
3312 HERMES_RID_CNFMWOROBUST_AGERE,
3313 &priv->mwo_robust);
3314 else
David Kilroyb2f30a02009-02-04 23:05:46 +00003315 err = hermes_read_wordrec(hw, USER_BAP,
3316 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 &priv->frag_thresh);
3318 if (err) {
3319 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3320 dev->name);
3321 goto out;
3322 }
3323
3324 /* Power management setup */
3325 if (priv->has_pm) {
3326 priv->pm_on = 0;
3327 priv->pm_mcast = 1;
3328 err = hermes_read_wordrec(hw, USER_BAP,
3329 HERMES_RID_CNFMAXSLEEPDURATION,
3330 &priv->pm_period);
3331 if (err) {
3332 printk(KERN_ERR "%s: failed to read power management period!\n",
3333 dev->name);
3334 goto out;
3335 }
3336 err = hermes_read_wordrec(hw, USER_BAP,
3337 HERMES_RID_CNFPMHOLDOVERDURATION,
3338 &priv->pm_timeout);
3339 if (err) {
3340 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3341 dev->name);
3342 goto out;
3343 }
3344 }
3345
3346 /* Preamble setup */
3347 if (priv->has_preamble) {
3348 err = hermes_read_wordrec(hw, USER_BAP,
3349 HERMES_RID_CNFPREAMBLE_SYMBOL,
3350 &priv->preamble);
3351 if (err)
3352 goto out;
3353 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00003354
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 /* Set up the default configuration */
3356 priv->iw_mode = IW_MODE_INFRA;
3357 /* By default use IEEE/IBSS ad-hoc mode if we have it */
David Kilroya94e8422009-02-04 23:05:44 +00003358 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04003360 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361
3362 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003363 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01003365 priv->wpa_enabled = 0;
3366 priv->tkip_cm_active = 0;
3367 priv->key_mgmt = 0;
3368 priv->wpa_ie_len = 0;
3369 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 /* Make the hardware available, as long as it hasn't been
3372 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3373 spin_lock_irq(&priv->lock);
3374 priv->hw_unavailable--;
3375 spin_unlock_irq(&priv->lock);
3376
3377 printk(KERN_DEBUG "%s: ready\n", dev->name);
3378
3379 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 return err;
3381}
3382
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03003383static const struct net_device_ops orinoco_netdev_ops = {
3384 .ndo_init = orinoco_init,
3385 .ndo_open = orinoco_open,
3386 .ndo_stop = orinoco_stop,
3387 .ndo_start_xmit = orinoco_xmit,
3388 .ndo_set_multicast_list = orinoco_set_multicast_list,
3389 .ndo_change_mtu = orinoco_change_mtu,
3390 .ndo_tx_timeout = orinoco_tx_timeout,
3391 .ndo_get_stats = orinoco_get_stats,
3392};
3393
David Kilroy3994d502008-08-21 23:27:54 +01003394struct net_device
3395*alloc_orinocodev(int sizeof_card,
3396 struct device *device,
3397 int (*hard_reset)(struct orinoco_private *),
3398 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399{
3400 struct net_device *dev;
3401 struct orinoco_private *priv;
3402
3403 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
Andrey Borzenkove129a942009-01-21 21:55:29 +03003404 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 return NULL;
3406 priv = netdev_priv(dev);
3407 priv->ndev = dev;
3408 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003409 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 + sizeof(struct orinoco_private));
3411 else
3412 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01003413 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
3415 /* Setup / override net_device fields */
Andrey Borzenkov89ea4092009-01-21 20:46:46 +03003416 dev->netdev_ops = &orinoco_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 dev->watchdog_timeo = HZ; /* 1 second timeout */
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02003418 dev->ethtool_ops = &orinoco_ethtool_ops;
Andrey Borzenkove129a942009-01-21 21:55:29 +03003419 dev->wireless_handlers = &orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04003420#ifdef WIRELESS_SPY
3421 priv->wireless_data.spy_data = &priv->spy_data;
3422 dev->wireless_data = &priv->wireless_data;
3423#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 /* we use the default eth_mac_addr for setting the MAC addr */
3425
David Kilroy23edcc42008-08-21 23:28:05 +01003426 /* Reserve space in skb for the SNAP header */
3427 dev->hard_header_len += ENCAPS_OVERHEAD;
3428
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 /* Set up default callbacks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01003431 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 spin_lock_init(&priv->lock);
3434 priv->open = 0;
3435 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3436 * before anything else touches the
3437 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00003438 INIT_WORK(&priv->reset_work, orinoco_reset);
3439 INIT_WORK(&priv->join_work, orinoco_join_ap);
3440 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
David Kilroy31afcef2008-08-21 23:28:04 +01003442 INIT_LIST_HEAD(&priv->rx_list);
3443 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3444 (unsigned long) dev);
3445
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 netif_carrier_off(dev);
3447 priv->last_linkstatus = 0xffff;
3448
David Kilroy2cea7b22008-11-22 10:37:26 +00003449 priv->cached_pri_fw = NULL;
Andrey Borzenkov4fb30782008-10-19 12:06:11 +04003450 priv->cached_fw = NULL;
3451
David Kilroy39d1ffe2008-11-22 10:37:28 +00003452 /* Register PM notifiers */
3453 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
3454 register_pm_notifier(&priv->pm_notifier);
3455
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457}
David Kilroy21312662009-02-04 23:05:47 +00003458EXPORT_SYMBOL(alloc_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
3460void free_orinocodev(struct net_device *dev)
3461{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003462 struct orinoco_private *priv = netdev_priv(dev);
David Kilroy20953ad2009-01-07 00:23:55 +00003463 struct orinoco_rx_data *rx_data, *temp;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003464
David Kilroy20953ad2009-01-07 00:23:55 +00003465 /* If the tasklet is scheduled when we call tasklet_kill it
3466 * will run one final time. However the tasklet will only
3467 * drain priv->rx_list if the hw is still available. */
David Kilroy31afcef2008-08-21 23:28:04 +01003468 tasklet_kill(&priv->rx_tasklet);
David Kilroy74734312008-11-22 10:37:25 +00003469
David Kilroy20953ad2009-01-07 00:23:55 +00003470 /* Explicitly drain priv->rx_list */
3471 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
3472 list_del(&rx_data->list);
3473
3474 dev_kfree_skb(rx_data->skb);
3475 kfree(rx_data->desc);
3476 kfree(rx_data);
3477 }
3478
David Kilroy39d1ffe2008-11-22 10:37:28 +00003479 unregister_pm_notifier(&priv->pm_notifier);
David Kilroy74734312008-11-22 10:37:25 +00003480 orinoco_uncache_fw(priv);
3481
David Kilroyd03032a2008-08-21 23:28:02 +01003482 priv->wpa_ie_len = 0;
3483 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01003484 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04003485 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 free_netdev(dev);
3487}
David Kilroy21312662009-02-04 23:05:47 +00003488EXPORT_SYMBOL(free_orinocodev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
3490/********************************************************************/
3491/* Wireless extensions */
3492/********************************************************************/
3493
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003494/* Return : < 0 -> error code ; >= 0 -> length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3496 char buf[IW_ESSID_MAX_SIZE+1])
3497{
3498 hermes_t *hw = &priv->hw;
3499 int err = 0;
3500 struct hermes_idstring essidbuf;
3501 char *p = (char *)(&essidbuf.val);
3502 int len;
3503 unsigned long flags;
3504
3505 if (orinoco_lock(priv, &flags) != 0)
3506 return -EBUSY;
3507
3508 if (strlen(priv->desired_essid) > 0) {
3509 /* We read the desired SSID from the hardware rather
3510 than from priv->desired_essid, just in case the
3511 firmware is allowed to change it on us. I'm not
3512 sure about this */
3513 /* My guess is that the OWNSSID should always be whatever
3514 * we set to the card, whereas CURRENT_SSID is the one that
3515 * may change... - Jean II */
3516 u16 rid;
3517
3518 *active = 1;
3519
3520 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3521 HERMES_RID_CNFDESIREDSSID;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003522
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3524 NULL, &essidbuf);
3525 if (err)
3526 goto fail_unlock;
3527 } else {
3528 *active = 0;
3529
3530 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3531 sizeof(essidbuf), NULL, &essidbuf);
3532 if (err)
3533 goto fail_unlock;
3534 }
3535
3536 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003537 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003539 memset(buf, 0, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 memcpy(buf, p, len);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003541 err = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542
3543 fail_unlock:
3544 orinoco_unlock(priv, &flags);
3545
David Kilroy6fe9deb2009-02-04 23:05:43 +00003546 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547}
3548
David Kilroy9ee677c2008-12-23 14:03:38 +00003549static int orinoco_hw_get_freq(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550{
David Kilroy6fe9deb2009-02-04 23:05:43 +00003551
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552 hermes_t *hw = &priv->hw;
3553 int err = 0;
3554 u16 channel;
David Kilroy9ee677c2008-12-23 14:03:38 +00003555 int freq = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556 unsigned long flags;
3557
3558 if (orinoco_lock(priv, &flags) != 0)
3559 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003560
David Kilroyb2f30a02009-02-04 23:05:46 +00003561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
3562 &channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 if (err)
3564 goto out;
3565
3566 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3567 if (channel == 0) {
3568 err = -EBUSY;
3569 goto out;
3570 }
3571
David Kilroya94e8422009-02-04 23:05:44 +00003572 if ((channel < 1) || (channel > NUM_CHANNELS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3574 priv->ndev->name, channel);
3575 err = -EBUSY;
3576 goto out;
3577
3578 }
David Kilroy9ee677c2008-12-23 14:03:38 +00003579 freq = ieee80211_dsss_chan_to_freq(channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581 out:
3582 orinoco_unlock(priv, &flags);
3583
3584 if (err > 0)
3585 err = -EBUSY;
3586 return err ? err : freq;
3587}
3588
3589static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3590 int *numrates, s32 *rates, int max)
3591{
3592 hermes_t *hw = &priv->hw;
3593 struct hermes_idstring list;
3594 unsigned char *p = (unsigned char *)&list.val;
3595 int err = 0;
3596 int num;
3597 int i;
3598 unsigned long flags;
3599
3600 if (orinoco_lock(priv, &flags) != 0)
3601 return -EBUSY;
3602
3603 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3604 sizeof(list), NULL, &list);
3605 orinoco_unlock(priv, &flags);
3606
3607 if (err)
3608 return err;
David Kilroy6fe9deb2009-02-04 23:05:43 +00003609
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 num = le16_to_cpu(list.len);
3611 *numrates = num;
3612 num = min(num, max);
3613
David Kilroy566f2d92009-02-04 23:05:45 +00003614 for (i = 0; i < num; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003616
3617 return 0;
3618}
3619
Christoph Hellwig620554e2005-06-19 01:27:33 +02003620static int orinoco_ioctl_getname(struct net_device *dev,
3621 struct iw_request_info *info,
3622 char *name,
3623 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624{
3625 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003627 int err;
3628
3629 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3630
3631 if (!err && (numrates > 2))
3632 strcpy(name, "IEEE 802.11b");
3633 else
3634 strcpy(name, "IEEE 802.11-DS");
3635
3636 return 0;
3637}
3638
Christoph Hellwig16739b02005-06-19 01:27:51 +02003639static int orinoco_ioctl_setwap(struct net_device *dev,
3640 struct iw_request_info *info,
3641 struct sockaddr *ap_addr,
3642 char *extra)
3643{
3644 struct orinoco_private *priv = netdev_priv(dev);
3645 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02003647 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3648 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
3650 if (orinoco_lock(priv, &flags) != 0)
3651 return -EBUSY;
3652
Christoph Hellwig16739b02005-06-19 01:27:51 +02003653 /* Enable automatic roaming - no sanity checks are needed */
3654 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3655 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3656 priv->bssid_fixed = 0;
3657 memset(priv->desired_bssid, 0, ETH_ALEN);
3658
3659 /* "off" means keep existing connection */
3660 if (ap_addr->sa_data[0] == 0) {
3661 __orinoco_hw_set_wap(priv);
3662 err = 0;
3663 }
3664 goto out;
3665 }
3666
3667 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3668 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3669 "support manual roaming\n",
3670 dev->name);
3671 err = -EOPNOTSUPP;
3672 goto out;
3673 }
3674
3675 if (priv->iw_mode != IW_MODE_INFRA) {
3676 printk(KERN_WARNING "%s: Manual roaming supported only in "
3677 "managed mode\n", dev->name);
3678 err = -EOPNOTSUPP;
3679 goto out;
3680 }
3681
3682 /* Intersil firmware hangs without Desired ESSID */
3683 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3684 strlen(priv->desired_essid) == 0) {
3685 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3686 "manual roaming\n", dev->name);
3687 err = -EOPNOTSUPP;
3688 goto out;
3689 }
3690
3691 /* Finally, enable manual roaming */
3692 priv->bssid_fixed = 1;
3693 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3694
3695 out:
3696 orinoco_unlock(priv, &flags);
3697 return err;
3698}
3699
Christoph Hellwig620554e2005-06-19 01:27:33 +02003700static int orinoco_ioctl_getwap(struct net_device *dev,
3701 struct iw_request_info *info,
3702 struct sockaddr *ap_addr,
3703 char *extra)
3704{
3705 struct orinoco_private *priv = netdev_priv(dev);
3706
3707 hermes_t *hw = &priv->hw;
3708 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 unsigned long flags;
3710
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 if (orinoco_lock(priv, &flags) != 0)
3712 return -EBUSY;
3713
Christoph Hellwig620554e2005-06-19 01:27:33 +02003714 ap_addr->sa_family = ARPHRD_ETHER;
3715 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3716 ETH_ALEN, NULL, ap_addr->sa_data);
3717
Linus Torvalds1da177e2005-04-16 15:20:36 -07003718 orinoco_unlock(priv, &flags);
3719
Christoph Hellwig620554e2005-06-19 01:27:33 +02003720 return err;
3721}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722
Christoph Hellwig620554e2005-06-19 01:27:33 +02003723static int orinoco_ioctl_setmode(struct net_device *dev,
3724 struct iw_request_info *info,
3725 u32 *mode,
3726 char *extra)
3727{
3728 struct orinoco_private *priv = netdev_priv(dev);
3729 int err = -EINPROGRESS; /* Call commit handler */
3730 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731
Christoph Hellwig620554e2005-06-19 01:27:33 +02003732 if (priv->iw_mode == *mode)
3733 return 0;
3734
3735 if (orinoco_lock(priv, &flags) != 0)
3736 return -EBUSY;
3737
3738 switch (*mode) {
3739 case IW_MODE_ADHOC:
3740 if (!priv->has_ibss && !priv->has_port3)
3741 err = -EOPNOTSUPP;
3742 break;
3743
3744 case IW_MODE_INFRA:
3745 break;
3746
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003747 case IW_MODE_MONITOR:
3748 if (priv->broken_monitor && !force_monitor) {
3749 printk(KERN_WARNING "%s: Monitor mode support is "
3750 "buggy in this firmware, not enabling\n",
3751 dev->name);
3752 err = -EOPNOTSUPP;
3753 }
3754 break;
3755
Christoph Hellwig620554e2005-06-19 01:27:33 +02003756 default:
3757 err = -EOPNOTSUPP;
3758 break;
3759 }
3760
3761 if (err == -EINPROGRESS) {
3762 priv->iw_mode = *mode;
3763 set_port_type(priv);
3764 }
3765
3766 orinoco_unlock(priv, &flags);
3767
3768 return err;
3769}
3770
3771static int orinoco_ioctl_getmode(struct net_device *dev,
3772 struct iw_request_info *info,
3773 u32 *mode,
3774 char *extra)
3775{
3776 struct orinoco_private *priv = netdev_priv(dev);
3777
3778 *mode = priv->iw_mode;
3779 return 0;
3780}
3781
3782static int orinoco_ioctl_getiwrange(struct net_device *dev,
3783 struct iw_request_info *info,
3784 struct iw_point *rrq,
3785 char *extra)
3786{
3787 struct orinoco_private *priv = netdev_priv(dev);
3788 int err = 0;
3789 struct iw_range *range = (struct iw_range *) extra;
3790 int numrates;
3791 int i, k;
3792
Christoph Hellwig620554e2005-06-19 01:27:33 +02003793 rrq->length = sizeof(struct iw_range);
3794 memset(range, 0, sizeof(struct iw_range));
3795
3796 range->we_version_compiled = WIRELESS_EXT;
David Kilroyd03032a2008-08-21 23:28:02 +01003797 range->we_version_source = 22;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
3799 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003800 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003801 k = 0;
3802 for (i = 0; i < NUM_CHANNELS; i++) {
3803 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003804 range->freq[k].i = i + 1;
David Kilroy9ee677c2008-12-23 14:03:38 +00003805 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
3806 100000);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003807 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 k++;
3809 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00003810
Linus Torvalds1da177e2005-04-16 15:20:36 -07003811 if (k >= IW_MAX_FREQUENCIES)
3812 break;
3813 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02003814 range->num_frequency = k;
3815 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816
Christoph Hellwig620554e2005-06-19 01:27:33 +02003817 if (priv->has_wep) {
3818 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3819 range->encoding_size[0] = SMALL_KEY_SIZE;
3820 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
Christoph Hellwig620554e2005-06-19 01:27:33 +02003822 if (priv->has_big_wep) {
3823 range->encoding_size[1] = LARGE_KEY_SIZE;
3824 range->num_encoding_sizes = 2;
3825 }
3826 }
3827
David Kilroyd03032a2008-08-21 23:28:02 +01003828 if (priv->has_wpa)
3829 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
3830
David Kilroya94e8422009-02-04 23:05:44 +00003831 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003833 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003834 range->max_qual.qual = 0x8b - 0x2f;
3835 range->max_qual.level = 0x2f - 0x95 - 1;
3836 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003838 range->avg_qual.qual = 0x24;
3839 range->avg_qual.level = 0xC2;
3840 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 }
3842
3843 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02003844 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 if (err)
3846 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003847 range->num_bitrates = numrates;
3848
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 /* Set an indication of the max TCP throughput in bit/s that we can
3850 * expect using this interface. May be use for QoS stuff...
3851 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003852 if (numrates > 2)
3853 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02003855 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003856
Christoph Hellwig620554e2005-06-19 01:27:33 +02003857 range->min_rts = 0;
3858 range->max_rts = 2347;
3859 range->min_frag = 256;
3860 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
Christoph Hellwig620554e2005-06-19 01:27:33 +02003862 range->min_pmp = 0;
3863 range->max_pmp = 65535000;
3864 range->min_pmt = 0;
3865 range->max_pmt = 65535 * 1000; /* ??? */
3866 range->pmp_flags = IW_POWER_PERIOD;
3867 range->pmt_flags = IW_POWER_TIMEOUT;
David Kilroyb2f30a02009-02-04 23:05:46 +00003868 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
3869 IW_POWER_UNICAST_R);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870
Christoph Hellwig620554e2005-06-19 01:27:33 +02003871 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3872 range->retry_flags = IW_RETRY_LIMIT;
3873 range->r_time_flags = IW_RETRY_LIFETIME;
3874 range->min_retry = 0;
3875 range->max_retry = 65535; /* ??? */
3876 range->min_r_time = 0;
3877 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
David Kilroy0753bba2008-08-21 23:27:46 +01003879 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3880 range->scan_capa = IW_SCAN_CAPA_ESSID;
3881 else
3882 range->scan_capa = IW_SCAN_CAPA_NONE;
3883
Pavel Roskin343c6862005-09-09 18:43:02 -04003884 /* Event capability (kernel) */
3885 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3886 /* Event capability (driver) */
3887 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3888 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3889 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3890 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3891
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 return 0;
3893}
3894
Christoph Hellwig620554e2005-06-19 01:27:33 +02003895static int orinoco_ioctl_setiwencode(struct net_device *dev,
3896 struct iw_request_info *info,
3897 struct iw_point *erq,
3898 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899{
3900 struct orinoco_private *priv = netdev_priv(dev);
3901 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3902 int setindex = priv->tx_key;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003903 int encode_alg = priv->encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904 int restricted = priv->wep_restrict;
3905 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003906 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 unsigned long flags;
3908
David Kilroya94e8422009-02-04 23:05:44 +00003909 if (!priv->has_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003910 return -EOPNOTSUPP;
3911
3912 if (erq->pointer) {
3913 /* We actually have a key to set - check its length */
3914 if (erq->length > LARGE_KEY_SIZE)
3915 return -E2BIG;
3916
David Kilroya94e8422009-02-04 23:05:44 +00003917 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 }
3920
3921 if (orinoco_lock(priv, &flags) != 0)
3922 return -EBUSY;
3923
David Kilroyd03032a2008-08-21 23:28:02 +01003924 /* Clear any TKIP key we have */
3925 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3926 (void) orinoco_clear_tkip_key(priv, setindex);
3927
Dan Williamsfe397d42006-07-14 11:41:47 -04003928 if (erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003929 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3930 index = priv->tx_key;
3931
3932 /* Adjust key length to a supported value */
David Kilroy566f2d92009-02-04 23:05:45 +00003933 if (erq->length > SMALL_KEY_SIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003934 xlen = LARGE_KEY_SIZE;
David Kilroy566f2d92009-02-04 23:05:45 +00003935 else if (erq->length > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003936 xlen = SMALL_KEY_SIZE;
David Kilroy566f2d92009-02-04 23:05:45 +00003937 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938 xlen = 0;
3939
3940 /* Switch on WEP if off */
David Kilroy4ae6ee22008-08-21 23:27:59 +01003941 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003942 setindex = index;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003943 encode_alg = IW_ENCODE_ALG_WEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003944 }
3945 } else {
3946 /* Important note : if the user do "iwconfig eth0 enc off",
3947 * we will arrive there with an index of -1. This is valid
3948 * but need to be taken care off... Jean II */
3949 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
David Kilroya94e8422009-02-04 23:05:44 +00003950 if ((index != -1) || (erq->flags == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 err = -EINVAL;
3952 goto out;
3953 }
3954 } else {
3955 /* Set the index : Check that the key is valid */
David Kilroya94e8422009-02-04 23:05:44 +00003956 if (priv->keys[index].len == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003957 err = -EINVAL;
3958 goto out;
3959 }
3960 setindex = index;
3961 }
3962 }
3963
3964 if (erq->flags & IW_ENCODE_DISABLED)
David Kilroy4ae6ee22008-08-21 23:27:59 +01003965 encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 if (erq->flags & IW_ENCODE_OPEN)
3967 restricted = 0;
3968 if (erq->flags & IW_ENCODE_RESTRICTED)
3969 restricted = 1;
3970
Dan Williamsfe397d42006-07-14 11:41:47 -04003971 if (erq->pointer && erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 priv->keys[index].len = cpu_to_le16(xlen);
3973 memset(priv->keys[index].data, 0,
3974 sizeof(priv->keys[index].data));
3975 memcpy(priv->keys[index].data, keybuf, erq->length);
3976 }
3977 priv->tx_key = setindex;
3978
3979 /* Try fast key change if connected and only keys are changed */
David Kilroy4ae6ee22008-08-21 23:27:59 +01003980 if ((priv->encode_alg == encode_alg) &&
3981 (priv->wep_restrict == restricted) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003982 netif_carrier_ok(dev)) {
3983 err = __orinoco_hw_setup_wepkeys(priv);
3984 /* No need to commit if successful */
3985 goto out;
3986 }
3987
David Kilroy4ae6ee22008-08-21 23:27:59 +01003988 priv->encode_alg = encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003989 priv->wep_restrict = restricted;
3990
3991 out:
3992 orinoco_unlock(priv, &flags);
3993
3994 return err;
3995}
3996
Christoph Hellwig620554e2005-06-19 01:27:33 +02003997static int orinoco_ioctl_getiwencode(struct net_device *dev,
3998 struct iw_request_info *info,
3999 struct iw_point *erq,
4000 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004001{
4002 struct orinoco_private *priv = netdev_priv(dev);
4003 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4004 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 unsigned long flags;
4006
David Kilroya94e8422009-02-04 23:05:44 +00004007 if (!priv->has_wep)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 return -EOPNOTSUPP;
4009
4010 if (orinoco_lock(priv, &flags) != 0)
4011 return -EBUSY;
4012
4013 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4014 index = priv->tx_key;
4015
4016 erq->flags = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01004017 if (!priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018 erq->flags |= IW_ENCODE_DISABLED;
4019 erq->flags |= index + 1;
4020
4021 if (priv->wep_restrict)
4022 erq->flags |= IW_ENCODE_RESTRICTED;
4023 else
4024 erq->flags |= IW_ENCODE_OPEN;
4025
4026 xlen = le16_to_cpu(priv->keys[index].len);
4027
4028 erq->length = xlen;
4029
4030 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
4031
4032 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 return 0;
4034}
4035
Christoph Hellwig620554e2005-06-19 01:27:33 +02004036static int orinoco_ioctl_setessid(struct net_device *dev,
4037 struct iw_request_info *info,
4038 struct iw_point *erq,
4039 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040{
4041 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 unsigned long flags;
4043
4044 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4045 * anyway... - Jean II */
4046
Christoph Hellwig620554e2005-06-19 01:27:33 +02004047 /* Hum... Should not use Wireless Extension constant (may change),
4048 * should use our own... - Jean II */
4049 if (erq->length > IW_ESSID_MAX_SIZE)
4050 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
4052 if (orinoco_lock(priv, &flags) != 0)
4053 return -EBUSY;
4054
Christoph Hellwig620554e2005-06-19 01:27:33 +02004055 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4056 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
4057
4058 /* If not ANY, get the new ESSID */
David Kilroy566f2d92009-02-04 23:05:45 +00004059 if (erq->flags)
Christoph Hellwig620554e2005-06-19 01:27:33 +02004060 memcpy(priv->desired_essid, essidbuf, erq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004061
4062 orinoco_unlock(priv, &flags);
4063
Christoph Hellwig620554e2005-06-19 01:27:33 +02004064 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004065}
4066
Christoph Hellwig620554e2005-06-19 01:27:33 +02004067static int orinoco_ioctl_getessid(struct net_device *dev,
4068 struct iw_request_info *info,
4069 struct iw_point *erq,
4070 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071{
4072 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 int active;
4074 int err = 0;
4075 unsigned long flags;
4076
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 if (netif_running(dev)) {
4078 err = orinoco_hw_get_essid(priv, &active, essidbuf);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004079 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004080 return err;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004081 erq->length = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082 } else {
4083 if (orinoco_lock(priv, &flags) != 0)
4084 return -EBUSY;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004085 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4086 erq->length = strlen(priv->desired_essid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 orinoco_unlock(priv, &flags);
4088 }
4089
4090 erq->flags = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004091
Linus Torvalds1da177e2005-04-16 15:20:36 -07004092 return 0;
4093}
4094
Christoph Hellwig620554e2005-06-19 01:27:33 +02004095static int orinoco_ioctl_setnick(struct net_device *dev,
4096 struct iw_request_info *info,
4097 struct iw_point *nrq,
4098 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004099{
4100 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101 unsigned long flags;
4102
4103 if (nrq->length > IW_ESSID_MAX_SIZE)
4104 return -E2BIG;
4105
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 if (orinoco_lock(priv, &flags) != 0)
4107 return -EBUSY;
4108
Christoph Hellwig620554e2005-06-19 01:27:33 +02004109 memset(priv->nick, 0, sizeof(priv->nick));
4110 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004111
4112 orinoco_unlock(priv, &flags);
4113
Christoph Hellwig620554e2005-06-19 01:27:33 +02004114 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115}
4116
Christoph Hellwig620554e2005-06-19 01:27:33 +02004117static int orinoco_ioctl_getnick(struct net_device *dev,
4118 struct iw_request_info *info,
4119 struct iw_point *nrq,
4120 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121{
4122 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123 unsigned long flags;
4124
4125 if (orinoco_lock(priv, &flags) != 0)
4126 return -EBUSY;
4127
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004128 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 orinoco_unlock(priv, &flags);
4130
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004131 nrq->length = strlen(priv->nick);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133 return 0;
4134}
4135
Christoph Hellwig620554e2005-06-19 01:27:33 +02004136static int orinoco_ioctl_setfreq(struct net_device *dev,
4137 struct iw_request_info *info,
4138 struct iw_freq *frq,
4139 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140{
4141 struct orinoco_private *priv = netdev_priv(dev);
4142 int chan = -1;
4143 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004144 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004146 /* In infrastructure mode the AP sets the channel */
4147 if (priv->iw_mode == IW_MODE_INFRA)
4148 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149
David Kilroya94e8422009-02-04 23:05:44 +00004150 if ((frq->e == 0) && (frq->m <= 1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 /* Setting by channel number */
4152 chan = frq->m;
4153 } else {
David Kilroy9ee677c2008-12-23 14:03:38 +00004154 /* Setting by frequency */
4155 int denom = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156 int i;
4157
David Kilroy9ee677c2008-12-23 14:03:38 +00004158 /* Calculate denominator to rescale to MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159 for (i = 0; i < (6 - frq->e); i++)
David Kilroy9ee677c2008-12-23 14:03:38 +00004160 denom *= 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161
David Kilroy9ee677c2008-12-23 14:03:38 +00004162 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 }
4164
David Kilroya94e8422009-02-04 23:05:44 +00004165 if ((chan < 1) || (chan > NUM_CHANNELS) ||
4166 !(priv->channel_mask & (1 << (chan-1))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004167 return -EINVAL;
4168
4169 if (orinoco_lock(priv, &flags) != 0)
4170 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004171
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004173 if (priv->iw_mode == IW_MODE_MONITOR) {
4174 /* Fast channel change - no commit if successful */
4175 hermes_t *hw = &priv->hw;
4176 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4177 HERMES_TEST_SET_CHANNEL,
4178 chan, NULL);
4179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180 orinoco_unlock(priv, &flags);
4181
Christoph Hellwig620554e2005-06-19 01:27:33 +02004182 return err;
4183}
4184
4185static int orinoco_ioctl_getfreq(struct net_device *dev,
4186 struct iw_request_info *info,
4187 struct iw_freq *frq,
4188 char *extra)
4189{
4190 struct orinoco_private *priv = netdev_priv(dev);
4191 int tmp;
4192
4193 /* Locking done in there */
4194 tmp = orinoco_hw_get_freq(priv);
David Kilroy566f2d92009-02-04 23:05:45 +00004195 if (tmp < 0)
Christoph Hellwig620554e2005-06-19 01:27:33 +02004196 return tmp;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004197
David Kilroy9ee677c2008-12-23 14:03:38 +00004198 frq->m = tmp * 100000;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004199 frq->e = 1;
4200
Linus Torvalds1da177e2005-04-16 15:20:36 -07004201 return 0;
4202}
4203
Christoph Hellwig620554e2005-06-19 01:27:33 +02004204static int orinoco_ioctl_getsens(struct net_device *dev,
4205 struct iw_request_info *info,
4206 struct iw_param *srq,
4207 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208{
4209 struct orinoco_private *priv = netdev_priv(dev);
4210 hermes_t *hw = &priv->hw;
4211 u16 val;
4212 int err;
4213 unsigned long flags;
4214
4215 if (!priv->has_sensitivity)
4216 return -EOPNOTSUPP;
4217
4218 if (orinoco_lock(priv, &flags) != 0)
4219 return -EBUSY;
4220 err = hermes_read_wordrec(hw, USER_BAP,
4221 HERMES_RID_CNFSYSTEMSCALE, &val);
4222 orinoco_unlock(priv, &flags);
4223
4224 if (err)
4225 return err;
4226
4227 srq->value = val;
4228 srq->fixed = 0; /* auto */
4229
4230 return 0;
4231}
4232
Christoph Hellwig620554e2005-06-19 01:27:33 +02004233static int orinoco_ioctl_setsens(struct net_device *dev,
4234 struct iw_request_info *info,
4235 struct iw_param *srq,
4236 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237{
4238 struct orinoco_private *priv = netdev_priv(dev);
4239 int val = srq->value;
4240 unsigned long flags;
4241
4242 if (!priv->has_sensitivity)
4243 return -EOPNOTSUPP;
4244
4245 if ((val < 1) || (val > 3))
4246 return -EINVAL;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004247
Linus Torvalds1da177e2005-04-16 15:20:36 -07004248 if (orinoco_lock(priv, &flags) != 0)
4249 return -EBUSY;
4250 priv->ap_density = val;
4251 orinoco_unlock(priv, &flags);
4252
Christoph Hellwig620554e2005-06-19 01:27:33 +02004253 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254}
4255
Christoph Hellwig620554e2005-06-19 01:27:33 +02004256static int orinoco_ioctl_setrts(struct net_device *dev,
4257 struct iw_request_info *info,
4258 struct iw_param *rrq,
4259 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260{
4261 struct orinoco_private *priv = netdev_priv(dev);
4262 int val = rrq->value;
4263 unsigned long flags;
4264
4265 if (rrq->disabled)
4266 val = 2347;
4267
David Kilroya94e8422009-02-04 23:05:44 +00004268 if ((val < 0) || (val > 2347))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 return -EINVAL;
4270
4271 if (orinoco_lock(priv, &flags) != 0)
4272 return -EBUSY;
4273
4274 priv->rts_thresh = val;
4275 orinoco_unlock(priv, &flags);
4276
Christoph Hellwig620554e2005-06-19 01:27:33 +02004277 return -EINPROGRESS; /* Call commit handler */
4278}
4279
4280static int orinoco_ioctl_getrts(struct net_device *dev,
4281 struct iw_request_info *info,
4282 struct iw_param *rrq,
4283 char *extra)
4284{
4285 struct orinoco_private *priv = netdev_priv(dev);
4286
4287 rrq->value = priv->rts_thresh;
4288 rrq->disabled = (rrq->value == 2347);
4289 rrq->fixed = 1;
4290
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 return 0;
4292}
4293
Christoph Hellwig620554e2005-06-19 01:27:33 +02004294static int orinoco_ioctl_setfrag(struct net_device *dev,
4295 struct iw_request_info *info,
4296 struct iw_param *frq,
4297 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004298{
4299 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004300 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301 unsigned long flags;
4302
4303 if (orinoco_lock(priv, &flags) != 0)
4304 return -EBUSY;
4305
4306 if (priv->has_mwo) {
4307 if (frq->disabled)
4308 priv->mwo_robust = 0;
4309 else {
4310 if (frq->fixed)
David Kilroyb2f30a02009-02-04 23:05:46 +00004311 printk(KERN_WARNING "%s: Fixed fragmentation "
4312 "is not supported on this firmware. "
4313 "Using MWO robust instead.\n",
4314 dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 priv->mwo_robust = 1;
4316 }
4317 } else {
4318 if (frq->disabled)
4319 priv->frag_thresh = 2346;
4320 else {
David Kilroya94e8422009-02-04 23:05:44 +00004321 if ((frq->value < 256) || (frq->value > 2346))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 err = -EINVAL;
4323 else
David Kilroyb2f30a02009-02-04 23:05:46 +00004324 /* must be even */
4325 priv->frag_thresh = frq->value & ~0x1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 }
4327 }
4328
4329 orinoco_unlock(priv, &flags);
4330
4331 return err;
4332}
4333
Christoph Hellwig620554e2005-06-19 01:27:33 +02004334static int orinoco_ioctl_getfrag(struct net_device *dev,
4335 struct iw_request_info *info,
4336 struct iw_param *frq,
4337 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338{
4339 struct orinoco_private *priv = netdev_priv(dev);
4340 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004341 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 u16 val;
4343 unsigned long flags;
4344
4345 if (orinoco_lock(priv, &flags) != 0)
4346 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004347
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348 if (priv->has_mwo) {
4349 err = hermes_read_wordrec(hw, USER_BAP,
4350 HERMES_RID_CNFMWOROBUST_AGERE,
4351 &val);
4352 if (err)
4353 val = 0;
4354
4355 frq->value = val ? 2347 : 0;
David Kilroya94e8422009-02-04 23:05:44 +00004356 frq->disabled = !val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 frq->fixed = 0;
4358 } else {
David Kilroyb2f30a02009-02-04 23:05:46 +00004359 err = hermes_read_wordrec(hw, USER_BAP,
4360 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004361 &val);
4362 if (err)
4363 val = 0;
4364
4365 frq->value = val;
4366 frq->disabled = (val >= 2346);
4367 frq->fixed = 1;
4368 }
4369
4370 orinoco_unlock(priv, &flags);
David Kilroy6fe9deb2009-02-04 23:05:43 +00004371
Linus Torvalds1da177e2005-04-16 15:20:36 -07004372 return err;
4373}
4374
Christoph Hellwig620554e2005-06-19 01:27:33 +02004375static int orinoco_ioctl_setrate(struct net_device *dev,
4376 struct iw_request_info *info,
4377 struct iw_param *rrq,
4378 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004379{
4380 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 int ratemode = -1;
4382 int bitrate; /* 100s of kilobits */
4383 int i;
4384 unsigned long flags;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004385
Linus Torvalds1da177e2005-04-16 15:20:36 -07004386 /* As the user space doesn't know our highest rate, it uses -1
4387 * to ask us to set the highest rate. Test it using "iwconfig
4388 * ethX rate auto" - Jean II */
4389 if (rrq->value == -1)
4390 bitrate = 110;
4391 else {
4392 if (rrq->value % 100000)
4393 return -EINVAL;
4394 bitrate = rrq->value / 100000;
4395 }
4396
David Kilroya94e8422009-02-04 23:05:44 +00004397 if ((bitrate != 10) && (bitrate != 20) &&
4398 (bitrate != 55) && (bitrate != 110))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004399 return -EINVAL;
4400
4401 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
David Kilroya94e8422009-02-04 23:05:44 +00004402 if ((bitrate_table[i].bitrate == bitrate) &&
4403 (bitrate_table[i].automatic == !rrq->fixed)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 ratemode = i;
4405 break;
4406 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00004407
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 if (ratemode == -1)
4409 return -EINVAL;
4410
4411 if (orinoco_lock(priv, &flags) != 0)
4412 return -EBUSY;
4413 priv->bitratemode = ratemode;
4414 orinoco_unlock(priv, &flags);
4415
Christoph Hellwig620554e2005-06-19 01:27:33 +02004416 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004417}
4418
Christoph Hellwig620554e2005-06-19 01:27:33 +02004419static int orinoco_ioctl_getrate(struct net_device *dev,
4420 struct iw_request_info *info,
4421 struct iw_param *rrq,
4422 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004423{
4424 struct orinoco_private *priv = netdev_priv(dev);
4425 hermes_t *hw = &priv->hw;
4426 int err = 0;
4427 int ratemode;
4428 int i;
4429 u16 val;
4430 unsigned long flags;
4431
4432 if (orinoco_lock(priv, &flags) != 0)
4433 return -EBUSY;
4434
4435 ratemode = priv->bitratemode;
4436
4437 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4438
4439 rrq->value = bitrate_table[ratemode].bitrate * 100000;
David Kilroya94e8422009-02-04 23:05:44 +00004440 rrq->fixed = !bitrate_table[ratemode].automatic;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004441 rrq->disabled = 0;
4442
4443 /* If the interface is running we try to find more about the
4444 current mode */
4445 if (netif_running(dev)) {
4446 err = hermes_read_wordrec(hw, USER_BAP,
4447 HERMES_RID_CURRENTTXRATE, &val);
4448 if (err)
4449 goto out;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004450
Linus Torvalds1da177e2005-04-16 15:20:36 -07004451 switch (priv->firmware_type) {
4452 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4453 /* Note : in Lucent firmware, the return value of
4454 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4455 * and therefore is totally different from the
4456 * encoding of HERMES_RID_CNFTXRATECONTROL.
4457 * Don't forget that 6Mb/s is really 5.5Mb/s */
4458 if (val == 6)
4459 rrq->value = 5500000;
4460 else
4461 rrq->value = val * 1000000;
4462 break;
4463 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4464 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4465 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4466 if (bitrate_table[i].intersil_txratectrl == val) {
4467 ratemode = i;
4468 break;
4469 }
4470 if (i >= BITRATE_TABLE_SIZE)
4471 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4472 dev->name, val);
4473
4474 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4475 break;
4476 default:
4477 BUG();
4478 }
4479 }
4480
4481 out:
4482 orinoco_unlock(priv, &flags);
4483
4484 return err;
4485}
4486
Christoph Hellwig620554e2005-06-19 01:27:33 +02004487static int orinoco_ioctl_setpower(struct net_device *dev,
4488 struct iw_request_info *info,
4489 struct iw_param *prq,
4490 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004491{
4492 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004493 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004494 unsigned long flags;
4495
4496 if (orinoco_lock(priv, &flags) != 0)
4497 return -EBUSY;
4498
4499 if (prq->disabled) {
4500 priv->pm_on = 0;
4501 } else {
4502 switch (prq->flags & IW_POWER_MODE) {
4503 case IW_POWER_UNICAST_R:
4504 priv->pm_mcast = 0;
4505 priv->pm_on = 1;
4506 break;
4507 case IW_POWER_ALL_R:
4508 priv->pm_mcast = 1;
4509 priv->pm_on = 1;
4510 break;
4511 case IW_POWER_ON:
4512 /* No flags : but we may have a value - Jean II */
4513 break;
4514 default:
4515 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05004517 }
David Kilroy6fe9deb2009-02-04 23:05:43 +00004518
Linus Torvalds1da177e2005-04-16 15:20:36 -07004519 if (prq->flags & IW_POWER_TIMEOUT) {
4520 priv->pm_on = 1;
4521 priv->pm_timeout = prq->value / 1000;
4522 }
4523 if (prq->flags & IW_POWER_PERIOD) {
4524 priv->pm_on = 1;
4525 priv->pm_period = prq->value / 1000;
4526 }
4527 /* It's valid to not have a value if we are just toggling
4528 * the flags... Jean II */
David Kilroya94e8422009-02-04 23:05:44 +00004529 if (!priv->pm_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004530 err = -EINVAL;
4531 goto out;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004532 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004533 }
4534
4535 out:
4536 orinoco_unlock(priv, &flags);
4537
4538 return err;
4539}
4540
Christoph Hellwig620554e2005-06-19 01:27:33 +02004541static int orinoco_ioctl_getpower(struct net_device *dev,
4542 struct iw_request_info *info,
4543 struct iw_param *prq,
4544 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004545{
4546 struct orinoco_private *priv = netdev_priv(dev);
4547 hermes_t *hw = &priv->hw;
4548 int err = 0;
4549 u16 enable, period, timeout, mcast;
4550 unsigned long flags;
4551
4552 if (orinoco_lock(priv, &flags) != 0)
4553 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004554
David Kilroyb2f30a02009-02-04 23:05:46 +00004555 err = hermes_read_wordrec(hw, USER_BAP,
4556 HERMES_RID_CNFPMENABLED, &enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004557 if (err)
4558 goto out;
4559
4560 err = hermes_read_wordrec(hw, USER_BAP,
4561 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4562 if (err)
4563 goto out;
4564
David Kilroyb2f30a02009-02-04 23:05:46 +00004565 err = hermes_read_wordrec(hw, USER_BAP,
4566 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004567 if (err)
4568 goto out;
4569
David Kilroyb2f30a02009-02-04 23:05:46 +00004570 err = hermes_read_wordrec(hw, USER_BAP,
4571 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004572 if (err)
4573 goto out;
4574
4575 prq->disabled = !enable;
4576 /* Note : by default, display the period */
4577 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4578 prq->flags = IW_POWER_TIMEOUT;
4579 prq->value = timeout * 1000;
4580 } else {
4581 prq->flags = IW_POWER_PERIOD;
4582 prq->value = period * 1000;
4583 }
4584 if (mcast)
4585 prq->flags |= IW_POWER_ALL_R;
4586 else
4587 prq->flags |= IW_POWER_UNICAST_R;
4588
4589 out:
4590 orinoco_unlock(priv, &flags);
4591
4592 return err;
4593}
4594
David Kilroyd03032a2008-08-21 23:28:02 +01004595static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4596 struct iw_request_info *info,
4597 union iwreq_data *wrqu,
4598 char *extra)
4599{
4600 struct orinoco_private *priv = netdev_priv(dev);
4601 struct iw_point *encoding = &wrqu->encoding;
4602 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4603 int idx, alg = ext->alg, set_key = 1;
4604 unsigned long flags;
4605 int err = -EINVAL;
4606 u16 key_len;
4607
4608 if (orinoco_lock(priv, &flags) != 0)
4609 return -EBUSY;
4610
4611 /* Determine and validate the key index */
4612 idx = encoding->flags & IW_ENCODE_INDEX;
4613 if (idx) {
Johannes Berg2c7060022008-10-30 22:09:54 +01004614 if ((idx < 1) || (idx > 4))
David Kilroyd03032a2008-08-21 23:28:02 +01004615 goto out;
4616 idx--;
4617 } else
4618 idx = priv->tx_key;
4619
4620 if (encoding->flags & IW_ENCODE_DISABLED)
David Kilroy6fe9deb2009-02-04 23:05:43 +00004621 alg = IW_ENCODE_ALG_NONE;
David Kilroyd03032a2008-08-21 23:28:02 +01004622
4623 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4624 /* Clear any TKIP TX key we had */
4625 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4626 }
4627
4628 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4629 priv->tx_key = idx;
4630 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4631 (ext->key_len > 0)) ? 1 : 0;
4632 }
4633
4634 if (set_key) {
4635 /* Set the requested key first */
4636 switch (alg) {
4637 case IW_ENCODE_ALG_NONE:
4638 priv->encode_alg = alg;
4639 priv->keys[idx].len = 0;
4640 break;
4641
4642 case IW_ENCODE_ALG_WEP:
4643 if (ext->key_len > SMALL_KEY_SIZE)
4644 key_len = LARGE_KEY_SIZE;
4645 else if (ext->key_len > 0)
4646 key_len = SMALL_KEY_SIZE;
4647 else
4648 goto out;
4649
4650 priv->encode_alg = alg;
4651 priv->keys[idx].len = cpu_to_le16(key_len);
4652
4653 key_len = min(ext->key_len, key_len);
4654
4655 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4656 memcpy(priv->keys[idx].data, ext->key, key_len);
4657 break;
4658
4659 case IW_ENCODE_ALG_TKIP:
4660 {
4661 hermes_t *hw = &priv->hw;
4662 u8 *tkip_iv = NULL;
4663
4664 if (!priv->has_wpa ||
4665 (ext->key_len > sizeof(priv->tkip_key[0])))
4666 goto out;
4667
4668 priv->encode_alg = alg;
4669 memset(&priv->tkip_key[idx], 0,
4670 sizeof(priv->tkip_key[idx]));
4671 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4672
4673 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4674 tkip_iv = &ext->rx_seq[0];
4675
4676 err = __orinoco_hw_set_tkip_key(hw, idx,
4677 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4678 (u8 *) &priv->tkip_key[idx],
4679 tkip_iv, NULL);
4680 if (err)
4681 printk(KERN_ERR "%s: Error %d setting TKIP key"
4682 "\n", dev->name, err);
4683
4684 goto out;
4685 }
4686 default:
4687 goto out;
4688 }
4689 }
4690 err = -EINPROGRESS;
4691 out:
4692 orinoco_unlock(priv, &flags);
4693
4694 return err;
4695}
4696
4697static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4698 struct iw_request_info *info,
4699 union iwreq_data *wrqu,
4700 char *extra)
4701{
4702 struct orinoco_private *priv = netdev_priv(dev);
4703 struct iw_point *encoding = &wrqu->encoding;
4704 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4705 int idx, max_key_len;
4706 unsigned long flags;
4707 int err;
4708
4709 if (orinoco_lock(priv, &flags) != 0)
4710 return -EBUSY;
4711
4712 err = -EINVAL;
4713 max_key_len = encoding->length - sizeof(*ext);
4714 if (max_key_len < 0)
4715 goto out;
4716
4717 idx = encoding->flags & IW_ENCODE_INDEX;
4718 if (idx) {
Johannes Berg2c7060022008-10-30 22:09:54 +01004719 if ((idx < 1) || (idx > 4))
David Kilroyd03032a2008-08-21 23:28:02 +01004720 goto out;
4721 idx--;
4722 } else
4723 idx = priv->tx_key;
4724
4725 encoding->flags = idx + 1;
4726 memset(ext, 0, sizeof(*ext));
4727
4728 ext->alg = priv->encode_alg;
4729 switch (priv->encode_alg) {
4730 case IW_ENCODE_ALG_NONE:
4731 ext->key_len = 0;
4732 encoding->flags |= IW_ENCODE_DISABLED;
4733 break;
4734 case IW_ENCODE_ALG_WEP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004735 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
4736 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004737 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4738 encoding->flags |= IW_ENCODE_ENABLED;
4739 break;
4740 case IW_ENCODE_ALG_TKIP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004741 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
4742 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004743 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4744 encoding->flags |= IW_ENCODE_ENABLED;
4745 break;
4746 }
4747
4748 err = 0;
4749 out:
4750 orinoco_unlock(priv, &flags);
4751
4752 return err;
4753}
4754
4755static int orinoco_ioctl_set_auth(struct net_device *dev,
4756 struct iw_request_info *info,
4757 union iwreq_data *wrqu, char *extra)
4758{
4759 struct orinoco_private *priv = netdev_priv(dev);
4760 hermes_t *hw = &priv->hw;
4761 struct iw_param *param = &wrqu->param;
4762 unsigned long flags;
4763 int ret = -EINPROGRESS;
4764
4765 if (orinoco_lock(priv, &flags) != 0)
4766 return -EBUSY;
4767
4768 switch (param->flags & IW_AUTH_INDEX) {
4769 case IW_AUTH_WPA_VERSION:
4770 case IW_AUTH_CIPHER_PAIRWISE:
4771 case IW_AUTH_CIPHER_GROUP:
4772 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4773 case IW_AUTH_PRIVACY_INVOKED:
4774 case IW_AUTH_DROP_UNENCRYPTED:
4775 /*
4776 * orinoco does not use these parameters
4777 */
4778 break;
4779
4780 case IW_AUTH_KEY_MGMT:
4781 /* wl_lkm implies value 2 == PSK for Hermes I
4782 * which ties in with WEXT
4783 * no other hints tho :(
4784 */
4785 priv->key_mgmt = param->value;
4786 break;
4787
4788 case IW_AUTH_TKIP_COUNTERMEASURES:
4789 /* When countermeasures are enabled, shut down the
4790 * card; when disabled, re-enable the card. This must
4791 * take effect immediately.
4792 *
4793 * TODO: Make sure that the EAPOL message is getting
4794 * out before card disabled
4795 */
4796 if (param->value) {
4797 priv->tkip_cm_active = 1;
4798 ret = hermes_enable_port(hw, 0);
4799 } else {
4800 priv->tkip_cm_active = 0;
4801 ret = hermes_disable_port(hw, 0);
4802 }
4803 break;
4804
4805 case IW_AUTH_80211_AUTH_ALG:
4806 if (param->value & IW_AUTH_ALG_SHARED_KEY)
4807 priv->wep_restrict = 1;
4808 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
4809 priv->wep_restrict = 0;
4810 else
4811 ret = -EINVAL;
4812 break;
4813
4814 case IW_AUTH_WPA_ENABLED:
4815 if (priv->has_wpa) {
4816 priv->wpa_enabled = param->value ? 1 : 0;
4817 } else {
4818 if (param->value)
4819 ret = -EOPNOTSUPP;
4820 /* else silently accept disable of WPA */
4821 priv->wpa_enabled = 0;
4822 }
4823 break;
4824
4825 default:
4826 ret = -EOPNOTSUPP;
4827 }
4828
4829 orinoco_unlock(priv, &flags);
4830 return ret;
4831}
4832
4833static int orinoco_ioctl_get_auth(struct net_device *dev,
4834 struct iw_request_info *info,
4835 union iwreq_data *wrqu, char *extra)
4836{
4837 struct orinoco_private *priv = netdev_priv(dev);
4838 struct iw_param *param = &wrqu->param;
4839 unsigned long flags;
4840 int ret = 0;
4841
4842 if (orinoco_lock(priv, &flags) != 0)
4843 return -EBUSY;
4844
4845 switch (param->flags & IW_AUTH_INDEX) {
4846 case IW_AUTH_KEY_MGMT:
4847 param->value = priv->key_mgmt;
4848 break;
4849
4850 case IW_AUTH_TKIP_COUNTERMEASURES:
4851 param->value = priv->tkip_cm_active;
4852 break;
4853
4854 case IW_AUTH_80211_AUTH_ALG:
4855 if (priv->wep_restrict)
4856 param->value = IW_AUTH_ALG_SHARED_KEY;
4857 else
4858 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
4859 break;
4860
4861 case IW_AUTH_WPA_ENABLED:
4862 param->value = priv->wpa_enabled;
4863 break;
4864
4865 default:
4866 ret = -EOPNOTSUPP;
4867 }
4868
4869 orinoco_unlock(priv, &flags);
4870 return ret;
4871}
4872
4873static int orinoco_ioctl_set_genie(struct net_device *dev,
4874 struct iw_request_info *info,
4875 union iwreq_data *wrqu, char *extra)
4876{
4877 struct orinoco_private *priv = netdev_priv(dev);
4878 u8 *buf;
4879 unsigned long flags;
David Kilroyd03032a2008-08-21 23:28:02 +01004880
Johannes Berg2c7060022008-10-30 22:09:54 +01004881 /* cut off at IEEE80211_MAX_DATA_LEN */
4882 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
David Kilroyd03032a2008-08-21 23:28:02 +01004883 (wrqu->data.length && (extra == NULL)))
4884 return -EINVAL;
4885
David Kilroyd03032a2008-08-21 23:28:02 +01004886 if (wrqu->data.length) {
4887 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004888 if (buf == NULL)
4889 return -ENOMEM;
David Kilroyd03032a2008-08-21 23:28:02 +01004890
4891 memcpy(buf, extra, wrqu->data.length);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004892 } else
4893 buf = NULL;
4894
4895 if (orinoco_lock(priv, &flags) != 0) {
4896 kfree(buf);
4897 return -EBUSY;
David Kilroyd03032a2008-08-21 23:28:02 +01004898 }
4899
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004900 kfree(priv->wpa_ie);
4901 priv->wpa_ie = buf;
4902 priv->wpa_ie_len = wrqu->data.length;
4903
David Kilroyd03032a2008-08-21 23:28:02 +01004904 if (priv->wpa_ie) {
4905 /* Looks like wl_lkm wants to check the auth alg, and
4906 * somehow pass it to the firmware.
4907 * Instead it just calls the key mgmt rid
4908 * - we do this in set auth.
4909 */
4910 }
4911
David Kilroyd03032a2008-08-21 23:28:02 +01004912 orinoco_unlock(priv, &flags);
Andrey Borzenkov7fe99c42009-01-20 20:26:46 +03004913 return 0;
David Kilroyd03032a2008-08-21 23:28:02 +01004914}
4915
4916static int orinoco_ioctl_get_genie(struct net_device *dev,
4917 struct iw_request_info *info,
4918 union iwreq_data *wrqu, char *extra)
4919{
4920 struct orinoco_private *priv = netdev_priv(dev);
4921 unsigned long flags;
4922 int err = 0;
4923
4924 if (orinoco_lock(priv, &flags) != 0)
4925 return -EBUSY;
4926
4927 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
4928 wrqu->data.length = 0;
4929 goto out;
4930 }
4931
4932 if (wrqu->data.length < priv->wpa_ie_len) {
4933 err = -E2BIG;
4934 goto out;
4935 }
4936
4937 wrqu->data.length = priv->wpa_ie_len;
4938 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
4939
4940out:
4941 orinoco_unlock(priv, &flags);
4942 return err;
4943}
4944
4945static int orinoco_ioctl_set_mlme(struct net_device *dev,
4946 struct iw_request_info *info,
4947 union iwreq_data *wrqu, char *extra)
4948{
4949 struct orinoco_private *priv = netdev_priv(dev);
4950 hermes_t *hw = &priv->hw;
4951 struct iw_mlme *mlme = (struct iw_mlme *)extra;
4952 unsigned long flags;
4953 int ret = 0;
4954
4955 if (orinoco_lock(priv, &flags) != 0)
4956 return -EBUSY;
4957
4958 switch (mlme->cmd) {
4959 case IW_MLME_DEAUTH:
4960 /* silently ignore */
4961 break;
4962
4963 case IW_MLME_DISASSOC:
4964 {
4965 struct {
4966 u8 addr[ETH_ALEN];
4967 __le16 reason_code;
4968 } __attribute__ ((packed)) buf;
4969
4970 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
4971 buf.reason_code = cpu_to_le16(mlme->reason_code);
4972 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
4973 HERMES_RID_CNFDISASSOCIATE,
4974 &buf);
4975 break;
4976 }
4977 default:
4978 ret = -EOPNOTSUPP;
4979 }
4980
4981 orinoco_unlock(priv, &flags);
4982 return ret;
4983}
4984
Christoph Hellwig620554e2005-06-19 01:27:33 +02004985static int orinoco_ioctl_getretry(struct net_device *dev,
4986 struct iw_request_info *info,
4987 struct iw_param *rrq,
4988 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004989{
4990 struct orinoco_private *priv = netdev_priv(dev);
4991 hermes_t *hw = &priv->hw;
4992 int err = 0;
4993 u16 short_limit, long_limit, lifetime;
4994 unsigned long flags;
4995
4996 if (orinoco_lock(priv, &flags) != 0)
4997 return -EBUSY;
David Kilroy6fe9deb2009-02-04 23:05:43 +00004998
Linus Torvalds1da177e2005-04-16 15:20:36 -07004999 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
5000 &short_limit);
5001 if (err)
5002 goto out;
5003
5004 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
5005 &long_limit);
5006 if (err)
5007 goto out;
5008
5009 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
5010 &lifetime);
5011 if (err)
5012 goto out;
5013
5014 rrq->disabled = 0; /* Can't be disabled */
5015
5016 /* Note : by default, display the retry number */
5017 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
5018 rrq->flags = IW_RETRY_LIFETIME;
5019 rrq->value = lifetime * 1000; /* ??? */
5020 } else {
5021 /* By default, display the min number */
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07005022 if ((rrq->flags & IW_RETRY_LONG)) {
5023 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005024 rrq->value = long_limit;
5025 } else {
5026 rrq->flags = IW_RETRY_LIMIT;
5027 rrq->value = short_limit;
David Kilroya94e8422009-02-04 23:05:44 +00005028 if (short_limit != long_limit)
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07005029 rrq->flags |= IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005030 }
5031 }
5032
5033 out:
5034 orinoco_unlock(priv, &flags);
5035
5036 return err;
5037}
5038
Christoph Hellwig620554e2005-06-19 01:27:33 +02005039static int orinoco_ioctl_reset(struct net_device *dev,
5040 struct iw_request_info *info,
5041 void *wrqu,
5042 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005043{
5044 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005045
David Kilroya94e8422009-02-04 23:05:44 +00005046 if (!capable(CAP_NET_ADMIN))
Christoph Hellwig620554e2005-06-19 01:27:33 +02005047 return -EPERM;
5048
5049 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
5050 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
5051
5052 /* Firmware reset */
David Howellsc4028952006-11-22 14:57:56 +00005053 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005054 } else {
5055 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
5056
5057 schedule_work(&priv->reset_work);
5058 }
5059
5060 return 0;
5061}
5062
5063static int orinoco_ioctl_setibssport(struct net_device *dev,
5064 struct iw_request_info *info,
5065 void *wrqu,
5066 char *extra)
5067
5068{
5069 struct orinoco_private *priv = netdev_priv(dev);
David Kilroya94e8422009-02-04 23:05:44 +00005070 int val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 unsigned long flags;
5072
5073 if (orinoco_lock(priv, &flags) != 0)
5074 return -EBUSY;
5075
5076 priv->ibss_port = val ;
5077
5078 /* Actually update the mode we are using */
5079 set_port_type(priv);
5080
5081 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005082 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005083}
5084
Christoph Hellwig620554e2005-06-19 01:27:33 +02005085static int orinoco_ioctl_getibssport(struct net_device *dev,
5086 struct iw_request_info *info,
5087 void *wrqu,
5088 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089{
5090 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005091 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005092
5093 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005094 return 0;
5095}
5096
Christoph Hellwig620554e2005-06-19 01:27:33 +02005097static int orinoco_ioctl_setport3(struct net_device *dev,
5098 struct iw_request_info *info,
5099 void *wrqu,
5100 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005101{
5102 struct orinoco_private *priv = netdev_priv(dev);
David Kilroya94e8422009-02-04 23:05:44 +00005103 int val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104 int err = 0;
5105 unsigned long flags;
5106
5107 if (orinoco_lock(priv, &flags) != 0)
5108 return -EBUSY;
5109
5110 switch (val) {
5111 case 0: /* Try to do IEEE ad-hoc mode */
David Kilroya94e8422009-02-04 23:05:44 +00005112 if (!priv->has_ibss) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005113 err = -EINVAL;
5114 break;
5115 }
5116 priv->prefer_port3 = 0;
David Kilroy6fe9deb2009-02-04 23:05:43 +00005117
Linus Torvalds1da177e2005-04-16 15:20:36 -07005118 break;
5119
5120 case 1: /* Try to do Lucent proprietary ad-hoc mode */
David Kilroya94e8422009-02-04 23:05:44 +00005121 if (!priv->has_port3) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005122 err = -EINVAL;
5123 break;
5124 }
5125 priv->prefer_port3 = 1;
5126 break;
5127
5128 default:
5129 err = -EINVAL;
5130 }
5131
David Kilroya94e8422009-02-04 23:05:44 +00005132 if (!err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005133 /* Actually update the mode we are using */
5134 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005135 err = -EINPROGRESS;
5136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137
5138 orinoco_unlock(priv, &flags);
5139
5140 return err;
5141}
5142
Christoph Hellwig620554e2005-06-19 01:27:33 +02005143static int orinoco_ioctl_getport3(struct net_device *dev,
5144 struct iw_request_info *info,
5145 void *wrqu,
5146 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005147{
5148 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005149 int *val = (int *) extra;
5150
5151 *val = priv->prefer_port3;
5152 return 0;
5153}
5154
5155static int orinoco_ioctl_setpreamble(struct net_device *dev,
5156 struct iw_request_info *info,
5157 void *wrqu,
5158 char *extra)
5159{
5160 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005161 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005162 int val;
5163
David Kilroya94e8422009-02-04 23:05:44 +00005164 if (!priv->has_preamble)
Christoph Hellwig620554e2005-06-19 01:27:33 +02005165 return -EOPNOTSUPP;
5166
5167 /* 802.11b has recently defined some short preamble.
5168 * Basically, the Phy header has been reduced in size.
5169 * This increase performance, especially at high rates
5170 * (the preamble is transmitted at 1Mb/s), unfortunately
5171 * this give compatibility troubles... - Jean II */
David Kilroya94e8422009-02-04 23:05:44 +00005172 val = *((int *) extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173
5174 if (orinoco_lock(priv, &flags) != 0)
5175 return -EBUSY;
5176
Christoph Hellwig620554e2005-06-19 01:27:33 +02005177 if (val)
5178 priv->preamble = 1;
5179 else
5180 priv->preamble = 0;
5181
Linus Torvalds1da177e2005-04-16 15:20:36 -07005182 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005183
5184 return -EINPROGRESS; /* Call commit handler */
5185}
5186
5187static int orinoco_ioctl_getpreamble(struct net_device *dev,
5188 struct iw_request_info *info,
5189 void *wrqu,
5190 char *extra)
5191{
5192 struct orinoco_private *priv = netdev_priv(dev);
5193 int *val = (int *) extra;
5194
David Kilroya94e8422009-02-04 23:05:44 +00005195 if (!priv->has_preamble)
Christoph Hellwig620554e2005-06-19 01:27:33 +02005196 return -EOPNOTSUPP;
5197
5198 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 return 0;
5200}
5201
Christoph Hellwig620554e2005-06-19 01:27:33 +02005202/* ioctl interface to hermes_read_ltv()
5203 * To use with iwpriv, pass the RID as the token argument, e.g.
5204 * iwpriv get_rid [0xfc00]
5205 * At least Wireless Tools 25 is required to use iwpriv.
5206 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5207static int orinoco_ioctl_getrid(struct net_device *dev,
5208 struct iw_request_info *info,
5209 struct iw_point *data,
5210 char *extra)
5211{
5212 struct orinoco_private *priv = netdev_priv(dev);
5213 hermes_t *hw = &priv->hw;
5214 int rid = data->flags;
5215 u16 length;
5216 int err;
5217 unsigned long flags;
5218
5219 /* It's a "get" function, but we don't want users to access the
5220 * WEP key and other raw firmware data */
David Kilroya94e8422009-02-04 23:05:44 +00005221 if (!capable(CAP_NET_ADMIN))
Christoph Hellwig620554e2005-06-19 01:27:33 +02005222 return -EPERM;
5223
5224 if (rid < 0xfc00 || rid > 0xffff)
5225 return -EINVAL;
5226
5227 if (orinoco_lock(priv, &flags) != 0)
5228 return -EBUSY;
5229
5230 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5231 extra);
5232 if (err)
5233 goto out;
5234
5235 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5236 MAX_RID_LEN);
5237
5238 out:
5239 orinoco_unlock(priv, &flags);
5240 return err;
5241}
5242
David Kilroy17a1a882008-08-21 23:27:47 +01005243/* Trigger a scan (look for other cells in the vicinity) */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005244static int orinoco_ioctl_setscan(struct net_device *dev,
5245 struct iw_request_info *info,
David Kilroy9930cce2008-09-13 12:22:05 +01005246 struct iw_point *srq,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005247 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248{
5249 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005250 hermes_t *hw = &priv->hw;
David Kilroy0753bba2008-08-21 23:27:46 +01005251 struct iw_scan_req *si = (struct iw_scan_req *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005252 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005253 unsigned long flags;
5254
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005255 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08005256 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005257 * perform scanning.
5258 * This is not an error, while the device perform scanning,
5259 * traffic doesn't flow, so it's a perfect DoS...
5260 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005261
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005262 if (orinoco_lock(priv, &flags) != 0)
5263 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005265 /* Scanning with port 0 disabled would fail */
5266 if (!netif_running(dev)) {
5267 err = -ENETDOWN;
5268 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005271 /* In monitor mode, the scan results are always empty.
5272 * Probe responses are passed to the driver as received
5273 * frames and could be processed in software. */
5274 if (priv->iw_mode == IW_MODE_MONITOR) {
5275 err = -EOPNOTSUPP;
5276 goto out;
5277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005278
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005279 /* Note : because we don't lock out the irq handler, the way
5280 * we access scan variables in priv is critical.
5281 * o scan_inprogress : not touched by irq handler
5282 * o scan_mode : not touched by irq handler
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005283 * Before modifying anything on those variables, please think hard !
5284 * Jean II */
5285
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005286 /* Save flags */
5287 priv->scan_mode = srq->flags;
5288
5289 /* Always trigger scanning, even if it's in progress.
5290 * This way, if the info frame get lost, we will recover somewhat
5291 * gracefully - Jean II */
5292
5293 if (priv->has_hostscan) {
5294 switch (priv->firmware_type) {
5295 case FIRMWARE_TYPE_SYMBOL:
5296 err = hermes_write_wordrec(hw, USER_BAP,
David Kilroyb2f30a02009-02-04 23:05:46 +00005297 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5298 HERMES_HOSTSCAN_SYMBOL_ONCE |
5299 HERMES_HOSTSCAN_SYMBOL_BCAST);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005300 break;
5301 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04005302 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005303
5304 req[0] = cpu_to_le16(0x3fff); /* All channels */
5305 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5306 req[2] = 0; /* Any ESSID */
5307 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5308 HERMES_RID_CNFHOSTSCAN, &req);
5309 }
5310 break;
5311 case FIRMWARE_TYPE_AGERE:
David Kilroy0753bba2008-08-21 23:27:46 +01005312 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5313 struct hermes_idstring idbuf;
5314 size_t len = min(sizeof(idbuf.val),
5315 (size_t) si->essid_len);
5316 idbuf.len = cpu_to_le16(len);
5317 memcpy(idbuf.val, si->essid, len);
5318
5319 err = hermes_write_ltv(hw, USER_BAP,
5320 HERMES_RID_CNFSCANSSID_AGERE,
5321 HERMES_BYTES_TO_RECLEN(len + 2),
5322 &idbuf);
5323 } else
5324 err = hermes_write_wordrec(hw, USER_BAP,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005325 HERMES_RID_CNFSCANSSID_AGERE,
5326 0); /* Any ESSID */
5327 if (err)
5328 break;
5329
David Kilroy01632fa2008-08-21 23:27:58 +01005330 if (priv->has_ext_scan) {
5331 /* Clear scan results at the start of
5332 * an extended scan */
5333 orinoco_clear_scan_results(priv,
5334 msecs_to_jiffies(15000));
5335
5336 /* TODO: Is this available on older firmware?
5337 * Can we use it to scan specific channels
5338 * for IW_SCAN_THIS_FREQ? */
5339 err = hermes_write_wordrec(hw, USER_BAP,
5340 HERMES_RID_CNFSCANCHANNELS2GHZ,
5341 0x7FFF);
5342 if (err)
5343 goto out;
5344
5345 err = hermes_inquire(hw,
5346 HERMES_INQ_CHANNELINFO);
5347 } else
5348 err = hermes_inquire(hw, HERMES_INQ_SCAN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005349 break;
5350 }
5351 } else
5352 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5353
5354 /* One more client */
David Kilroya94e8422009-02-04 23:05:44 +00005355 if (!err)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005356 priv->scan_inprogress = 1;
5357
5358 out:
5359 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 return err;
5361}
5362
Dan Williams1e3428e2007-10-10 23:56:25 -04005363#define MAX_CUSTOM_LEN 64
5364
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005365/* Translate scan data returned from the card to a card independant
David Kilroy17a1a882008-08-21 23:27:47 +01005366 * format that the Wireless Tools will understand - Jean II */
Dan Williams1e3428e2007-10-10 23:56:25 -04005367static inline char *orinoco_translate_scan(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07005368 struct iw_request_info *info,
Dan Williams1e3428e2007-10-10 23:56:25 -04005369 char *current_ev,
5370 char *end_buf,
5371 union hermes_scan_info *bss,
Pavel Roskindfe1baf2008-11-10 09:25:53 -05005372 unsigned long last_scanned)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005373{
5374 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005375 u16 capabilities;
5376 u16 channel;
5377 struct iw_event iwe; /* Temporary buffer */
Dan Williams1e3428e2007-10-10 23:56:25 -04005378 char custom[MAX_CUSTOM_LEN];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005379
David Kilroy17a1a882008-08-21 23:27:47 +01005380 memset(&iwe, 0, sizeof(iwe));
5381
Dan Williams1e3428e2007-10-10 23:56:25 -04005382 /* First entry *MUST* be the AP MAC address */
5383 iwe.cmd = SIOCGIWAP;
5384 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5385 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07005386 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5387 &iwe, IW_EV_ADDR_LEN);
Dan Williams1e3428e2007-10-10 23:56:25 -04005388
5389 /* Other entries will be displayed in the order we give them */
5390
5391 /* Add the ESSID */
5392 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5393 if (iwe.u.data.length > 32)
5394 iwe.u.data.length = 32;
5395 iwe.cmd = SIOCGIWESSID;
5396 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005397 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5398 &iwe, bss->a.essid);
Dan Williams1e3428e2007-10-10 23:56:25 -04005399
5400 /* Add mode */
5401 iwe.cmd = SIOCGIWMODE;
5402 capabilities = le16_to_cpu(bss->a.capabilities);
David Kilroy17a1a882008-08-21 23:27:47 +01005403 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5404 if (capabilities & WLAN_CAPABILITY_ESS)
Dan Williams1e3428e2007-10-10 23:56:25 -04005405 iwe.u.mode = IW_MODE_MASTER;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005406 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005407 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07005408 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5409 &iwe, IW_EV_UINT_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005410 }
5411
Dan Williams1e3428e2007-10-10 23:56:25 -04005412 channel = bss->s.channel;
5413 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
David Kilroy17a1a882008-08-21 23:27:47 +01005414 /* Add channel and frequency */
Dan Williams1e3428e2007-10-10 23:56:25 -04005415 iwe.cmd = SIOCGIWFREQ;
David Kilroy17a1a882008-08-21 23:27:47 +01005416 iwe.u.freq.m = channel;
5417 iwe.u.freq.e = 0;
5418 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5419 &iwe, IW_EV_FREQ_LEN);
5420
David Kilroy9ee677c2008-12-23 14:03:38 +00005421 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
Dan Williams1e3428e2007-10-10 23:56:25 -04005422 iwe.u.freq.e = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005423 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
Dan Williams1e3428e2007-10-10 23:56:25 -04005424 &iwe, IW_EV_FREQ_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005425 }
5426
David Kilroy17a1a882008-08-21 23:27:47 +01005427 /* Add quality statistics. level and noise in dB. No link quality */
Dan Williams1e3428e2007-10-10 23:56:25 -04005428 iwe.cmd = IWEVQUAL;
David Kilroy17a1a882008-08-21 23:27:47 +01005429 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
Dan Williams1e3428e2007-10-10 23:56:25 -04005430 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5431 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5432 /* Wireless tools prior to 27.pre22 will show link quality
5433 * anyway, so we provide a reasonable value. */
5434 if (iwe.u.qual.level > iwe.u.qual.noise)
5435 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5436 else
5437 iwe.u.qual.qual = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005438 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5439 &iwe, IW_EV_QUAL_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005440
Dan Williams1e3428e2007-10-10 23:56:25 -04005441 /* Add encryption capability */
5442 iwe.cmd = SIOCGIWENCODE;
David Kilroy17a1a882008-08-21 23:27:47 +01005443 if (capabilities & WLAN_CAPABILITY_PRIVACY)
Dan Williams1e3428e2007-10-10 23:56:25 -04005444 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5445 else
5446 iwe.u.data.flags = IW_ENCODE_DISABLED;
5447 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005448 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
David Kilroy17a1a882008-08-21 23:27:47 +01005449 &iwe, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005450
Dan Williams1e3428e2007-10-10 23:56:25 -04005451 /* Bit rate is not available in Lucent/Agere firmwares */
5452 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
David S. Millerccc58052008-06-16 18:50:49 -07005453 char *current_val = current_ev + iwe_stream_lcp_len(info);
Dan Williams1e3428e2007-10-10 23:56:25 -04005454 int i;
5455 int step;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005456
Dan Williams1e3428e2007-10-10 23:56:25 -04005457 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5458 step = 2;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005459 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005460 step = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005461
Dan Williams1e3428e2007-10-10 23:56:25 -04005462 iwe.cmd = SIOCGIWRATE;
5463 /* Those two flags are ignored... */
5464 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5465 /* Max 10 values */
5466 for (i = 0; i < 10; i += step) {
5467 /* NULL terminated */
5468 if (bss->p.rates[i] == 0x0)
5469 break;
5470 /* Bit rate given in 500 kb/s units (+ 0x80) */
David Kilroy17a1a882008-08-21 23:27:47 +01005471 iwe.u.bitrate.value =
5472 ((bss->p.rates[i] & 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07005473 current_val = iwe_stream_add_value(info, current_ev,
5474 current_val,
Dan Williams1e3428e2007-10-10 23:56:25 -04005475 end_buf, &iwe,
5476 IW_EV_PARAM_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005477 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005478 /* Check if we added any event */
David S. Millerccc58052008-06-16 18:50:49 -07005479 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
Dan Williams1e3428e2007-10-10 23:56:25 -04005480 current_ev = current_val;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005481 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005482
David Kilroy17a1a882008-08-21 23:27:47 +01005483 /* Beacon interval */
5484 iwe.cmd = IWEVCUSTOM;
5485 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5486 "bcn_int=%d",
5487 le16_to_cpu(bss->a.beacon_interv));
5488 if (iwe.u.data.length)
5489 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5490 &iwe, custom);
5491
5492 /* Capabilites */
5493 iwe.cmd = IWEVCUSTOM;
5494 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5495 "capab=0x%04x",
5496 capabilities);
5497 if (iwe.u.data.length)
5498 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5499 &iwe, custom);
5500
5501 /* Add EXTRA: Age to display seconds since last beacon/probe response
5502 * for given network. */
5503 iwe.cmd = IWEVCUSTOM;
5504 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5505 " Last beacon: %dms ago",
5506 jiffies_to_msecs(jiffies - last_scanned));
5507 if (iwe.u.data.length)
5508 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5509 &iwe, custom);
5510
Dan Williams1e3428e2007-10-10 23:56:25 -04005511 return current_ev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005512}
5513
David Kilroy01632fa2008-08-21 23:27:58 +01005514static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5515 struct iw_request_info *info,
5516 char *current_ev,
5517 char *end_buf,
5518 struct agere_ext_scan_info *bss,
Pavel Roskindfe1baf2008-11-10 09:25:53 -05005519 unsigned long last_scanned)
David Kilroy01632fa2008-08-21 23:27:58 +01005520{
5521 u16 capabilities;
5522 u16 channel;
5523 struct iw_event iwe; /* Temporary buffer */
5524 char custom[MAX_CUSTOM_LEN];
5525 u8 *ie;
5526
5527 memset(&iwe, 0, sizeof(iwe));
5528
5529 /* First entry *MUST* be the AP MAC address */
5530 iwe.cmd = SIOCGIWAP;
5531 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5532 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5533 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5534 &iwe, IW_EV_ADDR_LEN);
5535
5536 /* Other entries will be displayed in the order we give them */
5537
5538 /* Add the ESSID */
5539 ie = bss->data;
5540 iwe.u.data.length = ie[1];
5541 if (iwe.u.data.length) {
5542 if (iwe.u.data.length > 32)
5543 iwe.u.data.length = 32;
5544 iwe.cmd = SIOCGIWESSID;
5545 iwe.u.data.flags = 1;
5546 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5547 &iwe, &ie[2]);
5548 }
5549
5550 /* Add mode */
5551 capabilities = le16_to_cpu(bss->capabilities);
5552 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5553 iwe.cmd = SIOCGIWMODE;
5554 if (capabilities & WLAN_CAPABILITY_ESS)
5555 iwe.u.mode = IW_MODE_MASTER;
5556 else
5557 iwe.u.mode = IW_MODE_ADHOC;
5558 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5559 &iwe, IW_EV_UINT_LEN);
5560 }
5561
Johannes Berg2c7060022008-10-30 22:09:54 +01005562 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
David Kilroy01632fa2008-08-21 23:27:58 +01005563 channel = ie ? ie[2] : 0;
5564 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5565 /* Add channel and frequency */
5566 iwe.cmd = SIOCGIWFREQ;
5567 iwe.u.freq.m = channel;
5568 iwe.u.freq.e = 0;
5569 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5570 &iwe, IW_EV_FREQ_LEN);
5571
David Kilroy9ee677c2008-12-23 14:03:38 +00005572 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
David Kilroy01632fa2008-08-21 23:27:58 +01005573 iwe.u.freq.e = 1;
5574 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5575 &iwe, IW_EV_FREQ_LEN);
5576 }
5577
5578 /* Add quality statistics. level and noise in dB. No link quality */
5579 iwe.cmd = IWEVQUAL;
5580 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5581 iwe.u.qual.level = bss->level - 0x95;
5582 iwe.u.qual.noise = bss->noise - 0x95;
5583 /* Wireless tools prior to 27.pre22 will show link quality
5584 * anyway, so we provide a reasonable value. */
5585 if (iwe.u.qual.level > iwe.u.qual.noise)
5586 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5587 else
5588 iwe.u.qual.qual = 0;
5589 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5590 &iwe, IW_EV_QUAL_LEN);
5591
5592 /* Add encryption capability */
5593 iwe.cmd = SIOCGIWENCODE;
5594 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5595 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5596 else
5597 iwe.u.data.flags = IW_ENCODE_DISABLED;
5598 iwe.u.data.length = 0;
5599 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5600 &iwe, NULL);
5601
5602 /* WPA IE */
5603 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5604 if (ie) {
5605 iwe.cmd = IWEVGENIE;
5606 iwe.u.data.length = ie[1] + 2;
5607 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5608 &iwe, ie);
5609 }
5610
5611 /* RSN IE */
Johannes Berg2c7060022008-10-30 22:09:54 +01005612 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
David Kilroy01632fa2008-08-21 23:27:58 +01005613 if (ie) {
5614 iwe.cmd = IWEVGENIE;
5615 iwe.u.data.length = ie[1] + 2;
5616 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5617 &iwe, ie);
5618 }
5619
Johannes Berg2c7060022008-10-30 22:09:54 +01005620 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
David Kilroy01632fa2008-08-21 23:27:58 +01005621 if (ie) {
5622 char *p = current_ev + iwe_stream_lcp_len(info);
5623 int i;
5624
5625 iwe.cmd = SIOCGIWRATE;
5626 /* Those two flags are ignored... */
5627 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5628
5629 for (i = 2; i < (ie[1] + 2); i++) {
5630 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5631 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5632 &iwe, IW_EV_PARAM_LEN);
5633 }
5634 /* Check if we added any event */
5635 if (p > (current_ev + iwe_stream_lcp_len(info)))
5636 current_ev = p;
5637 }
5638
5639 /* Timestamp */
5640 iwe.cmd = IWEVCUSTOM;
David Kilroy75d31cf2008-09-12 22:28:18 +01005641 iwe.u.data.length =
5642 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
5643 (unsigned long long) le64_to_cpu(bss->timestamp));
David Kilroy01632fa2008-08-21 23:27:58 +01005644 if (iwe.u.data.length)
5645 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5646 &iwe, custom);
5647
5648 /* Beacon interval */
5649 iwe.cmd = IWEVCUSTOM;
5650 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5651 "bcn_int=%d",
5652 le16_to_cpu(bss->beacon_interval));
5653 if (iwe.u.data.length)
5654 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5655 &iwe, custom);
5656
5657 /* Capabilites */
5658 iwe.cmd = IWEVCUSTOM;
5659 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5660 "capab=0x%04x",
5661 capabilities);
5662 if (iwe.u.data.length)
5663 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5664 &iwe, custom);
5665
5666 /* Add EXTRA: Age to display seconds since last beacon/probe response
5667 * for given network. */
5668 iwe.cmd = IWEVCUSTOM;
5669 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5670 " Last beacon: %dms ago",
5671 jiffies_to_msecs(jiffies - last_scanned));
5672 if (iwe.u.data.length)
5673 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5674 &iwe, custom);
5675
5676 return current_ev;
5677}
5678
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005679/* Return results of a scan */
5680static int orinoco_ioctl_getscan(struct net_device *dev,
5681 struct iw_request_info *info,
5682 struct iw_point *srq,
5683 char *extra)
5684{
5685 struct orinoco_private *priv = netdev_priv(dev);
5686 int err = 0;
5687 unsigned long flags;
Dan Williams1e3428e2007-10-10 23:56:25 -04005688 char *current_ev = extra;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005689
5690 if (orinoco_lock(priv, &flags) != 0)
5691 return -EBUSY;
5692
Dan Williams1e3428e2007-10-10 23:56:25 -04005693 if (priv->scan_inprogress) {
5694 /* Important note : we don't want to block the caller
5695 * until results are ready for various reasons.
5696 * First, managing wait queues is complex and racy.
5697 * Second, we grab some rtnetlink lock before comming
5698 * here (in dev_ioctl()).
5699 * Third, we generate an Wireless Event, so the
5700 * caller can wait itself on that - Jean II */
5701 err = -EAGAIN;
5702 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005703 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005704
David Kilroy01632fa2008-08-21 23:27:58 +01005705 if (priv->has_ext_scan) {
5706 struct xbss_element *bss;
Dan Williams1e3428e2007-10-10 23:56:25 -04005707
David Kilroy01632fa2008-08-21 23:27:58 +01005708 list_for_each_entry(bss, &priv->bss_list, list) {
5709 /* Translate this entry to WE format */
5710 current_ev =
5711 orinoco_translate_ext_scan(dev, info,
5712 current_ev,
5713 extra + srq->length,
5714 &bss->bss,
5715 bss->last_scanned);
5716
5717 /* Check if there is space for one more entry */
5718 if ((extra + srq->length - current_ev)
5719 <= IW_EV_ADDR_LEN) {
5720 /* Ask user space to try again with a
5721 * bigger buffer */
5722 err = -E2BIG;
5723 goto out;
5724 }
5725 }
5726
5727 } else {
5728 struct bss_element *bss;
5729
5730 list_for_each_entry(bss, &priv->bss_list, list) {
5731 /* Translate this entry to WE format */
5732 current_ev = orinoco_translate_scan(dev, info,
5733 current_ev,
5734 extra + srq->length,
5735 &bss->bss,
5736 bss->last_scanned);
5737
5738 /* Check if there is space for one more entry */
5739 if ((extra + srq->length - current_ev)
5740 <= IW_EV_ADDR_LEN) {
5741 /* Ask user space to try again with a
5742 * bigger buffer */
5743 err = -E2BIG;
5744 goto out;
5745 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005746 }
5747 }
5748
5749 srq->length = (current_ev - extra);
5750 srq->flags = (__u16) priv->scan_mode;
5751
5752out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005753 orinoco_unlock(priv, &flags);
5754 return err;
5755}
5756
Christoph Hellwig620554e2005-06-19 01:27:33 +02005757/* Commit handler, called after set operations */
5758static int orinoco_ioctl_commit(struct net_device *dev,
5759 struct iw_request_info *info,
5760 void *wrqu,
5761 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762{
5763 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005764 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005766 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005767
Christoph Hellwig620554e2005-06-19 01:27:33 +02005768 if (!priv->open)
5769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005770
Christoph Hellwig620554e2005-06-19 01:27:33 +02005771 if (priv->broken_disableport) {
David Howellsc4028952006-11-22 14:57:56 +00005772 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005773 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005775
Christoph Hellwig620554e2005-06-19 01:27:33 +02005776 if (orinoco_lock(priv, &flags) != 0)
5777 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778
Christoph Hellwig620554e2005-06-19 01:27:33 +02005779 err = hermes_disable_port(hw, 0);
5780 if (err) {
5781 printk(KERN_WARNING "%s: Unable to disable port "
5782 "while reconfiguring card\n", dev->name);
5783 priv->broken_disableport = 1;
5784 goto out;
5785 }
5786
5787 err = __orinoco_program_rids(dev);
5788 if (err) {
5789 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5790 dev->name);
5791 goto out;
5792 }
5793
5794 err = hermes_enable_port(hw, 0);
5795 if (err) {
5796 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5797 dev->name);
5798 goto out;
5799 }
5800
5801 out:
5802 if (err) {
5803 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5804 schedule_work(&priv->reset_work);
5805 err = 0;
5806 }
5807
5808 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 return err;
5810}
5811
Christoph Hellwig620554e2005-06-19 01:27:33 +02005812static const struct iw_priv_args orinoco_privtab[] = {
5813 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5814 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5815 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5816 0, "set_port3" },
5817 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5818 "get_port3" },
5819 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5820 0, "set_preamble" },
5821 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5822 "get_preamble" },
5823 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5824 0, "set_ibssport" },
5825 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5826 "get_ibssport" },
5827 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5828 "get_rid" },
5829};
5830
5831
5832/*
5833 * Structures to export the Wireless Handlers
5834 */
5835
David Kilroy409644a2008-08-21 23:28:01 +01005836#define STD_IW_HANDLER(id, func) \
5837 [IW_IOCTL_IDX(id)] = (iw_handler) func
Christoph Hellwig620554e2005-06-19 01:27:33 +02005838static const iw_handler orinoco_handler[] = {
David Kilroy409644a2008-08-21 23:28:01 +01005839 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
5840 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
5841 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
5842 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
5843 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
5844 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
5845 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
5846 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
5847 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
5848 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
5849 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
5850 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
5851 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
5852 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
5853 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
5854 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
5855 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
5856 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
5857 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
5858 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
5859 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
5860 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
5861 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
5862 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
5863 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
5864 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
5865 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
5866 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
5867 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
5868 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
5869 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
5870 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
David Kilroyd03032a2008-08-21 23:28:02 +01005871 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
5872 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
5873 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
5874 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
5875 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
5876 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
5877 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
Christoph Hellwig620554e2005-06-19 01:27:33 +02005878};
5879
5880
5881/*
5882 Added typecasting since we no longer use iwreq_data -- Moustafa
5883 */
5884static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07005885 [0] = (iw_handler) orinoco_ioctl_reset,
5886 [1] = (iw_handler) orinoco_ioctl_reset,
5887 [2] = (iw_handler) orinoco_ioctl_setport3,
5888 [3] = (iw_handler) orinoco_ioctl_getport3,
5889 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5890 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5891 [6] = (iw_handler) orinoco_ioctl_setibssport,
5892 [7] = (iw_handler) orinoco_ioctl_getibssport,
5893 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005894};
5895
5896static const struct iw_handler_def orinoco_handler_def = {
5897 .num_standard = ARRAY_SIZE(orinoco_handler),
5898 .num_private = ARRAY_SIZE(orinoco_private_handler),
5899 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5900 .standard = orinoco_handler,
5901 .private = orinoco_private_handler,
5902 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04005903 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005904};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005906static void orinoco_get_drvinfo(struct net_device *dev,
5907 struct ethtool_drvinfo *info)
5908{
5909 struct orinoco_private *priv = netdev_priv(dev);
5910
5911 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5912 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5913 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07005914 if (dev->dev.parent)
Kay Sieversfb28ad32008-11-10 13:55:14 -08005915 strncpy(info->bus_info, dev_name(dev->dev.parent),
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005916 sizeof(info->bus_info) - 1);
5917 else
5918 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5919 "PCMCIA %p", priv->hw.iobase);
5920}
5921
Jeff Garzik7282d492006-09-13 14:30:00 -04005922static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005923 .get_drvinfo = orinoco_get_drvinfo,
5924 .get_link = ethtool_op_get_link,
5925};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005926
5927/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07005928/* Module initialization */
5929/********************************************************************/
5930
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931/* Can't be declared "const" or the whole __initdata section will
5932 * become const */
5933static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
5934 " (David Gibson <hermes@gibson.dropbear.id.au>, "
5935 "Pavel Roskin <proski@gnu.org>, et al)";
5936
5937static int __init init_orinoco(void)
5938{
5939 printk(KERN_DEBUG "%s\n", version);
5940 return 0;
5941}
5942
5943static void __exit exit_orinoco(void)
5944{
5945}
5946
5947module_init(init_orinoco);
5948module_exit(exit_orinoco);