blob: 7bd1559e8711f0667cb58cf5dd70f99b09f5ab1d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
2 *
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
5 *
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
9 *
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
15 *
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
17 *
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
21 *
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
26 *
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
31 *
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
35 * Reserved.
36 *
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
47
48/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 * TODO
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
57 */
58
59/* Locking and synchronization:
60 *
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
66 *
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
75 */
76
77#define DRIVER_NAME "orinoco"
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#include <linux/module.h>
80#include <linux/kernel.h>
81#include <linux/init.h>
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>
Pavel Roskin9c974fb2006-08-15 20:45:03 -040087#include <linux/if_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#include <linux/wireless.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020089#include <net/iw_handler.h>
Christoph Hellwig5d558b72005-06-19 01:27:28 +020090#include <net/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
David Kilroy23edcc42008-08-21 23:28:05 +010092#include <linux/scatterlist.h>
93#include <linux/crypto.h>
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#include "hermes_rid.h"
David Kilroy3994d502008-08-21 23:27:54 +010096#include "hermes_dld.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99/********************************************************************/
100/* Module information */
101/********************************************************************/
102
103MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
104MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
105MODULE_LICENSE("Dual MPL/GPL");
106
107/* Level of debugging. Used in the macros in orinoco.h */
108#ifdef ORINOCO_DEBUG
109int orinoco_debug = ORINOCO_DEBUG;
110module_param(orinoco_debug, int, 0644);
111MODULE_PARM_DESC(orinoco_debug, "Debug level");
112EXPORT_SYMBOL(orinoco_debug);
113#endif
114
115static int suppress_linkstatus; /* = 0 */
116module_param(suppress_linkstatus, bool, 0644);
117MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Gibson7bb7c3a2005-05-12 20:02:10 -0400118static int ignore_disconnect; /* = 0 */
119module_param(ignore_disconnect, int, 0644);
120MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200122static int force_monitor; /* = 0 */
123module_param(force_monitor, int, 0644);
124MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/********************************************************************/
127/* Compile time configuration and compatibility stuff */
128/********************************************************************/
129
130/* We do this this way to avoid ifdefs in the actual code */
131#ifdef WIRELESS_SPY
Pavel Roskin343c6862005-09-09 18:43:02 -0400132#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#else
134#define SPY_NUMBER(priv) 0
135#endif /* WIRELESS_SPY */
136
137/********************************************************************/
138/* Internal constants */
139/********************************************************************/
140
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200141/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
142static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define ORINOCO_MIN_MTU 256
Jeff Garzikb4538722005-05-12 22:48:20 -0400146#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148#define SYMBOL_MAX_VER_LEN (14)
149#define USER_BAP 0
150#define IRQ_BAP 1
151#define MAX_IRQLOOPS_PER_IRQ 10
152#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
153 * how many events the
154 * device could
155 * legitimately generate */
156#define SMALL_KEY_SIZE 5
157#define LARGE_KEY_SIZE 13
158#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
159
160#define DUMMY_FID 0xFFFF
161
162/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
163 HERMES_MAX_MULTICAST : 0)*/
164#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
165
166#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
167 | HERMES_EV_TX | HERMES_EV_TXEXC \
168 | HERMES_EV_WTERR | HERMES_EV_INFO \
169 | HERMES_EV_INFDROP )
170
Christoph Hellwig620554e2005-06-19 01:27:33 +0200171#define MAX_RID_LEN 1024
172
173static const struct iw_handler_def orinoco_handler_def;
Jeff Garzik7282d492006-09-13 14:30:00 -0400174static const struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/********************************************************************/
177/* Data tables */
178/********************************************************************/
179
180/* The frequency of each channel in MHz */
181static const long channel_frequency[] = {
182 2412, 2417, 2422, 2427, 2432, 2437, 2442,
183 2447, 2452, 2457, 2462, 2467, 2472, 2484
184};
185#define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
186
187/* This tables gives the actual meanings of the bitrate IDs returned
188 * by the firmware. */
189static struct {
190 int bitrate; /* in 100s of kilobits */
191 int automatic;
192 u16 agere_txratectrl;
193 u16 intersil_txratectrl;
194} bitrate_table[] = {
195 {110, 1, 3, 15}, /* Entry 0 is the default */
196 {10, 0, 1, 1},
197 {10, 1, 1, 1},
198 {20, 0, 2, 2},
199 {20, 1, 6, 3},
200 {55, 0, 4, 4},
201 {55, 1, 7, 7},
202 {110, 0, 5, 8},
203};
204#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
205
206/********************************************************************/
207/* Data types */
208/********************************************************************/
209
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400210/* Beginning of the Tx descriptor, used in TxExc handling */
211struct hermes_txexc_data {
212 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400213 __le16 frame_ctl;
214 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200215 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216} __attribute__ ((packed));
217
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200218/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200220 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400221 __le16 status;
222 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 u8 silence;
224 u8 signal;
225 u8 rate;
226 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400227 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200228
229 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400230 __le16 frame_ctl;
231 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200232 u8 addr1[ETH_ALEN];
233 u8 addr2[ETH_ALEN];
234 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400235 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200236 u8 addr4[ETH_ALEN];
237
238 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400239 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240} __attribute__ ((packed));
241
242/********************************************************************/
243/* Function prototypes */
244/********************************************************************/
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246static int __orinoco_program_rids(struct net_device *dev);
247static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249/********************************************************************/
David Kilroy23edcc42008-08-21 23:28:05 +0100250/* Michael MIC crypto setup */
251/********************************************************************/
252#define MICHAEL_MIC_LEN 8
253static int orinoco_mic_init(struct orinoco_private *priv)
254{
255 priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
256 if (IS_ERR(priv->tx_tfm_mic)) {
257 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
258 "crypto API michael_mic\n");
259 priv->tx_tfm_mic = NULL;
260 return -ENOMEM;
261 }
262
263 priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
264 if (IS_ERR(priv->rx_tfm_mic)) {
265 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
266 "crypto API michael_mic\n");
267 priv->rx_tfm_mic = NULL;
268 return -ENOMEM;
269 }
270
271 return 0;
272}
273
274static void orinoco_mic_free(struct orinoco_private *priv)
275{
276 if (priv->tx_tfm_mic)
277 crypto_free_hash(priv->tx_tfm_mic);
278 if (priv->rx_tfm_mic)
279 crypto_free_hash(priv->rx_tfm_mic);
280}
281
282static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
283 u8 *da, u8 *sa, u8 priority,
284 u8 *data, size_t data_len, u8 *mic)
285{
286 struct hash_desc desc;
287 struct scatterlist sg[2];
288 u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
289
290 if (tfm_michael == NULL) {
291 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
292 return -1;
293 }
294
295 /* Copy header into buffer. We need the padding on the end zeroed */
296 memcpy(&hdr[0], da, ETH_ALEN);
297 memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
298 hdr[ETH_ALEN*2] = priority;
299 hdr[ETH_ALEN*2+1] = 0;
300 hdr[ETH_ALEN*2+2] = 0;
301 hdr[ETH_ALEN*2+3] = 0;
302
303 /* Use scatter gather to MIC header and data in one go */
304 sg_init_table(sg, 2);
305 sg_set_buf(&sg[0], hdr, sizeof(hdr));
306 sg_set_buf(&sg[1], data, data_len);
307
308 if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
309 return -1;
310
311 desc.tfm = tfm_michael;
312 desc.flags = 0;
313 return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
314 mic);
315}
316
317/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/* Internal helper functions */
319/********************************************************************/
320
321static inline void set_port_type(struct orinoco_private *priv)
322{
323 switch (priv->iw_mode) {
324 case IW_MODE_INFRA:
325 priv->port_type = 1;
326 priv->createibss = 0;
327 break;
328 case IW_MODE_ADHOC:
329 if (priv->prefer_port3) {
330 priv->port_type = 3;
331 priv->createibss = 0;
332 } else {
333 priv->port_type = priv->ibss_port;
334 priv->createibss = 1;
335 }
336 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200337 case IW_MODE_MONITOR:
338 priv->port_type = 3;
339 priv->createibss = 0;
340 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 default:
342 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
343 priv->ndev->name);
344 }
345}
346
Dan Williams1e3428e2007-10-10 23:56:25 -0400347#define ORINOCO_MAX_BSS_COUNT 64
348static int orinoco_bss_data_allocate(struct orinoco_private *priv)
349{
David Kilroy01632fa2008-08-21 23:27:58 +0100350 if (priv->bss_xbss_data)
Dan Williams1e3428e2007-10-10 23:56:25 -0400351 return 0;
352
David Kilroy01632fa2008-08-21 23:27:58 +0100353 if (priv->has_ext_scan)
354 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
355 sizeof(struct xbss_element),
356 GFP_KERNEL);
357 else
358 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
359 sizeof(struct bss_element),
360 GFP_KERNEL);
361
362 if (!priv->bss_xbss_data) {
Dan Williams1e3428e2007-10-10 23:56:25 -0400363 printk(KERN_WARNING "Out of memory allocating beacons");
364 return -ENOMEM;
365 }
366 return 0;
367}
368
369static void orinoco_bss_data_free(struct orinoco_private *priv)
370{
David Kilroy01632fa2008-08-21 23:27:58 +0100371 kfree(priv->bss_xbss_data);
372 priv->bss_xbss_data = NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -0400373}
374
David Kilroy01632fa2008-08-21 23:27:58 +0100375#define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
376#define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
Dan Williams1e3428e2007-10-10 23:56:25 -0400377static void orinoco_bss_data_init(struct orinoco_private *priv)
378{
379 int i;
380
381 INIT_LIST_HEAD(&priv->bss_free_list);
382 INIT_LIST_HEAD(&priv->bss_list);
David Kilroy01632fa2008-08-21 23:27:58 +0100383 if (priv->has_ext_scan)
384 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
385 list_add_tail(&(PRIV_XBSS[i].list),
386 &priv->bss_free_list);
387 else
388 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
389 list_add_tail(&(PRIV_BSS[i].list),
390 &priv->bss_free_list);
391
392}
393
394static inline u8 *orinoco_get_ie(u8 *data, size_t len,
395 enum ieee80211_mfie eid)
396{
397 u8 *p = data;
398 while ((p + 2) < (data + len)) {
399 if (p[0] == eid)
400 return p;
401 p += p[1] + 2;
402 }
403 return NULL;
404}
405
406#define WPA_OUI_TYPE "\x00\x50\xF2\x01"
407#define WPA_SELECTOR_LEN 4
408static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
409{
410 u8 *p = data;
411 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
412 if ((p[0] == MFIE_TYPE_GENERIC) &&
413 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
414 return p;
415 p += p[1] + 2;
416 }
417 return NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -0400418}
419
David Kilroy3994d502008-08-21 23:27:54 +0100420
421/********************************************************************/
422/* Download functionality */
423/********************************************************************/
424
425struct fw_info {
426 char *pri_fw;
427 char *sta_fw;
428 char *ap_fw;
429 u32 pda_addr;
430 u16 pda_size;
431};
432
433const static struct fw_info orinoco_fw[] = {
434 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
435 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
Andrey Borzenkov70458252008-10-10 21:26:30 +0400436 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 512 }
David Kilroy3994d502008-08-21 23:27:54 +0100437};
438
439/* Structure used to access fields in FW
440 * Make sure LE decoding macros are used
441 */
442struct orinoco_fw_header {
443 char hdr_vers[6]; /* ASCII string for header version */
444 __le16 headersize; /* Total length of header */
445 __le32 entry_point; /* NIC entry point */
446 __le32 blocks; /* Number of blocks to program */
447 __le32 block_offset; /* Offset of block data from eof header */
448 __le32 pdr_offset; /* Offset to PDR data from eof header */
449 __le32 pri_offset; /* Offset to primary plug data */
450 __le32 compat_offset; /* Offset to compatibility data*/
451 char signature[0]; /* FW signature length headersize-20 */
452} __attribute__ ((packed));
453
454/* Download either STA or AP firmware into the card. */
455static int
456orinoco_dl_firmware(struct orinoco_private *priv,
457 const struct fw_info *fw,
458 int ap)
459{
460 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400461 __le16 *pda;
David Kilroy3994d502008-08-21 23:27:54 +0100462
463 hermes_t *hw = &priv->hw;
464 const struct firmware *fw_entry;
465 const struct orinoco_fw_header *hdr;
466 const unsigned char *first_block;
467 const unsigned char *end;
468 const char *firmware;
469 struct net_device *dev = priv->ndev;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400470 int err = 0;
471
472 pda = kzalloc(fw->pda_size, GFP_KERNEL);
473 if (!pda)
474 return -ENOMEM;
David Kilroy3994d502008-08-21 23:27:54 +0100475
476 if (ap)
477 firmware = fw->ap_fw;
478 else
479 firmware = fw->sta_fw;
480
481 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
482 dev->name, firmware);
483
484 /* Read current plug data */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400485 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
David Kilroy3994d502008-08-21 23:27:54 +0100486 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
487 if (err)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400488 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100489
490 err = request_firmware(&fw_entry, firmware, priv->dev);
491 if (err) {
492 printk(KERN_ERR "%s: Cannot find firmware %s\n",
493 dev->name, firmware);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400494 err = -ENOENT;
495 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100496 }
497
498 hdr = (const struct orinoco_fw_header *) fw_entry->data;
499
500 /* Enable aux port to allow programming */
501 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
502 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
503 if (err != 0)
504 goto abort;
505
506 /* Program data */
507 first_block = (fw_entry->data +
508 le16_to_cpu(hdr->headersize) +
509 le32_to_cpu(hdr->block_offset));
510 end = fw_entry->data + fw_entry->size;
511
512 err = hermes_program(hw, first_block, end);
513 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
514 if (err != 0)
515 goto abort;
516
517 /* Update production data */
518 first_block = (fw_entry->data +
519 le16_to_cpu(hdr->headersize) +
520 le32_to_cpu(hdr->pdr_offset));
521
522 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
523 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
524 if (err)
525 goto abort;
526
527 /* Tell card we've finished */
528 err = hermesi_program_end(hw);
529 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
530 if (err != 0)
531 goto abort;
532
533 /* Check if we're running */
534 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
535 dev->name, hermes_present(hw));
536
537abort:
538 release_firmware(fw_entry);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400539
540free:
541 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100542 return err;
543}
544
545/* End markers */
546#define TEXT_END 0x1A /* End of text header */
547
548/*
549 * Process a firmware image - stop the card, load the firmware, reset
550 * the card and make sure it responds. For the secondary firmware take
551 * care of the PDA - read it and then write it on top of the firmware.
552 */
553static int
554symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
555 const unsigned char *image, const unsigned char *end,
556 int secondary)
557{
558 hermes_t *hw = &priv->hw;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400559 int ret = 0;
David Kilroy3994d502008-08-21 23:27:54 +0100560 const unsigned char *ptr;
561 const unsigned char *first_block;
562
563 /* Plug Data Area (PDA) */
Andrey Borzenkov70458252008-10-10 21:26:30 +0400564 __le16 *pda = NULL;
David Kilroy3994d502008-08-21 23:27:54 +0100565
566 /* Binary block begins after the 0x1A marker */
567 ptr = image;
568 while (*ptr++ != TEXT_END);
569 first_block = ptr;
570
571 /* Read the PDA from EEPROM */
572 if (secondary) {
Andrey Borzenkov70458252008-10-10 21:26:30 +0400573 pda = kzalloc(fw->pda_size, GFP_KERNEL);
574 if (!pda)
575 return -ENOMEM;
576
577 ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
David Kilroy3994d502008-08-21 23:27:54 +0100578 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400579 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100580 }
581
582 /* Stop the firmware, so that it can be safely rewritten */
583 if (priv->stop_fw) {
584 ret = priv->stop_fw(priv, 1);
585 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400586 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100587 }
588
589 /* Program the adapter with new firmware */
590 ret = hermes_program(hw, first_block, end);
591 if (ret)
Andrey Borzenkov70458252008-10-10 21:26:30 +0400592 goto free;
David Kilroy3994d502008-08-21 23:27:54 +0100593
594 /* Write the PDA to the adapter */
595 if (secondary) {
596 size_t len = hermes_blocks_length(first_block);
597 ptr = first_block + len;
598 ret = hermes_apply_pda(hw, ptr, pda);
Andrey Borzenkov70458252008-10-10 21:26:30 +0400599 kfree(pda);
David Kilroy3994d502008-08-21 23:27:54 +0100600 if (ret)
601 return ret;
602 }
603
604 /* Run the firmware */
605 if (priv->stop_fw) {
606 ret = priv->stop_fw(priv, 0);
607 if (ret)
608 return ret;
609 }
610
611 /* Reset hermes chip and make sure it responds */
612 ret = hermes_init(hw);
613
614 /* hermes_reset() should return 0 with the secondary firmware */
615 if (secondary && ret != 0)
616 return -ENODEV;
617
618 /* And this should work with any firmware */
619 if (!hermes_present(hw))
620 return -ENODEV;
621
622 return 0;
Andrey Borzenkov70458252008-10-10 21:26:30 +0400623
624free:
625 kfree(pda);
626 return ret;
David Kilroy3994d502008-08-21 23:27:54 +0100627}
628
629
630/*
631 * Download the firmware into the card, this also does a PCMCIA soft
632 * reset on the card, to make sure it's in a sane state.
633 */
634static int
635symbol_dl_firmware(struct orinoco_private *priv,
636 const struct fw_info *fw)
637{
638 struct net_device *dev = priv->ndev;
639 int ret;
640 const struct firmware *fw_entry;
641
642 if (request_firmware(&fw_entry, fw->pri_fw,
643 priv->dev) != 0) {
644 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
645 dev->name, fw->pri_fw);
646 return -ENOENT;
647 }
648
649 /* Load primary firmware */
650 ret = symbol_dl_image(priv, fw, fw_entry->data,
651 fw_entry->data + fw_entry->size, 0);
652 release_firmware(fw_entry);
653 if (ret) {
654 printk(KERN_ERR "%s: Primary firmware download failed\n",
655 dev->name);
656 return ret;
657 }
658
659 if (request_firmware(&fw_entry, fw->sta_fw,
660 priv->dev) != 0) {
661 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
662 dev->name, fw->sta_fw);
663 return -ENOENT;
664 }
665
666 /* Load secondary firmware */
667 ret = symbol_dl_image(priv, fw, fw_entry->data,
668 fw_entry->data + fw_entry->size, 1);
669 release_firmware(fw_entry);
670 if (ret) {
671 printk(KERN_ERR "%s: Secondary firmware download failed\n",
672 dev->name);
673 }
674
675 return ret;
676}
677
678static int orinoco_download(struct orinoco_private *priv)
679{
680 int err = 0;
681 /* Reload firmware */
682 switch (priv->firmware_type) {
683 case FIRMWARE_TYPE_AGERE:
684 /* case FIRMWARE_TYPE_INTERSIL: */
685 err = orinoco_dl_firmware(priv,
686 &orinoco_fw[priv->firmware_type], 0);
687 break;
688
689 case FIRMWARE_TYPE_SYMBOL:
690 err = symbol_dl_firmware(priv,
691 &orinoco_fw[priv->firmware_type]);
692 break;
693 case FIRMWARE_TYPE_INTERSIL:
694 break;
695 }
696 /* TODO: if we fail we probably need to reinitialise
697 * the driver */
698
699 return err;
700}
701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702/********************************************************************/
703/* Device methods */
704/********************************************************************/
705
706static int orinoco_open(struct net_device *dev)
707{
708 struct orinoco_private *priv = netdev_priv(dev);
709 unsigned long flags;
710 int err;
711
712 if (orinoco_lock(priv, &flags) != 0)
713 return -EBUSY;
714
715 err = __orinoco_up(dev);
716
717 if (! err)
718 priv->open = 1;
719
720 orinoco_unlock(priv, &flags);
721
722 return err;
723}
724
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200725static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
727 struct orinoco_private *priv = netdev_priv(dev);
728 int err = 0;
729
730 /* We mustn't use orinoco_lock() here, because we need to be
731 able to close the interface even if hw_unavailable is set
732 (e.g. as we're released after a PC Card removal) */
733 spin_lock_irq(&priv->lock);
734
735 priv->open = 0;
736
737 err = __orinoco_down(dev);
738
739 spin_unlock_irq(&priv->lock);
740
741 return err;
742}
743
744static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
745{
746 struct orinoco_private *priv = netdev_priv(dev);
747
748 return &priv->stats;
749}
750
751static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
752{
753 struct orinoco_private *priv = netdev_priv(dev);
754 hermes_t *hw = &priv->hw;
755 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400756 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 unsigned long flags;
758
759 if (! netif_device_present(dev)) {
760 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
761 dev->name);
762 return NULL; /* FIXME: Can we do better than this? */
763 }
764
David Gibsone67d9d92005-05-12 20:01:22 -0400765 /* If busy, return the old stats. Returning NULL may cause
766 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400768 return wstats;
769
770 /* We can't really wait for the tallies inquiry command to
771 * complete, so we just use the previous results and trigger
772 * a new tallies inquiry command for next time - Jean II */
773 /* FIXME: Really we should wait for the inquiry to come back -
774 * as it is the stats we give don't make a whole lot of sense.
775 * Unfortunately, it's not clear how to do that within the
776 * wireless extensions framework: I think we're in user
777 * context, but a lock seems to be held by the time we get in
778 * here so we're not safe to sleep here. */
779 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 if (priv->iw_mode == IW_MODE_ADHOC) {
782 memset(&wstats->qual, 0, sizeof(wstats->qual));
783 /* If a spy address is defined, we report stats of the
784 * first spy address - Jean II */
785 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400786 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
787 wstats->qual.level = priv->spy_data.spy_stat[0].level;
788 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
789 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791 } else {
792 struct {
Pavel Roskina208c4e2006-04-07 04:10:26 -0400793 __le16 qual, signal, noise, unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 } __attribute__ ((packed)) cq;
795
796 err = HERMES_READ_RECORD(hw, USER_BAP,
797 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400798
799 if (!err) {
800 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
801 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
802 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
803 wstats->qual.updated = 7;
804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
806
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 return wstats;
809}
810
811static void orinoco_set_multicast_list(struct net_device *dev)
812{
813 struct orinoco_private *priv = netdev_priv(dev);
814 unsigned long flags;
815
816 if (orinoco_lock(priv, &flags) != 0) {
817 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
818 "called when hw_unavailable\n", dev->name);
819 return;
820 }
821
822 __orinoco_set_multicast_list(dev);
823 orinoco_unlock(priv, &flags);
824}
825
826static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
827{
828 struct orinoco_private *priv = netdev_priv(dev);
829
830 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
831 return -EINVAL;
832
Jeff Garzikb4538722005-05-12 22:48:20 -0400833 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 (priv->nicbuf_size - ETH_HLEN) )
835 return -EINVAL;
836
837 dev->mtu = new_mtu;
838
839 return 0;
840}
841
842/********************************************************************/
843/* Tx path */
844/********************************************************************/
845
846static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
847{
848 struct orinoco_private *priv = netdev_priv(dev);
849 struct net_device_stats *stats = &priv->stats;
850 hermes_t *hw = &priv->hw;
851 int err = 0;
852 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 struct ethhdr *eh;
David Kilroy6eecad72008-08-21 23:27:56 +0100854 int tx_control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 unsigned long flags;
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (! netif_running(dev)) {
858 printk(KERN_ERR "%s: Tx on stopped device!\n",
859 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400860 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
862
863 if (netif_queue_stopped(dev)) {
864 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
865 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400866 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868
869 if (orinoco_lock(priv, &flags) != 0) {
870 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
871 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400872 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
874
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200875 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 /* Oops, the firmware hasn't established a connection,
877 silently drop the packet (this seems to be the
878 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400879 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
Pavel Roskin8d5be082006-04-07 04:10:41 -0400882 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400883 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400884 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
David Kilroy6eecad72008-08-21 23:27:56 +0100886 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
David Kilroy23edcc42008-08-21 23:28:05 +0100888 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
889 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
890 HERMES_TXCTRL_MIC;
891
David Kilroy6eecad72008-08-21 23:27:56 +0100892 if (priv->has_alt_txcntl) {
893 /* WPA enabled firmwares have tx_cntl at the end of
894 * the 802.11 header. So write zeroed descriptor and
895 * 802.11 header at the same time
896 */
897 char desc[HERMES_802_3_OFFSET];
898 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
899
900 memset(&desc, 0, sizeof(desc));
901
902 *txcntl = cpu_to_le16(tx_control);
903 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
904 txfid, 0);
905 if (err) {
906 if (net_ratelimit())
907 printk(KERN_ERR "%s: Error %d writing Tx "
908 "descriptor to BAP\n", dev->name, err);
909 goto busy;
910 }
911 } else {
912 struct hermes_tx_descriptor desc;
913
914 memset(&desc, 0, sizeof(desc));
915
916 desc.tx_control = cpu_to_le16(tx_control);
917 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
918 txfid, 0);
919 if (err) {
920 if (net_ratelimit())
921 printk(KERN_ERR "%s: Error %d writing Tx "
922 "descriptor to BAP\n", dev->name, err);
923 goto busy;
924 }
925
926 /* Clear the 802.11 header and data length fields - some
927 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
928 * if this isn't done. */
929 hermes_clear_words(hw, HERMES_DATA0,
930 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
David Kilroy23edcc42008-08-21 23:28:05 +0100933 eh = (struct ethhdr *)skb->data;
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 /* Encapsulate Ethernet-II frames */
936 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400937 struct header_struct {
938 struct ethhdr eth; /* 802.3 header */
939 u8 encap[6]; /* 802.2 header */
940 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Pavel Roskina28dc812006-04-07 04:10:45 -0400942 /* Strip destination and source from the data */
943 skb_pull(skb, 2 * ETH_ALEN);
Pavel Roskina28dc812006-04-07 04:10:45 -0400944
945 /* And move them to a separate header */
946 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
947 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
948 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
949
David Kilroy23edcc42008-08-21 23:28:05 +0100950 /* Insert the SNAP header */
951 if (skb_headroom(skb) < sizeof(hdr)) {
952 printk(KERN_ERR
953 "%s: Not enough headroom for 802.2 headers %d\n",
954 dev->name, skb_headroom(skb));
955 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
David Kilroy23edcc42008-08-21 23:28:05 +0100957 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
958 memcpy(eh, &hdr, sizeof(hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 }
960
Pavel Roskina28dc812006-04-07 04:10:45 -0400961 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
David Kilroy23edcc42008-08-21 23:28:05 +0100962 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 if (err) {
964 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
965 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400966 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968
David Kilroy23edcc42008-08-21 23:28:05 +0100969 /* Calculate Michael MIC */
970 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
971 u8 mic_buf[MICHAEL_MIC_LEN + 1];
972 u8 *mic;
973 size_t offset;
974 size_t len;
975
976 if (skb->len % 2) {
977 /* MIC start is on an odd boundary */
978 mic_buf[0] = skb->data[skb->len - 1];
979 mic = &mic_buf[1];
980 offset = skb->len - 1;
981 len = MICHAEL_MIC_LEN + 1;
982 } else {
983 mic = &mic_buf[0];
984 offset = skb->len;
985 len = MICHAEL_MIC_LEN;
986 }
987
988 michael_mic(priv->tx_tfm_mic,
989 priv->tkip_key[priv->tx_key].tx_mic,
990 eh->h_dest, eh->h_source, 0 /* priority */,
991 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
992
993 /* Write the MIC */
994 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
995 txfid, HERMES_802_3_OFFSET + offset);
996 if (err) {
997 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
998 dev->name, err);
999 goto busy;
1000 }
1001 }
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 /* Finally, we actually initiate the send */
1004 netif_stop_queue(dev);
1005
1006 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
1007 txfid, NULL);
1008 if (err) {
1009 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -07001010 if (net_ratelimit())
1011 printk(KERN_ERR "%s: Error %d transmitting packet\n",
1012 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001013 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015
1016 dev->trans_start = jiffies;
David Kilroy23edcc42008-08-21 23:28:05 +01001017 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001018 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001020 drop:
1021 stats->tx_errors++;
1022 stats->tx_dropped++;
1023
1024 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -04001027 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Pavel Roskin470e2aa2006-04-07 04:10:43 -04001029 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -04001030 if (err == -EIO)
1031 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -04001033 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034}
1035
1036static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1037{
1038 struct orinoco_private *priv = netdev_priv(dev);
1039 u16 fid = hermes_read_regn(hw, ALLOCFID);
1040
1041 if (fid != priv->txfid) {
1042 if (fid != DUMMY_FID)
1043 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1044 dev->name, fid);
1045 return;
1046 }
1047
1048 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1049}
1050
1051static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1052{
1053 struct orinoco_private *priv = netdev_priv(dev);
1054 struct net_device_stats *stats = &priv->stats;
1055
1056 stats->tx_packets++;
1057
1058 netif_wake_queue(dev);
1059
1060 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1061}
1062
1063static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1064{
1065 struct orinoco_private *priv = netdev_priv(dev);
1066 struct net_device_stats *stats = &priv->stats;
1067 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -04001068 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001069 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 int err = 0;
1071
1072 if (fid == DUMMY_FID)
1073 return; /* Nothing's really happened */
1074
Pavel Roskin48ca7032005-09-23 04:18:06 -04001075 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001076 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001077 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001078 fid, 0);
1079
1080 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1081 stats->tx_errors++;
1082
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 if (err) {
1084 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1085 "(FID=%04X error %d)\n",
1086 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001087 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001090 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1091 err, fid);
1092
1093 /* We produce a TXDROP event only for retry or lifetime
1094 * exceeded, because that's the only status that really mean
1095 * that this particular node went away.
1096 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -04001097 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -04001098 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001099 union iwreq_data wrqu;
1100
1101 /* Copy 802.11 dest address.
1102 * We use the 802.11 header because the frame may
1103 * not be 802.3 or may be mangled...
1104 * In Ad-Hoc mode, it will be the node address.
1105 * In managed mode, it will be most likely the AP addr
1106 * User space will figure out how to convert it to
1107 * whatever it needs (IP address or else).
1108 * - Jean II */
1109 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1110 wrqu.addr.sa_family = ARPHRD_ETHER;
1111
1112 /* Send event to user space */
1113 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117}
1118
1119static void orinoco_tx_timeout(struct net_device *dev)
1120{
1121 struct orinoco_private *priv = netdev_priv(dev);
1122 struct net_device_stats *stats = &priv->stats;
1123 struct hermes *hw = &priv->hw;
1124
1125 printk(KERN_WARNING "%s: Tx timeout! "
1126 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1127 dev->name, hermes_read_regn(hw, ALLOCFID),
1128 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1129
1130 stats->tx_errors++;
1131
1132 schedule_work(&priv->reset_work);
1133}
1134
1135/********************************************************************/
1136/* Rx path (data frames) */
1137/********************************************************************/
1138
1139/* Does the frame have a SNAP header indicating it should be
1140 * de-encapsulated to Ethernet-II? */
1141static inline int is_ethersnap(void *_hdr)
1142{
1143 u8 *hdr = _hdr;
1144
1145 /* We de-encapsulate all packets which, a) have SNAP headers
1146 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1147 * and where b) the OUI of the SNAP header is 00:00:00 or
1148 * 00:00:f8 - we need both because different APs appear to use
1149 * different OUIs for some reason */
1150 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1151 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1152}
1153
1154static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1155 int level, int noise)
1156{
Pavel Roskin343c6862005-09-09 18:43:02 -04001157 struct iw_quality wstats;
1158 wstats.level = level - 0x95;
1159 wstats.noise = noise - 0x95;
1160 wstats.qual = (level > noise) ? (level - noise) : 0;
1161 wstats.updated = 7;
1162 /* Update spy records */
1163 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
1166static void orinoco_stat_gather(struct net_device *dev,
1167 struct sk_buff *skb,
1168 struct hermes_rx_descriptor *desc)
1169{
1170 struct orinoco_private *priv = netdev_priv(dev);
1171
1172 /* Using spy support with lots of Rx packets, like in an
1173 * infrastructure (AP), will really slow down everything, because
1174 * the MAC address must be compared to each entry of the spy list.
1175 * If the user really asks for it (set some address in the
1176 * spy list), we do it, but he will pay the price.
1177 * Note that to get here, you need both WIRELESS_SPY
1178 * compiled in AND some addresses in the list !!!
1179 */
1180 /* Note : gcc will optimise the whole section away if
1181 * WIRELESS_SPY is not defined... - Jean II */
1182 if (SPY_NUMBER(priv)) {
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07001183 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 desc->signal, desc->silence);
1185 }
1186}
1187
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001188/*
1189 * orinoco_rx_monitor - handle received monitor frames.
1190 *
1191 * Arguments:
1192 * dev network device
1193 * rxfid received FID
1194 * desc rx descriptor of the frame
1195 *
1196 * Call context: interrupt
1197 */
1198static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1199 struct hermes_rx_descriptor *desc)
1200{
1201 u32 hdrlen = 30; /* return full header by default */
1202 u32 datalen = 0;
1203 u16 fc;
1204 int err;
1205 int len;
1206 struct sk_buff *skb;
1207 struct orinoco_private *priv = netdev_priv(dev);
1208 struct net_device_stats *stats = &priv->stats;
1209 hermes_t *hw = &priv->hw;
1210
1211 len = le16_to_cpu(desc->data_len);
1212
1213 /* Determine the size of the header and the data */
1214 fc = le16_to_cpu(desc->frame_ctl);
1215 switch (fc & IEEE80211_FCTL_FTYPE) {
1216 case IEEE80211_FTYPE_DATA:
1217 if ((fc & IEEE80211_FCTL_TODS)
1218 && (fc & IEEE80211_FCTL_FROMDS))
1219 hdrlen = 30;
1220 else
1221 hdrlen = 24;
1222 datalen = len;
1223 break;
1224 case IEEE80211_FTYPE_MGMT:
1225 hdrlen = 24;
1226 datalen = len;
1227 break;
1228 case IEEE80211_FTYPE_CTL:
1229 switch (fc & IEEE80211_FCTL_STYPE) {
1230 case IEEE80211_STYPE_PSPOLL:
1231 case IEEE80211_STYPE_RTS:
1232 case IEEE80211_STYPE_CFEND:
1233 case IEEE80211_STYPE_CFENDACK:
1234 hdrlen = 16;
1235 break;
1236 case IEEE80211_STYPE_CTS:
1237 case IEEE80211_STYPE_ACK:
1238 hdrlen = 10;
1239 break;
1240 }
1241 break;
1242 default:
1243 /* Unknown frame type */
1244 break;
1245 }
1246
1247 /* sanity check the length */
1248 if (datalen > IEEE80211_DATA_LEN + 12) {
1249 printk(KERN_DEBUG "%s: oversized monitor frame, "
1250 "data length = %d\n", dev->name, datalen);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001251 stats->rx_length_errors++;
1252 goto update_stats;
1253 }
1254
1255 skb = dev_alloc_skb(hdrlen + datalen);
1256 if (!skb) {
1257 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1258 dev->name);
Florin Malitabb6e0932006-05-22 22:35:30 -07001259 goto update_stats;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001260 }
1261
1262 /* Copy the 802.11 header to the skb */
1263 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001264 skb_reset_mac_header(skb);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001265
1266 /* If any, copy the data from the card to the skb */
1267 if (datalen > 0) {
1268 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1269 ALIGN(datalen, 2), rxfid,
1270 HERMES_802_2_OFFSET);
1271 if (err) {
1272 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1273 dev->name, err);
1274 goto drop;
1275 }
1276 }
1277
1278 skb->dev = dev;
1279 skb->ip_summed = CHECKSUM_NONE;
1280 skb->pkt_type = PACKET_OTHERHOST;
1281 skb->protocol = __constant_htons(ETH_P_802_2);
1282
1283 dev->last_rx = jiffies;
1284 stats->rx_packets++;
1285 stats->rx_bytes += skb->len;
1286
1287 netif_rx(skb);
1288 return;
1289
1290 drop:
1291 dev_kfree_skb_irq(skb);
1292 update_stats:
1293 stats->rx_errors++;
1294 stats->rx_dropped++;
1295}
1296
David Kilroy23edcc42008-08-21 23:28:05 +01001297/* Get tsc from the firmware */
1298static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1299 u8 *tsc)
1300{
1301 hermes_t *hw = &priv->hw;
1302 int err = 0;
1303 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1304
1305 if ((key < 0) || (key > 4))
1306 return -EINVAL;
1307
1308 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1309 sizeof(tsc_arr), NULL, &tsc_arr);
1310 if (!err)
1311 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1312
1313 return err;
1314}
1315
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1317{
1318 struct orinoco_private *priv = netdev_priv(dev);
1319 struct net_device_stats *stats = &priv->stats;
1320 struct iw_statistics *wstats = &priv->wstats;
1321 struct sk_buff *skb = NULL;
David Kilroy31afcef2008-08-21 23:28:04 +01001322 u16 rxfid, status;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001323 int length;
David Kilroy31afcef2008-08-21 23:28:04 +01001324 struct hermes_rx_descriptor *desc;
1325 struct orinoco_rx_data *rx_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 int err;
1327
David Kilroy31afcef2008-08-21 23:28:04 +01001328 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1329 if (!desc) {
1330 printk(KERN_WARNING
1331 "%s: Can't allocate space for RX descriptor\n",
1332 dev->name);
1333 goto update_stats;
1334 }
1335
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 rxfid = hermes_read_regn(hw, RXFID);
1337
David Kilroy31afcef2008-08-21 23:28:04 +01001338 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 rxfid, 0);
1340 if (err) {
1341 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1342 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001343 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
1345
David Kilroy31afcef2008-08-21 23:28:04 +01001346 status = le16_to_cpu(desc->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001348 if (status & HERMES_RXSTAT_BADCRC) {
1349 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1350 dev->name);
1351 stats->rx_crc_errors++;
1352 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 }
1354
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001355 /* Handle frames in monitor mode */
1356 if (priv->iw_mode == IW_MODE_MONITOR) {
David Kilroy31afcef2008-08-21 23:28:04 +01001357 orinoco_rx_monitor(dev, rxfid, desc);
1358 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001361 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1362 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1363 dev->name);
1364 wstats->discard.code++;
1365 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
1367
David Kilroy31afcef2008-08-21 23:28:04 +01001368 length = le16_to_cpu(desc->data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 /* Sanity checks */
1371 if (length < 3) { /* No for even an 802.2 LLC header */
1372 /* At least on Symbol firmware with PCF we get quite a
1373 lot of these legitimately - Poll frames with no
1374 data. */
David Kilroy31afcef2008-08-21 23:28:04 +01001375 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
Jeff Garzikb4538722005-05-12 22:48:20 -04001377 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1379 dev->name, length);
1380 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001381 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 }
1383
David Kilroy23edcc42008-08-21 23:28:05 +01001384 /* Payload size does not include Michael MIC. Increase payload
1385 * size to read it together with the data. */
1386 if (status & HERMES_RXSTAT_MIC)
1387 length += MICHAEL_MIC_LEN;
1388
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 /* We need space for the packet data itself, plus an ethernet
1390 header, plus 2 bytes so we can align the IP header on a
1391 32bit boundary, plus 1 byte so we can read in odd length
1392 packets from the card, which has an IO granularity of 16
1393 bits */
1394 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1395 if (!skb) {
1396 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1397 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001398 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 }
1400
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001401 /* We'll prepend the header, so reserve space for it. The worst
1402 case is no decapsulation, when 802.3 header is prepended and
1403 nothing is removed. 2 is for aligning the IP header. */
1404 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001406 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1407 ALIGN(length, 2), rxfid,
1408 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 if (err) {
1410 printk(KERN_ERR "%s: error %d reading frame. "
1411 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 goto drop;
1413 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
David Kilroy31afcef2008-08-21 23:28:04 +01001415 /* Add desc and skb to rx queue */
1416 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1417 if (!rx_data) {
1418 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1419 dev->name);
1420 goto drop;
1421 }
1422 rx_data->desc = desc;
1423 rx_data->skb = skb;
1424 list_add_tail(&rx_data->list, &priv->rx_list);
1425 tasklet_schedule(&priv->rx_tasklet);
1426
1427 return;
1428
1429drop:
1430 dev_kfree_skb_irq(skb);
1431update_stats:
1432 stats->rx_errors++;
1433 stats->rx_dropped++;
1434out:
1435 kfree(desc);
1436}
1437
1438static void orinoco_rx(struct net_device *dev,
1439 struct hermes_rx_descriptor *desc,
1440 struct sk_buff *skb)
1441{
1442 struct orinoco_private *priv = netdev_priv(dev);
1443 struct net_device_stats *stats = &priv->stats;
1444 u16 status, fc;
1445 int length;
1446 struct ethhdr *hdr;
1447
1448 status = le16_to_cpu(desc->status);
1449 length = le16_to_cpu(desc->data_len);
1450 fc = le16_to_cpu(desc->frame_ctl);
1451
David Kilroy23edcc42008-08-21 23:28:05 +01001452 /* Calculate and check MIC */
1453 if (status & HERMES_RXSTAT_MIC) {
1454 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1455 HERMES_MIC_KEY_ID_SHIFT);
1456 u8 mic[MICHAEL_MIC_LEN];
1457 u8 *rxmic;
1458 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1459 desc->addr3 : desc->addr2;
1460
1461 /* Extract Michael MIC from payload */
1462 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1463
1464 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1465 length -= MICHAEL_MIC_LEN;
1466
1467 michael_mic(priv->rx_tfm_mic,
1468 priv->tkip_key[key_id].rx_mic,
1469 desc->addr1,
1470 src,
1471 0, /* priority or QoS? */
1472 skb->data,
1473 skb->len,
1474 &mic[0]);
1475
1476 if (memcmp(mic, rxmic,
1477 MICHAEL_MIC_LEN)) {
1478 union iwreq_data wrqu;
1479 struct iw_michaelmicfailure wxmic;
David Kilroy23edcc42008-08-21 23:28:05 +01001480
1481 printk(KERN_WARNING "%s: "
Johannes Berge1749612008-10-27 15:59:26 -07001482 "Invalid Michael MIC in data frame from %pM, "
David Kilroy23edcc42008-08-21 23:28:05 +01001483 "using key %i\n",
Johannes Berge1749612008-10-27 15:59:26 -07001484 dev->name, src, key_id);
David Kilroy23edcc42008-08-21 23:28:05 +01001485
1486 /* TODO: update stats */
1487
1488 /* Notify userspace */
1489 memset(&wxmic, 0, sizeof(wxmic));
1490 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1491 wxmic.flags |= (desc->addr1[0] & 1) ?
1492 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1493 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1494 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1495
1496 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1497 &wxmic.tsc[0]);
1498
1499 memset(&wrqu, 0, sizeof(wrqu));
1500 wrqu.data.length = sizeof(wxmic);
1501 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1502 (char *) &wxmic);
1503
1504 goto drop;
1505 }
1506 }
1507
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 /* Handle decapsulation
1509 * In most cases, the firmware tell us about SNAP frames.
1510 * For some reason, the SNAP frames sent by LinkSys APs
1511 * are not properly recognised by most firmwares.
1512 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001513 if (length >= ENCAPS_OVERHEAD &&
1514 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1515 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1516 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 /* These indicate a SNAP within 802.2 LLC within
1518 802.11 frame which we'll need to de-encapsulate to
1519 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001520 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001522 /* 802.3 frame - prepend 802.3 header as is */
1523 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1524 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
David Kilroy31afcef2008-08-21 23:28:04 +01001526 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001527 if (fc & IEEE80211_FCTL_FROMDS)
David Kilroy31afcef2008-08-21 23:28:04 +01001528 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001529 else
David Kilroy31afcef2008-08-21 23:28:04 +01001530 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532 dev->last_rx = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 skb->protocol = eth_type_trans(skb, dev);
1534 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001535 if (fc & IEEE80211_FCTL_TODS)
1536 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 /* Process the wireless stats if needed */
David Kilroy31afcef2008-08-21 23:28:04 +01001539 orinoco_stat_gather(dev, skb, desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
1541 /* Pass the packet to the networking stack */
1542 netif_rx(skb);
1543 stats->rx_packets++;
1544 stats->rx_bytes += length;
1545
1546 return;
David Kilroy23edcc42008-08-21 23:28:05 +01001547
1548 drop:
1549 dev_kfree_skb(skb);
1550 stats->rx_errors++;
1551 stats->rx_dropped++;
David Kilroy31afcef2008-08-21 23:28:04 +01001552}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
David Kilroy31afcef2008-08-21 23:28:04 +01001554static void orinoco_rx_isr_tasklet(unsigned long data)
1555{
1556 struct net_device *dev = (struct net_device *) data;
1557 struct orinoco_private *priv = netdev_priv(dev);
1558 struct orinoco_rx_data *rx_data, *temp;
1559 struct hermes_rx_descriptor *desc;
1560 struct sk_buff *skb;
1561
1562 /* extract desc and skb from queue */
1563 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1564 desc = rx_data->desc;
1565 skb = rx_data->skb;
1566 list_del(&rx_data->list);
1567 kfree(rx_data);
1568
1569 orinoco_rx(dev, desc, skb);
1570
1571 kfree(desc);
1572 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573}
1574
1575/********************************************************************/
1576/* Rx path (info frames) */
1577/********************************************************************/
1578
1579static void print_linkstatus(struct net_device *dev, u16 status)
1580{
1581 char * s;
1582
1583 if (suppress_linkstatus)
1584 return;
1585
1586 switch (status) {
1587 case HERMES_LINKSTATUS_NOT_CONNECTED:
1588 s = "Not Connected";
1589 break;
1590 case HERMES_LINKSTATUS_CONNECTED:
1591 s = "Connected";
1592 break;
1593 case HERMES_LINKSTATUS_DISCONNECTED:
1594 s = "Disconnected";
1595 break;
1596 case HERMES_LINKSTATUS_AP_CHANGE:
1597 s = "AP Changed";
1598 break;
1599 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1600 s = "AP Out of Range";
1601 break;
1602 case HERMES_LINKSTATUS_AP_IN_RANGE:
1603 s = "AP In Range";
1604 break;
1605 case HERMES_LINKSTATUS_ASSOC_FAILED:
1606 s = "Association Failed";
1607 break;
1608 default:
1609 s = "UNKNOWN";
1610 }
1611
1612 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1613 dev->name, s, status);
1614}
1615
Christoph Hellwig16739b02005-06-19 01:27:51 +02001616/* Search scan results for requested BSSID, join it if found */
David Howellsc4028952006-11-22 14:57:56 +00001617static void orinoco_join_ap(struct work_struct *work)
Christoph Hellwig16739b02005-06-19 01:27:51 +02001618{
David Howellsc4028952006-11-22 14:57:56 +00001619 struct orinoco_private *priv =
1620 container_of(work, struct orinoco_private, join_work);
1621 struct net_device *dev = priv->ndev;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001622 struct hermes *hw = &priv->hw;
1623 int err;
1624 unsigned long flags;
1625 struct join_req {
1626 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -04001627 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001628 } __attribute__ ((packed)) req;
1629 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001630 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001631 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -04001632 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001633 u8 *buf;
1634 u16 len;
1635
1636 /* Allocate buffer for scan results */
1637 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1638 if (! buf)
1639 return;
1640
1641 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001642 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001643
1644 /* Sanity checks in case user changed something in the meantime */
1645 if (! priv->bssid_fixed)
1646 goto out;
1647
1648 if (strlen(priv->desired_essid) == 0)
1649 goto out;
1650
1651 /* Read scan results from the firmware */
1652 err = hermes_read_ltv(hw, USER_BAP,
1653 HERMES_RID_SCANRESULTSTABLE,
1654 MAX_SCAN_LEN, &len, buf);
1655 if (err) {
1656 printk(KERN_ERR "%s: Cannot read scan results\n",
1657 dev->name);
1658 goto out;
1659 }
1660
1661 len = HERMES_RECLEN_TO_BYTES(len);
1662
1663 /* Go through the scan results looking for the channel of the AP
1664 * we were requested to join */
1665 for (; offset + atom_len <= len; offset += atom_len) {
1666 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001667 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1668 found = 1;
1669 break;
1670 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001671 }
1672
Pavel Roskinc89cc222005-09-01 20:06:06 -04001673 if (! found) {
1674 DEBUG(1, "%s: Requested AP not found in scan results\n",
1675 dev->name);
1676 goto out;
1677 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001678
Christoph Hellwig16739b02005-06-19 01:27:51 +02001679 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1680 req.channel = atom->channel; /* both are little-endian */
1681 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1682 &req);
1683 if (err)
1684 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1685
1686 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001687 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001688
1689 fail_lock:
1690 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001691}
1692
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001693/* Send new BSSID to userspace */
David Kilroy6cd90b12008-08-21 23:28:00 +01001694static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001695{
David Howellsc4028952006-11-22 14:57:56 +00001696 struct net_device *dev = priv->ndev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001697 struct hermes *hw = &priv->hw;
1698 union iwreq_data wrqu;
1699 int err;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001700
1701 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1702 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1703 if (err != 0)
David Kilroy6cd90b12008-08-21 23:28:00 +01001704 return;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001705
1706 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1707
1708 /* Send event to user space */
1709 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001710}
1711
David Kilroy06009fd2008-08-21 23:28:03 +01001712static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1713{
1714 struct net_device *dev = priv->ndev;
1715 struct hermes *hw = &priv->hw;
1716 union iwreq_data wrqu;
1717 int err;
1718 u8 buf[88];
1719 u8 *ie;
1720
1721 if (!priv->has_wpa)
1722 return;
1723
1724 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1725 sizeof(buf), NULL, &buf);
1726 if (err != 0)
1727 return;
1728
1729 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1730 if (ie) {
1731 int rem = sizeof(buf) - (ie - &buf[0]);
1732 wrqu.data.length = ie[1] + 2;
1733 if (wrqu.data.length > rem)
1734 wrqu.data.length = rem;
1735
1736 if (wrqu.data.length)
1737 /* Send event to user space */
1738 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1739 }
1740}
1741
1742static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1743{
1744 struct net_device *dev = priv->ndev;
1745 struct hermes *hw = &priv->hw;
1746 union iwreq_data wrqu;
1747 int err;
1748 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1749 u8 *ie;
1750
1751 if (!priv->has_wpa)
1752 return;
1753
1754 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1755 sizeof(buf), NULL, &buf);
1756 if (err != 0)
1757 return;
1758
1759 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1760 if (ie) {
1761 int rem = sizeof(buf) - (ie - &buf[0]);
1762 wrqu.data.length = ie[1] + 2;
1763 if (wrqu.data.length > rem)
1764 wrqu.data.length = rem;
1765
1766 if (wrqu.data.length)
1767 /* Send event to user space */
1768 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1769 }
1770}
1771
David Kilroy6cd90b12008-08-21 23:28:00 +01001772static void orinoco_send_wevents(struct work_struct *work)
1773{
1774 struct orinoco_private *priv =
1775 container_of(work, struct orinoco_private, wevent_work);
1776 unsigned long flags;
1777
1778 if (orinoco_lock(priv, &flags) != 0)
1779 return;
1780
David Kilroy06009fd2008-08-21 23:28:03 +01001781 orinoco_send_assocreqie_wevent(priv);
1782 orinoco_send_assocrespie_wevent(priv);
David Kilroy6cd90b12008-08-21 23:28:00 +01001783 orinoco_send_bssid_wevent(priv);
1784
1785 orinoco_unlock(priv, &flags);
1786}
Dan Williams1e3428e2007-10-10 23:56:25 -04001787
1788static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1789 unsigned long scan_age)
1790{
David Kilroy01632fa2008-08-21 23:27:58 +01001791 if (priv->has_ext_scan) {
1792 struct xbss_element *bss;
1793 struct xbss_element *tmp_bss;
Dan Williams1e3428e2007-10-10 23:56:25 -04001794
David Kilroy01632fa2008-08-21 23:27:58 +01001795 /* Blow away current list of scan results */
1796 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1797 if (!scan_age ||
1798 time_after(jiffies, bss->last_scanned + scan_age)) {
1799 list_move_tail(&bss->list,
1800 &priv->bss_free_list);
1801 /* Don't blow away ->list, just BSS data */
1802 memset(&bss->bss, 0, sizeof(bss->bss));
1803 bss->last_scanned = 0;
1804 }
Dan Williams1e3428e2007-10-10 23:56:25 -04001805 }
David Kilroy01632fa2008-08-21 23:27:58 +01001806 } else {
1807 struct bss_element *bss;
1808 struct bss_element *tmp_bss;
1809
1810 /* Blow away current list of scan results */
1811 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1812 if (!scan_age ||
1813 time_after(jiffies, bss->last_scanned + scan_age)) {
1814 list_move_tail(&bss->list,
1815 &priv->bss_free_list);
1816 /* Don't blow away ->list, just BSS data */
1817 memset(&bss->bss, 0, sizeof(bss->bss));
1818 bss->last_scanned = 0;
1819 }
1820 }
1821 }
1822}
1823
1824static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
1825 struct agere_ext_scan_info *atom)
1826{
1827 struct xbss_element *bss = NULL;
1828 int found = 0;
1829
1830 /* Try to update an existing bss first */
1831 list_for_each_entry(bss, &priv->bss_list, list) {
1832 if (compare_ether_addr(bss->bss.bssid, atom->bssid))
1833 continue;
1834 /* ESSID lengths */
1835 if (bss->bss.data[1] != atom->data[1])
1836 continue;
1837 if (memcmp(&bss->bss.data[2], &atom->data[2],
1838 atom->data[1]))
1839 continue;
1840 found = 1;
1841 break;
1842 }
1843
1844 /* Grab a bss off the free list */
1845 if (!found && !list_empty(&priv->bss_free_list)) {
1846 bss = list_entry(priv->bss_free_list.next,
1847 struct xbss_element, list);
1848 list_del(priv->bss_free_list.next);
1849
1850 list_add_tail(&bss->list, &priv->bss_list);
1851 }
1852
1853 if (bss) {
1854 /* Always update the BSS to get latest beacon info */
1855 memcpy(&bss->bss, atom, sizeof(bss->bss));
1856 bss->last_scanned = jiffies;
Dan Williams1e3428e2007-10-10 23:56:25 -04001857 }
1858}
1859
1860static int orinoco_process_scan_results(struct net_device *dev,
1861 unsigned char *buf,
1862 int len)
1863{
1864 struct orinoco_private *priv = netdev_priv(dev);
1865 int offset; /* In the scan data */
1866 union hermes_scan_info *atom;
1867 int atom_len;
1868
1869 switch (priv->firmware_type) {
1870 case FIRMWARE_TYPE_AGERE:
1871 atom_len = sizeof(struct agere_scan_apinfo);
1872 offset = 0;
1873 break;
1874 case FIRMWARE_TYPE_SYMBOL:
1875 /* Lack of documentation necessitates this hack.
1876 * Different firmwares have 68 or 76 byte long atoms.
1877 * We try modulo first. If the length divides by both,
1878 * we check what would be the channel in the second
1879 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1880 * Valid channel cannot be 0. */
1881 if (len % 76)
1882 atom_len = 68;
1883 else if (len % 68)
1884 atom_len = 76;
1885 else if (len >= 1292 && buf[68] == 0)
1886 atom_len = 76;
1887 else
1888 atom_len = 68;
1889 offset = 0;
1890 break;
1891 case FIRMWARE_TYPE_INTERSIL:
1892 offset = 4;
1893 if (priv->has_hostscan) {
1894 atom_len = le16_to_cpup((__le16 *)buf);
1895 /* Sanity check for atom_len */
1896 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1897 printk(KERN_ERR "%s: Invalid atom_len in scan "
1898 "data: %d\n", dev->name, atom_len);
1899 return -EIO;
1900 }
1901 } else
1902 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1903 break;
1904 default:
1905 return -EOPNOTSUPP;
1906 }
1907
1908 /* Check that we got an whole number of atoms */
1909 if ((len - offset) % atom_len) {
1910 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1911 "atom_len %d, offset %d\n", dev->name, len,
1912 atom_len, offset);
1913 return -EIO;
1914 }
1915
1916 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1917
1918 /* Read the entries one by one */
1919 for (; offset + atom_len <= len; offset += atom_len) {
1920 int found = 0;
David Kilroy3056c402008-08-21 23:27:57 +01001921 struct bss_element *bss = NULL;
Dan Williams1e3428e2007-10-10 23:56:25 -04001922
1923 /* Get next atom */
1924 atom = (union hermes_scan_info *) (buf + offset);
1925
1926 /* Try to update an existing bss first */
1927 list_for_each_entry(bss, &priv->bss_list, list) {
1928 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1929 continue;
1930 if (le16_to_cpu(bss->bss.a.essid_len) !=
1931 le16_to_cpu(atom->a.essid_len))
1932 continue;
1933 if (memcmp(bss->bss.a.essid, atom->a.essid,
1934 le16_to_cpu(atom->a.essid_len)))
1935 continue;
Dan Williams1e3428e2007-10-10 23:56:25 -04001936 found = 1;
1937 break;
1938 }
1939
1940 /* Grab a bss off the free list */
1941 if (!found && !list_empty(&priv->bss_free_list)) {
1942 bss = list_entry(priv->bss_free_list.next,
David Kilroy3056c402008-08-21 23:27:57 +01001943 struct bss_element, list);
Dan Williams1e3428e2007-10-10 23:56:25 -04001944 list_del(priv->bss_free_list.next);
1945
Dan Williams1e3428e2007-10-10 23:56:25 -04001946 list_add_tail(&bss->list, &priv->bss_list);
1947 }
Dan Williams22367612007-12-05 11:01:23 -05001948
1949 if (bss) {
1950 /* Always update the BSS to get latest beacon info */
1951 memcpy(&bss->bss, atom, sizeof(bss->bss));
1952 bss->last_scanned = jiffies;
1953 }
Dan Williams1e3428e2007-10-10 23:56:25 -04001954 }
1955
1956 return 0;
1957}
1958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1960{
1961 struct orinoco_private *priv = netdev_priv(dev);
1962 u16 infofid;
1963 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001964 __le16 len;
1965 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 } __attribute__ ((packed)) info;
1967 int len, type;
1968 int err;
1969
1970 /* This is an answer to an INQUIRE command that we did earlier,
1971 * or an information "event" generated by the card
1972 * The controller return to us a pseudo frame containing
1973 * the information in question - Jean II */
1974 infofid = hermes_read_regn(hw, INFOFID);
1975
1976 /* Read the info frame header - don't try too hard */
1977 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1978 infofid, 0);
1979 if (err) {
1980 printk(KERN_ERR "%s: error %d reading info frame. "
1981 "Frame dropped.\n", dev->name, err);
1982 return;
1983 }
1984
1985 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1986 type = le16_to_cpu(info.type);
1987
1988 switch (type) {
1989 case HERMES_INQ_TALLIES: {
1990 struct hermes_tallies_frame tallies;
1991 struct iw_statistics *wstats = &priv->wstats;
1992
1993 if (len > sizeof(tallies)) {
1994 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1995 dev->name, len);
1996 len = sizeof(tallies);
1997 }
1998
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001999 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
2000 infofid, sizeof(info));
2001 if (err)
2002 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
2004 /* Increment our various counters */
2005 /* wstats->discard.nwid - no wrong BSSID stuff */
2006 wstats->discard.code +=
2007 le16_to_cpu(tallies.RxWEPUndecryptable);
2008 if (len == sizeof(tallies))
2009 wstats->discard.code +=
2010 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
2011 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
2012 wstats->discard.misc +=
2013 le16_to_cpu(tallies.TxDiscardsWrongSA);
2014 wstats->discard.fragment +=
2015 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
2016 wstats->discard.retries +=
2017 le16_to_cpu(tallies.TxRetryLimitExceeded);
2018 /* wstats->miss.beacon - no match */
2019 }
2020 break;
2021 case HERMES_INQ_LINKSTATUS: {
2022 struct hermes_linkstatus linkstatus;
2023 u16 newstatus;
2024 int connected;
2025
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02002026 if (priv->iw_mode == IW_MODE_MONITOR)
2027 break;
2028
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 if (len != sizeof(linkstatus)) {
2030 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
2031 dev->name, len);
2032 break;
2033 }
2034
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002035 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
2036 infofid, sizeof(info));
2037 if (err)
2038 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 newstatus = le16_to_cpu(linkstatus.linkstatus);
2040
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002041 /* Symbol firmware uses "out of range" to signal that
2042 * the hostscan frame can be requested. */
2043 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
2044 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
2045 priv->has_hostscan && priv->scan_inprogress) {
2046 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
2047 break;
2048 }
2049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
2051 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
2052 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
2053
2054 if (connected)
2055 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04002056 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 netif_carrier_off(dev);
2058
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002059 if (newstatus != priv->last_linkstatus) {
2060 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002062 /* The info frame contains only one word which is the
2063 * status (see hermes.h). The status is pretty boring
2064 * in itself, that's why we export the new BSSID...
2065 * Jean II */
2066 schedule_work(&priv->wevent_work);
2067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 }
2069 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002070 case HERMES_INQ_SCAN:
2071 if (!priv->scan_inprogress && priv->bssid_fixed &&
2072 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
2073 schedule_work(&priv->join_work);
2074 break;
2075 }
2076 /* fall through */
2077 case HERMES_INQ_HOSTSCAN:
2078 case HERMES_INQ_HOSTSCAN_SYMBOL: {
2079 /* Result of a scanning. Contains information about
2080 * cells in the vicinity - Jean II */
2081 union iwreq_data wrqu;
2082 unsigned char *buf;
2083
Dan Williams1e3428e2007-10-10 23:56:25 -04002084 /* Scan is no longer in progress */
2085 priv->scan_inprogress = 0;
2086
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002087 /* Sanity check */
2088 if (len > 4096) {
2089 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
2090 dev->name, len);
2091 break;
2092 }
2093
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002094 /* Allocate buffer for results */
2095 buf = kmalloc(len, GFP_ATOMIC);
2096 if (buf == NULL)
2097 /* No memory, so can't printk()... */
2098 break;
2099
2100 /* Read scan data */
2101 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
2102 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04002103 if (err) {
2104 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002105 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04002106 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002107
2108#ifdef ORINOCO_DEBUG
2109 {
2110 int i;
2111 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
2112 for(i = 1; i < (len * 2); i++)
2113 printk(":%02X", buf[i]);
2114 printk("]\n");
2115 }
2116#endif /* ORINOCO_DEBUG */
2117
Dan Williams1e3428e2007-10-10 23:56:25 -04002118 if (orinoco_process_scan_results(dev, buf, len) == 0) {
2119 /* Send an empty event to user space.
2120 * We don't send the received data on the event because
2121 * it would require us to do complex transcoding, and
2122 * we want to minimise the work done in the irq handler
2123 * Use a request to extract the data - Jean II */
2124 wrqu.data.length = 0;
2125 wrqu.data.flags = 0;
2126 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2127 }
2128 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002129 }
2130 break;
David Kilroy01632fa2008-08-21 23:27:58 +01002131 case HERMES_INQ_CHANNELINFO:
2132 {
2133 struct agere_ext_scan_info *bss;
2134
2135 if (!priv->scan_inprogress) {
2136 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
2137 "len=%d\n", dev->name, len);
2138 break;
2139 }
2140
2141 /* An empty result indicates that the scan is complete */
2142 if (len == 0) {
2143 union iwreq_data wrqu;
2144
2145 /* Scan is no longer in progress */
2146 priv->scan_inprogress = 0;
2147
2148 wrqu.data.length = 0;
2149 wrqu.data.flags = 0;
2150 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2151 break;
2152 }
2153
2154 /* Sanity check */
2155 else if (len > sizeof(*bss)) {
2156 printk(KERN_WARNING
2157 "%s: Ext scan results too large (%d bytes). "
2158 "Truncating results to %zd bytes.\n",
2159 dev->name, len, sizeof(*bss));
2160 len = sizeof(*bss);
2161 } else if (len < (offsetof(struct agere_ext_scan_info,
2162 data) + 2)) {
2163 /* Drop this result now so we don't have to
2164 * keep checking later */
2165 printk(KERN_WARNING
2166 "%s: Ext scan results too short (%d bytes)\n",
2167 dev->name, len);
2168 break;
2169 }
2170
2171 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
2172 if (bss == NULL)
2173 break;
2174
2175 /* Read scan data */
2176 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
2177 infofid, sizeof(info));
2178 if (err) {
2179 kfree(bss);
2180 break;
2181 }
2182
2183 orinoco_add_ext_scan_result(priv, bss);
2184
2185 kfree(bss);
2186 break;
2187 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002188 case HERMES_INQ_SEC_STAT_AGERE:
2189 /* Security status (Agere specific) */
2190 /* Ignore this frame for now */
2191 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2192 break;
2193 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 default:
2195 printk(KERN_DEBUG "%s: Unknown information frame received: "
2196 "type 0x%04x, length %d\n", dev->name, type, len);
2197 /* We don't actually do anything about it */
2198 break;
2199 }
2200}
2201
2202static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
2203{
2204 if (net_ratelimit())
2205 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
2206}
2207
2208/********************************************************************/
2209/* Internal hardware control routines */
2210/********************************************************************/
2211
2212int __orinoco_up(struct net_device *dev)
2213{
2214 struct orinoco_private *priv = netdev_priv(dev);
2215 struct hermes *hw = &priv->hw;
2216 int err;
2217
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002218 netif_carrier_off(dev); /* just to make sure */
2219
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 err = __orinoco_program_rids(dev);
2221 if (err) {
2222 printk(KERN_ERR "%s: Error %d configuring card\n",
2223 dev->name, err);
2224 return err;
2225 }
2226
2227 /* Fire things up again */
2228 hermes_set_irqmask(hw, ORINOCO_INTEN);
2229 err = hermes_enable_port(hw, 0);
2230 if (err) {
2231 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2232 dev->name, err);
2233 return err;
2234 }
2235
2236 netif_start_queue(dev);
2237
2238 return 0;
2239}
2240
2241int __orinoco_down(struct net_device *dev)
2242{
2243 struct orinoco_private *priv = netdev_priv(dev);
2244 struct hermes *hw = &priv->hw;
2245 int err;
2246
2247 netif_stop_queue(dev);
2248
2249 if (! priv->hw_unavailable) {
2250 if (! priv->broken_disableport) {
2251 err = hermes_disable_port(hw, 0);
2252 if (err) {
2253 /* Some firmwares (e.g. Intersil 1.3.x) seem
2254 * to have problems disabling the port, oh
2255 * well, too bad. */
2256 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2257 dev->name, err);
2258 priv->broken_disableport = 1;
2259 }
2260 }
2261 hermes_set_irqmask(hw, 0);
2262 hermes_write_regn(hw, EVACK, 0xffff);
2263 }
2264
2265 /* firmware will have to reassociate */
2266 netif_carrier_off(dev);
2267 priv->last_linkstatus = 0xffff;
2268
2269 return 0;
2270}
2271
Pavel Roskin37a6c612006-04-07 04:10:49 -04002272static int orinoco_allocate_fid(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273{
2274 struct orinoco_private *priv = netdev_priv(dev);
2275 struct hermes *hw = &priv->hw;
2276 int err;
2277
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04002279 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 /* Try workaround for old Symbol firmware bug */
2281 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2282 "(old Symbol firmware?). Trying to work around... ",
2283 dev->name);
2284
2285 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2286 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2287 if (err)
2288 printk("failed!\n");
2289 else
2290 printk("ok.\n");
2291 }
2292
2293 return err;
2294}
2295
Pavel Roskin37a6c612006-04-07 04:10:49 -04002296int orinoco_reinit_firmware(struct net_device *dev)
2297{
2298 struct orinoco_private *priv = netdev_priv(dev);
2299 struct hermes *hw = &priv->hw;
2300 int err;
2301
2302 err = hermes_init(hw);
Andrey Borzenkov0df6cbb2008-10-12 20:15:43 +04002303 if (priv->do_fw_download && !err) {
2304 err = orinoco_download(priv);
2305 if (err)
2306 priv->do_fw_download = 0;
2307 }
Pavel Roskin37a6c612006-04-07 04:10:49 -04002308 if (!err)
2309 err = orinoco_allocate_fid(dev);
2310
2311 return err;
2312}
2313
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2315{
2316 hermes_t *hw = &priv->hw;
2317 int err = 0;
2318
2319 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
2320 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
2321 priv->ndev->name, priv->bitratemode);
2322 return -EINVAL;
2323 }
2324
2325 switch (priv->firmware_type) {
2326 case FIRMWARE_TYPE_AGERE:
2327 err = hermes_write_wordrec(hw, USER_BAP,
2328 HERMES_RID_CNFTXRATECONTROL,
2329 bitrate_table[priv->bitratemode].agere_txratectrl);
2330 break;
2331 case FIRMWARE_TYPE_INTERSIL:
2332 case FIRMWARE_TYPE_SYMBOL:
2333 err = hermes_write_wordrec(hw, USER_BAP,
2334 HERMES_RID_CNFTXRATECONTROL,
2335 bitrate_table[priv->bitratemode].intersil_txratectrl);
2336 break;
2337 default:
2338 BUG();
2339 }
2340
2341 return err;
2342}
2343
Christoph Hellwig16739b02005-06-19 01:27:51 +02002344/* Set fixed AP address */
2345static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2346{
2347 int roaming_flag;
2348 int err = 0;
2349 hermes_t *hw = &priv->hw;
2350
2351 switch (priv->firmware_type) {
2352 case FIRMWARE_TYPE_AGERE:
2353 /* not supported */
2354 break;
2355 case FIRMWARE_TYPE_INTERSIL:
2356 if (priv->bssid_fixed)
2357 roaming_flag = 2;
2358 else
2359 roaming_flag = 1;
2360
2361 err = hermes_write_wordrec(hw, USER_BAP,
2362 HERMES_RID_CNFROAMINGMODE,
2363 roaming_flag);
2364 break;
2365 case FIRMWARE_TYPE_SYMBOL:
2366 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2367 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2368 &priv->desired_bssid);
2369 break;
2370 }
2371 return err;
2372}
2373
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374/* Change the WEP keys and/or the current keys. Can be called
David Kilroyd03032a2008-08-21 23:28:02 +01002375 * either from __orinoco_hw_setup_enc() or directly from
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 * orinoco_ioctl_setiwencode(). In the later case the association
2377 * with the AP is not broken (if the firmware can handle it),
2378 * which is needed for 802.1x implementations. */
2379static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2380{
2381 hermes_t *hw = &priv->hw;
2382 int err = 0;
2383
2384 switch (priv->firmware_type) {
2385 case FIRMWARE_TYPE_AGERE:
2386 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2387 HERMES_RID_CNFWEPKEYS_AGERE,
2388 &priv->keys);
2389 if (err)
2390 return err;
2391 err = hermes_write_wordrec(hw, USER_BAP,
2392 HERMES_RID_CNFTXKEY_AGERE,
2393 priv->tx_key);
2394 if (err)
2395 return err;
2396 break;
2397 case FIRMWARE_TYPE_INTERSIL:
2398 case FIRMWARE_TYPE_SYMBOL:
2399 {
2400 int keylen;
2401 int i;
2402
2403 /* Force uniform key length to work around firmware bugs */
2404 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
2405
2406 if (keylen > LARGE_KEY_SIZE) {
2407 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2408 priv->ndev->name, priv->tx_key, keylen);
2409 return -E2BIG;
2410 }
2411
2412 /* Write all 4 keys */
2413 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
2414 err = hermes_write_ltv(hw, USER_BAP,
2415 HERMES_RID_CNFDEFAULTKEY0 + i,
2416 HERMES_BYTES_TO_RECLEN(keylen),
2417 priv->keys[i].data);
2418 if (err)
2419 return err;
2420 }
2421
2422 /* Write the index of the key used in transmission */
2423 err = hermes_write_wordrec(hw, USER_BAP,
2424 HERMES_RID_CNFWEPDEFAULTKEYID,
2425 priv->tx_key);
2426 if (err)
2427 return err;
2428 }
2429 break;
2430 }
2431
2432 return 0;
2433}
2434
David Kilroyd03032a2008-08-21 23:28:02 +01002435static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436{
2437 hermes_t *hw = &priv->hw;
2438 int err = 0;
2439 int master_wep_flag;
2440 int auth_flag;
David Kilroy4ae6ee22008-08-21 23:27:59 +01002441 int enc_flag;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
David Kilroyd03032a2008-08-21 23:28:02 +01002443 /* Setup WEP keys for WEP and WPA */
2444 if (priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 __orinoco_hw_setup_wepkeys(priv);
2446
2447 if (priv->wep_restrict)
2448 auth_flag = HERMES_AUTH_SHARED_KEY;
2449 else
2450 auth_flag = HERMES_AUTH_OPEN;
2451
David Kilroyd03032a2008-08-21 23:28:02 +01002452 if (priv->wpa_enabled)
2453 enc_flag = 2;
2454 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
David Kilroy4ae6ee22008-08-21 23:27:59 +01002455 enc_flag = 1;
2456 else
2457 enc_flag = 0;
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 switch (priv->firmware_type) {
2460 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002461 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 /* Enable the shared-key authentication. */
2463 err = hermes_write_wordrec(hw, USER_BAP,
2464 HERMES_RID_CNFAUTHENTICATION_AGERE,
2465 auth_flag);
2466 }
2467 err = hermes_write_wordrec(hw, USER_BAP,
2468 HERMES_RID_CNFWEPENABLED_AGERE,
David Kilroy4ae6ee22008-08-21 23:27:59 +01002469 enc_flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 if (err)
2471 return err;
David Kilroyd03032a2008-08-21 23:28:02 +01002472
2473 if (priv->has_wpa) {
2474 /* Set WPA key management */
2475 err = hermes_write_wordrec(hw, USER_BAP,
2476 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2477 priv->key_mgmt);
2478 if (err)
2479 return err;
2480 }
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 break;
2483
2484 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2485 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
David Kilroy4ae6ee22008-08-21 23:27:59 +01002486 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 if (priv->wep_restrict ||
2488 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2489 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2490 HERMES_WEP_EXCL_UNENCRYPTED;
2491 else
2492 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2493
2494 err = hermes_write_wordrec(hw, USER_BAP,
2495 HERMES_RID_CNFAUTHENTICATION,
2496 auth_flag);
2497 if (err)
2498 return err;
2499 } else
2500 master_wep_flag = 0;
2501
2502 if (priv->iw_mode == IW_MODE_MONITOR)
2503 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2504
2505 /* Master WEP setting : on/off */
2506 err = hermes_write_wordrec(hw, USER_BAP,
2507 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2508 master_wep_flag);
2509 if (err)
2510 return err;
2511
2512 break;
2513 }
2514
2515 return 0;
2516}
2517
David Kilroyd03032a2008-08-21 23:28:02 +01002518/* key must be 32 bytes, including the tx and rx MIC keys.
2519 * rsc must be 8 bytes
2520 * tsc must be 8 bytes or NULL
2521 */
2522static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2523 u8 *key, u8 *rsc, u8 *tsc)
2524{
2525 struct {
2526 __le16 idx;
2527 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2528 u8 key[TKIP_KEYLEN];
2529 u8 tx_mic[MIC_KEYLEN];
2530 u8 rx_mic[MIC_KEYLEN];
2531 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2532 } __attribute__ ((packed)) buf;
2533 int ret;
2534 int err;
2535 int k;
2536 u16 xmitting;
2537
2538 key_idx &= 0x3;
2539
2540 if (set_tx)
2541 key_idx |= 0x8000;
2542
2543 buf.idx = cpu_to_le16(key_idx);
2544 memcpy(buf.key, key,
2545 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2546
2547 if (rsc == NULL)
2548 memset(buf.rsc, 0, sizeof(buf.rsc));
2549 else
2550 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2551
2552 if (tsc == NULL) {
2553 memset(buf.tsc, 0, sizeof(buf.tsc));
2554 buf.tsc[4] = 0x10;
2555 } else {
2556 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2557 }
2558
2559 /* Wait upto 100ms for tx queue to empty */
2560 k = 100;
2561 do {
2562 k--;
2563 udelay(1000);
2564 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2565 &xmitting);
2566 if (ret)
2567 break;
2568 } while ((k > 0) && xmitting);
2569
2570 if (k == 0)
2571 ret = -ETIMEDOUT;
2572
2573 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2574 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2575 &buf);
2576
2577 return ret ? ret : err;
2578}
2579
2580static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2581 int key_idx)
2582{
2583 hermes_t *hw = &priv->hw;
2584 int err;
2585
2586 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2587 err = hermes_write_wordrec(hw, USER_BAP,
2588 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2589 key_idx);
2590 if (err)
2591 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2592 priv->ndev->name, err, key_idx);
2593 return err;
2594}
2595
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596static int __orinoco_program_rids(struct net_device *dev)
2597{
2598 struct orinoco_private *priv = netdev_priv(dev);
2599 hermes_t *hw = &priv->hw;
2600 int err;
2601 struct hermes_idstring idbuf;
2602
2603 /* Set the MAC address */
2604 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2605 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2606 if (err) {
2607 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2608 dev->name, err);
2609 return err;
2610 }
2611
2612 /* Set up the link mode */
2613 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2614 priv->port_type);
2615 if (err) {
2616 printk(KERN_ERR "%s: Error %d setting port type\n",
2617 dev->name, err);
2618 return err;
2619 }
2620 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04002621 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2622 err = hermes_write_wordrec(hw, USER_BAP,
2623 HERMES_RID_CNFOWNCHANNEL,
2624 priv->channel);
2625 if (err) {
2626 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2627 dev->name, err, priv->channel);
2628 return err;
2629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 }
2631
2632 if (priv->has_ibss) {
2633 u16 createibss;
2634
2635 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2636 printk(KERN_WARNING "%s: This firmware requires an "
2637 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2638 /* With wvlan_cs, in this case, we would crash.
2639 * hopefully, this driver will behave better...
2640 * Jean II */
2641 createibss = 0;
2642 } else {
2643 createibss = priv->createibss;
2644 }
2645
2646 err = hermes_write_wordrec(hw, USER_BAP,
2647 HERMES_RID_CNFCREATEIBSS,
2648 createibss);
2649 if (err) {
2650 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2651 dev->name, err);
2652 return err;
2653 }
2654 }
2655
Christoph Hellwig16739b02005-06-19 01:27:51 +02002656 /* Set the desired BSSID */
2657 err = __orinoco_hw_set_wap(priv);
2658 if (err) {
2659 printk(KERN_ERR "%s: Error %d setting AP address\n",
2660 dev->name, err);
2661 return err;
2662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 /* Set the desired ESSID */
2664 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2665 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2666 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2667 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2668 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2669 &idbuf);
2670 if (err) {
2671 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2672 dev->name, err);
2673 return err;
2674 }
2675 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2676 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2677 &idbuf);
2678 if (err) {
2679 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2680 dev->name, err);
2681 return err;
2682 }
2683
2684 /* Set the station name */
2685 idbuf.len = cpu_to_le16(strlen(priv->nick));
2686 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2687 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2688 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2689 &idbuf);
2690 if (err) {
2691 printk(KERN_ERR "%s: Error %d setting nickname\n",
2692 dev->name, err);
2693 return err;
2694 }
2695
2696 /* Set AP density */
2697 if (priv->has_sensitivity) {
2698 err = hermes_write_wordrec(hw, USER_BAP,
2699 HERMES_RID_CNFSYSTEMSCALE,
2700 priv->ap_density);
2701 if (err) {
2702 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2703 "Disabling sensitivity control\n",
2704 dev->name, err);
2705
2706 priv->has_sensitivity = 0;
2707 }
2708 }
2709
2710 /* Set RTS threshold */
2711 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2712 priv->rts_thresh);
2713 if (err) {
2714 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2715 dev->name, err);
2716 return err;
2717 }
2718
2719 /* Set fragmentation threshold or MWO robustness */
2720 if (priv->has_mwo)
2721 err = hermes_write_wordrec(hw, USER_BAP,
2722 HERMES_RID_CNFMWOROBUST_AGERE,
2723 priv->mwo_robust);
2724 else
2725 err = hermes_write_wordrec(hw, USER_BAP,
2726 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2727 priv->frag_thresh);
2728 if (err) {
2729 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2730 dev->name, err);
2731 return err;
2732 }
2733
2734 /* Set bitrate */
2735 err = __orinoco_hw_set_bitrate(priv);
2736 if (err) {
2737 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2738 dev->name, err);
2739 return err;
2740 }
2741
2742 /* Set power management */
2743 if (priv->has_pm) {
2744 err = hermes_write_wordrec(hw, USER_BAP,
2745 HERMES_RID_CNFPMENABLED,
2746 priv->pm_on);
2747 if (err) {
2748 printk(KERN_ERR "%s: Error %d setting up PM\n",
2749 dev->name, err);
2750 return err;
2751 }
2752
2753 err = hermes_write_wordrec(hw, USER_BAP,
2754 HERMES_RID_CNFMULTICASTRECEIVE,
2755 priv->pm_mcast);
2756 if (err) {
2757 printk(KERN_ERR "%s: Error %d setting up PM\n",
2758 dev->name, err);
2759 return err;
2760 }
2761 err = hermes_write_wordrec(hw, USER_BAP,
2762 HERMES_RID_CNFMAXSLEEPDURATION,
2763 priv->pm_period);
2764 if (err) {
2765 printk(KERN_ERR "%s: Error %d setting up PM\n",
2766 dev->name, err);
2767 return err;
2768 }
2769 err = hermes_write_wordrec(hw, USER_BAP,
2770 HERMES_RID_CNFPMHOLDOVERDURATION,
2771 priv->pm_timeout);
2772 if (err) {
2773 printk(KERN_ERR "%s: Error %d setting up PM\n",
2774 dev->name, err);
2775 return err;
2776 }
2777 }
2778
2779 /* Set preamble - only for Symbol so far... */
2780 if (priv->has_preamble) {
2781 err = hermes_write_wordrec(hw, USER_BAP,
2782 HERMES_RID_CNFPREAMBLE_SYMBOL,
2783 priv->preamble);
2784 if (err) {
2785 printk(KERN_ERR "%s: Error %d setting preamble\n",
2786 dev->name, err);
2787 return err;
2788 }
2789 }
2790
2791 /* Set up encryption */
David Kilroyd03032a2008-08-21 23:28:02 +01002792 if (priv->has_wep || priv->has_wpa) {
2793 err = __orinoco_hw_setup_enc(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 if (err) {
David Kilroyd03032a2008-08-21 23:28:02 +01002795 printk(KERN_ERR "%s: Error %d activating encryption\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 dev->name, err);
2797 return err;
2798 }
2799 }
2800
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002801 if (priv->iw_mode == IW_MODE_MONITOR) {
2802 /* Enable monitor mode */
2803 dev->type = ARPHRD_IEEE80211;
2804 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2805 HERMES_TEST_MONITOR, 0, NULL);
2806 } else {
2807 /* Disable monitor mode */
2808 dev->type = ARPHRD_ETHER;
2809 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2810 HERMES_TEST_STOP, 0, NULL);
2811 }
2812 if (err)
2813 return err;
2814
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 /* Set promiscuity / multicast*/
2816 priv->promiscuous = 0;
2817 priv->mc_count = 0;
Herbert Xu932ff272006-06-09 12:20:56 -07002818
2819 /* FIXME: what about netif_tx_lock */
2820 __orinoco_set_multicast_list(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 return 0;
2823}
2824
2825/* FIXME: return int? */
2826static void
2827__orinoco_set_multicast_list(struct net_device *dev)
2828{
2829 struct orinoco_private *priv = netdev_priv(dev);
2830 hermes_t *hw = &priv->hw;
2831 int err = 0;
2832 int promisc, mc_count;
2833
2834 /* The Hermes doesn't seem to have an allmulti mode, so we go
2835 * into promiscuous mode and let the upper levels deal. */
2836 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2837 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2838 promisc = 1;
2839 mc_count = 0;
2840 } else {
2841 promisc = 0;
2842 mc_count = dev->mc_count;
2843 }
2844
2845 if (promisc != priv->promiscuous) {
2846 err = hermes_write_wordrec(hw, USER_BAP,
2847 HERMES_RID_CNFPROMISCUOUSMODE,
2848 promisc);
2849 if (err) {
2850 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2851 dev->name, err);
2852 } else
2853 priv->promiscuous = promisc;
2854 }
2855
David Kilroy667d4102008-08-23 19:03:34 +01002856 /* If we're not in promiscuous mode, then we need to set the
2857 * group address if either we want to multicast, or if we were
2858 * multicasting and want to stop */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 if (! promisc && (mc_count || priv->mc_count) ) {
2860 struct dev_mc_list *p = dev->mc_list;
2861 struct hermes_multicast mclist;
2862 int i;
2863
2864 for (i = 0; i < mc_count; i++) {
2865 /* paranoia: is list shorter than mc_count? */
2866 BUG_ON(! p);
2867 /* paranoia: bad address size in list? */
2868 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2869
2870 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2871 p = p->next;
2872 }
2873
2874 if (p)
2875 printk(KERN_WARNING "%s: Multicast list is "
2876 "longer than mc_count\n", dev->name);
2877
David Kilroy667d4102008-08-23 19:03:34 +01002878 err = hermes_write_ltv(hw, USER_BAP,
2879 HERMES_RID_CNFGROUPADDRESSES,
2880 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2881 &mclist);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 if (err)
2883 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2884 dev->name, err);
2885 else
2886 priv->mc_count = mc_count;
2887 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888}
2889
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890/* This must be called from user context, without locks held - use
2891 * schedule_work() */
David Howellsc4028952006-11-22 14:57:56 +00002892static void orinoco_reset(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893{
David Howellsc4028952006-11-22 14:57:56 +00002894 struct orinoco_private *priv =
2895 container_of(work, struct orinoco_private, reset_work);
2896 struct net_device *dev = priv->ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002898 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 unsigned long flags;
2900
2901 if (orinoco_lock(priv, &flags) != 0)
2902 /* When the hardware becomes available again, whatever
2903 * detects that is responsible for re-initializing
2904 * it. So no need for anything further */
2905 return;
2906
2907 netif_stop_queue(dev);
2908
2909 /* Shut off interrupts. Depending on what state the hardware
2910 * is in, this might not work, but we'll try anyway */
2911 hermes_set_irqmask(hw, 0);
2912 hermes_write_regn(hw, EVACK, 0xffff);
2913
2914 priv->hw_unavailable++;
2915 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2916 netif_carrier_off(dev);
2917
2918 orinoco_unlock(priv, &flags);
2919
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002920 /* Scanning support: Cleanup of driver struct */
Dan Williams1e3428e2007-10-10 23:56:25 -04002921 orinoco_clear_scan_results(priv, 0);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002922 priv->scan_inprogress = 0;
2923
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002924 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002926 if (err) {
2927 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2928 "performing hard reset\n", dev->name, err);
2929 goto disable;
2930 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 }
2932
2933 err = orinoco_reinit_firmware(dev);
2934 if (err) {
2935 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2936 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002937 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939
2940 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2941
2942 priv->hw_unavailable--;
2943
2944 /* priv->open or priv->hw_unavailable might have changed while
2945 * we dropped the lock */
2946 if (priv->open && (! priv->hw_unavailable)) {
2947 err = __orinoco_up(dev);
2948 if (err) {
2949 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2950 dev->name, err);
2951 } else
2952 dev->trans_start = jiffies;
2953 }
2954
2955 spin_unlock_irq(&priv->lock);
2956
2957 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02002958 disable:
2959 hermes_set_irqmask(hw, 0);
2960 netif_device_detach(dev);
2961 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962}
2963
2964/********************************************************************/
2965/* Interrupt handler */
2966/********************************************************************/
2967
2968static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2969{
2970 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2971}
2972
2973static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2974{
2975 /* This seems to happen a fair bit under load, but ignoring it
2976 seems to work fine...*/
2977 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2978 dev->name);
2979}
2980
David Howells7d12e782006-10-05 14:55:46 +01002981irqreturn_t orinoco_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982{
Jeff Garzikc31f28e2006-10-06 14:56:04 -04002983 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 struct orinoco_private *priv = netdev_priv(dev);
2985 hermes_t *hw = &priv->hw;
2986 int count = MAX_IRQLOOPS_PER_IRQ;
2987 u16 evstat, events;
2988 /* These are used to detect a runaway interrupt situation */
2989 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2990 * we panic and shut down the hardware */
2991 static int last_irq_jiffy = 0; /* jiffies value the last time
2992 * we were called */
2993 static int loops_this_jiffy = 0;
2994 unsigned long flags;
2995
2996 if (orinoco_lock(priv, &flags) != 0) {
2997 /* If hw is unavailable - we don't know if the irq was
2998 * for us or not */
2999 return IRQ_HANDLED;
3000 }
3001
3002 evstat = hermes_read_regn(hw, EVSTAT);
3003 events = evstat & hw->inten;
3004 if (! events) {
3005 orinoco_unlock(priv, &flags);
3006 return IRQ_NONE;
3007 }
3008
3009 if (jiffies != last_irq_jiffy)
3010 loops_this_jiffy = 0;
3011 last_irq_jiffy = jiffies;
3012
3013 while (events && count--) {
3014 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
3015 printk(KERN_WARNING "%s: IRQ handler is looping too "
3016 "much! Resetting.\n", dev->name);
3017 /* Disable interrupts for now */
3018 hermes_set_irqmask(hw, 0);
3019 schedule_work(&priv->reset_work);
3020 break;
3021 }
3022
3023 /* Check the card hasn't been removed */
3024 if (! hermes_present(hw)) {
3025 DEBUG(0, "orinoco_interrupt(): card removed\n");
3026 break;
3027 }
3028
3029 if (events & HERMES_EV_TICK)
3030 __orinoco_ev_tick(dev, hw);
3031 if (events & HERMES_EV_WTERR)
3032 __orinoco_ev_wterr(dev, hw);
3033 if (events & HERMES_EV_INFDROP)
3034 __orinoco_ev_infdrop(dev, hw);
3035 if (events & HERMES_EV_INFO)
3036 __orinoco_ev_info(dev, hw);
3037 if (events & HERMES_EV_RX)
3038 __orinoco_ev_rx(dev, hw);
3039 if (events & HERMES_EV_TXEXC)
3040 __orinoco_ev_txexc(dev, hw);
3041 if (events & HERMES_EV_TX)
3042 __orinoco_ev_tx(dev, hw);
3043 if (events & HERMES_EV_ALLOC)
3044 __orinoco_ev_alloc(dev, hw);
3045
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003046 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047
3048 evstat = hermes_read_regn(hw, EVSTAT);
3049 events = evstat & hw->inten;
3050 };
3051
3052 orinoco_unlock(priv, &flags);
3053 return IRQ_HANDLED;
3054}
3055
3056/********************************************************************/
3057/* Initialization */
3058/********************************************************************/
3059
3060struct comp_id {
3061 u16 id, variant, major, minor;
3062} __attribute__ ((packed));
3063
3064static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
3065{
3066 if (nic_id->id < 0x8000)
3067 return FIRMWARE_TYPE_AGERE;
3068 else if (nic_id->id == 0x8000 && nic_id->major == 0)
3069 return FIRMWARE_TYPE_SYMBOL;
3070 else
3071 return FIRMWARE_TYPE_INTERSIL;
3072}
3073
3074/* Set priv->firmware type, determine firmware properties */
3075static int determine_firmware(struct net_device *dev)
3076{
3077 struct orinoco_private *priv = netdev_priv(dev);
3078 hermes_t *hw = &priv->hw;
3079 int err;
3080 struct comp_id nic_id, sta_id;
3081 unsigned int firmver;
Hennerich, Michaeldde6d432007-02-05 16:41:35 -08003082 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
3084 /* Get the hardware version */
3085 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
3086 if (err) {
3087 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
3088 dev->name, err);
3089 return err;
3090 }
3091
3092 le16_to_cpus(&nic_id.id);
3093 le16_to_cpus(&nic_id.variant);
3094 le16_to_cpus(&nic_id.major);
3095 le16_to_cpus(&nic_id.minor);
3096 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
3097 dev->name, nic_id.id, nic_id.variant,
3098 nic_id.major, nic_id.minor);
3099
3100 priv->firmware_type = determine_firmware_type(&nic_id);
3101
3102 /* Get the firmware version */
3103 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
3104 if (err) {
3105 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
3106 dev->name, err);
3107 return err;
3108 }
3109
3110 le16_to_cpus(&sta_id.id);
3111 le16_to_cpus(&sta_id.variant);
3112 le16_to_cpus(&sta_id.major);
3113 le16_to_cpus(&sta_id.minor);
3114 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
3115 dev->name, sta_id.id, sta_id.variant,
3116 sta_id.major, sta_id.minor);
3117
3118 switch (sta_id.id) {
3119 case 0x15:
3120 printk(KERN_ERR "%s: Primary firmware is active\n",
3121 dev->name);
3122 return -ENODEV;
3123 case 0x14b:
3124 printk(KERN_ERR "%s: Tertiary firmware is active\n",
3125 dev->name);
3126 return -ENODEV;
3127 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3128 case 0x21: /* Symbol Spectrum24 Trilogy */
3129 break;
3130 default:
3131 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
3132 dev->name);
3133 break;
3134 }
3135
3136 /* Default capabilities */
3137 priv->has_sensitivity = 1;
3138 priv->has_mwo = 0;
3139 priv->has_preamble = 0;
3140 priv->has_port3 = 1;
3141 priv->has_ibss = 1;
3142 priv->has_wep = 0;
3143 priv->has_big_wep = 0;
David Kilroy6eecad72008-08-21 23:27:56 +01003144 priv->has_alt_txcntl = 0;
David Kilroy01632fa2008-08-21 23:27:58 +01003145 priv->has_ext_scan = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01003146 priv->has_wpa = 0;
David Kilroy3994d502008-08-21 23:27:54 +01003147 priv->do_fw_download = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 /* Determine capabilities from the firmware version */
3150 switch (priv->firmware_type) {
3151 case FIRMWARE_TYPE_AGERE:
3152 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3153 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3154 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3155 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
3156
3157 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
3158
3159 priv->has_ibss = (firmver >= 0x60006);
3160 priv->has_wep = (firmver >= 0x40020);
3161 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
3162 Gold cards from the others? */
3163 priv->has_mwo = (firmver >= 0x60000);
3164 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3165 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003166 priv->has_hostscan = (firmver >= 0x8000a);
David Kilroy3994d502008-08-21 23:27:54 +01003167 priv->do_fw_download = 1;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003168 priv->broken_monitor = (firmver >= 0x80000);
David Kilroy6eecad72008-08-21 23:27:56 +01003169 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
David Kilroy01632fa2008-08-21 23:27:58 +01003170 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
David Kilroyd03032a2008-08-21 23:28:02 +01003171 priv->has_wpa = (firmver >= 0x9002a);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 /* Tested with Agere firmware :
3173 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3174 * Tested CableTron firmware : 4.32 => Anton */
3175 break;
3176 case FIRMWARE_TYPE_SYMBOL:
3177 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3178 /* Intel MAC : 00:02:B3:* */
3179 /* 3Com MAC : 00:50:DA:* */
3180 memset(tmp, 0, sizeof(tmp));
3181 /* Get the Symbol firmware version */
3182 err = hermes_read_ltv(hw, USER_BAP,
3183 HERMES_RID_SECONDARYVERSION_SYMBOL,
3184 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3185 if (err) {
3186 printk(KERN_WARNING
3187 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3188 dev->name, err);
3189 firmver = 0;
3190 tmp[0] = '\0';
3191 } else {
3192 /* The firmware revision is a string, the format is
3193 * something like : "V2.20-01".
3194 * Quick and dirty parsing... - Jean II
3195 */
3196 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
3197 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
3198 | (tmp[7] - '0');
3199
3200 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3201 }
3202
3203 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3204 "Symbol %s", tmp);
3205
3206 priv->has_ibss = (firmver >= 0x20000);
3207 priv->has_wep = (firmver >= 0x15012);
3208 priv->has_big_wep = (firmver >= 0x20000);
3209 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
3210 (firmver >= 0x29000 && firmver < 0x30000) ||
3211 firmver >= 0x31000;
3212 priv->has_preamble = (firmver >= 0x20000);
3213 priv->ibss_port = 4;
David Kilroy3994d502008-08-21 23:27:54 +01003214
3215 /* Symbol firmware is found on various cards, but
3216 * there has been no attempt to check firmware
3217 * download on non-spectrum_cs based cards.
3218 *
3219 * Given that the Agere firmware download works
3220 * differently, we should avoid doing a firmware
3221 * download with the Symbol algorithm on non-spectrum
3222 * cards.
3223 *
3224 * For now we can identify a spectrum_cs based card
3225 * because it has a firmware reset function.
3226 */
3227 priv->do_fw_download = (priv->stop_fw != NULL);
3228
Christoph Hellwig649e59e2005-05-14 17:30:10 +02003229 priv->broken_disableport = (firmver == 0x25013) ||
3230 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003231 priv->has_hostscan = (firmver >= 0x31001) ||
3232 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 /* Tested with Intel firmware : 0x20015 => Jean II */
3234 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3235 break;
3236 case FIRMWARE_TYPE_INTERSIL:
3237 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3238 * Samsung, Compaq 100/200 and Proxim are slightly
3239 * different and less well tested */
3240 /* D-Link MAC : 00:40:05:* */
3241 /* Addtron MAC : 00:90:D1:* */
3242 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3243 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3244 sta_id.variant);
3245
3246 firmver = ((unsigned long)sta_id.major << 16) |
3247 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3248
3249 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3250 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3251 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003252 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253
3254 if (firmver >= 0x000800)
3255 priv->ibss_port = 0;
3256 else {
3257 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3258 "than v0.8.x - several features not supported\n",
3259 dev->name);
3260 priv->ibss_port = 1;
3261 }
3262 break;
3263 }
3264 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3265 priv->fw_name);
3266
3267 return 0;
3268}
3269
3270static int orinoco_init(struct net_device *dev)
3271{
3272 struct orinoco_private *priv = netdev_priv(dev);
3273 hermes_t *hw = &priv->hw;
3274 int err = 0;
3275 struct hermes_idstring nickbuf;
3276 u16 reclen;
3277 int len;
3278
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 /* No need to lock, the hw_unavailable flag is already set in
3280 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04003281 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
3283 /* Initialize the firmware */
Pavel Roskin37a6c612006-04-07 04:10:49 -04003284 err = hermes_init(hw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 if (err != 0) {
3286 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3287 dev->name, err);
3288 goto out;
3289 }
3290
3291 err = determine_firmware(dev);
3292 if (err != 0) {
3293 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3294 dev->name);
3295 goto out;
3296 }
3297
David Kilroy3994d502008-08-21 23:27:54 +01003298 if (priv->do_fw_download) {
3299 err = orinoco_download(priv);
3300 if (err)
3301 priv->do_fw_download = 0;
3302
3303 /* Check firmware version again */
3304 err = determine_firmware(dev);
3305 if (err != 0) {
3306 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3307 dev->name);
3308 goto out;
3309 }
3310 }
3311
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 if (priv->has_port3)
3313 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
3314 if (priv->has_ibss)
3315 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3316 dev->name);
3317 if (priv->has_wep) {
3318 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
3319 if (priv->has_big_wep)
3320 printk("104-bit key\n");
3321 else
3322 printk("40-bit key\n");
3323 }
David Kilroy23edcc42008-08-21 23:28:05 +01003324 if (priv->has_wpa) {
David Kilroyd03032a2008-08-21 23:28:02 +01003325 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
David Kilroy23edcc42008-08-21 23:28:05 +01003326 if (orinoco_mic_init(priv)) {
3327 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3328 "algorithm. Disabling WPA support\n", dev->name);
3329 priv->has_wpa = 0;
3330 }
3331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332
David Kilroy01632fa2008-08-21 23:27:58 +01003333 /* Now we have the firmware capabilities, allocate appropiate
3334 * sized scan buffers */
3335 if (orinoco_bss_data_allocate(priv))
3336 goto out;
3337 orinoco_bss_data_init(priv);
3338
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /* Get the MAC address */
3340 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3341 ETH_ALEN, NULL, dev->dev_addr);
3342 if (err) {
3343 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3344 dev->name);
3345 goto out;
3346 }
3347
Johannes Berge1749612008-10-27 15:59:26 -07003348 printk(KERN_DEBUG "%s: MAC address %pM\n",
3349 dev->name, dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350
3351 /* Get the station name */
3352 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3353 sizeof(nickbuf), &reclen, &nickbuf);
3354 if (err) {
3355 printk(KERN_ERR "%s: failed to read station name\n",
3356 dev->name);
3357 goto out;
3358 }
3359 if (nickbuf.len)
3360 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3361 else
3362 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3363 memcpy(priv->nick, &nickbuf.val, len);
3364 priv->nick[len] = '\0';
3365
3366 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3367
Pavel Roskin37a6c612006-04-07 04:10:49 -04003368 err = orinoco_allocate_fid(dev);
3369 if (err) {
3370 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3371 dev->name);
3372 goto out;
3373 }
3374
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 /* Get allowed channels */
3376 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3377 &priv->channel_mask);
3378 if (err) {
3379 printk(KERN_ERR "%s: failed to read channel list!\n",
3380 dev->name);
3381 goto out;
3382 }
3383
3384 /* Get initial AP density */
3385 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3386 &priv->ap_density);
3387 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
3388 priv->has_sensitivity = 0;
3389 }
3390
3391 /* Get initial RTS threshold */
3392 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3393 &priv->rts_thresh);
3394 if (err) {
3395 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3396 dev->name);
3397 goto out;
3398 }
3399
3400 /* Get initial fragmentation settings */
3401 if (priv->has_mwo)
3402 err = hermes_read_wordrec(hw, USER_BAP,
3403 HERMES_RID_CNFMWOROBUST_AGERE,
3404 &priv->mwo_robust);
3405 else
3406 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3407 &priv->frag_thresh);
3408 if (err) {
3409 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3410 dev->name);
3411 goto out;
3412 }
3413
3414 /* Power management setup */
3415 if (priv->has_pm) {
3416 priv->pm_on = 0;
3417 priv->pm_mcast = 1;
3418 err = hermes_read_wordrec(hw, USER_BAP,
3419 HERMES_RID_CNFMAXSLEEPDURATION,
3420 &priv->pm_period);
3421 if (err) {
3422 printk(KERN_ERR "%s: failed to read power management period!\n",
3423 dev->name);
3424 goto out;
3425 }
3426 err = hermes_read_wordrec(hw, USER_BAP,
3427 HERMES_RID_CNFPMHOLDOVERDURATION,
3428 &priv->pm_timeout);
3429 if (err) {
3430 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3431 dev->name);
3432 goto out;
3433 }
3434 }
3435
3436 /* Preamble setup */
3437 if (priv->has_preamble) {
3438 err = hermes_read_wordrec(hw, USER_BAP,
3439 HERMES_RID_CNFPREAMBLE_SYMBOL,
3440 &priv->preamble);
3441 if (err)
3442 goto out;
3443 }
3444
3445 /* Set up the default configuration */
3446 priv->iw_mode = IW_MODE_INFRA;
3447 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3448 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
3449 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04003450 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
3452 priv->promiscuous = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003453 priv->encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003454 priv->tx_key = 0;
David Kilroyd03032a2008-08-21 23:28:02 +01003455 priv->wpa_enabled = 0;
3456 priv->tkip_cm_active = 0;
3457 priv->key_mgmt = 0;
3458 priv->wpa_ie_len = 0;
3459 priv->wpa_ie = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 /* Make the hardware available, as long as it hasn't been
3462 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3463 spin_lock_irq(&priv->lock);
3464 priv->hw_unavailable--;
3465 spin_unlock_irq(&priv->lock);
3466
3467 printk(KERN_DEBUG "%s: ready\n", dev->name);
3468
3469 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 return err;
3471}
3472
David Kilroy3994d502008-08-21 23:27:54 +01003473struct net_device
3474*alloc_orinocodev(int sizeof_card,
3475 struct device *device,
3476 int (*hard_reset)(struct orinoco_private *),
3477 int (*stop_fw)(struct orinoco_private *, int))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478{
3479 struct net_device *dev;
3480 struct orinoco_private *priv;
3481
3482 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
3483 if (! dev)
3484 return NULL;
3485 priv = netdev_priv(dev);
3486 priv->ndev = dev;
3487 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003488 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 + sizeof(struct orinoco_private));
3490 else
3491 priv->card = NULL;
David Kilroy3994d502008-08-21 23:27:54 +01003492 priv->dev = device;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
3494 /* Setup / override net_device fields */
3495 dev->init = orinoco_init;
3496 dev->hard_start_xmit = orinoco_xmit;
3497 dev->tx_timeout = orinoco_tx_timeout;
3498 dev->watchdog_timeo = HZ; /* 1 second timeout */
3499 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02003500 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003501 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04003502#ifdef WIRELESS_SPY
3503 priv->wireless_data.spy_data = &priv->spy_data;
3504 dev->wireless_data = &priv->wireless_data;
3505#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 dev->change_mtu = orinoco_change_mtu;
3507 dev->set_multicast_list = orinoco_set_multicast_list;
3508 /* we use the default eth_mac_addr for setting the MAC addr */
3509
David Kilroy23edcc42008-08-21 23:28:05 +01003510 /* Reserve space in skb for the SNAP header */
3511 dev->hard_header_len += ENCAPS_OVERHEAD;
3512
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 /* Set up default callbacks */
3514 dev->open = orinoco_open;
3515 dev->stop = orinoco_stop;
3516 priv->hard_reset = hard_reset;
David Kilroy3994d502008-08-21 23:27:54 +01003517 priv->stop_fw = stop_fw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518
3519 spin_lock_init(&priv->lock);
3520 priv->open = 0;
3521 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3522 * before anything else touches the
3523 * hardware */
David Howellsc4028952006-11-22 14:57:56 +00003524 INIT_WORK(&priv->reset_work, orinoco_reset);
3525 INIT_WORK(&priv->join_work, orinoco_join_ap);
3526 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527
David Kilroy31afcef2008-08-21 23:28:04 +01003528 INIT_LIST_HEAD(&priv->rx_list);
3529 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3530 (unsigned long) dev);
3531
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 netif_carrier_off(dev);
3533 priv->last_linkstatus = 0xffff;
3534
3535 return dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536}
3537
3538void free_orinocodev(struct net_device *dev)
3539{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003540 struct orinoco_private *priv = netdev_priv(dev);
3541
David Kilroy31afcef2008-08-21 23:28:04 +01003542 /* No need to empty priv->rx_list: if the tasklet is scheduled
3543 * when we call tasklet_kill it will run one final time,
3544 * emptying the list */
3545 tasklet_kill(&priv->rx_tasklet);
David Kilroyd03032a2008-08-21 23:28:02 +01003546 priv->wpa_ie_len = 0;
3547 kfree(priv->wpa_ie);
David Kilroy23edcc42008-08-21 23:28:05 +01003548 orinoco_mic_free(priv);
Dan Williams1e3428e2007-10-10 23:56:25 -04003549 orinoco_bss_data_free(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 free_netdev(dev);
3551}
3552
3553/********************************************************************/
3554/* Wireless extensions */
3555/********************************************************************/
3556
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003557/* Return : < 0 -> error code ; >= 0 -> length */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3559 char buf[IW_ESSID_MAX_SIZE+1])
3560{
3561 hermes_t *hw = &priv->hw;
3562 int err = 0;
3563 struct hermes_idstring essidbuf;
3564 char *p = (char *)(&essidbuf.val);
3565 int len;
3566 unsigned long flags;
3567
3568 if (orinoco_lock(priv, &flags) != 0)
3569 return -EBUSY;
3570
3571 if (strlen(priv->desired_essid) > 0) {
3572 /* We read the desired SSID from the hardware rather
3573 than from priv->desired_essid, just in case the
3574 firmware is allowed to change it on us. I'm not
3575 sure about this */
3576 /* My guess is that the OWNSSID should always be whatever
3577 * we set to the card, whereas CURRENT_SSID is the one that
3578 * may change... - Jean II */
3579 u16 rid;
3580
3581 *active = 1;
3582
3583 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3584 HERMES_RID_CNFDESIREDSSID;
3585
3586 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3587 NULL, &essidbuf);
3588 if (err)
3589 goto fail_unlock;
3590 } else {
3591 *active = 0;
3592
3593 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3594 sizeof(essidbuf), NULL, &essidbuf);
3595 if (err)
3596 goto fail_unlock;
3597 }
3598
3599 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02003600 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003602 memset(buf, 0, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 memcpy(buf, p, len);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07003604 err = len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
3606 fail_unlock:
3607 orinoco_unlock(priv, &flags);
3608
3609 return err;
3610}
3611
3612static long orinoco_hw_get_freq(struct orinoco_private *priv)
3613{
3614
3615 hermes_t *hw = &priv->hw;
3616 int err = 0;
3617 u16 channel;
3618 long freq = 0;
3619 unsigned long flags;
3620
3621 if (orinoco_lock(priv, &flags) != 0)
3622 return -EBUSY;
3623
3624 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3625 if (err)
3626 goto out;
3627
3628 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3629 if (channel == 0) {
3630 err = -EBUSY;
3631 goto out;
3632 }
3633
3634 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3635 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3636 priv->ndev->name, channel);
3637 err = -EBUSY;
3638 goto out;
3639
3640 }
3641 freq = channel_frequency[channel-1] * 100000;
3642
3643 out:
3644 orinoco_unlock(priv, &flags);
3645
3646 if (err > 0)
3647 err = -EBUSY;
3648 return err ? err : freq;
3649}
3650
3651static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3652 int *numrates, s32 *rates, int max)
3653{
3654 hermes_t *hw = &priv->hw;
3655 struct hermes_idstring list;
3656 unsigned char *p = (unsigned char *)&list.val;
3657 int err = 0;
3658 int num;
3659 int i;
3660 unsigned long flags;
3661
3662 if (orinoco_lock(priv, &flags) != 0)
3663 return -EBUSY;
3664
3665 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3666 sizeof(list), NULL, &list);
3667 orinoco_unlock(priv, &flags);
3668
3669 if (err)
3670 return err;
3671
3672 num = le16_to_cpu(list.len);
3673 *numrates = num;
3674 num = min(num, max);
3675
3676 for (i = 0; i < num; i++) {
3677 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3678 }
3679
3680 return 0;
3681}
3682
Christoph Hellwig620554e2005-06-19 01:27:33 +02003683static int orinoco_ioctl_getname(struct net_device *dev,
3684 struct iw_request_info *info,
3685 char *name,
3686 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687{
3688 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003689 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003690 int err;
3691
3692 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3693
3694 if (!err && (numrates > 2))
3695 strcpy(name, "IEEE 802.11b");
3696 else
3697 strcpy(name, "IEEE 802.11-DS");
3698
3699 return 0;
3700}
3701
Christoph Hellwig16739b02005-06-19 01:27:51 +02003702static int orinoco_ioctl_setwap(struct net_device *dev,
3703 struct iw_request_info *info,
3704 struct sockaddr *ap_addr,
3705 char *extra)
3706{
3707 struct orinoco_private *priv = netdev_priv(dev);
3708 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02003710 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3711 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712
3713 if (orinoco_lock(priv, &flags) != 0)
3714 return -EBUSY;
3715
Christoph Hellwig16739b02005-06-19 01:27:51 +02003716 /* Enable automatic roaming - no sanity checks are needed */
3717 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3718 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3719 priv->bssid_fixed = 0;
3720 memset(priv->desired_bssid, 0, ETH_ALEN);
3721
3722 /* "off" means keep existing connection */
3723 if (ap_addr->sa_data[0] == 0) {
3724 __orinoco_hw_set_wap(priv);
3725 err = 0;
3726 }
3727 goto out;
3728 }
3729
3730 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3731 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3732 "support manual roaming\n",
3733 dev->name);
3734 err = -EOPNOTSUPP;
3735 goto out;
3736 }
3737
3738 if (priv->iw_mode != IW_MODE_INFRA) {
3739 printk(KERN_WARNING "%s: Manual roaming supported only in "
3740 "managed mode\n", dev->name);
3741 err = -EOPNOTSUPP;
3742 goto out;
3743 }
3744
3745 /* Intersil firmware hangs without Desired ESSID */
3746 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3747 strlen(priv->desired_essid) == 0) {
3748 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3749 "manual roaming\n", dev->name);
3750 err = -EOPNOTSUPP;
3751 goto out;
3752 }
3753
3754 /* Finally, enable manual roaming */
3755 priv->bssid_fixed = 1;
3756 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3757
3758 out:
3759 orinoco_unlock(priv, &flags);
3760 return err;
3761}
3762
Christoph Hellwig620554e2005-06-19 01:27:33 +02003763static int orinoco_ioctl_getwap(struct net_device *dev,
3764 struct iw_request_info *info,
3765 struct sockaddr *ap_addr,
3766 char *extra)
3767{
3768 struct orinoco_private *priv = netdev_priv(dev);
3769
3770 hermes_t *hw = &priv->hw;
3771 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 unsigned long flags;
3773
Linus Torvalds1da177e2005-04-16 15:20:36 -07003774 if (orinoco_lock(priv, &flags) != 0)
3775 return -EBUSY;
3776
Christoph Hellwig620554e2005-06-19 01:27:33 +02003777 ap_addr->sa_family = ARPHRD_ETHER;
3778 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3779 ETH_ALEN, NULL, ap_addr->sa_data);
3780
Linus Torvalds1da177e2005-04-16 15:20:36 -07003781 orinoco_unlock(priv, &flags);
3782
Christoph Hellwig620554e2005-06-19 01:27:33 +02003783 return err;
3784}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Christoph Hellwig620554e2005-06-19 01:27:33 +02003786static int orinoco_ioctl_setmode(struct net_device *dev,
3787 struct iw_request_info *info,
3788 u32 *mode,
3789 char *extra)
3790{
3791 struct orinoco_private *priv = netdev_priv(dev);
3792 int err = -EINPROGRESS; /* Call commit handler */
3793 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794
Christoph Hellwig620554e2005-06-19 01:27:33 +02003795 if (priv->iw_mode == *mode)
3796 return 0;
3797
3798 if (orinoco_lock(priv, &flags) != 0)
3799 return -EBUSY;
3800
3801 switch (*mode) {
3802 case IW_MODE_ADHOC:
3803 if (!priv->has_ibss && !priv->has_port3)
3804 err = -EOPNOTSUPP;
3805 break;
3806
3807 case IW_MODE_INFRA:
3808 break;
3809
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003810 case IW_MODE_MONITOR:
3811 if (priv->broken_monitor && !force_monitor) {
3812 printk(KERN_WARNING "%s: Monitor mode support is "
3813 "buggy in this firmware, not enabling\n",
3814 dev->name);
3815 err = -EOPNOTSUPP;
3816 }
3817 break;
3818
Christoph Hellwig620554e2005-06-19 01:27:33 +02003819 default:
3820 err = -EOPNOTSUPP;
3821 break;
3822 }
3823
3824 if (err == -EINPROGRESS) {
3825 priv->iw_mode = *mode;
3826 set_port_type(priv);
3827 }
3828
3829 orinoco_unlock(priv, &flags);
3830
3831 return err;
3832}
3833
3834static int orinoco_ioctl_getmode(struct net_device *dev,
3835 struct iw_request_info *info,
3836 u32 *mode,
3837 char *extra)
3838{
3839 struct orinoco_private *priv = netdev_priv(dev);
3840
3841 *mode = priv->iw_mode;
3842 return 0;
3843}
3844
3845static int orinoco_ioctl_getiwrange(struct net_device *dev,
3846 struct iw_request_info *info,
3847 struct iw_point *rrq,
3848 char *extra)
3849{
3850 struct orinoco_private *priv = netdev_priv(dev);
3851 int err = 0;
3852 struct iw_range *range = (struct iw_range *) extra;
3853 int numrates;
3854 int i, k;
3855
Christoph Hellwig620554e2005-06-19 01:27:33 +02003856 rrq->length = sizeof(struct iw_range);
3857 memset(range, 0, sizeof(struct iw_range));
3858
3859 range->we_version_compiled = WIRELESS_EXT;
David Kilroyd03032a2008-08-21 23:28:02 +01003860 range->we_version_source = 22;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003863 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864 k = 0;
3865 for (i = 0; i < NUM_CHANNELS; i++) {
3866 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003867 range->freq[k].i = i + 1;
3868 range->freq[k].m = channel_frequency[i] * 100000;
3869 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003870 k++;
3871 }
3872
3873 if (k >= IW_MAX_FREQUENCIES)
3874 break;
3875 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02003876 range->num_frequency = k;
3877 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878
Christoph Hellwig620554e2005-06-19 01:27:33 +02003879 if (priv->has_wep) {
3880 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3881 range->encoding_size[0] = SMALL_KEY_SIZE;
3882 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883
Christoph Hellwig620554e2005-06-19 01:27:33 +02003884 if (priv->has_big_wep) {
3885 range->encoding_size[1] = LARGE_KEY_SIZE;
3886 range->num_encoding_sizes = 2;
3887 }
3888 }
3889
David Kilroyd03032a2008-08-21 23:28:02 +01003890 if (priv->has_wpa)
3891 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
3892
Pavel Roskin343c6862005-09-09 18:43:02 -04003893 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02003896 range->max_qual.qual = 0x8b - 0x2f;
3897 range->max_qual.level = 0x2f - 0x95 - 1;
3898 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003900 range->avg_qual.qual = 0x24;
3901 range->avg_qual.level = 0xC2;
3902 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003903 }
3904
3905 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02003906 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 if (err)
3908 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003909 range->num_bitrates = numrates;
3910
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911 /* Set an indication of the max TCP throughput in bit/s that we can
3912 * expect using this interface. May be use for QoS stuff...
3913 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02003914 if (numrates > 2)
3915 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02003917 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918
Christoph Hellwig620554e2005-06-19 01:27:33 +02003919 range->min_rts = 0;
3920 range->max_rts = 2347;
3921 range->min_frag = 256;
3922 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923
Christoph Hellwig620554e2005-06-19 01:27:33 +02003924 range->min_pmp = 0;
3925 range->max_pmp = 65535000;
3926 range->min_pmt = 0;
3927 range->max_pmt = 65535 * 1000; /* ??? */
3928 range->pmp_flags = IW_POWER_PERIOD;
3929 range->pmt_flags = IW_POWER_TIMEOUT;
3930 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003931
Christoph Hellwig620554e2005-06-19 01:27:33 +02003932 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3933 range->retry_flags = IW_RETRY_LIMIT;
3934 range->r_time_flags = IW_RETRY_LIFETIME;
3935 range->min_retry = 0;
3936 range->max_retry = 65535; /* ??? */
3937 range->min_r_time = 0;
3938 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003939
David Kilroy0753bba2008-08-21 23:27:46 +01003940 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3941 range->scan_capa = IW_SCAN_CAPA_ESSID;
3942 else
3943 range->scan_capa = IW_SCAN_CAPA_NONE;
3944
Pavel Roskin343c6862005-09-09 18:43:02 -04003945 /* Event capability (kernel) */
3946 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3947 /* Event capability (driver) */
3948 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3949 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3950 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3951 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3952
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 return 0;
3954}
3955
Christoph Hellwig620554e2005-06-19 01:27:33 +02003956static int orinoco_ioctl_setiwencode(struct net_device *dev,
3957 struct iw_request_info *info,
3958 struct iw_point *erq,
3959 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003960{
3961 struct orinoco_private *priv = netdev_priv(dev);
3962 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3963 int setindex = priv->tx_key;
David Kilroy4ae6ee22008-08-21 23:27:59 +01003964 int encode_alg = priv->encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 int restricted = priv->wep_restrict;
3966 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003967 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 unsigned long flags;
3969
3970 if (! priv->has_wep)
3971 return -EOPNOTSUPP;
3972
3973 if (erq->pointer) {
3974 /* We actually have a key to set - check its length */
3975 if (erq->length > LARGE_KEY_SIZE)
3976 return -E2BIG;
3977
3978 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3979 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003980 }
3981
3982 if (orinoco_lock(priv, &flags) != 0)
3983 return -EBUSY;
3984
David Kilroyd03032a2008-08-21 23:28:02 +01003985 /* Clear any TKIP key we have */
3986 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3987 (void) orinoco_clear_tkip_key(priv, setindex);
3988
Dan Williamsfe397d42006-07-14 11:41:47 -04003989 if (erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003990 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3991 index = priv->tx_key;
3992
3993 /* Adjust key length to a supported value */
3994 if (erq->length > SMALL_KEY_SIZE) {
3995 xlen = LARGE_KEY_SIZE;
3996 } else if (erq->length > 0) {
3997 xlen = SMALL_KEY_SIZE;
3998 } else
3999 xlen = 0;
4000
4001 /* Switch on WEP if off */
David Kilroy4ae6ee22008-08-21 23:27:59 +01004002 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 setindex = index;
David Kilroy4ae6ee22008-08-21 23:27:59 +01004004 encode_alg = IW_ENCODE_ALG_WEP;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 }
4006 } else {
4007 /* Important note : if the user do "iwconfig eth0 enc off",
4008 * we will arrive there with an index of -1. This is valid
4009 * but need to be taken care off... Jean II */
4010 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
4011 if((index != -1) || (erq->flags == 0)) {
4012 err = -EINVAL;
4013 goto out;
4014 }
4015 } else {
4016 /* Set the index : Check that the key is valid */
4017 if(priv->keys[index].len == 0) {
4018 err = -EINVAL;
4019 goto out;
4020 }
4021 setindex = index;
4022 }
4023 }
4024
4025 if (erq->flags & IW_ENCODE_DISABLED)
David Kilroy4ae6ee22008-08-21 23:27:59 +01004026 encode_alg = IW_ENCODE_ALG_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027 if (erq->flags & IW_ENCODE_OPEN)
4028 restricted = 0;
4029 if (erq->flags & IW_ENCODE_RESTRICTED)
4030 restricted = 1;
4031
Dan Williamsfe397d42006-07-14 11:41:47 -04004032 if (erq->pointer && erq->length > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033 priv->keys[index].len = cpu_to_le16(xlen);
4034 memset(priv->keys[index].data, 0,
4035 sizeof(priv->keys[index].data));
4036 memcpy(priv->keys[index].data, keybuf, erq->length);
4037 }
4038 priv->tx_key = setindex;
4039
4040 /* Try fast key change if connected and only keys are changed */
David Kilroy4ae6ee22008-08-21 23:27:59 +01004041 if ((priv->encode_alg == encode_alg) &&
4042 (priv->wep_restrict == restricted) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 netif_carrier_ok(dev)) {
4044 err = __orinoco_hw_setup_wepkeys(priv);
4045 /* No need to commit if successful */
4046 goto out;
4047 }
4048
David Kilroy4ae6ee22008-08-21 23:27:59 +01004049 priv->encode_alg = encode_alg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 priv->wep_restrict = restricted;
4051
4052 out:
4053 orinoco_unlock(priv, &flags);
4054
4055 return err;
4056}
4057
Christoph Hellwig620554e2005-06-19 01:27:33 +02004058static int orinoco_ioctl_getiwencode(struct net_device *dev,
4059 struct iw_request_info *info,
4060 struct iw_point *erq,
4061 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062{
4063 struct orinoco_private *priv = netdev_priv(dev);
4064 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4065 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066 unsigned long flags;
4067
4068 if (! priv->has_wep)
4069 return -EOPNOTSUPP;
4070
4071 if (orinoco_lock(priv, &flags) != 0)
4072 return -EBUSY;
4073
4074 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4075 index = priv->tx_key;
4076
4077 erq->flags = 0;
David Kilroy4ae6ee22008-08-21 23:27:59 +01004078 if (!priv->encode_alg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 erq->flags |= IW_ENCODE_DISABLED;
4080 erq->flags |= index + 1;
4081
4082 if (priv->wep_restrict)
4083 erq->flags |= IW_ENCODE_RESTRICTED;
4084 else
4085 erq->flags |= IW_ENCODE_OPEN;
4086
4087 xlen = le16_to_cpu(priv->keys[index].len);
4088
4089 erq->length = xlen;
4090
4091 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
4092
4093 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094 return 0;
4095}
4096
Christoph Hellwig620554e2005-06-19 01:27:33 +02004097static int orinoco_ioctl_setessid(struct net_device *dev,
4098 struct iw_request_info *info,
4099 struct iw_point *erq,
4100 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004101{
4102 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 unsigned long flags;
4104
4105 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4106 * anyway... - Jean II */
4107
Christoph Hellwig620554e2005-06-19 01:27:33 +02004108 /* Hum... Should not use Wireless Extension constant (may change),
4109 * should use our own... - Jean II */
4110 if (erq->length > IW_ESSID_MAX_SIZE)
4111 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004112
4113 if (orinoco_lock(priv, &flags) != 0)
4114 return -EBUSY;
4115
Christoph Hellwig620554e2005-06-19 01:27:33 +02004116 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4117 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
4118
4119 /* If not ANY, get the new ESSID */
4120 if (erq->flags) {
4121 memcpy(priv->desired_essid, essidbuf, erq->length);
4122 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123
4124 orinoco_unlock(priv, &flags);
4125
Christoph Hellwig620554e2005-06-19 01:27:33 +02004126 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127}
4128
Christoph Hellwig620554e2005-06-19 01:27:33 +02004129static int orinoco_ioctl_getessid(struct net_device *dev,
4130 struct iw_request_info *info,
4131 struct iw_point *erq,
4132 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004133{
4134 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 int active;
4136 int err = 0;
4137 unsigned long flags;
4138
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 if (netif_running(dev)) {
4140 err = orinoco_hw_get_essid(priv, &active, essidbuf);
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004141 if (err < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 return err;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004143 erq->length = err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 } else {
4145 if (orinoco_lock(priv, &flags) != 0)
4146 return -EBUSY;
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004147 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4148 erq->length = strlen(priv->desired_essid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004149 orinoco_unlock(priv, &flags);
4150 }
4151
4152 erq->flags = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 return 0;
4155}
4156
Christoph Hellwig620554e2005-06-19 01:27:33 +02004157static int orinoco_ioctl_setnick(struct net_device *dev,
4158 struct iw_request_info *info,
4159 struct iw_point *nrq,
4160 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161{
4162 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 unsigned long flags;
4164
4165 if (nrq->length > IW_ESSID_MAX_SIZE)
4166 return -E2BIG;
4167
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 if (orinoco_lock(priv, &flags) != 0)
4169 return -EBUSY;
4170
Christoph Hellwig620554e2005-06-19 01:27:33 +02004171 memset(priv->nick, 0, sizeof(priv->nick));
4172 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004173
4174 orinoco_unlock(priv, &flags);
4175
Christoph Hellwig620554e2005-06-19 01:27:33 +02004176 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177}
4178
Christoph Hellwig620554e2005-06-19 01:27:33 +02004179static int orinoco_ioctl_getnick(struct net_device *dev,
4180 struct iw_request_info *info,
4181 struct iw_point *nrq,
4182 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004183{
4184 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 unsigned long flags;
4186
4187 if (orinoco_lock(priv, &flags) != 0)
4188 return -EBUSY;
4189
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004190 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004191 orinoco_unlock(priv, &flags);
4192
Jean Tourrilhes7e4e8d92006-10-10 14:45:44 -07004193 nrq->length = strlen(priv->nick);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194
Linus Torvalds1da177e2005-04-16 15:20:36 -07004195 return 0;
4196}
4197
Christoph Hellwig620554e2005-06-19 01:27:33 +02004198static int orinoco_ioctl_setfreq(struct net_device *dev,
4199 struct iw_request_info *info,
4200 struct iw_freq *frq,
4201 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202{
4203 struct orinoco_private *priv = netdev_priv(dev);
4204 int chan = -1;
4205 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004206 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004208 /* In infrastructure mode the AP sets the channel */
4209 if (priv->iw_mode == IW_MODE_INFRA)
4210 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004211
4212 if ( (frq->e == 0) && (frq->m <= 1000) ) {
4213 /* Setting by channel number */
4214 chan = frq->m;
4215 } else {
4216 /* Setting by frequency - search the table */
4217 int mult = 1;
4218 int i;
4219
4220 for (i = 0; i < (6 - frq->e); i++)
4221 mult *= 10;
4222
4223 for (i = 0; i < NUM_CHANNELS; i++)
4224 if (frq->m == (channel_frequency[i] * mult))
4225 chan = i+1;
4226 }
4227
4228 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
4229 ! (priv->channel_mask & (1 << (chan-1)) ) )
4230 return -EINVAL;
4231
4232 if (orinoco_lock(priv, &flags) != 0)
4233 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004234
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02004236 if (priv->iw_mode == IW_MODE_MONITOR) {
4237 /* Fast channel change - no commit if successful */
4238 hermes_t *hw = &priv->hw;
4239 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4240 HERMES_TEST_SET_CHANNEL,
4241 chan, NULL);
4242 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004243 orinoco_unlock(priv, &flags);
4244
Christoph Hellwig620554e2005-06-19 01:27:33 +02004245 return err;
4246}
4247
4248static int orinoco_ioctl_getfreq(struct net_device *dev,
4249 struct iw_request_info *info,
4250 struct iw_freq *frq,
4251 char *extra)
4252{
4253 struct orinoco_private *priv = netdev_priv(dev);
4254 int tmp;
4255
4256 /* Locking done in there */
4257 tmp = orinoco_hw_get_freq(priv);
4258 if (tmp < 0) {
4259 return tmp;
4260 }
4261
4262 frq->m = tmp;
4263 frq->e = 1;
4264
Linus Torvalds1da177e2005-04-16 15:20:36 -07004265 return 0;
4266}
4267
Christoph Hellwig620554e2005-06-19 01:27:33 +02004268static int orinoco_ioctl_getsens(struct net_device *dev,
4269 struct iw_request_info *info,
4270 struct iw_param *srq,
4271 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004272{
4273 struct orinoco_private *priv = netdev_priv(dev);
4274 hermes_t *hw = &priv->hw;
4275 u16 val;
4276 int err;
4277 unsigned long flags;
4278
4279 if (!priv->has_sensitivity)
4280 return -EOPNOTSUPP;
4281
4282 if (orinoco_lock(priv, &flags) != 0)
4283 return -EBUSY;
4284 err = hermes_read_wordrec(hw, USER_BAP,
4285 HERMES_RID_CNFSYSTEMSCALE, &val);
4286 orinoco_unlock(priv, &flags);
4287
4288 if (err)
4289 return err;
4290
4291 srq->value = val;
4292 srq->fixed = 0; /* auto */
4293
4294 return 0;
4295}
4296
Christoph Hellwig620554e2005-06-19 01:27:33 +02004297static int orinoco_ioctl_setsens(struct net_device *dev,
4298 struct iw_request_info *info,
4299 struct iw_param *srq,
4300 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301{
4302 struct orinoco_private *priv = netdev_priv(dev);
4303 int val = srq->value;
4304 unsigned long flags;
4305
4306 if (!priv->has_sensitivity)
4307 return -EOPNOTSUPP;
4308
4309 if ((val < 1) || (val > 3))
4310 return -EINVAL;
4311
4312 if (orinoco_lock(priv, &flags) != 0)
4313 return -EBUSY;
4314 priv->ap_density = val;
4315 orinoco_unlock(priv, &flags);
4316
Christoph Hellwig620554e2005-06-19 01:27:33 +02004317 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004318}
4319
Christoph Hellwig620554e2005-06-19 01:27:33 +02004320static int orinoco_ioctl_setrts(struct net_device *dev,
4321 struct iw_request_info *info,
4322 struct iw_param *rrq,
4323 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324{
4325 struct orinoco_private *priv = netdev_priv(dev);
4326 int val = rrq->value;
4327 unsigned long flags;
4328
4329 if (rrq->disabled)
4330 val = 2347;
4331
4332 if ( (val < 0) || (val > 2347) )
4333 return -EINVAL;
4334
4335 if (orinoco_lock(priv, &flags) != 0)
4336 return -EBUSY;
4337
4338 priv->rts_thresh = val;
4339 orinoco_unlock(priv, &flags);
4340
Christoph Hellwig620554e2005-06-19 01:27:33 +02004341 return -EINPROGRESS; /* Call commit handler */
4342}
4343
4344static int orinoco_ioctl_getrts(struct net_device *dev,
4345 struct iw_request_info *info,
4346 struct iw_param *rrq,
4347 char *extra)
4348{
4349 struct orinoco_private *priv = netdev_priv(dev);
4350
4351 rrq->value = priv->rts_thresh;
4352 rrq->disabled = (rrq->value == 2347);
4353 rrq->fixed = 1;
4354
Linus Torvalds1da177e2005-04-16 15:20:36 -07004355 return 0;
4356}
4357
Christoph Hellwig620554e2005-06-19 01:27:33 +02004358static int orinoco_ioctl_setfrag(struct net_device *dev,
4359 struct iw_request_info *info,
4360 struct iw_param *frq,
4361 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004362{
4363 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004364 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004365 unsigned long flags;
4366
4367 if (orinoco_lock(priv, &flags) != 0)
4368 return -EBUSY;
4369
4370 if (priv->has_mwo) {
4371 if (frq->disabled)
4372 priv->mwo_robust = 0;
4373 else {
4374 if (frq->fixed)
4375 printk(KERN_WARNING "%s: Fixed fragmentation is "
4376 "not supported on this firmware. "
4377 "Using MWO robust instead.\n", dev->name);
4378 priv->mwo_robust = 1;
4379 }
4380 } else {
4381 if (frq->disabled)
4382 priv->frag_thresh = 2346;
4383 else {
4384 if ( (frq->value < 256) || (frq->value > 2346) )
4385 err = -EINVAL;
4386 else
4387 priv->frag_thresh = frq->value & ~0x1; /* must be even */
4388 }
4389 }
4390
4391 orinoco_unlock(priv, &flags);
4392
4393 return err;
4394}
4395
Christoph Hellwig620554e2005-06-19 01:27:33 +02004396static int orinoco_ioctl_getfrag(struct net_device *dev,
4397 struct iw_request_info *info,
4398 struct iw_param *frq,
4399 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004400{
4401 struct orinoco_private *priv = netdev_priv(dev);
4402 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004403 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004404 u16 val;
4405 unsigned long flags;
4406
4407 if (orinoco_lock(priv, &flags) != 0)
4408 return -EBUSY;
4409
4410 if (priv->has_mwo) {
4411 err = hermes_read_wordrec(hw, USER_BAP,
4412 HERMES_RID_CNFMWOROBUST_AGERE,
4413 &val);
4414 if (err)
4415 val = 0;
4416
4417 frq->value = val ? 2347 : 0;
4418 frq->disabled = ! val;
4419 frq->fixed = 0;
4420 } else {
4421 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
4422 &val);
4423 if (err)
4424 val = 0;
4425
4426 frq->value = val;
4427 frq->disabled = (val >= 2346);
4428 frq->fixed = 1;
4429 }
4430
4431 orinoco_unlock(priv, &flags);
4432
4433 return err;
4434}
4435
Christoph Hellwig620554e2005-06-19 01:27:33 +02004436static int orinoco_ioctl_setrate(struct net_device *dev,
4437 struct iw_request_info *info,
4438 struct iw_param *rrq,
4439 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004440{
4441 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004442 int ratemode = -1;
4443 int bitrate; /* 100s of kilobits */
4444 int i;
4445 unsigned long flags;
4446
4447 /* As the user space doesn't know our highest rate, it uses -1
4448 * to ask us to set the highest rate. Test it using "iwconfig
4449 * ethX rate auto" - Jean II */
4450 if (rrq->value == -1)
4451 bitrate = 110;
4452 else {
4453 if (rrq->value % 100000)
4454 return -EINVAL;
4455 bitrate = rrq->value / 100000;
4456 }
4457
4458 if ( (bitrate != 10) && (bitrate != 20) &&
4459 (bitrate != 55) && (bitrate != 110) )
4460 return -EINVAL;
4461
4462 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4463 if ( (bitrate_table[i].bitrate == bitrate) &&
4464 (bitrate_table[i].automatic == ! rrq->fixed) ) {
4465 ratemode = i;
4466 break;
4467 }
4468
4469 if (ratemode == -1)
4470 return -EINVAL;
4471
4472 if (orinoco_lock(priv, &flags) != 0)
4473 return -EBUSY;
4474 priv->bitratemode = ratemode;
4475 orinoco_unlock(priv, &flags);
4476
Christoph Hellwig620554e2005-06-19 01:27:33 +02004477 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478}
4479
Christoph Hellwig620554e2005-06-19 01:27:33 +02004480static int orinoco_ioctl_getrate(struct net_device *dev,
4481 struct iw_request_info *info,
4482 struct iw_param *rrq,
4483 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004484{
4485 struct orinoco_private *priv = netdev_priv(dev);
4486 hermes_t *hw = &priv->hw;
4487 int err = 0;
4488 int ratemode;
4489 int i;
4490 u16 val;
4491 unsigned long flags;
4492
4493 if (orinoco_lock(priv, &flags) != 0)
4494 return -EBUSY;
4495
4496 ratemode = priv->bitratemode;
4497
4498 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4499
4500 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4501 rrq->fixed = ! bitrate_table[ratemode].automatic;
4502 rrq->disabled = 0;
4503
4504 /* If the interface is running we try to find more about the
4505 current mode */
4506 if (netif_running(dev)) {
4507 err = hermes_read_wordrec(hw, USER_BAP,
4508 HERMES_RID_CURRENTTXRATE, &val);
4509 if (err)
4510 goto out;
4511
4512 switch (priv->firmware_type) {
4513 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4514 /* Note : in Lucent firmware, the return value of
4515 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4516 * and therefore is totally different from the
4517 * encoding of HERMES_RID_CNFTXRATECONTROL.
4518 * Don't forget that 6Mb/s is really 5.5Mb/s */
4519 if (val == 6)
4520 rrq->value = 5500000;
4521 else
4522 rrq->value = val * 1000000;
4523 break;
4524 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4525 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4526 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4527 if (bitrate_table[i].intersil_txratectrl == val) {
4528 ratemode = i;
4529 break;
4530 }
4531 if (i >= BITRATE_TABLE_SIZE)
4532 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4533 dev->name, val);
4534
4535 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4536 break;
4537 default:
4538 BUG();
4539 }
4540 }
4541
4542 out:
4543 orinoco_unlock(priv, &flags);
4544
4545 return err;
4546}
4547
Christoph Hellwig620554e2005-06-19 01:27:33 +02004548static int orinoco_ioctl_setpower(struct net_device *dev,
4549 struct iw_request_info *info,
4550 struct iw_param *prq,
4551 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004552{
4553 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004554 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004555 unsigned long flags;
4556
4557 if (orinoco_lock(priv, &flags) != 0)
4558 return -EBUSY;
4559
4560 if (prq->disabled) {
4561 priv->pm_on = 0;
4562 } else {
4563 switch (prq->flags & IW_POWER_MODE) {
4564 case IW_POWER_UNICAST_R:
4565 priv->pm_mcast = 0;
4566 priv->pm_on = 1;
4567 break;
4568 case IW_POWER_ALL_R:
4569 priv->pm_mcast = 1;
4570 priv->pm_on = 1;
4571 break;
4572 case IW_POWER_ON:
4573 /* No flags : but we may have a value - Jean II */
4574 break;
4575 default:
4576 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004577 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05004578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004579
4580 if (prq->flags & IW_POWER_TIMEOUT) {
4581 priv->pm_on = 1;
4582 priv->pm_timeout = prq->value / 1000;
4583 }
4584 if (prq->flags & IW_POWER_PERIOD) {
4585 priv->pm_on = 1;
4586 priv->pm_period = prq->value / 1000;
4587 }
4588 /* It's valid to not have a value if we are just toggling
4589 * the flags... Jean II */
4590 if(!priv->pm_on) {
4591 err = -EINVAL;
4592 goto out;
4593 }
4594 }
4595
4596 out:
4597 orinoco_unlock(priv, &flags);
4598
4599 return err;
4600}
4601
Christoph Hellwig620554e2005-06-19 01:27:33 +02004602static int orinoco_ioctl_getpower(struct net_device *dev,
4603 struct iw_request_info *info,
4604 struct iw_param *prq,
4605 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004606{
4607 struct orinoco_private *priv = netdev_priv(dev);
4608 hermes_t *hw = &priv->hw;
4609 int err = 0;
4610 u16 enable, period, timeout, mcast;
4611 unsigned long flags;
4612
4613 if (orinoco_lock(priv, &flags) != 0)
4614 return -EBUSY;
4615
4616 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
4617 if (err)
4618 goto out;
4619
4620 err = hermes_read_wordrec(hw, USER_BAP,
4621 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4622 if (err)
4623 goto out;
4624
4625 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4626 if (err)
4627 goto out;
4628
4629 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4630 if (err)
4631 goto out;
4632
4633 prq->disabled = !enable;
4634 /* Note : by default, display the period */
4635 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4636 prq->flags = IW_POWER_TIMEOUT;
4637 prq->value = timeout * 1000;
4638 } else {
4639 prq->flags = IW_POWER_PERIOD;
4640 prq->value = period * 1000;
4641 }
4642 if (mcast)
4643 prq->flags |= IW_POWER_ALL_R;
4644 else
4645 prq->flags |= IW_POWER_UNICAST_R;
4646
4647 out:
4648 orinoco_unlock(priv, &flags);
4649
4650 return err;
4651}
4652
David Kilroyd03032a2008-08-21 23:28:02 +01004653static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4654 struct iw_request_info *info,
4655 union iwreq_data *wrqu,
4656 char *extra)
4657{
4658 struct orinoco_private *priv = netdev_priv(dev);
4659 struct iw_point *encoding = &wrqu->encoding;
4660 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4661 int idx, alg = ext->alg, set_key = 1;
4662 unsigned long flags;
4663 int err = -EINVAL;
4664 u16 key_len;
4665
4666 if (orinoco_lock(priv, &flags) != 0)
4667 return -EBUSY;
4668
4669 /* Determine and validate the key index */
4670 idx = encoding->flags & IW_ENCODE_INDEX;
4671 if (idx) {
4672 if ((idx < 1) || (idx > WEP_KEYS))
4673 goto out;
4674 idx--;
4675 } else
4676 idx = priv->tx_key;
4677
4678 if (encoding->flags & IW_ENCODE_DISABLED)
4679 alg = IW_ENCODE_ALG_NONE;
4680
4681 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4682 /* Clear any TKIP TX key we had */
4683 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4684 }
4685
4686 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4687 priv->tx_key = idx;
4688 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4689 (ext->key_len > 0)) ? 1 : 0;
4690 }
4691
4692 if (set_key) {
4693 /* Set the requested key first */
4694 switch (alg) {
4695 case IW_ENCODE_ALG_NONE:
4696 priv->encode_alg = alg;
4697 priv->keys[idx].len = 0;
4698 break;
4699
4700 case IW_ENCODE_ALG_WEP:
4701 if (ext->key_len > SMALL_KEY_SIZE)
4702 key_len = LARGE_KEY_SIZE;
4703 else if (ext->key_len > 0)
4704 key_len = SMALL_KEY_SIZE;
4705 else
4706 goto out;
4707
4708 priv->encode_alg = alg;
4709 priv->keys[idx].len = cpu_to_le16(key_len);
4710
4711 key_len = min(ext->key_len, key_len);
4712
4713 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4714 memcpy(priv->keys[idx].data, ext->key, key_len);
4715 break;
4716
4717 case IW_ENCODE_ALG_TKIP:
4718 {
4719 hermes_t *hw = &priv->hw;
4720 u8 *tkip_iv = NULL;
4721
4722 if (!priv->has_wpa ||
4723 (ext->key_len > sizeof(priv->tkip_key[0])))
4724 goto out;
4725
4726 priv->encode_alg = alg;
4727 memset(&priv->tkip_key[idx], 0,
4728 sizeof(priv->tkip_key[idx]));
4729 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4730
4731 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4732 tkip_iv = &ext->rx_seq[0];
4733
4734 err = __orinoco_hw_set_tkip_key(hw, idx,
4735 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4736 (u8 *) &priv->tkip_key[idx],
4737 tkip_iv, NULL);
4738 if (err)
4739 printk(KERN_ERR "%s: Error %d setting TKIP key"
4740 "\n", dev->name, err);
4741
4742 goto out;
4743 }
4744 default:
4745 goto out;
4746 }
4747 }
4748 err = -EINPROGRESS;
4749 out:
4750 orinoco_unlock(priv, &flags);
4751
4752 return err;
4753}
4754
4755static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4756 struct iw_request_info *info,
4757 union iwreq_data *wrqu,
4758 char *extra)
4759{
4760 struct orinoco_private *priv = netdev_priv(dev);
4761 struct iw_point *encoding = &wrqu->encoding;
4762 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4763 int idx, max_key_len;
4764 unsigned long flags;
4765 int err;
4766
4767 if (orinoco_lock(priv, &flags) != 0)
4768 return -EBUSY;
4769
4770 err = -EINVAL;
4771 max_key_len = encoding->length - sizeof(*ext);
4772 if (max_key_len < 0)
4773 goto out;
4774
4775 idx = encoding->flags & IW_ENCODE_INDEX;
4776 if (idx) {
4777 if ((idx < 1) || (idx > WEP_KEYS))
4778 goto out;
4779 idx--;
4780 } else
4781 idx = priv->tx_key;
4782
4783 encoding->flags = idx + 1;
4784 memset(ext, 0, sizeof(*ext));
4785
4786 ext->alg = priv->encode_alg;
4787 switch (priv->encode_alg) {
4788 case IW_ENCODE_ALG_NONE:
4789 ext->key_len = 0;
4790 encoding->flags |= IW_ENCODE_DISABLED;
4791 break;
4792 case IW_ENCODE_ALG_WEP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004793 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
4794 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004795 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4796 encoding->flags |= IW_ENCODE_ENABLED;
4797 break;
4798 case IW_ENCODE_ALG_TKIP:
David Kilroy75d31cf2008-09-12 22:28:18 +01004799 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
4800 max_key_len);
David Kilroyd03032a2008-08-21 23:28:02 +01004801 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4802 encoding->flags |= IW_ENCODE_ENABLED;
4803 break;
4804 }
4805
4806 err = 0;
4807 out:
4808 orinoco_unlock(priv, &flags);
4809
4810 return err;
4811}
4812
4813static int orinoco_ioctl_set_auth(struct net_device *dev,
4814 struct iw_request_info *info,
4815 union iwreq_data *wrqu, char *extra)
4816{
4817 struct orinoco_private *priv = netdev_priv(dev);
4818 hermes_t *hw = &priv->hw;
4819 struct iw_param *param = &wrqu->param;
4820 unsigned long flags;
4821 int ret = -EINPROGRESS;
4822
4823 if (orinoco_lock(priv, &flags) != 0)
4824 return -EBUSY;
4825
4826 switch (param->flags & IW_AUTH_INDEX) {
4827 case IW_AUTH_WPA_VERSION:
4828 case IW_AUTH_CIPHER_PAIRWISE:
4829 case IW_AUTH_CIPHER_GROUP:
4830 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4831 case IW_AUTH_PRIVACY_INVOKED:
4832 case IW_AUTH_DROP_UNENCRYPTED:
4833 /*
4834 * orinoco does not use these parameters
4835 */
4836 break;
4837
4838 case IW_AUTH_KEY_MGMT:
4839 /* wl_lkm implies value 2 == PSK for Hermes I
4840 * which ties in with WEXT
4841 * no other hints tho :(
4842 */
4843 priv->key_mgmt = param->value;
4844 break;
4845
4846 case IW_AUTH_TKIP_COUNTERMEASURES:
4847 /* When countermeasures are enabled, shut down the
4848 * card; when disabled, re-enable the card. This must
4849 * take effect immediately.
4850 *
4851 * TODO: Make sure that the EAPOL message is getting
4852 * out before card disabled
4853 */
4854 if (param->value) {
4855 priv->tkip_cm_active = 1;
4856 ret = hermes_enable_port(hw, 0);
4857 } else {
4858 priv->tkip_cm_active = 0;
4859 ret = hermes_disable_port(hw, 0);
4860 }
4861 break;
4862
4863 case IW_AUTH_80211_AUTH_ALG:
4864 if (param->value & IW_AUTH_ALG_SHARED_KEY)
4865 priv->wep_restrict = 1;
4866 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
4867 priv->wep_restrict = 0;
4868 else
4869 ret = -EINVAL;
4870 break;
4871
4872 case IW_AUTH_WPA_ENABLED:
4873 if (priv->has_wpa) {
4874 priv->wpa_enabled = param->value ? 1 : 0;
4875 } else {
4876 if (param->value)
4877 ret = -EOPNOTSUPP;
4878 /* else silently accept disable of WPA */
4879 priv->wpa_enabled = 0;
4880 }
4881 break;
4882
4883 default:
4884 ret = -EOPNOTSUPP;
4885 }
4886
4887 orinoco_unlock(priv, &flags);
4888 return ret;
4889}
4890
4891static int orinoco_ioctl_get_auth(struct net_device *dev,
4892 struct iw_request_info *info,
4893 union iwreq_data *wrqu, char *extra)
4894{
4895 struct orinoco_private *priv = netdev_priv(dev);
4896 struct iw_param *param = &wrqu->param;
4897 unsigned long flags;
4898 int ret = 0;
4899
4900 if (orinoco_lock(priv, &flags) != 0)
4901 return -EBUSY;
4902
4903 switch (param->flags & IW_AUTH_INDEX) {
4904 case IW_AUTH_KEY_MGMT:
4905 param->value = priv->key_mgmt;
4906 break;
4907
4908 case IW_AUTH_TKIP_COUNTERMEASURES:
4909 param->value = priv->tkip_cm_active;
4910 break;
4911
4912 case IW_AUTH_80211_AUTH_ALG:
4913 if (priv->wep_restrict)
4914 param->value = IW_AUTH_ALG_SHARED_KEY;
4915 else
4916 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
4917 break;
4918
4919 case IW_AUTH_WPA_ENABLED:
4920 param->value = priv->wpa_enabled;
4921 break;
4922
4923 default:
4924 ret = -EOPNOTSUPP;
4925 }
4926
4927 orinoco_unlock(priv, &flags);
4928 return ret;
4929}
4930
4931static int orinoco_ioctl_set_genie(struct net_device *dev,
4932 struct iw_request_info *info,
4933 union iwreq_data *wrqu, char *extra)
4934{
4935 struct orinoco_private *priv = netdev_priv(dev);
4936 u8 *buf;
4937 unsigned long flags;
4938 int err = 0;
4939
4940 if ((wrqu->data.length > MAX_WPA_IE_LEN) ||
4941 (wrqu->data.length && (extra == NULL)))
4942 return -EINVAL;
4943
4944 if (orinoco_lock(priv, &flags) != 0)
4945 return -EBUSY;
4946
4947 if (wrqu->data.length) {
4948 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
4949 if (buf == NULL) {
4950 err = -ENOMEM;
4951 goto out;
4952 }
4953
4954 memcpy(buf, extra, wrqu->data.length);
4955 kfree(priv->wpa_ie);
4956 priv->wpa_ie = buf;
4957 priv->wpa_ie_len = wrqu->data.length;
4958 } else {
4959 kfree(priv->wpa_ie);
4960 priv->wpa_ie = NULL;
4961 priv->wpa_ie_len = 0;
4962 }
4963
4964 if (priv->wpa_ie) {
4965 /* Looks like wl_lkm wants to check the auth alg, and
4966 * somehow pass it to the firmware.
4967 * Instead it just calls the key mgmt rid
4968 * - we do this in set auth.
4969 */
4970 }
4971
4972out:
4973 orinoco_unlock(priv, &flags);
4974 return err;
4975}
4976
4977static int orinoco_ioctl_get_genie(struct net_device *dev,
4978 struct iw_request_info *info,
4979 union iwreq_data *wrqu, char *extra)
4980{
4981 struct orinoco_private *priv = netdev_priv(dev);
4982 unsigned long flags;
4983 int err = 0;
4984
4985 if (orinoco_lock(priv, &flags) != 0)
4986 return -EBUSY;
4987
4988 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
4989 wrqu->data.length = 0;
4990 goto out;
4991 }
4992
4993 if (wrqu->data.length < priv->wpa_ie_len) {
4994 err = -E2BIG;
4995 goto out;
4996 }
4997
4998 wrqu->data.length = priv->wpa_ie_len;
4999 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
5000
5001out:
5002 orinoco_unlock(priv, &flags);
5003 return err;
5004}
5005
5006static int orinoco_ioctl_set_mlme(struct net_device *dev,
5007 struct iw_request_info *info,
5008 union iwreq_data *wrqu, char *extra)
5009{
5010 struct orinoco_private *priv = netdev_priv(dev);
5011 hermes_t *hw = &priv->hw;
5012 struct iw_mlme *mlme = (struct iw_mlme *)extra;
5013 unsigned long flags;
5014 int ret = 0;
5015
5016 if (orinoco_lock(priv, &flags) != 0)
5017 return -EBUSY;
5018
5019 switch (mlme->cmd) {
5020 case IW_MLME_DEAUTH:
5021 /* silently ignore */
5022 break;
5023
5024 case IW_MLME_DISASSOC:
5025 {
5026 struct {
5027 u8 addr[ETH_ALEN];
5028 __le16 reason_code;
5029 } __attribute__ ((packed)) buf;
5030
5031 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
5032 buf.reason_code = cpu_to_le16(mlme->reason_code);
5033 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
5034 HERMES_RID_CNFDISASSOCIATE,
5035 &buf);
5036 break;
5037 }
5038 default:
5039 ret = -EOPNOTSUPP;
5040 }
5041
5042 orinoco_unlock(priv, &flags);
5043 return ret;
5044}
5045
Christoph Hellwig620554e2005-06-19 01:27:33 +02005046static int orinoco_ioctl_getretry(struct net_device *dev,
5047 struct iw_request_info *info,
5048 struct iw_param *rrq,
5049 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005050{
5051 struct orinoco_private *priv = netdev_priv(dev);
5052 hermes_t *hw = &priv->hw;
5053 int err = 0;
5054 u16 short_limit, long_limit, lifetime;
5055 unsigned long flags;
5056
5057 if (orinoco_lock(priv, &flags) != 0)
5058 return -EBUSY;
5059
5060 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
5061 &short_limit);
5062 if (err)
5063 goto out;
5064
5065 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
5066 &long_limit);
5067 if (err)
5068 goto out;
5069
5070 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
5071 &lifetime);
5072 if (err)
5073 goto out;
5074
5075 rrq->disabled = 0; /* Can't be disabled */
5076
5077 /* Note : by default, display the retry number */
5078 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
5079 rrq->flags = IW_RETRY_LIFETIME;
5080 rrq->value = lifetime * 1000; /* ??? */
5081 } else {
5082 /* By default, display the min number */
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07005083 if ((rrq->flags & IW_RETRY_LONG)) {
5084 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005085 rrq->value = long_limit;
5086 } else {
5087 rrq->flags = IW_RETRY_LIMIT;
5088 rrq->value = short_limit;
5089 if(short_limit != long_limit)
Jean Tourrilheseeec9f12006-08-29 18:02:31 -07005090 rrq->flags |= IW_RETRY_SHORT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 }
5092 }
5093
5094 out:
5095 orinoco_unlock(priv, &flags);
5096
5097 return err;
5098}
5099
Christoph Hellwig620554e2005-06-19 01:27:33 +02005100static int orinoco_ioctl_reset(struct net_device *dev,
5101 struct iw_request_info *info,
5102 void *wrqu,
5103 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005104{
5105 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005106
5107 if (! capable(CAP_NET_ADMIN))
5108 return -EPERM;
5109
5110 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
5111 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
5112
5113 /* Firmware reset */
David Howellsc4028952006-11-22 14:57:56 +00005114 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005115 } else {
5116 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
5117
5118 schedule_work(&priv->reset_work);
5119 }
5120
5121 return 0;
5122}
5123
5124static int orinoco_ioctl_setibssport(struct net_device *dev,
5125 struct iw_request_info *info,
5126 void *wrqu,
5127 char *extra)
5128
5129{
5130 struct orinoco_private *priv = netdev_priv(dev);
5131 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07005132 unsigned long flags;
5133
5134 if (orinoco_lock(priv, &flags) != 0)
5135 return -EBUSY;
5136
5137 priv->ibss_port = val ;
5138
5139 /* Actually update the mode we are using */
5140 set_port_type(priv);
5141
5142 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005143 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144}
5145
Christoph Hellwig620554e2005-06-19 01:27:33 +02005146static int orinoco_ioctl_getibssport(struct net_device *dev,
5147 struct iw_request_info *info,
5148 void *wrqu,
5149 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150{
5151 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005152 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153
5154 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 return 0;
5156}
5157
Christoph Hellwig620554e2005-06-19 01:27:33 +02005158static int orinoco_ioctl_setport3(struct net_device *dev,
5159 struct iw_request_info *info,
5160 void *wrqu,
5161 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005162{
5163 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005164 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07005165 int err = 0;
5166 unsigned long flags;
5167
5168 if (orinoco_lock(priv, &flags) != 0)
5169 return -EBUSY;
5170
5171 switch (val) {
5172 case 0: /* Try to do IEEE ad-hoc mode */
5173 if (! priv->has_ibss) {
5174 err = -EINVAL;
5175 break;
5176 }
5177 priv->prefer_port3 = 0;
5178
5179 break;
5180
5181 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5182 if (! priv->has_port3) {
5183 err = -EINVAL;
5184 break;
5185 }
5186 priv->prefer_port3 = 1;
5187 break;
5188
5189 default:
5190 err = -EINVAL;
5191 }
5192
Christoph Hellwig620554e2005-06-19 01:27:33 +02005193 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 /* Actually update the mode we are using */
5195 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005196 err = -EINPROGRESS;
5197 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005198
5199 orinoco_unlock(priv, &flags);
5200
5201 return err;
5202}
5203
Christoph Hellwig620554e2005-06-19 01:27:33 +02005204static int orinoco_ioctl_getport3(struct net_device *dev,
5205 struct iw_request_info *info,
5206 void *wrqu,
5207 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005208{
5209 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005210 int *val = (int *) extra;
5211
5212 *val = priv->prefer_port3;
5213 return 0;
5214}
5215
5216static int orinoco_ioctl_setpreamble(struct net_device *dev,
5217 struct iw_request_info *info,
5218 void *wrqu,
5219 char *extra)
5220{
5221 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005222 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005223 int val;
5224
5225 if (! priv->has_preamble)
5226 return -EOPNOTSUPP;
5227
5228 /* 802.11b has recently defined some short preamble.
5229 * Basically, the Phy header has been reduced in size.
5230 * This increase performance, especially at high rates
5231 * (the preamble is transmitted at 1Mb/s), unfortunately
5232 * this give compatibility troubles... - Jean II */
5233 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07005234
5235 if (orinoco_lock(priv, &flags) != 0)
5236 return -EBUSY;
5237
Christoph Hellwig620554e2005-06-19 01:27:33 +02005238 if (val)
5239 priv->preamble = 1;
5240 else
5241 priv->preamble = 0;
5242
Linus Torvalds1da177e2005-04-16 15:20:36 -07005243 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005244
5245 return -EINPROGRESS; /* Call commit handler */
5246}
5247
5248static int orinoco_ioctl_getpreamble(struct net_device *dev,
5249 struct iw_request_info *info,
5250 void *wrqu,
5251 char *extra)
5252{
5253 struct orinoco_private *priv = netdev_priv(dev);
5254 int *val = (int *) extra;
5255
5256 if (! priv->has_preamble)
5257 return -EOPNOTSUPP;
5258
5259 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005260 return 0;
5261}
5262
Christoph Hellwig620554e2005-06-19 01:27:33 +02005263/* ioctl interface to hermes_read_ltv()
5264 * To use with iwpriv, pass the RID as the token argument, e.g.
5265 * iwpriv get_rid [0xfc00]
5266 * At least Wireless Tools 25 is required to use iwpriv.
5267 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5268static int orinoco_ioctl_getrid(struct net_device *dev,
5269 struct iw_request_info *info,
5270 struct iw_point *data,
5271 char *extra)
5272{
5273 struct orinoco_private *priv = netdev_priv(dev);
5274 hermes_t *hw = &priv->hw;
5275 int rid = data->flags;
5276 u16 length;
5277 int err;
5278 unsigned long flags;
5279
5280 /* It's a "get" function, but we don't want users to access the
5281 * WEP key and other raw firmware data */
5282 if (! capable(CAP_NET_ADMIN))
5283 return -EPERM;
5284
5285 if (rid < 0xfc00 || rid > 0xffff)
5286 return -EINVAL;
5287
5288 if (orinoco_lock(priv, &flags) != 0)
5289 return -EBUSY;
5290
5291 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5292 extra);
5293 if (err)
5294 goto out;
5295
5296 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5297 MAX_RID_LEN);
5298
5299 out:
5300 orinoco_unlock(priv, &flags);
5301 return err;
5302}
5303
David Kilroy17a1a882008-08-21 23:27:47 +01005304/* Trigger a scan (look for other cells in the vicinity) */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005305static int orinoco_ioctl_setscan(struct net_device *dev,
5306 struct iw_request_info *info,
David Kilroy9930cce2008-09-13 12:22:05 +01005307 struct iw_point *srq,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005308 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309{
5310 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005311 hermes_t *hw = &priv->hw;
David Kilroy0753bba2008-08-21 23:27:46 +01005312 struct iw_scan_req *si = (struct iw_scan_req *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314 unsigned long flags;
5315
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005316 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08005317 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005318 * perform scanning.
5319 * This is not an error, while the device perform scanning,
5320 * traffic doesn't flow, so it's a perfect DoS...
5321 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005323 if (orinoco_lock(priv, &flags) != 0)
5324 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005326 /* Scanning with port 0 disabled would fail */
5327 if (!netif_running(dev)) {
5328 err = -ENETDOWN;
5329 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005332 /* In monitor mode, the scan results are always empty.
5333 * Probe responses are passed to the driver as received
5334 * frames and could be processed in software. */
5335 if (priv->iw_mode == IW_MODE_MONITOR) {
5336 err = -EOPNOTSUPP;
5337 goto out;
5338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005340 /* Note : because we don't lock out the irq handler, the way
5341 * we access scan variables in priv is critical.
5342 * o scan_inprogress : not touched by irq handler
5343 * o scan_mode : not touched by irq handler
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005344 * Before modifying anything on those variables, please think hard !
5345 * Jean II */
5346
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005347 /* Save flags */
5348 priv->scan_mode = srq->flags;
5349
5350 /* Always trigger scanning, even if it's in progress.
5351 * This way, if the info frame get lost, we will recover somewhat
5352 * gracefully - Jean II */
5353
5354 if (priv->has_hostscan) {
5355 switch (priv->firmware_type) {
5356 case FIRMWARE_TYPE_SYMBOL:
5357 err = hermes_write_wordrec(hw, USER_BAP,
5358 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5359 HERMES_HOSTSCAN_SYMBOL_ONCE |
5360 HERMES_HOSTSCAN_SYMBOL_BCAST);
5361 break;
5362 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04005363 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005364
5365 req[0] = cpu_to_le16(0x3fff); /* All channels */
5366 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5367 req[2] = 0; /* Any ESSID */
5368 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5369 HERMES_RID_CNFHOSTSCAN, &req);
5370 }
5371 break;
5372 case FIRMWARE_TYPE_AGERE:
David Kilroy0753bba2008-08-21 23:27:46 +01005373 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5374 struct hermes_idstring idbuf;
5375 size_t len = min(sizeof(idbuf.val),
5376 (size_t) si->essid_len);
5377 idbuf.len = cpu_to_le16(len);
5378 memcpy(idbuf.val, si->essid, len);
5379
5380 err = hermes_write_ltv(hw, USER_BAP,
5381 HERMES_RID_CNFSCANSSID_AGERE,
5382 HERMES_BYTES_TO_RECLEN(len + 2),
5383 &idbuf);
5384 } else
5385 err = hermes_write_wordrec(hw, USER_BAP,
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005386 HERMES_RID_CNFSCANSSID_AGERE,
5387 0); /* Any ESSID */
5388 if (err)
5389 break;
5390
David Kilroy01632fa2008-08-21 23:27:58 +01005391 if (priv->has_ext_scan) {
5392 /* Clear scan results at the start of
5393 * an extended scan */
5394 orinoco_clear_scan_results(priv,
5395 msecs_to_jiffies(15000));
5396
5397 /* TODO: Is this available on older firmware?
5398 * Can we use it to scan specific channels
5399 * for IW_SCAN_THIS_FREQ? */
5400 err = hermes_write_wordrec(hw, USER_BAP,
5401 HERMES_RID_CNFSCANCHANNELS2GHZ,
5402 0x7FFF);
5403 if (err)
5404 goto out;
5405
5406 err = hermes_inquire(hw,
5407 HERMES_INQ_CHANNELINFO);
5408 } else
5409 err = hermes_inquire(hw, HERMES_INQ_SCAN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005410 break;
5411 }
5412 } else
5413 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5414
5415 /* One more client */
5416 if (! err)
5417 priv->scan_inprogress = 1;
5418
5419 out:
5420 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005421 return err;
5422}
5423
Dan Williams1e3428e2007-10-10 23:56:25 -04005424#define MAX_CUSTOM_LEN 64
5425
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005426/* Translate scan data returned from the card to a card independant
David Kilroy17a1a882008-08-21 23:27:47 +01005427 * format that the Wireless Tools will understand - Jean II */
Dan Williams1e3428e2007-10-10 23:56:25 -04005428static inline char *orinoco_translate_scan(struct net_device *dev,
David S. Millerccc58052008-06-16 18:50:49 -07005429 struct iw_request_info *info,
Dan Williams1e3428e2007-10-10 23:56:25 -04005430 char *current_ev,
5431 char *end_buf,
5432 union hermes_scan_info *bss,
5433 unsigned int last_scanned)
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005434{
5435 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005436 u16 capabilities;
5437 u16 channel;
5438 struct iw_event iwe; /* Temporary buffer */
Dan Williams1e3428e2007-10-10 23:56:25 -04005439 char custom[MAX_CUSTOM_LEN];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005440
David Kilroy17a1a882008-08-21 23:27:47 +01005441 memset(&iwe, 0, sizeof(iwe));
5442
Dan Williams1e3428e2007-10-10 23:56:25 -04005443 /* First entry *MUST* be the AP MAC address */
5444 iwe.cmd = SIOCGIWAP;
5445 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5446 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
David S. Millerccc58052008-06-16 18:50:49 -07005447 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5448 &iwe, IW_EV_ADDR_LEN);
Dan Williams1e3428e2007-10-10 23:56:25 -04005449
5450 /* Other entries will be displayed in the order we give them */
5451
5452 /* Add the ESSID */
5453 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5454 if (iwe.u.data.length > 32)
5455 iwe.u.data.length = 32;
5456 iwe.cmd = SIOCGIWESSID;
5457 iwe.u.data.flags = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005458 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5459 &iwe, bss->a.essid);
Dan Williams1e3428e2007-10-10 23:56:25 -04005460
5461 /* Add mode */
5462 iwe.cmd = SIOCGIWMODE;
5463 capabilities = le16_to_cpu(bss->a.capabilities);
David Kilroy17a1a882008-08-21 23:27:47 +01005464 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5465 if (capabilities & WLAN_CAPABILITY_ESS)
Dan Williams1e3428e2007-10-10 23:56:25 -04005466 iwe.u.mode = IW_MODE_MASTER;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005467 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005468 iwe.u.mode = IW_MODE_ADHOC;
David S. Millerccc58052008-06-16 18:50:49 -07005469 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5470 &iwe, IW_EV_UINT_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005471 }
5472
Dan Williams1e3428e2007-10-10 23:56:25 -04005473 channel = bss->s.channel;
5474 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
David Kilroy17a1a882008-08-21 23:27:47 +01005475 /* Add channel and frequency */
Dan Williams1e3428e2007-10-10 23:56:25 -04005476 iwe.cmd = SIOCGIWFREQ;
David Kilroy17a1a882008-08-21 23:27:47 +01005477 iwe.u.freq.m = channel;
5478 iwe.u.freq.e = 0;
5479 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5480 &iwe, IW_EV_FREQ_LEN);
5481
Dan Williams1e3428e2007-10-10 23:56:25 -04005482 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5483 iwe.u.freq.e = 1;
David S. Millerccc58052008-06-16 18:50:49 -07005484 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
Dan Williams1e3428e2007-10-10 23:56:25 -04005485 &iwe, IW_EV_FREQ_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005486 }
5487
David Kilroy17a1a882008-08-21 23:27:47 +01005488 /* Add quality statistics. level and noise in dB. No link quality */
Dan Williams1e3428e2007-10-10 23:56:25 -04005489 iwe.cmd = IWEVQUAL;
David Kilroy17a1a882008-08-21 23:27:47 +01005490 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
Dan Williams1e3428e2007-10-10 23:56:25 -04005491 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5492 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5493 /* Wireless tools prior to 27.pre22 will show link quality
5494 * anyway, so we provide a reasonable value. */
5495 if (iwe.u.qual.level > iwe.u.qual.noise)
5496 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5497 else
5498 iwe.u.qual.qual = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005499 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5500 &iwe, IW_EV_QUAL_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005501
Dan Williams1e3428e2007-10-10 23:56:25 -04005502 /* Add encryption capability */
5503 iwe.cmd = SIOCGIWENCODE;
David Kilroy17a1a882008-08-21 23:27:47 +01005504 if (capabilities & WLAN_CAPABILITY_PRIVACY)
Dan Williams1e3428e2007-10-10 23:56:25 -04005505 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5506 else
5507 iwe.u.data.flags = IW_ENCODE_DISABLED;
5508 iwe.u.data.length = 0;
David S. Millerccc58052008-06-16 18:50:49 -07005509 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
David Kilroy17a1a882008-08-21 23:27:47 +01005510 &iwe, NULL);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005511
Dan Williams1e3428e2007-10-10 23:56:25 -04005512 /* Bit rate is not available in Lucent/Agere firmwares */
5513 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
David S. Millerccc58052008-06-16 18:50:49 -07005514 char *current_val = current_ev + iwe_stream_lcp_len(info);
Dan Williams1e3428e2007-10-10 23:56:25 -04005515 int i;
5516 int step;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005517
Dan Williams1e3428e2007-10-10 23:56:25 -04005518 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5519 step = 2;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005520 else
Dan Williams1e3428e2007-10-10 23:56:25 -04005521 step = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005522
Dan Williams1e3428e2007-10-10 23:56:25 -04005523 iwe.cmd = SIOCGIWRATE;
5524 /* Those two flags are ignored... */
5525 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5526 /* Max 10 values */
5527 for (i = 0; i < 10; i += step) {
5528 /* NULL terminated */
5529 if (bss->p.rates[i] == 0x0)
5530 break;
5531 /* Bit rate given in 500 kb/s units (+ 0x80) */
David Kilroy17a1a882008-08-21 23:27:47 +01005532 iwe.u.bitrate.value =
5533 ((bss->p.rates[i] & 0x7f) * 500000);
David S. Millerccc58052008-06-16 18:50:49 -07005534 current_val = iwe_stream_add_value(info, current_ev,
5535 current_val,
Dan Williams1e3428e2007-10-10 23:56:25 -04005536 end_buf, &iwe,
5537 IW_EV_PARAM_LEN);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005538 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005539 /* Check if we added any event */
David S. Millerccc58052008-06-16 18:50:49 -07005540 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
Dan Williams1e3428e2007-10-10 23:56:25 -04005541 current_ev = current_val;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005542 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005543
David Kilroy17a1a882008-08-21 23:27:47 +01005544 /* Beacon interval */
5545 iwe.cmd = IWEVCUSTOM;
5546 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5547 "bcn_int=%d",
5548 le16_to_cpu(bss->a.beacon_interv));
5549 if (iwe.u.data.length)
5550 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5551 &iwe, custom);
5552
5553 /* Capabilites */
5554 iwe.cmd = IWEVCUSTOM;
5555 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5556 "capab=0x%04x",
5557 capabilities);
5558 if (iwe.u.data.length)
5559 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5560 &iwe, custom);
5561
5562 /* Add EXTRA: Age to display seconds since last beacon/probe response
5563 * for given network. */
5564 iwe.cmd = IWEVCUSTOM;
5565 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5566 " Last beacon: %dms ago",
5567 jiffies_to_msecs(jiffies - last_scanned));
5568 if (iwe.u.data.length)
5569 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5570 &iwe, custom);
5571
Dan Williams1e3428e2007-10-10 23:56:25 -04005572 return current_ev;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005573}
5574
David Kilroy01632fa2008-08-21 23:27:58 +01005575static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5576 struct iw_request_info *info,
5577 char *current_ev,
5578 char *end_buf,
5579 struct agere_ext_scan_info *bss,
5580 unsigned int last_scanned)
5581{
5582 u16 capabilities;
5583 u16 channel;
5584 struct iw_event iwe; /* Temporary buffer */
5585 char custom[MAX_CUSTOM_LEN];
5586 u8 *ie;
5587
5588 memset(&iwe, 0, sizeof(iwe));
5589
5590 /* First entry *MUST* be the AP MAC address */
5591 iwe.cmd = SIOCGIWAP;
5592 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5593 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5594 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5595 &iwe, IW_EV_ADDR_LEN);
5596
5597 /* Other entries will be displayed in the order we give them */
5598
5599 /* Add the ESSID */
5600 ie = bss->data;
5601 iwe.u.data.length = ie[1];
5602 if (iwe.u.data.length) {
5603 if (iwe.u.data.length > 32)
5604 iwe.u.data.length = 32;
5605 iwe.cmd = SIOCGIWESSID;
5606 iwe.u.data.flags = 1;
5607 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5608 &iwe, &ie[2]);
5609 }
5610
5611 /* Add mode */
5612 capabilities = le16_to_cpu(bss->capabilities);
5613 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5614 iwe.cmd = SIOCGIWMODE;
5615 if (capabilities & WLAN_CAPABILITY_ESS)
5616 iwe.u.mode = IW_MODE_MASTER;
5617 else
5618 iwe.u.mode = IW_MODE_ADHOC;
5619 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5620 &iwe, IW_EV_UINT_LEN);
5621 }
5622
5623 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_DS_SET);
5624 channel = ie ? ie[2] : 0;
5625 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5626 /* Add channel and frequency */
5627 iwe.cmd = SIOCGIWFREQ;
5628 iwe.u.freq.m = channel;
5629 iwe.u.freq.e = 0;
5630 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5631 &iwe, IW_EV_FREQ_LEN);
5632
5633 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5634 iwe.u.freq.e = 1;
5635 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5636 &iwe, IW_EV_FREQ_LEN);
5637 }
5638
5639 /* Add quality statistics. level and noise in dB. No link quality */
5640 iwe.cmd = IWEVQUAL;
5641 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5642 iwe.u.qual.level = bss->level - 0x95;
5643 iwe.u.qual.noise = bss->noise - 0x95;
5644 /* Wireless tools prior to 27.pre22 will show link quality
5645 * anyway, so we provide a reasonable value. */
5646 if (iwe.u.qual.level > iwe.u.qual.noise)
5647 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5648 else
5649 iwe.u.qual.qual = 0;
5650 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5651 &iwe, IW_EV_QUAL_LEN);
5652
5653 /* Add encryption capability */
5654 iwe.cmd = SIOCGIWENCODE;
5655 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5656 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5657 else
5658 iwe.u.data.flags = IW_ENCODE_DISABLED;
5659 iwe.u.data.length = 0;
5660 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5661 &iwe, NULL);
5662
5663 /* WPA IE */
5664 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5665 if (ie) {
5666 iwe.cmd = IWEVGENIE;
5667 iwe.u.data.length = ie[1] + 2;
5668 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5669 &iwe, ie);
5670 }
5671
5672 /* RSN IE */
5673 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RSN);
5674 if (ie) {
5675 iwe.cmd = IWEVGENIE;
5676 iwe.u.data.length = ie[1] + 2;
5677 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5678 &iwe, ie);
5679 }
5680
5681 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RATES);
5682 if (ie) {
5683 char *p = current_ev + iwe_stream_lcp_len(info);
5684 int i;
5685
5686 iwe.cmd = SIOCGIWRATE;
5687 /* Those two flags are ignored... */
5688 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5689
5690 for (i = 2; i < (ie[1] + 2); i++) {
5691 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5692 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5693 &iwe, IW_EV_PARAM_LEN);
5694 }
5695 /* Check if we added any event */
5696 if (p > (current_ev + iwe_stream_lcp_len(info)))
5697 current_ev = p;
5698 }
5699
5700 /* Timestamp */
5701 iwe.cmd = IWEVCUSTOM;
David Kilroy75d31cf2008-09-12 22:28:18 +01005702 iwe.u.data.length =
5703 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
5704 (unsigned long long) le64_to_cpu(bss->timestamp));
David Kilroy01632fa2008-08-21 23:27:58 +01005705 if (iwe.u.data.length)
5706 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5707 &iwe, custom);
5708
5709 /* Beacon interval */
5710 iwe.cmd = IWEVCUSTOM;
5711 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5712 "bcn_int=%d",
5713 le16_to_cpu(bss->beacon_interval));
5714 if (iwe.u.data.length)
5715 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5716 &iwe, custom);
5717
5718 /* Capabilites */
5719 iwe.cmd = IWEVCUSTOM;
5720 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5721 "capab=0x%04x",
5722 capabilities);
5723 if (iwe.u.data.length)
5724 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5725 &iwe, custom);
5726
5727 /* Add EXTRA: Age to display seconds since last beacon/probe response
5728 * for given network. */
5729 iwe.cmd = IWEVCUSTOM;
5730 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5731 " Last beacon: %dms ago",
5732 jiffies_to_msecs(jiffies - last_scanned));
5733 if (iwe.u.data.length)
5734 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5735 &iwe, custom);
5736
5737 return current_ev;
5738}
5739
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005740/* Return results of a scan */
5741static int orinoco_ioctl_getscan(struct net_device *dev,
5742 struct iw_request_info *info,
5743 struct iw_point *srq,
5744 char *extra)
5745{
5746 struct orinoco_private *priv = netdev_priv(dev);
5747 int err = 0;
5748 unsigned long flags;
Dan Williams1e3428e2007-10-10 23:56:25 -04005749 char *current_ev = extra;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005750
5751 if (orinoco_lock(priv, &flags) != 0)
5752 return -EBUSY;
5753
Dan Williams1e3428e2007-10-10 23:56:25 -04005754 if (priv->scan_inprogress) {
5755 /* Important note : we don't want to block the caller
5756 * until results are ready for various reasons.
5757 * First, managing wait queues is complex and racy.
5758 * Second, we grab some rtnetlink lock before comming
5759 * here (in dev_ioctl()).
5760 * Third, we generate an Wireless Event, so the
5761 * caller can wait itself on that - Jean II */
5762 err = -EAGAIN;
5763 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005764 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005765
David Kilroy01632fa2008-08-21 23:27:58 +01005766 if (priv->has_ext_scan) {
5767 struct xbss_element *bss;
Dan Williams1e3428e2007-10-10 23:56:25 -04005768
David Kilroy01632fa2008-08-21 23:27:58 +01005769 list_for_each_entry(bss, &priv->bss_list, list) {
5770 /* Translate this entry to WE format */
5771 current_ev =
5772 orinoco_translate_ext_scan(dev, info,
5773 current_ev,
5774 extra + srq->length,
5775 &bss->bss,
5776 bss->last_scanned);
5777
5778 /* Check if there is space for one more entry */
5779 if ((extra + srq->length - current_ev)
5780 <= IW_EV_ADDR_LEN) {
5781 /* Ask user space to try again with a
5782 * bigger buffer */
5783 err = -E2BIG;
5784 goto out;
5785 }
5786 }
5787
5788 } else {
5789 struct bss_element *bss;
5790
5791 list_for_each_entry(bss, &priv->bss_list, list) {
5792 /* Translate this entry to WE format */
5793 current_ev = orinoco_translate_scan(dev, info,
5794 current_ev,
5795 extra + srq->length,
5796 &bss->bss,
5797 bss->last_scanned);
5798
5799 /* Check if there is space for one more entry */
5800 if ((extra + srq->length - current_ev)
5801 <= IW_EV_ADDR_LEN) {
5802 /* Ask user space to try again with a
5803 * bigger buffer */
5804 err = -E2BIG;
5805 goto out;
5806 }
Dan Williams1e3428e2007-10-10 23:56:25 -04005807 }
5808 }
5809
5810 srq->length = (current_ev - extra);
5811 srq->flags = (__u16) priv->scan_mode;
5812
5813out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02005814 orinoco_unlock(priv, &flags);
5815 return err;
5816}
5817
Christoph Hellwig620554e2005-06-19 01:27:33 +02005818/* Commit handler, called after set operations */
5819static int orinoco_ioctl_commit(struct net_device *dev,
5820 struct iw_request_info *info,
5821 void *wrqu,
5822 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005823{
5824 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005825 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02005827 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828
Christoph Hellwig620554e2005-06-19 01:27:33 +02005829 if (!priv->open)
5830 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005831
Christoph Hellwig620554e2005-06-19 01:27:33 +02005832 if (priv->broken_disableport) {
David Howellsc4028952006-11-22 14:57:56 +00005833 orinoco_reset(&priv->reset_work);
Christoph Hellwig620554e2005-06-19 01:27:33 +02005834 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005836
Christoph Hellwig620554e2005-06-19 01:27:33 +02005837 if (orinoco_lock(priv, &flags) != 0)
5838 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839
Christoph Hellwig620554e2005-06-19 01:27:33 +02005840 err = hermes_disable_port(hw, 0);
5841 if (err) {
5842 printk(KERN_WARNING "%s: Unable to disable port "
5843 "while reconfiguring card\n", dev->name);
5844 priv->broken_disableport = 1;
5845 goto out;
5846 }
5847
5848 err = __orinoco_program_rids(dev);
5849 if (err) {
5850 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5851 dev->name);
5852 goto out;
5853 }
5854
5855 err = hermes_enable_port(hw, 0);
5856 if (err) {
5857 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5858 dev->name);
5859 goto out;
5860 }
5861
5862 out:
5863 if (err) {
5864 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5865 schedule_work(&priv->reset_work);
5866 err = 0;
5867 }
5868
5869 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 return err;
5871}
5872
Christoph Hellwig620554e2005-06-19 01:27:33 +02005873static const struct iw_priv_args orinoco_privtab[] = {
5874 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5875 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5876 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5877 0, "set_port3" },
5878 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5879 "get_port3" },
5880 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5881 0, "set_preamble" },
5882 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5883 "get_preamble" },
5884 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5885 0, "set_ibssport" },
5886 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5887 "get_ibssport" },
5888 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5889 "get_rid" },
5890};
5891
5892
5893/*
5894 * Structures to export the Wireless Handlers
5895 */
5896
David Kilroy409644a2008-08-21 23:28:01 +01005897#define STD_IW_HANDLER(id, func) \
5898 [IW_IOCTL_IDX(id)] = (iw_handler) func
Christoph Hellwig620554e2005-06-19 01:27:33 +02005899static const iw_handler orinoco_handler[] = {
David Kilroy409644a2008-08-21 23:28:01 +01005900 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
5901 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
5902 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
5903 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
5904 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
5905 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
5906 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
5907 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
5908 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
5909 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
5910 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
5911 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
5912 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
5913 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
5914 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
5915 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
5916 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
5917 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
5918 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
5919 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
5920 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
5921 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
5922 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
5923 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
5924 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
5925 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
5926 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
5927 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
5928 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
5929 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
5930 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
5931 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
David Kilroyd03032a2008-08-21 23:28:02 +01005932 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
5933 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
5934 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
5935 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
5936 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
5937 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
5938 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
Christoph Hellwig620554e2005-06-19 01:27:33 +02005939};
5940
5941
5942/*
5943 Added typecasting since we no longer use iwreq_data -- Moustafa
5944 */
5945static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07005946 [0] = (iw_handler) orinoco_ioctl_reset,
5947 [1] = (iw_handler) orinoco_ioctl_reset,
5948 [2] = (iw_handler) orinoco_ioctl_setport3,
5949 [3] = (iw_handler) orinoco_ioctl_getport3,
5950 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5951 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5952 [6] = (iw_handler) orinoco_ioctl_setibssport,
5953 [7] = (iw_handler) orinoco_ioctl_getibssport,
5954 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005955};
5956
5957static const struct iw_handler_def orinoco_handler_def = {
5958 .num_standard = ARRAY_SIZE(orinoco_handler),
5959 .num_private = ARRAY_SIZE(orinoco_private_handler),
5960 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5961 .standard = orinoco_handler,
5962 .private = orinoco_private_handler,
5963 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04005964 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02005965};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005966
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005967static void orinoco_get_drvinfo(struct net_device *dev,
5968 struct ethtool_drvinfo *info)
5969{
5970 struct orinoco_private *priv = netdev_priv(dev);
5971
5972 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5973 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5974 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
Greg Kroah-Hartman43cb76d2002-04-09 12:14:34 -07005975 if (dev->dev.parent)
5976 strncpy(info->bus_info, dev->dev.parent->bus_id,
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005977 sizeof(info->bus_info) - 1);
5978 else
5979 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5980 "PCMCIA %p", priv->hw.iobase);
5981}
5982
Jeff Garzik7282d492006-09-13 14:30:00 -04005983static const struct ethtool_ops orinoco_ethtool_ops = {
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02005984 .get_drvinfo = orinoco_get_drvinfo,
5985 .get_link = ethtool_op_get_link,
5986};
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987
5988/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07005989/* Module initialization */
5990/********************************************************************/
5991
5992EXPORT_SYMBOL(alloc_orinocodev);
5993EXPORT_SYMBOL(free_orinocodev);
5994
5995EXPORT_SYMBOL(__orinoco_up);
5996EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005997EXPORT_SYMBOL(orinoco_reinit_firmware);
5998
5999EXPORT_SYMBOL(orinoco_interrupt);
6000
6001/* Can't be declared "const" or the whole __initdata section will
6002 * become const */
6003static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
6004 " (David Gibson <hermes@gibson.dropbear.id.au>, "
6005 "Pavel Roskin <proski@gnu.org>, et al)";
6006
6007static int __init init_orinoco(void)
6008{
6009 printk(KERN_DEBUG "%s\n", version);
6010 return 0;
6011}
6012
6013static void __exit exit_orinoco(void)
6014{
6015}
6016
6017module_init(init_orinoco);
6018module_exit(exit_orinoco);