blob: 80cf6fba3798ddedeaecde6f9990a2e3dbaf5051 [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
79#include <linux/config.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#include <linux/module.h>
81#include <linux/kernel.h>
82#include <linux/init.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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#include <linux/wireless.h>
Christoph Hellwig620554e2005-06-19 01:27:33 +020087#include <net/iw_handler.h>
Christoph Hellwig5d558b72005-06-19 01:27:28 +020088#include <net/ieee80211.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#include "hermes_rid.h"
91#include "orinoco.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/********************************************************************/
94/* Module information */
95/********************************************************************/
96
97MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
98MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
99MODULE_LICENSE("Dual MPL/GPL");
100
101/* Level of debugging. Used in the macros in orinoco.h */
102#ifdef ORINOCO_DEBUG
103int orinoco_debug = ORINOCO_DEBUG;
104module_param(orinoco_debug, int, 0644);
105MODULE_PARM_DESC(orinoco_debug, "Debug level");
106EXPORT_SYMBOL(orinoco_debug);
107#endif
108
109static int suppress_linkstatus; /* = 0 */
110module_param(suppress_linkstatus, bool, 0644);
111MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
David Gibson7bb7c3a2005-05-12 20:02:10 -0400112static int ignore_disconnect; /* = 0 */
113module_param(ignore_disconnect, int, 0644);
114MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200116static int force_monitor; /* = 0 */
117module_param(force_monitor, int, 0644);
118MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120/********************************************************************/
121/* Compile time configuration and compatibility stuff */
122/********************************************************************/
123
124/* We do this this way to avoid ifdefs in the actual code */
125#ifdef WIRELESS_SPY
Pavel Roskin343c6862005-09-09 18:43:02 -0400126#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#else
128#define SPY_NUMBER(priv) 0
129#endif /* WIRELESS_SPY */
130
131/********************************************************************/
132/* Internal constants */
133/********************************************************************/
134
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200135/* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
136static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
137#define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define ORINOCO_MIN_MTU 256
Jeff Garzikb4538722005-05-12 22:48:20 -0400140#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142#define SYMBOL_MAX_VER_LEN (14)
143#define USER_BAP 0
144#define IRQ_BAP 1
145#define MAX_IRQLOOPS_PER_IRQ 10
146#define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
148 * device could
149 * legitimately generate */
150#define SMALL_KEY_SIZE 5
151#define LARGE_KEY_SIZE 13
152#define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
153
154#define DUMMY_FID 0xFFFF
155
156/*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158#define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159
160#define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
163 | HERMES_EV_INFDROP )
164
Christoph Hellwig620554e2005-06-19 01:27:33 +0200165#define MAX_RID_LEN 1024
166
167static const struct iw_handler_def orinoco_handler_def;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +0200168static struct ethtool_ops orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +0200169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170/********************************************************************/
171/* Data tables */
172/********************************************************************/
173
174/* The frequency of each channel in MHz */
175static const long channel_frequency[] = {
176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
177 2447, 2452, 2457, 2462, 2467, 2472, 2484
178};
179#define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
180
181/* This tables gives the actual meanings of the bitrate IDs returned
182 * by the firmware. */
183static struct {
184 int bitrate; /* in 100s of kilobits */
185 int automatic;
186 u16 agere_txratectrl;
187 u16 intersil_txratectrl;
188} bitrate_table[] = {
189 {110, 1, 3, 15}, /* Entry 0 is the default */
190 {10, 0, 1, 1},
191 {10, 1, 1, 1},
192 {20, 0, 2, 2},
193 {20, 1, 6, 3},
194 {55, 0, 4, 4},
195 {55, 1, 7, 7},
196 {110, 0, 5, 8},
197};
198#define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
199
200/********************************************************************/
201/* Data types */
202/********************************************************************/
203
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400204/* Beginning of the Tx descriptor, used in TxExc handling */
205struct hermes_txexc_data {
206 struct hermes_tx_descriptor desc;
Pavel Roskind133ae42005-09-23 04:18:06 -0400207 __le16 frame_ctl;
208 __le16 duration_id;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200209 u8 addr1[ETH_ALEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210} __attribute__ ((packed));
211
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200212/* Rx frame header except compatibility 802.3 header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213struct hermes_rx_descriptor {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200214 /* Control */
Pavel Roskind133ae42005-09-23 04:18:06 -0400215 __le16 status;
216 __le32 time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 u8 silence;
218 u8 signal;
219 u8 rate;
220 u8 rxflow;
Pavel Roskind133ae42005-09-23 04:18:06 -0400221 __le32 reserved;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200222
223 /* 802.11 header */
Pavel Roskind133ae42005-09-23 04:18:06 -0400224 __le16 frame_ctl;
225 __le16 duration_id;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200226 u8 addr1[ETH_ALEN];
227 u8 addr2[ETH_ALEN];
228 u8 addr3[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400229 __le16 seq_ctl;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200230 u8 addr4[ETH_ALEN];
231
232 /* Data length */
Pavel Roskind133ae42005-09-23 04:18:06 -0400233 __le16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234} __attribute__ ((packed));
235
236/********************************************************************/
237/* Function prototypes */
238/********************************************************************/
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240static int __orinoco_program_rids(struct net_device *dev);
241static void __orinoco_set_multicast_list(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243/********************************************************************/
244/* Internal helper functions */
245/********************************************************************/
246
247static inline void set_port_type(struct orinoco_private *priv)
248{
249 switch (priv->iw_mode) {
250 case IW_MODE_INFRA:
251 priv->port_type = 1;
252 priv->createibss = 0;
253 break;
254 case IW_MODE_ADHOC:
255 if (priv->prefer_port3) {
256 priv->port_type = 3;
257 priv->createibss = 0;
258 } else {
259 priv->port_type = priv->ibss_port;
260 priv->createibss = 1;
261 }
262 break;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200263 case IW_MODE_MONITOR:
264 priv->port_type = 3;
265 priv->createibss = 0;
266 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 default:
268 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
269 priv->ndev->name);
270 }
271}
272
273/********************************************************************/
274/* Device methods */
275/********************************************************************/
276
277static int orinoco_open(struct net_device *dev)
278{
279 struct orinoco_private *priv = netdev_priv(dev);
280 unsigned long flags;
281 int err;
282
283 if (orinoco_lock(priv, &flags) != 0)
284 return -EBUSY;
285
286 err = __orinoco_up(dev);
287
288 if (! err)
289 priv->open = 1;
290
291 orinoco_unlock(priv, &flags);
292
293 return err;
294}
295
Christoph Hellwigad8f4512005-05-14 17:30:17 +0200296static int orinoco_stop(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297{
298 struct orinoco_private *priv = netdev_priv(dev);
299 int err = 0;
300
301 /* We mustn't use orinoco_lock() here, because we need to be
302 able to close the interface even if hw_unavailable is set
303 (e.g. as we're released after a PC Card removal) */
304 spin_lock_irq(&priv->lock);
305
306 priv->open = 0;
307
308 err = __orinoco_down(dev);
309
310 spin_unlock_irq(&priv->lock);
311
312 return err;
313}
314
315static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
316{
317 struct orinoco_private *priv = netdev_priv(dev);
318
319 return &priv->stats;
320}
321
322static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
323{
324 struct orinoco_private *priv = netdev_priv(dev);
325 hermes_t *hw = &priv->hw;
326 struct iw_statistics *wstats = &priv->wstats;
David Gibsone67d9d92005-05-12 20:01:22 -0400327 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 unsigned long flags;
329
330 if (! netif_device_present(dev)) {
331 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
332 dev->name);
333 return NULL; /* FIXME: Can we do better than this? */
334 }
335
David Gibsone67d9d92005-05-12 20:01:22 -0400336 /* If busy, return the old stats. Returning NULL may cause
337 * the interface to disappear from /proc/net/wireless */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (orinoco_lock(priv, &flags) != 0)
David Gibsone67d9d92005-05-12 20:01:22 -0400339 return wstats;
340
341 /* We can't really wait for the tallies inquiry command to
342 * complete, so we just use the previous results and trigger
343 * a new tallies inquiry command for next time - Jean II */
344 /* FIXME: Really we should wait for the inquiry to come back -
345 * as it is the stats we give don't make a whole lot of sense.
346 * Unfortunately, it's not clear how to do that within the
347 * wireless extensions framework: I think we're in user
348 * context, but a lock seems to be held by the time we get in
349 * here so we're not safe to sleep here. */
350 hermes_inquire(hw, HERMES_INQ_TALLIES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 if (priv->iw_mode == IW_MODE_ADHOC) {
353 memset(&wstats->qual, 0, sizeof(wstats->qual));
354 /* If a spy address is defined, we report stats of the
355 * first spy address - Jean II */
356 if (SPY_NUMBER(priv)) {
Pavel Roskin343c6862005-09-09 18:43:02 -0400357 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
358 wstats->qual.level = priv->spy_data.spy_stat[0].level;
359 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
360 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362 } else {
363 struct {
Pavel Roskina208c4e2006-04-07 04:10:26 -0400364 __le16 qual, signal, noise, unused;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } __attribute__ ((packed)) cq;
366
367 err = HERMES_READ_RECORD(hw, USER_BAP,
368 HERMES_RID_COMMSQUALITY, &cq);
David Gibsone67d9d92005-05-12 20:01:22 -0400369
370 if (!err) {
371 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
372 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
373 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
374 wstats->qual.updated = 7;
375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return wstats;
380}
381
382static void orinoco_set_multicast_list(struct net_device *dev)
383{
384 struct orinoco_private *priv = netdev_priv(dev);
385 unsigned long flags;
386
387 if (orinoco_lock(priv, &flags) != 0) {
388 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
389 "called when hw_unavailable\n", dev->name);
390 return;
391 }
392
393 __orinoco_set_multicast_list(dev);
394 orinoco_unlock(priv, &flags);
395}
396
397static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
398{
399 struct orinoco_private *priv = netdev_priv(dev);
400
401 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
402 return -EINVAL;
403
Jeff Garzikb4538722005-05-12 22:48:20 -0400404 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 (priv->nicbuf_size - ETH_HLEN) )
406 return -EINVAL;
407
408 dev->mtu = new_mtu;
409
410 return 0;
411}
412
413/********************************************************************/
414/* Tx path */
415/********************************************************************/
416
417static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
418{
419 struct orinoco_private *priv = netdev_priv(dev);
420 struct net_device_stats *stats = &priv->stats;
421 hermes_t *hw = &priv->hw;
422 int err = 0;
423 u16 txfid = priv->txfid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 struct ethhdr *eh;
Pavel Roskina28dc812006-04-07 04:10:45 -0400425 int data_off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 struct hermes_tx_descriptor desc;
427 unsigned long flags;
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (! netif_running(dev)) {
430 printk(KERN_ERR "%s: Tx on stopped device!\n",
431 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400432 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 }
434
435 if (netif_queue_stopped(dev)) {
436 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
437 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400438 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
440
441 if (orinoco_lock(priv, &flags) != 0) {
442 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
443 dev->name);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400444 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200447 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 /* Oops, the firmware hasn't established a connection,
449 silently drop the packet (this seems to be the
450 safest approach). */
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400451 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 }
453
Pavel Roskin8d5be082006-04-07 04:10:41 -0400454 /* Check packet length */
Pavel Roskina28dc812006-04-07 04:10:45 -0400455 if (skb->len < ETH_HLEN)
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400456 goto drop;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 eh = (struct ethhdr *)skb->data;
459
460 memset(&desc, 0, sizeof(desc));
461 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
462 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
463 if (err) {
464 if (net_ratelimit())
465 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
466 "to BAP\n", dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400467 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469
470 /* Clear the 802.11 header and data length fields - some
471 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
472 * if this isn't done. */
473 hermes_clear_words(hw, HERMES_DATA0,
474 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
475
476 /* Encapsulate Ethernet-II frames */
477 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
Pavel Roskina28dc812006-04-07 04:10:45 -0400478 struct header_struct {
479 struct ethhdr eth; /* 802.3 header */
480 u8 encap[6]; /* 802.2 header */
481 } __attribute__ ((packed)) hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Pavel Roskina28dc812006-04-07 04:10:45 -0400483 /* Strip destination and source from the data */
484 skb_pull(skb, 2 * ETH_ALEN);
485 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
486
487 /* And move them to a separate header */
488 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
489 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
490 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
491
492 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
493 txfid, HERMES_802_3_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (err) {
495 if (net_ratelimit())
496 printk(KERN_ERR "%s: Error %d writing packet "
497 "header to BAP\n", dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400498 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 }
500 } else { /* IEEE 802.3 frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 data_off = HERMES_802_3_OFFSET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 }
503
Pavel Roskina28dc812006-04-07 04:10:45 -0400504 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 txfid, data_off);
506 if (err) {
507 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
508 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400509 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 /* Finally, we actually initiate the send */
513 netif_stop_queue(dev);
514
515 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
516 txfid, NULL);
517 if (err) {
518 netif_start_queue(dev);
Andrew Mortonc367c212005-10-19 21:23:44 -0700519 if (net_ratelimit())
520 printk(KERN_ERR "%s: Error %d transmitting packet\n",
521 dev->name, err);
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400522 goto busy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
525 dev->trans_start = jiffies;
Pavel Roskina28dc812006-04-07 04:10:45 -0400526 stats->tx_bytes += data_off + skb->len;
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400527 goto ok;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400529 drop:
530 stats->tx_errors++;
531 stats->tx_dropped++;
532
533 ok:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 dev_kfree_skb(skb);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400536 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Pavel Roskin470e2aa2006-04-07 04:10:43 -0400538 busy:
Jiri Benc2c1bd262006-04-07 04:10:47 -0400539 if (err == -EIO)
540 schedule_work(&priv->reset_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 orinoco_unlock(priv, &flags);
Pavel Roskinb34b8672006-04-07 04:10:36 -0400542 return NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
545static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
546{
547 struct orinoco_private *priv = netdev_priv(dev);
548 u16 fid = hermes_read_regn(hw, ALLOCFID);
549
550 if (fid != priv->txfid) {
551 if (fid != DUMMY_FID)
552 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
553 dev->name, fid);
554 return;
555 }
556
557 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
558}
559
560static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
561{
562 struct orinoco_private *priv = netdev_priv(dev);
563 struct net_device_stats *stats = &priv->stats;
564
565 stats->tx_packets++;
566
567 netif_wake_queue(dev);
568
569 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
570}
571
572static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
573{
574 struct orinoco_private *priv = netdev_priv(dev);
575 struct net_device_stats *stats = &priv->stats;
576 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
Pavel Roskind133ae42005-09-23 04:18:06 -0400577 u16 status;
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400578 struct hermes_txexc_data hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 int err = 0;
580
581 if (fid == DUMMY_FID)
582 return; /* Nothing's really happened */
583
Pavel Roskin48ca7032005-09-23 04:18:06 -0400584 /* Read part of the frame header - we need status and addr1 */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200585 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400586 sizeof(struct hermes_txexc_data),
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200587 fid, 0);
588
589 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
590 stats->tx_errors++;
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 if (err) {
593 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
594 "(FID=%04X error %d)\n",
595 dev->name, fid, err);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200596 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200599 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
600 err, fid);
601
602 /* We produce a TXDROP event only for retry or lifetime
603 * exceeded, because that's the only status that really mean
604 * that this particular node went away.
605 * Other errors means that *we* screwed up. - Jean II */
Pavel Roskin30c2d3b2006-04-07 04:10:34 -0400606 status = le16_to_cpu(hdr.desc.status);
Pavel Roskind133ae42005-09-23 04:18:06 -0400607 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
Christoph Hellwig95dd91f2005-06-19 01:27:56 +0200608 union iwreq_data wrqu;
609
610 /* Copy 802.11 dest address.
611 * We use the 802.11 header because the frame may
612 * not be 802.3 or may be mangled...
613 * In Ad-Hoc mode, it will be the node address.
614 * In managed mode, it will be most likely the AP addr
615 * User space will figure out how to convert it to
616 * whatever it needs (IP address or else).
617 * - Jean II */
618 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
619 wrqu.addr.sa_family = ARPHRD_ETHER;
620
621 /* Send event to user space */
622 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
628static void orinoco_tx_timeout(struct net_device *dev)
629{
630 struct orinoco_private *priv = netdev_priv(dev);
631 struct net_device_stats *stats = &priv->stats;
632 struct hermes *hw = &priv->hw;
633
634 printk(KERN_WARNING "%s: Tx timeout! "
635 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
636 dev->name, hermes_read_regn(hw, ALLOCFID),
637 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
638
639 stats->tx_errors++;
640
641 schedule_work(&priv->reset_work);
642}
643
644/********************************************************************/
645/* Rx path (data frames) */
646/********************************************************************/
647
648/* Does the frame have a SNAP header indicating it should be
649 * de-encapsulated to Ethernet-II? */
650static inline int is_ethersnap(void *_hdr)
651{
652 u8 *hdr = _hdr;
653
654 /* We de-encapsulate all packets which, a) have SNAP headers
655 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
656 * and where b) the OUI of the SNAP header is 00:00:00 or
657 * 00:00:f8 - we need both because different APs appear to use
658 * different OUIs for some reason */
659 return (memcmp(hdr, &encaps_hdr, 5) == 0)
660 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
661}
662
663static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
664 int level, int noise)
665{
Pavel Roskin343c6862005-09-09 18:43:02 -0400666 struct iw_quality wstats;
667 wstats.level = level - 0x95;
668 wstats.noise = noise - 0x95;
669 wstats.qual = (level > noise) ? (level - noise) : 0;
670 wstats.updated = 7;
671 /* Update spy records */
672 wireless_spy_update(dev, mac, &wstats);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675static void orinoco_stat_gather(struct net_device *dev,
676 struct sk_buff *skb,
677 struct hermes_rx_descriptor *desc)
678{
679 struct orinoco_private *priv = netdev_priv(dev);
680
681 /* Using spy support with lots of Rx packets, like in an
682 * infrastructure (AP), will really slow down everything, because
683 * the MAC address must be compared to each entry of the spy list.
684 * If the user really asks for it (set some address in the
685 * spy list), we do it, but he will pay the price.
686 * Note that to get here, you need both WIRELESS_SPY
687 * compiled in AND some addresses in the list !!!
688 */
689 /* Note : gcc will optimise the whole section away if
690 * WIRELESS_SPY is not defined... - Jean II */
691 if (SPY_NUMBER(priv)) {
692 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
693 desc->signal, desc->silence);
694 }
695}
696
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200697/*
698 * orinoco_rx_monitor - handle received monitor frames.
699 *
700 * Arguments:
701 * dev network device
702 * rxfid received FID
703 * desc rx descriptor of the frame
704 *
705 * Call context: interrupt
706 */
707static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
708 struct hermes_rx_descriptor *desc)
709{
710 u32 hdrlen = 30; /* return full header by default */
711 u32 datalen = 0;
712 u16 fc;
713 int err;
714 int len;
715 struct sk_buff *skb;
716 struct orinoco_private *priv = netdev_priv(dev);
717 struct net_device_stats *stats = &priv->stats;
718 hermes_t *hw = &priv->hw;
719
720 len = le16_to_cpu(desc->data_len);
721
722 /* Determine the size of the header and the data */
723 fc = le16_to_cpu(desc->frame_ctl);
724 switch (fc & IEEE80211_FCTL_FTYPE) {
725 case IEEE80211_FTYPE_DATA:
726 if ((fc & IEEE80211_FCTL_TODS)
727 && (fc & IEEE80211_FCTL_FROMDS))
728 hdrlen = 30;
729 else
730 hdrlen = 24;
731 datalen = len;
732 break;
733 case IEEE80211_FTYPE_MGMT:
734 hdrlen = 24;
735 datalen = len;
736 break;
737 case IEEE80211_FTYPE_CTL:
738 switch (fc & IEEE80211_FCTL_STYPE) {
739 case IEEE80211_STYPE_PSPOLL:
740 case IEEE80211_STYPE_RTS:
741 case IEEE80211_STYPE_CFEND:
742 case IEEE80211_STYPE_CFENDACK:
743 hdrlen = 16;
744 break;
745 case IEEE80211_STYPE_CTS:
746 case IEEE80211_STYPE_ACK:
747 hdrlen = 10;
748 break;
749 }
750 break;
751 default:
752 /* Unknown frame type */
753 break;
754 }
755
756 /* sanity check the length */
757 if (datalen > IEEE80211_DATA_LEN + 12) {
758 printk(KERN_DEBUG "%s: oversized monitor frame, "
759 "data length = %d\n", dev->name, datalen);
760 err = -EIO;
761 stats->rx_length_errors++;
762 goto update_stats;
763 }
764
765 skb = dev_alloc_skb(hdrlen + datalen);
766 if (!skb) {
767 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
768 dev->name);
769 err = -ENOMEM;
770 goto drop;
771 }
772
773 /* Copy the 802.11 header to the skb */
774 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
775 skb->mac.raw = skb->data;
776
777 /* If any, copy the data from the card to the skb */
778 if (datalen > 0) {
779 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
780 ALIGN(datalen, 2), rxfid,
781 HERMES_802_2_OFFSET);
782 if (err) {
783 printk(KERN_ERR "%s: error %d reading monitor frame\n",
784 dev->name, err);
785 goto drop;
786 }
787 }
788
789 skb->dev = dev;
790 skb->ip_summed = CHECKSUM_NONE;
791 skb->pkt_type = PACKET_OTHERHOST;
792 skb->protocol = __constant_htons(ETH_P_802_2);
793
794 dev->last_rx = jiffies;
795 stats->rx_packets++;
796 stats->rx_bytes += skb->len;
797
798 netif_rx(skb);
799 return;
800
801 drop:
802 dev_kfree_skb_irq(skb);
803 update_stats:
804 stats->rx_errors++;
805 stats->rx_dropped++;
806}
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
809{
810 struct orinoco_private *priv = netdev_priv(dev);
811 struct net_device_stats *stats = &priv->stats;
812 struct iw_statistics *wstats = &priv->wstats;
813 struct sk_buff *skb = NULL;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200814 u16 rxfid, status, fc;
815 int length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 struct hermes_rx_descriptor desc;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200817 struct ethhdr *hdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 int err;
819
820 rxfid = hermes_read_regn(hw, RXFID);
821
822 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
823 rxfid, 0);
824 if (err) {
825 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
826 "Frame dropped.\n", dev->name, err);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200827 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
830 status = le16_to_cpu(desc.status);
831
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200832 if (status & HERMES_RXSTAT_BADCRC) {
833 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
834 dev->name);
835 stats->rx_crc_errors++;
836 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 }
838
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200839 /* Handle frames in monitor mode */
840 if (priv->iw_mode == IW_MODE_MONITOR) {
841 orinoco_rx_monitor(dev, rxfid, &desc);
842 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200845 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
846 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
847 dev->name);
848 wstats->discard.code++;
849 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 }
851
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200852 length = le16_to_cpu(desc.data_len);
853 fc = le16_to_cpu(desc.frame_ctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 /* Sanity checks */
856 if (length < 3) { /* No for even an 802.2 LLC header */
857 /* At least on Symbol firmware with PCF we get quite a
858 lot of these legitimately - Poll frames with no
859 data. */
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200860 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 }
Jeff Garzikb4538722005-05-12 22:48:20 -0400862 if (length > IEEE80211_DATA_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
864 dev->name, length);
865 stats->rx_length_errors++;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200866 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868
869 /* We need space for the packet data itself, plus an ethernet
870 header, plus 2 bytes so we can align the IP header on a
871 32bit boundary, plus 1 byte so we can read in odd length
872 packets from the card, which has an IO granularity of 16
873 bits */
874 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
875 if (!skb) {
876 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
877 dev->name);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200878 goto update_stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 }
880
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200881 /* We'll prepend the header, so reserve space for it. The worst
882 case is no decapsulation, when 802.3 header is prepended and
883 nothing is removed. 2 is for aligning the IP header. */
884 skb_reserve(skb, ETH_HLEN + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200886 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
887 ALIGN(length, 2), rxfid,
888 HERMES_802_2_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 if (err) {
890 printk(KERN_ERR "%s: error %d reading frame. "
891 "Frame dropped.\n", dev->name, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 goto drop;
893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
895 /* Handle decapsulation
896 * In most cases, the firmware tell us about SNAP frames.
897 * For some reason, the SNAP frames sent by LinkSys APs
898 * are not properly recognised by most firmwares.
899 * So, check ourselves */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200900 if (length >= ENCAPS_OVERHEAD &&
901 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
902 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
903 is_ethersnap(skb->data))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 /* These indicate a SNAP within 802.2 LLC within
905 802.11 frame which we'll need to de-encapsulate to
906 the original EthernetII frame. */
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200907 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 } else {
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200909 /* 802.3 frame - prepend 802.3 header as is */
910 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
911 hdr->h_proto = htons(length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 }
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200913 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
914 if (fc & IEEE80211_FCTL_FROMDS)
915 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
916 else
917 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 dev->last_rx = jiffies;
920 skb->dev = dev;
921 skb->protocol = eth_type_trans(skb, dev);
922 skb->ip_summed = CHECKSUM_NONE;
Christoph Hellwig8f2abf42005-06-19 01:28:02 +0200923 if (fc & IEEE80211_FCTL_TODS)
924 skb->pkt_type = PACKET_OTHERHOST;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* Process the wireless stats if needed */
927 orinoco_stat_gather(dev, skb, &desc);
928
929 /* Pass the packet to the networking stack */
930 netif_rx(skb);
931 stats->rx_packets++;
932 stats->rx_bytes += length;
933
934 return;
935
936 drop:
Christoph Hellwig98c4cae2005-06-19 01:28:06 +0200937 dev_kfree_skb_irq(skb);
938 update_stats:
939 stats->rx_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 stats->rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
943/********************************************************************/
944/* Rx path (info frames) */
945/********************************************************************/
946
947static void print_linkstatus(struct net_device *dev, u16 status)
948{
949 char * s;
950
951 if (suppress_linkstatus)
952 return;
953
954 switch (status) {
955 case HERMES_LINKSTATUS_NOT_CONNECTED:
956 s = "Not Connected";
957 break;
958 case HERMES_LINKSTATUS_CONNECTED:
959 s = "Connected";
960 break;
961 case HERMES_LINKSTATUS_DISCONNECTED:
962 s = "Disconnected";
963 break;
964 case HERMES_LINKSTATUS_AP_CHANGE:
965 s = "AP Changed";
966 break;
967 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
968 s = "AP Out of Range";
969 break;
970 case HERMES_LINKSTATUS_AP_IN_RANGE:
971 s = "AP In Range";
972 break;
973 case HERMES_LINKSTATUS_ASSOC_FAILED:
974 s = "Association Failed";
975 break;
976 default:
977 s = "UNKNOWN";
978 }
979
980 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
981 dev->name, s, status);
982}
983
Christoph Hellwig16739b02005-06-19 01:27:51 +0200984/* Search scan results for requested BSSID, join it if found */
985static void orinoco_join_ap(struct net_device *dev)
986{
987 struct orinoco_private *priv = netdev_priv(dev);
988 struct hermes *hw = &priv->hw;
989 int err;
990 unsigned long flags;
991 struct join_req {
992 u8 bssid[ETH_ALEN];
Pavel Roskind133ae42005-09-23 04:18:06 -0400993 __le16 channel;
Christoph Hellwig16739b02005-06-19 01:27:51 +0200994 } __attribute__ ((packed)) req;
995 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
Pavel Roskinc89cc222005-09-01 20:06:06 -0400996 struct prism2_scan_apinfo *atom = NULL;
Christoph Hellwig16739b02005-06-19 01:27:51 +0200997 int offset = 4;
Pavel Roskinc89cc222005-09-01 20:06:06 -0400998 int found = 0;
Christoph Hellwig16739b02005-06-19 01:27:51 +0200999 u8 *buf;
1000 u16 len;
1001
1002 /* Allocate buffer for scan results */
1003 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1004 if (! buf)
1005 return;
1006
1007 if (orinoco_lock(priv, &flags) != 0)
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001008 goto fail_lock;
Christoph Hellwig16739b02005-06-19 01:27:51 +02001009
1010 /* Sanity checks in case user changed something in the meantime */
1011 if (! priv->bssid_fixed)
1012 goto out;
1013
1014 if (strlen(priv->desired_essid) == 0)
1015 goto out;
1016
1017 /* Read scan results from the firmware */
1018 err = hermes_read_ltv(hw, USER_BAP,
1019 HERMES_RID_SCANRESULTSTABLE,
1020 MAX_SCAN_LEN, &len, buf);
1021 if (err) {
1022 printk(KERN_ERR "%s: Cannot read scan results\n",
1023 dev->name);
1024 goto out;
1025 }
1026
1027 len = HERMES_RECLEN_TO_BYTES(len);
1028
1029 /* Go through the scan results looking for the channel of the AP
1030 * we were requested to join */
1031 for (; offset + atom_len <= len; offset += atom_len) {
1032 atom = (struct prism2_scan_apinfo *) (buf + offset);
Pavel Roskinc89cc222005-09-01 20:06:06 -04001033 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1034 found = 1;
1035 break;
1036 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001037 }
1038
Pavel Roskinc89cc222005-09-01 20:06:06 -04001039 if (! found) {
1040 DEBUG(1, "%s: Requested AP not found in scan results\n",
1041 dev->name);
1042 goto out;
1043 }
Christoph Hellwig16739b02005-06-19 01:27:51 +02001044
Christoph Hellwig16739b02005-06-19 01:27:51 +02001045 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1046 req.channel = atom->channel; /* both are little-endian */
1047 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1048 &req);
1049 if (err)
1050 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1051
1052 out:
Christoph Hellwig16739b02005-06-19 01:27:51 +02001053 orinoco_unlock(priv, &flags);
Pavel Roskinf3cb4cc2005-09-23 04:18:06 -04001054
1055 fail_lock:
1056 kfree(buf);
Christoph Hellwig16739b02005-06-19 01:27:51 +02001057}
1058
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001059/* Send new BSSID to userspace */
1060static void orinoco_send_wevents(struct net_device *dev)
1061{
1062 struct orinoco_private *priv = netdev_priv(dev);
1063 struct hermes *hw = &priv->hw;
1064 union iwreq_data wrqu;
1065 int err;
1066 unsigned long flags;
1067
1068 if (orinoco_lock(priv, &flags) != 0)
1069 return;
1070
1071 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1072 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1073 if (err != 0)
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001074 goto out;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001075
1076 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1077
1078 /* Send event to user space */
1079 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
Pavel Roskin8aeabc32005-09-23 04:18:06 -04001080
1081 out:
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001082 orinoco_unlock(priv, &flags);
1083}
1084
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1086{
1087 struct orinoco_private *priv = netdev_priv(dev);
1088 u16 infofid;
1089 struct {
Pavel Roskind133ae42005-09-23 04:18:06 -04001090 __le16 len;
1091 __le16 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 } __attribute__ ((packed)) info;
1093 int len, type;
1094 int err;
1095
1096 /* This is an answer to an INQUIRE command that we did earlier,
1097 * or an information "event" generated by the card
1098 * The controller return to us a pseudo frame containing
1099 * the information in question - Jean II */
1100 infofid = hermes_read_regn(hw, INFOFID);
1101
1102 /* Read the info frame header - don't try too hard */
1103 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1104 infofid, 0);
1105 if (err) {
1106 printk(KERN_ERR "%s: error %d reading info frame. "
1107 "Frame dropped.\n", dev->name, err);
1108 return;
1109 }
1110
1111 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1112 type = le16_to_cpu(info.type);
1113
1114 switch (type) {
1115 case HERMES_INQ_TALLIES: {
1116 struct hermes_tallies_frame tallies;
1117 struct iw_statistics *wstats = &priv->wstats;
1118
1119 if (len > sizeof(tallies)) {
1120 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1121 dev->name, len);
1122 len = sizeof(tallies);
1123 }
1124
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001125 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1126 infofid, sizeof(info));
1127 if (err)
1128 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 /* Increment our various counters */
1131 /* wstats->discard.nwid - no wrong BSSID stuff */
1132 wstats->discard.code +=
1133 le16_to_cpu(tallies.RxWEPUndecryptable);
1134 if (len == sizeof(tallies))
1135 wstats->discard.code +=
1136 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1137 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1138 wstats->discard.misc +=
1139 le16_to_cpu(tallies.TxDiscardsWrongSA);
1140 wstats->discard.fragment +=
1141 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1142 wstats->discard.retries +=
1143 le16_to_cpu(tallies.TxRetryLimitExceeded);
1144 /* wstats->miss.beacon - no match */
1145 }
1146 break;
1147 case HERMES_INQ_LINKSTATUS: {
1148 struct hermes_linkstatus linkstatus;
1149 u16 newstatus;
1150 int connected;
1151
Christoph Hellwig8f2abf42005-06-19 01:28:02 +02001152 if (priv->iw_mode == IW_MODE_MONITOR)
1153 break;
1154
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 if (len != sizeof(linkstatus)) {
1156 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1157 dev->name, len);
1158 break;
1159 }
1160
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001161 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1162 infofid, sizeof(info));
1163 if (err)
1164 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 newstatus = le16_to_cpu(linkstatus.linkstatus);
1166
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001167 /* Symbol firmware uses "out of range" to signal that
1168 * the hostscan frame can be requested. */
1169 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1170 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1171 priv->has_hostscan && priv->scan_inprogress) {
1172 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1173 break;
1174 }
1175
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1177 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1178 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1179
1180 if (connected)
1181 netif_carrier_on(dev);
David Gibson7bb7c3a2005-05-12 20:02:10 -04001182 else if (!ignore_disconnect)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 netif_carrier_off(dev);
1184
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001185 if (newstatus != priv->last_linkstatus) {
1186 priv->last_linkstatus = newstatus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 print_linkstatus(dev, newstatus);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001188 /* The info frame contains only one word which is the
1189 * status (see hermes.h). The status is pretty boring
1190 * in itself, that's why we export the new BSSID...
1191 * Jean II */
1192 schedule_work(&priv->wevent_work);
1193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 }
1195 break;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001196 case HERMES_INQ_SCAN:
1197 if (!priv->scan_inprogress && priv->bssid_fixed &&
1198 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1199 schedule_work(&priv->join_work);
1200 break;
1201 }
1202 /* fall through */
1203 case HERMES_INQ_HOSTSCAN:
1204 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1205 /* Result of a scanning. Contains information about
1206 * cells in the vicinity - Jean II */
1207 union iwreq_data wrqu;
1208 unsigned char *buf;
1209
1210 /* Sanity check */
1211 if (len > 4096) {
1212 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1213 dev->name, len);
1214 break;
1215 }
1216
1217 /* We are a strict producer. If the previous scan results
1218 * have not been consumed, we just have to drop this
1219 * frame. We can't remove the previous results ourselves,
1220 * that would be *very* racy... Jean II */
1221 if (priv->scan_result != NULL) {
1222 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1223 break;
1224 }
1225
1226 /* Allocate buffer for results */
1227 buf = kmalloc(len, GFP_ATOMIC);
1228 if (buf == NULL)
1229 /* No memory, so can't printk()... */
1230 break;
1231
1232 /* Read scan data */
1233 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1234 infofid, sizeof(info));
Pavel Roskin708218b2005-09-01 20:05:19 -04001235 if (err) {
1236 kfree(buf);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001237 break;
Pavel Roskin708218b2005-09-01 20:05:19 -04001238 }
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001239
1240#ifdef ORINOCO_DEBUG
1241 {
1242 int i;
1243 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1244 for(i = 1; i < (len * 2); i++)
1245 printk(":%02X", buf[i]);
1246 printk("]\n");
1247 }
1248#endif /* ORINOCO_DEBUG */
1249
1250 /* Allow the clients to access the results */
1251 priv->scan_len = len;
1252 priv->scan_result = buf;
1253
1254 /* Send an empty event to user space.
1255 * We don't send the received data on the event because
1256 * it would require us to do complex transcoding, and
1257 * we want to minimise the work done in the irq handler
1258 * Use a request to extract the data - Jean II */
1259 wrqu.data.length = 0;
1260 wrqu.data.flags = 0;
1261 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1262 }
1263 break;
1264 case HERMES_INQ_SEC_STAT_AGERE:
1265 /* Security status (Agere specific) */
1266 /* Ignore this frame for now */
1267 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1268 break;
1269 /* fall through */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 default:
1271 printk(KERN_DEBUG "%s: Unknown information frame received: "
1272 "type 0x%04x, length %d\n", dev->name, type, len);
1273 /* We don't actually do anything about it */
1274 break;
1275 }
1276}
1277
1278static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1279{
1280 if (net_ratelimit())
1281 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1282}
1283
1284/********************************************************************/
1285/* Internal hardware control routines */
1286/********************************************************************/
1287
1288int __orinoco_up(struct net_device *dev)
1289{
1290 struct orinoco_private *priv = netdev_priv(dev);
1291 struct hermes *hw = &priv->hw;
1292 int err;
1293
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02001294 netif_carrier_off(dev); /* just to make sure */
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 err = __orinoco_program_rids(dev);
1297 if (err) {
1298 printk(KERN_ERR "%s: Error %d configuring card\n",
1299 dev->name, err);
1300 return err;
1301 }
1302
1303 /* Fire things up again */
1304 hermes_set_irqmask(hw, ORINOCO_INTEN);
1305 err = hermes_enable_port(hw, 0);
1306 if (err) {
1307 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1308 dev->name, err);
1309 return err;
1310 }
1311
1312 netif_start_queue(dev);
1313
1314 return 0;
1315}
1316
1317int __orinoco_down(struct net_device *dev)
1318{
1319 struct orinoco_private *priv = netdev_priv(dev);
1320 struct hermes *hw = &priv->hw;
1321 int err;
1322
1323 netif_stop_queue(dev);
1324
1325 if (! priv->hw_unavailable) {
1326 if (! priv->broken_disableport) {
1327 err = hermes_disable_port(hw, 0);
1328 if (err) {
1329 /* Some firmwares (e.g. Intersil 1.3.x) seem
1330 * to have problems disabling the port, oh
1331 * well, too bad. */
1332 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1333 dev->name, err);
1334 priv->broken_disableport = 1;
1335 }
1336 }
1337 hermes_set_irqmask(hw, 0);
1338 hermes_write_regn(hw, EVACK, 0xffff);
1339 }
1340
1341 /* firmware will have to reassociate */
1342 netif_carrier_off(dev);
1343 priv->last_linkstatus = 0xffff;
1344
1345 return 0;
1346}
1347
1348int orinoco_reinit_firmware(struct net_device *dev)
1349{
1350 struct orinoco_private *priv = netdev_priv(dev);
1351 struct hermes *hw = &priv->hw;
1352 int err;
1353
1354 err = hermes_init(hw);
1355 if (err)
1356 return err;
1357
1358 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
David Gibsonb24d4582005-05-12 20:04:16 -04001359 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 /* Try workaround for old Symbol firmware bug */
1361 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1362 "(old Symbol firmware?). Trying to work around... ",
1363 dev->name);
1364
1365 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1366 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1367 if (err)
1368 printk("failed!\n");
1369 else
1370 printk("ok.\n");
1371 }
1372
1373 return err;
1374}
1375
1376static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1377{
1378 hermes_t *hw = &priv->hw;
1379 int err = 0;
1380
1381 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1382 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1383 priv->ndev->name, priv->bitratemode);
1384 return -EINVAL;
1385 }
1386
1387 switch (priv->firmware_type) {
1388 case FIRMWARE_TYPE_AGERE:
1389 err = hermes_write_wordrec(hw, USER_BAP,
1390 HERMES_RID_CNFTXRATECONTROL,
1391 bitrate_table[priv->bitratemode].agere_txratectrl);
1392 break;
1393 case FIRMWARE_TYPE_INTERSIL:
1394 case FIRMWARE_TYPE_SYMBOL:
1395 err = hermes_write_wordrec(hw, USER_BAP,
1396 HERMES_RID_CNFTXRATECONTROL,
1397 bitrate_table[priv->bitratemode].intersil_txratectrl);
1398 break;
1399 default:
1400 BUG();
1401 }
1402
1403 return err;
1404}
1405
Christoph Hellwig16739b02005-06-19 01:27:51 +02001406/* Set fixed AP address */
1407static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1408{
1409 int roaming_flag;
1410 int err = 0;
1411 hermes_t *hw = &priv->hw;
1412
1413 switch (priv->firmware_type) {
1414 case FIRMWARE_TYPE_AGERE:
1415 /* not supported */
1416 break;
1417 case FIRMWARE_TYPE_INTERSIL:
1418 if (priv->bssid_fixed)
1419 roaming_flag = 2;
1420 else
1421 roaming_flag = 1;
1422
1423 err = hermes_write_wordrec(hw, USER_BAP,
1424 HERMES_RID_CNFROAMINGMODE,
1425 roaming_flag);
1426 break;
1427 case FIRMWARE_TYPE_SYMBOL:
1428 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1429 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1430 &priv->desired_bssid);
1431 break;
1432 }
1433 return err;
1434}
1435
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436/* Change the WEP keys and/or the current keys. Can be called
1437 * either from __orinoco_hw_setup_wep() or directly from
1438 * orinoco_ioctl_setiwencode(). In the later case the association
1439 * with the AP is not broken (if the firmware can handle it),
1440 * which is needed for 802.1x implementations. */
1441static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1442{
1443 hermes_t *hw = &priv->hw;
1444 int err = 0;
1445
1446 switch (priv->firmware_type) {
1447 case FIRMWARE_TYPE_AGERE:
1448 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1449 HERMES_RID_CNFWEPKEYS_AGERE,
1450 &priv->keys);
1451 if (err)
1452 return err;
1453 err = hermes_write_wordrec(hw, USER_BAP,
1454 HERMES_RID_CNFTXKEY_AGERE,
1455 priv->tx_key);
1456 if (err)
1457 return err;
1458 break;
1459 case FIRMWARE_TYPE_INTERSIL:
1460 case FIRMWARE_TYPE_SYMBOL:
1461 {
1462 int keylen;
1463 int i;
1464
1465 /* Force uniform key length to work around firmware bugs */
1466 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1467
1468 if (keylen > LARGE_KEY_SIZE) {
1469 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1470 priv->ndev->name, priv->tx_key, keylen);
1471 return -E2BIG;
1472 }
1473
1474 /* Write all 4 keys */
1475 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1476 err = hermes_write_ltv(hw, USER_BAP,
1477 HERMES_RID_CNFDEFAULTKEY0 + i,
1478 HERMES_BYTES_TO_RECLEN(keylen),
1479 priv->keys[i].data);
1480 if (err)
1481 return err;
1482 }
1483
1484 /* Write the index of the key used in transmission */
1485 err = hermes_write_wordrec(hw, USER_BAP,
1486 HERMES_RID_CNFWEPDEFAULTKEYID,
1487 priv->tx_key);
1488 if (err)
1489 return err;
1490 }
1491 break;
1492 }
1493
1494 return 0;
1495}
1496
1497static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1498{
1499 hermes_t *hw = &priv->hw;
1500 int err = 0;
1501 int master_wep_flag;
1502 int auth_flag;
1503
1504 if (priv->wep_on)
1505 __orinoco_hw_setup_wepkeys(priv);
1506
1507 if (priv->wep_restrict)
1508 auth_flag = HERMES_AUTH_SHARED_KEY;
1509 else
1510 auth_flag = HERMES_AUTH_OPEN;
1511
1512 switch (priv->firmware_type) {
1513 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1514 if (priv->wep_on) {
1515 /* Enable the shared-key authentication. */
1516 err = hermes_write_wordrec(hw, USER_BAP,
1517 HERMES_RID_CNFAUTHENTICATION_AGERE,
1518 auth_flag);
1519 }
1520 err = hermes_write_wordrec(hw, USER_BAP,
1521 HERMES_RID_CNFWEPENABLED_AGERE,
1522 priv->wep_on);
1523 if (err)
1524 return err;
1525 break;
1526
1527 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1528 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1529 if (priv->wep_on) {
1530 if (priv->wep_restrict ||
1531 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1532 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1533 HERMES_WEP_EXCL_UNENCRYPTED;
1534 else
1535 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1536
1537 err = hermes_write_wordrec(hw, USER_BAP,
1538 HERMES_RID_CNFAUTHENTICATION,
1539 auth_flag);
1540 if (err)
1541 return err;
1542 } else
1543 master_wep_flag = 0;
1544
1545 if (priv->iw_mode == IW_MODE_MONITOR)
1546 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1547
1548 /* Master WEP setting : on/off */
1549 err = hermes_write_wordrec(hw, USER_BAP,
1550 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1551 master_wep_flag);
1552 if (err)
1553 return err;
1554
1555 break;
1556 }
1557
1558 return 0;
1559}
1560
1561static int __orinoco_program_rids(struct net_device *dev)
1562{
1563 struct orinoco_private *priv = netdev_priv(dev);
1564 hermes_t *hw = &priv->hw;
1565 int err;
1566 struct hermes_idstring idbuf;
1567
1568 /* Set the MAC address */
1569 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1570 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1571 if (err) {
1572 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1573 dev->name, err);
1574 return err;
1575 }
1576
1577 /* Set up the link mode */
1578 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1579 priv->port_type);
1580 if (err) {
1581 printk(KERN_ERR "%s: Error %d setting port type\n",
1582 dev->name, err);
1583 return err;
1584 }
1585 /* Set the channel/frequency */
David Gibsond51d8b12005-05-12 20:03:36 -04001586 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1587 err = hermes_write_wordrec(hw, USER_BAP,
1588 HERMES_RID_CNFOWNCHANNEL,
1589 priv->channel);
1590 if (err) {
1591 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1592 dev->name, err, priv->channel);
1593 return err;
1594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 }
1596
1597 if (priv->has_ibss) {
1598 u16 createibss;
1599
1600 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1601 printk(KERN_WARNING "%s: This firmware requires an "
1602 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1603 /* With wvlan_cs, in this case, we would crash.
1604 * hopefully, this driver will behave better...
1605 * Jean II */
1606 createibss = 0;
1607 } else {
1608 createibss = priv->createibss;
1609 }
1610
1611 err = hermes_write_wordrec(hw, USER_BAP,
1612 HERMES_RID_CNFCREATEIBSS,
1613 createibss);
1614 if (err) {
1615 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1616 dev->name, err);
1617 return err;
1618 }
1619 }
1620
Christoph Hellwig16739b02005-06-19 01:27:51 +02001621 /* Set the desired BSSID */
1622 err = __orinoco_hw_set_wap(priv);
1623 if (err) {
1624 printk(KERN_ERR "%s: Error %d setting AP address\n",
1625 dev->name, err);
1626 return err;
1627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 /* Set the desired ESSID */
1629 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1630 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1631 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1632 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1633 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1634 &idbuf);
1635 if (err) {
1636 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1637 dev->name, err);
1638 return err;
1639 }
1640 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1641 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1642 &idbuf);
1643 if (err) {
1644 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1645 dev->name, err);
1646 return err;
1647 }
1648
1649 /* Set the station name */
1650 idbuf.len = cpu_to_le16(strlen(priv->nick));
1651 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1652 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1653 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1654 &idbuf);
1655 if (err) {
1656 printk(KERN_ERR "%s: Error %d setting nickname\n",
1657 dev->name, err);
1658 return err;
1659 }
1660
1661 /* Set AP density */
1662 if (priv->has_sensitivity) {
1663 err = hermes_write_wordrec(hw, USER_BAP,
1664 HERMES_RID_CNFSYSTEMSCALE,
1665 priv->ap_density);
1666 if (err) {
1667 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1668 "Disabling sensitivity control\n",
1669 dev->name, err);
1670
1671 priv->has_sensitivity = 0;
1672 }
1673 }
1674
1675 /* Set RTS threshold */
1676 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1677 priv->rts_thresh);
1678 if (err) {
1679 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1680 dev->name, err);
1681 return err;
1682 }
1683
1684 /* Set fragmentation threshold or MWO robustness */
1685 if (priv->has_mwo)
1686 err = hermes_write_wordrec(hw, USER_BAP,
1687 HERMES_RID_CNFMWOROBUST_AGERE,
1688 priv->mwo_robust);
1689 else
1690 err = hermes_write_wordrec(hw, USER_BAP,
1691 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1692 priv->frag_thresh);
1693 if (err) {
1694 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1695 dev->name, err);
1696 return err;
1697 }
1698
1699 /* Set bitrate */
1700 err = __orinoco_hw_set_bitrate(priv);
1701 if (err) {
1702 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1703 dev->name, err);
1704 return err;
1705 }
1706
1707 /* Set power management */
1708 if (priv->has_pm) {
1709 err = hermes_write_wordrec(hw, USER_BAP,
1710 HERMES_RID_CNFPMENABLED,
1711 priv->pm_on);
1712 if (err) {
1713 printk(KERN_ERR "%s: Error %d setting up PM\n",
1714 dev->name, err);
1715 return err;
1716 }
1717
1718 err = hermes_write_wordrec(hw, USER_BAP,
1719 HERMES_RID_CNFMULTICASTRECEIVE,
1720 priv->pm_mcast);
1721 if (err) {
1722 printk(KERN_ERR "%s: Error %d setting up PM\n",
1723 dev->name, err);
1724 return err;
1725 }
1726 err = hermes_write_wordrec(hw, USER_BAP,
1727 HERMES_RID_CNFMAXSLEEPDURATION,
1728 priv->pm_period);
1729 if (err) {
1730 printk(KERN_ERR "%s: Error %d setting up PM\n",
1731 dev->name, err);
1732 return err;
1733 }
1734 err = hermes_write_wordrec(hw, USER_BAP,
1735 HERMES_RID_CNFPMHOLDOVERDURATION,
1736 priv->pm_timeout);
1737 if (err) {
1738 printk(KERN_ERR "%s: Error %d setting up PM\n",
1739 dev->name, err);
1740 return err;
1741 }
1742 }
1743
1744 /* Set preamble - only for Symbol so far... */
1745 if (priv->has_preamble) {
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFPREAMBLE_SYMBOL,
1748 priv->preamble);
1749 if (err) {
1750 printk(KERN_ERR "%s: Error %d setting preamble\n",
1751 dev->name, err);
1752 return err;
1753 }
1754 }
1755
1756 /* Set up encryption */
1757 if (priv->has_wep) {
1758 err = __orinoco_hw_setup_wep(priv);
1759 if (err) {
1760 printk(KERN_ERR "%s: Error %d activating WEP\n",
1761 dev->name, err);
1762 return err;
1763 }
1764 }
1765
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02001766 if (priv->iw_mode == IW_MODE_MONITOR) {
1767 /* Enable monitor mode */
1768 dev->type = ARPHRD_IEEE80211;
1769 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1770 HERMES_TEST_MONITOR, 0, NULL);
1771 } else {
1772 /* Disable monitor mode */
1773 dev->type = ARPHRD_ETHER;
1774 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1775 HERMES_TEST_STOP, 0, NULL);
1776 }
1777 if (err)
1778 return err;
1779
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 /* Set promiscuity / multicast*/
1781 priv->promiscuous = 0;
1782 priv->mc_count = 0;
1783 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1784
1785 return 0;
1786}
1787
1788/* FIXME: return int? */
1789static void
1790__orinoco_set_multicast_list(struct net_device *dev)
1791{
1792 struct orinoco_private *priv = netdev_priv(dev);
1793 hermes_t *hw = &priv->hw;
1794 int err = 0;
1795 int promisc, mc_count;
1796
1797 /* The Hermes doesn't seem to have an allmulti mode, so we go
1798 * into promiscuous mode and let the upper levels deal. */
1799 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1800 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1801 promisc = 1;
1802 mc_count = 0;
1803 } else {
1804 promisc = 0;
1805 mc_count = dev->mc_count;
1806 }
1807
1808 if (promisc != priv->promiscuous) {
1809 err = hermes_write_wordrec(hw, USER_BAP,
1810 HERMES_RID_CNFPROMISCUOUSMODE,
1811 promisc);
1812 if (err) {
1813 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1814 dev->name, err);
1815 } else
1816 priv->promiscuous = promisc;
1817 }
1818
1819 if (! promisc && (mc_count || priv->mc_count) ) {
1820 struct dev_mc_list *p = dev->mc_list;
1821 struct hermes_multicast mclist;
1822 int i;
1823
1824 for (i = 0; i < mc_count; i++) {
1825 /* paranoia: is list shorter than mc_count? */
1826 BUG_ON(! p);
1827 /* paranoia: bad address size in list? */
1828 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1829
1830 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1831 p = p->next;
1832 }
1833
1834 if (p)
1835 printk(KERN_WARNING "%s: Multicast list is "
1836 "longer than mc_count\n", dev->name);
1837
1838 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1839 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1840 &mclist);
1841 if (err)
1842 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1843 dev->name, err);
1844 else
1845 priv->mc_count = mc_count;
1846 }
1847
1848 /* Since we can set the promiscuous flag when it wasn't asked
1849 for, make sure the net_device knows about it. */
1850 if (priv->promiscuous)
1851 dev->flags |= IFF_PROMISC;
1852 else
1853 dev->flags &= ~IFF_PROMISC;
1854}
1855
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856/* This must be called from user context, without locks held - use
1857 * schedule_work() */
1858static void orinoco_reset(struct net_device *dev)
1859{
1860 struct orinoco_private *priv = netdev_priv(dev);
1861 struct hermes *hw = &priv->hw;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001862 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 unsigned long flags;
1864
1865 if (orinoco_lock(priv, &flags) != 0)
1866 /* When the hardware becomes available again, whatever
1867 * detects that is responsible for re-initializing
1868 * it. So no need for anything further */
1869 return;
1870
1871 netif_stop_queue(dev);
1872
1873 /* Shut off interrupts. Depending on what state the hardware
1874 * is in, this might not work, but we'll try anyway */
1875 hermes_set_irqmask(hw, 0);
1876 hermes_write_regn(hw, EVACK, 0xffff);
1877
1878 priv->hw_unavailable++;
1879 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1880 netif_carrier_off(dev);
1881
1882 orinoco_unlock(priv, &flags);
1883
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02001884 /* Scanning support: Cleanup of driver struct */
1885 kfree(priv->scan_result);
1886 priv->scan_result = NULL;
1887 priv->scan_inprogress = 0;
1888
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001889 if (priv->hard_reset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 err = (*priv->hard_reset)(priv);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001891 if (err) {
1892 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1893 "performing hard reset\n", dev->name, err);
1894 goto disable;
1895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
1897
1898 err = orinoco_reinit_firmware(dev);
1899 if (err) {
1900 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1901 dev->name, err);
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001902 goto disable;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 }
1904
1905 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1906
1907 priv->hw_unavailable--;
1908
1909 /* priv->open or priv->hw_unavailable might have changed while
1910 * we dropped the lock */
1911 if (priv->open && (! priv->hw_unavailable)) {
1912 err = __orinoco_up(dev);
1913 if (err) {
1914 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1915 dev->name, err);
1916 } else
1917 dev->trans_start = jiffies;
1918 }
1919
1920 spin_unlock_irq(&priv->lock);
1921
1922 return;
Christoph Hellwig8551cb92005-05-14 17:30:04 +02001923 disable:
1924 hermes_set_irqmask(hw, 0);
1925 netif_device_detach(dev);
1926 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927}
1928
1929/********************************************************************/
1930/* Interrupt handler */
1931/********************************************************************/
1932
1933static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1934{
1935 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1936}
1937
1938static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1939{
1940 /* This seems to happen a fair bit under load, but ignoring it
1941 seems to work fine...*/
1942 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1943 dev->name);
1944}
1945
1946irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1947{
1948 struct net_device *dev = (struct net_device *)dev_id;
1949 struct orinoco_private *priv = netdev_priv(dev);
1950 hermes_t *hw = &priv->hw;
1951 int count = MAX_IRQLOOPS_PER_IRQ;
1952 u16 evstat, events;
1953 /* These are used to detect a runaway interrupt situation */
1954 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1955 * we panic and shut down the hardware */
1956 static int last_irq_jiffy = 0; /* jiffies value the last time
1957 * we were called */
1958 static int loops_this_jiffy = 0;
1959 unsigned long flags;
1960
1961 if (orinoco_lock(priv, &flags) != 0) {
1962 /* If hw is unavailable - we don't know if the irq was
1963 * for us or not */
1964 return IRQ_HANDLED;
1965 }
1966
1967 evstat = hermes_read_regn(hw, EVSTAT);
1968 events = evstat & hw->inten;
1969 if (! events) {
1970 orinoco_unlock(priv, &flags);
1971 return IRQ_NONE;
1972 }
1973
1974 if (jiffies != last_irq_jiffy)
1975 loops_this_jiffy = 0;
1976 last_irq_jiffy = jiffies;
1977
1978 while (events && count--) {
1979 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1980 printk(KERN_WARNING "%s: IRQ handler is looping too "
1981 "much! Resetting.\n", dev->name);
1982 /* Disable interrupts for now */
1983 hermes_set_irqmask(hw, 0);
1984 schedule_work(&priv->reset_work);
1985 break;
1986 }
1987
1988 /* Check the card hasn't been removed */
1989 if (! hermes_present(hw)) {
1990 DEBUG(0, "orinoco_interrupt(): card removed\n");
1991 break;
1992 }
1993
1994 if (events & HERMES_EV_TICK)
1995 __orinoco_ev_tick(dev, hw);
1996 if (events & HERMES_EV_WTERR)
1997 __orinoco_ev_wterr(dev, hw);
1998 if (events & HERMES_EV_INFDROP)
1999 __orinoco_ev_infdrop(dev, hw);
2000 if (events & HERMES_EV_INFO)
2001 __orinoco_ev_info(dev, hw);
2002 if (events & HERMES_EV_RX)
2003 __orinoco_ev_rx(dev, hw);
2004 if (events & HERMES_EV_TXEXC)
2005 __orinoco_ev_txexc(dev, hw);
2006 if (events & HERMES_EV_TX)
2007 __orinoco_ev_tx(dev, hw);
2008 if (events & HERMES_EV_ALLOC)
2009 __orinoco_ev_alloc(dev, hw);
2010
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002011 hermes_write_regn(hw, EVACK, evstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
2013 evstat = hermes_read_regn(hw, EVSTAT);
2014 events = evstat & hw->inten;
2015 };
2016
2017 orinoco_unlock(priv, &flags);
2018 return IRQ_HANDLED;
2019}
2020
2021/********************************************************************/
2022/* Initialization */
2023/********************************************************************/
2024
2025struct comp_id {
2026 u16 id, variant, major, minor;
2027} __attribute__ ((packed));
2028
2029static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2030{
2031 if (nic_id->id < 0x8000)
2032 return FIRMWARE_TYPE_AGERE;
2033 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2034 return FIRMWARE_TYPE_SYMBOL;
2035 else
2036 return FIRMWARE_TYPE_INTERSIL;
2037}
2038
2039/* Set priv->firmware type, determine firmware properties */
2040static int determine_firmware(struct net_device *dev)
2041{
2042 struct orinoco_private *priv = netdev_priv(dev);
2043 hermes_t *hw = &priv->hw;
2044 int err;
2045 struct comp_id nic_id, sta_id;
2046 unsigned int firmver;
2047 char tmp[SYMBOL_MAX_VER_LEN+1];
2048
2049 /* Get the hardware version */
2050 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2051 if (err) {
2052 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2053 dev->name, err);
2054 return err;
2055 }
2056
2057 le16_to_cpus(&nic_id.id);
2058 le16_to_cpus(&nic_id.variant);
2059 le16_to_cpus(&nic_id.major);
2060 le16_to_cpus(&nic_id.minor);
2061 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2062 dev->name, nic_id.id, nic_id.variant,
2063 nic_id.major, nic_id.minor);
2064
2065 priv->firmware_type = determine_firmware_type(&nic_id);
2066
2067 /* Get the firmware version */
2068 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2069 if (err) {
2070 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2071 dev->name, err);
2072 return err;
2073 }
2074
2075 le16_to_cpus(&sta_id.id);
2076 le16_to_cpus(&sta_id.variant);
2077 le16_to_cpus(&sta_id.major);
2078 le16_to_cpus(&sta_id.minor);
2079 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2080 dev->name, sta_id.id, sta_id.variant,
2081 sta_id.major, sta_id.minor);
2082
2083 switch (sta_id.id) {
2084 case 0x15:
2085 printk(KERN_ERR "%s: Primary firmware is active\n",
2086 dev->name);
2087 return -ENODEV;
2088 case 0x14b:
2089 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2090 dev->name);
2091 return -ENODEV;
2092 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2093 case 0x21: /* Symbol Spectrum24 Trilogy */
2094 break;
2095 default:
2096 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2097 dev->name);
2098 break;
2099 }
2100
2101 /* Default capabilities */
2102 priv->has_sensitivity = 1;
2103 priv->has_mwo = 0;
2104 priv->has_preamble = 0;
2105 priv->has_port3 = 1;
2106 priv->has_ibss = 1;
2107 priv->has_wep = 0;
2108 priv->has_big_wep = 0;
2109
2110 /* Determine capabilities from the firmware version */
2111 switch (priv->firmware_type) {
2112 case FIRMWARE_TYPE_AGERE:
2113 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2114 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2115 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2116 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2117
2118 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2119
2120 priv->has_ibss = (firmver >= 0x60006);
2121 priv->has_wep = (firmver >= 0x40020);
2122 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2123 Gold cards from the others? */
2124 priv->has_mwo = (firmver >= 0x60000);
2125 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2126 priv->ibss_port = 1;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002127 priv->has_hostscan = (firmver >= 0x8000a);
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002128 priv->broken_monitor = (firmver >= 0x80000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 /* Tested with Agere firmware :
2131 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2132 * Tested CableTron firmware : 4.32 => Anton */
2133 break;
2134 case FIRMWARE_TYPE_SYMBOL:
2135 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2136 /* Intel MAC : 00:02:B3:* */
2137 /* 3Com MAC : 00:50:DA:* */
2138 memset(tmp, 0, sizeof(tmp));
2139 /* Get the Symbol firmware version */
2140 err = hermes_read_ltv(hw, USER_BAP,
2141 HERMES_RID_SECONDARYVERSION_SYMBOL,
2142 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2143 if (err) {
2144 printk(KERN_WARNING
2145 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2146 dev->name, err);
2147 firmver = 0;
2148 tmp[0] = '\0';
2149 } else {
2150 /* The firmware revision is a string, the format is
2151 * something like : "V2.20-01".
2152 * Quick and dirty parsing... - Jean II
2153 */
2154 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2155 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2156 | (tmp[7] - '0');
2157
2158 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2159 }
2160
2161 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2162 "Symbol %s", tmp);
2163
2164 priv->has_ibss = (firmver >= 0x20000);
2165 priv->has_wep = (firmver >= 0x15012);
2166 priv->has_big_wep = (firmver >= 0x20000);
2167 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2168 (firmver >= 0x29000 && firmver < 0x30000) ||
2169 firmver >= 0x31000;
2170 priv->has_preamble = (firmver >= 0x20000);
2171 priv->ibss_port = 4;
Christoph Hellwig649e59e2005-05-14 17:30:10 +02002172 priv->broken_disableport = (firmver == 0x25013) ||
2173 (firmver >= 0x30000 && firmver <= 0x31000);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002174 priv->has_hostscan = (firmver >= 0x31001) ||
2175 (firmver >= 0x29057 && firmver < 0x30000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 /* Tested with Intel firmware : 0x20015 => Jean II */
2177 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2178 break;
2179 case FIRMWARE_TYPE_INTERSIL:
2180 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2181 * Samsung, Compaq 100/200 and Proxim are slightly
2182 * different and less well tested */
2183 /* D-Link MAC : 00:40:05:* */
2184 /* Addtron MAC : 00:90:D1:* */
2185 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2186 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2187 sta_id.variant);
2188
2189 firmver = ((unsigned long)sta_id.major << 16) |
2190 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2191
2192 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2193 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2194 priv->has_pm = (firmver >= 0x000700);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002195 priv->has_hostscan = (firmver >= 0x010301);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196
2197 if (firmver >= 0x000800)
2198 priv->ibss_port = 0;
2199 else {
2200 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2201 "than v0.8.x - several features not supported\n",
2202 dev->name);
2203 priv->ibss_port = 1;
2204 }
2205 break;
2206 }
2207 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2208 priv->fw_name);
2209
2210 return 0;
2211}
2212
2213static int orinoco_init(struct net_device *dev)
2214{
2215 struct orinoco_private *priv = netdev_priv(dev);
2216 hermes_t *hw = &priv->hw;
2217 int err = 0;
2218 struct hermes_idstring nickbuf;
2219 u16 reclen;
2220 int len;
2221
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 /* No need to lock, the hw_unavailable flag is already set in
2223 * alloc_orinocodev() */
Jeff Garzikb4538722005-05-12 22:48:20 -04002224 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
2226 /* Initialize the firmware */
David Gibsonb24d4582005-05-12 20:04:16 -04002227 err = orinoco_reinit_firmware(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 if (err != 0) {
2229 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2230 dev->name, err);
2231 goto out;
2232 }
2233
2234 err = determine_firmware(dev);
2235 if (err != 0) {
2236 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2237 dev->name);
2238 goto out;
2239 }
2240
2241 if (priv->has_port3)
2242 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2243 if (priv->has_ibss)
2244 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2245 dev->name);
2246 if (priv->has_wep) {
2247 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2248 if (priv->has_big_wep)
2249 printk("104-bit key\n");
2250 else
2251 printk("40-bit key\n");
2252 }
2253
2254 /* Get the MAC address */
2255 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2256 ETH_ALEN, NULL, dev->dev_addr);
2257 if (err) {
2258 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2259 dev->name);
2260 goto out;
2261 }
2262
2263 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2264 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2265 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2266 dev->dev_addr[5]);
2267
2268 /* Get the station name */
2269 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2270 sizeof(nickbuf), &reclen, &nickbuf);
2271 if (err) {
2272 printk(KERN_ERR "%s: failed to read station name\n",
2273 dev->name);
2274 goto out;
2275 }
2276 if (nickbuf.len)
2277 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2278 else
2279 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2280 memcpy(priv->nick, &nickbuf.val, len);
2281 priv->nick[len] = '\0';
2282
2283 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2284
2285 /* Get allowed channels */
2286 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2287 &priv->channel_mask);
2288 if (err) {
2289 printk(KERN_ERR "%s: failed to read channel list!\n",
2290 dev->name);
2291 goto out;
2292 }
2293
2294 /* Get initial AP density */
2295 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2296 &priv->ap_density);
2297 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2298 priv->has_sensitivity = 0;
2299 }
2300
2301 /* Get initial RTS threshold */
2302 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2303 &priv->rts_thresh);
2304 if (err) {
2305 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2306 dev->name);
2307 goto out;
2308 }
2309
2310 /* Get initial fragmentation settings */
2311 if (priv->has_mwo)
2312 err = hermes_read_wordrec(hw, USER_BAP,
2313 HERMES_RID_CNFMWOROBUST_AGERE,
2314 &priv->mwo_robust);
2315 else
2316 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2317 &priv->frag_thresh);
2318 if (err) {
2319 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2320 dev->name);
2321 goto out;
2322 }
2323
2324 /* Power management setup */
2325 if (priv->has_pm) {
2326 priv->pm_on = 0;
2327 priv->pm_mcast = 1;
2328 err = hermes_read_wordrec(hw, USER_BAP,
2329 HERMES_RID_CNFMAXSLEEPDURATION,
2330 &priv->pm_period);
2331 if (err) {
2332 printk(KERN_ERR "%s: failed to read power management period!\n",
2333 dev->name);
2334 goto out;
2335 }
2336 err = hermes_read_wordrec(hw, USER_BAP,
2337 HERMES_RID_CNFPMHOLDOVERDURATION,
2338 &priv->pm_timeout);
2339 if (err) {
2340 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2341 dev->name);
2342 goto out;
2343 }
2344 }
2345
2346 /* Preamble setup */
2347 if (priv->has_preamble) {
2348 err = hermes_read_wordrec(hw, USER_BAP,
2349 HERMES_RID_CNFPREAMBLE_SYMBOL,
2350 &priv->preamble);
2351 if (err)
2352 goto out;
2353 }
2354
2355 /* Set up the default configuration */
2356 priv->iw_mode = IW_MODE_INFRA;
2357 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2358 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2359 set_port_type(priv);
David Gibsond51d8b12005-05-12 20:03:36 -04002360 priv->channel = 0; /* use firmware default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362 priv->promiscuous = 0;
2363 priv->wep_on = 0;
2364 priv->tx_key = 0;
2365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 /* Make the hardware available, as long as it hasn't been
2367 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2368 spin_lock_irq(&priv->lock);
2369 priv->hw_unavailable--;
2370 spin_unlock_irq(&priv->lock);
2371
2372 printk(KERN_DEBUG "%s: ready\n", dev->name);
2373
2374 out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 return err;
2376}
2377
2378struct net_device *alloc_orinocodev(int sizeof_card,
2379 int (*hard_reset)(struct orinoco_private *))
2380{
2381 struct net_device *dev;
2382 struct orinoco_private *priv;
2383
2384 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2385 if (! dev)
2386 return NULL;
2387 priv = netdev_priv(dev);
2388 priv->ndev = dev;
2389 if (sizeof_card)
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002390 priv->card = (void *)((unsigned long)priv
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 + sizeof(struct orinoco_private));
2392 else
2393 priv->card = NULL;
2394
2395 /* Setup / override net_device fields */
2396 dev->init = orinoco_init;
2397 dev->hard_start_xmit = orinoco_xmit;
2398 dev->tx_timeout = orinoco_tx_timeout;
2399 dev->watchdog_timeo = HZ; /* 1 second timeout */
2400 dev->get_stats = orinoco_get_stats;
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02002401 dev->ethtool_ops = &orinoco_ethtool_ops;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002402 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
Pavel Roskin343c6862005-09-09 18:43:02 -04002403#ifdef WIRELESS_SPY
2404 priv->wireless_data.spy_data = &priv->spy_data;
2405 dev->wireless_data = &priv->wireless_data;
2406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 dev->change_mtu = orinoco_change_mtu;
2408 dev->set_multicast_list = orinoco_set_multicast_list;
2409 /* we use the default eth_mac_addr for setting the MAC addr */
2410
2411 /* Set up default callbacks */
2412 dev->open = orinoco_open;
2413 dev->stop = orinoco_stop;
2414 priv->hard_reset = hard_reset;
2415
2416 spin_lock_init(&priv->lock);
2417 priv->open = 0;
2418 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2419 * before anything else touches the
2420 * hardware */
2421 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
Christoph Hellwig16739b02005-06-19 01:27:51 +02002422 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002423 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 netif_carrier_off(dev);
2426 priv->last_linkstatus = 0xffff;
2427
2428 return dev;
2429
2430}
2431
2432void free_orinocodev(struct net_device *dev)
2433{
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02002434 struct orinoco_private *priv = netdev_priv(dev);
2435
2436 kfree(priv->scan_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 free_netdev(dev);
2438}
2439
2440/********************************************************************/
2441/* Wireless extensions */
2442/********************************************************************/
2443
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2445 char buf[IW_ESSID_MAX_SIZE+1])
2446{
2447 hermes_t *hw = &priv->hw;
2448 int err = 0;
2449 struct hermes_idstring essidbuf;
2450 char *p = (char *)(&essidbuf.val);
2451 int len;
2452 unsigned long flags;
2453
2454 if (orinoco_lock(priv, &flags) != 0)
2455 return -EBUSY;
2456
2457 if (strlen(priv->desired_essid) > 0) {
2458 /* We read the desired SSID from the hardware rather
2459 than from priv->desired_essid, just in case the
2460 firmware is allowed to change it on us. I'm not
2461 sure about this */
2462 /* My guess is that the OWNSSID should always be whatever
2463 * we set to the card, whereas CURRENT_SSID is the one that
2464 * may change... - Jean II */
2465 u16 rid;
2466
2467 *active = 1;
2468
2469 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2470 HERMES_RID_CNFDESIREDSSID;
2471
2472 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2473 NULL, &essidbuf);
2474 if (err)
2475 goto fail_unlock;
2476 } else {
2477 *active = 0;
2478
2479 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2480 sizeof(essidbuf), NULL, &essidbuf);
2481 if (err)
2482 goto fail_unlock;
2483 }
2484
2485 len = le16_to_cpu(essidbuf.len);
Christoph Hellwig84d8a2f2005-05-14 17:30:22 +02002486 BUG_ON(len > IW_ESSID_MAX_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487
2488 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2489 memcpy(buf, p, len);
2490 buf[len] = '\0';
2491
2492 fail_unlock:
2493 orinoco_unlock(priv, &flags);
2494
2495 return err;
2496}
2497
2498static long orinoco_hw_get_freq(struct orinoco_private *priv)
2499{
2500
2501 hermes_t *hw = &priv->hw;
2502 int err = 0;
2503 u16 channel;
2504 long freq = 0;
2505 unsigned long flags;
2506
2507 if (orinoco_lock(priv, &flags) != 0)
2508 return -EBUSY;
2509
2510 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2511 if (err)
2512 goto out;
2513
2514 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2515 if (channel == 0) {
2516 err = -EBUSY;
2517 goto out;
2518 }
2519
2520 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2521 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2522 priv->ndev->name, channel);
2523 err = -EBUSY;
2524 goto out;
2525
2526 }
2527 freq = channel_frequency[channel-1] * 100000;
2528
2529 out:
2530 orinoco_unlock(priv, &flags);
2531
2532 if (err > 0)
2533 err = -EBUSY;
2534 return err ? err : freq;
2535}
2536
2537static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2538 int *numrates, s32 *rates, int max)
2539{
2540 hermes_t *hw = &priv->hw;
2541 struct hermes_idstring list;
2542 unsigned char *p = (unsigned char *)&list.val;
2543 int err = 0;
2544 int num;
2545 int i;
2546 unsigned long flags;
2547
2548 if (orinoco_lock(priv, &flags) != 0)
2549 return -EBUSY;
2550
2551 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2552 sizeof(list), NULL, &list);
2553 orinoco_unlock(priv, &flags);
2554
2555 if (err)
2556 return err;
2557
2558 num = le16_to_cpu(list.len);
2559 *numrates = num;
2560 num = min(num, max);
2561
2562 for (i = 0; i < num; i++) {
2563 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2564 }
2565
2566 return 0;
2567}
2568
Christoph Hellwig620554e2005-06-19 01:27:33 +02002569static int orinoco_ioctl_getname(struct net_device *dev,
2570 struct iw_request_info *info,
2571 char *name,
2572 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573{
2574 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 int numrates;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002576 int err;
2577
2578 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2579
2580 if (!err && (numrates > 2))
2581 strcpy(name, "IEEE 802.11b");
2582 else
2583 strcpy(name, "IEEE 802.11-DS");
2584
2585 return 0;
2586}
2587
Christoph Hellwig16739b02005-06-19 01:27:51 +02002588static int orinoco_ioctl_setwap(struct net_device *dev,
2589 struct iw_request_info *info,
2590 struct sockaddr *ap_addr,
2591 char *extra)
2592{
2593 struct orinoco_private *priv = netdev_priv(dev);
2594 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 unsigned long flags;
Christoph Hellwig16739b02005-06-19 01:27:51 +02002596 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2597 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
2599 if (orinoco_lock(priv, &flags) != 0)
2600 return -EBUSY;
2601
Christoph Hellwig16739b02005-06-19 01:27:51 +02002602 /* Enable automatic roaming - no sanity checks are needed */
2603 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2604 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2605 priv->bssid_fixed = 0;
2606 memset(priv->desired_bssid, 0, ETH_ALEN);
2607
2608 /* "off" means keep existing connection */
2609 if (ap_addr->sa_data[0] == 0) {
2610 __orinoco_hw_set_wap(priv);
2611 err = 0;
2612 }
2613 goto out;
2614 }
2615
2616 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2617 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2618 "support manual roaming\n",
2619 dev->name);
2620 err = -EOPNOTSUPP;
2621 goto out;
2622 }
2623
2624 if (priv->iw_mode != IW_MODE_INFRA) {
2625 printk(KERN_WARNING "%s: Manual roaming supported only in "
2626 "managed mode\n", dev->name);
2627 err = -EOPNOTSUPP;
2628 goto out;
2629 }
2630
2631 /* Intersil firmware hangs without Desired ESSID */
2632 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2633 strlen(priv->desired_essid) == 0) {
2634 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2635 "manual roaming\n", dev->name);
2636 err = -EOPNOTSUPP;
2637 goto out;
2638 }
2639
2640 /* Finally, enable manual roaming */
2641 priv->bssid_fixed = 1;
2642 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2643
2644 out:
2645 orinoco_unlock(priv, &flags);
2646 return err;
2647}
2648
Christoph Hellwig620554e2005-06-19 01:27:33 +02002649static int orinoco_ioctl_getwap(struct net_device *dev,
2650 struct iw_request_info *info,
2651 struct sockaddr *ap_addr,
2652 char *extra)
2653{
2654 struct orinoco_private *priv = netdev_priv(dev);
2655
2656 hermes_t *hw = &priv->hw;
2657 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 unsigned long flags;
2659
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 if (orinoco_lock(priv, &flags) != 0)
2661 return -EBUSY;
2662
Christoph Hellwig620554e2005-06-19 01:27:33 +02002663 ap_addr->sa_family = ARPHRD_ETHER;
2664 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2665 ETH_ALEN, NULL, ap_addr->sa_data);
2666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 orinoco_unlock(priv, &flags);
2668
Christoph Hellwig620554e2005-06-19 01:27:33 +02002669 return err;
2670}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
Christoph Hellwig620554e2005-06-19 01:27:33 +02002672static int orinoco_ioctl_setmode(struct net_device *dev,
2673 struct iw_request_info *info,
2674 u32 *mode,
2675 char *extra)
2676{
2677 struct orinoco_private *priv = netdev_priv(dev);
2678 int err = -EINPROGRESS; /* Call commit handler */
2679 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
Christoph Hellwig620554e2005-06-19 01:27:33 +02002681 if (priv->iw_mode == *mode)
2682 return 0;
2683
2684 if (orinoco_lock(priv, &flags) != 0)
2685 return -EBUSY;
2686
2687 switch (*mode) {
2688 case IW_MODE_ADHOC:
2689 if (!priv->has_ibss && !priv->has_port3)
2690 err = -EOPNOTSUPP;
2691 break;
2692
2693 case IW_MODE_INFRA:
2694 break;
2695
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02002696 case IW_MODE_MONITOR:
2697 if (priv->broken_monitor && !force_monitor) {
2698 printk(KERN_WARNING "%s: Monitor mode support is "
2699 "buggy in this firmware, not enabling\n",
2700 dev->name);
2701 err = -EOPNOTSUPP;
2702 }
2703 break;
2704
Christoph Hellwig620554e2005-06-19 01:27:33 +02002705 default:
2706 err = -EOPNOTSUPP;
2707 break;
2708 }
2709
2710 if (err == -EINPROGRESS) {
2711 priv->iw_mode = *mode;
2712 set_port_type(priv);
2713 }
2714
2715 orinoco_unlock(priv, &flags);
2716
2717 return err;
2718}
2719
2720static int orinoco_ioctl_getmode(struct net_device *dev,
2721 struct iw_request_info *info,
2722 u32 *mode,
2723 char *extra)
2724{
2725 struct orinoco_private *priv = netdev_priv(dev);
2726
2727 *mode = priv->iw_mode;
2728 return 0;
2729}
2730
2731static int orinoco_ioctl_getiwrange(struct net_device *dev,
2732 struct iw_request_info *info,
2733 struct iw_point *rrq,
2734 char *extra)
2735{
2736 struct orinoco_private *priv = netdev_priv(dev);
2737 int err = 0;
2738 struct iw_range *range = (struct iw_range *) extra;
2739 int numrates;
2740 int i, k;
2741
Christoph Hellwig620554e2005-06-19 01:27:33 +02002742 rrq->length = sizeof(struct iw_range);
2743 memset(range, 0, sizeof(struct iw_range));
2744
2745 range->we_version_compiled = WIRELESS_EXT;
2746 range->we_version_source = 14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 /* Set available channels/frequencies */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002749 range->num_channels = NUM_CHANNELS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 k = 0;
2751 for (i = 0; i < NUM_CHANNELS; i++) {
2752 if (priv->channel_mask & (1 << i)) {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002753 range->freq[k].i = i + 1;
2754 range->freq[k].m = channel_frequency[i] * 100000;
2755 range->freq[k].e = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 k++;
2757 }
2758
2759 if (k >= IW_MAX_FREQUENCIES)
2760 break;
2761 }
Christoph Hellwig620554e2005-06-19 01:27:33 +02002762 range->num_frequency = k;
2763 range->sensitivity = 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764
Christoph Hellwig620554e2005-06-19 01:27:33 +02002765 if (priv->has_wep) {
2766 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2767 range->encoding_size[0] = SMALL_KEY_SIZE;
2768 range->num_encoding_sizes = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769
Christoph Hellwig620554e2005-06-19 01:27:33 +02002770 if (priv->has_big_wep) {
2771 range->encoding_size[1] = LARGE_KEY_SIZE;
2772 range->num_encoding_sizes = 2;
2773 }
2774 }
2775
Pavel Roskin343c6862005-09-09 18:43:02 -04002776 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 /* Quality stats meaningless in ad-hoc mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 } else {
Christoph Hellwig620554e2005-06-19 01:27:33 +02002779 range->max_qual.qual = 0x8b - 0x2f;
2780 range->max_qual.level = 0x2f - 0x95 - 1;
2781 range->max_qual.noise = 0x2f - 0x95 - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 /* Need to get better values */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002783 range->avg_qual.qual = 0x24;
2784 range->avg_qual.level = 0xC2;
2785 range->avg_qual.noise = 0x9E;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 }
2787
2788 err = orinoco_hw_get_bitratelist(priv, &numrates,
Christoph Hellwig620554e2005-06-19 01:27:33 +02002789 range->bitrate, IW_MAX_BITRATES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 if (err)
2791 return err;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002792 range->num_bitrates = numrates;
2793
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 /* Set an indication of the max TCP throughput in bit/s that we can
2795 * expect using this interface. May be use for QoS stuff...
2796 * Jean II */
Christoph Hellwig620554e2005-06-19 01:27:33 +02002797 if (numrates > 2)
2798 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 else
Christoph Hellwig620554e2005-06-19 01:27:33 +02002800 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
Christoph Hellwig620554e2005-06-19 01:27:33 +02002802 range->min_rts = 0;
2803 range->max_rts = 2347;
2804 range->min_frag = 256;
2805 range->max_frag = 2346;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Christoph Hellwig620554e2005-06-19 01:27:33 +02002807 range->min_pmp = 0;
2808 range->max_pmp = 65535000;
2809 range->min_pmt = 0;
2810 range->max_pmt = 65535 * 1000; /* ??? */
2811 range->pmp_flags = IW_POWER_PERIOD;
2812 range->pmt_flags = IW_POWER_TIMEOUT;
2813 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
Christoph Hellwig620554e2005-06-19 01:27:33 +02002815 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2816 range->retry_flags = IW_RETRY_LIMIT;
2817 range->r_time_flags = IW_RETRY_LIFETIME;
2818 range->min_retry = 0;
2819 range->max_retry = 65535; /* ??? */
2820 range->min_r_time = 0;
2821 range->max_r_time = 65535 * 1000; /* ??? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Pavel Roskin343c6862005-09-09 18:43:02 -04002823 /* Event capability (kernel) */
2824 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2825 /* Event capability (driver) */
2826 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2827 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2828 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2829 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 return 0;
2832}
2833
Christoph Hellwig620554e2005-06-19 01:27:33 +02002834static int orinoco_ioctl_setiwencode(struct net_device *dev,
2835 struct iw_request_info *info,
2836 struct iw_point *erq,
2837 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838{
2839 struct orinoco_private *priv = netdev_priv(dev);
2840 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2841 int setindex = priv->tx_key;
2842 int enable = priv->wep_on;
2843 int restricted = priv->wep_restrict;
2844 u16 xlen = 0;
Christoph Hellwig620554e2005-06-19 01:27:33 +02002845 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 unsigned long flags;
2847
2848 if (! priv->has_wep)
2849 return -EOPNOTSUPP;
2850
2851 if (erq->pointer) {
2852 /* We actually have a key to set - check its length */
2853 if (erq->length > LARGE_KEY_SIZE)
2854 return -E2BIG;
2855
2856 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2857 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 }
2859
2860 if (orinoco_lock(priv, &flags) != 0)
2861 return -EBUSY;
2862
2863 if (erq->pointer) {
2864 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2865 index = priv->tx_key;
2866
2867 /* Adjust key length to a supported value */
2868 if (erq->length > SMALL_KEY_SIZE) {
2869 xlen = LARGE_KEY_SIZE;
2870 } else if (erq->length > 0) {
2871 xlen = SMALL_KEY_SIZE;
2872 } else
2873 xlen = 0;
2874
2875 /* Switch on WEP if off */
2876 if ((!enable) && (xlen > 0)) {
2877 setindex = index;
2878 enable = 1;
2879 }
2880 } else {
2881 /* Important note : if the user do "iwconfig eth0 enc off",
2882 * we will arrive there with an index of -1. This is valid
2883 * but need to be taken care off... Jean II */
2884 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2885 if((index != -1) || (erq->flags == 0)) {
2886 err = -EINVAL;
2887 goto out;
2888 }
2889 } else {
2890 /* Set the index : Check that the key is valid */
2891 if(priv->keys[index].len == 0) {
2892 err = -EINVAL;
2893 goto out;
2894 }
2895 setindex = index;
2896 }
2897 }
2898
2899 if (erq->flags & IW_ENCODE_DISABLED)
2900 enable = 0;
2901 if (erq->flags & IW_ENCODE_OPEN)
2902 restricted = 0;
2903 if (erq->flags & IW_ENCODE_RESTRICTED)
2904 restricted = 1;
2905
2906 if (erq->pointer) {
2907 priv->keys[index].len = cpu_to_le16(xlen);
2908 memset(priv->keys[index].data, 0,
2909 sizeof(priv->keys[index].data));
2910 memcpy(priv->keys[index].data, keybuf, erq->length);
2911 }
2912 priv->tx_key = setindex;
2913
2914 /* Try fast key change if connected and only keys are changed */
2915 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2916 netif_carrier_ok(dev)) {
2917 err = __orinoco_hw_setup_wepkeys(priv);
2918 /* No need to commit if successful */
2919 goto out;
2920 }
2921
2922 priv->wep_on = enable;
2923 priv->wep_restrict = restricted;
2924
2925 out:
2926 orinoco_unlock(priv, &flags);
2927
2928 return err;
2929}
2930
Christoph Hellwig620554e2005-06-19 01:27:33 +02002931static int orinoco_ioctl_getiwencode(struct net_device *dev,
2932 struct iw_request_info *info,
2933 struct iw_point *erq,
2934 char *keybuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935{
2936 struct orinoco_private *priv = netdev_priv(dev);
2937 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2938 u16 xlen = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 unsigned long flags;
2940
2941 if (! priv->has_wep)
2942 return -EOPNOTSUPP;
2943
2944 if (orinoco_lock(priv, &flags) != 0)
2945 return -EBUSY;
2946
2947 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2948 index = priv->tx_key;
2949
2950 erq->flags = 0;
2951 if (! priv->wep_on)
2952 erq->flags |= IW_ENCODE_DISABLED;
2953 erq->flags |= index + 1;
2954
2955 if (priv->wep_restrict)
2956 erq->flags |= IW_ENCODE_RESTRICTED;
2957 else
2958 erq->flags |= IW_ENCODE_OPEN;
2959
2960 xlen = le16_to_cpu(priv->keys[index].len);
2961
2962 erq->length = xlen;
2963
2964 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2965
2966 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 return 0;
2968}
2969
Christoph Hellwig620554e2005-06-19 01:27:33 +02002970static int orinoco_ioctl_setessid(struct net_device *dev,
2971 struct iw_request_info *info,
2972 struct iw_point *erq,
2973 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974{
2975 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 unsigned long flags;
2977
2978 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2979 * anyway... - Jean II */
2980
Christoph Hellwig620554e2005-06-19 01:27:33 +02002981 /* Hum... Should not use Wireless Extension constant (may change),
2982 * should use our own... - Jean II */
2983 if (erq->length > IW_ESSID_MAX_SIZE)
2984 return -E2BIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
2986 if (orinoco_lock(priv, &flags) != 0)
2987 return -EBUSY;
2988
Christoph Hellwig620554e2005-06-19 01:27:33 +02002989 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
2990 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
2991
2992 /* If not ANY, get the new ESSID */
2993 if (erq->flags) {
2994 memcpy(priv->desired_essid, essidbuf, erq->length);
2995 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996
2997 orinoco_unlock(priv, &flags);
2998
Christoph Hellwig620554e2005-06-19 01:27:33 +02002999 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000}
3001
Christoph Hellwig620554e2005-06-19 01:27:33 +02003002static int orinoco_ioctl_getessid(struct net_device *dev,
3003 struct iw_request_info *info,
3004 struct iw_point *erq,
3005 char *essidbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006{
3007 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 int active;
3009 int err = 0;
3010 unsigned long flags;
3011
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 if (netif_running(dev)) {
3013 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3014 if (err)
3015 return err;
3016 } else {
3017 if (orinoco_lock(priv, &flags) != 0)
3018 return -EBUSY;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003019 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 orinoco_unlock(priv, &flags);
3021 }
3022
3023 erq->flags = 1;
3024 erq->length = strlen(essidbuf) + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 return 0;
3027}
3028
Christoph Hellwig620554e2005-06-19 01:27:33 +02003029static int orinoco_ioctl_setnick(struct net_device *dev,
3030 struct iw_request_info *info,
3031 struct iw_point *nrq,
3032 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033{
3034 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 unsigned long flags;
3036
3037 if (nrq->length > IW_ESSID_MAX_SIZE)
3038 return -E2BIG;
3039
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 if (orinoco_lock(priv, &flags) != 0)
3041 return -EBUSY;
3042
Christoph Hellwig620554e2005-06-19 01:27:33 +02003043 memset(priv->nick, 0, sizeof(priv->nick));
3044 memcpy(priv->nick, nickbuf, nrq->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045
3046 orinoco_unlock(priv, &flags);
3047
Christoph Hellwig620554e2005-06-19 01:27:33 +02003048 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049}
3050
Christoph Hellwig620554e2005-06-19 01:27:33 +02003051static int orinoco_ioctl_getnick(struct net_device *dev,
3052 struct iw_request_info *info,
3053 struct iw_point *nrq,
3054 char *nickbuf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055{
3056 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 unsigned long flags;
3058
3059 if (orinoco_lock(priv, &flags) != 0)
3060 return -EBUSY;
3061
3062 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3063 orinoco_unlock(priv, &flags);
3064
3065 nrq->length = strlen(nickbuf)+1;
3066
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 return 0;
3068}
3069
Christoph Hellwig620554e2005-06-19 01:27:33 +02003070static int orinoco_ioctl_setfreq(struct net_device *dev,
3071 struct iw_request_info *info,
3072 struct iw_freq *frq,
3073 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074{
3075 struct orinoco_private *priv = netdev_priv(dev);
3076 int chan = -1;
3077 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003078 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003080 /* In infrastructure mode the AP sets the channel */
3081 if (priv->iw_mode == IW_MODE_INFRA)
3082 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083
3084 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3085 /* Setting by channel number */
3086 chan = frq->m;
3087 } else {
3088 /* Setting by frequency - search the table */
3089 int mult = 1;
3090 int i;
3091
3092 for (i = 0; i < (6 - frq->e); i++)
3093 mult *= 10;
3094
3095 for (i = 0; i < NUM_CHANNELS; i++)
3096 if (frq->m == (channel_frequency[i] * mult))
3097 chan = i+1;
3098 }
3099
3100 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3101 ! (priv->channel_mask & (1 << (chan-1)) ) )
3102 return -EINVAL;
3103
3104 if (orinoco_lock(priv, &flags) != 0)
3105 return -EBUSY;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003106
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 priv->channel = chan;
Christoph Hellwig98c4cae2005-06-19 01:28:06 +02003108 if (priv->iw_mode == IW_MODE_MONITOR) {
3109 /* Fast channel change - no commit if successful */
3110 hermes_t *hw = &priv->hw;
3111 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3112 HERMES_TEST_SET_CHANNEL,
3113 chan, NULL);
3114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 orinoco_unlock(priv, &flags);
3116
Christoph Hellwig620554e2005-06-19 01:27:33 +02003117 return err;
3118}
3119
3120static int orinoco_ioctl_getfreq(struct net_device *dev,
3121 struct iw_request_info *info,
3122 struct iw_freq *frq,
3123 char *extra)
3124{
3125 struct orinoco_private *priv = netdev_priv(dev);
3126 int tmp;
3127
3128 /* Locking done in there */
3129 tmp = orinoco_hw_get_freq(priv);
3130 if (tmp < 0) {
3131 return tmp;
3132 }
3133
3134 frq->m = tmp;
3135 frq->e = 1;
3136
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 return 0;
3138}
3139
Christoph Hellwig620554e2005-06-19 01:27:33 +02003140static int orinoco_ioctl_getsens(struct net_device *dev,
3141 struct iw_request_info *info,
3142 struct iw_param *srq,
3143 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144{
3145 struct orinoco_private *priv = netdev_priv(dev);
3146 hermes_t *hw = &priv->hw;
3147 u16 val;
3148 int err;
3149 unsigned long flags;
3150
3151 if (!priv->has_sensitivity)
3152 return -EOPNOTSUPP;
3153
3154 if (orinoco_lock(priv, &flags) != 0)
3155 return -EBUSY;
3156 err = hermes_read_wordrec(hw, USER_BAP,
3157 HERMES_RID_CNFSYSTEMSCALE, &val);
3158 orinoco_unlock(priv, &flags);
3159
3160 if (err)
3161 return err;
3162
3163 srq->value = val;
3164 srq->fixed = 0; /* auto */
3165
3166 return 0;
3167}
3168
Christoph Hellwig620554e2005-06-19 01:27:33 +02003169static int orinoco_ioctl_setsens(struct net_device *dev,
3170 struct iw_request_info *info,
3171 struct iw_param *srq,
3172 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173{
3174 struct orinoco_private *priv = netdev_priv(dev);
3175 int val = srq->value;
3176 unsigned long flags;
3177
3178 if (!priv->has_sensitivity)
3179 return -EOPNOTSUPP;
3180
3181 if ((val < 1) || (val > 3))
3182 return -EINVAL;
3183
3184 if (orinoco_lock(priv, &flags) != 0)
3185 return -EBUSY;
3186 priv->ap_density = val;
3187 orinoco_unlock(priv, &flags);
3188
Christoph Hellwig620554e2005-06-19 01:27:33 +02003189 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190}
3191
Christoph Hellwig620554e2005-06-19 01:27:33 +02003192static int orinoco_ioctl_setrts(struct net_device *dev,
3193 struct iw_request_info *info,
3194 struct iw_param *rrq,
3195 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196{
3197 struct orinoco_private *priv = netdev_priv(dev);
3198 int val = rrq->value;
3199 unsigned long flags;
3200
3201 if (rrq->disabled)
3202 val = 2347;
3203
3204 if ( (val < 0) || (val > 2347) )
3205 return -EINVAL;
3206
3207 if (orinoco_lock(priv, &flags) != 0)
3208 return -EBUSY;
3209
3210 priv->rts_thresh = val;
3211 orinoco_unlock(priv, &flags);
3212
Christoph Hellwig620554e2005-06-19 01:27:33 +02003213 return -EINPROGRESS; /* Call commit handler */
3214}
3215
3216static int orinoco_ioctl_getrts(struct net_device *dev,
3217 struct iw_request_info *info,
3218 struct iw_param *rrq,
3219 char *extra)
3220{
3221 struct orinoco_private *priv = netdev_priv(dev);
3222
3223 rrq->value = priv->rts_thresh;
3224 rrq->disabled = (rrq->value == 2347);
3225 rrq->fixed = 1;
3226
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 return 0;
3228}
3229
Christoph Hellwig620554e2005-06-19 01:27:33 +02003230static int orinoco_ioctl_setfrag(struct net_device *dev,
3231 struct iw_request_info *info,
3232 struct iw_param *frq,
3233 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234{
3235 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003236 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 unsigned long flags;
3238
3239 if (orinoco_lock(priv, &flags) != 0)
3240 return -EBUSY;
3241
3242 if (priv->has_mwo) {
3243 if (frq->disabled)
3244 priv->mwo_robust = 0;
3245 else {
3246 if (frq->fixed)
3247 printk(KERN_WARNING "%s: Fixed fragmentation is "
3248 "not supported on this firmware. "
3249 "Using MWO robust instead.\n", dev->name);
3250 priv->mwo_robust = 1;
3251 }
3252 } else {
3253 if (frq->disabled)
3254 priv->frag_thresh = 2346;
3255 else {
3256 if ( (frq->value < 256) || (frq->value > 2346) )
3257 err = -EINVAL;
3258 else
3259 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3260 }
3261 }
3262
3263 orinoco_unlock(priv, &flags);
3264
3265 return err;
3266}
3267
Christoph Hellwig620554e2005-06-19 01:27:33 +02003268static int orinoco_ioctl_getfrag(struct net_device *dev,
3269 struct iw_request_info *info,
3270 struct iw_param *frq,
3271 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272{
3273 struct orinoco_private *priv = netdev_priv(dev);
3274 hermes_t *hw = &priv->hw;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003275 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 u16 val;
3277 unsigned long flags;
3278
3279 if (orinoco_lock(priv, &flags) != 0)
3280 return -EBUSY;
3281
3282 if (priv->has_mwo) {
3283 err = hermes_read_wordrec(hw, USER_BAP,
3284 HERMES_RID_CNFMWOROBUST_AGERE,
3285 &val);
3286 if (err)
3287 val = 0;
3288
3289 frq->value = val ? 2347 : 0;
3290 frq->disabled = ! val;
3291 frq->fixed = 0;
3292 } else {
3293 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3294 &val);
3295 if (err)
3296 val = 0;
3297
3298 frq->value = val;
3299 frq->disabled = (val >= 2346);
3300 frq->fixed = 1;
3301 }
3302
3303 orinoco_unlock(priv, &flags);
3304
3305 return err;
3306}
3307
Christoph Hellwig620554e2005-06-19 01:27:33 +02003308static int orinoco_ioctl_setrate(struct net_device *dev,
3309 struct iw_request_info *info,
3310 struct iw_param *rrq,
3311 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312{
3313 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 int ratemode = -1;
3315 int bitrate; /* 100s of kilobits */
3316 int i;
3317 unsigned long flags;
3318
3319 /* As the user space doesn't know our highest rate, it uses -1
3320 * to ask us to set the highest rate. Test it using "iwconfig
3321 * ethX rate auto" - Jean II */
3322 if (rrq->value == -1)
3323 bitrate = 110;
3324 else {
3325 if (rrq->value % 100000)
3326 return -EINVAL;
3327 bitrate = rrq->value / 100000;
3328 }
3329
3330 if ( (bitrate != 10) && (bitrate != 20) &&
3331 (bitrate != 55) && (bitrate != 110) )
3332 return -EINVAL;
3333
3334 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3335 if ( (bitrate_table[i].bitrate == bitrate) &&
3336 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3337 ratemode = i;
3338 break;
3339 }
3340
3341 if (ratemode == -1)
3342 return -EINVAL;
3343
3344 if (orinoco_lock(priv, &flags) != 0)
3345 return -EBUSY;
3346 priv->bitratemode = ratemode;
3347 orinoco_unlock(priv, &flags);
3348
Christoph Hellwig620554e2005-06-19 01:27:33 +02003349 return -EINPROGRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350}
3351
Christoph Hellwig620554e2005-06-19 01:27:33 +02003352static int orinoco_ioctl_getrate(struct net_device *dev,
3353 struct iw_request_info *info,
3354 struct iw_param *rrq,
3355 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356{
3357 struct orinoco_private *priv = netdev_priv(dev);
3358 hermes_t *hw = &priv->hw;
3359 int err = 0;
3360 int ratemode;
3361 int i;
3362 u16 val;
3363 unsigned long flags;
3364
3365 if (orinoco_lock(priv, &flags) != 0)
3366 return -EBUSY;
3367
3368 ratemode = priv->bitratemode;
3369
3370 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3371
3372 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3373 rrq->fixed = ! bitrate_table[ratemode].automatic;
3374 rrq->disabled = 0;
3375
3376 /* If the interface is running we try to find more about the
3377 current mode */
3378 if (netif_running(dev)) {
3379 err = hermes_read_wordrec(hw, USER_BAP,
3380 HERMES_RID_CURRENTTXRATE, &val);
3381 if (err)
3382 goto out;
3383
3384 switch (priv->firmware_type) {
3385 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3386 /* Note : in Lucent firmware, the return value of
3387 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3388 * and therefore is totally different from the
3389 * encoding of HERMES_RID_CNFTXRATECONTROL.
3390 * Don't forget that 6Mb/s is really 5.5Mb/s */
3391 if (val == 6)
3392 rrq->value = 5500000;
3393 else
3394 rrq->value = val * 1000000;
3395 break;
3396 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3397 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3398 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3399 if (bitrate_table[i].intersil_txratectrl == val) {
3400 ratemode = i;
3401 break;
3402 }
3403 if (i >= BITRATE_TABLE_SIZE)
3404 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3405 dev->name, val);
3406
3407 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3408 break;
3409 default:
3410 BUG();
3411 }
3412 }
3413
3414 out:
3415 orinoco_unlock(priv, &flags);
3416
3417 return err;
3418}
3419
Christoph Hellwig620554e2005-06-19 01:27:33 +02003420static int orinoco_ioctl_setpower(struct net_device *dev,
3421 struct iw_request_info *info,
3422 struct iw_param *prq,
3423 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424{
3425 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003426 int err = -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 unsigned long flags;
3428
3429 if (orinoco_lock(priv, &flags) != 0)
3430 return -EBUSY;
3431
3432 if (prq->disabled) {
3433 priv->pm_on = 0;
3434 } else {
3435 switch (prq->flags & IW_POWER_MODE) {
3436 case IW_POWER_UNICAST_R:
3437 priv->pm_mcast = 0;
3438 priv->pm_on = 1;
3439 break;
3440 case IW_POWER_ALL_R:
3441 priv->pm_mcast = 1;
3442 priv->pm_on = 1;
3443 break;
3444 case IW_POWER_ON:
3445 /* No flags : but we may have a value - Jean II */
3446 break;
3447 default:
3448 err = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449 goto out;
Pavel Roskinc08ad1e2005-11-29 02:59:27 -05003450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451
3452 if (prq->flags & IW_POWER_TIMEOUT) {
3453 priv->pm_on = 1;
3454 priv->pm_timeout = prq->value / 1000;
3455 }
3456 if (prq->flags & IW_POWER_PERIOD) {
3457 priv->pm_on = 1;
3458 priv->pm_period = prq->value / 1000;
3459 }
3460 /* It's valid to not have a value if we are just toggling
3461 * the flags... Jean II */
3462 if(!priv->pm_on) {
3463 err = -EINVAL;
3464 goto out;
3465 }
3466 }
3467
3468 out:
3469 orinoco_unlock(priv, &flags);
3470
3471 return err;
3472}
3473
Christoph Hellwig620554e2005-06-19 01:27:33 +02003474static int orinoco_ioctl_getpower(struct net_device *dev,
3475 struct iw_request_info *info,
3476 struct iw_param *prq,
3477 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478{
3479 struct orinoco_private *priv = netdev_priv(dev);
3480 hermes_t *hw = &priv->hw;
3481 int err = 0;
3482 u16 enable, period, timeout, mcast;
3483 unsigned long flags;
3484
3485 if (orinoco_lock(priv, &flags) != 0)
3486 return -EBUSY;
3487
3488 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3489 if (err)
3490 goto out;
3491
3492 err = hermes_read_wordrec(hw, USER_BAP,
3493 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3494 if (err)
3495 goto out;
3496
3497 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3498 if (err)
3499 goto out;
3500
3501 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3502 if (err)
3503 goto out;
3504
3505 prq->disabled = !enable;
3506 /* Note : by default, display the period */
3507 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3508 prq->flags = IW_POWER_TIMEOUT;
3509 prq->value = timeout * 1000;
3510 } else {
3511 prq->flags = IW_POWER_PERIOD;
3512 prq->value = period * 1000;
3513 }
3514 if (mcast)
3515 prq->flags |= IW_POWER_ALL_R;
3516 else
3517 prq->flags |= IW_POWER_UNICAST_R;
3518
3519 out:
3520 orinoco_unlock(priv, &flags);
3521
3522 return err;
3523}
3524
Christoph Hellwig620554e2005-06-19 01:27:33 +02003525static int orinoco_ioctl_getretry(struct net_device *dev,
3526 struct iw_request_info *info,
3527 struct iw_param *rrq,
3528 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529{
3530 struct orinoco_private *priv = netdev_priv(dev);
3531 hermes_t *hw = &priv->hw;
3532 int err = 0;
3533 u16 short_limit, long_limit, lifetime;
3534 unsigned long flags;
3535
3536 if (orinoco_lock(priv, &flags) != 0)
3537 return -EBUSY;
3538
3539 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3540 &short_limit);
3541 if (err)
3542 goto out;
3543
3544 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3545 &long_limit);
3546 if (err)
3547 goto out;
3548
3549 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3550 &lifetime);
3551 if (err)
3552 goto out;
3553
3554 rrq->disabled = 0; /* Can't be disabled */
3555
3556 /* Note : by default, display the retry number */
3557 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3558 rrq->flags = IW_RETRY_LIFETIME;
3559 rrq->value = lifetime * 1000; /* ??? */
3560 } else {
3561 /* By default, display the min number */
3562 if ((rrq->flags & IW_RETRY_MAX)) {
3563 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3564 rrq->value = long_limit;
3565 } else {
3566 rrq->flags = IW_RETRY_LIMIT;
3567 rrq->value = short_limit;
3568 if(short_limit != long_limit)
3569 rrq->flags |= IW_RETRY_MIN;
3570 }
3571 }
3572
3573 out:
3574 orinoco_unlock(priv, &flags);
3575
3576 return err;
3577}
3578
Christoph Hellwig620554e2005-06-19 01:27:33 +02003579static int orinoco_ioctl_reset(struct net_device *dev,
3580 struct iw_request_info *info,
3581 void *wrqu,
3582 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583{
3584 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003585
3586 if (! capable(CAP_NET_ADMIN))
3587 return -EPERM;
3588
3589 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3590 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3591
3592 /* Firmware reset */
3593 orinoco_reset(dev);
3594 } else {
3595 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3596
3597 schedule_work(&priv->reset_work);
3598 }
3599
3600 return 0;
3601}
3602
3603static int orinoco_ioctl_setibssport(struct net_device *dev,
3604 struct iw_request_info *info,
3605 void *wrqu,
3606 char *extra)
3607
3608{
3609 struct orinoco_private *priv = netdev_priv(dev);
3610 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 unsigned long flags;
3612
3613 if (orinoco_lock(priv, &flags) != 0)
3614 return -EBUSY;
3615
3616 priv->ibss_port = val ;
3617
3618 /* Actually update the mode we are using */
3619 set_port_type(priv);
3620
3621 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003622 return -EINPROGRESS; /* Call commit handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623}
3624
Christoph Hellwig620554e2005-06-19 01:27:33 +02003625static int orinoco_ioctl_getibssport(struct net_device *dev,
3626 struct iw_request_info *info,
3627 void *wrqu,
3628 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629{
3630 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003631 int *val = (int *) extra;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632
3633 *val = priv->ibss_port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 return 0;
3635}
3636
Christoph Hellwig620554e2005-06-19 01:27:33 +02003637static int orinoco_ioctl_setport3(struct net_device *dev,
3638 struct iw_request_info *info,
3639 void *wrqu,
3640 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641{
3642 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003643 int val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 int err = 0;
3645 unsigned long flags;
3646
3647 if (orinoco_lock(priv, &flags) != 0)
3648 return -EBUSY;
3649
3650 switch (val) {
3651 case 0: /* Try to do IEEE ad-hoc mode */
3652 if (! priv->has_ibss) {
3653 err = -EINVAL;
3654 break;
3655 }
3656 priv->prefer_port3 = 0;
3657
3658 break;
3659
3660 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3661 if (! priv->has_port3) {
3662 err = -EINVAL;
3663 break;
3664 }
3665 priv->prefer_port3 = 1;
3666 break;
3667
3668 default:
3669 err = -EINVAL;
3670 }
3671
Christoph Hellwig620554e2005-06-19 01:27:33 +02003672 if (! err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 /* Actually update the mode we are using */
3674 set_port_type(priv);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003675 err = -EINPROGRESS;
3676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
3678 orinoco_unlock(priv, &flags);
3679
3680 return err;
3681}
3682
Christoph Hellwig620554e2005-06-19 01:27:33 +02003683static int orinoco_ioctl_getport3(struct net_device *dev,
3684 struct iw_request_info *info,
3685 void *wrqu,
3686 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003687{
3688 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003689 int *val = (int *) extra;
3690
3691 *val = priv->prefer_port3;
3692 return 0;
3693}
3694
3695static int orinoco_ioctl_setpreamble(struct net_device *dev,
3696 struct iw_request_info *info,
3697 void *wrqu,
3698 char *extra)
3699{
3700 struct orinoco_private *priv = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003701 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02003702 int val;
3703
3704 if (! priv->has_preamble)
3705 return -EOPNOTSUPP;
3706
3707 /* 802.11b has recently defined some short preamble.
3708 * Basically, the Phy header has been reduced in size.
3709 * This increase performance, especially at high rates
3710 * (the preamble is transmitted at 1Mb/s), unfortunately
3711 * this give compatibility troubles... - Jean II */
3712 val = *( (int *) extra );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713
3714 if (orinoco_lock(priv, &flags) != 0)
3715 return -EBUSY;
3716
Christoph Hellwig620554e2005-06-19 01:27:33 +02003717 if (val)
3718 priv->preamble = 1;
3719 else
3720 priv->preamble = 0;
3721
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 orinoco_unlock(priv, &flags);
Christoph Hellwig620554e2005-06-19 01:27:33 +02003723
3724 return -EINPROGRESS; /* Call commit handler */
3725}
3726
3727static int orinoco_ioctl_getpreamble(struct net_device *dev,
3728 struct iw_request_info *info,
3729 void *wrqu,
3730 char *extra)
3731{
3732 struct orinoco_private *priv = netdev_priv(dev);
3733 int *val = (int *) extra;
3734
3735 if (! priv->has_preamble)
3736 return -EOPNOTSUPP;
3737
3738 *val = priv->preamble;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 return 0;
3740}
3741
Christoph Hellwig620554e2005-06-19 01:27:33 +02003742/* ioctl interface to hermes_read_ltv()
3743 * To use with iwpriv, pass the RID as the token argument, e.g.
3744 * iwpriv get_rid [0xfc00]
3745 * At least Wireless Tools 25 is required to use iwpriv.
3746 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3747static int orinoco_ioctl_getrid(struct net_device *dev,
3748 struct iw_request_info *info,
3749 struct iw_point *data,
3750 char *extra)
3751{
3752 struct orinoco_private *priv = netdev_priv(dev);
3753 hermes_t *hw = &priv->hw;
3754 int rid = data->flags;
3755 u16 length;
3756 int err;
3757 unsigned long flags;
3758
3759 /* It's a "get" function, but we don't want users to access the
3760 * WEP key and other raw firmware data */
3761 if (! capable(CAP_NET_ADMIN))
3762 return -EPERM;
3763
3764 if (rid < 0xfc00 || rid > 0xffff)
3765 return -EINVAL;
3766
3767 if (orinoco_lock(priv, &flags) != 0)
3768 return -EBUSY;
3769
3770 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3771 extra);
3772 if (err)
3773 goto out;
3774
3775 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3776 MAX_RID_LEN);
3777
3778 out:
3779 orinoco_unlock(priv, &flags);
3780 return err;
3781}
3782
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003783/* Trigger a scan (look for other cells in the vicinity */
3784static int orinoco_ioctl_setscan(struct net_device *dev,
3785 struct iw_request_info *info,
3786 struct iw_param *srq,
3787 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
3789 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003790 hermes_t *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792 unsigned long flags;
3793
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003794 /* Note : you may have realised that, as this is a SET operation,
Alexey Dobriyan7f927fc2006-03-28 01:56:53 -08003795 * this is privileged and therefore a normal user can't
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003796 * perform scanning.
3797 * This is not an error, while the device perform scanning,
3798 * traffic doesn't flow, so it's a perfect DoS...
3799 * Jean II */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003801 if (orinoco_lock(priv, &flags) != 0)
3802 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003804 /* Scanning with port 0 disabled would fail */
3805 if (!netif_running(dev)) {
3806 err = -ENETDOWN;
3807 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003809
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003810 /* In monitor mode, the scan results are always empty.
3811 * Probe responses are passed to the driver as received
3812 * frames and could be processed in software. */
3813 if (priv->iw_mode == IW_MODE_MONITOR) {
3814 err = -EOPNOTSUPP;
3815 goto out;
3816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003818 /* Note : because we don't lock out the irq handler, the way
3819 * we access scan variables in priv is critical.
3820 * o scan_inprogress : not touched by irq handler
3821 * o scan_mode : not touched by irq handler
3822 * o scan_result : irq is strict producer, non-irq is strict
3823 * consumer.
3824 * o scan_len : synchronised with scan_result
3825 * Before modifying anything on those variables, please think hard !
3826 * Jean II */
3827
3828 /* If there is still some left-over scan results, get rid of it */
3829 if (priv->scan_result != NULL) {
3830 /* What's likely is that a client did crash or was killed
3831 * between triggering the scan request and reading the
3832 * results, so we need to reset everything.
3833 * Some clients that are too slow may suffer from that...
3834 * Jean II */
3835 kfree(priv->scan_result);
3836 priv->scan_result = NULL;
3837 }
3838
3839 /* Save flags */
3840 priv->scan_mode = srq->flags;
3841
3842 /* Always trigger scanning, even if it's in progress.
3843 * This way, if the info frame get lost, we will recover somewhat
3844 * gracefully - Jean II */
3845
3846 if (priv->has_hostscan) {
3847 switch (priv->firmware_type) {
3848 case FIRMWARE_TYPE_SYMBOL:
3849 err = hermes_write_wordrec(hw, USER_BAP,
3850 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3851 HERMES_HOSTSCAN_SYMBOL_ONCE |
3852 HERMES_HOSTSCAN_SYMBOL_BCAST);
3853 break;
3854 case FIRMWARE_TYPE_INTERSIL: {
Pavel Roskind133ae42005-09-23 04:18:06 -04003855 __le16 req[3];
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003856
3857 req[0] = cpu_to_le16(0x3fff); /* All channels */
3858 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3859 req[2] = 0; /* Any ESSID */
3860 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3861 HERMES_RID_CNFHOSTSCAN, &req);
3862 }
3863 break;
3864 case FIRMWARE_TYPE_AGERE:
3865 err = hermes_write_wordrec(hw, USER_BAP,
3866 HERMES_RID_CNFSCANSSID_AGERE,
3867 0); /* Any ESSID */
3868 if (err)
3869 break;
3870
3871 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3872 break;
3873 }
3874 } else
3875 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3876
3877 /* One more client */
3878 if (! err)
3879 priv->scan_inprogress = 1;
3880
3881 out:
3882 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003883 return err;
3884}
3885
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003886/* Translate scan data returned from the card to a card independant
Pavel Roskin70817c42005-09-01 20:02:50 -04003887 * format that the Wireless Tools will understand - Jean II
3888 * Return message length or -errno for fatal errors */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003889static inline int orinoco_translate_scan(struct net_device *dev,
3890 char *buffer,
3891 char *scan,
3892 int scan_len)
3893{
3894 struct orinoco_private *priv = netdev_priv(dev);
3895 int offset; /* In the scan data */
3896 union hermes_scan_info *atom;
3897 int atom_len;
3898 u16 capabilities;
3899 u16 channel;
3900 struct iw_event iwe; /* Temporary buffer */
3901 char * current_ev = buffer;
3902 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3903
3904 switch (priv->firmware_type) {
3905 case FIRMWARE_TYPE_AGERE:
3906 atom_len = sizeof(struct agere_scan_apinfo);
3907 offset = 0;
3908 break;
3909 case FIRMWARE_TYPE_SYMBOL:
3910 /* Lack of documentation necessitates this hack.
3911 * Different firmwares have 68 or 76 byte long atoms.
3912 * We try modulo first. If the length divides by both,
3913 * we check what would be the channel in the second
3914 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3915 * Valid channel cannot be 0. */
3916 if (scan_len % 76)
3917 atom_len = 68;
3918 else if (scan_len % 68)
3919 atom_len = 76;
3920 else if (scan_len >= 1292 && scan[68] == 0)
3921 atom_len = 76;
3922 else
3923 atom_len = 68;
3924 offset = 0;
3925 break;
3926 case FIRMWARE_TYPE_INTERSIL:
3927 offset = 4;
Pavel Roskin70817c42005-09-01 20:02:50 -04003928 if (priv->has_hostscan) {
Pavel Roskind133ae42005-09-23 04:18:06 -04003929 atom_len = le16_to_cpup((__le16 *)scan);
Pavel Roskin70817c42005-09-01 20:02:50 -04003930 /* Sanity check for atom_len */
3931 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3932 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3933 dev->name, atom_len);
3934 return -EIO;
3935 }
3936 } else
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003937 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3938 break;
3939 default:
Pavel Roskin70817c42005-09-01 20:02:50 -04003940 return -EOPNOTSUPP;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003941 }
3942
3943 /* Check that we got an whole number of atoms */
3944 if ((scan_len - offset) % atom_len) {
3945 printk(KERN_ERR "%s: Unexpected scan data length %d, "
3946 "atom_len %d, offset %d\n", dev->name, scan_len,
3947 atom_len, offset);
Pavel Roskin70817c42005-09-01 20:02:50 -04003948 return -EIO;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02003949 }
3950
3951 /* Read the entries one by one */
3952 for (; offset + atom_len <= scan_len; offset += atom_len) {
3953 /* Get next atom */
3954 atom = (union hermes_scan_info *) (scan + offset);
3955
3956 /* First entry *MUST* be the AP MAC address */
3957 iwe.cmd = SIOCGIWAP;
3958 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3959 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
3960 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
3961
3962 /* Other entries will be displayed in the order we give them */
3963
3964 /* Add the ESSID */
3965 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
3966 if (iwe.u.data.length > 32)
3967 iwe.u.data.length = 32;
3968 iwe.cmd = SIOCGIWESSID;
3969 iwe.u.data.flags = 1;
3970 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
3971
3972 /* Add mode */
3973 iwe.cmd = SIOCGIWMODE;
3974 capabilities = le16_to_cpu(atom->a.capabilities);
3975 if (capabilities & 0x3) {
3976 if (capabilities & 0x1)
3977 iwe.u.mode = IW_MODE_MASTER;
3978 else
3979 iwe.u.mode = IW_MODE_ADHOC;
3980 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
3981 }
3982
3983 channel = atom->s.channel;
3984 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
3985 /* Add frequency */
3986 iwe.cmd = SIOCGIWFREQ;
3987 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
3988 iwe.u.freq.e = 1;
3989 current_ev = iwe_stream_add_event(current_ev, end_buf,
3990 &iwe, IW_EV_FREQ_LEN);
3991 }
3992
3993 /* Add quality statistics */
3994 iwe.cmd = IWEVQUAL;
3995 iwe.u.qual.updated = 0x10; /* no link quality */
3996 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
3997 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
3998 /* Wireless tools prior to 27.pre22 will show link quality
3999 * anyway, so we provide a reasonable value. */
4000 if (iwe.u.qual.level > iwe.u.qual.noise)
4001 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4002 else
4003 iwe.u.qual.qual = 0;
4004 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4005
4006 /* Add encryption capability */
4007 iwe.cmd = SIOCGIWENCODE;
4008 if (capabilities & 0x10)
4009 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4010 else
4011 iwe.u.data.flags = IW_ENCODE_DISABLED;
4012 iwe.u.data.length = 0;
4013 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4014
4015 /* Bit rate is not available in Lucent/Agere firmwares */
4016 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4017 char * current_val = current_ev + IW_EV_LCP_LEN;
4018 int i;
4019 int step;
4020
4021 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4022 step = 2;
4023 else
4024 step = 1;
4025
4026 iwe.cmd = SIOCGIWRATE;
4027 /* Those two flags are ignored... */
4028 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4029 /* Max 10 values */
4030 for (i = 0; i < 10; i += step) {
4031 /* NULL terminated */
4032 if (atom->p.rates[i] == 0x0)
4033 break;
4034 /* Bit rate given in 500 kb/s units (+ 0x80) */
4035 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4036 current_val = iwe_stream_add_value(current_ev, current_val,
4037 end_buf, &iwe,
4038 IW_EV_PARAM_LEN);
4039 }
4040 /* Check if we added any event */
4041 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4042 current_ev = current_val;
4043 }
4044
4045 /* The other data in the scan result are not really
4046 * interesting, so for now drop it - Jean II */
4047 }
4048 return current_ev - buffer;
4049}
4050
4051/* Return results of a scan */
4052static int orinoco_ioctl_getscan(struct net_device *dev,
4053 struct iw_request_info *info,
4054 struct iw_point *srq,
4055 char *extra)
4056{
4057 struct orinoco_private *priv = netdev_priv(dev);
4058 int err = 0;
4059 unsigned long flags;
4060
4061 if (orinoco_lock(priv, &flags) != 0)
4062 return -EBUSY;
4063
4064 /* If no results yet, ask to try again later */
4065 if (priv->scan_result == NULL) {
4066 if (priv->scan_inprogress)
4067 /* Important note : we don't want to block the caller
4068 * until results are ready for various reasons.
4069 * First, managing wait queues is complex and racy.
4070 * Second, we grab some rtnetlink lock before comming
4071 * here (in dev_ioctl()).
4072 * Third, we generate an Wireless Event, so the
4073 * caller can wait itself on that - Jean II */
4074 err = -EAGAIN;
4075 else
4076 /* Client error, no scan results...
4077 * The caller need to restart the scan. */
4078 err = -ENODATA;
4079 } else {
4080 /* We have some results to push back to user space */
4081
4082 /* Translate to WE format */
Pavel Roskin70817c42005-09-01 20:02:50 -04004083 int ret = orinoco_translate_scan(dev, extra,
4084 priv->scan_result,
4085 priv->scan_len);
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004086
Pavel Roskin70817c42005-09-01 20:02:50 -04004087 if (ret < 0) {
4088 err = ret;
4089 kfree(priv->scan_result);
4090 priv->scan_result = NULL;
4091 } else {
4092 srq->length = ret;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004093
Pavel Roskin70817c42005-09-01 20:02:50 -04004094 /* Return flags */
4095 srq->flags = (__u16) priv->scan_mode;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004096
Pavel Roskin70817c42005-09-01 20:02:50 -04004097 /* In any case, Scan results will be cleaned up in the
4098 * reset function and when exiting the driver.
4099 * The person triggering the scanning may never come to
4100 * pick the results, so we need to do it in those places.
4101 * Jean II */
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004102
4103#ifdef SCAN_SINGLE_READ
Pavel Roskin70817c42005-09-01 20:02:50 -04004104 /* If you enable this option, only one client (the first
4105 * one) will be able to read the result (and only one
4106 * time). If there is multiple concurent clients that
4107 * want to read scan results, this behavior is not
4108 * advisable - Jean II */
4109 kfree(priv->scan_result);
4110 priv->scan_result = NULL;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004111#endif /* SCAN_SINGLE_READ */
Pavel Roskin70817c42005-09-01 20:02:50 -04004112 /* Here, if too much time has elapsed since last scan,
4113 * we may want to clean up scan results... - Jean II */
4114 }
4115
4116 /* Scan is no longer in progress */
4117 priv->scan_inprogress = 0;
Christoph Hellwig95dd91f2005-06-19 01:27:56 +02004118 }
4119
4120 orinoco_unlock(priv, &flags);
4121 return err;
4122}
4123
Christoph Hellwig620554e2005-06-19 01:27:33 +02004124/* Commit handler, called after set operations */
4125static int orinoco_ioctl_commit(struct net_device *dev,
4126 struct iw_request_info *info,
4127 void *wrqu,
4128 char *extra)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129{
4130 struct orinoco_private *priv = netdev_priv(dev);
Christoph Hellwig620554e2005-06-19 01:27:33 +02004131 struct hermes *hw = &priv->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 unsigned long flags;
Christoph Hellwig620554e2005-06-19 01:27:33 +02004133 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134
Christoph Hellwig620554e2005-06-19 01:27:33 +02004135 if (!priv->open)
4136 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137
Christoph Hellwig620554e2005-06-19 01:27:33 +02004138 if (priv->broken_disableport) {
4139 orinoco_reset(dev);
4140 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142
Christoph Hellwig620554e2005-06-19 01:27:33 +02004143 if (orinoco_lock(priv, &flags) != 0)
4144 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004145
Christoph Hellwig620554e2005-06-19 01:27:33 +02004146 err = hermes_disable_port(hw, 0);
4147 if (err) {
4148 printk(KERN_WARNING "%s: Unable to disable port "
4149 "while reconfiguring card\n", dev->name);
4150 priv->broken_disableport = 1;
4151 goto out;
4152 }
4153
4154 err = __orinoco_program_rids(dev);
4155 if (err) {
4156 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4157 dev->name);
4158 goto out;
4159 }
4160
4161 err = hermes_enable_port(hw, 0);
4162 if (err) {
4163 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4164 dev->name);
4165 goto out;
4166 }
4167
4168 out:
4169 if (err) {
4170 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4171 schedule_work(&priv->reset_work);
4172 err = 0;
4173 }
4174
4175 orinoco_unlock(priv, &flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 return err;
4177}
4178
Christoph Hellwig620554e2005-06-19 01:27:33 +02004179static const struct iw_priv_args orinoco_privtab[] = {
4180 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4181 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4182 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4183 0, "set_port3" },
4184 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4185 "get_port3" },
4186 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4187 0, "set_preamble" },
4188 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4189 "get_preamble" },
4190 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4191 0, "set_ibssport" },
4192 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4193 "get_ibssport" },
4194 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4195 "get_rid" },
4196};
4197
4198
4199/*
4200 * Structures to export the Wireless Handlers
4201 */
4202
4203static const iw_handler orinoco_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004204 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4205 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4206 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4207 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4208 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4209 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4210 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4211 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4212 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
Pavel Roskin343c6862005-09-09 18:43:02 -04004213 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4214 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4215 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4216 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004217 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4218 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4219 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4220 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4221 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4222 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4223 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4224 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4225 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4226 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4227 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4228 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4229 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4230 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4231 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4232 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4233 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4234 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4235 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004236};
4237
4238
4239/*
4240 Added typecasting since we no longer use iwreq_data -- Moustafa
4241 */
4242static const iw_handler orinoco_private_handler[] = {
Peter Hagervall6b9b97c2005-07-27 01:14:46 -07004243 [0] = (iw_handler) orinoco_ioctl_reset,
4244 [1] = (iw_handler) orinoco_ioctl_reset,
4245 [2] = (iw_handler) orinoco_ioctl_setport3,
4246 [3] = (iw_handler) orinoco_ioctl_getport3,
4247 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4248 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4249 [6] = (iw_handler) orinoco_ioctl_setibssport,
4250 [7] = (iw_handler) orinoco_ioctl_getibssport,
4251 [9] = (iw_handler) orinoco_ioctl_getrid,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004252};
4253
4254static const struct iw_handler_def orinoco_handler_def = {
4255 .num_standard = ARRAY_SIZE(orinoco_handler),
4256 .num_private = ARRAY_SIZE(orinoco_private_handler),
4257 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4258 .standard = orinoco_handler,
4259 .private = orinoco_private_handler,
4260 .private_args = orinoco_privtab,
Pavel Roskin343c6862005-09-09 18:43:02 -04004261 .get_wireless_stats = orinoco_get_wireless_stats,
Christoph Hellwig620554e2005-06-19 01:27:33 +02004262};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004263
Christoph Hellwig1fab2e82005-06-19 01:27:40 +02004264static void orinoco_get_drvinfo(struct net_device *dev,
4265 struct ethtool_drvinfo *info)
4266{
4267 struct orinoco_private *priv = netdev_priv(dev);
4268
4269 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4270 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4271 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4272 if (dev->class_dev.dev)
4273 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4274 sizeof(info->bus_info) - 1);
4275 else
4276 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4277 "PCMCIA %p", priv->hw.iobase);
4278}
4279
4280static struct ethtool_ops orinoco_ethtool_ops = {
4281 .get_drvinfo = orinoco_get_drvinfo,
4282 .get_link = ethtool_op_get_link,
4283};
Linus Torvalds1da177e2005-04-16 15:20:36 -07004284
4285/********************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07004286/* Module initialization */
4287/********************************************************************/
4288
4289EXPORT_SYMBOL(alloc_orinocodev);
4290EXPORT_SYMBOL(free_orinocodev);
4291
4292EXPORT_SYMBOL(__orinoco_up);
4293EXPORT_SYMBOL(__orinoco_down);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004294EXPORT_SYMBOL(orinoco_reinit_firmware);
4295
4296EXPORT_SYMBOL(orinoco_interrupt);
4297
4298/* Can't be declared "const" or the whole __initdata section will
4299 * become const */
4300static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4301 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4302 "Pavel Roskin <proski@gnu.org>, et al)";
4303
4304static int __init init_orinoco(void)
4305{
4306 printk(KERN_DEBUG "%s\n", version);
4307 return 0;
4308}
4309
4310static void __exit exit_orinoco(void)
4311{
4312}
4313
4314module_init(init_orinoco);
4315module_exit(exit_orinoco);