]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/orinoco.c
[PATCH] orinoco: Annotate endianess of variables and structure members.
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / orinoco.c
CommitLineData
1da177e4
LT
1/* 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/*
1da177e4 49 * TODO
1da177e4
LT
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
1da177e4
LT
52 * 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>
1da177e4
LT
80#include <linux/module.h>
81#include <linux/kernel.h>
82#include <linux/init.h>
1da177e4 83#include <linux/netdevice.h>
1da177e4 84#include <linux/etherdevice.h>
1fab2e8b 85#include <linux/ethtool.h>
1da177e4 86#include <linux/wireless.h>
620554e4 87#include <net/iw_handler.h>
5d558b7f 88#include <net/ieee80211.h>
1da177e4 89
1da177e4
LT
90#include "hermes_rid.h"
91#include "orinoco.h"
1da177e4
LT
92
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");
7bb7c3a3
DG
112static int ignore_disconnect; /* = 0 */
113module_param(ignore_disconnect, int, 0644);
114MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
1da177e4 115
98c4cae1
CH
116static int force_monitor; /* = 0 */
117module_param(force_monitor, int, 0644);
118MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
119
1da177e4
LT
120/********************************************************************/
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
343c686c 126#define SPY_NUMBER(priv) (priv->spy_data.spy_number)
1da177e4
LT
127#else
128#define SPY_NUMBER(priv) 0
129#endif /* WIRELESS_SPY */
130
131/********************************************************************/
132/* Internal constants */
133/********************************************************************/
134
95dd91fb
CH
135/* 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
1da177e4 139#define ORINOCO_MIN_MTU 256
b453872c 140#define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
1da177e4
LT
141
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
620554e4
CH
165#define MAX_RID_LEN 1024
166
167static const struct iw_handler_def orinoco_handler_def;
1fab2e8b 168static struct ethtool_ops orinoco_ethtool_ops;
620554e4 169
1da177e4
LT
170/********************************************************************/
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
95dd91fb 204/* Used in Event handling.
d133ae4c 205 * We avoid nested structures as they break on ARM -- Moustafa */
95dd91fb
CH
206struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
d133ae4c
PR
208 __le16 status;
209 __le16 reserved1;
210 __le16 reserved2;
211 __le32 sw_support;
95dd91fb
CH
212 u8 retry_count;
213 u8 tx_rate;
d133ae4c 214 __le16 tx_control;
95dd91fb 215
d133ae4c
PR
216 /* ieee80211_hdr */
217 __le16 frame_ctl;
218 __le16 duration_id;
95dd91fb
CH
219 u8 addr1[ETH_ALEN];
220 u8 addr2[ETH_ALEN];
221 u8 addr3[ETH_ALEN];
d133ae4c 222 __le16 seq_ctl;
95dd91fb 223 u8 addr4[ETH_ALEN];
d133ae4c
PR
224
225 __le16 data_len;
95dd91fb
CH
226
227 /* ethhdr */
d133ae4c
PR
228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
229 u8 h_source[ETH_ALEN]; /* source ether addr */
230 __be16 h_proto; /* packet type ID field */
95dd91fb
CH
231
232 /* p8022_hdr */
1da177e4
LT
233 u8 dsap;
234 u8 ssap;
235 u8 ctrl;
1da177e4 236 u8 oui[3];
95dd91fb 237
d133ae4c 238 __be16 ethertype;
1da177e4
LT
239} __attribute__ ((packed));
240
8f2abf44 241/* Rx frame header except compatibility 802.3 header */
1da177e4 242struct hermes_rx_descriptor {
8f2abf44 243 /* Control */
d133ae4c
PR
244 __le16 status;
245 __le32 time;
1da177e4
LT
246 u8 silence;
247 u8 signal;
248 u8 rate;
249 u8 rxflow;
d133ae4c 250 __le32 reserved;
8f2abf44
CH
251
252 /* 802.11 header */
d133ae4c
PR
253 __le16 frame_ctl;
254 __le16 duration_id;
8f2abf44
CH
255 u8 addr1[ETH_ALEN];
256 u8 addr2[ETH_ALEN];
257 u8 addr3[ETH_ALEN];
d133ae4c 258 __le16 seq_ctl;
8f2abf44
CH
259 u8 addr4[ETH_ALEN];
260
261 /* Data length */
d133ae4c 262 __le16 data_len;
1da177e4
LT
263} __attribute__ ((packed));
264
265/********************************************************************/
266/* Function prototypes */
267/********************************************************************/
268
1da177e4
LT
269static int __orinoco_program_rids(struct net_device *dev);
270static void __orinoco_set_multicast_list(struct net_device *dev);
1da177e4
LT
271
272/********************************************************************/
273/* Internal helper functions */
274/********************************************************************/
275
276static inline void set_port_type(struct orinoco_private *priv)
277{
278 switch (priv->iw_mode) {
279 case IW_MODE_INFRA:
280 priv->port_type = 1;
281 priv->createibss = 0;
282 break;
283 case IW_MODE_ADHOC:
284 if (priv->prefer_port3) {
285 priv->port_type = 3;
286 priv->createibss = 0;
287 } else {
288 priv->port_type = priv->ibss_port;
289 priv->createibss = 1;
290 }
291 break;
98c4cae1
CH
292 case IW_MODE_MONITOR:
293 priv->port_type = 3;
294 priv->createibss = 0;
295 break;
1da177e4
LT
296 default:
297 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
298 priv->ndev->name);
299 }
300}
301
302/********************************************************************/
303/* Device methods */
304/********************************************************************/
305
306static int orinoco_open(struct net_device *dev)
307{
308 struct orinoco_private *priv = netdev_priv(dev);
309 unsigned long flags;
310 int err;
311
312 if (orinoco_lock(priv, &flags) != 0)
313 return -EBUSY;
314
315 err = __orinoco_up(dev);
316
317 if (! err)
318 priv->open = 1;
319
320 orinoco_unlock(priv, &flags);
321
322 return err;
323}
324
ad8f451b 325static int orinoco_stop(struct net_device *dev)
1da177e4
LT
326{
327 struct orinoco_private *priv = netdev_priv(dev);
328 int err = 0;
329
330 /* We mustn't use orinoco_lock() here, because we need to be
331 able to close the interface even if hw_unavailable is set
332 (e.g. as we're released after a PC Card removal) */
333 spin_lock_irq(&priv->lock);
334
335 priv->open = 0;
336
337 err = __orinoco_down(dev);
338
339 spin_unlock_irq(&priv->lock);
340
341 return err;
342}
343
344static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
345{
346 struct orinoco_private *priv = netdev_priv(dev);
347
348 return &priv->stats;
349}
350
351static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
352{
353 struct orinoco_private *priv = netdev_priv(dev);
354 hermes_t *hw = &priv->hw;
355 struct iw_statistics *wstats = &priv->wstats;
e67d9d9d 356 int err;
1da177e4
LT
357 unsigned long flags;
358
359 if (! netif_device_present(dev)) {
360 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
361 dev->name);
362 return NULL; /* FIXME: Can we do better than this? */
363 }
364
e67d9d9d
DG
365 /* If busy, return the old stats. Returning NULL may cause
366 * the interface to disappear from /proc/net/wireless */
1da177e4 367 if (orinoco_lock(priv, &flags) != 0)
e67d9d9d
DG
368 return wstats;
369
370 /* We can't really wait for the tallies inquiry command to
371 * complete, so we just use the previous results and trigger
372 * a new tallies inquiry command for next time - Jean II */
373 /* FIXME: Really we should wait for the inquiry to come back -
374 * as it is the stats we give don't make a whole lot of sense.
375 * Unfortunately, it's not clear how to do that within the
376 * wireless extensions framework: I think we're in user
377 * context, but a lock seems to be held by the time we get in
378 * here so we're not safe to sleep here. */
379 hermes_inquire(hw, HERMES_INQ_TALLIES);
1da177e4
LT
380
381 if (priv->iw_mode == IW_MODE_ADHOC) {
382 memset(&wstats->qual, 0, sizeof(wstats->qual));
383 /* If a spy address is defined, we report stats of the
384 * first spy address - Jean II */
385 if (SPY_NUMBER(priv)) {
343c686c
PR
386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
1da177e4
LT
390 }
391 } else {
392 struct {
d133ae4c 393 __le16 qual, signal, noise;
1da177e4
LT
394 } __attribute__ ((packed)) cq;
395
396 err = HERMES_READ_RECORD(hw, USER_BAP,
397 HERMES_RID_COMMSQUALITY, &cq);
e67d9d9d
DG
398
399 if (!err) {
400 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
401 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
402 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
403 wstats->qual.updated = 7;
404 }
1da177e4
LT
405 }
406
1da177e4 407 orinoco_unlock(priv, &flags);
1da177e4
LT
408 return wstats;
409}
410
411static void orinoco_set_multicast_list(struct net_device *dev)
412{
413 struct orinoco_private *priv = netdev_priv(dev);
414 unsigned long flags;
415
416 if (orinoco_lock(priv, &flags) != 0) {
417 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
418 "called when hw_unavailable\n", dev->name);
419 return;
420 }
421
422 __orinoco_set_multicast_list(dev);
423 orinoco_unlock(priv, &flags);
424}
425
426static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
427{
428 struct orinoco_private *priv = netdev_priv(dev);
429
430 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
431 return -EINVAL;
432
b453872c 433 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
1da177e4
LT
434 (priv->nicbuf_size - ETH_HLEN) )
435 return -EINVAL;
436
437 dev->mtu = new_mtu;
438
439 return 0;
440}
441
442/********************************************************************/
443/* Tx path */
444/********************************************************************/
445
446static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
447{
448 struct orinoco_private *priv = netdev_priv(dev);
449 struct net_device_stats *stats = &priv->stats;
450 hermes_t *hw = &priv->hw;
451 int err = 0;
452 u16 txfid = priv->txfid;
453 char *p;
454 struct ethhdr *eh;
455 int len, data_len, data_off;
456 struct hermes_tx_descriptor desc;
457 unsigned long flags;
458
459 TRACE_ENTER(dev->name);
460
461 if (! netif_running(dev)) {
462 printk(KERN_ERR "%s: Tx on stopped device!\n",
463 dev->name);
464 TRACE_EXIT(dev->name);
465 return 1;
466 }
467
468 if (netif_queue_stopped(dev)) {
469 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
470 dev->name);
471 TRACE_EXIT(dev->name);
472 return 1;
473 }
474
475 if (orinoco_lock(priv, &flags) != 0) {
476 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
477 dev->name);
478 TRACE_EXIT(dev->name);
479 return 1;
480 }
481
98c4cae1 482 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
1da177e4
LT
483 /* Oops, the firmware hasn't established a connection,
484 silently drop the packet (this seems to be the
485 safest approach). */
486 stats->tx_errors++;
487 orinoco_unlock(priv, &flags);
488 dev_kfree_skb(skb);
489 TRACE_EXIT(dev->name);
490 return 0;
491 }
492
493 /* Length of the packet body */
494 /* FIXME: what if the skb is smaller than this? */
495 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
496
497 eh = (struct ethhdr *)skb->data;
498
499 memset(&desc, 0, sizeof(desc));
500 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
501 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
502 if (err) {
503 if (net_ratelimit())
504 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
505 "to BAP\n", dev->name, err);
506 stats->tx_errors++;
507 goto fail;
508 }
509
510 /* Clear the 802.11 header and data length fields - some
511 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
512 * if this isn't done. */
513 hermes_clear_words(hw, HERMES_DATA0,
514 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
515
516 /* Encapsulate Ethernet-II frames */
517 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
518 struct header_struct hdr;
519 data_len = len;
520 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
521 p = skb->data + ETH_HLEN;
522
523 /* 802.3 header */
524 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
525 memcpy(hdr.src, eh->h_source, ETH_ALEN);
526 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
527
528 /* 802.2 header */
529 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
530
531 hdr.ethertype = eh->h_proto;
532 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
533 txfid, HERMES_802_3_OFFSET);
534 if (err) {
535 if (net_ratelimit())
536 printk(KERN_ERR "%s: Error %d writing packet "
537 "header to BAP\n", dev->name, err);
538 stats->tx_errors++;
539 goto fail;
540 }
541 } else { /* IEEE 802.3 frame */
542 data_len = len + ETH_HLEN;
543 data_off = HERMES_802_3_OFFSET;
544 p = skb->data;
545 }
546
547 /* Round up for odd length packets */
548 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
549 txfid, data_off);
550 if (err) {
551 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
552 dev->name, err);
553 stats->tx_errors++;
554 goto fail;
555 }
556
557 /* Finally, we actually initiate the send */
558 netif_stop_queue(dev);
559
560 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
561 txfid, NULL);
562 if (err) {
563 netif_start_queue(dev);
564 printk(KERN_ERR "%s: Error %d transmitting packet\n",
565 dev->name, err);
566 stats->tx_errors++;
567 goto fail;
568 }
569
570 dev->trans_start = jiffies;
571 stats->tx_bytes += data_off + data_len;
572
573 orinoco_unlock(priv, &flags);
574
575 dev_kfree_skb(skb);
576
577 TRACE_EXIT(dev->name);
578
579 return 0;
580 fail:
581 TRACE_EXIT(dev->name);
582
583 orinoco_unlock(priv, &flags);
584 return err;
585}
586
587static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
588{
589 struct orinoco_private *priv = netdev_priv(dev);
590 u16 fid = hermes_read_regn(hw, ALLOCFID);
591
592 if (fid != priv->txfid) {
593 if (fid != DUMMY_FID)
594 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
595 dev->name, fid);
596 return;
597 }
598
599 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
600}
601
602static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
603{
604 struct orinoco_private *priv = netdev_priv(dev);
605 struct net_device_stats *stats = &priv->stats;
606
607 stats->tx_packets++;
608
609 netif_wake_queue(dev);
610
611 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
612}
613
614static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
615{
616 struct orinoco_private *priv = netdev_priv(dev);
617 struct net_device_stats *stats = &priv->stats;
618 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
d133ae4c 619 u16 status;
95dd91fb 620 struct hermes_tx_descriptor_802_11 hdr;
1da177e4
LT
621 int err = 0;
622
623 if (fid == DUMMY_FID)
624 return; /* Nothing's really happened */
625
95dd91fb
CH
626 /* Read the frame header */
627 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
628 sizeof(struct hermes_tx_descriptor) +
af9288a7 629 sizeof(struct ieee80211_hdr_4addr),
95dd91fb
CH
630 fid, 0);
631
632 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
633 stats->tx_errors++;
634
1da177e4
LT
635 if (err) {
636 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
637 "(FID=%04X error %d)\n",
638 dev->name, fid, err);
95dd91fb 639 return;
1da177e4
LT
640 }
641
95dd91fb
CH
642 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
643 err, fid);
644
645 /* We produce a TXDROP event only for retry or lifetime
646 * exceeded, because that's the only status that really mean
647 * that this particular node went away.
648 * Other errors means that *we* screwed up. - Jean II */
d133ae4c
PR
649 status = le16_to_cpu(hdr.status);
650 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
95dd91fb
CH
651 union iwreq_data wrqu;
652
653 /* Copy 802.11 dest address.
654 * We use the 802.11 header because the frame may
655 * not be 802.3 or may be mangled...
656 * In Ad-Hoc mode, it will be the node address.
657 * In managed mode, it will be most likely the AP addr
658 * User space will figure out how to convert it to
659 * whatever it needs (IP address or else).
660 * - Jean II */
661 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
662 wrqu.addr.sa_family = ARPHRD_ETHER;
663
664 /* Send event to user space */
665 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
666 }
1da177e4
LT
667
668 netif_wake_queue(dev);
1da177e4
LT
669}
670
671static void orinoco_tx_timeout(struct net_device *dev)
672{
673 struct orinoco_private *priv = netdev_priv(dev);
674 struct net_device_stats *stats = &priv->stats;
675 struct hermes *hw = &priv->hw;
676
677 printk(KERN_WARNING "%s: Tx timeout! "
678 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
679 dev->name, hermes_read_regn(hw, ALLOCFID),
680 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
681
682 stats->tx_errors++;
683
684 schedule_work(&priv->reset_work);
685}
686
687/********************************************************************/
688/* Rx path (data frames) */
689/********************************************************************/
690
691/* Does the frame have a SNAP header indicating it should be
692 * de-encapsulated to Ethernet-II? */
693static inline int is_ethersnap(void *_hdr)
694{
695 u8 *hdr = _hdr;
696
697 /* We de-encapsulate all packets which, a) have SNAP headers
698 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
699 * and where b) the OUI of the SNAP header is 00:00:00 or
700 * 00:00:f8 - we need both because different APs appear to use
701 * different OUIs for some reason */
702 return (memcmp(hdr, &encaps_hdr, 5) == 0)
703 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
704}
705
706static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
707 int level, int noise)
708{
343c686c
PR
709 struct iw_quality wstats;
710 wstats.level = level - 0x95;
711 wstats.noise = noise - 0x95;
712 wstats.qual = (level > noise) ? (level - noise) : 0;
713 wstats.updated = 7;
714 /* Update spy records */
715 wireless_spy_update(dev, mac, &wstats);
1da177e4
LT
716}
717
718static void orinoco_stat_gather(struct net_device *dev,
719 struct sk_buff *skb,
720 struct hermes_rx_descriptor *desc)
721{
722 struct orinoco_private *priv = netdev_priv(dev);
723
724 /* Using spy support with lots of Rx packets, like in an
725 * infrastructure (AP), will really slow down everything, because
726 * the MAC address must be compared to each entry of the spy list.
727 * If the user really asks for it (set some address in the
728 * spy list), we do it, but he will pay the price.
729 * Note that to get here, you need both WIRELESS_SPY
730 * compiled in AND some addresses in the list !!!
731 */
732 /* Note : gcc will optimise the whole section away if
733 * WIRELESS_SPY is not defined... - Jean II */
734 if (SPY_NUMBER(priv)) {
735 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
736 desc->signal, desc->silence);
737 }
738}
739
98c4cae1
CH
740/*
741 * orinoco_rx_monitor - handle received monitor frames.
742 *
743 * Arguments:
744 * dev network device
745 * rxfid received FID
746 * desc rx descriptor of the frame
747 *
748 * Call context: interrupt
749 */
750static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
751 struct hermes_rx_descriptor *desc)
752{
753 u32 hdrlen = 30; /* return full header by default */
754 u32 datalen = 0;
755 u16 fc;
756 int err;
757 int len;
758 struct sk_buff *skb;
759 struct orinoco_private *priv = netdev_priv(dev);
760 struct net_device_stats *stats = &priv->stats;
761 hermes_t *hw = &priv->hw;
762
763 len = le16_to_cpu(desc->data_len);
764
765 /* Determine the size of the header and the data */
766 fc = le16_to_cpu(desc->frame_ctl);
767 switch (fc & IEEE80211_FCTL_FTYPE) {
768 case IEEE80211_FTYPE_DATA:
769 if ((fc & IEEE80211_FCTL_TODS)
770 && (fc & IEEE80211_FCTL_FROMDS))
771 hdrlen = 30;
772 else
773 hdrlen = 24;
774 datalen = len;
775 break;
776 case IEEE80211_FTYPE_MGMT:
777 hdrlen = 24;
778 datalen = len;
779 break;
780 case IEEE80211_FTYPE_CTL:
781 switch (fc & IEEE80211_FCTL_STYPE) {
782 case IEEE80211_STYPE_PSPOLL:
783 case IEEE80211_STYPE_RTS:
784 case IEEE80211_STYPE_CFEND:
785 case IEEE80211_STYPE_CFENDACK:
786 hdrlen = 16;
787 break;
788 case IEEE80211_STYPE_CTS:
789 case IEEE80211_STYPE_ACK:
790 hdrlen = 10;
791 break;
792 }
793 break;
794 default:
795 /* Unknown frame type */
796 break;
797 }
798
799 /* sanity check the length */
800 if (datalen > IEEE80211_DATA_LEN + 12) {
801 printk(KERN_DEBUG "%s: oversized monitor frame, "
802 "data length = %d\n", dev->name, datalen);
803 err = -EIO;
804 stats->rx_length_errors++;
805 goto update_stats;
806 }
807
808 skb = dev_alloc_skb(hdrlen + datalen);
809 if (!skb) {
810 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
811 dev->name);
812 err = -ENOMEM;
813 goto drop;
814 }
815
816 /* Copy the 802.11 header to the skb */
817 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
818 skb->mac.raw = skb->data;
819
820 /* If any, copy the data from the card to the skb */
821 if (datalen > 0) {
822 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
823 ALIGN(datalen, 2), rxfid,
824 HERMES_802_2_OFFSET);
825 if (err) {
826 printk(KERN_ERR "%s: error %d reading monitor frame\n",
827 dev->name, err);
828 goto drop;
829 }
830 }
831
832 skb->dev = dev;
833 skb->ip_summed = CHECKSUM_NONE;
834 skb->pkt_type = PACKET_OTHERHOST;
835 skb->protocol = __constant_htons(ETH_P_802_2);
836
837 dev->last_rx = jiffies;
838 stats->rx_packets++;
839 stats->rx_bytes += skb->len;
840
841 netif_rx(skb);
842 return;
843
844 drop:
845 dev_kfree_skb_irq(skb);
846 update_stats:
847 stats->rx_errors++;
848 stats->rx_dropped++;
849}
850
1da177e4
LT
851static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
852{
853 struct orinoco_private *priv = netdev_priv(dev);
854 struct net_device_stats *stats = &priv->stats;
855 struct iw_statistics *wstats = &priv->wstats;
856 struct sk_buff *skb = NULL;
8f2abf44
CH
857 u16 rxfid, status, fc;
858 int length;
1da177e4 859 struct hermes_rx_descriptor desc;
8f2abf44 860 struct ethhdr *hdr;
1da177e4
LT
861 int err;
862
863 rxfid = hermes_read_regn(hw, RXFID);
864
865 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
866 rxfid, 0);
867 if (err) {
868 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
869 "Frame dropped.\n", dev->name, err);
98c4cae1 870 goto update_stats;
1da177e4
LT
871 }
872
873 status = le16_to_cpu(desc.status);
874
98c4cae1
CH
875 if (status & HERMES_RXSTAT_BADCRC) {
876 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
877 dev->name);
878 stats->rx_crc_errors++;
879 goto update_stats;
1da177e4
LT
880 }
881
98c4cae1
CH
882 /* Handle frames in monitor mode */
883 if (priv->iw_mode == IW_MODE_MONITOR) {
884 orinoco_rx_monitor(dev, rxfid, &desc);
885 return;
886 }
1da177e4 887
98c4cae1
CH
888 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
889 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
890 dev->name);
891 wstats->discard.code++;
892 goto update_stats;
1da177e4
LT
893 }
894
8f2abf44
CH
895 length = le16_to_cpu(desc.data_len);
896 fc = le16_to_cpu(desc.frame_ctl);
897
1da177e4
LT
898 /* Sanity checks */
899 if (length < 3) { /* No for even an 802.2 LLC header */
900 /* At least on Symbol firmware with PCF we get quite a
901 lot of these legitimately - Poll frames with no
902 data. */
98c4cae1 903 return;
1da177e4 904 }
b453872c 905 if (length > IEEE80211_DATA_LEN) {
1da177e4
LT
906 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
907 dev->name, length);
908 stats->rx_length_errors++;
98c4cae1 909 goto update_stats;
1da177e4
LT
910 }
911
912 /* We need space for the packet data itself, plus an ethernet
913 header, plus 2 bytes so we can align the IP header on a
914 32bit boundary, plus 1 byte so we can read in odd length
915 packets from the card, which has an IO granularity of 16
916 bits */
917 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
918 if (!skb) {
919 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
920 dev->name);
98c4cae1 921 goto update_stats;
1da177e4
LT
922 }
923
8f2abf44
CH
924 /* We'll prepend the header, so reserve space for it. The worst
925 case is no decapsulation, when 802.3 header is prepended and
926 nothing is removed. 2 is for aligning the IP header. */
927 skb_reserve(skb, ETH_HLEN + 2);
928
929 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
930 ALIGN(length, 2), rxfid,
931 HERMES_802_2_OFFSET);
932 if (err) {
933 printk(KERN_ERR "%s: error %d reading frame. "
934 "Frame dropped.\n", dev->name, err);
8f2abf44
CH
935 goto drop;
936 }
1da177e4
LT
937
938 /* Handle decapsulation
939 * In most cases, the firmware tell us about SNAP frames.
940 * For some reason, the SNAP frames sent by LinkSys APs
941 * are not properly recognised by most firmwares.
942 * So, check ourselves */
8f2abf44
CH
943 if (length >= ENCAPS_OVERHEAD &&
944 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
945 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
946 is_ethersnap(skb->data))) {
1da177e4
LT
947 /* These indicate a SNAP within 802.2 LLC within
948 802.11 frame which we'll need to de-encapsulate to
949 the original EthernetII frame. */
8f2abf44 950 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1da177e4 951 } else {
8f2abf44
CH
952 /* 802.3 frame - prepend 802.3 header as is */
953 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
954 hdr->h_proto = htons(length);
1da177e4 955 }
8f2abf44
CH
956 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
957 if (fc & IEEE80211_FCTL_FROMDS)
958 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
959 else
960 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1da177e4
LT
961
962 dev->last_rx = jiffies;
963 skb->dev = dev;
964 skb->protocol = eth_type_trans(skb, dev);
965 skb->ip_summed = CHECKSUM_NONE;
8f2abf44
CH
966 if (fc & IEEE80211_FCTL_TODS)
967 skb->pkt_type = PACKET_OTHERHOST;
1da177e4
LT
968
969 /* Process the wireless stats if needed */
970 orinoco_stat_gather(dev, skb, &desc);
971
972 /* Pass the packet to the networking stack */
973 netif_rx(skb);
974 stats->rx_packets++;
975 stats->rx_bytes += length;
976
977 return;
978
979 drop:
98c4cae1
CH
980 dev_kfree_skb_irq(skb);
981 update_stats:
982 stats->rx_errors++;
1da177e4 983 stats->rx_dropped++;
1da177e4
LT
984}
985
986/********************************************************************/
987/* Rx path (info frames) */
988/********************************************************************/
989
990static void print_linkstatus(struct net_device *dev, u16 status)
991{
992 char * s;
993
994 if (suppress_linkstatus)
995 return;
996
997 switch (status) {
998 case HERMES_LINKSTATUS_NOT_CONNECTED:
999 s = "Not Connected";
1000 break;
1001 case HERMES_LINKSTATUS_CONNECTED:
1002 s = "Connected";
1003 break;
1004 case HERMES_LINKSTATUS_DISCONNECTED:
1005 s = "Disconnected";
1006 break;
1007 case HERMES_LINKSTATUS_AP_CHANGE:
1008 s = "AP Changed";
1009 break;
1010 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1011 s = "AP Out of Range";
1012 break;
1013 case HERMES_LINKSTATUS_AP_IN_RANGE:
1014 s = "AP In Range";
1015 break;
1016 case HERMES_LINKSTATUS_ASSOC_FAILED:
1017 s = "Association Failed";
1018 break;
1019 default:
1020 s = "UNKNOWN";
1021 }
1022
1023 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1024 dev->name, s, status);
1025}
1026
16739b06
CH
1027/* Search scan results for requested BSSID, join it if found */
1028static void orinoco_join_ap(struct net_device *dev)
1029{
1030 struct orinoco_private *priv = netdev_priv(dev);
1031 struct hermes *hw = &priv->hw;
1032 int err;
1033 unsigned long flags;
1034 struct join_req {
1035 u8 bssid[ETH_ALEN];
d133ae4c 1036 __le16 channel;
16739b06
CH
1037 } __attribute__ ((packed)) req;
1038 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
c89cc225 1039 struct prism2_scan_apinfo *atom = NULL;
16739b06 1040 int offset = 4;
c89cc225 1041 int found = 0;
16739b06
CH
1042 u8 *buf;
1043 u16 len;
1044
1045 /* Allocate buffer for scan results */
1046 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1047 if (! buf)
1048 return;
1049
1050 if (orinoco_lock(priv, &flags) != 0)
f3cb4cc1 1051 goto fail_lock;
16739b06
CH
1052
1053 /* Sanity checks in case user changed something in the meantime */
1054 if (! priv->bssid_fixed)
1055 goto out;
1056
1057 if (strlen(priv->desired_essid) == 0)
1058 goto out;
1059
1060 /* Read scan results from the firmware */
1061 err = hermes_read_ltv(hw, USER_BAP,
1062 HERMES_RID_SCANRESULTSTABLE,
1063 MAX_SCAN_LEN, &len, buf);
1064 if (err) {
1065 printk(KERN_ERR "%s: Cannot read scan results\n",
1066 dev->name);
1067 goto out;
1068 }
1069
1070 len = HERMES_RECLEN_TO_BYTES(len);
1071
1072 /* Go through the scan results looking for the channel of the AP
1073 * we were requested to join */
1074 for (; offset + atom_len <= len; offset += atom_len) {
1075 atom = (struct prism2_scan_apinfo *) (buf + offset);
c89cc225
PR
1076 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1077 found = 1;
1078 break;
1079 }
16739b06
CH
1080 }
1081
c89cc225
PR
1082 if (! found) {
1083 DEBUG(1, "%s: Requested AP not found in scan results\n",
1084 dev->name);
1085 goto out;
1086 }
16739b06 1087
16739b06
CH
1088 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1089 req.channel = atom->channel; /* both are little-endian */
1090 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1091 &req);
1092 if (err)
1093 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1094
1095 out:
16739b06 1096 orinoco_unlock(priv, &flags);
f3cb4cc1
PR
1097
1098 fail_lock:
1099 kfree(buf);
16739b06
CH
1100}
1101
95dd91fb
CH
1102/* Send new BSSID to userspace */
1103static void orinoco_send_wevents(struct net_device *dev)
1104{
1105 struct orinoco_private *priv = netdev_priv(dev);
1106 struct hermes *hw = &priv->hw;
1107 union iwreq_data wrqu;
1108 int err;
1109 unsigned long flags;
1110
1111 if (orinoco_lock(priv, &flags) != 0)
1112 return;
1113
1114 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1115 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1116 if (err != 0)
8aeabc37 1117 goto out;
95dd91fb
CH
1118
1119 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1120
1121 /* Send event to user space */
1122 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
8aeabc37
PR
1123
1124 out:
95dd91fb
CH
1125 orinoco_unlock(priv, &flags);
1126}
1127
1da177e4
LT
1128static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1129{
1130 struct orinoco_private *priv = netdev_priv(dev);
1131 u16 infofid;
1132 struct {
d133ae4c
PR
1133 __le16 len;
1134 __le16 type;
1da177e4
LT
1135 } __attribute__ ((packed)) info;
1136 int len, type;
1137 int err;
1138
1139 /* This is an answer to an INQUIRE command that we did earlier,
1140 * or an information "event" generated by the card
1141 * The controller return to us a pseudo frame containing
1142 * the information in question - Jean II */
1143 infofid = hermes_read_regn(hw, INFOFID);
1144
1145 /* Read the info frame header - don't try too hard */
1146 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1147 infofid, 0);
1148 if (err) {
1149 printk(KERN_ERR "%s: error %d reading info frame. "
1150 "Frame dropped.\n", dev->name, err);
1151 return;
1152 }
1153
1154 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1155 type = le16_to_cpu(info.type);
1156
1157 switch (type) {
1158 case HERMES_INQ_TALLIES: {
1159 struct hermes_tallies_frame tallies;
1160 struct iw_statistics *wstats = &priv->wstats;
1161
1162 if (len > sizeof(tallies)) {
1163 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1164 dev->name, len);
1165 len = sizeof(tallies);
1166 }
1167
84d8a2fb
CH
1168 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1169 infofid, sizeof(info));
1170 if (err)
1171 break;
1da177e4
LT
1172
1173 /* Increment our various counters */
1174 /* wstats->discard.nwid - no wrong BSSID stuff */
1175 wstats->discard.code +=
1176 le16_to_cpu(tallies.RxWEPUndecryptable);
1177 if (len == sizeof(tallies))
1178 wstats->discard.code +=
1179 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1180 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1181 wstats->discard.misc +=
1182 le16_to_cpu(tallies.TxDiscardsWrongSA);
1183 wstats->discard.fragment +=
1184 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1185 wstats->discard.retries +=
1186 le16_to_cpu(tallies.TxRetryLimitExceeded);
1187 /* wstats->miss.beacon - no match */
1188 }
1189 break;
1190 case HERMES_INQ_LINKSTATUS: {
1191 struct hermes_linkstatus linkstatus;
1192 u16 newstatus;
1193 int connected;
1194
8f2abf44
CH
1195 if (priv->iw_mode == IW_MODE_MONITOR)
1196 break;
1197
1da177e4
LT
1198 if (len != sizeof(linkstatus)) {
1199 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1200 dev->name, len);
1201 break;
1202 }
1203
84d8a2fb
CH
1204 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1205 infofid, sizeof(info));
1206 if (err)
1207 break;
1da177e4
LT
1208 newstatus = le16_to_cpu(linkstatus.linkstatus);
1209
95dd91fb
CH
1210 /* Symbol firmware uses "out of range" to signal that
1211 * the hostscan frame can be requested. */
1212 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1213 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1214 priv->has_hostscan && priv->scan_inprogress) {
1215 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1216 break;
1217 }
1218
1da177e4
LT
1219 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1220 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1221 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1222
1223 if (connected)
1224 netif_carrier_on(dev);
7bb7c3a3 1225 else if (!ignore_disconnect)
1da177e4
LT
1226 netif_carrier_off(dev);
1227
95dd91fb
CH
1228 if (newstatus != priv->last_linkstatus) {
1229 priv->last_linkstatus = newstatus;
1da177e4 1230 print_linkstatus(dev, newstatus);
95dd91fb
CH
1231 /* The info frame contains only one word which is the
1232 * status (see hermes.h). The status is pretty boring
1233 * in itself, that's why we export the new BSSID...
1234 * Jean II */
1235 schedule_work(&priv->wevent_work);
1236 }
1237 }
1238 break;
1239 case HERMES_INQ_SCAN:
1240 if (!priv->scan_inprogress && priv->bssid_fixed &&
1241 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1242 schedule_work(&priv->join_work);
1243 break;
1244 }
1245 /* fall through */
1246 case HERMES_INQ_HOSTSCAN:
1247 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1248 /* Result of a scanning. Contains information about
1249 * cells in the vicinity - Jean II */
1250 union iwreq_data wrqu;
1251 unsigned char *buf;
1252
1253 /* Sanity check */
1254 if (len > 4096) {
1255 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1256 dev->name, len);
1257 break;
1258 }
1259
1260 /* We are a strict producer. If the previous scan results
1261 * have not been consumed, we just have to drop this
1262 * frame. We can't remove the previous results ourselves,
1263 * that would be *very* racy... Jean II */
1264 if (priv->scan_result != NULL) {
1265 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1266 break;
1267 }
1da177e4 1268
95dd91fb
CH
1269 /* Allocate buffer for results */
1270 buf = kmalloc(len, GFP_ATOMIC);
1271 if (buf == NULL)
1272 /* No memory, so can't printk()... */
1273 break;
1274
1275 /* Read scan data */
1276 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1277 infofid, sizeof(info));
708218b0
PR
1278 if (err) {
1279 kfree(buf);
95dd91fb 1280 break;
708218b0 1281 }
1da177e4 1282
95dd91fb
CH
1283#ifdef ORINOCO_DEBUG
1284 {
1285 int i;
1286 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1287 for(i = 1; i < (len * 2); i++)
1288 printk(":%02X", buf[i]);
1289 printk("]\n");
1290 }
1291#endif /* ORINOCO_DEBUG */
1292
1293 /* Allow the clients to access the results */
1294 priv->scan_len = len;
1295 priv->scan_result = buf;
1296
1297 /* Send an empty event to user space.
1298 * We don't send the received data on the event because
1299 * it would require us to do complex transcoding, and
1300 * we want to minimise the work done in the irq handler
1301 * Use a request to extract the data - Jean II */
1302 wrqu.data.length = 0;
1303 wrqu.data.flags = 0;
1304 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1da177e4
LT
1305 }
1306 break;
95dd91fb
CH
1307 case HERMES_INQ_SEC_STAT_AGERE:
1308 /* Security status (Agere specific) */
1309 /* Ignore this frame for now */
1310 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1311 break;
1312 /* fall through */
1da177e4
LT
1313 default:
1314 printk(KERN_DEBUG "%s: Unknown information frame received: "
1315 "type 0x%04x, length %d\n", dev->name, type, len);
1316 /* We don't actually do anything about it */
1317 break;
1318 }
1319}
1320
1321static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1322{
1323 if (net_ratelimit())
1324 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1325}
1326
1327/********************************************************************/
1328/* Internal hardware control routines */
1329/********************************************************************/
1330
1331int __orinoco_up(struct net_device *dev)
1332{
1333 struct orinoco_private *priv = netdev_priv(dev);
1334 struct hermes *hw = &priv->hw;
1335 int err;
1336
84d8a2fb
CH
1337 netif_carrier_off(dev); /* just to make sure */
1338
1da177e4
LT
1339 err = __orinoco_program_rids(dev);
1340 if (err) {
1341 printk(KERN_ERR "%s: Error %d configuring card\n",
1342 dev->name, err);
1343 return err;
1344 }
1345
1346 /* Fire things up again */
1347 hermes_set_irqmask(hw, ORINOCO_INTEN);
1348 err = hermes_enable_port(hw, 0);
1349 if (err) {
1350 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1351 dev->name, err);
1352 return err;
1353 }
1354
1355 netif_start_queue(dev);
1356
1357 return 0;
1358}
1359
1360int __orinoco_down(struct net_device *dev)
1361{
1362 struct orinoco_private *priv = netdev_priv(dev);
1363 struct hermes *hw = &priv->hw;
1364 int err;
1365
1366 netif_stop_queue(dev);
1367
1368 if (! priv->hw_unavailable) {
1369 if (! priv->broken_disableport) {
1370 err = hermes_disable_port(hw, 0);
1371 if (err) {
1372 /* Some firmwares (e.g. Intersil 1.3.x) seem
1373 * to have problems disabling the port, oh
1374 * well, too bad. */
1375 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1376 dev->name, err);
1377 priv->broken_disableport = 1;
1378 }
1379 }
1380 hermes_set_irqmask(hw, 0);
1381 hermes_write_regn(hw, EVACK, 0xffff);
1382 }
1383
1384 /* firmware will have to reassociate */
1385 netif_carrier_off(dev);
1386 priv->last_linkstatus = 0xffff;
1387
1388 return 0;
1389}
1390
1391int orinoco_reinit_firmware(struct net_device *dev)
1392{
1393 struct orinoco_private *priv = netdev_priv(dev);
1394 struct hermes *hw = &priv->hw;
1395 int err;
1396
1397 err = hermes_init(hw);
1398 if (err)
1399 return err;
1400
1401 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
b24d4582 1402 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1da177e4
LT
1403 /* Try workaround for old Symbol firmware bug */
1404 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1405 "(old Symbol firmware?). Trying to work around... ",
1406 dev->name);
1407
1408 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1409 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1410 if (err)
1411 printk("failed!\n");
1412 else
1413 printk("ok.\n");
1414 }
1415
1416 return err;
1417}
1418
1419static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1420{
1421 hermes_t *hw = &priv->hw;
1422 int err = 0;
1423
1424 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1425 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1426 priv->ndev->name, priv->bitratemode);
1427 return -EINVAL;
1428 }
1429
1430 switch (priv->firmware_type) {
1431 case FIRMWARE_TYPE_AGERE:
1432 err = hermes_write_wordrec(hw, USER_BAP,
1433 HERMES_RID_CNFTXRATECONTROL,
1434 bitrate_table[priv->bitratemode].agere_txratectrl);
1435 break;
1436 case FIRMWARE_TYPE_INTERSIL:
1437 case FIRMWARE_TYPE_SYMBOL:
1438 err = hermes_write_wordrec(hw, USER_BAP,
1439 HERMES_RID_CNFTXRATECONTROL,
1440 bitrate_table[priv->bitratemode].intersil_txratectrl);
1441 break;
1442 default:
1443 BUG();
1444 }
1445
1446 return err;
1447}
1448
16739b06
CH
1449/* Set fixed AP address */
1450static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1451{
1452 int roaming_flag;
1453 int err = 0;
1454 hermes_t *hw = &priv->hw;
1455
1456 switch (priv->firmware_type) {
1457 case FIRMWARE_TYPE_AGERE:
1458 /* not supported */
1459 break;
1460 case FIRMWARE_TYPE_INTERSIL:
1461 if (priv->bssid_fixed)
1462 roaming_flag = 2;
1463 else
1464 roaming_flag = 1;
1465
1466 err = hermes_write_wordrec(hw, USER_BAP,
1467 HERMES_RID_CNFROAMINGMODE,
1468 roaming_flag);
1469 break;
1470 case FIRMWARE_TYPE_SYMBOL:
1471 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1472 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1473 &priv->desired_bssid);
1474 break;
1475 }
1476 return err;
1477}
1478
1da177e4
LT
1479/* Change the WEP keys and/or the current keys. Can be called
1480 * either from __orinoco_hw_setup_wep() or directly from
1481 * orinoco_ioctl_setiwencode(). In the later case the association
1482 * with the AP is not broken (if the firmware can handle it),
1483 * which is needed for 802.1x implementations. */
1484static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1485{
1486 hermes_t *hw = &priv->hw;
1487 int err = 0;
1488
1489 switch (priv->firmware_type) {
1490 case FIRMWARE_TYPE_AGERE:
1491 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1492 HERMES_RID_CNFWEPKEYS_AGERE,
1493 &priv->keys);
1494 if (err)
1495 return err;
1496 err = hermes_write_wordrec(hw, USER_BAP,
1497 HERMES_RID_CNFTXKEY_AGERE,
1498 priv->tx_key);
1499 if (err)
1500 return err;
1501 break;
1502 case FIRMWARE_TYPE_INTERSIL:
1503 case FIRMWARE_TYPE_SYMBOL:
1504 {
1505 int keylen;
1506 int i;
1507
1508 /* Force uniform key length to work around firmware bugs */
1509 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1510
1511 if (keylen > LARGE_KEY_SIZE) {
1512 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1513 priv->ndev->name, priv->tx_key, keylen);
1514 return -E2BIG;
1515 }
1516
1517 /* Write all 4 keys */
1518 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1519 err = hermes_write_ltv(hw, USER_BAP,
1520 HERMES_RID_CNFDEFAULTKEY0 + i,
1521 HERMES_BYTES_TO_RECLEN(keylen),
1522 priv->keys[i].data);
1523 if (err)
1524 return err;
1525 }
1526
1527 /* Write the index of the key used in transmission */
1528 err = hermes_write_wordrec(hw, USER_BAP,
1529 HERMES_RID_CNFWEPDEFAULTKEYID,
1530 priv->tx_key);
1531 if (err)
1532 return err;
1533 }
1534 break;
1535 }
1536
1537 return 0;
1538}
1539
1540static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1541{
1542 hermes_t *hw = &priv->hw;
1543 int err = 0;
1544 int master_wep_flag;
1545 int auth_flag;
1546
1547 if (priv->wep_on)
1548 __orinoco_hw_setup_wepkeys(priv);
1549
1550 if (priv->wep_restrict)
1551 auth_flag = HERMES_AUTH_SHARED_KEY;
1552 else
1553 auth_flag = HERMES_AUTH_OPEN;
1554
1555 switch (priv->firmware_type) {
1556 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1557 if (priv->wep_on) {
1558 /* Enable the shared-key authentication. */
1559 err = hermes_write_wordrec(hw, USER_BAP,
1560 HERMES_RID_CNFAUTHENTICATION_AGERE,
1561 auth_flag);
1562 }
1563 err = hermes_write_wordrec(hw, USER_BAP,
1564 HERMES_RID_CNFWEPENABLED_AGERE,
1565 priv->wep_on);
1566 if (err)
1567 return err;
1568 break;
1569
1570 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1571 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1572 if (priv->wep_on) {
1573 if (priv->wep_restrict ||
1574 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1575 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1576 HERMES_WEP_EXCL_UNENCRYPTED;
1577 else
1578 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1579
1580 err = hermes_write_wordrec(hw, USER_BAP,
1581 HERMES_RID_CNFAUTHENTICATION,
1582 auth_flag);
1583 if (err)
1584 return err;
1585 } else
1586 master_wep_flag = 0;
1587
1588 if (priv->iw_mode == IW_MODE_MONITOR)
1589 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1590
1591 /* Master WEP setting : on/off */
1592 err = hermes_write_wordrec(hw, USER_BAP,
1593 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1594 master_wep_flag);
1595 if (err)
1596 return err;
1597
1598 break;
1599 }
1600
1601 return 0;
1602}
1603
1604static int __orinoco_program_rids(struct net_device *dev)
1605{
1606 struct orinoco_private *priv = netdev_priv(dev);
1607 hermes_t *hw = &priv->hw;
1608 int err;
1609 struct hermes_idstring idbuf;
1610
1611 /* Set the MAC address */
1612 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1613 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1614 if (err) {
1615 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1616 dev->name, err);
1617 return err;
1618 }
1619
1620 /* Set up the link mode */
1621 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1622 priv->port_type);
1623 if (err) {
1624 printk(KERN_ERR "%s: Error %d setting port type\n",
1625 dev->name, err);
1626 return err;
1627 }
1628 /* Set the channel/frequency */
d51d8b1f
DG
1629 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1630 err = hermes_write_wordrec(hw, USER_BAP,
1631 HERMES_RID_CNFOWNCHANNEL,
1632 priv->channel);
1633 if (err) {
1634 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1635 dev->name, err, priv->channel);
1636 return err;
1637 }
1da177e4
LT
1638 }
1639
1640 if (priv->has_ibss) {
1641 u16 createibss;
1642
1643 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1644 printk(KERN_WARNING "%s: This firmware requires an "
1645 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1646 /* With wvlan_cs, in this case, we would crash.
1647 * hopefully, this driver will behave better...
1648 * Jean II */
1649 createibss = 0;
1650 } else {
1651 createibss = priv->createibss;
1652 }
1653
1654 err = hermes_write_wordrec(hw, USER_BAP,
1655 HERMES_RID_CNFCREATEIBSS,
1656 createibss);
1657 if (err) {
1658 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1659 dev->name, err);
1660 return err;
1661 }
1662 }
1663
16739b06
CH
1664 /* Set the desired BSSID */
1665 err = __orinoco_hw_set_wap(priv);
1666 if (err) {
1667 printk(KERN_ERR "%s: Error %d setting AP address\n",
1668 dev->name, err);
1669 return err;
1670 }
1da177e4
LT
1671 /* Set the desired ESSID */
1672 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1673 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1674 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1675 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1676 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1677 &idbuf);
1678 if (err) {
1679 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1680 dev->name, err);
1681 return err;
1682 }
1683 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1684 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1685 &idbuf);
1686 if (err) {
1687 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1688 dev->name, err);
1689 return err;
1690 }
1691
1692 /* Set the station name */
1693 idbuf.len = cpu_to_le16(strlen(priv->nick));
1694 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1695 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1696 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1697 &idbuf);
1698 if (err) {
1699 printk(KERN_ERR "%s: Error %d setting nickname\n",
1700 dev->name, err);
1701 return err;
1702 }
1703
1704 /* Set AP density */
1705 if (priv->has_sensitivity) {
1706 err = hermes_write_wordrec(hw, USER_BAP,
1707 HERMES_RID_CNFSYSTEMSCALE,
1708 priv->ap_density);
1709 if (err) {
1710 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1711 "Disabling sensitivity control\n",
1712 dev->name, err);
1713
1714 priv->has_sensitivity = 0;
1715 }
1716 }
1717
1718 /* Set RTS threshold */
1719 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1720 priv->rts_thresh);
1721 if (err) {
1722 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1723 dev->name, err);
1724 return err;
1725 }
1726
1727 /* Set fragmentation threshold or MWO robustness */
1728 if (priv->has_mwo)
1729 err = hermes_write_wordrec(hw, USER_BAP,
1730 HERMES_RID_CNFMWOROBUST_AGERE,
1731 priv->mwo_robust);
1732 else
1733 err = hermes_write_wordrec(hw, USER_BAP,
1734 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1735 priv->frag_thresh);
1736 if (err) {
1737 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1738 dev->name, err);
1739 return err;
1740 }
1741
1742 /* Set bitrate */
1743 err = __orinoco_hw_set_bitrate(priv);
1744 if (err) {
1745 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1746 dev->name, err);
1747 return err;
1748 }
1749
1750 /* Set power management */
1751 if (priv->has_pm) {
1752 err = hermes_write_wordrec(hw, USER_BAP,
1753 HERMES_RID_CNFPMENABLED,
1754 priv->pm_on);
1755 if (err) {
1756 printk(KERN_ERR "%s: Error %d setting up PM\n",
1757 dev->name, err);
1758 return err;
1759 }
1760
1761 err = hermes_write_wordrec(hw, USER_BAP,
1762 HERMES_RID_CNFMULTICASTRECEIVE,
1763 priv->pm_mcast);
1764 if (err) {
1765 printk(KERN_ERR "%s: Error %d setting up PM\n",
1766 dev->name, err);
1767 return err;
1768 }
1769 err = hermes_write_wordrec(hw, USER_BAP,
1770 HERMES_RID_CNFMAXSLEEPDURATION,
1771 priv->pm_period);
1772 if (err) {
1773 printk(KERN_ERR "%s: Error %d setting up PM\n",
1774 dev->name, err);
1775 return err;
1776 }
1777 err = hermes_write_wordrec(hw, USER_BAP,
1778 HERMES_RID_CNFPMHOLDOVERDURATION,
1779 priv->pm_timeout);
1780 if (err) {
1781 printk(KERN_ERR "%s: Error %d setting up PM\n",
1782 dev->name, err);
1783 return err;
1784 }
1785 }
1786
1787 /* Set preamble - only for Symbol so far... */
1788 if (priv->has_preamble) {
1789 err = hermes_write_wordrec(hw, USER_BAP,
1790 HERMES_RID_CNFPREAMBLE_SYMBOL,
1791 priv->preamble);
1792 if (err) {
1793 printk(KERN_ERR "%s: Error %d setting preamble\n",
1794 dev->name, err);
1795 return err;
1796 }
1797 }
1798
1799 /* Set up encryption */
1800 if (priv->has_wep) {
1801 err = __orinoco_hw_setup_wep(priv);
1802 if (err) {
1803 printk(KERN_ERR "%s: Error %d activating WEP\n",
1804 dev->name, err);
1805 return err;
1806 }
1807 }
1808
98c4cae1
CH
1809 if (priv->iw_mode == IW_MODE_MONITOR) {
1810 /* Enable monitor mode */
1811 dev->type = ARPHRD_IEEE80211;
1812 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1813 HERMES_TEST_MONITOR, 0, NULL);
1814 } else {
1815 /* Disable monitor mode */
1816 dev->type = ARPHRD_ETHER;
1817 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1818 HERMES_TEST_STOP, 0, NULL);
1819 }
1820 if (err)
1821 return err;
1822
1da177e4
LT
1823 /* Set promiscuity / multicast*/
1824 priv->promiscuous = 0;
1825 priv->mc_count = 0;
1826 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1827
1828 return 0;
1829}
1830
1831/* FIXME: return int? */
1832static void
1833__orinoco_set_multicast_list(struct net_device *dev)
1834{
1835 struct orinoco_private *priv = netdev_priv(dev);
1836 hermes_t *hw = &priv->hw;
1837 int err = 0;
1838 int promisc, mc_count;
1839
1840 /* The Hermes doesn't seem to have an allmulti mode, so we go
1841 * into promiscuous mode and let the upper levels deal. */
1842 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1843 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1844 promisc = 1;
1845 mc_count = 0;
1846 } else {
1847 promisc = 0;
1848 mc_count = dev->mc_count;
1849 }
1850
1851 if (promisc != priv->promiscuous) {
1852 err = hermes_write_wordrec(hw, USER_BAP,
1853 HERMES_RID_CNFPROMISCUOUSMODE,
1854 promisc);
1855 if (err) {
1856 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1857 dev->name, err);
1858 } else
1859 priv->promiscuous = promisc;
1860 }
1861
1862 if (! promisc && (mc_count || priv->mc_count) ) {
1863 struct dev_mc_list *p = dev->mc_list;
1864 struct hermes_multicast mclist;
1865 int i;
1866
1867 for (i = 0; i < mc_count; i++) {
1868 /* paranoia: is list shorter than mc_count? */
1869 BUG_ON(! p);
1870 /* paranoia: bad address size in list? */
1871 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1872
1873 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1874 p = p->next;
1875 }
1876
1877 if (p)
1878 printk(KERN_WARNING "%s: Multicast list is "
1879 "longer than mc_count\n", dev->name);
1880
1881 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1882 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1883 &mclist);
1884 if (err)
1885 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1886 dev->name, err);
1887 else
1888 priv->mc_count = mc_count;
1889 }
1890
1891 /* Since we can set the promiscuous flag when it wasn't asked
1892 for, make sure the net_device knows about it. */
1893 if (priv->promiscuous)
1894 dev->flags |= IFF_PROMISC;
1895 else
1896 dev->flags &= ~IFF_PROMISC;
1897}
1898
1da177e4
LT
1899/* This must be called from user context, without locks held - use
1900 * schedule_work() */
1901static void orinoco_reset(struct net_device *dev)
1902{
1903 struct orinoco_private *priv = netdev_priv(dev);
1904 struct hermes *hw = &priv->hw;
8551cb98 1905 int err;
1da177e4
LT
1906 unsigned long flags;
1907
1908 if (orinoco_lock(priv, &flags) != 0)
1909 /* When the hardware becomes available again, whatever
1910 * detects that is responsible for re-initializing
1911 * it. So no need for anything further */
1912 return;
1913
1914 netif_stop_queue(dev);
1915
1916 /* Shut off interrupts. Depending on what state the hardware
1917 * is in, this might not work, but we'll try anyway */
1918 hermes_set_irqmask(hw, 0);
1919 hermes_write_regn(hw, EVACK, 0xffff);
1920
1921 priv->hw_unavailable++;
1922 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1923 netif_carrier_off(dev);
1924
1925 orinoco_unlock(priv, &flags);
1926
95dd91fb
CH
1927 /* Scanning support: Cleanup of driver struct */
1928 kfree(priv->scan_result);
1929 priv->scan_result = NULL;
1930 priv->scan_inprogress = 0;
1931
8551cb98 1932 if (priv->hard_reset) {
1da177e4 1933 err = (*priv->hard_reset)(priv);
8551cb98
CH
1934 if (err) {
1935 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1936 "performing hard reset\n", dev->name, err);
1937 goto disable;
1938 }
1da177e4
LT
1939 }
1940
1941 err = orinoco_reinit_firmware(dev);
1942 if (err) {
1943 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1944 dev->name, err);
8551cb98 1945 goto disable;
1da177e4
LT
1946 }
1947
1948 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1949
1950 priv->hw_unavailable--;
1951
1952 /* priv->open or priv->hw_unavailable might have changed while
1953 * we dropped the lock */
1954 if (priv->open && (! priv->hw_unavailable)) {
1955 err = __orinoco_up(dev);
1956 if (err) {
1957 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1958 dev->name, err);
1959 } else
1960 dev->trans_start = jiffies;
1961 }
1962
1963 spin_unlock_irq(&priv->lock);
1964
1965 return;
8551cb98
CH
1966 disable:
1967 hermes_set_irqmask(hw, 0);
1968 netif_device_detach(dev);
1969 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1da177e4
LT
1970}
1971
1972/********************************************************************/
1973/* Interrupt handler */
1974/********************************************************************/
1975
1976static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1977{
1978 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1979}
1980
1981static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1982{
1983 /* This seems to happen a fair bit under load, but ignoring it
1984 seems to work fine...*/
1985 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1986 dev->name);
1987}
1988
1989irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1990{
1991 struct net_device *dev = (struct net_device *)dev_id;
1992 struct orinoco_private *priv = netdev_priv(dev);
1993 hermes_t *hw = &priv->hw;
1994 int count = MAX_IRQLOOPS_PER_IRQ;
1995 u16 evstat, events;
1996 /* These are used to detect a runaway interrupt situation */
1997 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1998 * we panic and shut down the hardware */
1999 static int last_irq_jiffy = 0; /* jiffies value the last time
2000 * we were called */
2001 static int loops_this_jiffy = 0;
2002 unsigned long flags;
2003
2004 if (orinoco_lock(priv, &flags) != 0) {
2005 /* If hw is unavailable - we don't know if the irq was
2006 * for us or not */
2007 return IRQ_HANDLED;
2008 }
2009
2010 evstat = hermes_read_regn(hw, EVSTAT);
2011 events = evstat & hw->inten;
2012 if (! events) {
2013 orinoco_unlock(priv, &flags);
2014 return IRQ_NONE;
2015 }
2016
2017 if (jiffies != last_irq_jiffy)
2018 loops_this_jiffy = 0;
2019 last_irq_jiffy = jiffies;
2020
2021 while (events && count--) {
2022 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2023 printk(KERN_WARNING "%s: IRQ handler is looping too "
2024 "much! Resetting.\n", dev->name);
2025 /* Disable interrupts for now */
2026 hermes_set_irqmask(hw, 0);
2027 schedule_work(&priv->reset_work);
2028 break;
2029 }
2030
2031 /* Check the card hasn't been removed */
2032 if (! hermes_present(hw)) {
2033 DEBUG(0, "orinoco_interrupt(): card removed\n");
2034 break;
2035 }
2036
2037 if (events & HERMES_EV_TICK)
2038 __orinoco_ev_tick(dev, hw);
2039 if (events & HERMES_EV_WTERR)
2040 __orinoco_ev_wterr(dev, hw);
2041 if (events & HERMES_EV_INFDROP)
2042 __orinoco_ev_infdrop(dev, hw);
2043 if (events & HERMES_EV_INFO)
2044 __orinoco_ev_info(dev, hw);
2045 if (events & HERMES_EV_RX)
2046 __orinoco_ev_rx(dev, hw);
2047 if (events & HERMES_EV_TXEXC)
2048 __orinoco_ev_txexc(dev, hw);
2049 if (events & HERMES_EV_TX)
2050 __orinoco_ev_tx(dev, hw);
2051 if (events & HERMES_EV_ALLOC)
2052 __orinoco_ev_alloc(dev, hw);
2053
84d8a2fb 2054 hermes_write_regn(hw, EVACK, evstat);
1da177e4
LT
2055
2056 evstat = hermes_read_regn(hw, EVSTAT);
2057 events = evstat & hw->inten;
2058 };
2059
2060 orinoco_unlock(priv, &flags);
2061 return IRQ_HANDLED;
2062}
2063
2064/********************************************************************/
2065/* Initialization */
2066/********************************************************************/
2067
2068struct comp_id {
2069 u16 id, variant, major, minor;
2070} __attribute__ ((packed));
2071
2072static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2073{
2074 if (nic_id->id < 0x8000)
2075 return FIRMWARE_TYPE_AGERE;
2076 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2077 return FIRMWARE_TYPE_SYMBOL;
2078 else
2079 return FIRMWARE_TYPE_INTERSIL;
2080}
2081
2082/* Set priv->firmware type, determine firmware properties */
2083static int determine_firmware(struct net_device *dev)
2084{
2085 struct orinoco_private *priv = netdev_priv(dev);
2086 hermes_t *hw = &priv->hw;
2087 int err;
2088 struct comp_id nic_id, sta_id;
2089 unsigned int firmver;
2090 char tmp[SYMBOL_MAX_VER_LEN+1];
2091
2092 /* Get the hardware version */
2093 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2094 if (err) {
2095 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2096 dev->name, err);
2097 return err;
2098 }
2099
2100 le16_to_cpus(&nic_id.id);
2101 le16_to_cpus(&nic_id.variant);
2102 le16_to_cpus(&nic_id.major);
2103 le16_to_cpus(&nic_id.minor);
2104 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2105 dev->name, nic_id.id, nic_id.variant,
2106 nic_id.major, nic_id.minor);
2107
2108 priv->firmware_type = determine_firmware_type(&nic_id);
2109
2110 /* Get the firmware version */
2111 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2112 if (err) {
2113 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2114 dev->name, err);
2115 return err;
2116 }
2117
2118 le16_to_cpus(&sta_id.id);
2119 le16_to_cpus(&sta_id.variant);
2120 le16_to_cpus(&sta_id.major);
2121 le16_to_cpus(&sta_id.minor);
2122 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2123 dev->name, sta_id.id, sta_id.variant,
2124 sta_id.major, sta_id.minor);
2125
2126 switch (sta_id.id) {
2127 case 0x15:
2128 printk(KERN_ERR "%s: Primary firmware is active\n",
2129 dev->name);
2130 return -ENODEV;
2131 case 0x14b:
2132 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2133 dev->name);
2134 return -ENODEV;
2135 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2136 case 0x21: /* Symbol Spectrum24 Trilogy */
2137 break;
2138 default:
2139 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2140 dev->name);
2141 break;
2142 }
2143
2144 /* Default capabilities */
2145 priv->has_sensitivity = 1;
2146 priv->has_mwo = 0;
2147 priv->has_preamble = 0;
2148 priv->has_port3 = 1;
2149 priv->has_ibss = 1;
2150 priv->has_wep = 0;
2151 priv->has_big_wep = 0;
2152
2153 /* Determine capabilities from the firmware version */
2154 switch (priv->firmware_type) {
2155 case FIRMWARE_TYPE_AGERE:
2156 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2157 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2158 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2159 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2160
2161 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2162
2163 priv->has_ibss = (firmver >= 0x60006);
2164 priv->has_wep = (firmver >= 0x40020);
2165 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2166 Gold cards from the others? */
2167 priv->has_mwo = (firmver >= 0x60000);
2168 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2169 priv->ibss_port = 1;
95dd91fb 2170 priv->has_hostscan = (firmver >= 0x8000a);
98c4cae1 2171 priv->broken_monitor = (firmver >= 0x80000);
1da177e4
LT
2172
2173 /* Tested with Agere firmware :
2174 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2175 * Tested CableTron firmware : 4.32 => Anton */
2176 break;
2177 case FIRMWARE_TYPE_SYMBOL:
2178 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2179 /* Intel MAC : 00:02:B3:* */
2180 /* 3Com MAC : 00:50:DA:* */
2181 memset(tmp, 0, sizeof(tmp));
2182 /* Get the Symbol firmware version */
2183 err = hermes_read_ltv(hw, USER_BAP,
2184 HERMES_RID_SECONDARYVERSION_SYMBOL,
2185 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2186 if (err) {
2187 printk(KERN_WARNING
2188 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2189 dev->name, err);
2190 firmver = 0;
2191 tmp[0] = '\0';
2192 } else {
2193 /* The firmware revision is a string, the format is
2194 * something like : "V2.20-01".
2195 * Quick and dirty parsing... - Jean II
2196 */
2197 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2198 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2199 | (tmp[7] - '0');
2200
2201 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2202 }
2203
2204 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2205 "Symbol %s", tmp);
2206
2207 priv->has_ibss = (firmver >= 0x20000);
2208 priv->has_wep = (firmver >= 0x15012);
2209 priv->has_big_wep = (firmver >= 0x20000);
2210 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2211 (firmver >= 0x29000 && firmver < 0x30000) ||
2212 firmver >= 0x31000;
2213 priv->has_preamble = (firmver >= 0x20000);
2214 priv->ibss_port = 4;
649e59e6
CH
2215 priv->broken_disableport = (firmver == 0x25013) ||
2216 (firmver >= 0x30000 && firmver <= 0x31000);
95dd91fb
CH
2217 priv->has_hostscan = (firmver >= 0x31001) ||
2218 (firmver >= 0x29057 && firmver < 0x30000);
1da177e4
LT
2219 /* Tested with Intel firmware : 0x20015 => Jean II */
2220 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2221 break;
2222 case FIRMWARE_TYPE_INTERSIL:
2223 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2224 * Samsung, Compaq 100/200 and Proxim are slightly
2225 * different and less well tested */
2226 /* D-Link MAC : 00:40:05:* */
2227 /* Addtron MAC : 00:90:D1:* */
2228 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2229 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2230 sta_id.variant);
2231
2232 firmver = ((unsigned long)sta_id.major << 16) |
2233 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2234
2235 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2236 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2237 priv->has_pm = (firmver >= 0x000700);
95dd91fb 2238 priv->has_hostscan = (firmver >= 0x010301);
1da177e4
LT
2239
2240 if (firmver >= 0x000800)
2241 priv->ibss_port = 0;
2242 else {
2243 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2244 "than v0.8.x - several features not supported\n",
2245 dev->name);
2246 priv->ibss_port = 1;
2247 }
2248 break;
2249 }
2250 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2251 priv->fw_name);
2252
2253 return 0;
2254}
2255
2256static int orinoco_init(struct net_device *dev)
2257{
2258 struct orinoco_private *priv = netdev_priv(dev);
2259 hermes_t *hw = &priv->hw;
2260 int err = 0;
2261 struct hermes_idstring nickbuf;
2262 u16 reclen;
2263 int len;
2264
2265 TRACE_ENTER(dev->name);
2266
2267 /* No need to lock, the hw_unavailable flag is already set in
2268 * alloc_orinocodev() */
b453872c 2269 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
1da177e4
LT
2270
2271 /* Initialize the firmware */
b24d4582 2272 err = orinoco_reinit_firmware(dev);
1da177e4
LT
2273 if (err != 0) {
2274 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2275 dev->name, err);
2276 goto out;
2277 }
2278
2279 err = determine_firmware(dev);
2280 if (err != 0) {
2281 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2282 dev->name);
2283 goto out;
2284 }
2285
2286 if (priv->has_port3)
2287 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2288 if (priv->has_ibss)
2289 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2290 dev->name);
2291 if (priv->has_wep) {
2292 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2293 if (priv->has_big_wep)
2294 printk("104-bit key\n");
2295 else
2296 printk("40-bit key\n");
2297 }
2298
2299 /* Get the MAC address */
2300 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2301 ETH_ALEN, NULL, dev->dev_addr);
2302 if (err) {
2303 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2304 dev->name);
2305 goto out;
2306 }
2307
2308 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2309 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2310 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2311 dev->dev_addr[5]);
2312
2313 /* Get the station name */
2314 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2315 sizeof(nickbuf), &reclen, &nickbuf);
2316 if (err) {
2317 printk(KERN_ERR "%s: failed to read station name\n",
2318 dev->name);
2319 goto out;
2320 }
2321 if (nickbuf.len)
2322 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2323 else
2324 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2325 memcpy(priv->nick, &nickbuf.val, len);
2326 priv->nick[len] = '\0';
2327
2328 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2329
2330 /* Get allowed channels */
2331 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2332 &priv->channel_mask);
2333 if (err) {
2334 printk(KERN_ERR "%s: failed to read channel list!\n",
2335 dev->name);
2336 goto out;
2337 }
2338
2339 /* Get initial AP density */
2340 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2341 &priv->ap_density);
2342 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2343 priv->has_sensitivity = 0;
2344 }
2345
2346 /* Get initial RTS threshold */
2347 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2348 &priv->rts_thresh);
2349 if (err) {
2350 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2351 dev->name);
2352 goto out;
2353 }
2354
2355 /* Get initial fragmentation settings */
2356 if (priv->has_mwo)
2357 err = hermes_read_wordrec(hw, USER_BAP,
2358 HERMES_RID_CNFMWOROBUST_AGERE,
2359 &priv->mwo_robust);
2360 else
2361 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2362 &priv->frag_thresh);
2363 if (err) {
2364 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2365 dev->name);
2366 goto out;
2367 }
2368
2369 /* Power management setup */
2370 if (priv->has_pm) {
2371 priv->pm_on = 0;
2372 priv->pm_mcast = 1;
2373 err = hermes_read_wordrec(hw, USER_BAP,
2374 HERMES_RID_CNFMAXSLEEPDURATION,
2375 &priv->pm_period);
2376 if (err) {
2377 printk(KERN_ERR "%s: failed to read power management period!\n",
2378 dev->name);
2379 goto out;
2380 }
2381 err = hermes_read_wordrec(hw, USER_BAP,
2382 HERMES_RID_CNFPMHOLDOVERDURATION,
2383 &priv->pm_timeout);
2384 if (err) {
2385 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2386 dev->name);
2387 goto out;
2388 }
2389 }
2390
2391 /* Preamble setup */
2392 if (priv->has_preamble) {
2393 err = hermes_read_wordrec(hw, USER_BAP,
2394 HERMES_RID_CNFPREAMBLE_SYMBOL,
2395 &priv->preamble);
2396 if (err)
2397 goto out;
2398 }
2399
2400 /* Set up the default configuration */
2401 priv->iw_mode = IW_MODE_INFRA;
2402 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2403 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2404 set_port_type(priv);
d51d8b1f 2405 priv->channel = 0; /* use firmware default */
1da177e4
LT
2406
2407 priv->promiscuous = 0;
2408 priv->wep_on = 0;
2409 priv->tx_key = 0;
2410
1da177e4
LT
2411 /* Make the hardware available, as long as it hasn't been
2412 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2413 spin_lock_irq(&priv->lock);
2414 priv->hw_unavailable--;
2415 spin_unlock_irq(&priv->lock);
2416
2417 printk(KERN_DEBUG "%s: ready\n", dev->name);
2418
2419 out:
2420 TRACE_EXIT(dev->name);
2421 return err;
2422}
2423
2424struct net_device *alloc_orinocodev(int sizeof_card,
2425 int (*hard_reset)(struct orinoco_private *))
2426{
2427 struct net_device *dev;
2428 struct orinoco_private *priv;
2429
2430 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2431 if (! dev)
2432 return NULL;
2433 priv = netdev_priv(dev);
2434 priv->ndev = dev;
2435 if (sizeof_card)
84d8a2fb 2436 priv->card = (void *)((unsigned long)priv
1da177e4
LT
2437 + sizeof(struct orinoco_private));
2438 else
2439 priv->card = NULL;
2440
2441 /* Setup / override net_device fields */
2442 dev->init = orinoco_init;
2443 dev->hard_start_xmit = orinoco_xmit;
2444 dev->tx_timeout = orinoco_tx_timeout;
2445 dev->watchdog_timeo = HZ; /* 1 second timeout */
2446 dev->get_stats = orinoco_get_stats;
1fab2e8b 2447 dev->ethtool_ops = &orinoco_ethtool_ops;
620554e4 2448 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
343c686c
PR
2449#ifdef WIRELESS_SPY
2450 priv->wireless_data.spy_data = &priv->spy_data;
2451 dev->wireless_data = &priv->wireless_data;
2452#endif
1da177e4
LT
2453 dev->change_mtu = orinoco_change_mtu;
2454 dev->set_multicast_list = orinoco_set_multicast_list;
2455 /* we use the default eth_mac_addr for setting the MAC addr */
2456
2457 /* Set up default callbacks */
2458 dev->open = orinoco_open;
2459 dev->stop = orinoco_stop;
2460 priv->hard_reset = hard_reset;
2461
2462 spin_lock_init(&priv->lock);
2463 priv->open = 0;
2464 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2465 * before anything else touches the
2466 * hardware */
2467 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
16739b06 2468 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
95dd91fb 2469 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
1da177e4
LT
2470
2471 netif_carrier_off(dev);
2472 priv->last_linkstatus = 0xffff;
2473
2474 return dev;
2475
2476}
2477
2478void free_orinocodev(struct net_device *dev)
2479{
95dd91fb
CH
2480 struct orinoco_private *priv = netdev_priv(dev);
2481
2482 kfree(priv->scan_result);
1da177e4
LT
2483 free_netdev(dev);
2484}
2485
2486/********************************************************************/
2487/* Wireless extensions */
2488/********************************************************************/
2489
1da177e4
LT
2490static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2491 char buf[IW_ESSID_MAX_SIZE+1])
2492{
2493 hermes_t *hw = &priv->hw;
2494 int err = 0;
2495 struct hermes_idstring essidbuf;
2496 char *p = (char *)(&essidbuf.val);
2497 int len;
2498 unsigned long flags;
2499
2500 if (orinoco_lock(priv, &flags) != 0)
2501 return -EBUSY;
2502
2503 if (strlen(priv->desired_essid) > 0) {
2504 /* We read the desired SSID from the hardware rather
2505 than from priv->desired_essid, just in case the
2506 firmware is allowed to change it on us. I'm not
2507 sure about this */
2508 /* My guess is that the OWNSSID should always be whatever
2509 * we set to the card, whereas CURRENT_SSID is the one that
2510 * may change... - Jean II */
2511 u16 rid;
2512
2513 *active = 1;
2514
2515 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2516 HERMES_RID_CNFDESIREDSSID;
2517
2518 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2519 NULL, &essidbuf);
2520 if (err)
2521 goto fail_unlock;
2522 } else {
2523 *active = 0;
2524
2525 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2526 sizeof(essidbuf), NULL, &essidbuf);
2527 if (err)
2528 goto fail_unlock;
2529 }
2530
2531 len = le16_to_cpu(essidbuf.len);
84d8a2fb 2532 BUG_ON(len > IW_ESSID_MAX_SIZE);
1da177e4
LT
2533
2534 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2535 memcpy(buf, p, len);
2536 buf[len] = '\0';
2537
2538 fail_unlock:
2539 orinoco_unlock(priv, &flags);
2540
2541 return err;
2542}
2543
2544static long orinoco_hw_get_freq(struct orinoco_private *priv)
2545{
2546
2547 hermes_t *hw = &priv->hw;
2548 int err = 0;
2549 u16 channel;
2550 long freq = 0;
2551 unsigned long flags;
2552
2553 if (orinoco_lock(priv, &flags) != 0)
2554 return -EBUSY;
2555
2556 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2557 if (err)
2558 goto out;
2559
2560 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2561 if (channel == 0) {
2562 err = -EBUSY;
2563 goto out;
2564 }
2565
2566 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2567 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2568 priv->ndev->name, channel);
2569 err = -EBUSY;
2570 goto out;
2571
2572 }
2573 freq = channel_frequency[channel-1] * 100000;
2574
2575 out:
2576 orinoco_unlock(priv, &flags);
2577
2578 if (err > 0)
2579 err = -EBUSY;
2580 return err ? err : freq;
2581}
2582
2583static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2584 int *numrates, s32 *rates, int max)
2585{
2586 hermes_t *hw = &priv->hw;
2587 struct hermes_idstring list;
2588 unsigned char *p = (unsigned char *)&list.val;
2589 int err = 0;
2590 int num;
2591 int i;
2592 unsigned long flags;
2593
2594 if (orinoco_lock(priv, &flags) != 0)
2595 return -EBUSY;
2596
2597 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2598 sizeof(list), NULL, &list);
2599 orinoco_unlock(priv, &flags);
2600
2601 if (err)
2602 return err;
2603
2604 num = le16_to_cpu(list.len);
2605 *numrates = num;
2606 num = min(num, max);
2607
2608 for (i = 0; i < num; i++) {
2609 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2610 }
2611
2612 return 0;
2613}
2614
620554e4
CH
2615static int orinoco_ioctl_getname(struct net_device *dev,
2616 struct iw_request_info *info,
2617 char *name,
2618 char *extra)
1da177e4
LT
2619{
2620 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 2621 int numrates;
620554e4
CH
2622 int err;
2623
2624 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2625
2626 if (!err && (numrates > 2))
2627 strcpy(name, "IEEE 802.11b");
2628 else
2629 strcpy(name, "IEEE 802.11-DS");
2630
2631 return 0;
2632}
2633
16739b06
CH
2634static int orinoco_ioctl_setwap(struct net_device *dev,
2635 struct iw_request_info *info,
2636 struct sockaddr *ap_addr,
2637 char *extra)
2638{
2639 struct orinoco_private *priv = netdev_priv(dev);
2640 int err = -EINPROGRESS; /* Call commit handler */
1da177e4 2641 unsigned long flags;
16739b06
CH
2642 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2643 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1da177e4 2644
16739b06
CH
2645 if (orinoco_lock(priv, &flags) != 0)
2646 return -EBUSY;
2647
2648 /* Enable automatic roaming - no sanity checks are needed */
2649 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2650 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2651 priv->bssid_fixed = 0;
2652 memset(priv->desired_bssid, 0, ETH_ALEN);
2653
2654 /* "off" means keep existing connection */
2655 if (ap_addr->sa_data[0] == 0) {
2656 __orinoco_hw_set_wap(priv);
2657 err = 0;
2658 }
2659 goto out;
2660 }
2661
2662 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2663 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2664 "support manual roaming\n",
2665 dev->name);
2666 err = -EOPNOTSUPP;
2667 goto out;
2668 }
2669
2670 if (priv->iw_mode != IW_MODE_INFRA) {
2671 printk(KERN_WARNING "%s: Manual roaming supported only in "
2672 "managed mode\n", dev->name);
2673 err = -EOPNOTSUPP;
2674 goto out;
2675 }
2676
2677 /* Intersil firmware hangs without Desired ESSID */
2678 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2679 strlen(priv->desired_essid) == 0) {
2680 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2681 "manual roaming\n", dev->name);
2682 err = -EOPNOTSUPP;
2683 goto out;
2684 }
2685
2686 /* Finally, enable manual roaming */
2687 priv->bssid_fixed = 1;
2688 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2689
2690 out:
2691 orinoco_unlock(priv, &flags);
2692 return err;
2693}
2694
620554e4
CH
2695static int orinoco_ioctl_getwap(struct net_device *dev,
2696 struct iw_request_info *info,
2697 struct sockaddr *ap_addr,
2698 char *extra)
2699{
2700 struct orinoco_private *priv = netdev_priv(dev);
2701
2702 hermes_t *hw = &priv->hw;
2703 int err = 0;
1da177e4
LT
2704 unsigned long flags;
2705
620554e4
CH
2706 if (orinoco_lock(priv, &flags) != 0)
2707 return -EBUSY;
1da177e4 2708
620554e4
CH
2709 ap_addr->sa_family = ARPHRD_ETHER;
2710 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2711 ETH_ALEN, NULL, ap_addr->sa_data);
1da177e4 2712
620554e4
CH
2713 orinoco_unlock(priv, &flags);
2714
2715 return err;
2716}
1da177e4 2717
620554e4
CH
2718static int orinoco_ioctl_setmode(struct net_device *dev,
2719 struct iw_request_info *info,
2720 u32 *mode,
2721 char *extra)
2722{
2723 struct orinoco_private *priv = netdev_priv(dev);
2724 int err = -EINPROGRESS; /* Call commit handler */
2725 unsigned long flags;
1da177e4 2726
620554e4
CH
2727 if (priv->iw_mode == *mode)
2728 return 0;
1da177e4
LT
2729
2730 if (orinoco_lock(priv, &flags) != 0)
2731 return -EBUSY;
2732
620554e4
CH
2733 switch (*mode) {
2734 case IW_MODE_ADHOC:
2735 if (!priv->has_ibss && !priv->has_port3)
2736 err = -EOPNOTSUPP;
2737 break;
2738
2739 case IW_MODE_INFRA:
2740 break;
2741
98c4cae1
CH
2742 case IW_MODE_MONITOR:
2743 if (priv->broken_monitor && !force_monitor) {
2744 printk(KERN_WARNING "%s: Monitor mode support is "
2745 "buggy in this firmware, not enabling\n",
2746 dev->name);
2747 err = -EOPNOTSUPP;
2748 }
2749 break;
2750
620554e4
CH
2751 default:
2752 err = -EOPNOTSUPP;
2753 break;
2754 }
2755
2756 if (err == -EINPROGRESS) {
2757 priv->iw_mode = *mode;
2758 set_port_type(priv);
2759 }
2760
1da177e4
LT
2761 orinoco_unlock(priv, &flags);
2762
620554e4
CH
2763 return err;
2764}
1da177e4 2765
620554e4
CH
2766static int orinoco_ioctl_getmode(struct net_device *dev,
2767 struct iw_request_info *info,
2768 u32 *mode,
2769 char *extra)
2770{
2771 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 2772
620554e4
CH
2773 *mode = priv->iw_mode;
2774 return 0;
2775}
1da177e4 2776
620554e4
CH
2777static int orinoco_ioctl_getiwrange(struct net_device *dev,
2778 struct iw_request_info *info,
2779 struct iw_point *rrq,
2780 char *extra)
2781{
2782 struct orinoco_private *priv = netdev_priv(dev);
2783 int err = 0;
2784 struct iw_range *range = (struct iw_range *) extra;
2785 int numrates;
2786 int i, k;
2787
2788 TRACE_ENTER(dev->name);
2789
2790 rrq->length = sizeof(struct iw_range);
2791 memset(range, 0, sizeof(struct iw_range));
2792
2793 range->we_version_compiled = WIRELESS_EXT;
2794 range->we_version_source = 14;
1da177e4
LT
2795
2796 /* Set available channels/frequencies */
620554e4 2797 range->num_channels = NUM_CHANNELS;
1da177e4
LT
2798 k = 0;
2799 for (i = 0; i < NUM_CHANNELS; i++) {
2800 if (priv->channel_mask & (1 << i)) {
620554e4
CH
2801 range->freq[k].i = i + 1;
2802 range->freq[k].m = channel_frequency[i] * 100000;
2803 range->freq[k].e = 1;
1da177e4
LT
2804 k++;
2805 }
2806
2807 if (k >= IW_MAX_FREQUENCIES)
2808 break;
2809 }
620554e4
CH
2810 range->num_frequency = k;
2811 range->sensitivity = 3;
1da177e4 2812
620554e4
CH
2813 if (priv->has_wep) {
2814 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2815 range->encoding_size[0] = SMALL_KEY_SIZE;
2816 range->num_encoding_sizes = 1;
1da177e4 2817
620554e4
CH
2818 if (priv->has_big_wep) {
2819 range->encoding_size[1] = LARGE_KEY_SIZE;
2820 range->num_encoding_sizes = 2;
2821 }
2822 }
1da177e4 2823
343c686c 2824 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
1da177e4 2825 /* Quality stats meaningless in ad-hoc mode */
1da177e4 2826 } else {
620554e4
CH
2827 range->max_qual.qual = 0x8b - 0x2f;
2828 range->max_qual.level = 0x2f - 0x95 - 1;
2829 range->max_qual.noise = 0x2f - 0x95 - 1;
1da177e4 2830 /* Need to get better values */
620554e4
CH
2831 range->avg_qual.qual = 0x24;
2832 range->avg_qual.level = 0xC2;
2833 range->avg_qual.noise = 0x9E;
1da177e4
LT
2834 }
2835
2836 err = orinoco_hw_get_bitratelist(priv, &numrates,
620554e4 2837 range->bitrate, IW_MAX_BITRATES);
1da177e4
LT
2838 if (err)
2839 return err;
620554e4
CH
2840 range->num_bitrates = numrates;
2841
1da177e4
LT
2842 /* Set an indication of the max TCP throughput in bit/s that we can
2843 * expect using this interface. May be use for QoS stuff...
2844 * Jean II */
620554e4
CH
2845 if (numrates > 2)
2846 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
1da177e4 2847 else
620554e4
CH
2848 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2849
2850 range->min_rts = 0;
2851 range->max_rts = 2347;
2852 range->min_frag = 256;
2853 range->max_frag = 2346;
2854
2855 range->min_pmp = 0;
2856 range->max_pmp = 65535000;
2857 range->min_pmt = 0;
2858 range->max_pmt = 65535 * 1000; /* ??? */
2859 range->pmp_flags = IW_POWER_PERIOD;
2860 range->pmt_flags = IW_POWER_TIMEOUT;
2861 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2862
2863 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2864 range->retry_flags = IW_RETRY_LIMIT;
2865 range->r_time_flags = IW_RETRY_LIFETIME;
2866 range->min_retry = 0;
2867 range->max_retry = 65535; /* ??? */
2868 range->min_r_time = 0;
2869 range->max_r_time = 65535 * 1000; /* ??? */
1da177e4 2870
343c686c
PR
2871 /* Event capability (kernel) */
2872 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2873 /* Event capability (driver) */
2874 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2875 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2876 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2877 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2878
1da177e4
LT
2879 TRACE_EXIT(dev->name);
2880
2881 return 0;
2882}
2883
620554e4
CH
2884static int orinoco_ioctl_setiwencode(struct net_device *dev,
2885 struct iw_request_info *info,
2886 struct iw_point *erq,
2887 char *keybuf)
1da177e4
LT
2888{
2889 struct orinoco_private *priv = netdev_priv(dev);
2890 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2891 int setindex = priv->tx_key;
2892 int enable = priv->wep_on;
2893 int restricted = priv->wep_restrict;
2894 u16 xlen = 0;
620554e4 2895 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
2896 unsigned long flags;
2897
2898 if (! priv->has_wep)
2899 return -EOPNOTSUPP;
2900
2901 if (erq->pointer) {
2902 /* We actually have a key to set - check its length */
2903 if (erq->length > LARGE_KEY_SIZE)
2904 return -E2BIG;
2905
2906 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2907 return -E2BIG;
1da177e4
LT
2908 }
2909
2910 if (orinoco_lock(priv, &flags) != 0)
2911 return -EBUSY;
2912
2913 if (erq->pointer) {
2914 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2915 index = priv->tx_key;
2916
2917 /* Adjust key length to a supported value */
2918 if (erq->length > SMALL_KEY_SIZE) {
2919 xlen = LARGE_KEY_SIZE;
2920 } else if (erq->length > 0) {
2921 xlen = SMALL_KEY_SIZE;
2922 } else
2923 xlen = 0;
2924
2925 /* Switch on WEP if off */
2926 if ((!enable) && (xlen > 0)) {
2927 setindex = index;
2928 enable = 1;
2929 }
2930 } else {
2931 /* Important note : if the user do "iwconfig eth0 enc off",
2932 * we will arrive there with an index of -1. This is valid
2933 * but need to be taken care off... Jean II */
2934 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2935 if((index != -1) || (erq->flags == 0)) {
2936 err = -EINVAL;
2937 goto out;
2938 }
2939 } else {
2940 /* Set the index : Check that the key is valid */
2941 if(priv->keys[index].len == 0) {
2942 err = -EINVAL;
2943 goto out;
2944 }
2945 setindex = index;
2946 }
2947 }
2948
2949 if (erq->flags & IW_ENCODE_DISABLED)
2950 enable = 0;
2951 if (erq->flags & IW_ENCODE_OPEN)
2952 restricted = 0;
2953 if (erq->flags & IW_ENCODE_RESTRICTED)
2954 restricted = 1;
2955
2956 if (erq->pointer) {
2957 priv->keys[index].len = cpu_to_le16(xlen);
2958 memset(priv->keys[index].data, 0,
2959 sizeof(priv->keys[index].data));
2960 memcpy(priv->keys[index].data, keybuf, erq->length);
2961 }
2962 priv->tx_key = setindex;
2963
2964 /* Try fast key change if connected and only keys are changed */
2965 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2966 netif_carrier_ok(dev)) {
2967 err = __orinoco_hw_setup_wepkeys(priv);
2968 /* No need to commit if successful */
2969 goto out;
2970 }
2971
2972 priv->wep_on = enable;
2973 priv->wep_restrict = restricted;
2974
2975 out:
2976 orinoco_unlock(priv, &flags);
2977
2978 return err;
2979}
2980
620554e4
CH
2981static int orinoco_ioctl_getiwencode(struct net_device *dev,
2982 struct iw_request_info *info,
2983 struct iw_point *erq,
2984 char *keybuf)
1da177e4
LT
2985{
2986 struct orinoco_private *priv = netdev_priv(dev);
2987 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2988 u16 xlen = 0;
1da177e4
LT
2989 unsigned long flags;
2990
2991 if (! priv->has_wep)
2992 return -EOPNOTSUPP;
2993
2994 if (orinoco_lock(priv, &flags) != 0)
2995 return -EBUSY;
2996
2997 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2998 index = priv->tx_key;
2999
3000 erq->flags = 0;
3001 if (! priv->wep_on)
3002 erq->flags |= IW_ENCODE_DISABLED;
3003 erq->flags |= index + 1;
3004
3005 if (priv->wep_restrict)
3006 erq->flags |= IW_ENCODE_RESTRICTED;
3007 else
3008 erq->flags |= IW_ENCODE_OPEN;
3009
3010 xlen = le16_to_cpu(priv->keys[index].len);
3011
3012 erq->length = xlen;
3013
3014 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3015
3016 orinoco_unlock(priv, &flags);
1da177e4
LT
3017 return 0;
3018}
3019
620554e4
CH
3020static int orinoco_ioctl_setessid(struct net_device *dev,
3021 struct iw_request_info *info,
3022 struct iw_point *erq,
3023 char *essidbuf)
1da177e4
LT
3024{
3025 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3026 unsigned long flags;
3027
3028 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3029 * anyway... - Jean II */
3030
620554e4
CH
3031 /* Hum... Should not use Wireless Extension constant (may change),
3032 * should use our own... - Jean II */
3033 if (erq->length > IW_ESSID_MAX_SIZE)
3034 return -E2BIG;
1da177e4
LT
3035
3036 if (orinoco_lock(priv, &flags) != 0)
3037 return -EBUSY;
3038
620554e4
CH
3039 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3040 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3041
3042 /* If not ANY, get the new ESSID */
3043 if (erq->flags) {
3044 memcpy(priv->desired_essid, essidbuf, erq->length);
3045 }
1da177e4
LT
3046
3047 orinoco_unlock(priv, &flags);
3048
620554e4 3049 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3050}
3051
620554e4
CH
3052static int orinoco_ioctl_getessid(struct net_device *dev,
3053 struct iw_request_info *info,
3054 struct iw_point *erq,
3055 char *essidbuf)
1da177e4
LT
3056{
3057 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3058 int active;
3059 int err = 0;
3060 unsigned long flags;
3061
3062 TRACE_ENTER(dev->name);
3063
3064 if (netif_running(dev)) {
3065 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3066 if (err)
3067 return err;
3068 } else {
3069 if (orinoco_lock(priv, &flags) != 0)
3070 return -EBUSY;
620554e4 3071 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
1da177e4
LT
3072 orinoco_unlock(priv, &flags);
3073 }
3074
3075 erq->flags = 1;
3076 erq->length = strlen(essidbuf) + 1;
1da177e4
LT
3077
3078 TRACE_EXIT(dev->name);
3079
3080 return 0;
3081}
3082
620554e4
CH
3083static int orinoco_ioctl_setnick(struct net_device *dev,
3084 struct iw_request_info *info,
3085 struct iw_point *nrq,
3086 char *nickbuf)
1da177e4
LT
3087{
3088 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3089 unsigned long flags;
3090
3091 if (nrq->length > IW_ESSID_MAX_SIZE)
3092 return -E2BIG;
3093
1da177e4
LT
3094 if (orinoco_lock(priv, &flags) != 0)
3095 return -EBUSY;
3096
620554e4
CH
3097 memset(priv->nick, 0, sizeof(priv->nick));
3098 memcpy(priv->nick, nickbuf, nrq->length);
1da177e4
LT
3099
3100 orinoco_unlock(priv, &flags);
3101
620554e4 3102 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3103}
3104
620554e4
CH
3105static int orinoco_ioctl_getnick(struct net_device *dev,
3106 struct iw_request_info *info,
3107 struct iw_point *nrq,
3108 char *nickbuf)
1da177e4
LT
3109{
3110 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3111 unsigned long flags;
3112
3113 if (orinoco_lock(priv, &flags) != 0)
3114 return -EBUSY;
3115
3116 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3117 orinoco_unlock(priv, &flags);
3118
3119 nrq->length = strlen(nickbuf)+1;
3120
1da177e4
LT
3121 return 0;
3122}
3123
620554e4
CH
3124static int orinoco_ioctl_setfreq(struct net_device *dev,
3125 struct iw_request_info *info,
3126 struct iw_freq *frq,
3127 char *extra)
1da177e4
LT
3128{
3129 struct orinoco_private *priv = netdev_priv(dev);
3130 int chan = -1;
3131 unsigned long flags;
620554e4 3132 int err = -EINPROGRESS; /* Call commit handler */
1da177e4 3133
98c4cae1
CH
3134 /* In infrastructure mode the AP sets the channel */
3135 if (priv->iw_mode == IW_MODE_INFRA)
3136 return -EBUSY;
1da177e4
LT
3137
3138 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3139 /* Setting by channel number */
3140 chan = frq->m;
3141 } else {
3142 /* Setting by frequency - search the table */
3143 int mult = 1;
3144 int i;
3145
3146 for (i = 0; i < (6 - frq->e); i++)
3147 mult *= 10;
3148
3149 for (i = 0; i < NUM_CHANNELS; i++)
3150 if (frq->m == (channel_frequency[i] * mult))
3151 chan = i+1;
3152 }
3153
3154 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3155 ! (priv->channel_mask & (1 << (chan-1)) ) )
3156 return -EINVAL;
3157
3158 if (orinoco_lock(priv, &flags) != 0)
3159 return -EBUSY;
98c4cae1 3160
1da177e4 3161 priv->channel = chan;
98c4cae1
CH
3162 if (priv->iw_mode == IW_MODE_MONITOR) {
3163 /* Fast channel change - no commit if successful */
3164 hermes_t *hw = &priv->hw;
3165 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3166 HERMES_TEST_SET_CHANNEL,
3167 chan, NULL);
3168 }
1da177e4
LT
3169 orinoco_unlock(priv, &flags);
3170
620554e4
CH
3171 return err;
3172}
3173
3174static int orinoco_ioctl_getfreq(struct net_device *dev,
3175 struct iw_request_info *info,
3176 struct iw_freq *frq,
3177 char *extra)
3178{
3179 struct orinoco_private *priv = netdev_priv(dev);
3180 int tmp;
3181
3182 /* Locking done in there */
3183 tmp = orinoco_hw_get_freq(priv);
3184 if (tmp < 0) {
3185 return tmp;
3186 }
3187
3188 frq->m = tmp;
3189 frq->e = 1;
3190
1da177e4
LT
3191 return 0;
3192}
3193
620554e4
CH
3194static int orinoco_ioctl_getsens(struct net_device *dev,
3195 struct iw_request_info *info,
3196 struct iw_param *srq,
3197 char *extra)
1da177e4
LT
3198{
3199 struct orinoco_private *priv = netdev_priv(dev);
3200 hermes_t *hw = &priv->hw;
3201 u16 val;
3202 int err;
3203 unsigned long flags;
3204
3205 if (!priv->has_sensitivity)
3206 return -EOPNOTSUPP;
3207
3208 if (orinoco_lock(priv, &flags) != 0)
3209 return -EBUSY;
3210 err = hermes_read_wordrec(hw, USER_BAP,
3211 HERMES_RID_CNFSYSTEMSCALE, &val);
3212 orinoco_unlock(priv, &flags);
3213
3214 if (err)
3215 return err;
3216
3217 srq->value = val;
3218 srq->fixed = 0; /* auto */
3219
3220 return 0;
3221}
3222
620554e4
CH
3223static int orinoco_ioctl_setsens(struct net_device *dev,
3224 struct iw_request_info *info,
3225 struct iw_param *srq,
3226 char *extra)
1da177e4
LT
3227{
3228 struct orinoco_private *priv = netdev_priv(dev);
3229 int val = srq->value;
3230 unsigned long flags;
3231
3232 if (!priv->has_sensitivity)
3233 return -EOPNOTSUPP;
3234
3235 if ((val < 1) || (val > 3))
3236 return -EINVAL;
3237
3238 if (orinoco_lock(priv, &flags) != 0)
3239 return -EBUSY;
3240 priv->ap_density = val;
3241 orinoco_unlock(priv, &flags);
3242
620554e4 3243 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3244}
3245
620554e4
CH
3246static int orinoco_ioctl_setrts(struct net_device *dev,
3247 struct iw_request_info *info,
3248 struct iw_param *rrq,
3249 char *extra)
1da177e4
LT
3250{
3251 struct orinoco_private *priv = netdev_priv(dev);
3252 int val = rrq->value;
3253 unsigned long flags;
3254
3255 if (rrq->disabled)
3256 val = 2347;
3257
3258 if ( (val < 0) || (val > 2347) )
3259 return -EINVAL;
3260
3261 if (orinoco_lock(priv, &flags) != 0)
3262 return -EBUSY;
3263
3264 priv->rts_thresh = val;
3265 orinoco_unlock(priv, &flags);
3266
620554e4
CH
3267 return -EINPROGRESS; /* Call commit handler */
3268}
3269
3270static int orinoco_ioctl_getrts(struct net_device *dev,
3271 struct iw_request_info *info,
3272 struct iw_param *rrq,
3273 char *extra)
3274{
3275 struct orinoco_private *priv = netdev_priv(dev);
3276
3277 rrq->value = priv->rts_thresh;
3278 rrq->disabled = (rrq->value == 2347);
3279 rrq->fixed = 1;
3280
1da177e4
LT
3281 return 0;
3282}
3283
620554e4
CH
3284static int orinoco_ioctl_setfrag(struct net_device *dev,
3285 struct iw_request_info *info,
3286 struct iw_param *frq,
3287 char *extra)
1da177e4
LT
3288{
3289 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3290 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3291 unsigned long flags;
3292
3293 if (orinoco_lock(priv, &flags) != 0)
3294 return -EBUSY;
3295
3296 if (priv->has_mwo) {
3297 if (frq->disabled)
3298 priv->mwo_robust = 0;
3299 else {
3300 if (frq->fixed)
3301 printk(KERN_WARNING "%s: Fixed fragmentation is "
3302 "not supported on this firmware. "
3303 "Using MWO robust instead.\n", dev->name);
3304 priv->mwo_robust = 1;
3305 }
3306 } else {
3307 if (frq->disabled)
3308 priv->frag_thresh = 2346;
3309 else {
3310 if ( (frq->value < 256) || (frq->value > 2346) )
3311 err = -EINVAL;
3312 else
3313 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3314 }
3315 }
3316
3317 orinoco_unlock(priv, &flags);
3318
3319 return err;
3320}
3321
620554e4
CH
3322static int orinoco_ioctl_getfrag(struct net_device *dev,
3323 struct iw_request_info *info,
3324 struct iw_param *frq,
3325 char *extra)
1da177e4
LT
3326{
3327 struct orinoco_private *priv = netdev_priv(dev);
3328 hermes_t *hw = &priv->hw;
620554e4 3329 int err;
1da177e4
LT
3330 u16 val;
3331 unsigned long flags;
3332
3333 if (orinoco_lock(priv, &flags) != 0)
3334 return -EBUSY;
3335
3336 if (priv->has_mwo) {
3337 err = hermes_read_wordrec(hw, USER_BAP,
3338 HERMES_RID_CNFMWOROBUST_AGERE,
3339 &val);
3340 if (err)
3341 val = 0;
3342
3343 frq->value = val ? 2347 : 0;
3344 frq->disabled = ! val;
3345 frq->fixed = 0;
3346 } else {
3347 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3348 &val);
3349 if (err)
3350 val = 0;
3351
3352 frq->value = val;
3353 frq->disabled = (val >= 2346);
3354 frq->fixed = 1;
3355 }
3356
3357 orinoco_unlock(priv, &flags);
3358
3359 return err;
3360}
3361
620554e4
CH
3362static int orinoco_ioctl_setrate(struct net_device *dev,
3363 struct iw_request_info *info,
3364 struct iw_param *rrq,
3365 char *extra)
1da177e4
LT
3366{
3367 struct orinoco_private *priv = netdev_priv(dev);
1da177e4
LT
3368 int ratemode = -1;
3369 int bitrate; /* 100s of kilobits */
3370 int i;
3371 unsigned long flags;
3372
3373 /* As the user space doesn't know our highest rate, it uses -1
3374 * to ask us to set the highest rate. Test it using "iwconfig
3375 * ethX rate auto" - Jean II */
3376 if (rrq->value == -1)
3377 bitrate = 110;
3378 else {
3379 if (rrq->value % 100000)
3380 return -EINVAL;
3381 bitrate = rrq->value / 100000;
3382 }
3383
3384 if ( (bitrate != 10) && (bitrate != 20) &&
3385 (bitrate != 55) && (bitrate != 110) )
3386 return -EINVAL;
3387
3388 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3389 if ( (bitrate_table[i].bitrate == bitrate) &&
3390 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3391 ratemode = i;
3392 break;
3393 }
3394
3395 if (ratemode == -1)
3396 return -EINVAL;
3397
3398 if (orinoco_lock(priv, &flags) != 0)
3399 return -EBUSY;
3400 priv->bitratemode = ratemode;
3401 orinoco_unlock(priv, &flags);
3402
620554e4 3403 return -EINPROGRESS;
1da177e4
LT
3404}
3405
620554e4
CH
3406static int orinoco_ioctl_getrate(struct net_device *dev,
3407 struct iw_request_info *info,
3408 struct iw_param *rrq,
3409 char *extra)
1da177e4
LT
3410{
3411 struct orinoco_private *priv = netdev_priv(dev);
3412 hermes_t *hw = &priv->hw;
3413 int err = 0;
3414 int ratemode;
3415 int i;
3416 u16 val;
3417 unsigned long flags;
3418
3419 if (orinoco_lock(priv, &flags) != 0)
3420 return -EBUSY;
3421
3422 ratemode = priv->bitratemode;
3423
3424 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3425
3426 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3427 rrq->fixed = ! bitrate_table[ratemode].automatic;
3428 rrq->disabled = 0;
3429
3430 /* If the interface is running we try to find more about the
3431 current mode */
3432 if (netif_running(dev)) {
3433 err = hermes_read_wordrec(hw, USER_BAP,
3434 HERMES_RID_CURRENTTXRATE, &val);
3435 if (err)
3436 goto out;
3437
3438 switch (priv->firmware_type) {
3439 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3440 /* Note : in Lucent firmware, the return value of
3441 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3442 * and therefore is totally different from the
3443 * encoding of HERMES_RID_CNFTXRATECONTROL.
3444 * Don't forget that 6Mb/s is really 5.5Mb/s */
3445 if (val == 6)
3446 rrq->value = 5500000;
3447 else
3448 rrq->value = val * 1000000;
3449 break;
3450 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3451 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3452 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3453 if (bitrate_table[i].intersil_txratectrl == val) {
3454 ratemode = i;
3455 break;
3456 }
3457 if (i >= BITRATE_TABLE_SIZE)
3458 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3459 dev->name, val);
3460
3461 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3462 break;
3463 default:
3464 BUG();
3465 }
3466 }
3467
3468 out:
3469 orinoco_unlock(priv, &flags);
3470
3471 return err;
3472}
3473
620554e4
CH
3474static int orinoco_ioctl_setpower(struct net_device *dev,
3475 struct iw_request_info *info,
3476 struct iw_param *prq,
3477 char *extra)
1da177e4
LT
3478{
3479 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3480 int err = -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3481 unsigned long flags;
3482
3483 if (orinoco_lock(priv, &flags) != 0)
3484 return -EBUSY;
3485
3486 if (prq->disabled) {
3487 priv->pm_on = 0;
3488 } else {
3489 switch (prq->flags & IW_POWER_MODE) {
3490 case IW_POWER_UNICAST_R:
3491 priv->pm_mcast = 0;
3492 priv->pm_on = 1;
3493 break;
3494 case IW_POWER_ALL_R:
3495 priv->pm_mcast = 1;
3496 priv->pm_on = 1;
3497 break;
3498 case IW_POWER_ON:
3499 /* No flags : but we may have a value - Jean II */
3500 break;
3501 default:
3502 err = -EINVAL;
3503 }
3504 if (err)
3505 goto out;
3506
3507 if (prq->flags & IW_POWER_TIMEOUT) {
3508 priv->pm_on = 1;
3509 priv->pm_timeout = prq->value / 1000;
3510 }
3511 if (prq->flags & IW_POWER_PERIOD) {
3512 priv->pm_on = 1;
3513 priv->pm_period = prq->value / 1000;
3514 }
3515 /* It's valid to not have a value if we are just toggling
3516 * the flags... Jean II */
3517 if(!priv->pm_on) {
3518 err = -EINVAL;
3519 goto out;
3520 }
3521 }
3522
3523 out:
3524 orinoco_unlock(priv, &flags);
3525
3526 return err;
3527}
3528
620554e4
CH
3529static int orinoco_ioctl_getpower(struct net_device *dev,
3530 struct iw_request_info *info,
3531 struct iw_param *prq,
3532 char *extra)
1da177e4
LT
3533{
3534 struct orinoco_private *priv = netdev_priv(dev);
3535 hermes_t *hw = &priv->hw;
3536 int err = 0;
3537 u16 enable, period, timeout, mcast;
3538 unsigned long flags;
3539
3540 if (orinoco_lock(priv, &flags) != 0)
3541 return -EBUSY;
3542
3543 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3544 if (err)
3545 goto out;
3546
3547 err = hermes_read_wordrec(hw, USER_BAP,
3548 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3549 if (err)
3550 goto out;
3551
3552 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3553 if (err)
3554 goto out;
3555
3556 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3557 if (err)
3558 goto out;
3559
3560 prq->disabled = !enable;
3561 /* Note : by default, display the period */
3562 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3563 prq->flags = IW_POWER_TIMEOUT;
3564 prq->value = timeout * 1000;
3565 } else {
3566 prq->flags = IW_POWER_PERIOD;
3567 prq->value = period * 1000;
3568 }
3569 if (mcast)
3570 prq->flags |= IW_POWER_ALL_R;
3571 else
3572 prq->flags |= IW_POWER_UNICAST_R;
3573
3574 out:
3575 orinoco_unlock(priv, &flags);
3576
3577 return err;
3578}
3579
620554e4
CH
3580static int orinoco_ioctl_getretry(struct net_device *dev,
3581 struct iw_request_info *info,
3582 struct iw_param *rrq,
3583 char *extra)
1da177e4
LT
3584{
3585 struct orinoco_private *priv = netdev_priv(dev);
3586 hermes_t *hw = &priv->hw;
3587 int err = 0;
3588 u16 short_limit, long_limit, lifetime;
3589 unsigned long flags;
3590
3591 if (orinoco_lock(priv, &flags) != 0)
3592 return -EBUSY;
3593
3594 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3595 &short_limit);
3596 if (err)
3597 goto out;
3598
3599 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3600 &long_limit);
3601 if (err)
3602 goto out;
3603
3604 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3605 &lifetime);
3606 if (err)
3607 goto out;
3608
3609 rrq->disabled = 0; /* Can't be disabled */
3610
3611 /* Note : by default, display the retry number */
3612 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3613 rrq->flags = IW_RETRY_LIFETIME;
3614 rrq->value = lifetime * 1000; /* ??? */
3615 } else {
3616 /* By default, display the min number */
3617 if ((rrq->flags & IW_RETRY_MAX)) {
3618 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3619 rrq->value = long_limit;
3620 } else {
3621 rrq->flags = IW_RETRY_LIMIT;
3622 rrq->value = short_limit;
3623 if(short_limit != long_limit)
3624 rrq->flags |= IW_RETRY_MIN;
3625 }
3626 }
3627
3628 out:
3629 orinoco_unlock(priv, &flags);
3630
3631 return err;
3632}
3633
620554e4
CH
3634static int orinoco_ioctl_reset(struct net_device *dev,
3635 struct iw_request_info *info,
3636 void *wrqu,
3637 char *extra)
3638{
3639 struct orinoco_private *priv = netdev_priv(dev);
3640
3641 if (! capable(CAP_NET_ADMIN))
3642 return -EPERM;
3643
3644 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3645 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3646
3647 /* Firmware reset */
3648 orinoco_reset(dev);
3649 } else {
3650 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3651
3652 schedule_work(&priv->reset_work);
3653 }
3654
3655 return 0;
3656}
3657
3658static int orinoco_ioctl_setibssport(struct net_device *dev,
3659 struct iw_request_info *info,
3660 void *wrqu,
3661 char *extra)
3662
1da177e4
LT
3663{
3664 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3665 int val = *( (int *) extra );
1da177e4
LT
3666 unsigned long flags;
3667
3668 if (orinoco_lock(priv, &flags) != 0)
3669 return -EBUSY;
3670
3671 priv->ibss_port = val ;
3672
3673 /* Actually update the mode we are using */
3674 set_port_type(priv);
3675
3676 orinoco_unlock(priv, &flags);
620554e4 3677 return -EINPROGRESS; /* Call commit handler */
1da177e4
LT
3678}
3679
620554e4
CH
3680static int orinoco_ioctl_getibssport(struct net_device *dev,
3681 struct iw_request_info *info,
3682 void *wrqu,
3683 char *extra)
1da177e4
LT
3684{
3685 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3686 int *val = (int *) extra;
1da177e4
LT
3687
3688 *val = priv->ibss_port;
1da177e4
LT
3689 return 0;
3690}
3691
620554e4
CH
3692static int orinoco_ioctl_setport3(struct net_device *dev,
3693 struct iw_request_info *info,
3694 void *wrqu,
3695 char *extra)
1da177e4
LT
3696{
3697 struct orinoco_private *priv = netdev_priv(dev);
620554e4 3698 int val = *( (int *) extra );
1da177e4
LT
3699 int err = 0;
3700 unsigned long flags;
3701
3702 if (orinoco_lock(priv, &flags) != 0)
3703 return -EBUSY;
3704
3705 switch (val) {
3706 case 0: /* Try to do IEEE ad-hoc mode */
3707 if (! priv->has_ibss) {
3708 err = -EINVAL;
3709 break;
3710 }
3711 priv->prefer_port3 = 0;
3712
3713 break;
3714
3715 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3716 if (! priv->has_port3) {
3717 err = -EINVAL;
3718 break;
3719 }
3720 priv->prefer_port3 = 1;
3721 break;
3722
3723 default:
3724 err = -EINVAL;
3725 }
3726
620554e4 3727 if (! err) {
1da177e4
LT
3728 /* Actually update the mode we are using */
3729 set_port_type(priv);
620554e4
CH
3730 err = -EINPROGRESS;
3731 }
1da177e4
LT
3732
3733 orinoco_unlock(priv, &flags);
3734
3735 return err;
3736}
3737
620554e4
CH
3738static int orinoco_ioctl_getport3(struct net_device *dev,
3739 struct iw_request_info *info,
3740 void *wrqu,
3741 char *extra)
3742{
3743 struct orinoco_private *priv = netdev_priv(dev);
3744 int *val = (int *) extra;
3745
3746 *val = priv->prefer_port3;
3747 return 0;
3748}
3749
3750static int orinoco_ioctl_setpreamble(struct net_device *dev,
3751 struct iw_request_info *info,
3752 void *wrqu,
3753 char *extra)
1da177e4
LT
3754{
3755 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 3756 unsigned long flags;
620554e4
CH
3757 int val;
3758
3759 if (! priv->has_preamble)
3760 return -EOPNOTSUPP;
3761
3762 /* 802.11b has recently defined some short preamble.
3763 * Basically, the Phy header has been reduced in size.
3764 * This increase performance, especially at high rates
3765 * (the preamble is transmitted at 1Mb/s), unfortunately
3766 * this give compatibility troubles... - Jean II */
3767 val = *( (int *) extra );
1da177e4
LT
3768
3769 if (orinoco_lock(priv, &flags) != 0)
3770 return -EBUSY;
3771
620554e4
CH
3772 if (val)
3773 priv->preamble = 1;
3774 else
3775 priv->preamble = 0;
3776
1da177e4 3777 orinoco_unlock(priv, &flags);
620554e4
CH
3778
3779 return -EINPROGRESS; /* Call commit handler */
3780}
3781
3782static int orinoco_ioctl_getpreamble(struct net_device *dev,
3783 struct iw_request_info *info,
3784 void *wrqu,
3785 char *extra)
3786{
3787 struct orinoco_private *priv = netdev_priv(dev);
3788 int *val = (int *) extra;
3789
3790 if (! priv->has_preamble)
3791 return -EOPNOTSUPP;
3792
3793 *val = priv->preamble;
1da177e4
LT
3794 return 0;
3795}
3796
620554e4
CH
3797/* ioctl interface to hermes_read_ltv()
3798 * To use with iwpriv, pass the RID as the token argument, e.g.
3799 * iwpriv get_rid [0xfc00]
3800 * At least Wireless Tools 25 is required to use iwpriv.
3801 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3802static int orinoco_ioctl_getrid(struct net_device *dev,
3803 struct iw_request_info *info,
3804 struct iw_point *data,
3805 char *extra)
3806{
3807 struct orinoco_private *priv = netdev_priv(dev);
3808 hermes_t *hw = &priv->hw;
3809 int rid = data->flags;
3810 u16 length;
3811 int err;
3812 unsigned long flags;
3813
3814 /* It's a "get" function, but we don't want users to access the
3815 * WEP key and other raw firmware data */
3816 if (! capable(CAP_NET_ADMIN))
3817 return -EPERM;
3818
3819 if (rid < 0xfc00 || rid > 0xffff)
3820 return -EINVAL;
3821
3822 if (orinoco_lock(priv, &flags) != 0)
3823 return -EBUSY;
3824
3825 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3826 extra);
3827 if (err)
3828 goto out;
3829
3830 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3831 MAX_RID_LEN);
3832
3833 out:
3834 orinoco_unlock(priv, &flags);
3835 return err;
3836}
3837
95dd91fb
CH
3838/* Trigger a scan (look for other cells in the vicinity */
3839static int orinoco_ioctl_setscan(struct net_device *dev,
3840 struct iw_request_info *info,
3841 struct iw_param *srq,
3842 char *extra)
1da177e4
LT
3843{
3844 struct orinoco_private *priv = netdev_priv(dev);
95dd91fb 3845 hermes_t *hw = &priv->hw;
1da177e4 3846 int err = 0;
1da177e4
LT
3847 unsigned long flags;
3848
95dd91fb
CH
3849 /* Note : you may have realised that, as this is a SET operation,
3850 * this is priviledged and therefore a normal user can't
3851 * perform scanning.
3852 * This is not an error, while the device perform scanning,
3853 * traffic doesn't flow, so it's a perfect DoS...
3854 * Jean II */
1da177e4 3855
95dd91fb
CH
3856 if (orinoco_lock(priv, &flags) != 0)
3857 return -EBUSY;
1da177e4 3858
95dd91fb
CH
3859 /* Scanning with port 0 disabled would fail */
3860 if (!netif_running(dev)) {
3861 err = -ENETDOWN;
3862 goto out;
3863 }
1da177e4 3864
95dd91fb
CH
3865 /* In monitor mode, the scan results are always empty.
3866 * Probe responses are passed to the driver as received
3867 * frames and could be processed in software. */
3868 if (priv->iw_mode == IW_MODE_MONITOR) {
3869 err = -EOPNOTSUPP;
3870 goto out;
3871 }
1da177e4 3872
95dd91fb
CH
3873 /* Note : because we don't lock out the irq handler, the way
3874 * we access scan variables in priv is critical.
3875 * o scan_inprogress : not touched by irq handler
3876 * o scan_mode : not touched by irq handler
3877 * o scan_result : irq is strict producer, non-irq is strict
3878 * consumer.
3879 * o scan_len : synchronised with scan_result
3880 * Before modifying anything on those variables, please think hard !
3881 * Jean II */
1da177e4 3882
95dd91fb
CH
3883 /* If there is still some left-over scan results, get rid of it */
3884 if (priv->scan_result != NULL) {
3885 /* What's likely is that a client did crash or was killed
3886 * between triggering the scan request and reading the
3887 * results, so we need to reset everything.
3888 * Some clients that are too slow may suffer from that...
3889 * Jean II */
3890 kfree(priv->scan_result);
3891 priv->scan_result = NULL;
3892 }
1da177e4 3893
95dd91fb
CH
3894 /* Save flags */
3895 priv->scan_mode = srq->flags;
1da177e4 3896
95dd91fb
CH
3897 /* Always trigger scanning, even if it's in progress.
3898 * This way, if the info frame get lost, we will recover somewhat
3899 * gracefully - Jean II */
1da177e4 3900
95dd91fb
CH
3901 if (priv->has_hostscan) {
3902 switch (priv->firmware_type) {
3903 case FIRMWARE_TYPE_SYMBOL:
3904 err = hermes_write_wordrec(hw, USER_BAP,
3905 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3906 HERMES_HOSTSCAN_SYMBOL_ONCE |
3907 HERMES_HOSTSCAN_SYMBOL_BCAST);
3908 break;
3909 case FIRMWARE_TYPE_INTERSIL: {
d133ae4c 3910 __le16 req[3];
95dd91fb
CH
3911
3912 req[0] = cpu_to_le16(0x3fff); /* All channels */
3913 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3914 req[2] = 0; /* Any ESSID */
3915 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3916 HERMES_RID_CNFHOSTSCAN, &req);
3917 }
1da177e4 3918 break;
95dd91fb
CH
3919 case FIRMWARE_TYPE_AGERE:
3920 err = hermes_write_wordrec(hw, USER_BAP,
3921 HERMES_RID_CNFSCANSSID_AGERE,
3922 0); /* Any ESSID */
3923 if (err)
3924 break;
1da177e4 3925
95dd91fb 3926 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1da177e4
LT
3927 break;
3928 }
95dd91fb
CH
3929 } else
3930 err = hermes_inquire(hw, HERMES_INQ_SCAN);
1da177e4 3931
95dd91fb
CH
3932 /* One more client */
3933 if (! err)
3934 priv->scan_inprogress = 1;
1da177e4 3935
95dd91fb
CH
3936 out:
3937 orinoco_unlock(priv, &flags);
3938 return err;
3939}
1da177e4 3940
95dd91fb 3941/* Translate scan data returned from the card to a card independant
70817c40
PR
3942 * format that the Wireless Tools will understand - Jean II
3943 * Return message length or -errno for fatal errors */
95dd91fb
CH
3944static inline int orinoco_translate_scan(struct net_device *dev,
3945 char *buffer,
3946 char *scan,
3947 int scan_len)
3948{
3949 struct orinoco_private *priv = netdev_priv(dev);
3950 int offset; /* In the scan data */
3951 union hermes_scan_info *atom;
3952 int atom_len;
3953 u16 capabilities;
3954 u16 channel;
3955 struct iw_event iwe; /* Temporary buffer */
3956 char * current_ev = buffer;
3957 char * end_buf = buffer + IW_SCAN_MAX_DATA;
1da177e4 3958
95dd91fb
CH
3959 switch (priv->firmware_type) {
3960 case FIRMWARE_TYPE_AGERE:
3961 atom_len = sizeof(struct agere_scan_apinfo);
3962 offset = 0;
1da177e4 3963 break;
95dd91fb
CH
3964 case FIRMWARE_TYPE_SYMBOL:
3965 /* Lack of documentation necessitates this hack.
3966 * Different firmwares have 68 or 76 byte long atoms.
3967 * We try modulo first. If the length divides by both,
3968 * we check what would be the channel in the second
3969 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3970 * Valid channel cannot be 0. */
3971 if (scan_len % 76)
3972 atom_len = 68;
3973 else if (scan_len % 68)
3974 atom_len = 76;
3975 else if (scan_len >= 1292 && scan[68] == 0)
3976 atom_len = 76;
3977 else
3978 atom_len = 68;
3979 offset = 0;
1da177e4 3980 break;
95dd91fb
CH
3981 case FIRMWARE_TYPE_INTERSIL:
3982 offset = 4;
70817c40 3983 if (priv->has_hostscan) {
d133ae4c 3984 atom_len = le16_to_cpup((__le16 *)scan);
70817c40
PR
3985 /* Sanity check for atom_len */
3986 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3987 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3988 dev->name, atom_len);
3989 return -EIO;
3990 }
3991 } else
95dd91fb 3992 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1da177e4 3993 break;
95dd91fb 3994 default:
70817c40 3995 return -EOPNOTSUPP;
95dd91fb 3996 }
1da177e4 3997
95dd91fb
CH
3998 /* Check that we got an whole number of atoms */
3999 if ((scan_len - offset) % atom_len) {
4000 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4001 "atom_len %d, offset %d\n", dev->name, scan_len,
4002 atom_len, offset);
70817c40 4003 return -EIO;
95dd91fb 4004 }
1da177e4 4005
95dd91fb
CH
4006 /* Read the entries one by one */
4007 for (; offset + atom_len <= scan_len; offset += atom_len) {
4008 /* Get next atom */
4009 atom = (union hermes_scan_info *) (scan + offset);
4010
4011 /* First entry *MUST* be the AP MAC address */
4012 iwe.cmd = SIOCGIWAP;
4013 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4014 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4015 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4016
4017 /* Other entries will be displayed in the order we give them */
4018
4019 /* Add the ESSID */
4020 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4021 if (iwe.u.data.length > 32)
4022 iwe.u.data.length = 32;
4023 iwe.cmd = SIOCGIWESSID;
4024 iwe.u.data.flags = 1;
4025 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4026
4027 /* Add mode */
4028 iwe.cmd = SIOCGIWMODE;
4029 capabilities = le16_to_cpu(atom->a.capabilities);
4030 if (capabilities & 0x3) {
4031 if (capabilities & 0x1)
4032 iwe.u.mode = IW_MODE_MASTER;
4033 else
4034 iwe.u.mode = IW_MODE_ADHOC;
4035 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4036 }
1da177e4 4037
95dd91fb
CH
4038 channel = atom->s.channel;
4039 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4040 /* Add frequency */
4041 iwe.cmd = SIOCGIWFREQ;
4042 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4043 iwe.u.freq.e = 1;
4044 current_ev = iwe_stream_add_event(current_ev, end_buf,
4045 &iwe, IW_EV_FREQ_LEN);
4046 }
1da177e4 4047
95dd91fb
CH
4048 /* Add quality statistics */
4049 iwe.cmd = IWEVQUAL;
4050 iwe.u.qual.updated = 0x10; /* no link quality */
4051 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4052 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4053 /* Wireless tools prior to 27.pre22 will show link quality
4054 * anyway, so we provide a reasonable value. */
4055 if (iwe.u.qual.level > iwe.u.qual.noise)
4056 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4057 else
4058 iwe.u.qual.qual = 0;
4059 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
1da177e4 4060
95dd91fb
CH
4061 /* Add encryption capability */
4062 iwe.cmd = SIOCGIWENCODE;
4063 if (capabilities & 0x10)
4064 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4065 else
4066 iwe.u.data.flags = IW_ENCODE_DISABLED;
4067 iwe.u.data.length = 0;
4068 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4069
4070 /* Bit rate is not available in Lucent/Agere firmwares */
4071 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4072 char * current_val = current_ev + IW_EV_LCP_LEN;
4073 int i;
4074 int step;
4075
4076 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4077 step = 2;
4078 else
4079 step = 1;
4080
4081 iwe.cmd = SIOCGIWRATE;
4082 /* Those two flags are ignored... */
4083 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4084 /* Max 10 values */
4085 for (i = 0; i < 10; i += step) {
4086 /* NULL terminated */
4087 if (atom->p.rates[i] == 0x0)
4088 break;
4089 /* Bit rate given in 500 kb/s units (+ 0x80) */
4090 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4091 current_val = iwe_stream_add_value(current_ev, current_val,
4092 end_buf, &iwe,
4093 IW_EV_PARAM_LEN);
4094 }
4095 /* Check if we added any event */
4096 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4097 current_ev = current_val;
4098 }
1da177e4 4099
95dd91fb
CH
4100 /* The other data in the scan result are not really
4101 * interesting, so for now drop it - Jean II */
4102 }
4103 return current_ev - buffer;
4104}
1da177e4 4105
95dd91fb
CH
4106/* Return results of a scan */
4107static int orinoco_ioctl_getscan(struct net_device *dev,
4108 struct iw_request_info *info,
4109 struct iw_point *srq,
4110 char *extra)
4111{
4112 struct orinoco_private *priv = netdev_priv(dev);
4113 int err = 0;
4114 unsigned long flags;
1da177e4 4115
95dd91fb
CH
4116 if (orinoco_lock(priv, &flags) != 0)
4117 return -EBUSY;
1da177e4 4118
95dd91fb
CH
4119 /* If no results yet, ask to try again later */
4120 if (priv->scan_result == NULL) {
4121 if (priv->scan_inprogress)
4122 /* Important note : we don't want to block the caller
4123 * until results are ready for various reasons.
4124 * First, managing wait queues is complex and racy.
4125 * Second, we grab some rtnetlink lock before comming
4126 * here (in dev_ioctl()).
4127 * Third, we generate an Wireless Event, so the
4128 * caller can wait itself on that - Jean II */
4129 err = -EAGAIN;
4130 else
4131 /* Client error, no scan results...
4132 * The caller need to restart the scan. */
4133 err = -ENODATA;
4134 } else {
4135 /* We have some results to push back to user space */
4136
4137 /* Translate to WE format */
70817c40
PR
4138 int ret = orinoco_translate_scan(dev, extra,
4139 priv->scan_result,
4140 priv->scan_len);
4141
4142 if (ret < 0) {
4143 err = ret;
4144 kfree(priv->scan_result);
4145 priv->scan_result = NULL;
4146 } else {
4147 srq->length = ret;
95dd91fb 4148
70817c40
PR
4149 /* Return flags */
4150 srq->flags = (__u16) priv->scan_mode;
95dd91fb 4151
70817c40
PR
4152 /* In any case, Scan results will be cleaned up in the
4153 * reset function and when exiting the driver.
4154 * The person triggering the scanning may never come to
4155 * pick the results, so we need to do it in those places.
4156 * Jean II */
95dd91fb
CH
4157
4158#ifdef SCAN_SINGLE_READ
70817c40
PR
4159 /* If you enable this option, only one client (the first
4160 * one) will be able to read the result (and only one
4161 * time). If there is multiple concurent clients that
4162 * want to read scan results, this behavior is not
4163 * advisable - Jean II */
4164 kfree(priv->scan_result);
4165 priv->scan_result = NULL;
95dd91fb 4166#endif /* SCAN_SINGLE_READ */
70817c40
PR
4167 /* Here, if too much time has elapsed since last scan,
4168 * we may want to clean up scan results... - Jean II */
4169 }
4170
4171 /* Scan is no longer in progress */
4172 priv->scan_inprogress = 0;
95dd91fb
CH
4173 }
4174
4175 orinoco_unlock(priv, &flags);
4176 return err;
4177}
1da177e4 4178
620554e4
CH
4179/* Commit handler, called after set operations */
4180static int orinoco_ioctl_commit(struct net_device *dev,
4181 struct iw_request_info *info,
4182 void *wrqu,
4183 char *extra)
1da177e4
LT
4184{
4185 struct orinoco_private *priv = netdev_priv(dev);
620554e4 4186 struct hermes *hw = &priv->hw;
1da177e4 4187 unsigned long flags;
620554e4 4188 int err = 0;
1da177e4 4189
620554e4
CH
4190 if (!priv->open)
4191 return 0;
1da177e4 4192
620554e4
CH
4193 if (priv->broken_disableport) {
4194 orinoco_reset(dev);
4195 return 0;
4196 }
1da177e4 4197
620554e4
CH
4198 if (orinoco_lock(priv, &flags) != 0)
4199 return err;
1da177e4 4200
620554e4
CH
4201 err = hermes_disable_port(hw, 0);
4202 if (err) {
4203 printk(KERN_WARNING "%s: Unable to disable port "
4204 "while reconfiguring card\n", dev->name);
4205 priv->broken_disableport = 1;
4206 goto out;
4207 }
1da177e4 4208
620554e4
CH
4209 err = __orinoco_program_rids(dev);
4210 if (err) {
4211 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4212 dev->name);
4213 goto out;
4214 }
1da177e4 4215
620554e4
CH
4216 err = hermes_enable_port(hw, 0);
4217 if (err) {
4218 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4219 dev->name);
4220 goto out;
4221 }
1da177e4 4222
620554e4
CH
4223 out:
4224 if (err) {
4225 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
1da177e4 4226 schedule_work(&priv->reset_work);
620554e4
CH
4227 err = 0;
4228 }
1da177e4 4229
620554e4
CH
4230 orinoco_unlock(priv, &flags);
4231 return err;
4232}
1da177e4 4233
620554e4
CH
4234static const struct iw_priv_args orinoco_privtab[] = {
4235 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4236 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4237 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4238 0, "set_port3" },
4239 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4240 "get_port3" },
4241 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4242 0, "set_preamble" },
4243 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4244 "get_preamble" },
4245 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4246 0, "set_ibssport" },
4247 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4248 "get_ibssport" },
4249 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4250 "get_rid" },
4251};
1da177e4 4252
1da177e4 4253
620554e4
CH
4254/*
4255 * Structures to export the Wireless Handlers
4256 */
1da177e4 4257
620554e4 4258static const iw_handler orinoco_handler[] = {
6b9b97ce
PH
4259 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4260 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4261 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4262 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4263 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4264 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4265 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4266 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4267 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
343c686c
PR
4268 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4269 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4270 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4271 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
6b9b97ce
PH
4272 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4273 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4274 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4275 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4276 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4277 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4278 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4279 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4280 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4281 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4282 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4283 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4284 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4285 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4286 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4287 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4288 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4289 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4290 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
620554e4 4291};
1da177e4 4292
1da177e4 4293
620554e4
CH
4294/*
4295 Added typecasting since we no longer use iwreq_data -- Moustafa
4296 */
4297static const iw_handler orinoco_private_handler[] = {
6b9b97ce
PH
4298 [0] = (iw_handler) orinoco_ioctl_reset,
4299 [1] = (iw_handler) orinoco_ioctl_reset,
4300 [2] = (iw_handler) orinoco_ioctl_setport3,
4301 [3] = (iw_handler) orinoco_ioctl_getport3,
4302 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4303 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4304 [6] = (iw_handler) orinoco_ioctl_setibssport,
4305 [7] = (iw_handler) orinoco_ioctl_getibssport,
4306 [9] = (iw_handler) orinoco_ioctl_getrid,
620554e4 4307};
1da177e4 4308
620554e4
CH
4309static const struct iw_handler_def orinoco_handler_def = {
4310 .num_standard = ARRAY_SIZE(orinoco_handler),
4311 .num_private = ARRAY_SIZE(orinoco_private_handler),
4312 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4313 .standard = orinoco_handler,
4314 .private = orinoco_private_handler,
4315 .private_args = orinoco_privtab,
343c686c 4316 .get_wireless_stats = orinoco_get_wireless_stats,
620554e4 4317};
1da177e4 4318
1fab2e8b
CH
4319static void orinoco_get_drvinfo(struct net_device *dev,
4320 struct ethtool_drvinfo *info)
4321{
4322 struct orinoco_private *priv = netdev_priv(dev);
1da177e4 4323
1fab2e8b
CH
4324 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4325 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4326 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4327 if (dev->class_dev.dev)
4328 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4329 sizeof(info->bus_info) - 1);
4330 else
4331 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4332 "PCMCIA %p", priv->hw.iobase);
1da177e4
LT
4333}
4334
1fab2e8b
CH
4335static struct ethtool_ops orinoco_ethtool_ops = {
4336 .get_drvinfo = orinoco_get_drvinfo,
4337 .get_link = ethtool_op_get_link,
4338};
1da177e4
LT
4339
4340/********************************************************************/
4341/* Debugging */
4342/********************************************************************/
4343
4344#if 0
4345static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4346{
4347 printk(KERN_DEBUG "RX descriptor:\n");
4348 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4349 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4350 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4351 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4352 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4353 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4354 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4355
4356 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4357 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4358 frame->p80211.frame_ctl);
4359 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4360 frame->p80211.duration_id);
4361 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4362 frame->p80211.addr1[0], frame->p80211.addr1[1],
4363 frame->p80211.addr1[2], frame->p80211.addr1[3],
4364 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4365 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4366 frame->p80211.addr2[0], frame->p80211.addr2[1],
4367 frame->p80211.addr2[2], frame->p80211.addr2[3],
4368 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4369 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4370 frame->p80211.addr3[0], frame->p80211.addr3[1],
4371 frame->p80211.addr3[2], frame->p80211.addr3[3],
4372 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4373 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4374 frame->p80211.seq_ctl);
4375 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4376 frame->p80211.addr4[0], frame->p80211.addr4[1],
4377 frame->p80211.addr4[2], frame->p80211.addr4[3],
4378 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4379 printk(KERN_DEBUG " data_len = 0x%04x\n",
4380 frame->p80211.data_len);
4381
4382 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4383 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4384 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4385 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4386 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4387 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4388 frame->p8023.h_source[0], frame->p8023.h_source[1],
4389 frame->p8023.h_source[2], frame->p8023.h_source[3],
4390 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4391 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4392
4393 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4394 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4395 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4396 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4397 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4398 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4399 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4400}
4401#endif /* 0 */
4402
4403/********************************************************************/
4404/* Module initialization */
4405/********************************************************************/
4406
4407EXPORT_SYMBOL(alloc_orinocodev);
4408EXPORT_SYMBOL(free_orinocodev);
4409
4410EXPORT_SYMBOL(__orinoco_up);
4411EXPORT_SYMBOL(__orinoco_down);
1da177e4
LT
4412EXPORT_SYMBOL(orinoco_reinit_firmware);
4413
4414EXPORT_SYMBOL(orinoco_interrupt);
4415
4416/* Can't be declared "const" or the whole __initdata section will
4417 * become const */
4418static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4419 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4420 "Pavel Roskin <proski@gnu.org>, et al)";
4421
4422static int __init init_orinoco(void)
4423{
4424 printk(KERN_DEBUG "%s\n", version);
4425 return 0;
4426}
4427
4428static void __exit exit_orinoco(void)
4429{
4430}
4431
4432module_init(init_orinoco);
4433module_exit(exit_orinoco);