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
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. */
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/if_arp.h>
86 #include <linux/wireless.h>
87 #include <net/iw_handler.h>
88 #include <net/ieee80211.h>
90 #include "hermes_rid.h"
93 /********************************************************************/
94 /* Module information */
95 /********************************************************************/
97 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
98 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
99 MODULE_LICENSE("Dual MPL/GPL");
101 /* Level of debugging. Used in the macros in orinoco.h */
103 int orinoco_debug = ORINOCO_DEBUG;
104 module_param(orinoco_debug, int, 0644);
105 MODULE_PARM_DESC(orinoco_debug, "Debug level");
106 EXPORT_SYMBOL(orinoco_debug);
109 static int suppress_linkstatus; /* = 0 */
110 module_param(suppress_linkstatus, bool, 0644);
111 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
112 static int ignore_disconnect; /* = 0 */
113 module_param(ignore_disconnect, int, 0644);
114 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
116 static int force_monitor; /* = 0 */
117 module_param(force_monitor, int, 0644);
118 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
120 /********************************************************************/
121 /* Compile time configuration and compatibility stuff */
122 /********************************************************************/
124 /* We do this this way to avoid ifdefs in the actual code */
126 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
128 #define SPY_NUMBER(priv) 0
129 #endif /* WIRELESS_SPY */
131 /********************************************************************/
132 /* Internal constants */
133 /********************************************************************/
135 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
136 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
137 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
139 #define ORINOCO_MIN_MTU 256
140 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
142 #define SYMBOL_MAX_VER_LEN (14)
145 #define MAX_IRQLOOPS_PER_IRQ 10
146 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
149 * legitimately generate */
150 #define SMALL_KEY_SIZE 5
151 #define LARGE_KEY_SIZE 13
152 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
154 #define DUMMY_FID 0xFFFF
156 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
160 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
163 | HERMES_EV_INFDROP )
165 #define MAX_RID_LEN 1024
167 static const struct iw_handler_def orinoco_handler_def;
168 static const struct ethtool_ops orinoco_ethtool_ops;
170 /********************************************************************/
172 /********************************************************************/
174 /* The frequency of each channel in MHz */
175 static const long channel_frequency[] = {
176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
177 2447, 2452, 2457, 2462, 2467, 2472, 2484
179 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
181 /* This tables gives the actual meanings of the bitrate IDs returned
182 * by the firmware. */
184 int bitrate; /* in 100s of kilobits */
186 u16 agere_txratectrl;
187 u16 intersil_txratectrl;
188 } bitrate_table[] = {
189 {110, 1, 3, 15}, /* Entry 0 is the default */
198 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
200 /********************************************************************/
202 /********************************************************************/
204 /* Beginning of the Tx descriptor, used in TxExc handling */
205 struct hermes_txexc_data {
206 struct hermes_tx_descriptor desc;
210 } __attribute__ ((packed));
212 /* Rx frame header except compatibility 802.3 header */
213 struct hermes_rx_descriptor {
234 } __attribute__ ((packed));
236 /********************************************************************/
237 /* Function prototypes */
238 /********************************************************************/
240 static int __orinoco_program_rids(struct net_device *dev);
241 static void __orinoco_set_multicast_list(struct net_device *dev);
243 /********************************************************************/
244 /* Internal helper functions */
245 /********************************************************************/
247 static inline void set_port_type(struct orinoco_private *priv)
249 switch (priv->iw_mode) {
252 priv->createibss = 0;
255 if (priv->prefer_port3) {
257 priv->createibss = 0;
259 priv->port_type = priv->ibss_port;
260 priv->createibss = 1;
263 case IW_MODE_MONITOR:
265 priv->createibss = 0;
268 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
273 /********************************************************************/
275 /********************************************************************/
277 static int orinoco_open(struct net_device *dev)
279 struct orinoco_private *priv = netdev_priv(dev);
283 if (orinoco_lock(priv, &flags) != 0)
286 err = __orinoco_up(dev);
291 orinoco_unlock(priv, &flags);
296 static int orinoco_stop(struct net_device *dev)
298 struct orinoco_private *priv = netdev_priv(dev);
301 /* We mustn't use orinoco_lock() here, because we need to be
302 able to close the interface even if hw_unavailable is set
303 (e.g. as we're released after a PC Card removal) */
304 spin_lock_irq(&priv->lock);
308 err = __orinoco_down(dev);
310 spin_unlock_irq(&priv->lock);
315 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
317 struct orinoco_private *priv = netdev_priv(dev);
322 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
324 struct orinoco_private *priv = netdev_priv(dev);
325 hermes_t *hw = &priv->hw;
326 struct iw_statistics *wstats = &priv->wstats;
330 if (! netif_device_present(dev)) {
331 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
333 return NULL; /* FIXME: Can we do better than this? */
336 /* If busy, return the old stats. Returning NULL may cause
337 * the interface to disappear from /proc/net/wireless */
338 if (orinoco_lock(priv, &flags) != 0)
341 /* We can't really wait for the tallies inquiry command to
342 * complete, so we just use the previous results and trigger
343 * a new tallies inquiry command for next time - Jean II */
344 /* FIXME: Really we should wait for the inquiry to come back -
345 * as it is the stats we give don't make a whole lot of sense.
346 * Unfortunately, it's not clear how to do that within the
347 * wireless extensions framework: I think we're in user
348 * context, but a lock seems to be held by the time we get in
349 * here so we're not safe to sleep here. */
350 hermes_inquire(hw, HERMES_INQ_TALLIES);
352 if (priv->iw_mode == IW_MODE_ADHOC) {
353 memset(&wstats->qual, 0, sizeof(wstats->qual));
354 /* If a spy address is defined, we report stats of the
355 * first spy address - Jean II */
356 if (SPY_NUMBER(priv)) {
357 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
358 wstats->qual.level = priv->spy_data.spy_stat[0].level;
359 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
360 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
364 __le16 qual, signal, noise, unused;
365 } __attribute__ ((packed)) cq;
367 err = HERMES_READ_RECORD(hw, USER_BAP,
368 HERMES_RID_COMMSQUALITY, &cq);
371 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
372 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
373 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
374 wstats->qual.updated = 7;
378 orinoco_unlock(priv, &flags);
382 static void orinoco_set_multicast_list(struct net_device *dev)
384 struct orinoco_private *priv = netdev_priv(dev);
387 if (orinoco_lock(priv, &flags) != 0) {
388 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
389 "called when hw_unavailable\n", dev->name);
393 __orinoco_set_multicast_list(dev);
394 orinoco_unlock(priv, &flags);
397 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
399 struct orinoco_private *priv = netdev_priv(dev);
401 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
404 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
405 (priv->nicbuf_size - ETH_HLEN) )
413 /********************************************************************/
415 /********************************************************************/
417 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
419 struct orinoco_private *priv = netdev_priv(dev);
420 struct net_device_stats *stats = &priv->stats;
421 hermes_t *hw = &priv->hw;
423 u16 txfid = priv->txfid;
426 struct hermes_tx_descriptor desc;
429 if (! netif_running(dev)) {
430 printk(KERN_ERR "%s: Tx on stopped device!\n",
432 return NETDEV_TX_BUSY;
435 if (netif_queue_stopped(dev)) {
436 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
438 return NETDEV_TX_BUSY;
441 if (orinoco_lock(priv, &flags) != 0) {
442 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
444 return NETDEV_TX_BUSY;
447 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
448 /* Oops, the firmware hasn't established a connection,
449 silently drop the packet (this seems to be the
454 /* Check packet length */
455 if (skb->len < ETH_HLEN)
458 eh = (struct ethhdr *)skb->data;
460 memset(&desc, 0, sizeof(desc));
461 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
462 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
465 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
466 "to BAP\n", dev->name, err);
470 /* Clear the 802.11 header and data length fields - some
471 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
472 * if this isn't done. */
473 hermes_clear_words(hw, HERMES_DATA0,
474 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
476 /* Encapsulate Ethernet-II frames */
477 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
478 struct header_struct {
479 struct ethhdr eth; /* 802.3 header */
480 u8 encap[6]; /* 802.2 header */
481 } __attribute__ ((packed)) hdr;
483 /* Strip destination and source from the data */
484 skb_pull(skb, 2 * ETH_ALEN);
485 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
487 /* And move them to a separate header */
488 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
489 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
490 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
492 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
493 txfid, HERMES_802_3_OFFSET);
496 printk(KERN_ERR "%s: Error %d writing packet "
497 "header to BAP\n", dev->name, err);
500 } else { /* IEEE 802.3 frame */
501 data_off = HERMES_802_3_OFFSET;
504 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
507 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
512 /* Finally, we actually initiate the send */
513 netif_stop_queue(dev);
515 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
518 netif_start_queue(dev);
520 printk(KERN_ERR "%s: Error %d transmitting packet\n",
525 dev->trans_start = jiffies;
526 stats->tx_bytes += data_off + skb->len;
534 orinoco_unlock(priv, &flags);
540 schedule_work(&priv->reset_work);
541 orinoco_unlock(priv, &flags);
542 return NETDEV_TX_BUSY;
545 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
547 struct orinoco_private *priv = netdev_priv(dev);
548 u16 fid = hermes_read_regn(hw, ALLOCFID);
550 if (fid != priv->txfid) {
551 if (fid != DUMMY_FID)
552 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
557 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
560 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
562 struct orinoco_private *priv = netdev_priv(dev);
563 struct net_device_stats *stats = &priv->stats;
567 netif_wake_queue(dev);
569 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
572 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
574 struct orinoco_private *priv = netdev_priv(dev);
575 struct net_device_stats *stats = &priv->stats;
576 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
578 struct hermes_txexc_data hdr;
581 if (fid == DUMMY_FID)
582 return; /* Nothing's really happened */
584 /* Read part of the frame header - we need status and addr1 */
585 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
586 sizeof(struct hermes_txexc_data),
589 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
593 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
594 "(FID=%04X error %d)\n",
595 dev->name, fid, err);
599 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
602 /* We produce a TXDROP event only for retry or lifetime
603 * exceeded, because that's the only status that really mean
604 * that this particular node went away.
605 * Other errors means that *we* screwed up. - Jean II */
606 status = le16_to_cpu(hdr.desc.status);
607 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
608 union iwreq_data wrqu;
610 /* Copy 802.11 dest address.
611 * We use the 802.11 header because the frame may
612 * not be 802.3 or may be mangled...
613 * In Ad-Hoc mode, it will be the node address.
614 * In managed mode, it will be most likely the AP addr
615 * User space will figure out how to convert it to
616 * whatever it needs (IP address or else).
618 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
619 wrqu.addr.sa_family = ARPHRD_ETHER;
621 /* Send event to user space */
622 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
625 netif_wake_queue(dev);
628 static void orinoco_tx_timeout(struct net_device *dev)
630 struct orinoco_private *priv = netdev_priv(dev);
631 struct net_device_stats *stats = &priv->stats;
632 struct hermes *hw = &priv->hw;
634 printk(KERN_WARNING "%s: Tx timeout! "
635 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
636 dev->name, hermes_read_regn(hw, ALLOCFID),
637 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
641 schedule_work(&priv->reset_work);
644 /********************************************************************/
645 /* Rx path (data frames) */
646 /********************************************************************/
648 /* Does the frame have a SNAP header indicating it should be
649 * de-encapsulated to Ethernet-II? */
650 static inline int is_ethersnap(void *_hdr)
654 /* We de-encapsulate all packets which, a) have SNAP headers
655 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
656 * and where b) the OUI of the SNAP header is 00:00:00 or
657 * 00:00:f8 - we need both because different APs appear to use
658 * different OUIs for some reason */
659 return (memcmp(hdr, &encaps_hdr, 5) == 0)
660 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
663 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
664 int level, int noise)
666 struct iw_quality wstats;
667 wstats.level = level - 0x95;
668 wstats.noise = noise - 0x95;
669 wstats.qual = (level > noise) ? (level - noise) : 0;
671 /* Update spy records */
672 wireless_spy_update(dev, mac, &wstats);
675 static void orinoco_stat_gather(struct net_device *dev,
677 struct hermes_rx_descriptor *desc)
679 struct orinoco_private *priv = netdev_priv(dev);
681 /* Using spy support with lots of Rx packets, like in an
682 * infrastructure (AP), will really slow down everything, because
683 * the MAC address must be compared to each entry of the spy list.
684 * If the user really asks for it (set some address in the
685 * spy list), we do it, but he will pay the price.
686 * Note that to get here, you need both WIRELESS_SPY
687 * compiled in AND some addresses in the list !!!
689 /* Note : gcc will optimise the whole section away if
690 * WIRELESS_SPY is not defined... - Jean II */
691 if (SPY_NUMBER(priv)) {
692 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
693 desc->signal, desc->silence);
698 * orinoco_rx_monitor - handle received monitor frames.
703 * desc rx descriptor of the frame
705 * Call context: interrupt
707 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
708 struct hermes_rx_descriptor *desc)
710 u32 hdrlen = 30; /* return full header by default */
716 struct orinoco_private *priv = netdev_priv(dev);
717 struct net_device_stats *stats = &priv->stats;
718 hermes_t *hw = &priv->hw;
720 len = le16_to_cpu(desc->data_len);
722 /* Determine the size of the header and the data */
723 fc = le16_to_cpu(desc->frame_ctl);
724 switch (fc & IEEE80211_FCTL_FTYPE) {
725 case IEEE80211_FTYPE_DATA:
726 if ((fc & IEEE80211_FCTL_TODS)
727 && (fc & IEEE80211_FCTL_FROMDS))
733 case IEEE80211_FTYPE_MGMT:
737 case IEEE80211_FTYPE_CTL:
738 switch (fc & IEEE80211_FCTL_STYPE) {
739 case IEEE80211_STYPE_PSPOLL:
740 case IEEE80211_STYPE_RTS:
741 case IEEE80211_STYPE_CFEND:
742 case IEEE80211_STYPE_CFENDACK:
745 case IEEE80211_STYPE_CTS:
746 case IEEE80211_STYPE_ACK:
752 /* Unknown frame type */
756 /* sanity check the length */
757 if (datalen > IEEE80211_DATA_LEN + 12) {
758 printk(KERN_DEBUG "%s: oversized monitor frame, "
759 "data length = %d\n", dev->name, datalen);
760 stats->rx_length_errors++;
764 skb = dev_alloc_skb(hdrlen + datalen);
766 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
771 /* Copy the 802.11 header to the skb */
772 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
773 skb_reset_mac_header(skb);
775 /* If any, copy the data from the card to the skb */
777 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
778 ALIGN(datalen, 2), rxfid,
779 HERMES_802_2_OFFSET);
781 printk(KERN_ERR "%s: error %d reading monitor frame\n",
788 skb->ip_summed = CHECKSUM_NONE;
789 skb->pkt_type = PACKET_OTHERHOST;
790 skb->protocol = __constant_htons(ETH_P_802_2);
792 dev->last_rx = jiffies;
794 stats->rx_bytes += skb->len;
800 dev_kfree_skb_irq(skb);
806 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
808 struct orinoco_private *priv = netdev_priv(dev);
809 struct net_device_stats *stats = &priv->stats;
810 struct iw_statistics *wstats = &priv->wstats;
811 struct sk_buff *skb = NULL;
812 u16 rxfid, status, fc;
814 struct hermes_rx_descriptor desc;
818 rxfid = hermes_read_regn(hw, RXFID);
820 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
823 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
824 "Frame dropped.\n", dev->name, err);
828 status = le16_to_cpu(desc.status);
830 if (status & HERMES_RXSTAT_BADCRC) {
831 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
833 stats->rx_crc_errors++;
837 /* Handle frames in monitor mode */
838 if (priv->iw_mode == IW_MODE_MONITOR) {
839 orinoco_rx_monitor(dev, rxfid, &desc);
843 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
844 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
846 wstats->discard.code++;
850 length = le16_to_cpu(desc.data_len);
851 fc = le16_to_cpu(desc.frame_ctl);
854 if (length < 3) { /* No for even an 802.2 LLC header */
855 /* At least on Symbol firmware with PCF we get quite a
856 lot of these legitimately - Poll frames with no
860 if (length > IEEE80211_DATA_LEN) {
861 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
863 stats->rx_length_errors++;
867 /* We need space for the packet data itself, plus an ethernet
868 header, plus 2 bytes so we can align the IP header on a
869 32bit boundary, plus 1 byte so we can read in odd length
870 packets from the card, which has an IO granularity of 16
872 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
874 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
879 /* We'll prepend the header, so reserve space for it. The worst
880 case is no decapsulation, when 802.3 header is prepended and
881 nothing is removed. 2 is for aligning the IP header. */
882 skb_reserve(skb, ETH_HLEN + 2);
884 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
885 ALIGN(length, 2), rxfid,
886 HERMES_802_2_OFFSET);
888 printk(KERN_ERR "%s: error %d reading frame. "
889 "Frame dropped.\n", dev->name, err);
893 /* Handle decapsulation
894 * In most cases, the firmware tell us about SNAP frames.
895 * For some reason, the SNAP frames sent by LinkSys APs
896 * are not properly recognised by most firmwares.
897 * So, check ourselves */
898 if (length >= ENCAPS_OVERHEAD &&
899 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
900 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
901 is_ethersnap(skb->data))) {
902 /* These indicate a SNAP within 802.2 LLC within
903 802.11 frame which we'll need to de-encapsulate to
904 the original EthernetII frame. */
905 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
907 /* 802.3 frame - prepend 802.3 header as is */
908 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
909 hdr->h_proto = htons(length);
911 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
912 if (fc & IEEE80211_FCTL_FROMDS)
913 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
915 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
917 dev->last_rx = jiffies;
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 */
929 stats->rx_bytes += length;
934 dev_kfree_skb_irq(skb);
940 /********************************************************************/
941 /* Rx path (info frames) */
942 /********************************************************************/
944 static void print_linkstatus(struct net_device *dev, u16 status)
948 if (suppress_linkstatus)
952 case HERMES_LINKSTATUS_NOT_CONNECTED:
955 case HERMES_LINKSTATUS_CONNECTED:
958 case HERMES_LINKSTATUS_DISCONNECTED:
961 case HERMES_LINKSTATUS_AP_CHANGE:
964 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
965 s = "AP Out of Range";
967 case HERMES_LINKSTATUS_AP_IN_RANGE:
970 case HERMES_LINKSTATUS_ASSOC_FAILED:
971 s = "Association Failed";
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;
993 } __attribute__ ((packed)) req;
994 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
995 struct prism2_scan_apinfo *atom = NULL;
1001 /* Allocate buffer for scan results */
1002 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1006 if (orinoco_lock(priv, &flags) != 0)
1009 /* Sanity checks in case user changed something in the meantime */
1010 if (! priv->bssid_fixed)
1013 if (strlen(priv->desired_essid) == 0)
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);
1021 printk(KERN_ERR "%s: Cannot read scan results\n",
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) {
1039 DEBUG(1, "%s: Requested AP not found in scan results\n",
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,
1049 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1052 orinoco_unlock(priv, &flags);
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;
1067 unsigned long flags;
1069 if (orinoco_lock(priv, &flags) != 0)
1072 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1073 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1077 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1079 /* Send event to user space */
1080 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1083 orinoco_unlock(priv, &flags);
1086 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1088 struct orinoco_private *priv = netdev_priv(dev);
1093 } __attribute__ ((packed)) info;
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),
1107 printk(KERN_ERR "%s: error %d reading info frame. "
1108 "Frame dropped.\n", dev->name, err);
1112 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1113 type = le16_to_cpu(info.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",
1123 len = sizeof(tallies);
1126 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1127 infofid, sizeof(info));
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 */
1148 case HERMES_INQ_LINKSTATUS: {
1149 struct hermes_linkstatus linkstatus;
1153 if (priv->iw_mode == IW_MODE_MONITOR)
1156 if (len != sizeof(linkstatus)) {
1157 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1162 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1163 infofid, sizeof(info));
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);
1177 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1178 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1179 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
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...
1193 schedule_work(&priv->wevent_work);
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);
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;
1213 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
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);
1227 /* Allocate buffer for results */
1228 buf = kmalloc(len, GFP_ATOMIC);
1230 /* No memory, so can't printk()... */
1233 /* Read scan data */
1234 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1235 infofid, sizeof(info));
1241 #ifdef ORINOCO_DEBUG
1244 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1245 for(i = 1; i < (len * 2); i++)
1246 printk(":%02X", buf[i]);
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);
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)
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 */
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;
1295 netif_carrier_off(dev); /* just to make sure */
1297 err = __orinoco_program_rids(dev);
1299 printk(KERN_ERR "%s: Error %d configuring card\n",
1304 /* Fire things up again */
1305 hermes_set_irqmask(hw, ORINOCO_INTEN);
1306 err = hermes_enable_port(hw, 0);
1308 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1313 netif_start_queue(dev);
1318 int __orinoco_down(struct net_device *dev)
1320 struct orinoco_private *priv = netdev_priv(dev);
1321 struct hermes *hw = &priv->hw;
1324 netif_stop_queue(dev);
1326 if (! priv->hw_unavailable) {
1327 if (! priv->broken_disableport) {
1328 err = hermes_disable_port(hw, 0);
1330 /* Some firmwares (e.g. Intersil 1.3.x) seem
1331 * to have problems disabling the port, oh
1333 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
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;
1349 static int orinoco_allocate_fid(struct net_device *dev)
1351 struct orinoco_private *priv = netdev_priv(dev);
1352 struct hermes *hw = &priv->hw;
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... ",
1362 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1363 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1365 printk("failed!\n");
1373 int orinoco_reinit_firmware(struct net_device *dev)
1375 struct orinoco_private *priv = netdev_priv(dev);
1376 struct hermes *hw = &priv->hw;
1379 err = hermes_init(hw);
1381 err = orinoco_allocate_fid(dev);
1386 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1388 hermes_t *hw = &priv->hw;
1391 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1392 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1393 priv->ndev->name, priv->bitratemode);
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);
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);
1416 /* Set fixed AP address */
1417 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1421 hermes_t *hw = &priv->hw;
1423 switch (priv->firmware_type) {
1424 case FIRMWARE_TYPE_AGERE:
1427 case FIRMWARE_TYPE_INTERSIL:
1428 if (priv->bssid_fixed)
1433 err = hermes_write_wordrec(hw, USER_BAP,
1434 HERMES_RID_CNFROAMINGMODE,
1437 case FIRMWARE_TYPE_SYMBOL:
1438 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1439 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1440 &priv->desired_bssid);
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;
1456 switch (priv->firmware_type) {
1457 case FIRMWARE_TYPE_AGERE:
1458 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1459 HERMES_RID_CNFWEPKEYS_AGERE,
1463 err = hermes_write_wordrec(hw, USER_BAP,
1464 HERMES_RID_CNFTXKEY_AGERE,
1469 case FIRMWARE_TYPE_INTERSIL:
1470 case FIRMWARE_TYPE_SYMBOL:
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);
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);
1494 /* Write the index of the key used in transmission */
1495 err = hermes_write_wordrec(hw, USER_BAP,
1496 HERMES_RID_CNFWEPDEFAULTKEYID,
1507 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1509 hermes_t *hw = &priv->hw;
1511 int master_wep_flag;
1515 __orinoco_hw_setup_wepkeys(priv);
1517 if (priv->wep_restrict)
1518 auth_flag = HERMES_AUTH_SHARED_KEY;
1520 auth_flag = HERMES_AUTH_OPEN;
1522 switch (priv->firmware_type) {
1523 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1525 /* Enable the shared-key authentication. */
1526 err = hermes_write_wordrec(hw, USER_BAP,
1527 HERMES_RID_CNFAUTHENTICATION_AGERE,
1530 err = hermes_write_wordrec(hw, USER_BAP,
1531 HERMES_RID_CNFWEPENABLED_AGERE,
1537 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1538 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
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;
1545 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1547 err = hermes_write_wordrec(hw, USER_BAP,
1548 HERMES_RID_CNFAUTHENTICATION,
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,
1571 static int __orinoco_program_rids(struct net_device *dev)
1573 struct orinoco_private *priv = netdev_priv(dev);
1574 hermes_t *hw = &priv->hw;
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);
1582 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1587 /* Set up the link mode */
1588 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1591 printk(KERN_ERR "%s: Error %d setting port type\n",
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,
1601 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1602 dev->name, err, priv->channel);
1607 if (priv->has_ibss) {
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...
1618 createibss = priv->createibss;
1621 err = hermes_write_wordrec(hw, USER_BAP,
1622 HERMES_RID_CNFCREATEIBSS,
1625 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1631 /* Set the desired BSSID */
1632 err = __orinoco_hw_set_wap(priv);
1634 printk(KERN_ERR "%s: Error %d setting AP address\n",
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),
1646 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1650 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1651 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1654 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
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),
1666 printk(KERN_ERR "%s: Error %d setting nickname\n",
1671 /* Set AP density */
1672 if (priv->has_sensitivity) {
1673 err = hermes_write_wordrec(hw, USER_BAP,
1674 HERMES_RID_CNFSYSTEMSCALE,
1677 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1678 "Disabling sensitivity control\n",
1681 priv->has_sensitivity = 0;
1685 /* Set RTS threshold */
1686 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1689 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1694 /* Set fragmentation threshold or MWO robustness */
1696 err = hermes_write_wordrec(hw, USER_BAP,
1697 HERMES_RID_CNFMWOROBUST_AGERE,
1700 err = hermes_write_wordrec(hw, USER_BAP,
1701 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1704 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1710 err = __orinoco_hw_set_bitrate(priv);
1712 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1717 /* Set power management */
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFPMENABLED,
1723 printk(KERN_ERR "%s: Error %d setting up PM\n",
1728 err = hermes_write_wordrec(hw, USER_BAP,
1729 HERMES_RID_CNFMULTICASTRECEIVE,
1732 printk(KERN_ERR "%s: Error %d setting up PM\n",
1736 err = hermes_write_wordrec(hw, USER_BAP,
1737 HERMES_RID_CNFMAXSLEEPDURATION,
1740 printk(KERN_ERR "%s: Error %d setting up PM\n",
1744 err = hermes_write_wordrec(hw, USER_BAP,
1745 HERMES_RID_CNFPMHOLDOVERDURATION,
1748 printk(KERN_ERR "%s: Error %d setting up PM\n",
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,
1760 printk(KERN_ERR "%s: Error %d setting preamble\n",
1766 /* Set up encryption */
1767 if (priv->has_wep) {
1768 err = __orinoco_hw_setup_wep(priv);
1770 printk(KERN_ERR "%s: Error %d activating WEP\n",
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);
1782 /* Disable monitor mode */
1783 dev->type = ARPHRD_ETHER;
1784 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1785 HERMES_TEST_STOP, 0, NULL);
1790 /* Set promiscuity / multicast*/
1791 priv->promiscuous = 0;
1794 /* FIXME: what about netif_tx_lock */
1795 __orinoco_set_multicast_list(dev);
1800 /* FIXME: return int? */
1802 __orinoco_set_multicast_list(struct net_device *dev)
1804 struct orinoco_private *priv = netdev_priv(dev);
1805 hermes_t *hw = &priv->hw;
1807 int promisc, mc_count;
1809 /* The Hermes doesn't seem to have an allmulti mode, so we go
1810 * into promiscuous mode and let the upper levels deal. */
1811 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1812 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1817 mc_count = dev->mc_count;
1820 if (promisc != priv->promiscuous) {
1821 err = hermes_write_wordrec(hw, USER_BAP,
1822 HERMES_RID_CNFPROMISCUOUSMODE,
1825 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1828 priv->promiscuous = promisc;
1831 if (! promisc && (mc_count || priv->mc_count) ) {
1832 struct dev_mc_list *p = dev->mc_list;
1833 struct hermes_multicast mclist;
1836 for (i = 0; i < mc_count; i++) {
1837 /* paranoia: is list shorter than mc_count? */
1839 /* paranoia: bad address size in list? */
1840 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1842 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1847 printk(KERN_WARNING "%s: Multicast list is "
1848 "longer than mc_count\n", dev->name);
1850 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1851 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1854 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1857 priv->mc_count = mc_count;
1860 /* Since we can set the promiscuous flag when it wasn't asked
1861 for, make sure the net_device knows about it. */
1862 if (priv->promiscuous)
1863 dev->flags |= IFF_PROMISC;
1865 dev->flags &= ~IFF_PROMISC;
1868 /* This must be called from user context, without locks held - use
1869 * schedule_work() */
1870 static void orinoco_reset(struct work_struct *work)
1872 struct orinoco_private *priv =
1873 container_of(work, struct orinoco_private, reset_work);
1874 struct net_device *dev = priv->ndev;
1875 struct hermes *hw = &priv->hw;
1877 unsigned long flags;
1879 if (orinoco_lock(priv, &flags) != 0)
1880 /* When the hardware becomes available again, whatever
1881 * detects that is responsible for re-initializing
1882 * it. So no need for anything further */
1885 netif_stop_queue(dev);
1887 /* Shut off interrupts. Depending on what state the hardware
1888 * is in, this might not work, but we'll try anyway */
1889 hermes_set_irqmask(hw, 0);
1890 hermes_write_regn(hw, EVACK, 0xffff);
1892 priv->hw_unavailable++;
1893 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1894 netif_carrier_off(dev);
1896 orinoco_unlock(priv, &flags);
1898 /* Scanning support: Cleanup of driver struct */
1899 kfree(priv->scan_result);
1900 priv->scan_result = NULL;
1901 priv->scan_inprogress = 0;
1903 if (priv->hard_reset) {
1904 err = (*priv->hard_reset)(priv);
1906 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1907 "performing hard reset\n", dev->name, err);
1912 err = orinoco_reinit_firmware(dev);
1914 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1919 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1921 priv->hw_unavailable--;
1923 /* priv->open or priv->hw_unavailable might have changed while
1924 * we dropped the lock */
1925 if (priv->open && (! priv->hw_unavailable)) {
1926 err = __orinoco_up(dev);
1928 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1931 dev->trans_start = jiffies;
1934 spin_unlock_irq(&priv->lock);
1938 hermes_set_irqmask(hw, 0);
1939 netif_device_detach(dev);
1940 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1943 /********************************************************************/
1944 /* Interrupt handler */
1945 /********************************************************************/
1947 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1949 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1952 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1954 /* This seems to happen a fair bit under load, but ignoring it
1955 seems to work fine...*/
1956 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1960 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
1962 struct net_device *dev = dev_id;
1963 struct orinoco_private *priv = netdev_priv(dev);
1964 hermes_t *hw = &priv->hw;
1965 int count = MAX_IRQLOOPS_PER_IRQ;
1967 /* These are used to detect a runaway interrupt situation */
1968 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1969 * we panic and shut down the hardware */
1970 static int last_irq_jiffy = 0; /* jiffies value the last time
1972 static int loops_this_jiffy = 0;
1973 unsigned long flags;
1975 if (orinoco_lock(priv, &flags) != 0) {
1976 /* If hw is unavailable - we don't know if the irq was
1981 evstat = hermes_read_regn(hw, EVSTAT);
1982 events = evstat & hw->inten;
1984 orinoco_unlock(priv, &flags);
1988 if (jiffies != last_irq_jiffy)
1989 loops_this_jiffy = 0;
1990 last_irq_jiffy = jiffies;
1992 while (events && count--) {
1993 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
1994 printk(KERN_WARNING "%s: IRQ handler is looping too "
1995 "much! Resetting.\n", dev->name);
1996 /* Disable interrupts for now */
1997 hermes_set_irqmask(hw, 0);
1998 schedule_work(&priv->reset_work);
2002 /* Check the card hasn't been removed */
2003 if (! hermes_present(hw)) {
2004 DEBUG(0, "orinoco_interrupt(): card removed\n");
2008 if (events & HERMES_EV_TICK)
2009 __orinoco_ev_tick(dev, hw);
2010 if (events & HERMES_EV_WTERR)
2011 __orinoco_ev_wterr(dev, hw);
2012 if (events & HERMES_EV_INFDROP)
2013 __orinoco_ev_infdrop(dev, hw);
2014 if (events & HERMES_EV_INFO)
2015 __orinoco_ev_info(dev, hw);
2016 if (events & HERMES_EV_RX)
2017 __orinoco_ev_rx(dev, hw);
2018 if (events & HERMES_EV_TXEXC)
2019 __orinoco_ev_txexc(dev, hw);
2020 if (events & HERMES_EV_TX)
2021 __orinoco_ev_tx(dev, hw);
2022 if (events & HERMES_EV_ALLOC)
2023 __orinoco_ev_alloc(dev, hw);
2025 hermes_write_regn(hw, EVACK, evstat);
2027 evstat = hermes_read_regn(hw, EVSTAT);
2028 events = evstat & hw->inten;
2031 orinoco_unlock(priv, &flags);
2035 /********************************************************************/
2036 /* Initialization */
2037 /********************************************************************/
2040 u16 id, variant, major, minor;
2041 } __attribute__ ((packed));
2043 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2045 if (nic_id->id < 0x8000)
2046 return FIRMWARE_TYPE_AGERE;
2047 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2048 return FIRMWARE_TYPE_SYMBOL;
2050 return FIRMWARE_TYPE_INTERSIL;
2053 /* Set priv->firmware type, determine firmware properties */
2054 static int determine_firmware(struct net_device *dev)
2056 struct orinoco_private *priv = netdev_priv(dev);
2057 hermes_t *hw = &priv->hw;
2059 struct comp_id nic_id, sta_id;
2060 unsigned int firmver;
2061 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2063 /* Get the hardware version */
2064 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2066 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2071 le16_to_cpus(&nic_id.id);
2072 le16_to_cpus(&nic_id.variant);
2073 le16_to_cpus(&nic_id.major);
2074 le16_to_cpus(&nic_id.minor);
2075 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2076 dev->name, nic_id.id, nic_id.variant,
2077 nic_id.major, nic_id.minor);
2079 priv->firmware_type = determine_firmware_type(&nic_id);
2081 /* Get the firmware version */
2082 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2084 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2089 le16_to_cpus(&sta_id.id);
2090 le16_to_cpus(&sta_id.variant);
2091 le16_to_cpus(&sta_id.major);
2092 le16_to_cpus(&sta_id.minor);
2093 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2094 dev->name, sta_id.id, sta_id.variant,
2095 sta_id.major, sta_id.minor);
2097 switch (sta_id.id) {
2099 printk(KERN_ERR "%s: Primary firmware is active\n",
2103 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2106 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2107 case 0x21: /* Symbol Spectrum24 Trilogy */
2110 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2115 /* Default capabilities */
2116 priv->has_sensitivity = 1;
2118 priv->has_preamble = 0;
2119 priv->has_port3 = 1;
2122 priv->has_big_wep = 0;
2124 /* Determine capabilities from the firmware version */
2125 switch (priv->firmware_type) {
2126 case FIRMWARE_TYPE_AGERE:
2127 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2128 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2129 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2130 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2132 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2134 priv->has_ibss = (firmver >= 0x60006);
2135 priv->has_wep = (firmver >= 0x40020);
2136 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2137 Gold cards from the others? */
2138 priv->has_mwo = (firmver >= 0x60000);
2139 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2140 priv->ibss_port = 1;
2141 priv->has_hostscan = (firmver >= 0x8000a);
2142 priv->broken_monitor = (firmver >= 0x80000);
2144 /* Tested with Agere firmware :
2145 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2146 * Tested CableTron firmware : 4.32 => Anton */
2148 case FIRMWARE_TYPE_SYMBOL:
2149 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2150 /* Intel MAC : 00:02:B3:* */
2151 /* 3Com MAC : 00:50:DA:* */
2152 memset(tmp, 0, sizeof(tmp));
2153 /* Get the Symbol firmware version */
2154 err = hermes_read_ltv(hw, USER_BAP,
2155 HERMES_RID_SECONDARYVERSION_SYMBOL,
2156 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2159 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2164 /* The firmware revision is a string, the format is
2165 * something like : "V2.20-01".
2166 * Quick and dirty parsing... - Jean II
2168 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2169 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2172 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2175 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2178 priv->has_ibss = (firmver >= 0x20000);
2179 priv->has_wep = (firmver >= 0x15012);
2180 priv->has_big_wep = (firmver >= 0x20000);
2181 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2182 (firmver >= 0x29000 && firmver < 0x30000) ||
2184 priv->has_preamble = (firmver >= 0x20000);
2185 priv->ibss_port = 4;
2186 priv->broken_disableport = (firmver == 0x25013) ||
2187 (firmver >= 0x30000 && firmver <= 0x31000);
2188 priv->has_hostscan = (firmver >= 0x31001) ||
2189 (firmver >= 0x29057 && firmver < 0x30000);
2190 /* Tested with Intel firmware : 0x20015 => Jean II */
2191 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2193 case FIRMWARE_TYPE_INTERSIL:
2194 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2195 * Samsung, Compaq 100/200 and Proxim are slightly
2196 * different and less well tested */
2197 /* D-Link MAC : 00:40:05:* */
2198 /* Addtron MAC : 00:90:D1:* */
2199 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2200 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2203 firmver = ((unsigned long)sta_id.major << 16) |
2204 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2206 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2207 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2208 priv->has_pm = (firmver >= 0x000700);
2209 priv->has_hostscan = (firmver >= 0x010301);
2211 if (firmver >= 0x000800)
2212 priv->ibss_port = 0;
2214 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2215 "than v0.8.x - several features not supported\n",
2217 priv->ibss_port = 1;
2221 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2227 static int orinoco_init(struct net_device *dev)
2229 struct orinoco_private *priv = netdev_priv(dev);
2230 hermes_t *hw = &priv->hw;
2232 struct hermes_idstring nickbuf;
2235 DECLARE_MAC_BUF(mac);
2237 /* No need to lock, the hw_unavailable flag is already set in
2238 * alloc_orinocodev() */
2239 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2241 /* Initialize the firmware */
2242 err = hermes_init(hw);
2244 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2249 err = determine_firmware(dev);
2251 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2256 if (priv->has_port3)
2257 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2259 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2261 if (priv->has_wep) {
2262 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2263 if (priv->has_big_wep)
2264 printk("104-bit key\n");
2266 printk("40-bit key\n");
2269 /* Get the MAC address */
2270 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2271 ETH_ALEN, NULL, dev->dev_addr);
2273 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2278 printk(KERN_DEBUG "%s: MAC address %s\n",
2279 dev->name, print_mac(mac, dev->dev_addr));
2281 /* Get the station name */
2282 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2283 sizeof(nickbuf), &reclen, &nickbuf);
2285 printk(KERN_ERR "%s: failed to read station name\n",
2290 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2292 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2293 memcpy(priv->nick, &nickbuf.val, len);
2294 priv->nick[len] = '\0';
2296 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2298 err = orinoco_allocate_fid(dev);
2300 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2305 /* Get allowed channels */
2306 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2307 &priv->channel_mask);
2309 printk(KERN_ERR "%s: failed to read channel list!\n",
2314 /* Get initial AP density */
2315 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2317 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2318 priv->has_sensitivity = 0;
2321 /* Get initial RTS threshold */
2322 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2325 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2330 /* Get initial fragmentation settings */
2332 err = hermes_read_wordrec(hw, USER_BAP,
2333 HERMES_RID_CNFMWOROBUST_AGERE,
2336 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2337 &priv->frag_thresh);
2339 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2344 /* Power management setup */
2348 err = hermes_read_wordrec(hw, USER_BAP,
2349 HERMES_RID_CNFMAXSLEEPDURATION,
2352 printk(KERN_ERR "%s: failed to read power management period!\n",
2356 err = hermes_read_wordrec(hw, USER_BAP,
2357 HERMES_RID_CNFPMHOLDOVERDURATION,
2360 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2366 /* Preamble setup */
2367 if (priv->has_preamble) {
2368 err = hermes_read_wordrec(hw, USER_BAP,
2369 HERMES_RID_CNFPREAMBLE_SYMBOL,
2375 /* Set up the default configuration */
2376 priv->iw_mode = IW_MODE_INFRA;
2377 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2378 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2379 set_port_type(priv);
2380 priv->channel = 0; /* use firmware default */
2382 priv->promiscuous = 0;
2386 /* Make the hardware available, as long as it hasn't been
2387 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2388 spin_lock_irq(&priv->lock);
2389 priv->hw_unavailable--;
2390 spin_unlock_irq(&priv->lock);
2392 printk(KERN_DEBUG "%s: ready\n", dev->name);
2398 struct net_device *alloc_orinocodev(int sizeof_card,
2399 int (*hard_reset)(struct orinoco_private *))
2401 struct net_device *dev;
2402 struct orinoco_private *priv;
2404 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2407 priv = netdev_priv(dev);
2410 priv->card = (void *)((unsigned long)priv
2411 + sizeof(struct orinoco_private));
2415 /* Setup / override net_device fields */
2416 dev->init = orinoco_init;
2417 dev->hard_start_xmit = orinoco_xmit;
2418 dev->tx_timeout = orinoco_tx_timeout;
2419 dev->watchdog_timeo = HZ; /* 1 second timeout */
2420 dev->get_stats = orinoco_get_stats;
2421 dev->ethtool_ops = &orinoco_ethtool_ops;
2422 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2424 priv->wireless_data.spy_data = &priv->spy_data;
2425 dev->wireless_data = &priv->wireless_data;
2427 dev->change_mtu = orinoco_change_mtu;
2428 dev->set_multicast_list = orinoco_set_multicast_list;
2429 /* we use the default eth_mac_addr for setting the MAC addr */
2431 /* Set up default callbacks */
2432 dev->open = orinoco_open;
2433 dev->stop = orinoco_stop;
2434 priv->hard_reset = hard_reset;
2436 spin_lock_init(&priv->lock);
2438 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2439 * before anything else touches the
2441 INIT_WORK(&priv->reset_work, orinoco_reset);
2442 INIT_WORK(&priv->join_work, orinoco_join_ap);
2443 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2445 netif_carrier_off(dev);
2446 priv->last_linkstatus = 0xffff;
2452 void free_orinocodev(struct net_device *dev)
2454 struct orinoco_private *priv = netdev_priv(dev);
2456 kfree(priv->scan_result);
2460 /********************************************************************/
2461 /* Wireless extensions */
2462 /********************************************************************/
2464 /* Return : < 0 -> error code ; >= 0 -> length */
2465 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2466 char buf[IW_ESSID_MAX_SIZE+1])
2468 hermes_t *hw = &priv->hw;
2470 struct hermes_idstring essidbuf;
2471 char *p = (char *)(&essidbuf.val);
2473 unsigned long flags;
2475 if (orinoco_lock(priv, &flags) != 0)
2478 if (strlen(priv->desired_essid) > 0) {
2479 /* We read the desired SSID from the hardware rather
2480 than from priv->desired_essid, just in case the
2481 firmware is allowed to change it on us. I'm not
2483 /* My guess is that the OWNSSID should always be whatever
2484 * we set to the card, whereas CURRENT_SSID is the one that
2485 * may change... - Jean II */
2490 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2491 HERMES_RID_CNFDESIREDSSID;
2493 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2500 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2501 sizeof(essidbuf), NULL, &essidbuf);
2506 len = le16_to_cpu(essidbuf.len);
2507 BUG_ON(len > IW_ESSID_MAX_SIZE);
2509 memset(buf, 0, IW_ESSID_MAX_SIZE);
2510 memcpy(buf, p, len);
2514 orinoco_unlock(priv, &flags);
2519 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2522 hermes_t *hw = &priv->hw;
2526 unsigned long flags;
2528 if (orinoco_lock(priv, &flags) != 0)
2531 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2535 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2541 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2542 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2543 priv->ndev->name, channel);
2548 freq = channel_frequency[channel-1] * 100000;
2551 orinoco_unlock(priv, &flags);
2555 return err ? err : freq;
2558 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2559 int *numrates, s32 *rates, int max)
2561 hermes_t *hw = &priv->hw;
2562 struct hermes_idstring list;
2563 unsigned char *p = (unsigned char *)&list.val;
2567 unsigned long flags;
2569 if (orinoco_lock(priv, &flags) != 0)
2572 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2573 sizeof(list), NULL, &list);
2574 orinoco_unlock(priv, &flags);
2579 num = le16_to_cpu(list.len);
2581 num = min(num, max);
2583 for (i = 0; i < num; i++) {
2584 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2590 static int orinoco_ioctl_getname(struct net_device *dev,
2591 struct iw_request_info *info,
2595 struct orinoco_private *priv = netdev_priv(dev);
2599 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2601 if (!err && (numrates > 2))
2602 strcpy(name, "IEEE 802.11b");
2604 strcpy(name, "IEEE 802.11-DS");
2609 static int orinoco_ioctl_setwap(struct net_device *dev,
2610 struct iw_request_info *info,
2611 struct sockaddr *ap_addr,
2614 struct orinoco_private *priv = netdev_priv(dev);
2615 int err = -EINPROGRESS; /* Call commit handler */
2616 unsigned long flags;
2617 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2618 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2620 if (orinoco_lock(priv, &flags) != 0)
2623 /* Enable automatic roaming - no sanity checks are needed */
2624 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2625 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2626 priv->bssid_fixed = 0;
2627 memset(priv->desired_bssid, 0, ETH_ALEN);
2629 /* "off" means keep existing connection */
2630 if (ap_addr->sa_data[0] == 0) {
2631 __orinoco_hw_set_wap(priv);
2637 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2638 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2639 "support manual roaming\n",
2645 if (priv->iw_mode != IW_MODE_INFRA) {
2646 printk(KERN_WARNING "%s: Manual roaming supported only in "
2647 "managed mode\n", dev->name);
2652 /* Intersil firmware hangs without Desired ESSID */
2653 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2654 strlen(priv->desired_essid) == 0) {
2655 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2656 "manual roaming\n", dev->name);
2661 /* Finally, enable manual roaming */
2662 priv->bssid_fixed = 1;
2663 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2666 orinoco_unlock(priv, &flags);
2670 static int orinoco_ioctl_getwap(struct net_device *dev,
2671 struct iw_request_info *info,
2672 struct sockaddr *ap_addr,
2675 struct orinoco_private *priv = netdev_priv(dev);
2677 hermes_t *hw = &priv->hw;
2679 unsigned long flags;
2681 if (orinoco_lock(priv, &flags) != 0)
2684 ap_addr->sa_family = ARPHRD_ETHER;
2685 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2686 ETH_ALEN, NULL, ap_addr->sa_data);
2688 orinoco_unlock(priv, &flags);
2693 static int orinoco_ioctl_setmode(struct net_device *dev,
2694 struct iw_request_info *info,
2698 struct orinoco_private *priv = netdev_priv(dev);
2699 int err = -EINPROGRESS; /* Call commit handler */
2700 unsigned long flags;
2702 if (priv->iw_mode == *mode)
2705 if (orinoco_lock(priv, &flags) != 0)
2710 if (!priv->has_ibss && !priv->has_port3)
2717 case IW_MODE_MONITOR:
2718 if (priv->broken_monitor && !force_monitor) {
2719 printk(KERN_WARNING "%s: Monitor mode support is "
2720 "buggy in this firmware, not enabling\n",
2731 if (err == -EINPROGRESS) {
2732 priv->iw_mode = *mode;
2733 set_port_type(priv);
2736 orinoco_unlock(priv, &flags);
2741 static int orinoco_ioctl_getmode(struct net_device *dev,
2742 struct iw_request_info *info,
2746 struct orinoco_private *priv = netdev_priv(dev);
2748 *mode = priv->iw_mode;
2752 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2753 struct iw_request_info *info,
2754 struct iw_point *rrq,
2757 struct orinoco_private *priv = netdev_priv(dev);
2759 struct iw_range *range = (struct iw_range *) extra;
2763 rrq->length = sizeof(struct iw_range);
2764 memset(range, 0, sizeof(struct iw_range));
2766 range->we_version_compiled = WIRELESS_EXT;
2767 range->we_version_source = 14;
2769 /* Set available channels/frequencies */
2770 range->num_channels = NUM_CHANNELS;
2772 for (i = 0; i < NUM_CHANNELS; i++) {
2773 if (priv->channel_mask & (1 << i)) {
2774 range->freq[k].i = i + 1;
2775 range->freq[k].m = channel_frequency[i] * 100000;
2776 range->freq[k].e = 1;
2780 if (k >= IW_MAX_FREQUENCIES)
2783 range->num_frequency = k;
2784 range->sensitivity = 3;
2786 if (priv->has_wep) {
2787 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2788 range->encoding_size[0] = SMALL_KEY_SIZE;
2789 range->num_encoding_sizes = 1;
2791 if (priv->has_big_wep) {
2792 range->encoding_size[1] = LARGE_KEY_SIZE;
2793 range->num_encoding_sizes = 2;
2797 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2798 /* Quality stats meaningless in ad-hoc mode */
2800 range->max_qual.qual = 0x8b - 0x2f;
2801 range->max_qual.level = 0x2f - 0x95 - 1;
2802 range->max_qual.noise = 0x2f - 0x95 - 1;
2803 /* Need to get better values */
2804 range->avg_qual.qual = 0x24;
2805 range->avg_qual.level = 0xC2;
2806 range->avg_qual.noise = 0x9E;
2809 err = orinoco_hw_get_bitratelist(priv, &numrates,
2810 range->bitrate, IW_MAX_BITRATES);
2813 range->num_bitrates = numrates;
2815 /* Set an indication of the max TCP throughput in bit/s that we can
2816 * expect using this interface. May be use for QoS stuff...
2819 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2821 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2824 range->max_rts = 2347;
2825 range->min_frag = 256;
2826 range->max_frag = 2346;
2829 range->max_pmp = 65535000;
2831 range->max_pmt = 65535 * 1000; /* ??? */
2832 range->pmp_flags = IW_POWER_PERIOD;
2833 range->pmt_flags = IW_POWER_TIMEOUT;
2834 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2836 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2837 range->retry_flags = IW_RETRY_LIMIT;
2838 range->r_time_flags = IW_RETRY_LIFETIME;
2839 range->min_retry = 0;
2840 range->max_retry = 65535; /* ??? */
2841 range->min_r_time = 0;
2842 range->max_r_time = 65535 * 1000; /* ??? */
2844 /* Event capability (kernel) */
2845 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2846 /* Event capability (driver) */
2847 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2848 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2849 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2850 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2855 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2856 struct iw_request_info *info,
2857 struct iw_point *erq,
2860 struct orinoco_private *priv = netdev_priv(dev);
2861 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2862 int setindex = priv->tx_key;
2863 int enable = priv->wep_on;
2864 int restricted = priv->wep_restrict;
2866 int err = -EINPROGRESS; /* Call commit handler */
2867 unsigned long flags;
2869 if (! priv->has_wep)
2873 /* We actually have a key to set - check its length */
2874 if (erq->length > LARGE_KEY_SIZE)
2877 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2881 if (orinoco_lock(priv, &flags) != 0)
2884 if (erq->length > 0) {
2885 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2886 index = priv->tx_key;
2888 /* Adjust key length to a supported value */
2889 if (erq->length > SMALL_KEY_SIZE) {
2890 xlen = LARGE_KEY_SIZE;
2891 } else if (erq->length > 0) {
2892 xlen = SMALL_KEY_SIZE;
2896 /* Switch on WEP if off */
2897 if ((!enable) && (xlen > 0)) {
2902 /* Important note : if the user do "iwconfig eth0 enc off",
2903 * we will arrive there with an index of -1. This is valid
2904 * but need to be taken care off... Jean II */
2905 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2906 if((index != -1) || (erq->flags == 0)) {
2911 /* Set the index : Check that the key is valid */
2912 if(priv->keys[index].len == 0) {
2920 if (erq->flags & IW_ENCODE_DISABLED)
2922 if (erq->flags & IW_ENCODE_OPEN)
2924 if (erq->flags & IW_ENCODE_RESTRICTED)
2927 if (erq->pointer && erq->length > 0) {
2928 priv->keys[index].len = cpu_to_le16(xlen);
2929 memset(priv->keys[index].data, 0,
2930 sizeof(priv->keys[index].data));
2931 memcpy(priv->keys[index].data, keybuf, erq->length);
2933 priv->tx_key = setindex;
2935 /* Try fast key change if connected and only keys are changed */
2936 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2937 netif_carrier_ok(dev)) {
2938 err = __orinoco_hw_setup_wepkeys(priv);
2939 /* No need to commit if successful */
2943 priv->wep_on = enable;
2944 priv->wep_restrict = restricted;
2947 orinoco_unlock(priv, &flags);
2952 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2953 struct iw_request_info *info,
2954 struct iw_point *erq,
2957 struct orinoco_private *priv = netdev_priv(dev);
2958 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2960 unsigned long flags;
2962 if (! priv->has_wep)
2965 if (orinoco_lock(priv, &flags) != 0)
2968 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2969 index = priv->tx_key;
2973 erq->flags |= IW_ENCODE_DISABLED;
2974 erq->flags |= index + 1;
2976 if (priv->wep_restrict)
2977 erq->flags |= IW_ENCODE_RESTRICTED;
2979 erq->flags |= IW_ENCODE_OPEN;
2981 xlen = le16_to_cpu(priv->keys[index].len);
2985 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
2987 orinoco_unlock(priv, &flags);
2991 static int orinoco_ioctl_setessid(struct net_device *dev,
2992 struct iw_request_info *info,
2993 struct iw_point *erq,
2996 struct orinoco_private *priv = netdev_priv(dev);
2997 unsigned long flags;
2999 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3000 * anyway... - Jean II */
3002 /* Hum... Should not use Wireless Extension constant (may change),
3003 * should use our own... - Jean II */
3004 if (erq->length > IW_ESSID_MAX_SIZE)
3007 if (orinoco_lock(priv, &flags) != 0)
3010 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3011 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3013 /* If not ANY, get the new ESSID */
3015 memcpy(priv->desired_essid, essidbuf, erq->length);
3018 orinoco_unlock(priv, &flags);
3020 return -EINPROGRESS; /* Call commit handler */
3023 static int orinoco_ioctl_getessid(struct net_device *dev,
3024 struct iw_request_info *info,
3025 struct iw_point *erq,
3028 struct orinoco_private *priv = netdev_priv(dev);
3031 unsigned long flags;
3033 if (netif_running(dev)) {
3034 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3039 if (orinoco_lock(priv, &flags) != 0)
3041 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3042 erq->length = strlen(priv->desired_essid);
3043 orinoco_unlock(priv, &flags);
3051 static int orinoco_ioctl_setnick(struct net_device *dev,
3052 struct iw_request_info *info,
3053 struct iw_point *nrq,
3056 struct orinoco_private *priv = netdev_priv(dev);
3057 unsigned long flags;
3059 if (nrq->length > IW_ESSID_MAX_SIZE)
3062 if (orinoco_lock(priv, &flags) != 0)
3065 memset(priv->nick, 0, sizeof(priv->nick));
3066 memcpy(priv->nick, nickbuf, nrq->length);
3068 orinoco_unlock(priv, &flags);
3070 return -EINPROGRESS; /* Call commit handler */
3073 static int orinoco_ioctl_getnick(struct net_device *dev,
3074 struct iw_request_info *info,
3075 struct iw_point *nrq,
3078 struct orinoco_private *priv = netdev_priv(dev);
3079 unsigned long flags;
3081 if (orinoco_lock(priv, &flags) != 0)
3084 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3085 orinoco_unlock(priv, &flags);
3087 nrq->length = strlen(priv->nick);
3092 static int orinoco_ioctl_setfreq(struct net_device *dev,
3093 struct iw_request_info *info,
3094 struct iw_freq *frq,
3097 struct orinoco_private *priv = netdev_priv(dev);
3099 unsigned long flags;
3100 int err = -EINPROGRESS; /* Call commit handler */
3102 /* In infrastructure mode the AP sets the channel */
3103 if (priv->iw_mode == IW_MODE_INFRA)
3106 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3107 /* Setting by channel number */
3110 /* Setting by frequency - search the table */
3114 for (i = 0; i < (6 - frq->e); i++)
3117 for (i = 0; i < NUM_CHANNELS; i++)
3118 if (frq->m == (channel_frequency[i] * mult))
3122 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3123 ! (priv->channel_mask & (1 << (chan-1)) ) )
3126 if (orinoco_lock(priv, &flags) != 0)
3129 priv->channel = chan;
3130 if (priv->iw_mode == IW_MODE_MONITOR) {
3131 /* Fast channel change - no commit if successful */
3132 hermes_t *hw = &priv->hw;
3133 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3134 HERMES_TEST_SET_CHANNEL,
3137 orinoco_unlock(priv, &flags);
3142 static int orinoco_ioctl_getfreq(struct net_device *dev,
3143 struct iw_request_info *info,
3144 struct iw_freq *frq,
3147 struct orinoco_private *priv = netdev_priv(dev);
3150 /* Locking done in there */
3151 tmp = orinoco_hw_get_freq(priv);
3162 static int orinoco_ioctl_getsens(struct net_device *dev,
3163 struct iw_request_info *info,
3164 struct iw_param *srq,
3167 struct orinoco_private *priv = netdev_priv(dev);
3168 hermes_t *hw = &priv->hw;
3171 unsigned long flags;
3173 if (!priv->has_sensitivity)
3176 if (orinoco_lock(priv, &flags) != 0)
3178 err = hermes_read_wordrec(hw, USER_BAP,
3179 HERMES_RID_CNFSYSTEMSCALE, &val);
3180 orinoco_unlock(priv, &flags);
3186 srq->fixed = 0; /* auto */
3191 static int orinoco_ioctl_setsens(struct net_device *dev,
3192 struct iw_request_info *info,
3193 struct iw_param *srq,
3196 struct orinoco_private *priv = netdev_priv(dev);
3197 int val = srq->value;
3198 unsigned long flags;
3200 if (!priv->has_sensitivity)
3203 if ((val < 1) || (val > 3))
3206 if (orinoco_lock(priv, &flags) != 0)
3208 priv->ap_density = val;
3209 orinoco_unlock(priv, &flags);
3211 return -EINPROGRESS; /* Call commit handler */
3214 static int orinoco_ioctl_setrts(struct net_device *dev,
3215 struct iw_request_info *info,
3216 struct iw_param *rrq,
3219 struct orinoco_private *priv = netdev_priv(dev);
3220 int val = rrq->value;
3221 unsigned long flags;
3226 if ( (val < 0) || (val > 2347) )
3229 if (orinoco_lock(priv, &flags) != 0)
3232 priv->rts_thresh = val;
3233 orinoco_unlock(priv, &flags);
3235 return -EINPROGRESS; /* Call commit handler */
3238 static int orinoco_ioctl_getrts(struct net_device *dev,
3239 struct iw_request_info *info,
3240 struct iw_param *rrq,
3243 struct orinoco_private *priv = netdev_priv(dev);
3245 rrq->value = priv->rts_thresh;
3246 rrq->disabled = (rrq->value == 2347);
3252 static int orinoco_ioctl_setfrag(struct net_device *dev,
3253 struct iw_request_info *info,
3254 struct iw_param *frq,
3257 struct orinoco_private *priv = netdev_priv(dev);
3258 int err = -EINPROGRESS; /* Call commit handler */
3259 unsigned long flags;
3261 if (orinoco_lock(priv, &flags) != 0)
3264 if (priv->has_mwo) {
3266 priv->mwo_robust = 0;
3269 printk(KERN_WARNING "%s: Fixed fragmentation is "
3270 "not supported on this firmware. "
3271 "Using MWO robust instead.\n", dev->name);
3272 priv->mwo_robust = 1;
3276 priv->frag_thresh = 2346;
3278 if ( (frq->value < 256) || (frq->value > 2346) )
3281 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3285 orinoco_unlock(priv, &flags);
3290 static int orinoco_ioctl_getfrag(struct net_device *dev,
3291 struct iw_request_info *info,
3292 struct iw_param *frq,
3295 struct orinoco_private *priv = netdev_priv(dev);
3296 hermes_t *hw = &priv->hw;
3299 unsigned long flags;
3301 if (orinoco_lock(priv, &flags) != 0)
3304 if (priv->has_mwo) {
3305 err = hermes_read_wordrec(hw, USER_BAP,
3306 HERMES_RID_CNFMWOROBUST_AGERE,
3311 frq->value = val ? 2347 : 0;
3312 frq->disabled = ! val;
3315 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3321 frq->disabled = (val >= 2346);
3325 orinoco_unlock(priv, &flags);
3330 static int orinoco_ioctl_setrate(struct net_device *dev,
3331 struct iw_request_info *info,
3332 struct iw_param *rrq,
3335 struct orinoco_private *priv = netdev_priv(dev);
3337 int bitrate; /* 100s of kilobits */
3339 unsigned long flags;
3341 /* As the user space doesn't know our highest rate, it uses -1
3342 * to ask us to set the highest rate. Test it using "iwconfig
3343 * ethX rate auto" - Jean II */
3344 if (rrq->value == -1)
3347 if (rrq->value % 100000)
3349 bitrate = rrq->value / 100000;
3352 if ( (bitrate != 10) && (bitrate != 20) &&
3353 (bitrate != 55) && (bitrate != 110) )
3356 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3357 if ( (bitrate_table[i].bitrate == bitrate) &&
3358 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3366 if (orinoco_lock(priv, &flags) != 0)
3368 priv->bitratemode = ratemode;
3369 orinoco_unlock(priv, &flags);
3371 return -EINPROGRESS;
3374 static int orinoco_ioctl_getrate(struct net_device *dev,
3375 struct iw_request_info *info,
3376 struct iw_param *rrq,
3379 struct orinoco_private *priv = netdev_priv(dev);
3380 hermes_t *hw = &priv->hw;
3385 unsigned long flags;
3387 if (orinoco_lock(priv, &flags) != 0)
3390 ratemode = priv->bitratemode;
3392 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3394 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3395 rrq->fixed = ! bitrate_table[ratemode].automatic;
3398 /* If the interface is running we try to find more about the
3400 if (netif_running(dev)) {
3401 err = hermes_read_wordrec(hw, USER_BAP,
3402 HERMES_RID_CURRENTTXRATE, &val);
3406 switch (priv->firmware_type) {
3407 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3408 /* Note : in Lucent firmware, the return value of
3409 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3410 * and therefore is totally different from the
3411 * encoding of HERMES_RID_CNFTXRATECONTROL.
3412 * Don't forget that 6Mb/s is really 5.5Mb/s */
3414 rrq->value = 5500000;
3416 rrq->value = val * 1000000;
3418 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3419 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3420 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3421 if (bitrate_table[i].intersil_txratectrl == val) {
3425 if (i >= BITRATE_TABLE_SIZE)
3426 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3429 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3437 orinoco_unlock(priv, &flags);
3442 static int orinoco_ioctl_setpower(struct net_device *dev,
3443 struct iw_request_info *info,
3444 struct iw_param *prq,
3447 struct orinoco_private *priv = netdev_priv(dev);
3448 int err = -EINPROGRESS; /* Call commit handler */
3449 unsigned long flags;
3451 if (orinoco_lock(priv, &flags) != 0)
3454 if (prq->disabled) {
3457 switch (prq->flags & IW_POWER_MODE) {
3458 case IW_POWER_UNICAST_R:
3462 case IW_POWER_ALL_R:
3467 /* No flags : but we may have a value - Jean II */
3474 if (prq->flags & IW_POWER_TIMEOUT) {
3476 priv->pm_timeout = prq->value / 1000;
3478 if (prq->flags & IW_POWER_PERIOD) {
3480 priv->pm_period = prq->value / 1000;
3482 /* It's valid to not have a value if we are just toggling
3483 * the flags... Jean II */
3491 orinoco_unlock(priv, &flags);
3496 static int orinoco_ioctl_getpower(struct net_device *dev,
3497 struct iw_request_info *info,
3498 struct iw_param *prq,
3501 struct orinoco_private *priv = netdev_priv(dev);
3502 hermes_t *hw = &priv->hw;
3504 u16 enable, period, timeout, mcast;
3505 unsigned long flags;
3507 if (orinoco_lock(priv, &flags) != 0)
3510 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3514 err = hermes_read_wordrec(hw, USER_BAP,
3515 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3519 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3523 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3527 prq->disabled = !enable;
3528 /* Note : by default, display the period */
3529 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3530 prq->flags = IW_POWER_TIMEOUT;
3531 prq->value = timeout * 1000;
3533 prq->flags = IW_POWER_PERIOD;
3534 prq->value = period * 1000;
3537 prq->flags |= IW_POWER_ALL_R;
3539 prq->flags |= IW_POWER_UNICAST_R;
3542 orinoco_unlock(priv, &flags);
3547 static int orinoco_ioctl_getretry(struct net_device *dev,
3548 struct iw_request_info *info,
3549 struct iw_param *rrq,
3552 struct orinoco_private *priv = netdev_priv(dev);
3553 hermes_t *hw = &priv->hw;
3555 u16 short_limit, long_limit, lifetime;
3556 unsigned long flags;
3558 if (orinoco_lock(priv, &flags) != 0)
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3566 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3571 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3576 rrq->disabled = 0; /* Can't be disabled */
3578 /* Note : by default, display the retry number */
3579 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3580 rrq->flags = IW_RETRY_LIFETIME;
3581 rrq->value = lifetime * 1000; /* ??? */
3583 /* By default, display the min number */
3584 if ((rrq->flags & IW_RETRY_LONG)) {
3585 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
3586 rrq->value = long_limit;
3588 rrq->flags = IW_RETRY_LIMIT;
3589 rrq->value = short_limit;
3590 if(short_limit != long_limit)
3591 rrq->flags |= IW_RETRY_SHORT;
3596 orinoco_unlock(priv, &flags);
3601 static int orinoco_ioctl_reset(struct net_device *dev,
3602 struct iw_request_info *info,
3606 struct orinoco_private *priv = netdev_priv(dev);
3608 if (! capable(CAP_NET_ADMIN))
3611 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3612 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3614 /* Firmware reset */
3615 orinoco_reset(&priv->reset_work);
3617 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3619 schedule_work(&priv->reset_work);
3625 static int orinoco_ioctl_setibssport(struct net_device *dev,
3626 struct iw_request_info *info,
3631 struct orinoco_private *priv = netdev_priv(dev);
3632 int val = *( (int *) extra );
3633 unsigned long flags;
3635 if (orinoco_lock(priv, &flags) != 0)
3638 priv->ibss_port = val ;
3640 /* Actually update the mode we are using */
3641 set_port_type(priv);
3643 orinoco_unlock(priv, &flags);
3644 return -EINPROGRESS; /* Call commit handler */
3647 static int orinoco_ioctl_getibssport(struct net_device *dev,
3648 struct iw_request_info *info,
3652 struct orinoco_private *priv = netdev_priv(dev);
3653 int *val = (int *) extra;
3655 *val = priv->ibss_port;
3659 static int orinoco_ioctl_setport3(struct net_device *dev,
3660 struct iw_request_info *info,
3664 struct orinoco_private *priv = netdev_priv(dev);
3665 int val = *( (int *) extra );
3667 unsigned long flags;
3669 if (orinoco_lock(priv, &flags) != 0)
3673 case 0: /* Try to do IEEE ad-hoc mode */
3674 if (! priv->has_ibss) {
3678 priv->prefer_port3 = 0;
3682 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3683 if (! priv->has_port3) {
3687 priv->prefer_port3 = 1;
3695 /* Actually update the mode we are using */
3696 set_port_type(priv);
3700 orinoco_unlock(priv, &flags);
3705 static int orinoco_ioctl_getport3(struct net_device *dev,
3706 struct iw_request_info *info,
3710 struct orinoco_private *priv = netdev_priv(dev);
3711 int *val = (int *) extra;
3713 *val = priv->prefer_port3;
3717 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3718 struct iw_request_info *info,
3722 struct orinoco_private *priv = netdev_priv(dev);
3723 unsigned long flags;
3726 if (! priv->has_preamble)
3729 /* 802.11b has recently defined some short preamble.
3730 * Basically, the Phy header has been reduced in size.
3731 * This increase performance, especially at high rates
3732 * (the preamble is transmitted at 1Mb/s), unfortunately
3733 * this give compatibility troubles... - Jean II */
3734 val = *( (int *) extra );
3736 if (orinoco_lock(priv, &flags) != 0)
3744 orinoco_unlock(priv, &flags);
3746 return -EINPROGRESS; /* Call commit handler */
3749 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3750 struct iw_request_info *info,
3754 struct orinoco_private *priv = netdev_priv(dev);
3755 int *val = (int *) extra;
3757 if (! priv->has_preamble)
3760 *val = priv->preamble;
3764 /* ioctl interface to hermes_read_ltv()
3765 * To use with iwpriv, pass the RID as the token argument, e.g.
3766 * iwpriv get_rid [0xfc00]
3767 * At least Wireless Tools 25 is required to use iwpriv.
3768 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3769 static int orinoco_ioctl_getrid(struct net_device *dev,
3770 struct iw_request_info *info,
3771 struct iw_point *data,
3774 struct orinoco_private *priv = netdev_priv(dev);
3775 hermes_t *hw = &priv->hw;
3776 int rid = data->flags;
3779 unsigned long flags;
3781 /* It's a "get" function, but we don't want users to access the
3782 * WEP key and other raw firmware data */
3783 if (! capable(CAP_NET_ADMIN))
3786 if (rid < 0xfc00 || rid > 0xffff)
3789 if (orinoco_lock(priv, &flags) != 0)
3792 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3797 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3801 orinoco_unlock(priv, &flags);
3805 /* Trigger a scan (look for other cells in the vicinity */
3806 static int orinoco_ioctl_setscan(struct net_device *dev,
3807 struct iw_request_info *info,
3808 struct iw_param *srq,
3811 struct orinoco_private *priv = netdev_priv(dev);
3812 hermes_t *hw = &priv->hw;
3814 unsigned long flags;
3816 /* Note : you may have realised that, as this is a SET operation,
3817 * this is privileged and therefore a normal user can't
3819 * This is not an error, while the device perform scanning,
3820 * traffic doesn't flow, so it's a perfect DoS...
3823 if (orinoco_lock(priv, &flags) != 0)
3826 /* Scanning with port 0 disabled would fail */
3827 if (!netif_running(dev)) {
3832 /* In monitor mode, the scan results are always empty.
3833 * Probe responses are passed to the driver as received
3834 * frames and could be processed in software. */
3835 if (priv->iw_mode == IW_MODE_MONITOR) {
3840 /* Note : because we don't lock out the irq handler, the way
3841 * we access scan variables in priv is critical.
3842 * o scan_inprogress : not touched by irq handler
3843 * o scan_mode : not touched by irq handler
3844 * o scan_result : irq is strict producer, non-irq is strict
3846 * o scan_len : synchronised with scan_result
3847 * Before modifying anything on those variables, please think hard !
3850 /* If there is still some left-over scan results, get rid of it */
3851 if (priv->scan_result != NULL) {
3852 /* What's likely is that a client did crash or was killed
3853 * between triggering the scan request and reading the
3854 * results, so we need to reset everything.
3855 * Some clients that are too slow may suffer from that...
3857 kfree(priv->scan_result);
3858 priv->scan_result = NULL;
3862 priv->scan_mode = srq->flags;
3864 /* Always trigger scanning, even if it's in progress.
3865 * This way, if the info frame get lost, we will recover somewhat
3866 * gracefully - Jean II */
3868 if (priv->has_hostscan) {
3869 switch (priv->firmware_type) {
3870 case FIRMWARE_TYPE_SYMBOL:
3871 err = hermes_write_wordrec(hw, USER_BAP,
3872 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3873 HERMES_HOSTSCAN_SYMBOL_ONCE |
3874 HERMES_HOSTSCAN_SYMBOL_BCAST);
3876 case FIRMWARE_TYPE_INTERSIL: {
3879 req[0] = cpu_to_le16(0x3fff); /* All channels */
3880 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3881 req[2] = 0; /* Any ESSID */
3882 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3883 HERMES_RID_CNFHOSTSCAN, &req);
3886 case FIRMWARE_TYPE_AGERE:
3887 err = hermes_write_wordrec(hw, USER_BAP,
3888 HERMES_RID_CNFSCANSSID_AGERE,
3893 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3897 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3899 /* One more client */
3901 priv->scan_inprogress = 1;
3904 orinoco_unlock(priv, &flags);
3908 /* Translate scan data returned from the card to a card independant
3909 * format that the Wireless Tools will understand - Jean II
3910 * Return message length or -errno for fatal errors */
3911 static inline int orinoco_translate_scan(struct net_device *dev,
3916 struct orinoco_private *priv = netdev_priv(dev);
3917 int offset; /* In the scan data */
3918 union hermes_scan_info *atom;
3922 struct iw_event iwe; /* Temporary buffer */
3923 char * current_ev = buffer;
3924 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3926 switch (priv->firmware_type) {
3927 case FIRMWARE_TYPE_AGERE:
3928 atom_len = sizeof(struct agere_scan_apinfo);
3931 case FIRMWARE_TYPE_SYMBOL:
3932 /* Lack of documentation necessitates this hack.
3933 * Different firmwares have 68 or 76 byte long atoms.
3934 * We try modulo first. If the length divides by both,
3935 * we check what would be the channel in the second
3936 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3937 * Valid channel cannot be 0. */
3940 else if (scan_len % 68)
3942 else if (scan_len >= 1292 && scan[68] == 0)
3948 case FIRMWARE_TYPE_INTERSIL:
3950 if (priv->has_hostscan) {
3951 atom_len = le16_to_cpup((__le16 *)scan);
3952 /* Sanity check for atom_len */
3953 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3954 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3955 dev->name, atom_len);
3959 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3965 /* Check that we got an whole number of atoms */
3966 if ((scan_len - offset) % atom_len) {
3967 printk(KERN_ERR "%s: Unexpected scan data length %d, "
3968 "atom_len %d, offset %d\n", dev->name, scan_len,
3973 /* Read the entries one by one */
3974 for (; offset + atom_len <= scan_len; offset += atom_len) {
3976 atom = (union hermes_scan_info *) (scan + offset);
3978 /* First entry *MUST* be the AP MAC address */
3979 iwe.cmd = SIOCGIWAP;
3980 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
3981 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
3982 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
3984 /* Other entries will be displayed in the order we give them */
3987 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
3988 if (iwe.u.data.length > 32)
3989 iwe.u.data.length = 32;
3990 iwe.cmd = SIOCGIWESSID;
3991 iwe.u.data.flags = 1;
3992 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
3995 iwe.cmd = SIOCGIWMODE;
3996 capabilities = le16_to_cpu(atom->a.capabilities);
3997 if (capabilities & 0x3) {
3998 if (capabilities & 0x1)
3999 iwe.u.mode = IW_MODE_MASTER;
4001 iwe.u.mode = IW_MODE_ADHOC;
4002 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4005 channel = atom->s.channel;
4006 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4008 iwe.cmd = SIOCGIWFREQ;
4009 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4011 current_ev = iwe_stream_add_event(current_ev, end_buf,
4012 &iwe, IW_EV_FREQ_LEN);
4015 /* Add quality statistics */
4017 iwe.u.qual.updated = 0x10; /* no link quality */
4018 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4019 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4020 /* Wireless tools prior to 27.pre22 will show link quality
4021 * anyway, so we provide a reasonable value. */
4022 if (iwe.u.qual.level > iwe.u.qual.noise)
4023 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4025 iwe.u.qual.qual = 0;
4026 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4028 /* Add encryption capability */
4029 iwe.cmd = SIOCGIWENCODE;
4030 if (capabilities & 0x10)
4031 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4033 iwe.u.data.flags = IW_ENCODE_DISABLED;
4034 iwe.u.data.length = 0;
4035 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4037 /* Bit rate is not available in Lucent/Agere firmwares */
4038 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4039 char * current_val = current_ev + IW_EV_LCP_LEN;
4043 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4048 iwe.cmd = SIOCGIWRATE;
4049 /* Those two flags are ignored... */
4050 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4052 for (i = 0; i < 10; i += step) {
4053 /* NULL terminated */
4054 if (atom->p.rates[i] == 0x0)
4056 /* Bit rate given in 500 kb/s units (+ 0x80) */
4057 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4058 current_val = iwe_stream_add_value(current_ev, current_val,
4062 /* Check if we added any event */
4063 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4064 current_ev = current_val;
4067 /* The other data in the scan result are not really
4068 * interesting, so for now drop it - Jean II */
4070 return current_ev - buffer;
4073 /* Return results of a scan */
4074 static int orinoco_ioctl_getscan(struct net_device *dev,
4075 struct iw_request_info *info,
4076 struct iw_point *srq,
4079 struct orinoco_private *priv = netdev_priv(dev);
4081 unsigned long flags;
4083 if (orinoco_lock(priv, &flags) != 0)
4086 /* If no results yet, ask to try again later */
4087 if (priv->scan_result == NULL) {
4088 if (priv->scan_inprogress)
4089 /* Important note : we don't want to block the caller
4090 * until results are ready for various reasons.
4091 * First, managing wait queues is complex and racy.
4092 * Second, we grab some rtnetlink lock before comming
4093 * here (in dev_ioctl()).
4094 * Third, we generate an Wireless Event, so the
4095 * caller can wait itself on that - Jean II */
4098 /* Client error, no scan results...
4099 * The caller need to restart the scan. */
4102 /* We have some results to push back to user space */
4104 /* Translate to WE format */
4105 int ret = orinoco_translate_scan(dev, extra,
4111 kfree(priv->scan_result);
4112 priv->scan_result = NULL;
4117 srq->flags = (__u16) priv->scan_mode;
4119 /* In any case, Scan results will be cleaned up in the
4120 * reset function and when exiting the driver.
4121 * The person triggering the scanning may never come to
4122 * pick the results, so we need to do it in those places.
4125 #ifdef SCAN_SINGLE_READ
4126 /* If you enable this option, only one client (the first
4127 * one) will be able to read the result (and only one
4128 * time). If there is multiple concurent clients that
4129 * want to read scan results, this behavior is not
4130 * advisable - Jean II */
4131 kfree(priv->scan_result);
4132 priv->scan_result = NULL;
4133 #endif /* SCAN_SINGLE_READ */
4134 /* Here, if too much time has elapsed since last scan,
4135 * we may want to clean up scan results... - Jean II */
4138 /* Scan is no longer in progress */
4139 priv->scan_inprogress = 0;
4142 orinoco_unlock(priv, &flags);
4146 /* Commit handler, called after set operations */
4147 static int orinoco_ioctl_commit(struct net_device *dev,
4148 struct iw_request_info *info,
4152 struct orinoco_private *priv = netdev_priv(dev);
4153 struct hermes *hw = &priv->hw;
4154 unsigned long flags;
4160 if (priv->broken_disableport) {
4161 orinoco_reset(&priv->reset_work);
4165 if (orinoco_lock(priv, &flags) != 0)
4168 err = hermes_disable_port(hw, 0);
4170 printk(KERN_WARNING "%s: Unable to disable port "
4171 "while reconfiguring card\n", dev->name);
4172 priv->broken_disableport = 1;
4176 err = __orinoco_program_rids(dev);
4178 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4183 err = hermes_enable_port(hw, 0);
4185 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4192 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4193 schedule_work(&priv->reset_work);
4197 orinoco_unlock(priv, &flags);
4201 static const struct iw_priv_args orinoco_privtab[] = {
4202 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4203 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4204 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4206 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4208 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4209 0, "set_preamble" },
4210 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4212 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4213 0, "set_ibssport" },
4214 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4216 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4222 * Structures to export the Wireless Handlers
4225 static const iw_handler orinoco_handler[] = {
4226 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4227 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4228 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4229 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4230 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4231 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4232 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4233 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4234 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4235 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4236 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4237 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4238 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4239 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4240 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4241 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4242 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4243 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4244 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4245 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4246 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4247 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4248 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4249 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4250 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4251 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4252 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4253 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4254 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4255 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4256 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4257 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4262 Added typecasting since we no longer use iwreq_data -- Moustafa
4264 static const iw_handler orinoco_private_handler[] = {
4265 [0] = (iw_handler) orinoco_ioctl_reset,
4266 [1] = (iw_handler) orinoco_ioctl_reset,
4267 [2] = (iw_handler) orinoco_ioctl_setport3,
4268 [3] = (iw_handler) orinoco_ioctl_getport3,
4269 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4270 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4271 [6] = (iw_handler) orinoco_ioctl_setibssport,
4272 [7] = (iw_handler) orinoco_ioctl_getibssport,
4273 [9] = (iw_handler) orinoco_ioctl_getrid,
4276 static const struct iw_handler_def orinoco_handler_def = {
4277 .num_standard = ARRAY_SIZE(orinoco_handler),
4278 .num_private = ARRAY_SIZE(orinoco_private_handler),
4279 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4280 .standard = orinoco_handler,
4281 .private = orinoco_private_handler,
4282 .private_args = orinoco_privtab,
4283 .get_wireless_stats = orinoco_get_wireless_stats,
4286 static void orinoco_get_drvinfo(struct net_device *dev,
4287 struct ethtool_drvinfo *info)
4289 struct orinoco_private *priv = netdev_priv(dev);
4291 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4292 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4293 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4294 if (dev->dev.parent)
4295 strncpy(info->bus_info, dev->dev.parent->bus_id,
4296 sizeof(info->bus_info) - 1);
4298 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4299 "PCMCIA %p", priv->hw.iobase);
4302 static const struct ethtool_ops orinoco_ethtool_ops = {
4303 .get_drvinfo = orinoco_get_drvinfo,
4304 .get_link = ethtool_op_get_link,
4307 /********************************************************************/
4308 /* Module initialization */
4309 /********************************************************************/
4311 EXPORT_SYMBOL(alloc_orinocodev);
4312 EXPORT_SYMBOL(free_orinocodev);
4314 EXPORT_SYMBOL(__orinoco_up);
4315 EXPORT_SYMBOL(__orinoco_down);
4316 EXPORT_SYMBOL(orinoco_reinit_firmware);
4318 EXPORT_SYMBOL(orinoco_interrupt);
4320 /* Can't be declared "const" or the whole __initdata section will
4322 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4323 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4324 "Pavel Roskin <proski@gnu.org>, et al)";
4326 static int __init init_orinoco(void)
4328 printk(KERN_DEBUG "%s\n", version);
4332 static void __exit exit_orinoco(void)
4336 module_init(init_orinoco);
4337 module_exit(exit_orinoco);