Revert "Fix compile on v2.6.30"
[orinoco_usb.git] / drivers / net / wireless / orinoco.c
blobc8d0d56082ca7abfa7358f6adf1754ee0bd480dc
1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
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>
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
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
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/
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/
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.
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.
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. */
49 * TODO
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
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.
59 /* Locking and synchronization:
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.
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).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/module.h>
80 #include <linux/kernel.h>
81 #include <linux/init.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/ethtool.h>
85 #include <linux/wireless.h>
86 #include <net/iw_handler.h>
87 #include <net/ieee80211.h>
89 #include "hermes_rid.h"
90 #include "orinoco.h"
92 /********************************************************************/
93 /* Module information */
94 /********************************************************************/
96 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
97 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
98 MODULE_LICENSE("Dual MPL/GPL");
100 /* Level of debugging. Used in the macros in orinoco.h */
101 #ifdef ORINOCO_DEBUG
102 int orinoco_debug = ORINOCO_DEBUG;
103 module_param(orinoco_debug, int, 0644);
104 MODULE_PARM_DESC(orinoco_debug, "Debug level");
105 EXPORT_SYMBOL(orinoco_debug);
106 #endif
108 static int suppress_linkstatus; /* = 0 */
109 module_param(suppress_linkstatus, bool, 0644);
110 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
111 static int ignore_disconnect; /* = 0 */
112 module_param(ignore_disconnect, int, 0644);
113 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
115 static int force_monitor; /* = 0 */
116 module_param(force_monitor, int, 0644);
117 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
119 /********************************************************************/
120 /* Compile time configuration and compatibility stuff */
121 /********************************************************************/
123 /* We do this this way to avoid ifdefs in the actual code */
124 #ifdef WIRELESS_SPY
125 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
126 #else
127 #define SPY_NUMBER(priv) 0
128 #endif /* WIRELESS_SPY */
130 /********************************************************************/
131 /* Internal constants */
132 /********************************************************************/
134 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
135 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
136 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
138 #define ORINOCO_MIN_MTU 256
139 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
141 #define SYMBOL_MAX_VER_LEN (14)
142 #define USER_BAP 0
143 #define IRQ_BAP 1
144 #define MAX_IRQLOOPS_PER_IRQ 10
145 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
146 * how many events the
147 * device could
148 * legitimately generate */
149 #define SMALL_KEY_SIZE 5
150 #define LARGE_KEY_SIZE 13
151 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
153 #define DUMMY_FID 0xFFFF
155 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
156 HERMES_MAX_MULTICAST : 0)*/
157 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
160 | HERMES_EV_TX | HERMES_EV_TXEXC \
161 | HERMES_EV_WTERR | HERMES_EV_INFO \
162 | HERMES_EV_INFDROP )
164 #define MAX_RID_LEN 1024
166 static const struct iw_handler_def orinoco_handler_def;
167 static struct ethtool_ops orinoco_ethtool_ops;
169 /********************************************************************/
170 /* Data tables */
171 /********************************************************************/
173 /* The frequency of each channel in MHz */
174 static const long channel_frequency[] = {
175 2412, 2417, 2422, 2427, 2432, 2437, 2442,
176 2447, 2452, 2457, 2462, 2467, 2472, 2484
178 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
180 /* This tables gives the actual meanings of the bitrate IDs returned
181 * by the firmware. */
182 static struct {
183 int bitrate; /* in 100s of kilobits */
184 int automatic;
185 u16 agere_txratectrl;
186 u16 intersil_txratectrl;
187 } bitrate_table[] = {
188 {110, 1, 3, 15}, /* Entry 0 is the default */
189 {10, 0, 1, 1},
190 {10, 1, 1, 1},
191 {20, 0, 2, 2},
192 {20, 1, 6, 3},
193 {55, 0, 4, 4},
194 {55, 1, 7, 7},
195 {110, 0, 5, 8},
197 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
199 /********************************************************************/
200 /* Data types */
201 /********************************************************************/
203 /* Beginning of the Tx descriptor, used in TxExc handling */
204 struct hermes_txexc_data {
205 struct hermes_tx_descriptor desc;
206 __le16 frame_ctl;
207 __le16 duration_id;
208 u8 addr1[ETH_ALEN];
209 } __attribute__ ((packed));
211 /* Rx frame header except compatibility 802.3 header */
212 struct hermes_rx_descriptor {
213 /* Control */
214 __le16 status;
215 __le32 time;
216 u8 silence;
217 u8 signal;
218 u8 rate;
219 u8 rxflow;
220 __le32 reserved;
222 /* 802.11 header */
223 __le16 frame_ctl;
224 __le16 duration_id;
225 u8 addr1[ETH_ALEN];
226 u8 addr2[ETH_ALEN];
227 u8 addr3[ETH_ALEN];
228 __le16 seq_ctl;
229 u8 addr4[ETH_ALEN];
231 /* Data length */
232 __le16 data_len;
233 } __attribute__ ((packed));
235 /********************************************************************/
236 /* Function prototypes */
237 /********************************************************************/
239 static int __orinoco_program_rids(struct net_device *dev);
240 static void __orinoco_set_multicast_list(struct net_device *dev);
242 /********************************************************************/
243 /* Internal helper functions */
244 /********************************************************************/
246 static inline void set_port_type(struct orinoco_private *priv)
248 switch (priv->iw_mode) {
249 case IW_MODE_INFRA:
250 priv->port_type = 1;
251 priv->createibss = 0;
252 break;
253 case IW_MODE_ADHOC:
254 if (priv->prefer_port3) {
255 priv->port_type = 3;
256 priv->createibss = 0;
257 } else {
258 priv->port_type = priv->ibss_port;
259 priv->createibss = 1;
261 break;
262 case IW_MODE_MONITOR:
263 priv->port_type = 3;
264 priv->createibss = 0;
265 break;
266 default:
267 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
268 priv->ndev->name);
272 /********************************************************************/
273 /* Device methods */
274 /********************************************************************/
276 static int orinoco_open(struct net_device *dev)
278 struct orinoco_private *priv = netdev_priv(dev);
279 unsigned long flags;
280 int err;
282 if (orinoco_lock(priv, &flags) != 0)
283 return -EBUSY;
285 err = __orinoco_up(dev);
287 if (! err)
288 priv->open = 1;
290 orinoco_unlock(priv, &flags);
292 return err;
295 static int orinoco_stop(struct net_device *dev)
297 struct orinoco_private *priv = netdev_priv(dev);
298 int err = 0;
300 /* We mustn't use orinoco_lock() here, because we need to be
301 able to close the interface even if hw_unavailable is set
302 (e.g. as we're released after a PC Card removal) */
303 orinoco_spin_lock(priv);
305 priv->open = 0;
307 err = __orinoco_down(dev);
309 orinoco_spin_unlock(priv);
311 return err;
314 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
316 struct orinoco_private *priv = netdev_priv(dev);
318 return &priv->stats;
321 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
323 struct orinoco_private *priv = netdev_priv(dev);
324 hermes_t *hw = &priv->hw;
325 struct iw_statistics *wstats = &priv->wstats;
326 int err;
327 unsigned long flags;
329 if (! netif_device_present(dev)) {
330 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
331 dev->name);
332 return NULL; /* FIXME: Can we do better than this? */
335 /* If busy, return the old stats. Returning NULL may cause
336 * the interface to disappear from /proc/net/wireless */
337 if (orinoco_lock(priv, &flags) != 0)
338 return wstats;
340 /* We can't really wait for the tallies inquiry command to
341 * complete, so we just use the previous results and trigger
342 * a new tallies inquiry command for next time - Jean II */
343 /* FIXME: Really we should wait for the inquiry to come back -
344 * as it is the stats we give don't make a whole lot of sense.
345 * Unfortunately, it's not clear how to do that within the
346 * wireless extensions framework: I think we're in user
347 * context, but a lock seems to be held by the time we get in
348 * here so we're not safe to sleep here. */
349 hermes_inquire(hw, HERMES_INQ_TALLIES);
351 if (priv->iw_mode == IW_MODE_ADHOC) {
352 memset(&wstats->qual, 0, sizeof(wstats->qual));
353 /* If a spy address is defined, we report stats of the
354 * first spy address - Jean II */
355 if (SPY_NUMBER(priv)) {
356 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
357 wstats->qual.level = priv->spy_data.spy_stat[0].level;
358 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
359 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
361 } else {
362 struct {
363 __le16 qual, signal, noise, unused;
364 } __attribute__ ((packed)) cq;
366 err = HERMES_READ_RECORD(hw, USER_BAP,
367 HERMES_RID_COMMSQUALITY, &cq);
369 if (!err) {
370 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
371 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
372 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
373 wstats->qual.updated = 7;
377 orinoco_unlock(priv, &flags);
378 return wstats;
381 static void orinoco_set_multicast_list(struct net_device *dev)
383 struct orinoco_private *priv = netdev_priv(dev);
384 unsigned long flags;
386 if (orinoco_lock(priv, &flags) != 0) {
387 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
388 "called when hw_unavailable\n", dev->name);
389 return;
392 __orinoco_set_multicast_list(dev);
393 orinoco_unlock(priv, &flags);
396 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
398 struct orinoco_private *priv = netdev_priv(dev);
400 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
401 return -EINVAL;
403 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
404 (priv->nicbuf_size - ETH_HLEN) )
405 return -EINVAL;
407 dev->mtu = new_mtu;
409 return 0;
412 /********************************************************************/
413 /* Tx path */
414 /********************************************************************/
416 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
418 struct orinoco_private *priv = netdev_priv(dev);
419 struct net_device_stats *stats = &priv->stats;
420 hermes_t *hw = &priv->hw;
421 int err = 0;
422 u16 txfid = priv->txfid;
423 struct ethhdr *eh;
424 int data_off;
425 struct hermes_tx_descriptor desc;
426 unsigned long flags;
428 if (! netif_running(dev)) {
429 printk(KERN_ERR "%s: Tx on stopped device!\n",
430 dev->name);
431 return NETDEV_TX_BUSY;
434 if (netif_queue_stopped(dev)) {
435 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
436 dev->name);
437 return NETDEV_TX_BUSY;
440 if (orinoco_lock(priv, &flags) != 0) {
441 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
442 dev->name);
443 return NETDEV_TX_BUSY;
446 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
447 /* Oops, the firmware hasn't established a connection,
448 silently drop the packet (this seems to be the
449 safest approach). */
450 goto drop;
453 /* Check packet length */
454 if (skb->len < ETH_HLEN)
455 goto drop;
457 eh = (struct ethhdr *)skb->data;
459 memset(&desc, 0, sizeof(desc));
460 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
461 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
462 if (err) {
463 if (net_ratelimit())
464 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
465 "to BAP\n", dev->name, err);
466 goto busy;
469 /* Clear the 802.11 header and data length fields - some
470 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
471 * if this isn't done. */
472 hermes_clear_words(hw, HERMES_DATA0,
473 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
475 /* Encapsulate Ethernet-II frames */
476 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
477 struct header_struct {
478 struct ethhdr eth; /* 802.3 header */
479 u8 encap[6]; /* 802.2 header */
480 } __attribute__ ((packed)) hdr;
482 /* Strip destination and source from the data */
483 skb_pull(skb, 2 * ETH_ALEN);
484 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
486 /* And move them to a separate header */
487 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
488 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
489 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
491 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
492 txfid, HERMES_802_3_OFFSET);
493 if (err) {
494 if (net_ratelimit())
495 printk(KERN_ERR "%s: Error %d writing packet "
496 "header to BAP\n", dev->name, err);
497 goto busy;
499 } else { /* IEEE 802.3 frame */
500 data_off = HERMES_802_3_OFFSET;
503 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
504 txfid, data_off);
505 if (err) {
506 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
507 dev->name, err);
508 goto busy;
511 /* Finally, we actually initiate the send */
512 netif_stop_queue(dev);
514 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
515 txfid, NULL);
516 if (err) {
517 netif_start_queue(dev);
518 if (net_ratelimit())
519 printk(KERN_ERR "%s: Error %d transmitting packet\n",
520 dev->name, err);
521 goto busy;
524 dev->trans_start = jiffies;
525 stats->tx_bytes += data_off + skb->len;
526 goto ok;
528 drop:
529 stats->tx_errors++;
530 stats->tx_dropped++;
533 orinoco_unlock(priv, &flags);
534 dev_kfree_skb(skb);
535 return NETDEV_TX_OK;
537 busy:
538 orinoco_unlock(priv, &flags);
539 return NETDEV_TX_BUSY;
542 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
544 struct orinoco_private *priv = netdev_priv(dev);
545 u16 fid = hermes_read_regn(hw, ALLOCFID);
547 if (fid != priv->txfid) {
548 if (fid != DUMMY_FID)
549 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
550 dev->name, fid);
551 return;
554 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
557 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
559 struct orinoco_private *priv = netdev_priv(dev);
560 struct net_device_stats *stats = &priv->stats;
562 stats->tx_packets++;
564 netif_wake_queue(dev);
566 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
569 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
571 struct orinoco_private *priv = netdev_priv(dev);
572 struct net_device_stats *stats = &priv->stats;
573 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
574 u16 status;
575 struct hermes_txexc_data hdr;
576 int err = 0;
578 if (fid == DUMMY_FID)
579 return; /* Nothing's really happened */
581 /* Read part of the frame header - we need status and addr1 */
582 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
583 sizeof(struct hermes_txexc_data),
584 fid, 0);
586 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
587 stats->tx_errors++;
589 if (err) {
590 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
591 "(FID=%04X error %d)\n",
592 dev->name, fid, err);
593 return;
596 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
597 err, fid);
599 /* We produce a TXDROP event only for retry or lifetime
600 * exceeded, because that's the only status that really mean
601 * that this particular node went away.
602 * Other errors means that *we* screwed up. - Jean II */
603 status = le16_to_cpu(hdr.desc.status);
604 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
605 union iwreq_data wrqu;
607 /* Copy 802.11 dest address.
608 * We use the 802.11 header because the frame may
609 * not be 802.3 or may be mangled...
610 * In Ad-Hoc mode, it will be the node address.
611 * In managed mode, it will be most likely the AP addr
612 * User space will figure out how to convert it to
613 * whatever it needs (IP address or else).
614 * - Jean II */
615 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
616 wrqu.addr.sa_family = ARPHRD_ETHER;
618 /* Send event to user space */
619 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
622 netif_wake_queue(dev);
625 static void orinoco_tx_timeout(struct net_device *dev)
627 struct orinoco_private *priv = netdev_priv(dev);
628 struct net_device_stats *stats = &priv->stats;
629 struct hermes *hw = &priv->hw;
631 printk(KERN_WARNING "%s: Tx timeout! "
632 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
633 dev->name, hermes_read_regn(hw, ALLOCFID),
634 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
636 stats->tx_errors++;
638 schedule_work(&priv->reset_work);
641 /********************************************************************/
642 /* Rx path (data frames) */
643 /********************************************************************/
645 /* Does the frame have a SNAP header indicating it should be
646 * de-encapsulated to Ethernet-II? */
647 static inline int is_ethersnap(void *_hdr)
649 u8 *hdr = _hdr;
651 /* We de-encapsulate all packets which, a) have SNAP headers
652 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
653 * and where b) the OUI of the SNAP header is 00:00:00 or
654 * 00:00:f8 - we need both because different APs appear to use
655 * different OUIs for some reason */
656 return (memcmp(hdr, &encaps_hdr, 5) == 0)
657 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
660 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
661 int level, int noise)
663 struct iw_quality wstats;
664 wstats.level = level - 0x95;
665 wstats.noise = noise - 0x95;
666 wstats.qual = (level > noise) ? (level - noise) : 0;
667 wstats.updated = 7;
668 /* Update spy records */
669 wireless_spy_update(dev, mac, &wstats);
672 static void orinoco_stat_gather(struct net_device *dev,
673 struct sk_buff *skb,
674 struct hermes_rx_descriptor *desc)
676 struct orinoco_private *priv = netdev_priv(dev);
678 /* Using spy support with lots of Rx packets, like in an
679 * infrastructure (AP), will really slow down everything, because
680 * the MAC address must be compared to each entry of the spy list.
681 * If the user really asks for it (set some address in the
682 * spy list), we do it, but he will pay the price.
683 * Note that to get here, you need both WIRELESS_SPY
684 * compiled in AND some addresses in the list !!!
686 /* Note : gcc will optimise the whole section away if
687 * WIRELESS_SPY is not defined... - Jean II */
688 if (SPY_NUMBER(priv)) {
689 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
690 desc->signal, desc->silence);
695 * orinoco_rx_monitor - handle received monitor frames.
697 * Arguments:
698 * dev network device
699 * rxfid received FID
700 * desc rx descriptor of the frame
702 * Call context: interrupt
704 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
705 struct hermes_rx_descriptor *desc)
707 u32 hdrlen = 30; /* return full header by default */
708 u32 datalen = 0;
709 u16 fc;
710 int err;
711 int len;
712 struct sk_buff *skb;
713 struct orinoco_private *priv = netdev_priv(dev);
714 struct net_device_stats *stats = &priv->stats;
715 hermes_t *hw = &priv->hw;
717 len = le16_to_cpu(desc->data_len);
719 /* Determine the size of the header and the data */
720 fc = le16_to_cpu(desc->frame_ctl);
721 switch (fc & IEEE80211_FCTL_FTYPE) {
722 case IEEE80211_FTYPE_DATA:
723 if ((fc & IEEE80211_FCTL_TODS)
724 && (fc & IEEE80211_FCTL_FROMDS))
725 hdrlen = 30;
726 else
727 hdrlen = 24;
728 datalen = len;
729 break;
730 case IEEE80211_FTYPE_MGMT:
731 hdrlen = 24;
732 datalen = len;
733 break;
734 case IEEE80211_FTYPE_CTL:
735 switch (fc & IEEE80211_FCTL_STYPE) {
736 case IEEE80211_STYPE_PSPOLL:
737 case IEEE80211_STYPE_RTS:
738 case IEEE80211_STYPE_CFEND:
739 case IEEE80211_STYPE_CFENDACK:
740 hdrlen = 16;
741 break;
742 case IEEE80211_STYPE_CTS:
743 case IEEE80211_STYPE_ACK:
744 hdrlen = 10;
745 break;
747 break;
748 default:
749 /* Unknown frame type */
750 break;
753 /* sanity check the length */
754 if (datalen > IEEE80211_DATA_LEN + 12) {
755 printk(KERN_DEBUG "%s: oversized monitor frame, "
756 "data length = %d\n", dev->name, datalen);
757 err = -EIO;
758 stats->rx_length_errors++;
759 goto update_stats;
762 skb = dev_alloc_skb(hdrlen + datalen);
763 if (!skb) {
764 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
765 dev->name);
766 err = -ENOMEM;
767 goto drop;
770 /* Copy the 802.11 header to the skb */
771 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
772 skb_reset_mac_header(skb);
774 /* If any, copy the data from the card to the skb */
775 if (datalen > 0) {
776 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
777 ALIGN(datalen, 2), rxfid,
778 HERMES_802_2_OFFSET);
779 if (err) {
780 printk(KERN_ERR "%s: error %d reading monitor frame\n",
781 dev->name, err);
782 goto drop;
786 skb->dev = dev;
787 skb->ip_summed = CHECKSUM_NONE;
788 skb->pkt_type = PACKET_OTHERHOST;
789 skb->protocol = __constant_htons(ETH_P_802_2);
791 dev->last_rx = jiffies;
792 stats->rx_packets++;
793 stats->rx_bytes += skb->len;
795 netif_rx(skb);
796 return;
798 drop:
799 dev_kfree_skb_irq(skb);
800 update_stats:
801 stats->rx_errors++;
802 stats->rx_dropped++;
805 void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
807 struct orinoco_private *priv = netdev_priv(dev);
808 struct net_device_stats *stats = &priv->stats;
809 struct iw_statistics *wstats = &priv->wstats;
810 struct sk_buff *skb = NULL;
811 u16 rxfid, status, fc;
812 int length;
813 struct hermes_rx_descriptor desc;
814 struct ethhdr *hdr;
815 int err;
817 rxfid = hermes_read_regn(hw, RXFID);
819 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
820 rxfid, 0);
821 if (err) {
822 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
823 "Frame dropped.\n", dev->name, err);
824 goto update_stats;
827 status = le16_to_cpu(desc.status);
829 if (status & HERMES_RXSTAT_BADCRC) {
830 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
831 dev->name);
832 stats->rx_crc_errors++;
833 goto update_stats;
836 /* Handle frames in monitor mode */
837 if (priv->iw_mode == IW_MODE_MONITOR) {
838 orinoco_rx_monitor(dev, rxfid, &desc);
839 return;
842 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
843 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
844 dev->name);
845 wstats->discard.code++;
846 goto update_stats;
849 length = le16_to_cpu(desc.data_len);
850 fc = le16_to_cpu(desc.frame_ctl);
852 /* Sanity checks */
853 if (length < 3) { /* No for even an 802.2 LLC header */
854 /* At least on Symbol firmware with PCF we get quite a
855 lot of these legitimately - Poll frames with no
856 data. */
857 return;
859 if (length > IEEE80211_DATA_LEN) {
860 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
861 dev->name, length);
862 stats->rx_length_errors++;
863 goto update_stats;
866 /* We need space for the packet data itself, plus an ethernet
867 header, plus 2 bytes so we can align the IP header on a
868 32bit boundary, plus 1 byte so we can read in odd length
869 packets from the card, which has an IO granularity of 16
870 bits */
871 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
872 if (!skb) {
873 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
874 dev->name);
875 goto update_stats;
878 /* We'll prepend the header, so reserve space for it. The worst
879 case is no decapsulation, when 802.3 header is prepended and
880 nothing is removed. 2 is for aligning the IP header. */
881 skb_reserve(skb, ETH_HLEN + 2);
883 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
884 ALIGN(length, 2), rxfid,
885 HERMES_802_2_OFFSET);
886 if (err) {
887 printk(KERN_ERR "%s: error %d reading frame. "
888 "Frame dropped.\n", dev->name, err);
889 goto drop;
892 /* Handle decapsulation
893 * In most cases, the firmware tell us about SNAP frames.
894 * For some reason, the SNAP frames sent by LinkSys APs
895 * are not properly recognised by most firmwares.
896 * So, check ourselves */
897 if (length >= ENCAPS_OVERHEAD &&
898 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
899 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
900 is_ethersnap(skb->data))) {
901 /* These indicate a SNAP within 802.2 LLC within
902 802.11 frame which we'll need to de-encapsulate to
903 the original EthernetII frame. */
904 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
905 } else {
906 /* 802.3 frame - prepend 802.3 header as is */
907 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
908 hdr->h_proto = htons(length);
910 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
911 if (fc & IEEE80211_FCTL_FROMDS)
912 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
913 else
914 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
916 dev->last_rx = jiffies;
917 skb->dev = dev;
918 skb->protocol = eth_type_trans(skb, dev);
919 skb->ip_summed = CHECKSUM_NONE;
920 if (fc & IEEE80211_FCTL_TODS)
921 skb->pkt_type = PACKET_OTHERHOST;
923 /* Process the wireless stats if needed */
924 orinoco_stat_gather(dev, skb, &desc);
926 /* Pass the packet to the networking stack */
927 netif_rx(skb);
928 stats->rx_packets++;
929 stats->rx_bytes += length;
931 return;
933 drop:
934 dev_kfree_skb_irq(skb);
935 update_stats:
936 stats->rx_errors++;
937 stats->rx_dropped++;
940 /********************************************************************/
941 /* Rx path (info frames) */
942 /********************************************************************/
944 static void print_linkstatus(struct net_device *dev, u16 status)
946 char * s;
948 if (suppress_linkstatus)
949 return;
951 switch (status) {
952 case HERMES_LINKSTATUS_NOT_CONNECTED:
953 s = "Not Connected";
954 break;
955 case HERMES_LINKSTATUS_CONNECTED:
956 s = "Connected";
957 break;
958 case HERMES_LINKSTATUS_DISCONNECTED:
959 s = "Disconnected";
960 break;
961 case HERMES_LINKSTATUS_AP_CHANGE:
962 s = "AP Changed";
963 break;
964 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
965 s = "AP Out of Range";
966 break;
967 case HERMES_LINKSTATUS_AP_IN_RANGE:
968 s = "AP In Range";
969 break;
970 case HERMES_LINKSTATUS_ASSOC_FAILED:
971 s = "Association Failed";
972 break;
973 default:
974 s = "UNKNOWN";
977 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
978 dev->name, s, status);
981 /* Search scan results for requested BSSID, join it if found */
982 static void orinoco_join_ap(struct work_struct *work)
984 struct orinoco_private *priv =
985 container_of(work, struct orinoco_private, join_work);
986 struct net_device *dev = priv->ndev;
987 struct hermes *hw = &priv->hw;
988 int err;
989 unsigned long flags;
990 struct join_req {
991 u8 bssid[ETH_ALEN];
992 __le16 channel;
993 } __attribute__ ((packed)) req;
994 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
995 struct prism2_scan_apinfo *atom = NULL;
996 int offset = 4;
997 int found = 0;
998 u8 *buf;
999 u16 len;
1001 /* Allocate buffer for scan results */
1002 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1003 if (! buf)
1004 return;
1006 if (orinoco_lock(priv, &flags) != 0)
1007 goto fail_lock;
1009 /* Sanity checks in case user changed something in the meantime */
1010 if (! priv->bssid_fixed)
1011 goto out;
1013 if (strlen(priv->desired_essid) == 0)
1014 goto out;
1016 /* Read scan results from the firmware */
1017 err = hermes_read_ltv(hw, USER_BAP,
1018 HERMES_RID_SCANRESULTSTABLE,
1019 MAX_SCAN_LEN, &len, buf);
1020 if (err) {
1021 printk(KERN_ERR "%s: Cannot read scan results\n",
1022 dev->name);
1023 goto out;
1026 len = HERMES_RECLEN_TO_BYTES(len);
1028 /* Go through the scan results looking for the channel of the AP
1029 * we were requested to join */
1030 for (; offset + atom_len <= len; offset += atom_len) {
1031 atom = (struct prism2_scan_apinfo *) (buf + offset);
1032 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1033 found = 1;
1034 break;
1038 if (! found) {
1039 DEBUG(1, "%s: Requested AP not found in scan results\n",
1040 dev->name);
1041 goto out;
1044 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1045 req.channel = atom->channel; /* both are little-endian */
1046 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1047 &req);
1048 if (err)
1049 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1051 out:
1052 orinoco_unlock(priv, &flags);
1054 fail_lock:
1055 kfree(buf);
1058 /* Send new BSSID to userspace */
1059 static void orinoco_send_wevents(struct work_struct *work)
1061 struct orinoco_private *priv =
1062 container_of(work, struct orinoco_private, wevent_work);
1063 struct net_device *dev = priv->ndev;
1064 struct hermes *hw = &priv->hw;
1065 union iwreq_data wrqu;
1066 int err;
1067 unsigned long flags;
1069 if (orinoco_lock(priv, &flags) != 0)
1070 return;
1072 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1073 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1074 if (err != 0)
1075 goto out;
1077 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1079 /* Send event to user space */
1080 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1082 out:
1083 orinoco_unlock(priv, &flags);
1086 void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1088 struct orinoco_private *priv = netdev_priv(dev);
1089 u16 infofid;
1090 struct {
1091 __le16 len;
1092 __le16 type;
1093 } __attribute__ ((packed)) info;
1094 int len, type;
1095 int err;
1097 /* This is an answer to an INQUIRE command that we did earlier,
1098 * or an information "event" generated by the card
1099 * The controller return to us a pseudo frame containing
1100 * the information in question - Jean II */
1101 infofid = hermes_read_regn(hw, INFOFID);
1103 /* Read the info frame header - don't try too hard */
1104 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1105 infofid, 0);
1106 if (err) {
1107 printk(KERN_ERR "%s: error %d reading info frame. "
1108 "Frame dropped.\n", dev->name, err);
1109 return;
1112 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1113 type = le16_to_cpu(info.type);
1115 switch (type) {
1116 case HERMES_INQ_TALLIES: {
1117 struct hermes_tallies_frame tallies;
1118 struct iw_statistics *wstats = &priv->wstats;
1120 if (len > sizeof(tallies)) {
1121 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1122 dev->name, len);
1123 len = sizeof(tallies);
1126 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1127 infofid, sizeof(info));
1128 if (err)
1129 break;
1131 /* Increment our various counters */
1132 /* wstats->discard.nwid - no wrong BSSID stuff */
1133 wstats->discard.code +=
1134 le16_to_cpu(tallies.RxWEPUndecryptable);
1135 if (len == sizeof(tallies))
1136 wstats->discard.code +=
1137 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1138 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1139 wstats->discard.misc +=
1140 le16_to_cpu(tallies.TxDiscardsWrongSA);
1141 wstats->discard.fragment +=
1142 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1143 wstats->discard.retries +=
1144 le16_to_cpu(tallies.TxRetryLimitExceeded);
1145 /* wstats->miss.beacon - no match */
1147 break;
1148 case HERMES_INQ_LINKSTATUS: {
1149 struct hermes_linkstatus linkstatus;
1150 u16 newstatus;
1151 int connected;
1153 if (priv->iw_mode == IW_MODE_MONITOR)
1154 break;
1156 if (len != sizeof(linkstatus)) {
1157 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1158 dev->name, len);
1159 break;
1162 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1163 infofid, sizeof(info));
1164 if (err)
1165 break;
1166 newstatus = le16_to_cpu(linkstatus.linkstatus);
1168 /* Symbol firmware uses "out of range" to signal that
1169 * the hostscan frame can be requested. */
1170 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1171 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1172 priv->has_hostscan && priv->scan_inprogress) {
1173 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1174 break;
1177 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1178 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1179 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1181 if (connected)
1182 netif_carrier_on(dev);
1183 else if (!ignore_disconnect)
1184 netif_carrier_off(dev);
1186 if (newstatus != priv->last_linkstatus) {
1187 priv->last_linkstatus = newstatus;
1188 print_linkstatus(dev, newstatus);
1189 /* The info frame contains only one word which is the
1190 * status (see hermes.h). The status is pretty boring
1191 * in itself, that's why we export the new BSSID...
1192 * Jean II */
1193 schedule_work(&priv->wevent_work);
1196 break;
1197 case HERMES_INQ_SCAN:
1198 if (!priv->scan_inprogress && priv->bssid_fixed &&
1199 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1200 schedule_work(&priv->join_work);
1201 break;
1203 /* fall through */
1204 case HERMES_INQ_HOSTSCAN:
1205 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1206 /* Result of a scanning. Contains information about
1207 * cells in the vicinity - Jean II */
1208 union iwreq_data wrqu;
1209 unsigned char *buf;
1211 /* Sanity check */
1212 if (len > 4096) {
1213 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1214 dev->name, len);
1215 break;
1218 /* We are a strict producer. If the previous scan results
1219 * have not been consumed, we just have to drop this
1220 * frame. We can't remove the previous results ourselves,
1221 * that would be *very* racy... Jean II */
1222 if (priv->scan_result != NULL) {
1223 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1224 break;
1227 /* Allocate buffer for results */
1228 buf = kmalloc(len, GFP_ATOMIC);
1229 if (buf == NULL)
1230 /* No memory, so can't printk()... */
1231 break;
1233 /* Read scan data */
1234 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1235 infofid, sizeof(info));
1236 if (err) {
1237 kfree(buf);
1238 break;
1241 #ifdef ORINOCO_DEBUG
1243 int i;
1244 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1245 for(i = 1; i < (len * 2); i++)
1246 printk(":%02X", buf[i]);
1247 printk("]\n");
1249 #endif /* ORINOCO_DEBUG */
1251 /* Allow the clients to access the results */
1252 priv->scan_len = len;
1253 priv->scan_result = buf;
1255 /* Send an empty event to user space.
1256 * We don't send the received data on the event because
1257 * it would require us to do complex transcoding, and
1258 * we want to minimise the work done in the irq handler
1259 * Use a request to extract the data - Jean II */
1260 wrqu.data.length = 0;
1261 wrqu.data.flags = 0;
1262 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1264 break;
1265 case HERMES_INQ_SEC_STAT_AGERE:
1266 /* Security status (Agere specific) */
1267 /* Ignore this frame for now */
1268 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1269 break;
1270 /* fall through */
1271 default:
1272 printk(KERN_DEBUG "%s: Unknown information frame received: "
1273 "type 0x%04x, length %d\n", dev->name, type, len);
1274 /* We don't actually do anything about it */
1275 break;
1279 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1281 if (net_ratelimit())
1282 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1285 /********************************************************************/
1286 /* Internal hardware control routines */
1287 /********************************************************************/
1289 int __orinoco_up(struct net_device *dev)
1291 struct orinoco_private *priv = netdev_priv(dev);
1292 struct hermes *hw = &priv->hw;
1293 int err;
1295 netif_carrier_off(dev); /* just to make sure */
1297 err = __orinoco_program_rids(dev);
1298 if (err) {
1299 printk(KERN_ERR "%s: Error %d configuring card\n",
1300 dev->name, err);
1301 return err;
1304 /* Fire things up again */
1305 hermes_set_irqmask(hw, ORINOCO_INTEN);
1306 err = hermes_enable_port(hw, 0);
1307 if (err) {
1308 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1309 dev->name, err);
1310 return err;
1313 netif_start_queue(dev);
1315 return 0;
1318 int __orinoco_down(struct net_device *dev)
1320 struct orinoco_private *priv = netdev_priv(dev);
1321 struct hermes *hw = &priv->hw;
1322 int err;
1324 netif_stop_queue(dev);
1326 if (! priv->hw_unavailable) {
1327 if (! priv->broken_disableport) {
1328 err = hermes_disable_port(hw, 0);
1329 if (err) {
1330 /* Some firmwares (e.g. Intersil 1.3.x) seem
1331 * to have problems disabling the port, oh
1332 * well, too bad. */
1333 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1334 dev->name, err);
1335 priv->broken_disableport = 1;
1338 hermes_set_irqmask(hw, 0);
1339 hermes_write_regn(hw, EVACK, 0xffff);
1342 /* firmware will have to reassociate */
1343 netif_carrier_off(dev);
1344 priv->last_linkstatus = 0xffff;
1346 return 0;
1349 static int orinoco_allocate_fid(struct net_device *dev)
1351 struct orinoco_private *priv = netdev_priv(dev);
1352 struct hermes *hw = &priv->hw;
1353 int err;
1355 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1356 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1357 /* Try workaround for old Symbol firmware bug */
1358 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1359 "(old Symbol firmware?). Trying to work around... ",
1360 dev->name);
1362 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1363 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1364 if (err)
1365 printk("failed!\n");
1366 else
1367 printk("ok.\n");
1370 return err;
1373 int orinoco_reinit_firmware(struct net_device *dev)
1375 struct orinoco_private *priv = netdev_priv(dev);
1376 struct hermes *hw = &priv->hw;
1377 int err;
1379 err = hermes_init(hw);
1380 if (!err)
1381 err = orinoco_allocate_fid(dev);
1383 return err;
1386 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1388 hermes_t *hw = &priv->hw;
1389 int err = 0;
1391 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1392 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1393 priv->ndev->name, priv->bitratemode);
1394 return -EINVAL;
1397 switch (priv->firmware_type) {
1398 case FIRMWARE_TYPE_AGERE:
1399 err = hermes_write_wordrec(hw, USER_BAP,
1400 HERMES_RID_CNFTXRATECONTROL,
1401 bitrate_table[priv->bitratemode].agere_txratectrl);
1402 break;
1403 case FIRMWARE_TYPE_INTERSIL:
1404 case FIRMWARE_TYPE_SYMBOL:
1405 err = hermes_write_wordrec(hw, USER_BAP,
1406 HERMES_RID_CNFTXRATECONTROL,
1407 bitrate_table[priv->bitratemode].intersil_txratectrl);
1408 break;
1409 default:
1410 BUG();
1413 return err;
1416 /* Set fixed AP address */
1417 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1419 int roaming_flag;
1420 int err = 0;
1421 hermes_t *hw = &priv->hw;
1423 switch (priv->firmware_type) {
1424 case FIRMWARE_TYPE_AGERE:
1425 /* not supported */
1426 break;
1427 case FIRMWARE_TYPE_INTERSIL:
1428 if (priv->bssid_fixed)
1429 roaming_flag = 2;
1430 else
1431 roaming_flag = 1;
1433 err = hermes_write_wordrec(hw, USER_BAP,
1434 HERMES_RID_CNFROAMINGMODE,
1435 roaming_flag);
1436 break;
1437 case FIRMWARE_TYPE_SYMBOL:
1438 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1439 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1440 &priv->desired_bssid);
1441 break;
1443 return err;
1446 /* Change the WEP keys and/or the current keys. Can be called
1447 * either from __orinoco_hw_setup_wep() or directly from
1448 * orinoco_ioctl_setiwencode(). In the later case the association
1449 * with the AP is not broken (if the firmware can handle it),
1450 * which is needed for 802.1x implementations. */
1451 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1453 hermes_t *hw = &priv->hw;
1454 int err = 0;
1456 switch (priv->firmware_type) {
1457 case FIRMWARE_TYPE_AGERE:
1458 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1459 HERMES_RID_CNFWEPKEYS_AGERE,
1460 &priv->keys);
1461 if (err)
1462 return err;
1463 err = hermes_write_wordrec(hw, USER_BAP,
1464 HERMES_RID_CNFTXKEY_AGERE,
1465 priv->tx_key);
1466 if (err)
1467 return err;
1468 break;
1469 case FIRMWARE_TYPE_INTERSIL:
1470 case FIRMWARE_TYPE_SYMBOL:
1472 int keylen;
1473 int i;
1475 /* Force uniform key length to work around firmware bugs */
1476 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1478 if (keylen > LARGE_KEY_SIZE) {
1479 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1480 priv->ndev->name, priv->tx_key, keylen);
1481 return -E2BIG;
1484 /* Write all 4 keys */
1485 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1486 err = hermes_write_ltv(hw, USER_BAP,
1487 HERMES_RID_CNFDEFAULTKEY0 + i,
1488 HERMES_BYTES_TO_RECLEN(keylen),
1489 priv->keys[i].data);
1490 if (err)
1491 return err;
1494 /* Write the index of the key used in transmission */
1495 err = hermes_write_wordrec(hw, USER_BAP,
1496 HERMES_RID_CNFWEPDEFAULTKEYID,
1497 priv->tx_key);
1498 if (err)
1499 return err;
1501 break;
1504 return 0;
1507 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1509 hermes_t *hw = &priv->hw;
1510 int err = 0;
1511 int master_wep_flag;
1512 int auth_flag;
1514 if (priv->wep_on)
1515 __orinoco_hw_setup_wepkeys(priv);
1517 if (priv->wep_restrict)
1518 auth_flag = HERMES_AUTH_SHARED_KEY;
1519 else
1520 auth_flag = HERMES_AUTH_OPEN;
1522 switch (priv->firmware_type) {
1523 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1524 if (priv->wep_on) {
1525 /* Enable the shared-key authentication. */
1526 err = hermes_write_wordrec(hw, USER_BAP,
1527 HERMES_RID_CNFAUTHENTICATION_AGERE,
1528 auth_flag);
1530 err = hermes_write_wordrec(hw, USER_BAP,
1531 HERMES_RID_CNFWEPENABLED_AGERE,
1532 priv->wep_on);
1533 if (err)
1534 return err;
1535 break;
1537 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1538 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1539 if (priv->wep_on) {
1540 if (priv->wep_restrict ||
1541 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1542 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1543 HERMES_WEP_EXCL_UNENCRYPTED;
1544 else
1545 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1547 err = hermes_write_wordrec(hw, USER_BAP,
1548 HERMES_RID_CNFAUTHENTICATION,
1549 auth_flag);
1550 if (err)
1551 return err;
1552 } else
1553 master_wep_flag = 0;
1555 if (priv->iw_mode == IW_MODE_MONITOR)
1556 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1558 /* Master WEP setting : on/off */
1559 err = hermes_write_wordrec(hw, USER_BAP,
1560 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1561 master_wep_flag);
1562 if (err)
1563 return err;
1565 break;
1568 return 0;
1571 static int __orinoco_program_rids(struct net_device *dev)
1573 struct orinoco_private *priv = netdev_priv(dev);
1574 hermes_t *hw = &priv->hw;
1575 int err;
1576 struct hermes_idstring idbuf;
1578 /* Set the MAC address */
1579 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1580 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1581 if (err) {
1582 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1583 dev->name, err);
1584 return err;
1587 /* Set up the link mode */
1588 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1589 priv->port_type);
1590 if (err) {
1591 printk(KERN_ERR "%s: Error %d setting port type\n",
1592 dev->name, err);
1593 return err;
1595 /* Set the channel/frequency */
1596 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1597 err = hermes_write_wordrec(hw, USER_BAP,
1598 HERMES_RID_CNFOWNCHANNEL,
1599 priv->channel);
1600 if (err) {
1601 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1602 dev->name, err, priv->channel);
1603 return err;
1607 if (priv->has_ibss) {
1608 u16 createibss;
1610 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1611 printk(KERN_WARNING "%s: This firmware requires an "
1612 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1613 /* With wvlan_cs, in this case, we would crash.
1614 * hopefully, this driver will behave better...
1615 * Jean II */
1616 createibss = 0;
1617 } else {
1618 createibss = priv->createibss;
1621 err = hermes_write_wordrec(hw, USER_BAP,
1622 HERMES_RID_CNFCREATEIBSS,
1623 createibss);
1624 if (err) {
1625 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1626 dev->name, err);
1627 return err;
1631 /* Set the desired BSSID */
1632 err = __orinoco_hw_set_wap(priv);
1633 if (err) {
1634 printk(KERN_ERR "%s: Error %d setting AP address\n",
1635 dev->name, err);
1636 return err;
1638 /* Set the desired ESSID */
1639 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1640 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1641 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1642 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1643 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1644 &idbuf);
1645 if (err) {
1646 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1647 dev->name, err);
1648 return err;
1650 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1651 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1652 &idbuf);
1653 if (err) {
1654 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1655 dev->name, err);
1656 return err;
1659 /* Set the station name */
1660 idbuf.len = cpu_to_le16(strlen(priv->nick));
1661 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1662 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1663 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1664 &idbuf);
1665 if (err) {
1666 printk(KERN_ERR "%s: Error %d setting nickname\n",
1667 dev->name, err);
1668 return err;
1671 /* Set AP density */
1672 if (priv->has_sensitivity) {
1673 err = hermes_write_wordrec(hw, USER_BAP,
1674 HERMES_RID_CNFSYSTEMSCALE,
1675 priv->ap_density);
1676 if (err) {
1677 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1678 "Disabling sensitivity control\n",
1679 dev->name, err);
1681 priv->has_sensitivity = 0;
1685 /* Set RTS threshold */
1686 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1687 priv->rts_thresh);
1688 if (err) {
1689 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1690 dev->name, err);
1691 return err;
1694 /* Set fragmentation threshold or MWO robustness */
1695 if (priv->has_mwo)
1696 err = hermes_write_wordrec(hw, USER_BAP,
1697 HERMES_RID_CNFMWOROBUST_AGERE,
1698 priv->mwo_robust);
1699 else
1700 err = hermes_write_wordrec(hw, USER_BAP,
1701 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1702 priv->frag_thresh);
1703 if (err) {
1704 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1705 dev->name, err);
1706 return err;
1709 /* Set bitrate */
1710 err = __orinoco_hw_set_bitrate(priv);
1711 if (err) {
1712 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1713 dev->name, err);
1714 return err;
1717 /* Set power management */
1718 if (priv->has_pm) {
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFPMENABLED,
1721 priv->pm_on);
1722 if (err) {
1723 printk(KERN_ERR "%s: Error %d setting up PM\n",
1724 dev->name, err);
1725 return err;
1728 err = hermes_write_wordrec(hw, USER_BAP,
1729 HERMES_RID_CNFMULTICASTRECEIVE,
1730 priv->pm_mcast);
1731 if (err) {
1732 printk(KERN_ERR "%s: Error %d setting up PM\n",
1733 dev->name, err);
1734 return err;
1736 err = hermes_write_wordrec(hw, USER_BAP,
1737 HERMES_RID_CNFMAXSLEEPDURATION,
1738 priv->pm_period);
1739 if (err) {
1740 printk(KERN_ERR "%s: Error %d setting up PM\n",
1741 dev->name, err);
1742 return err;
1744 err = hermes_write_wordrec(hw, USER_BAP,
1745 HERMES_RID_CNFPMHOLDOVERDURATION,
1746 priv->pm_timeout);
1747 if (err) {
1748 printk(KERN_ERR "%s: Error %d setting up PM\n",
1749 dev->name, err);
1750 return err;
1754 /* Set preamble - only for Symbol so far... */
1755 if (priv->has_preamble) {
1756 err = hermes_write_wordrec(hw, USER_BAP,
1757 HERMES_RID_CNFPREAMBLE_SYMBOL,
1758 priv->preamble);
1759 if (err) {
1760 printk(KERN_ERR "%s: Error %d setting preamble\n",
1761 dev->name, err);
1762 return err;
1766 /* Set up encryption */
1767 if (priv->has_wep) {
1768 err = __orinoco_hw_setup_wep(priv);
1769 if (err) {
1770 printk(KERN_ERR "%s: Error %d activating WEP\n",
1771 dev->name, err);
1772 return err;
1776 if (priv->iw_mode == IW_MODE_MONITOR) {
1777 /* Enable monitor mode */
1778 dev->type = ARPHRD_IEEE80211;
1779 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1780 HERMES_TEST_MONITOR, 0, NULL);
1781 } else {
1782 /* Disable monitor mode */
1783 dev->type = ARPHRD_ETHER;
1784 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1785 HERMES_TEST_STOP, 0, NULL);
1787 if (err)
1788 return err;
1790 /* Set promiscuity / multicast*/
1791 priv->promiscuous = 0;
1792 priv->mc_count = 0;
1793 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1795 return 0;
1798 /* FIXME: return int? */
1799 static void
1800 __orinoco_set_multicast_list(struct net_device *dev)
1802 struct orinoco_private *priv = netdev_priv(dev);
1803 hermes_t *hw = &priv->hw;
1804 int err = 0;
1805 int promisc, mc_count;
1807 /* The Hermes doesn't seem to have an allmulti mode, so we go
1808 * into promiscuous mode and let the upper levels deal. */
1809 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1810 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1811 promisc = 1;
1812 mc_count = 0;
1813 } else {
1814 promisc = 0;
1815 mc_count = dev->mc_count;
1818 if (promisc != priv->promiscuous) {
1819 err = hermes_write_wordrec(hw, USER_BAP,
1820 HERMES_RID_CNFPROMISCUOUSMODE,
1821 promisc);
1822 if (err) {
1823 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1824 dev->name, err);
1825 } else
1826 priv->promiscuous = promisc;
1829 /* If we're not in promiscuous mode, then we need to set the
1830 * group address if either we want to multicast, or if we were
1831 * multicasting and want to stop */
1832 if (! promisc && (mc_count || priv->mc_count) ) {
1833 struct dev_mc_list *p = dev->mc_list;
1834 struct hermes_multicast mclist;
1835 int i;
1837 for (i = 0; i < mc_count; i++) {
1838 /* paranoia: is list shorter than mc_count? */
1839 BUG_ON(! p);
1840 /* paranoia: bad address size in list? */
1841 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1843 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1844 p = p->next;
1847 if (p)
1848 printk(KERN_WARNING "%s: Multicast list is "
1849 "longer than mc_count\n", dev->name);
1851 err = hermes_write_ltv(hw, USER_BAP,
1852 HERMES_RID_CNFGROUPADDRESSES,
1853 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
1854 &mclist);
1855 if (err)
1856 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1857 dev->name, err);
1858 else
1859 priv->mc_count = mc_count;
1863 /* This must be called from user context, without locks held - use
1864 * schedule_work() */
1865 static void orinoco_reset(struct work_struct *work)
1867 struct orinoco_private *priv =
1868 container_of(work, struct orinoco_private, reset_work);
1869 struct net_device *dev = priv->ndev;
1870 struct hermes *hw = &priv->hw;
1871 int err;
1872 unsigned long flags;
1874 if (orinoco_lock(priv, &flags) != 0)
1875 /* When the hardware becomes available again, whatever
1876 * detects that is responsible for re-initializing
1877 * it. So no need for anything further */
1878 return;
1880 netif_stop_queue(dev);
1882 /* Shut off interrupts. Depending on what state the hardware
1883 * is in, this might not work, but we'll try anyway */
1884 hermes_set_irqmask(hw, 0);
1885 hermes_write_regn(hw, EVACK, 0xffff);
1887 priv->hw_unavailable++;
1888 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1889 netif_carrier_off(dev);
1891 orinoco_unlock(priv, &flags);
1893 /* Scanning support: Cleanup of driver struct */
1894 kfree(priv->scan_result);
1895 priv->scan_result = NULL;
1896 priv->scan_inprogress = 0;
1898 if (priv->hard_reset) {
1899 err = (*priv->hard_reset)(priv);
1900 if (err) {
1901 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1902 "performing hard reset\n", dev->name, err);
1903 goto disable;
1907 err = orinoco_reinit_firmware(dev);
1908 if (err) {
1909 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1910 dev->name, err);
1911 goto disable;
1914 orinoco_spin_lock(priv); /* This has to be called from user context */
1916 priv->hw_unavailable--;
1918 /* priv->open or priv->hw_unavailable might have changed while
1919 * we dropped the lock */
1920 if (priv->open && (! priv->hw_unavailable)) {
1921 err = __orinoco_up(dev);
1922 if (err) {
1923 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1924 dev->name, err);
1925 } else
1926 dev->trans_start = jiffies;
1929 orinoco_spin_unlock(priv);
1931 return;
1932 disable:
1933 hermes_set_irqmask(hw, 0);
1934 netif_device_detach(dev);
1935 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1938 /********************************************************************/
1939 /* Interrupt handler */
1940 /********************************************************************/
1942 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1944 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1947 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1949 /* This seems to happen a fair bit under load, but ignoring it
1950 seems to work fine...*/
1951 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1952 dev->name);
1955 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
1957 struct net_device *dev = dev_id;
1958 struct orinoco_private *priv = netdev_priv(dev);
1959 hermes_t *hw = &priv->hw;
1960 int count = MAX_IRQLOOPS_PER_IRQ;
1961 u16 evstat, events;
1962 /* These are used to detect a runaway interrupt situation */
1963 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1964 * we panic and shut down the hardware */
1965 static int last_irq_jiffy = 0; /* jiffies value the last time
1966 * we were called */
1967 static int loops_this_jiffy = 0;
1968 unsigned long flags;
1970 if (orinoco_lock(priv, &flags) != 0) {
1971 /* If hw is unavailable - we don't know if the irq was
1972 * for us or not */
1973 return IRQ_HANDLED;
1976 evstat = hermes_read_regn(hw, EVSTAT);
1977 events = evstat & hw->inten;
1978 if (! events) {
1979 orinoco_unlock(priv, &flags);
1980 return IRQ_NONE;
1983 if (jiffies != last_irq_jiffy)
1984 loops_this_jiffy = 0;
1985 last_irq_jiffy = jiffies;
1987 while (events && count--) {
1988 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1989 printk(KERN_WARNING "%s: IRQ handler is looping too "
1990 "much! Resetting.\n", dev->name);
1991 /* Disable interrupts for now */
1992 hermes_set_irqmask(hw, 0);
1993 schedule_work(&priv->reset_work);
1994 break;
1997 /* Check the card hasn't been removed */
1998 if (! hermes_present(hw)) {
1999 DEBUG(0, "orinoco_interrupt(): card removed\n");
2000 break;
2003 if (events & HERMES_EV_TICK)
2004 __orinoco_ev_tick(dev, hw);
2005 if (events & HERMES_EV_WTERR)
2006 __orinoco_ev_wterr(dev, hw);
2007 if (events & HERMES_EV_INFDROP)
2008 __orinoco_ev_infdrop(dev, hw);
2009 if (events & HERMES_EV_INFO)
2010 __orinoco_ev_info(dev, hw);
2011 if (events & HERMES_EV_RX)
2012 __orinoco_ev_rx(dev, hw);
2013 if (events & HERMES_EV_TXEXC)
2014 __orinoco_ev_txexc(dev, hw);
2015 if (events & HERMES_EV_TX)
2016 __orinoco_ev_tx(dev, hw);
2017 if (events & HERMES_EV_ALLOC)
2018 __orinoco_ev_alloc(dev, hw);
2020 hermes_write_regn(hw, EVACK, evstat);
2022 evstat = hermes_read_regn(hw, EVSTAT);
2023 events = evstat & hw->inten;
2026 orinoco_unlock(priv, &flags);
2027 return IRQ_HANDLED;
2030 /********************************************************************/
2031 /* Initialization */
2032 /********************************************************************/
2034 struct comp_id {
2035 u16 id, variant, major, minor;
2036 } __attribute__ ((packed));
2038 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2040 if (nic_id->id < 0x8000)
2041 return FIRMWARE_TYPE_AGERE;
2042 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2043 return FIRMWARE_TYPE_SYMBOL;
2044 else
2045 return FIRMWARE_TYPE_INTERSIL;
2048 /* Set priv->firmware type, determine firmware properties */
2049 static int determine_firmware(struct net_device *dev)
2051 struct orinoco_private *priv = netdev_priv(dev);
2052 hermes_t *hw = &priv->hw;
2053 int err;
2054 struct comp_id nic_id, sta_id;
2055 unsigned int firmver;
2056 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2058 /* Get the hardware version */
2059 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2060 if (err) {
2061 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2062 dev->name, err);
2063 return err;
2066 le16_to_cpus(&nic_id.id);
2067 le16_to_cpus(&nic_id.variant);
2068 le16_to_cpus(&nic_id.major);
2069 le16_to_cpus(&nic_id.minor);
2070 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2071 dev->name, nic_id.id, nic_id.variant,
2072 nic_id.major, nic_id.minor);
2074 priv->firmware_type = determine_firmware_type(&nic_id);
2076 /* Get the firmware version */
2077 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2078 if (err) {
2079 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2080 dev->name, err);
2081 return err;
2084 le16_to_cpus(&sta_id.id);
2085 le16_to_cpus(&sta_id.variant);
2086 le16_to_cpus(&sta_id.major);
2087 le16_to_cpus(&sta_id.minor);
2088 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2089 dev->name, sta_id.id, sta_id.variant,
2090 sta_id.major, sta_id.minor);
2092 switch (sta_id.id) {
2093 case 0x15:
2094 printk(KERN_ERR "%s: Primary firmware is active\n",
2095 dev->name);
2096 return -ENODEV;
2097 case 0x14b:
2098 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2099 dev->name);
2100 return -ENODEV;
2101 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2102 case 0x21: /* Symbol Spectrum24 Trilogy */
2103 break;
2104 default:
2105 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2106 dev->name);
2107 break;
2110 /* Default capabilities */
2111 priv->has_sensitivity = 1;
2112 priv->has_mwo = 0;
2113 priv->has_preamble = 0;
2114 priv->has_port3 = 1;
2115 priv->has_ibss = 1;
2116 priv->has_wep = 0;
2117 priv->has_big_wep = 0;
2119 /* Determine capabilities from the firmware version */
2120 switch (priv->firmware_type) {
2121 case FIRMWARE_TYPE_AGERE:
2122 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2123 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2124 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2125 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2127 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2129 priv->has_ibss = (firmver >= 0x60006);
2130 priv->has_wep = (firmver >= 0x40020);
2131 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2132 Gold cards from the others? */
2133 priv->has_mwo = (firmver >= 0x60000);
2134 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2135 priv->ibss_port = 1;
2136 priv->has_hostscan = (firmver >= 0x8000a);
2137 priv->broken_monitor = (firmver >= 0x80000);
2139 /* Tested with Agere firmware :
2140 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2141 * Tested CableTron firmware : 4.32 => Anton */
2142 break;
2143 case FIRMWARE_TYPE_SYMBOL:
2144 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2145 /* Intel MAC : 00:02:B3:* */
2146 /* 3Com MAC : 00:50:DA:* */
2147 memset(tmp, 0, sizeof(tmp));
2148 /* Get the Symbol firmware version */
2149 err = hermes_read_ltv(hw, USER_BAP,
2150 HERMES_RID_SECONDARYVERSION_SYMBOL,
2151 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2152 if (err) {
2153 printk(KERN_WARNING
2154 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2155 dev->name, err);
2156 firmver = 0;
2157 tmp[0] = '\0';
2158 } else {
2159 /* The firmware revision is a string, the format is
2160 * something like : "V2.20-01".
2161 * Quick and dirty parsing... - Jean II
2163 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2164 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2165 | (tmp[7] - '0');
2167 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2170 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2171 "Symbol %s", tmp);
2173 priv->has_ibss = (firmver >= 0x20000);
2174 priv->has_wep = (firmver >= 0x15012);
2175 priv->has_big_wep = (firmver >= 0x20000);
2176 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2177 (firmver >= 0x29000 && firmver < 0x30000) ||
2178 firmver >= 0x31000;
2179 priv->has_preamble = (firmver >= 0x20000);
2180 priv->ibss_port = 4;
2181 priv->broken_disableport = (firmver == 0x25013) ||
2182 (firmver >= 0x30000 && firmver <= 0x31000);
2183 priv->has_hostscan = (firmver >= 0x31001) ||
2184 (firmver >= 0x29057 && firmver < 0x30000);
2185 /* Tested with Intel firmware : 0x20015 => Jean II */
2186 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2187 break;
2188 case FIRMWARE_TYPE_INTERSIL:
2189 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2190 * Samsung, Compaq 100/200 and Proxim are slightly
2191 * different and less well tested */
2192 /* D-Link MAC : 00:40:05:* */
2193 /* Addtron MAC : 00:90:D1:* */
2194 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2195 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2196 sta_id.variant);
2198 firmver = ((unsigned long)sta_id.major << 16) |
2199 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2201 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2202 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2203 priv->has_pm = (firmver >= 0x000700);
2204 priv->has_hostscan = (firmver >= 0x010301);
2206 if (firmver >= 0x000800)
2207 priv->ibss_port = 0;
2208 else {
2209 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2210 "than v0.8.x - several features not supported\n",
2211 dev->name);
2212 priv->ibss_port = 1;
2214 break;
2216 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2217 priv->fw_name);
2219 return 0;
2222 static int orinoco_init(struct net_device *dev)
2224 struct orinoco_private *priv = netdev_priv(dev);
2225 hermes_t *hw = &priv->hw;
2226 int err = 0;
2227 struct hermes_idstring nickbuf;
2228 u16 reclen;
2229 int len;
2230 DECLARE_MAC_BUF(mac);
2232 /* No need to lock, the hw_unavailable flag is already set in
2233 * alloc_orinocodev() */
2234 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2236 /* Initialize the firmware */
2237 err = hermes_init(hw);
2238 if (err != 0) {
2239 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2240 dev->name, err);
2241 goto out;
2244 err = determine_firmware(dev);
2245 if (err != 0) {
2246 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2247 dev->name);
2248 goto out;
2251 if (priv->has_port3)
2252 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2253 if (priv->has_ibss)
2254 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2255 dev->name);
2256 if (!priv->has_big_wep)
2257 printk(KERN_NOTICE "%s: Only 40-bit WEP keys supported\n",
2258 dev->name);
2260 /* Get the MAC address */
2261 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2262 ETH_ALEN, NULL, dev->dev_addr);
2263 if (err) {
2264 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2265 dev->name);
2266 goto out;
2269 printk(KERN_DEBUG "%s: MAC address %s\n",
2270 dev->name, print_mac(mac, dev->dev_addr));
2272 /* Get the station name */
2273 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2274 sizeof(nickbuf), &reclen, &nickbuf);
2275 if (err) {
2276 printk(KERN_ERR "%s: failed to read station name\n",
2277 dev->name);
2278 goto out;
2280 if (nickbuf.len)
2281 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2282 else
2283 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2284 memcpy(priv->nick, &nickbuf.val, len);
2285 priv->nick[len] = '\0';
2287 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2289 err = orinoco_allocate_fid(dev);
2290 if (err) {
2291 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2292 dev->name);
2293 goto out;
2296 /* Get allowed channels */
2297 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2298 &priv->channel_mask);
2299 if (err) {
2300 printk(KERN_ERR "%s: failed to read channel list!\n",
2301 dev->name);
2302 goto out;
2305 /* Get initial AP density */
2306 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2307 &priv->ap_density);
2308 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2309 priv->has_sensitivity = 0;
2312 /* Get initial RTS threshold */
2313 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2314 &priv->rts_thresh);
2315 if (err) {
2316 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2317 dev->name);
2318 goto out;
2321 /* Get initial fragmentation settings */
2322 if (priv->has_mwo)
2323 err = hermes_read_wordrec(hw, USER_BAP,
2324 HERMES_RID_CNFMWOROBUST_AGERE,
2325 &priv->mwo_robust);
2326 else
2327 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2328 &priv->frag_thresh);
2329 if (err) {
2330 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2331 dev->name);
2332 goto out;
2335 /* Power management setup */
2336 if (priv->has_pm) {
2337 priv->pm_on = 0;
2338 priv->pm_mcast = 1;
2339 err = hermes_read_wordrec(hw, USER_BAP,
2340 HERMES_RID_CNFMAXSLEEPDURATION,
2341 &priv->pm_period);
2342 if (err) {
2343 printk(KERN_ERR "%s: failed to read power management period!\n",
2344 dev->name);
2345 goto out;
2347 err = hermes_read_wordrec(hw, USER_BAP,
2348 HERMES_RID_CNFPMHOLDOVERDURATION,
2349 &priv->pm_timeout);
2350 if (err) {
2351 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2352 dev->name);
2353 goto out;
2357 /* Preamble setup */
2358 if (priv->has_preamble) {
2359 err = hermes_read_wordrec(hw, USER_BAP,
2360 HERMES_RID_CNFPREAMBLE_SYMBOL,
2361 &priv->preamble);
2362 if (err)
2363 goto out;
2366 /* Set up the default configuration */
2367 priv->iw_mode = IW_MODE_INFRA;
2368 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2369 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2370 set_port_type(priv);
2371 priv->channel = 0; /* use firmware default */
2373 priv->promiscuous = 0;
2374 priv->wep_on = 0;
2375 priv->tx_key = 0;
2377 /* Make the hardware available, as long as it hasn't been
2378 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2379 orinoco_spin_lock(priv);
2380 priv->hw_unavailable--;
2381 orinoco_spin_unlock(priv);
2383 printk(KERN_DEBUG "%s: ready\n", dev->name);
2385 out:
2386 return err;
2389 struct net_device *alloc_orinocodev(int sizeof_card,
2390 int (*hard_reset)(struct orinoco_private *))
2392 struct net_device *dev;
2393 struct orinoco_private *priv;
2395 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2396 if (! dev)
2397 return NULL;
2398 priv = netdev_priv(dev);
2399 priv->ndev = dev;
2400 if (sizeof_card)
2401 priv->card = (void *)((unsigned long)priv
2402 + sizeof(struct orinoco_private));
2403 else
2404 priv->card = NULL;
2406 /* Setup / override net_device fields */
2407 dev->init = orinoco_init;
2408 dev->hard_start_xmit = orinoco_xmit;
2409 dev->tx_timeout = orinoco_tx_timeout;
2410 dev->watchdog_timeo = HZ; /* 1 second timeout */
2411 dev->get_stats = orinoco_get_stats;
2412 dev->ethtool_ops = &orinoco_ethtool_ops;
2413 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2414 #ifdef WIRELESS_SPY
2415 priv->wireless_data.spy_data = &priv->spy_data;
2416 dev->wireless_data = &priv->wireless_data;
2417 #endif
2418 dev->change_mtu = orinoco_change_mtu;
2419 dev->set_multicast_list = orinoco_set_multicast_list;
2420 /* we use the default eth_mac_addr for setting the MAC addr */
2422 /* Set up default callbacks */
2423 dev->open = orinoco_open;
2424 dev->stop = orinoco_stop;
2425 priv->hard_reset = hard_reset;
2427 spin_lock_init(&priv->lock);
2428 priv->open = 0;
2429 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2430 * before anything else touches the
2431 * hardware */
2432 INIT_WORK(&priv->reset_work, orinoco_reset);
2433 INIT_WORK(&priv->join_work, orinoco_join_ap);
2434 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2436 netif_carrier_off(dev);
2437 priv->last_linkstatus = 0xffff;
2439 return dev;
2442 void free_orinocodev(struct net_device *dev)
2444 struct orinoco_private *priv = netdev_priv(dev);
2446 kfree(priv->scan_result);
2447 free_netdev(dev);
2450 /********************************************************************/
2451 /* Wireless extensions */
2452 /********************************************************************/
2454 /* Return : < 0 -> error code ; >= 0 -> length */
2455 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2456 char buf[IW_ESSID_MAX_SIZE+1])
2458 hermes_t *hw = &priv->hw;
2459 int err = 0;
2460 struct hermes_idstring essidbuf;
2461 char *p = (char *)(&essidbuf.val);
2462 int len;
2463 unsigned long flags;
2465 if (orinoco_lock(priv, &flags) != 0)
2466 return -EBUSY;
2468 if (strlen(priv->desired_essid) > 0) {
2469 /* We read the desired SSID from the hardware rather
2470 than from priv->desired_essid, just in case the
2471 firmware is allowed to change it on us. I'm not
2472 sure about this */
2473 /* My guess is that the OWNSSID should always be whatever
2474 * we set to the card, whereas CURRENT_SSID is the one that
2475 * may change... - Jean II */
2476 u16 rid;
2478 *active = 1;
2480 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2481 HERMES_RID_CNFDESIREDSSID;
2483 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2484 NULL, &essidbuf);
2485 if (err)
2486 goto fail_unlock;
2487 } else {
2488 *active = 0;
2490 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2491 sizeof(essidbuf), NULL, &essidbuf);
2492 if (err)
2493 goto fail_unlock;
2496 len = le16_to_cpu(essidbuf.len);
2497 BUG_ON(len > IW_ESSID_MAX_SIZE);
2499 memset(buf, 0, IW_ESSID_MAX_SIZE);
2500 memcpy(buf, p, len);
2501 err = len;
2503 fail_unlock:
2504 orinoco_unlock(priv, &flags);
2506 return err;
2509 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2512 hermes_t *hw = &priv->hw;
2513 int err = 0;
2514 u16 channel;
2515 long freq = 0;
2516 unsigned long flags;
2518 if (orinoco_lock(priv, &flags) != 0)
2519 return -EBUSY;
2521 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2522 if (err)
2523 goto out;
2525 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2526 if (channel == 0) {
2527 err = -EBUSY;
2528 goto out;
2531 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2532 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2533 priv->ndev->name, channel);
2534 err = -EBUSY;
2535 goto out;
2538 freq = channel_frequency[channel-1] * 100000;
2540 out:
2541 orinoco_unlock(priv, &flags);
2543 if (err > 0)
2544 err = -EBUSY;
2545 return err ? err : freq;
2548 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2549 int *numrates, s32 *rates, int max)
2551 hermes_t *hw = &priv->hw;
2552 struct hermes_idstring list;
2553 unsigned char *p = (unsigned char *)&list.val;
2554 int err = 0;
2555 int num;
2556 int i;
2557 unsigned long flags;
2559 if (orinoco_lock(priv, &flags) != 0)
2560 return -EBUSY;
2562 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2563 sizeof(list), NULL, &list);
2564 orinoco_unlock(priv, &flags);
2566 if (err)
2567 return err;
2569 num = le16_to_cpu(list.len);
2570 *numrates = num;
2571 num = min(num, max);
2573 for (i = 0; i < num; i++) {
2574 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2577 return 0;
2580 static int orinoco_ioctl_getname(struct net_device *dev,
2581 struct iw_request_info *info,
2582 char *name,
2583 char *extra)
2585 struct orinoco_private *priv = netdev_priv(dev);
2586 int numrates;
2587 int err;
2589 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2591 if (!err && (numrates > 2))
2592 strcpy(name, "IEEE 802.11b");
2593 else
2594 strcpy(name, "IEEE 802.11-DS");
2596 return 0;
2599 static int orinoco_ioctl_setwap(struct net_device *dev,
2600 struct iw_request_info *info,
2601 struct sockaddr *ap_addr,
2602 char *extra)
2604 struct orinoco_private *priv = netdev_priv(dev);
2605 int err = -EINPROGRESS; /* Call commit handler */
2606 unsigned long flags;
2607 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2608 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2610 if (orinoco_lock(priv, &flags) != 0)
2611 return -EBUSY;
2613 /* Enable automatic roaming - no sanity checks are needed */
2614 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2615 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2616 priv->bssid_fixed = 0;
2617 memset(priv->desired_bssid, 0, ETH_ALEN);
2619 /* "off" means keep existing connection */
2620 if (ap_addr->sa_data[0] == 0) {
2621 __orinoco_hw_set_wap(priv);
2622 err = 0;
2624 goto out;
2627 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2628 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2629 "support manual roaming\n",
2630 dev->name);
2631 err = -EOPNOTSUPP;
2632 goto out;
2635 if (priv->iw_mode != IW_MODE_INFRA) {
2636 printk(KERN_WARNING "%s: Manual roaming supported only in "
2637 "managed mode\n", dev->name);
2638 err = -EOPNOTSUPP;
2639 goto out;
2642 /* Intersil firmware hangs without Desired ESSID */
2643 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2644 strlen(priv->desired_essid) == 0) {
2645 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2646 "manual roaming\n", dev->name);
2647 err = -EOPNOTSUPP;
2648 goto out;
2651 /* Finally, enable manual roaming */
2652 priv->bssid_fixed = 1;
2653 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2655 out:
2656 orinoco_unlock(priv, &flags);
2657 return err;
2660 static int orinoco_ioctl_getwap(struct net_device *dev,
2661 struct iw_request_info *info,
2662 struct sockaddr *ap_addr,
2663 char *extra)
2665 struct orinoco_private *priv = netdev_priv(dev);
2667 hermes_t *hw = &priv->hw;
2668 int err = 0;
2669 unsigned long flags;
2671 if (orinoco_lock(priv, &flags) != 0)
2672 return -EBUSY;
2674 ap_addr->sa_family = ARPHRD_ETHER;
2675 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2676 ETH_ALEN, NULL, ap_addr->sa_data);
2678 orinoco_unlock(priv, &flags);
2680 return err;
2683 static int orinoco_ioctl_setmode(struct net_device *dev,
2684 struct iw_request_info *info,
2685 u32 *mode,
2686 char *extra)
2688 struct orinoco_private *priv = netdev_priv(dev);
2689 int err = -EINPROGRESS; /* Call commit handler */
2690 unsigned long flags;
2692 if (priv->iw_mode == *mode)
2693 return 0;
2695 if (orinoco_lock(priv, &flags) != 0)
2696 return -EBUSY;
2698 switch (*mode) {
2699 case IW_MODE_ADHOC:
2700 if (!priv->has_ibss && !priv->has_port3)
2701 err = -EOPNOTSUPP;
2702 break;
2704 case IW_MODE_INFRA:
2705 break;
2707 case IW_MODE_MONITOR:
2708 if (priv->broken_monitor && !force_monitor) {
2709 printk(KERN_WARNING "%s: Monitor mode support is "
2710 "buggy in this firmware, not enabling\n",
2711 dev->name);
2712 err = -EOPNOTSUPP;
2714 break;
2716 default:
2717 err = -EOPNOTSUPP;
2718 break;
2721 if (err == -EINPROGRESS) {
2722 priv->iw_mode = *mode;
2723 set_port_type(priv);
2726 orinoco_unlock(priv, &flags);
2728 return err;
2731 static int orinoco_ioctl_getmode(struct net_device *dev,
2732 struct iw_request_info *info,
2733 u32 *mode,
2734 char *extra)
2736 struct orinoco_private *priv = netdev_priv(dev);
2738 *mode = priv->iw_mode;
2739 return 0;
2742 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2743 struct iw_request_info *info,
2744 struct iw_point *rrq,
2745 char *extra)
2747 struct orinoco_private *priv = netdev_priv(dev);
2748 int err = 0;
2749 struct iw_range *range = (struct iw_range *) extra;
2750 int numrates;
2751 int i, k;
2753 rrq->length = sizeof(struct iw_range);
2754 memset(range, 0, sizeof(struct iw_range));
2756 range->we_version_compiled = WIRELESS_EXT;
2757 range->we_version_source = 14;
2759 /* Set available channels/frequencies */
2760 range->num_channels = NUM_CHANNELS;
2761 k = 0;
2762 for (i = 0; i < NUM_CHANNELS; i++) {
2763 if (priv->channel_mask & (1 << i)) {
2764 range->freq[k].i = i + 1;
2765 range->freq[k].m = channel_frequency[i] * 100000;
2766 range->freq[k].e = 1;
2767 k++;
2770 if (k >= IW_MAX_FREQUENCIES)
2771 break;
2773 range->num_frequency = k;
2774 range->sensitivity = 3;
2776 if (priv->has_wep) {
2777 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2778 range->encoding_size[0] = SMALL_KEY_SIZE;
2779 range->num_encoding_sizes = 1;
2781 if (priv->has_big_wep) {
2782 range->encoding_size[1] = LARGE_KEY_SIZE;
2783 range->num_encoding_sizes = 2;
2787 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2788 /* Quality stats meaningless in ad-hoc mode */
2789 } else {
2790 range->max_qual.qual = 0x8b - 0x2f;
2791 range->max_qual.level = 0x2f - 0x95 - 1;
2792 range->max_qual.noise = 0x2f - 0x95 - 1;
2793 /* Need to get better values */
2794 range->avg_qual.qual = 0x24;
2795 range->avg_qual.level = 0xC2;
2796 range->avg_qual.noise = 0x9E;
2799 err = orinoco_hw_get_bitratelist(priv, &numrates,
2800 range->bitrate, IW_MAX_BITRATES);
2801 if (err)
2802 return err;
2803 range->num_bitrates = numrates;
2805 /* Set an indication of the max TCP throughput in bit/s that we can
2806 * expect using this interface. May be use for QoS stuff...
2807 * Jean II */
2808 if (numrates > 2)
2809 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2810 else
2811 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2813 range->min_rts = 0;
2814 range->max_rts = 2347;
2815 range->min_frag = 256;
2816 range->max_frag = 2346;
2818 range->min_pmp = 0;
2819 range->max_pmp = 65535000;
2820 range->min_pmt = 0;
2821 range->max_pmt = 65535 * 1000; /* ??? */
2822 range->pmp_flags = IW_POWER_PERIOD;
2823 range->pmt_flags = IW_POWER_TIMEOUT;
2824 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2826 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2827 range->retry_flags = IW_RETRY_LIMIT;
2828 range->r_time_flags = IW_RETRY_LIFETIME;
2829 range->min_retry = 0;
2830 range->max_retry = 65535; /* ??? */
2831 range->min_r_time = 0;
2832 range->max_r_time = 65535 * 1000; /* ??? */
2834 /* Event capability (kernel) */
2835 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2836 /* Event capability (driver) */
2837 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2838 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2839 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2840 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2842 return 0;
2845 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2846 struct iw_request_info *info,
2847 struct iw_point *erq,
2848 char *keybuf)
2850 struct orinoco_private *priv = netdev_priv(dev);
2851 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2852 int setindex = priv->tx_key;
2853 int enable = priv->wep_on;
2854 int restricted = priv->wep_restrict;
2855 u16 xlen = 0;
2856 int err = -EINPROGRESS; /* Call commit handler */
2857 unsigned long flags;
2859 if (! priv->has_wep)
2860 return -EOPNOTSUPP;
2862 if (erq->pointer) {
2863 /* We actually have a key to set - check its length */
2864 if (erq->length > LARGE_KEY_SIZE)
2865 return -E2BIG;
2867 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2868 return -E2BIG;
2871 if (orinoco_lock(priv, &flags) != 0)
2872 return -EBUSY;
2874 if (erq->pointer) {
2875 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2876 index = priv->tx_key;
2878 /* Adjust key length to a supported value */
2879 if (erq->length > SMALL_KEY_SIZE) {
2880 xlen = LARGE_KEY_SIZE;
2881 } else if (erq->length > 0) {
2882 xlen = SMALL_KEY_SIZE;
2883 } else
2884 xlen = 0;
2886 /* Switch on WEP if off */
2887 if ((!enable) && (xlen > 0)) {
2888 setindex = index;
2889 enable = 1;
2891 } else {
2892 /* Important note : if the user do "iwconfig eth0 enc off",
2893 * we will arrive there with an index of -1. This is valid
2894 * but need to be taken care off... Jean II */
2895 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2896 if((index != -1) || (erq->flags == 0)) {
2897 err = -EINVAL;
2898 goto out;
2900 } else {
2901 /* Set the index : Check that the key is valid */
2902 if(priv->keys[index].len == 0) {
2903 err = -EINVAL;
2904 goto out;
2906 setindex = index;
2910 if (erq->flags & IW_ENCODE_DISABLED)
2911 enable = 0;
2912 if (erq->flags & IW_ENCODE_OPEN)
2913 restricted = 0;
2914 if (erq->flags & IW_ENCODE_RESTRICTED)
2915 restricted = 1;
2917 if (erq->pointer) {
2918 priv->keys[index].len = cpu_to_le16(xlen);
2919 memset(priv->keys[index].data, 0,
2920 sizeof(priv->keys[index].data));
2921 memcpy(priv->keys[index].data, keybuf, erq->length);
2923 priv->tx_key = setindex;
2925 /* Try fast key change if connected and only keys are changed */
2926 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2927 netif_carrier_ok(dev)) {
2928 err = __orinoco_hw_setup_wepkeys(priv);
2929 /* No need to commit if successful */
2930 goto out;
2933 priv->wep_on = enable;
2934 priv->wep_restrict = restricted;
2936 out:
2937 orinoco_unlock(priv, &flags);
2939 return err;
2942 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2943 struct iw_request_info *info,
2944 struct iw_point *erq,
2945 char *keybuf)
2947 struct orinoco_private *priv = netdev_priv(dev);
2948 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2949 u16 xlen = 0;
2950 unsigned long flags;
2952 if (! priv->has_wep)
2953 return -EOPNOTSUPP;
2955 if (orinoco_lock(priv, &flags) != 0)
2956 return -EBUSY;
2958 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2959 index = priv->tx_key;
2961 erq->flags = 0;
2962 if (! priv->wep_on)
2963 erq->flags |= IW_ENCODE_DISABLED;
2964 erq->flags |= index + 1;
2966 if (priv->wep_restrict)
2967 erq->flags |= IW_ENCODE_RESTRICTED;
2968 else
2969 erq->flags |= IW_ENCODE_OPEN;
2971 xlen = le16_to_cpu(priv->keys[index].len);
2973 erq->length = xlen;
2975 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2977 orinoco_unlock(priv, &flags);
2978 return 0;
2981 static int orinoco_ioctl_setessid(struct net_device *dev,
2982 struct iw_request_info *info,
2983 struct iw_point *erq,
2984 char *essidbuf)
2986 struct orinoco_private *priv = netdev_priv(dev);
2987 unsigned long flags;
2989 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2990 * anyway... - Jean II */
2992 /* Hum... Should not use Wireless Extension constant (may change),
2993 * should use our own... - Jean II */
2994 if (erq->length > IW_ESSID_MAX_SIZE)
2995 return -E2BIG;
2997 if (orinoco_lock(priv, &flags) != 0)
2998 return -EBUSY;
3000 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3001 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3003 /* If not ANY, get the new ESSID */
3004 if (erq->flags) {
3005 memcpy(priv->desired_essid, essidbuf, erq->length);
3008 orinoco_unlock(priv, &flags);
3010 return -EINPROGRESS; /* Call commit handler */
3013 static int orinoco_ioctl_getessid(struct net_device *dev,
3014 struct iw_request_info *info,
3015 struct iw_point *erq,
3016 char *essidbuf)
3018 struct orinoco_private *priv = netdev_priv(dev);
3019 int active;
3020 int err = 0;
3021 unsigned long flags;
3023 if (netif_running(dev)) {
3024 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3025 if (err < 0)
3026 return err;
3027 erq->length = err;
3028 } else {
3029 if (orinoco_lock(priv, &flags) != 0)
3030 return -EBUSY;
3031 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3032 erq->length = strlen(priv->desired_essid);
3033 orinoco_unlock(priv, &flags);
3036 erq->flags = 1;
3038 return 0;
3041 static int orinoco_ioctl_setnick(struct net_device *dev,
3042 struct iw_request_info *info,
3043 struct iw_point *nrq,
3044 char *nickbuf)
3046 struct orinoco_private *priv = netdev_priv(dev);
3047 unsigned long flags;
3049 if (nrq->length > IW_ESSID_MAX_SIZE)
3050 return -E2BIG;
3052 if (orinoco_lock(priv, &flags) != 0)
3053 return -EBUSY;
3055 memset(priv->nick, 0, sizeof(priv->nick));
3056 memcpy(priv->nick, nickbuf, nrq->length);
3058 orinoco_unlock(priv, &flags);
3060 return -EINPROGRESS; /* Call commit handler */
3063 static int orinoco_ioctl_getnick(struct net_device *dev,
3064 struct iw_request_info *info,
3065 struct iw_point *nrq,
3066 char *nickbuf)
3068 struct orinoco_private *priv = netdev_priv(dev);
3069 unsigned long flags;
3071 if (orinoco_lock(priv, &flags) != 0)
3072 return -EBUSY;
3074 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3075 orinoco_unlock(priv, &flags);
3077 nrq->length = strlen(priv->nick);
3079 return 0;
3082 static int orinoco_ioctl_setfreq(struct net_device *dev,
3083 struct iw_request_info *info,
3084 struct iw_freq *frq,
3085 char *extra)
3087 struct orinoco_private *priv = netdev_priv(dev);
3088 int chan = -1;
3089 unsigned long flags;
3090 int err = -EINPROGRESS; /* Call commit handler */
3092 /* In infrastructure mode the AP sets the channel */
3093 if (priv->iw_mode == IW_MODE_INFRA)
3094 return -EBUSY;
3096 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3097 /* Setting by channel number */
3098 chan = frq->m;
3099 } else {
3100 /* Setting by frequency - search the table */
3101 int mult = 1;
3102 int i;
3104 for (i = 0; i < (6 - frq->e); i++)
3105 mult *= 10;
3107 for (i = 0; i < NUM_CHANNELS; i++)
3108 if (frq->m == (channel_frequency[i] * mult))
3109 chan = i+1;
3112 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3113 ! (priv->channel_mask & (1 << (chan-1)) ) )
3114 return -EINVAL;
3116 if (orinoco_lock(priv, &flags) != 0)
3117 return -EBUSY;
3119 priv->channel = chan;
3120 if (priv->iw_mode == IW_MODE_MONITOR) {
3121 /* Fast channel change - no commit if successful */
3122 hermes_t *hw = &priv->hw;
3123 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3124 HERMES_TEST_SET_CHANNEL,
3125 chan, NULL);
3127 orinoco_unlock(priv, &flags);
3129 return err;
3132 static int orinoco_ioctl_getfreq(struct net_device *dev,
3133 struct iw_request_info *info,
3134 struct iw_freq *frq,
3135 char *extra)
3137 struct orinoco_private *priv = netdev_priv(dev);
3138 int tmp;
3140 /* Locking done in there */
3141 tmp = orinoco_hw_get_freq(priv);
3142 if (tmp < 0) {
3143 return tmp;
3146 frq->m = tmp;
3147 frq->e = 1;
3149 return 0;
3152 static int orinoco_ioctl_getsens(struct net_device *dev,
3153 struct iw_request_info *info,
3154 struct iw_param *srq,
3155 char *extra)
3157 struct orinoco_private *priv = netdev_priv(dev);
3158 hermes_t *hw = &priv->hw;
3159 u16 val;
3160 int err;
3161 unsigned long flags;
3163 if (!priv->has_sensitivity)
3164 return -EOPNOTSUPP;
3166 if (orinoco_lock(priv, &flags) != 0)
3167 return -EBUSY;
3168 err = hermes_read_wordrec(hw, USER_BAP,
3169 HERMES_RID_CNFSYSTEMSCALE, &val);
3170 orinoco_unlock(priv, &flags);
3172 if (err)
3173 return err;
3175 srq->value = val;
3176 srq->fixed = 0; /* auto */
3178 return 0;
3181 static int orinoco_ioctl_setsens(struct net_device *dev,
3182 struct iw_request_info *info,
3183 struct iw_param *srq,
3184 char *extra)
3186 struct orinoco_private *priv = netdev_priv(dev);
3187 int val = srq->value;
3188 unsigned long flags;
3190 if (!priv->has_sensitivity)
3191 return -EOPNOTSUPP;
3193 if ((val < 1) || (val > 3))
3194 return -EINVAL;
3196 if (orinoco_lock(priv, &flags) != 0)
3197 return -EBUSY;
3198 priv->ap_density = val;
3199 orinoco_unlock(priv, &flags);
3201 return -EINPROGRESS; /* Call commit handler */
3204 static int orinoco_ioctl_setrts(struct net_device *dev,
3205 struct iw_request_info *info,
3206 struct iw_param *rrq,
3207 char *extra)
3209 struct orinoco_private *priv = netdev_priv(dev);
3210 int val = rrq->value;
3211 unsigned long flags;
3213 if (rrq->disabled)
3214 val = 2347;
3216 if ( (val < 0) || (val > 2347) )
3217 return -EINVAL;
3219 if (orinoco_lock(priv, &flags) != 0)
3220 return -EBUSY;
3222 priv->rts_thresh = val;
3223 orinoco_unlock(priv, &flags);
3225 return -EINPROGRESS; /* Call commit handler */
3228 static int orinoco_ioctl_getrts(struct net_device *dev,
3229 struct iw_request_info *info,
3230 struct iw_param *rrq,
3231 char *extra)
3233 struct orinoco_private *priv = netdev_priv(dev);
3235 rrq->value = priv->rts_thresh;
3236 rrq->disabled = (rrq->value == 2347);
3237 rrq->fixed = 1;
3239 return 0;
3242 static int orinoco_ioctl_setfrag(struct net_device *dev,
3243 struct iw_request_info *info,
3244 struct iw_param *frq,
3245 char *extra)
3247 struct orinoco_private *priv = netdev_priv(dev);
3248 int err = -EINPROGRESS; /* Call commit handler */
3249 unsigned long flags;
3251 if (orinoco_lock(priv, &flags) != 0)
3252 return -EBUSY;
3254 if (priv->has_mwo) {
3255 if (frq->disabled)
3256 priv->mwo_robust = 0;
3257 else {
3258 if (frq->fixed)
3259 printk(KERN_WARNING "%s: Fixed fragmentation is "
3260 "not supported on this firmware. "
3261 "Using MWO robust instead.\n", dev->name);
3262 priv->mwo_robust = 1;
3264 } else {
3265 if (frq->disabled)
3266 priv->frag_thresh = 2346;
3267 else {
3268 if ( (frq->value < 256) || (frq->value > 2346) )
3269 err = -EINVAL;
3270 else
3271 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3275 orinoco_unlock(priv, &flags);
3277 return err;
3280 static int orinoco_ioctl_getfrag(struct net_device *dev,
3281 struct iw_request_info *info,
3282 struct iw_param *frq,
3283 char *extra)
3285 struct orinoco_private *priv = netdev_priv(dev);
3286 hermes_t *hw = &priv->hw;
3287 int err;
3288 u16 val;
3289 unsigned long flags;
3291 if (orinoco_lock(priv, &flags) != 0)
3292 return -EBUSY;
3294 if (priv->has_mwo) {
3295 err = hermes_read_wordrec(hw, USER_BAP,
3296 HERMES_RID_CNFMWOROBUST_AGERE,
3297 &val);
3298 if (err)
3299 val = 0;
3301 frq->value = val ? 2347 : 0;
3302 frq->disabled = ! val;
3303 frq->fixed = 0;
3304 } else {
3305 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3306 &val);
3307 if (err)
3308 val = 0;
3310 frq->value = val;
3311 frq->disabled = (val >= 2346);
3312 frq->fixed = 1;
3315 orinoco_unlock(priv, &flags);
3317 return err;
3320 static int orinoco_ioctl_setrate(struct net_device *dev,
3321 struct iw_request_info *info,
3322 struct iw_param *rrq,
3323 char *extra)
3325 struct orinoco_private *priv = netdev_priv(dev);
3326 int ratemode = -1;
3327 int bitrate; /* 100s of kilobits */
3328 int i;
3329 unsigned long flags;
3331 /* As the user space doesn't know our highest rate, it uses -1
3332 * to ask us to set the highest rate. Test it using "iwconfig
3333 * ethX rate auto" - Jean II */
3334 if (rrq->value == -1)
3335 bitrate = 110;
3336 else {
3337 if (rrq->value % 100000)
3338 return -EINVAL;
3339 bitrate = rrq->value / 100000;
3342 if ( (bitrate != 10) && (bitrate != 20) &&
3343 (bitrate != 55) && (bitrate != 110) )
3344 return -EINVAL;
3346 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3347 if ( (bitrate_table[i].bitrate == bitrate) &&
3348 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3349 ratemode = i;
3350 break;
3353 if (ratemode == -1)
3354 return -EINVAL;
3356 if (orinoco_lock(priv, &flags) != 0)
3357 return -EBUSY;
3358 priv->bitratemode = ratemode;
3359 orinoco_unlock(priv, &flags);
3361 return -EINPROGRESS;
3364 static int orinoco_ioctl_getrate(struct net_device *dev,
3365 struct iw_request_info *info,
3366 struct iw_param *rrq,
3367 char *extra)
3369 struct orinoco_private *priv = netdev_priv(dev);
3370 hermes_t *hw = &priv->hw;
3371 int err = 0;
3372 int ratemode;
3373 int i;
3374 u16 val;
3375 unsigned long flags;
3377 if (orinoco_lock(priv, &flags) != 0)
3378 return -EBUSY;
3380 ratemode = priv->bitratemode;
3382 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3384 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3385 rrq->fixed = ! bitrate_table[ratemode].automatic;
3386 rrq->disabled = 0;
3388 /* If the interface is running we try to find more about the
3389 current mode */
3390 if (netif_running(dev)) {
3391 err = hermes_read_wordrec(hw, USER_BAP,
3392 HERMES_RID_CURRENTTXRATE, &val);
3393 if (err)
3394 goto out;
3396 switch (priv->firmware_type) {
3397 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3398 /* Note : in Lucent firmware, the return value of
3399 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3400 * and therefore is totally different from the
3401 * encoding of HERMES_RID_CNFTXRATECONTROL.
3402 * Don't forget that 6Mb/s is really 5.5Mb/s */
3403 if (val == 6)
3404 rrq->value = 5500000;
3405 else
3406 rrq->value = val * 1000000;
3407 break;
3408 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3409 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3410 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3411 if (bitrate_table[i].intersil_txratectrl == val) {
3412 ratemode = i;
3413 break;
3415 if (i >= BITRATE_TABLE_SIZE)
3416 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3417 dev->name, val);
3419 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3420 break;
3421 default:
3422 BUG();
3426 out:
3427 orinoco_unlock(priv, &flags);
3429 return err;
3432 static int orinoco_ioctl_setpower(struct net_device *dev,
3433 struct iw_request_info *info,
3434 struct iw_param *prq,
3435 char *extra)
3437 struct orinoco_private *priv = netdev_priv(dev);
3438 int err = -EINPROGRESS; /* Call commit handler */
3439 unsigned long flags;
3441 if (orinoco_lock(priv, &flags) != 0)
3442 return -EBUSY;
3444 if (prq->disabled) {
3445 priv->pm_on = 0;
3446 } else {
3447 switch (prq->flags & IW_POWER_MODE) {
3448 case IW_POWER_UNICAST_R:
3449 priv->pm_mcast = 0;
3450 priv->pm_on = 1;
3451 break;
3452 case IW_POWER_ALL_R:
3453 priv->pm_mcast = 1;
3454 priv->pm_on = 1;
3455 break;
3456 case IW_POWER_ON:
3457 /* No flags : but we may have a value - Jean II */
3458 break;
3459 default:
3460 err = -EINVAL;
3461 goto out;
3464 if (prq->flags & IW_POWER_TIMEOUT) {
3465 priv->pm_on = 1;
3466 priv->pm_timeout = prq->value / 1000;
3468 if (prq->flags & IW_POWER_PERIOD) {
3469 priv->pm_on = 1;
3470 priv->pm_period = prq->value / 1000;
3472 /* It's valid to not have a value if we are just toggling
3473 * the flags... Jean II */
3474 if(!priv->pm_on) {
3475 err = -EINVAL;
3476 goto out;
3480 out:
3481 orinoco_unlock(priv, &flags);
3483 return err;
3486 static int orinoco_ioctl_getpower(struct net_device *dev,
3487 struct iw_request_info *info,
3488 struct iw_param *prq,
3489 char *extra)
3491 struct orinoco_private *priv = netdev_priv(dev);
3492 hermes_t *hw = &priv->hw;
3493 int err = 0;
3494 u16 enable, period, timeout, mcast;
3495 unsigned long flags;
3497 if (orinoco_lock(priv, &flags) != 0)
3498 return -EBUSY;
3500 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3501 if (err)
3502 goto out;
3504 err = hermes_read_wordrec(hw, USER_BAP,
3505 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3506 if (err)
3507 goto out;
3509 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3510 if (err)
3511 goto out;
3513 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3514 if (err)
3515 goto out;
3517 prq->disabled = !enable;
3518 /* Note : by default, display the period */
3519 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3520 prq->flags = IW_POWER_TIMEOUT;
3521 prq->value = timeout * 1000;
3522 } else {
3523 prq->flags = IW_POWER_PERIOD;
3524 prq->value = period * 1000;
3526 if (mcast)
3527 prq->flags |= IW_POWER_ALL_R;
3528 else
3529 prq->flags |= IW_POWER_UNICAST_R;
3531 out:
3532 orinoco_unlock(priv, &flags);
3534 return err;
3537 static int orinoco_ioctl_getretry(struct net_device *dev,
3538 struct iw_request_info *info,
3539 struct iw_param *rrq,
3540 char *extra)
3542 struct orinoco_private *priv = netdev_priv(dev);
3543 hermes_t *hw = &priv->hw;
3544 int err = 0;
3545 u16 short_limit, long_limit, lifetime;
3546 unsigned long flags;
3548 if (orinoco_lock(priv, &flags) != 0)
3549 return -EBUSY;
3551 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3552 &short_limit);
3553 if (err)
3554 goto out;
3556 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3557 &long_limit);
3558 if (err)
3559 goto out;
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3562 &lifetime);
3563 if (err)
3564 goto out;
3566 rrq->disabled = 0; /* Can't be disabled */
3568 /* Note : by default, display the retry number */
3569 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3570 rrq->flags = IW_RETRY_LIFETIME;
3571 rrq->value = lifetime * 1000; /* ??? */
3572 } else {
3573 /* By default, display the min number */
3574 if ((rrq->flags & IW_RETRY_LONG)) {
3575 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
3576 rrq->value = long_limit;
3577 } else {
3578 rrq->flags = IW_RETRY_LIMIT;
3579 rrq->value = short_limit;
3580 if(short_limit != long_limit)
3581 rrq->flags |= IW_RETRY_SHORT;
3585 out:
3586 orinoco_unlock(priv, &flags);
3588 return err;
3591 static int orinoco_ioctl_reset(struct net_device *dev,
3592 struct iw_request_info *info,
3593 void *wrqu,
3594 char *extra)
3596 struct orinoco_private *priv = netdev_priv(dev);
3598 if (! capable(CAP_NET_ADMIN))
3599 return -EPERM;
3601 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3602 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3604 /* Firmware reset */
3605 orinoco_reset(&priv->reset_work);
3606 } else {
3607 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3609 schedule_work(&priv->reset_work);
3612 return 0;
3615 static int orinoco_ioctl_setibssport(struct net_device *dev,
3616 struct iw_request_info *info,
3617 void *wrqu,
3618 char *extra)
3621 struct orinoco_private *priv = netdev_priv(dev);
3622 int val = *( (int *) extra );
3623 unsigned long flags;
3625 if (orinoco_lock(priv, &flags) != 0)
3626 return -EBUSY;
3628 priv->ibss_port = val ;
3630 /* Actually update the mode we are using */
3631 set_port_type(priv);
3633 orinoco_unlock(priv, &flags);
3634 return -EINPROGRESS; /* Call commit handler */
3637 static int orinoco_ioctl_getibssport(struct net_device *dev,
3638 struct iw_request_info *info,
3639 void *wrqu,
3640 char *extra)
3642 struct orinoco_private *priv = netdev_priv(dev);
3643 int *val = (int *) extra;
3645 *val = priv->ibss_port;
3646 return 0;
3649 static int orinoco_ioctl_setport3(struct net_device *dev,
3650 struct iw_request_info *info,
3651 void *wrqu,
3652 char *extra)
3654 struct orinoco_private *priv = netdev_priv(dev);
3655 int val = *( (int *) extra );
3656 int err = 0;
3657 unsigned long flags;
3659 if (orinoco_lock(priv, &flags) != 0)
3660 return -EBUSY;
3662 switch (val) {
3663 case 0: /* Try to do IEEE ad-hoc mode */
3664 if (! priv->has_ibss) {
3665 err = -EINVAL;
3666 break;
3668 priv->prefer_port3 = 0;
3670 break;
3672 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3673 if (! priv->has_port3) {
3674 err = -EINVAL;
3675 break;
3677 priv->prefer_port3 = 1;
3678 break;
3680 default:
3681 err = -EINVAL;
3684 if (! err) {
3685 /* Actually update the mode we are using */
3686 set_port_type(priv);
3687 err = -EINPROGRESS;
3690 orinoco_unlock(priv, &flags);
3692 return err;
3695 static int orinoco_ioctl_getport3(struct net_device *dev,
3696 struct iw_request_info *info,
3697 void *wrqu,
3698 char *extra)
3700 struct orinoco_private *priv = netdev_priv(dev);
3701 int *val = (int *) extra;
3703 *val = priv->prefer_port3;
3704 return 0;
3707 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3708 struct iw_request_info *info,
3709 void *wrqu,
3710 char *extra)
3712 struct orinoco_private *priv = netdev_priv(dev);
3713 unsigned long flags;
3714 int val;
3716 if (! priv->has_preamble)
3717 return -EOPNOTSUPP;
3719 /* 802.11b has recently defined some short preamble.
3720 * Basically, the Phy header has been reduced in size.
3721 * This increase performance, especially at high rates
3722 * (the preamble is transmitted at 1Mb/s), unfortunately
3723 * this give compatibility troubles... - Jean II */
3724 val = *( (int *) extra );
3726 if (orinoco_lock(priv, &flags) != 0)
3727 return -EBUSY;
3729 if (val)
3730 priv->preamble = 1;
3731 else
3732 priv->preamble = 0;
3734 orinoco_unlock(priv, &flags);
3736 return -EINPROGRESS; /* Call commit handler */
3739 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3740 struct iw_request_info *info,
3741 void *wrqu,
3742 char *extra)
3744 struct orinoco_private *priv = netdev_priv(dev);
3745 int *val = (int *) extra;
3747 if (! priv->has_preamble)
3748 return -EOPNOTSUPP;
3750 *val = priv->preamble;
3751 return 0;
3754 /* ioctl interface to hermes_read_ltv()
3755 * To use with iwpriv, pass the RID as the token argument, e.g.
3756 * iwpriv get_rid [0xfc00]
3757 * At least Wireless Tools 25 is required to use iwpriv.
3758 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3759 static int orinoco_ioctl_getrid(struct net_device *dev,
3760 struct iw_request_info *info,
3761 struct iw_point *data,
3762 char *extra)
3764 struct orinoco_private *priv = netdev_priv(dev);
3765 hermes_t *hw = &priv->hw;
3766 int rid = data->flags;
3767 u16 length;
3768 int err;
3769 unsigned long flags;
3771 /* It's a "get" function, but we don't want users to access the
3772 * WEP key and other raw firmware data */
3773 if (! capable(CAP_NET_ADMIN))
3774 return -EPERM;
3776 if (rid < 0xfc00 || rid > 0xffff)
3777 return -EINVAL;
3779 if (orinoco_lock(priv, &flags) != 0)
3780 return -EBUSY;
3782 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3783 extra);
3784 if (err)
3785 goto out;
3787 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3788 MAX_RID_LEN);
3790 out:
3791 orinoco_unlock(priv, &flags);
3792 return err;
3795 /* Trigger a scan (look for other cells in the vicinity) */
3796 static int orinoco_ioctl_setscan(struct net_device *dev,
3797 struct iw_request_info *info,
3798 struct iw_param *srq,
3799 char *extra)
3801 struct orinoco_private *priv = netdev_priv(dev);
3802 hermes_t *hw = &priv->hw;
3803 int err = 0;
3804 unsigned long flags;
3806 /* Note : you may have realised that, as this is a SET operation,
3807 * this is privileged and therefore a normal user can't
3808 * perform scanning.
3809 * This is not an error, while the device perform scanning,
3810 * traffic doesn't flow, so it's a perfect DoS...
3811 * Jean II */
3813 if (orinoco_lock(priv, &flags) != 0)
3814 return -EBUSY;
3816 /* Scanning with port 0 disabled would fail */
3817 if (!netif_running(dev)) {
3818 err = -ENETDOWN;
3819 goto out;
3822 /* In monitor mode, the scan results are always empty.
3823 * Probe responses are passed to the driver as received
3824 * frames and could be processed in software. */
3825 if (priv->iw_mode == IW_MODE_MONITOR) {
3826 err = -EOPNOTSUPP;
3827 goto out;
3830 /* Note : because we don't lock out the irq handler, the way
3831 * we access scan variables in priv is critical.
3832 * o scan_inprogress : not touched by irq handler
3833 * o scan_mode : not touched by irq handler
3834 * o scan_result : irq is strict producer, non-irq is strict
3835 * consumer.
3836 * o scan_len : synchronised with scan_result
3837 * Before modifying anything on those variables, please think hard !
3838 * Jean II */
3840 /* If there is still some left-over scan results, get rid of it */
3841 if (priv->scan_result != NULL) {
3842 /* What's likely is that a client did crash or was killed
3843 * between triggering the scan request and reading the
3844 * results, so we need to reset everything.
3845 * Some clients that are too slow may suffer from that...
3846 * Jean II */
3847 kfree(priv->scan_result);
3848 priv->scan_result = NULL;
3851 /* Save flags */
3852 priv->scan_mode = srq->flags;
3854 /* Always trigger scanning, even if it's in progress.
3855 * This way, if the info frame get lost, we will recover somewhat
3856 * gracefully - Jean II */
3858 if (priv->has_hostscan) {
3859 switch (priv->firmware_type) {
3860 case FIRMWARE_TYPE_SYMBOL:
3861 err = hermes_write_wordrec(hw, USER_BAP,
3862 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3863 HERMES_HOSTSCAN_SYMBOL_ONCE |
3864 HERMES_HOSTSCAN_SYMBOL_BCAST);
3865 break;
3866 case FIRMWARE_TYPE_INTERSIL: {
3867 __le16 req[3];
3869 req[0] = cpu_to_le16(0x3fff); /* All channels */
3870 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3871 req[2] = 0; /* Any ESSID */
3872 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3873 HERMES_RID_CNFHOSTSCAN, &req);
3875 break;
3876 case FIRMWARE_TYPE_AGERE:
3877 err = hermes_write_wordrec(hw, USER_BAP,
3878 HERMES_RID_CNFSCANSSID_AGERE,
3879 0); /* Any ESSID */
3880 if (err)
3881 break;
3883 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3884 break;
3886 } else
3887 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3889 /* One more client */
3890 if (! err)
3891 priv->scan_inprogress = 1;
3893 out:
3894 orinoco_unlock(priv, &flags);
3895 return err;
3898 /* Translate scan data returned from the card to a card independant
3899 * format that the Wireless Tools will understand - Jean II
3900 * Return message length or -errno for fatal errors */
3901 static inline int orinoco_translate_scan(struct net_device *dev,
3902 struct iw_request_info *info,
3903 char *buffer,
3904 char *scan,
3905 int scan_len)
3907 struct orinoco_private *priv = netdev_priv(dev);
3908 int offset; /* In the scan data */
3909 union hermes_scan_info *atom;
3910 int atom_len;
3911 u16 capabilities;
3912 u16 channel;
3913 struct iw_event iwe; /* Temporary buffer */
3914 char * current_ev = buffer;
3915 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3917 switch (priv->firmware_type) {
3918 case FIRMWARE_TYPE_AGERE:
3919 atom_len = sizeof(struct agere_scan_apinfo);
3920 offset = 0;
3921 break;
3922 case FIRMWARE_TYPE_SYMBOL:
3923 /* Lack of documentation necessitates this hack.
3924 * Different firmwares have 68 or 76 byte long atoms.
3925 * We try modulo first. If the length divides by both,
3926 * we check what would be the channel in the second
3927 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3928 * Valid channel cannot be 0. */
3929 if (scan_len % 76)
3930 atom_len = 68;
3931 else if (scan_len % 68)
3932 atom_len = 76;
3933 else if (scan_len >= 1292 && scan[68] == 0)
3934 atom_len = 76;
3935 else
3936 atom_len = 68;
3937 offset = 0;
3938 break;
3939 case FIRMWARE_TYPE_INTERSIL:
3940 offset = 4;
3941 if (priv->has_hostscan) {
3942 atom_len = le16_to_cpup((__le16 *)scan);
3943 /* Sanity check for atom_len */
3944 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3945 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3946 dev->name, atom_len);
3947 return -EIO;
3949 } else
3950 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3951 break;
3952 default:
3953 return -EOPNOTSUPP;
3956 /* Check that we got an whole number of atoms */
3957 if ((scan_len - offset) % atom_len) {
3958 printk(KERN_ERR "%s: Unexpected scan data length %d, "
3959 "atom_len %d, offset %d\n", dev->name, scan_len,
3960 atom_len, offset);
3961 return -EIO;
3964 /* Read the entries one by one */
3965 for (; offset + atom_len <= scan_len; offset += atom_len) {
3966 /* Get next atom */
3967 atom = (union hermes_scan_info *) (scan + offset);
3969 memset(&iwe, 0, sizeof(iwe));
3971 /* First entry *MUST* be the AP MAC address */
3972 iwe.cmd = SIOCGIWAP;
3973 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3974 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
3975 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
3976 &iwe, IW_EV_ADDR_LEN);
3978 /* Other entries will be displayed in the order we give them */
3980 /* Add the ESSID */
3981 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
3982 if (iwe.u.data.length > 32)
3983 iwe.u.data.length = 32;
3984 iwe.cmd = SIOCGIWESSID;
3985 iwe.u.data.flags = 1;
3986 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
3987 &iwe, atom->a.essid);
3989 /* Add mode */
3990 iwe.cmd = SIOCGIWMODE;
3991 capabilities = le16_to_cpu(atom->a.capabilities);
3992 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
3993 if (capabilities & WLAN_CAPABILITY_ESS)
3994 iwe.u.mode = IW_MODE_MASTER;
3995 else
3996 iwe.u.mode = IW_MODE_ADHOC;
3997 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
3998 &iwe, IW_EV_UINT_LEN);
4001 channel = atom->s.channel;
4002 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4003 /* Add frequency */
4004 iwe.cmd = SIOCGIWFREQ;
4005 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4006 iwe.u.freq.e = 1;
4007 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4008 &iwe, IW_EV_FREQ_LEN);
4011 /* Add quality statistics. level and noise in dB. No link quality */
4012 iwe.cmd = IWEVQUAL;
4013 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4014 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4015 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4016 /* Wireless tools prior to 27.pre22 will show link quality
4017 * anyway, so we provide a reasonable value. */
4018 if (iwe.u.qual.level > iwe.u.qual.noise)
4019 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4020 else
4021 iwe.u.qual.qual = 0;
4022 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4023 &iwe, IW_EV_QUAL_LEN);
4025 /* Add encryption capability */
4026 iwe.cmd = SIOCGIWENCODE;
4027 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4028 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4029 else
4030 iwe.u.data.flags = IW_ENCODE_DISABLED;
4031 iwe.u.data.length = 0;
4032 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4033 &iwe, atom->a.essid);
4035 /* Bit rate is not available in Lucent/Agere firmwares */
4036 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4037 char * current_val = current_ev + IW_EV_LCP_LEN;
4038 int i;
4039 int step;
4041 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4042 step = 2;
4043 else
4044 step = 1;
4046 iwe.cmd = SIOCGIWRATE;
4047 /* Those two flags are ignored... */
4048 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4049 /* Max 10 values */
4050 for (i = 0; i < 10; i += step) {
4051 /* NULL terminated */
4052 if (atom->p.rates[i] == 0x0)
4053 break;
4054 /* Bit rate given in 500 kb/s units (+ 0x80) */
4055 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4056 current_val = iwe_stream_add_value(info, current_ev,
4057 current_val,
4058 end_buf, &iwe,
4059 IW_EV_PARAM_LEN);
4061 /* Check if we added any event */
4062 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
4063 current_ev = current_val;
4066 /* The other data in the scan result are not really
4067 * interesting, so for now drop it - Jean II */
4069 return current_ev - buffer;
4072 /* Return results of a scan */
4073 static int orinoco_ioctl_getscan(struct net_device *dev,
4074 struct iw_request_info *info,
4075 struct iw_point *srq,
4076 char *extra)
4078 struct orinoco_private *priv = netdev_priv(dev);
4079 int err = 0;
4080 unsigned long flags;
4082 if (orinoco_lock(priv, &flags) != 0)
4083 return -EBUSY;
4085 /* If no results yet, ask to try again later */
4086 if (priv->scan_result == NULL) {
4087 if (priv->scan_inprogress)
4088 /* Important note : we don't want to block the caller
4089 * until results are ready for various reasons.
4090 * First, managing wait queues is complex and racy.
4091 * Second, we grab some rtnetlink lock before comming
4092 * here (in dev_ioctl()).
4093 * Third, we generate an Wireless Event, so the
4094 * caller can wait itself on that - Jean II */
4095 err = -EAGAIN;
4096 else
4097 /* Client error, no scan results...
4098 * The caller need to restart the scan. */
4099 err = -ENODATA;
4100 } else {
4101 /* We have some results to push back to user space */
4103 /* Translate to WE format */
4104 int ret = orinoco_translate_scan(dev, info, extra,
4105 priv->scan_result,
4106 priv->scan_len);
4108 if (ret < 0) {
4109 err = ret;
4110 kfree(priv->scan_result);
4111 priv->scan_result = NULL;
4112 } else {
4113 srq->length = ret;
4115 /* Return flags */
4116 srq->flags = (__u16) priv->scan_mode;
4118 /* In any case, Scan results will be cleaned up in the
4119 * reset function and when exiting the driver.
4120 * The person triggering the scanning may never come to
4121 * pick the results, so we need to do it in those places.
4122 * Jean II */
4124 #ifdef SCAN_SINGLE_READ
4125 /* If you enable this option, only one client (the first
4126 * one) will be able to read the result (and only one
4127 * time). If there is multiple concurent clients that
4128 * want to read scan results, this behavior is not
4129 * advisable - Jean II */
4130 kfree(priv->scan_result);
4131 priv->scan_result = NULL;
4132 #endif /* SCAN_SINGLE_READ */
4133 /* Here, if too much time has elapsed since last scan,
4134 * we may want to clean up scan results... - Jean II */
4137 /* Scan is no longer in progress */
4138 priv->scan_inprogress = 0;
4141 orinoco_unlock(priv, &flags);
4142 return err;
4145 /* Commit handler, called after set operations */
4146 static int orinoco_ioctl_commit(struct net_device *dev,
4147 struct iw_request_info *info,
4148 void *wrqu,
4149 char *extra)
4151 struct orinoco_private *priv = netdev_priv(dev);
4152 struct hermes *hw = &priv->hw;
4153 unsigned long flags;
4154 int err = 0;
4156 if (!priv->open)
4157 return 0;
4159 if (priv->broken_disableport) {
4160 orinoco_reset(&priv->reset_work);
4161 return 0;
4164 if (orinoco_lock(priv, &flags) != 0)
4165 return err;
4167 err = hermes_disable_port(hw, 0);
4168 if (err) {
4169 printk(KERN_WARNING "%s: Unable to disable port "
4170 "while reconfiguring card\n", dev->name);
4171 priv->broken_disableport = 1;
4172 goto out;
4175 err = __orinoco_program_rids(dev);
4176 if (err) {
4177 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4178 dev->name);
4179 goto out;
4182 err = hermes_enable_port(hw, 0);
4183 if (err) {
4184 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4185 dev->name);
4186 goto out;
4189 out:
4190 if (err) {
4191 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4192 schedule_work(&priv->reset_work);
4193 err = 0;
4196 orinoco_unlock(priv, &flags);
4197 return err;
4200 static const struct iw_priv_args orinoco_privtab[] = {
4201 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4202 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4203 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4204 0, "set_port3" },
4205 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4206 "get_port3" },
4207 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4208 0, "set_preamble" },
4209 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4210 "get_preamble" },
4211 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4212 0, "set_ibssport" },
4213 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4214 "get_ibssport" },
4215 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4216 "get_rid" },
4221 * Structures to export the Wireless Handlers
4224 static const iw_handler orinoco_handler[] = {
4225 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4226 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4227 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4228 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4229 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4230 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4231 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4232 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4233 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4234 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4235 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4236 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4237 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4238 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4239 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4240 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4241 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4242 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4243 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4244 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4245 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4246 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4247 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4248 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4249 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4250 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4251 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4252 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4253 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4254 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4255 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4256 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4261 Added typecasting since we no longer use iwreq_data -- Moustafa
4263 static const iw_handler orinoco_private_handler[] = {
4264 [0] = (iw_handler) orinoco_ioctl_reset,
4265 [1] = (iw_handler) orinoco_ioctl_reset,
4266 [2] = (iw_handler) orinoco_ioctl_setport3,
4267 [3] = (iw_handler) orinoco_ioctl_getport3,
4268 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4269 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4270 [6] = (iw_handler) orinoco_ioctl_setibssport,
4271 [7] = (iw_handler) orinoco_ioctl_getibssport,
4272 [9] = (iw_handler) orinoco_ioctl_getrid,
4275 static const struct iw_handler_def orinoco_handler_def = {
4276 .num_standard = ARRAY_SIZE(orinoco_handler),
4277 .num_private = ARRAY_SIZE(orinoco_private_handler),
4278 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4279 .standard = orinoco_handler,
4280 .private = orinoco_private_handler,
4281 .private_args = orinoco_privtab,
4282 .get_wireless_stats = orinoco_get_wireless_stats,
4285 static void orinoco_get_drvinfo(struct net_device *dev,
4286 struct ethtool_drvinfo *info)
4288 struct orinoco_private *priv = netdev_priv(dev);
4290 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4291 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4292 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4295 static struct ethtool_ops orinoco_ethtool_ops = {
4296 .get_drvinfo = orinoco_get_drvinfo,
4297 .get_link = ethtool_op_get_link,
4300 /********************************************************************/
4301 /* Module initialization */
4302 /********************************************************************/
4304 EXPORT_SYMBOL(alloc_orinocodev);
4305 EXPORT_SYMBOL(free_orinocodev);
4307 EXPORT_SYMBOL(__orinoco_up);
4308 EXPORT_SYMBOL(__orinoco_down);
4309 EXPORT_SYMBOL(orinoco_reinit_firmware);
4311 EXPORT_SYMBOL(orinoco_interrupt);
4313 EXPORT_SYMBOL(__orinoco_ev_rx);
4314 EXPORT_SYMBOL(__orinoco_ev_info);
4316 /* Can't be declared "const" or the whole __initdata section will
4317 * become const */
4318 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4319 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4320 "Pavel Roskin <proski@gnu.org>, et al)";
4322 static int __init init_orinoco(void)
4324 printk(KERN_DEBUG "%s\n", version);
4325 return 0;
4328 static void __exit exit_orinoco(void)
4332 module_init(init_orinoco);
4333 module_exit(exit_orinoco);