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/config.h>
80 #include <linux/module.h>
81 #include <linux/kernel.h>
82 #include <linux/init.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.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 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 /* Used in Event handling.
205 * We avoid nested structures as they break on ARM -- Moustafa */
206 struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
229 u8 h_source[ETH_ALEN]; /* source ether addr */
230 __be16 h_proto; /* packet type ID field */
239 } __attribute__ ((packed));
241 /* Rx frame header except compatibility 802.3 header */
242 struct hermes_rx_descriptor {
263 } __attribute__ ((packed));
265 /********************************************************************/
266 /* Function prototypes */
267 /********************************************************************/
269 static int __orinoco_program_rids(struct net_device *dev);
270 static void __orinoco_set_multicast_list(struct net_device *dev);
272 /********************************************************************/
273 /* Internal helper functions */
274 /********************************************************************/
276 static inline void set_port_type(struct orinoco_private *priv)
278 switch (priv->iw_mode) {
281 priv->createibss = 0;
284 if (priv->prefer_port3) {
286 priv->createibss = 0;
288 priv->port_type = priv->ibss_port;
289 priv->createibss = 1;
292 case IW_MODE_MONITOR:
294 priv->createibss = 0;
297 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
302 /********************************************************************/
304 /********************************************************************/
306 static int orinoco_open(struct net_device *dev)
308 struct orinoco_private *priv = netdev_priv(dev);
312 if (orinoco_lock(priv, &flags) != 0)
315 err = __orinoco_up(dev);
320 orinoco_unlock(priv, &flags);
325 static int orinoco_stop(struct net_device *dev)
327 struct orinoco_private *priv = netdev_priv(dev);
330 /* We mustn't use orinoco_lock() here, because we need to be
331 able to close the interface even if hw_unavailable is set
332 (e.g. as we're released after a PC Card removal) */
333 spin_lock_irq(&priv->lock);
337 err = __orinoco_down(dev);
339 spin_unlock_irq(&priv->lock);
344 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
346 struct orinoco_private *priv = netdev_priv(dev);
351 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
353 struct orinoco_private *priv = netdev_priv(dev);
354 hermes_t *hw = &priv->hw;
355 struct iw_statistics *wstats = &priv->wstats;
359 if (! netif_device_present(dev)) {
360 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
362 return NULL; /* FIXME: Can we do better than this? */
365 /* If busy, return the old stats. Returning NULL may cause
366 * the interface to disappear from /proc/net/wireless */
367 if (orinoco_lock(priv, &flags) != 0)
370 /* We can't really wait for the tallies inquiry command to
371 * complete, so we just use the previous results and trigger
372 * a new tallies inquiry command for next time - Jean II */
373 /* FIXME: Really we should wait for the inquiry to come back -
374 * as it is the stats we give don't make a whole lot of sense.
375 * Unfortunately, it's not clear how to do that within the
376 * wireless extensions framework: I think we're in user
377 * context, but a lock seems to be held by the time we get in
378 * here so we're not safe to sleep here. */
379 hermes_inquire(hw, HERMES_INQ_TALLIES);
381 if (priv->iw_mode == IW_MODE_ADHOC) {
382 memset(&wstats->qual, 0, sizeof(wstats->qual));
383 /* If a spy address is defined, we report stats of the
384 * first spy address - Jean II */
385 if (SPY_NUMBER(priv)) {
386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
393 __le16 qual, signal, noise, unused;
394 } __attribute__ ((packed)) cq;
396 err = HERMES_READ_RECORD(hw, USER_BAP,
397 HERMES_RID_COMMSQUALITY, &cq);
400 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
401 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
402 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
403 wstats->qual.updated = 7;
407 orinoco_unlock(priv, &flags);
411 static void orinoco_set_multicast_list(struct net_device *dev)
413 struct orinoco_private *priv = netdev_priv(dev);
416 if (orinoco_lock(priv, &flags) != 0) {
417 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
418 "called when hw_unavailable\n", dev->name);
422 __orinoco_set_multicast_list(dev);
423 orinoco_unlock(priv, &flags);
426 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
428 struct orinoco_private *priv = netdev_priv(dev);
430 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
433 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
434 (priv->nicbuf_size - ETH_HLEN) )
442 /********************************************************************/
444 /********************************************************************/
446 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
448 struct orinoco_private *priv = netdev_priv(dev);
449 struct net_device_stats *stats = &priv->stats;
450 hermes_t *hw = &priv->hw;
452 u16 txfid = priv->txfid;
455 int len, data_len, data_off;
456 struct hermes_tx_descriptor desc;
459 if (! netif_running(dev)) {
460 printk(KERN_ERR "%s: Tx on stopped device!\n",
465 if (netif_queue_stopped(dev)) {
466 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
471 if (orinoco_lock(priv, &flags) != 0) {
472 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
477 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
478 /* Oops, the firmware hasn't established a connection,
479 silently drop the packet (this seems to be the
482 orinoco_unlock(priv, &flags);
487 /* Length of the packet body */
488 /* FIXME: what if the skb is smaller than this? */
489 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
490 skb = skb_padto(skb, len);
495 eh = (struct ethhdr *)skb->data;
497 memset(&desc, 0, sizeof(desc));
498 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
499 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
502 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
503 "to BAP\n", dev->name, err);
508 /* Clear the 802.11 header and data length fields - some
509 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
510 * if this isn't done. */
511 hermes_clear_words(hw, HERMES_DATA0,
512 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
514 /* Encapsulate Ethernet-II frames */
515 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
516 struct header_struct hdr;
518 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
519 p = skb->data + ETH_HLEN;
522 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
523 memcpy(hdr.src, eh->h_source, ETH_ALEN);
524 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
527 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
529 hdr.ethertype = eh->h_proto;
530 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
531 txfid, HERMES_802_3_OFFSET);
534 printk(KERN_ERR "%s: Error %d writing packet "
535 "header to BAP\n", dev->name, err);
539 /* Actual xfer length - allow for padding */
540 len = ALIGN(data_len, 2);
541 if (len < ETH_ZLEN - ETH_HLEN)
542 len = ETH_ZLEN - ETH_HLEN;
543 } else { /* IEEE 802.3 frame */
544 data_len = len + ETH_HLEN;
545 data_off = HERMES_802_3_OFFSET;
547 /* Actual xfer length - round up for odd length packets */
548 len = ALIGN(data_len, 2);
553 err = hermes_bap_pwrite_pad(hw, USER_BAP, p, data_len, len,
556 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
562 /* Finally, we actually initiate the send */
563 netif_stop_queue(dev);
565 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
568 netif_start_queue(dev);
570 printk(KERN_ERR "%s: Error %d transmitting packet\n",
576 dev->trans_start = jiffies;
577 stats->tx_bytes += data_off + data_len;
579 orinoco_unlock(priv, &flags);
586 orinoco_unlock(priv, &flags);
590 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
592 struct orinoco_private *priv = netdev_priv(dev);
593 u16 fid = hermes_read_regn(hw, ALLOCFID);
595 if (fid != priv->txfid) {
596 if (fid != DUMMY_FID)
597 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
602 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
605 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
607 struct orinoco_private *priv = netdev_priv(dev);
608 struct net_device_stats *stats = &priv->stats;
612 netif_wake_queue(dev);
614 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
617 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
619 struct orinoco_private *priv = netdev_priv(dev);
620 struct net_device_stats *stats = &priv->stats;
621 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
623 struct hermes_tx_descriptor_802_11 hdr;
626 if (fid == DUMMY_FID)
627 return; /* Nothing's really happened */
629 /* Read part of the frame header - we need status and addr1 */
630 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
631 offsetof(struct hermes_tx_descriptor_802_11,
635 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
639 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
640 "(FID=%04X error %d)\n",
641 dev->name, fid, err);
645 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
648 /* We produce a TXDROP event only for retry or lifetime
649 * exceeded, because that's the only status that really mean
650 * that this particular node went away.
651 * Other errors means that *we* screwed up. - Jean II */
652 status = le16_to_cpu(hdr.status);
653 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
654 union iwreq_data wrqu;
656 /* Copy 802.11 dest address.
657 * We use the 802.11 header because the frame may
658 * not be 802.3 or may be mangled...
659 * In Ad-Hoc mode, it will be the node address.
660 * In managed mode, it will be most likely the AP addr
661 * User space will figure out how to convert it to
662 * whatever it needs (IP address or else).
664 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
665 wrqu.addr.sa_family = ARPHRD_ETHER;
667 /* Send event to user space */
668 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
671 netif_wake_queue(dev);
674 static void orinoco_tx_timeout(struct net_device *dev)
676 struct orinoco_private *priv = netdev_priv(dev);
677 struct net_device_stats *stats = &priv->stats;
678 struct hermes *hw = &priv->hw;
680 printk(KERN_WARNING "%s: Tx timeout! "
681 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
682 dev->name, hermes_read_regn(hw, ALLOCFID),
683 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
687 schedule_work(&priv->reset_work);
690 /********************************************************************/
691 /* Rx path (data frames) */
692 /********************************************************************/
694 /* Does the frame have a SNAP header indicating it should be
695 * de-encapsulated to Ethernet-II? */
696 static inline int is_ethersnap(void *_hdr)
700 /* We de-encapsulate all packets which, a) have SNAP headers
701 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
702 * and where b) the OUI of the SNAP header is 00:00:00 or
703 * 00:00:f8 - we need both because different APs appear to use
704 * different OUIs for some reason */
705 return (memcmp(hdr, &encaps_hdr, 5) == 0)
706 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
709 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
710 int level, int noise)
712 struct iw_quality wstats;
713 wstats.level = level - 0x95;
714 wstats.noise = noise - 0x95;
715 wstats.qual = (level > noise) ? (level - noise) : 0;
717 /* Update spy records */
718 wireless_spy_update(dev, mac, &wstats);
721 static void orinoco_stat_gather(struct net_device *dev,
723 struct hermes_rx_descriptor *desc)
725 struct orinoco_private *priv = netdev_priv(dev);
727 /* Using spy support with lots of Rx packets, like in an
728 * infrastructure (AP), will really slow down everything, because
729 * the MAC address must be compared to each entry of the spy list.
730 * If the user really asks for it (set some address in the
731 * spy list), we do it, but he will pay the price.
732 * Note that to get here, you need both WIRELESS_SPY
733 * compiled in AND some addresses in the list !!!
735 /* Note : gcc will optimise the whole section away if
736 * WIRELESS_SPY is not defined... - Jean II */
737 if (SPY_NUMBER(priv)) {
738 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
739 desc->signal, desc->silence);
744 * orinoco_rx_monitor - handle received monitor frames.
749 * desc rx descriptor of the frame
751 * Call context: interrupt
753 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
754 struct hermes_rx_descriptor *desc)
756 u32 hdrlen = 30; /* return full header by default */
762 struct orinoco_private *priv = netdev_priv(dev);
763 struct net_device_stats *stats = &priv->stats;
764 hermes_t *hw = &priv->hw;
766 len = le16_to_cpu(desc->data_len);
768 /* Determine the size of the header and the data */
769 fc = le16_to_cpu(desc->frame_ctl);
770 switch (fc & IEEE80211_FCTL_FTYPE) {
771 case IEEE80211_FTYPE_DATA:
772 if ((fc & IEEE80211_FCTL_TODS)
773 && (fc & IEEE80211_FCTL_FROMDS))
779 case IEEE80211_FTYPE_MGMT:
783 case IEEE80211_FTYPE_CTL:
784 switch (fc & IEEE80211_FCTL_STYPE) {
785 case IEEE80211_STYPE_PSPOLL:
786 case IEEE80211_STYPE_RTS:
787 case IEEE80211_STYPE_CFEND:
788 case IEEE80211_STYPE_CFENDACK:
791 case IEEE80211_STYPE_CTS:
792 case IEEE80211_STYPE_ACK:
798 /* Unknown frame type */
802 /* sanity check the length */
803 if (datalen > IEEE80211_DATA_LEN + 12) {
804 printk(KERN_DEBUG "%s: oversized monitor frame, "
805 "data length = %d\n", dev->name, datalen);
807 stats->rx_length_errors++;
811 skb = dev_alloc_skb(hdrlen + datalen);
813 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
819 /* Copy the 802.11 header to the skb */
820 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
821 skb->mac.raw = skb->data;
823 /* If any, copy the data from the card to the skb */
825 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
826 ALIGN(datalen, 2), rxfid,
827 HERMES_802_2_OFFSET);
829 printk(KERN_ERR "%s: error %d reading monitor frame\n",
836 skb->ip_summed = CHECKSUM_NONE;
837 skb->pkt_type = PACKET_OTHERHOST;
838 skb->protocol = __constant_htons(ETH_P_802_2);
840 dev->last_rx = jiffies;
842 stats->rx_bytes += skb->len;
848 dev_kfree_skb_irq(skb);
854 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
856 struct orinoco_private *priv = netdev_priv(dev);
857 struct net_device_stats *stats = &priv->stats;
858 struct iw_statistics *wstats = &priv->wstats;
859 struct sk_buff *skb = NULL;
860 u16 rxfid, status, fc;
862 struct hermes_rx_descriptor desc;
866 rxfid = hermes_read_regn(hw, RXFID);
868 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
871 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
872 "Frame dropped.\n", dev->name, err);
876 status = le16_to_cpu(desc.status);
878 if (status & HERMES_RXSTAT_BADCRC) {
879 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
881 stats->rx_crc_errors++;
885 /* Handle frames in monitor mode */
886 if (priv->iw_mode == IW_MODE_MONITOR) {
887 orinoco_rx_monitor(dev, rxfid, &desc);
891 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
892 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
894 wstats->discard.code++;
898 length = le16_to_cpu(desc.data_len);
899 fc = le16_to_cpu(desc.frame_ctl);
902 if (length < 3) { /* No for even an 802.2 LLC header */
903 /* At least on Symbol firmware with PCF we get quite a
904 lot of these legitimately - Poll frames with no
908 if (length > IEEE80211_DATA_LEN) {
909 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
911 stats->rx_length_errors++;
915 /* We need space for the packet data itself, plus an ethernet
916 header, plus 2 bytes so we can align the IP header on a
917 32bit boundary, plus 1 byte so we can read in odd length
918 packets from the card, which has an IO granularity of 16
920 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
922 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
927 /* We'll prepend the header, so reserve space for it. The worst
928 case is no decapsulation, when 802.3 header is prepended and
929 nothing is removed. 2 is for aligning the IP header. */
930 skb_reserve(skb, ETH_HLEN + 2);
932 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
933 ALIGN(length, 2), rxfid,
934 HERMES_802_2_OFFSET);
936 printk(KERN_ERR "%s: error %d reading frame. "
937 "Frame dropped.\n", dev->name, err);
941 /* Handle decapsulation
942 * In most cases, the firmware tell us about SNAP frames.
943 * For some reason, the SNAP frames sent by LinkSys APs
944 * are not properly recognised by most firmwares.
945 * So, check ourselves */
946 if (length >= ENCAPS_OVERHEAD &&
947 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
948 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
949 is_ethersnap(skb->data))) {
950 /* These indicate a SNAP within 802.2 LLC within
951 802.11 frame which we'll need to de-encapsulate to
952 the original EthernetII frame. */
953 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
955 /* 802.3 frame - prepend 802.3 header as is */
956 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
957 hdr->h_proto = htons(length);
959 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
960 if (fc & IEEE80211_FCTL_FROMDS)
961 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
963 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
965 dev->last_rx = jiffies;
967 skb->protocol = eth_type_trans(skb, dev);
968 skb->ip_summed = CHECKSUM_NONE;
969 if (fc & IEEE80211_FCTL_TODS)
970 skb->pkt_type = PACKET_OTHERHOST;
972 /* Process the wireless stats if needed */
973 orinoco_stat_gather(dev, skb, &desc);
975 /* Pass the packet to the networking stack */
978 stats->rx_bytes += length;
983 dev_kfree_skb_irq(skb);
989 /********************************************************************/
990 /* Rx path (info frames) */
991 /********************************************************************/
993 static void print_linkstatus(struct net_device *dev, u16 status)
997 if (suppress_linkstatus)
1001 case HERMES_LINKSTATUS_NOT_CONNECTED:
1002 s = "Not Connected";
1004 case HERMES_LINKSTATUS_CONNECTED:
1007 case HERMES_LINKSTATUS_DISCONNECTED:
1010 case HERMES_LINKSTATUS_AP_CHANGE:
1013 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1014 s = "AP Out of Range";
1016 case HERMES_LINKSTATUS_AP_IN_RANGE:
1019 case HERMES_LINKSTATUS_ASSOC_FAILED:
1020 s = "Association Failed";
1026 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1027 dev->name, s, status);
1030 /* Search scan results for requested BSSID, join it if found */
1031 static void orinoco_join_ap(struct net_device *dev)
1033 struct orinoco_private *priv = netdev_priv(dev);
1034 struct hermes *hw = &priv->hw;
1036 unsigned long flags;
1040 } __attribute__ ((packed)) req;
1041 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1042 struct prism2_scan_apinfo *atom = NULL;
1048 /* Allocate buffer for scan results */
1049 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1053 if (orinoco_lock(priv, &flags) != 0)
1056 /* Sanity checks in case user changed something in the meantime */
1057 if (! priv->bssid_fixed)
1060 if (strlen(priv->desired_essid) == 0)
1063 /* Read scan results from the firmware */
1064 err = hermes_read_ltv(hw, USER_BAP,
1065 HERMES_RID_SCANRESULTSTABLE,
1066 MAX_SCAN_LEN, &len, buf);
1068 printk(KERN_ERR "%s: Cannot read scan results\n",
1073 len = HERMES_RECLEN_TO_BYTES(len);
1075 /* Go through the scan results looking for the channel of the AP
1076 * we were requested to join */
1077 for (; offset + atom_len <= len; offset += atom_len) {
1078 atom = (struct prism2_scan_apinfo *) (buf + offset);
1079 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1086 DEBUG(1, "%s: Requested AP not found in scan results\n",
1091 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1092 req.channel = atom->channel; /* both are little-endian */
1093 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1096 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1099 orinoco_unlock(priv, &flags);
1105 /* Send new BSSID to userspace */
1106 static void orinoco_send_wevents(struct net_device *dev)
1108 struct orinoco_private *priv = netdev_priv(dev);
1109 struct hermes *hw = &priv->hw;
1110 union iwreq_data wrqu;
1112 unsigned long flags;
1114 if (orinoco_lock(priv, &flags) != 0)
1117 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1118 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1122 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1124 /* Send event to user space */
1125 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1128 orinoco_unlock(priv, &flags);
1131 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1133 struct orinoco_private *priv = netdev_priv(dev);
1138 } __attribute__ ((packed)) info;
1142 /* This is an answer to an INQUIRE command that we did earlier,
1143 * or an information "event" generated by the card
1144 * The controller return to us a pseudo frame containing
1145 * the information in question - Jean II */
1146 infofid = hermes_read_regn(hw, INFOFID);
1148 /* Read the info frame header - don't try too hard */
1149 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1152 printk(KERN_ERR "%s: error %d reading info frame. "
1153 "Frame dropped.\n", dev->name, err);
1157 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1158 type = le16_to_cpu(info.type);
1161 case HERMES_INQ_TALLIES: {
1162 struct hermes_tallies_frame tallies;
1163 struct iw_statistics *wstats = &priv->wstats;
1165 if (len > sizeof(tallies)) {
1166 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1168 len = sizeof(tallies);
1171 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1172 infofid, sizeof(info));
1176 /* Increment our various counters */
1177 /* wstats->discard.nwid - no wrong BSSID stuff */
1178 wstats->discard.code +=
1179 le16_to_cpu(tallies.RxWEPUndecryptable);
1180 if (len == sizeof(tallies))
1181 wstats->discard.code +=
1182 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1183 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1184 wstats->discard.misc +=
1185 le16_to_cpu(tallies.TxDiscardsWrongSA);
1186 wstats->discard.fragment +=
1187 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1188 wstats->discard.retries +=
1189 le16_to_cpu(tallies.TxRetryLimitExceeded);
1190 /* wstats->miss.beacon - no match */
1193 case HERMES_INQ_LINKSTATUS: {
1194 struct hermes_linkstatus linkstatus;
1198 if (priv->iw_mode == IW_MODE_MONITOR)
1201 if (len != sizeof(linkstatus)) {
1202 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1207 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1208 infofid, sizeof(info));
1211 newstatus = le16_to_cpu(linkstatus.linkstatus);
1213 /* Symbol firmware uses "out of range" to signal that
1214 * the hostscan frame can be requested. */
1215 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1216 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1217 priv->has_hostscan && priv->scan_inprogress) {
1218 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1222 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1223 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1224 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1227 netif_carrier_on(dev);
1228 else if (!ignore_disconnect)
1229 netif_carrier_off(dev);
1231 if (newstatus != priv->last_linkstatus) {
1232 priv->last_linkstatus = newstatus;
1233 print_linkstatus(dev, newstatus);
1234 /* The info frame contains only one word which is the
1235 * status (see hermes.h). The status is pretty boring
1236 * in itself, that's why we export the new BSSID...
1238 schedule_work(&priv->wevent_work);
1242 case HERMES_INQ_SCAN:
1243 if (!priv->scan_inprogress && priv->bssid_fixed &&
1244 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1245 schedule_work(&priv->join_work);
1249 case HERMES_INQ_HOSTSCAN:
1250 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1251 /* Result of a scanning. Contains information about
1252 * cells in the vicinity - Jean II */
1253 union iwreq_data wrqu;
1258 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1263 /* We are a strict producer. If the previous scan results
1264 * have not been consumed, we just have to drop this
1265 * frame. We can't remove the previous results ourselves,
1266 * that would be *very* racy... Jean II */
1267 if (priv->scan_result != NULL) {
1268 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1272 /* Allocate buffer for results */
1273 buf = kmalloc(len, GFP_ATOMIC);
1275 /* No memory, so can't printk()... */
1278 /* Read scan data */
1279 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1280 infofid, sizeof(info));
1286 #ifdef ORINOCO_DEBUG
1289 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1290 for(i = 1; i < (len * 2); i++)
1291 printk(":%02X", buf[i]);
1294 #endif /* ORINOCO_DEBUG */
1296 /* Allow the clients to access the results */
1297 priv->scan_len = len;
1298 priv->scan_result = buf;
1300 /* Send an empty event to user space.
1301 * We don't send the received data on the event because
1302 * it would require us to do complex transcoding, and
1303 * we want to minimise the work done in the irq handler
1304 * Use a request to extract the data - Jean II */
1305 wrqu.data.length = 0;
1306 wrqu.data.flags = 0;
1307 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1310 case HERMES_INQ_SEC_STAT_AGERE:
1311 /* Security status (Agere specific) */
1312 /* Ignore this frame for now */
1313 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1317 printk(KERN_DEBUG "%s: Unknown information frame received: "
1318 "type 0x%04x, length %d\n", dev->name, type, len);
1319 /* We don't actually do anything about it */
1324 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1326 if (net_ratelimit())
1327 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1330 /********************************************************************/
1331 /* Internal hardware control routines */
1332 /********************************************************************/
1334 int __orinoco_up(struct net_device *dev)
1336 struct orinoco_private *priv = netdev_priv(dev);
1337 struct hermes *hw = &priv->hw;
1340 netif_carrier_off(dev); /* just to make sure */
1342 err = __orinoco_program_rids(dev);
1344 printk(KERN_ERR "%s: Error %d configuring card\n",
1349 /* Fire things up again */
1350 hermes_set_irqmask(hw, ORINOCO_INTEN);
1351 err = hermes_enable_port(hw, 0);
1353 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1358 netif_start_queue(dev);
1363 int __orinoco_down(struct net_device *dev)
1365 struct orinoco_private *priv = netdev_priv(dev);
1366 struct hermes *hw = &priv->hw;
1369 netif_stop_queue(dev);
1371 if (! priv->hw_unavailable) {
1372 if (! priv->broken_disableport) {
1373 err = hermes_disable_port(hw, 0);
1375 /* Some firmwares (e.g. Intersil 1.3.x) seem
1376 * to have problems disabling the port, oh
1378 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1380 priv->broken_disableport = 1;
1383 hermes_set_irqmask(hw, 0);
1384 hermes_write_regn(hw, EVACK, 0xffff);
1387 /* firmware will have to reassociate */
1388 netif_carrier_off(dev);
1389 priv->last_linkstatus = 0xffff;
1394 int orinoco_reinit_firmware(struct net_device *dev)
1396 struct orinoco_private *priv = netdev_priv(dev);
1397 struct hermes *hw = &priv->hw;
1400 err = hermes_init(hw);
1404 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1405 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1406 /* Try workaround for old Symbol firmware bug */
1407 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1408 "(old Symbol firmware?). Trying to work around... ",
1411 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1412 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1414 printk("failed!\n");
1422 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1424 hermes_t *hw = &priv->hw;
1427 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1428 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1429 priv->ndev->name, priv->bitratemode);
1433 switch (priv->firmware_type) {
1434 case FIRMWARE_TYPE_AGERE:
1435 err = hermes_write_wordrec(hw, USER_BAP,
1436 HERMES_RID_CNFTXRATECONTROL,
1437 bitrate_table[priv->bitratemode].agere_txratectrl);
1439 case FIRMWARE_TYPE_INTERSIL:
1440 case FIRMWARE_TYPE_SYMBOL:
1441 err = hermes_write_wordrec(hw, USER_BAP,
1442 HERMES_RID_CNFTXRATECONTROL,
1443 bitrate_table[priv->bitratemode].intersil_txratectrl);
1452 /* Set fixed AP address */
1453 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1457 hermes_t *hw = &priv->hw;
1459 switch (priv->firmware_type) {
1460 case FIRMWARE_TYPE_AGERE:
1463 case FIRMWARE_TYPE_INTERSIL:
1464 if (priv->bssid_fixed)
1469 err = hermes_write_wordrec(hw, USER_BAP,
1470 HERMES_RID_CNFROAMINGMODE,
1473 case FIRMWARE_TYPE_SYMBOL:
1474 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1475 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1476 &priv->desired_bssid);
1482 /* Change the WEP keys and/or the current keys. Can be called
1483 * either from __orinoco_hw_setup_wep() or directly from
1484 * orinoco_ioctl_setiwencode(). In the later case the association
1485 * with the AP is not broken (if the firmware can handle it),
1486 * which is needed for 802.1x implementations. */
1487 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1489 hermes_t *hw = &priv->hw;
1492 switch (priv->firmware_type) {
1493 case FIRMWARE_TYPE_AGERE:
1494 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1495 HERMES_RID_CNFWEPKEYS_AGERE,
1499 err = hermes_write_wordrec(hw, USER_BAP,
1500 HERMES_RID_CNFTXKEY_AGERE,
1505 case FIRMWARE_TYPE_INTERSIL:
1506 case FIRMWARE_TYPE_SYMBOL:
1511 /* Force uniform key length to work around firmware bugs */
1512 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1514 if (keylen > LARGE_KEY_SIZE) {
1515 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1516 priv->ndev->name, priv->tx_key, keylen);
1520 /* Write all 4 keys */
1521 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1522 err = hermes_write_ltv(hw, USER_BAP,
1523 HERMES_RID_CNFDEFAULTKEY0 + i,
1524 HERMES_BYTES_TO_RECLEN(keylen),
1525 priv->keys[i].data);
1530 /* Write the index of the key used in transmission */
1531 err = hermes_write_wordrec(hw, USER_BAP,
1532 HERMES_RID_CNFWEPDEFAULTKEYID,
1543 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1545 hermes_t *hw = &priv->hw;
1547 int master_wep_flag;
1551 __orinoco_hw_setup_wepkeys(priv);
1553 if (priv->wep_restrict)
1554 auth_flag = HERMES_AUTH_SHARED_KEY;
1556 auth_flag = HERMES_AUTH_OPEN;
1558 switch (priv->firmware_type) {
1559 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1561 /* Enable the shared-key authentication. */
1562 err = hermes_write_wordrec(hw, USER_BAP,
1563 HERMES_RID_CNFAUTHENTICATION_AGERE,
1566 err = hermes_write_wordrec(hw, USER_BAP,
1567 HERMES_RID_CNFWEPENABLED_AGERE,
1573 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1574 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1576 if (priv->wep_restrict ||
1577 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1578 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1579 HERMES_WEP_EXCL_UNENCRYPTED;
1581 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1583 err = hermes_write_wordrec(hw, USER_BAP,
1584 HERMES_RID_CNFAUTHENTICATION,
1589 master_wep_flag = 0;
1591 if (priv->iw_mode == IW_MODE_MONITOR)
1592 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1594 /* Master WEP setting : on/off */
1595 err = hermes_write_wordrec(hw, USER_BAP,
1596 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1607 static int __orinoco_program_rids(struct net_device *dev)
1609 struct orinoco_private *priv = netdev_priv(dev);
1610 hermes_t *hw = &priv->hw;
1612 struct hermes_idstring idbuf;
1614 /* Set the MAC address */
1615 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1616 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1618 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1623 /* Set up the link mode */
1624 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1627 printk(KERN_ERR "%s: Error %d setting port type\n",
1631 /* Set the channel/frequency */
1632 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1633 err = hermes_write_wordrec(hw, USER_BAP,
1634 HERMES_RID_CNFOWNCHANNEL,
1637 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1638 dev->name, err, priv->channel);
1643 if (priv->has_ibss) {
1646 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1647 printk(KERN_WARNING "%s: This firmware requires an "
1648 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1649 /* With wvlan_cs, in this case, we would crash.
1650 * hopefully, this driver will behave better...
1654 createibss = priv->createibss;
1657 err = hermes_write_wordrec(hw, USER_BAP,
1658 HERMES_RID_CNFCREATEIBSS,
1661 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1667 /* Set the desired BSSID */
1668 err = __orinoco_hw_set_wap(priv);
1670 printk(KERN_ERR "%s: Error %d setting AP address\n",
1674 /* Set the desired ESSID */
1675 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1676 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1677 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1678 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1679 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1682 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1686 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1687 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1690 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1695 /* Set the station name */
1696 idbuf.len = cpu_to_le16(strlen(priv->nick));
1697 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1698 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1699 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1702 printk(KERN_ERR "%s: Error %d setting nickname\n",
1707 /* Set AP density */
1708 if (priv->has_sensitivity) {
1709 err = hermes_write_wordrec(hw, USER_BAP,
1710 HERMES_RID_CNFSYSTEMSCALE,
1713 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1714 "Disabling sensitivity control\n",
1717 priv->has_sensitivity = 0;
1721 /* Set RTS threshold */
1722 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1725 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1730 /* Set fragmentation threshold or MWO robustness */
1732 err = hermes_write_wordrec(hw, USER_BAP,
1733 HERMES_RID_CNFMWOROBUST_AGERE,
1736 err = hermes_write_wordrec(hw, USER_BAP,
1737 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1740 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1746 err = __orinoco_hw_set_bitrate(priv);
1748 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1753 /* Set power management */
1755 err = hermes_write_wordrec(hw, USER_BAP,
1756 HERMES_RID_CNFPMENABLED,
1759 printk(KERN_ERR "%s: Error %d setting up PM\n",
1764 err = hermes_write_wordrec(hw, USER_BAP,
1765 HERMES_RID_CNFMULTICASTRECEIVE,
1768 printk(KERN_ERR "%s: Error %d setting up PM\n",
1772 err = hermes_write_wordrec(hw, USER_BAP,
1773 HERMES_RID_CNFMAXSLEEPDURATION,
1776 printk(KERN_ERR "%s: Error %d setting up PM\n",
1780 err = hermes_write_wordrec(hw, USER_BAP,
1781 HERMES_RID_CNFPMHOLDOVERDURATION,
1784 printk(KERN_ERR "%s: Error %d setting up PM\n",
1790 /* Set preamble - only for Symbol so far... */
1791 if (priv->has_preamble) {
1792 err = hermes_write_wordrec(hw, USER_BAP,
1793 HERMES_RID_CNFPREAMBLE_SYMBOL,
1796 printk(KERN_ERR "%s: Error %d setting preamble\n",
1802 /* Set up encryption */
1803 if (priv->has_wep) {
1804 err = __orinoco_hw_setup_wep(priv);
1806 printk(KERN_ERR "%s: Error %d activating WEP\n",
1812 if (priv->iw_mode == IW_MODE_MONITOR) {
1813 /* Enable monitor mode */
1814 dev->type = ARPHRD_IEEE80211;
1815 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1816 HERMES_TEST_MONITOR, 0, NULL);
1818 /* Disable monitor mode */
1819 dev->type = ARPHRD_ETHER;
1820 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1821 HERMES_TEST_STOP, 0, NULL);
1826 /* Set promiscuity / multicast*/
1827 priv->promiscuous = 0;
1829 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1834 /* FIXME: return int? */
1836 __orinoco_set_multicast_list(struct net_device *dev)
1838 struct orinoco_private *priv = netdev_priv(dev);
1839 hermes_t *hw = &priv->hw;
1841 int promisc, mc_count;
1843 /* The Hermes doesn't seem to have an allmulti mode, so we go
1844 * into promiscuous mode and let the upper levels deal. */
1845 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1846 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1851 mc_count = dev->mc_count;
1854 if (promisc != priv->promiscuous) {
1855 err = hermes_write_wordrec(hw, USER_BAP,
1856 HERMES_RID_CNFPROMISCUOUSMODE,
1859 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1862 priv->promiscuous = promisc;
1865 if (! promisc && (mc_count || priv->mc_count) ) {
1866 struct dev_mc_list *p = dev->mc_list;
1867 struct hermes_multicast mclist;
1870 for (i = 0; i < mc_count; i++) {
1871 /* paranoia: is list shorter than mc_count? */
1873 /* paranoia: bad address size in list? */
1874 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1876 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1881 printk(KERN_WARNING "%s: Multicast list is "
1882 "longer than mc_count\n", dev->name);
1884 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1885 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1888 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1891 priv->mc_count = mc_count;
1894 /* Since we can set the promiscuous flag when it wasn't asked
1895 for, make sure the net_device knows about it. */
1896 if (priv->promiscuous)
1897 dev->flags |= IFF_PROMISC;
1899 dev->flags &= ~IFF_PROMISC;
1902 /* This must be called from user context, without locks held - use
1903 * schedule_work() */
1904 static void orinoco_reset(struct net_device *dev)
1906 struct orinoco_private *priv = netdev_priv(dev);
1907 struct hermes *hw = &priv->hw;
1909 unsigned long flags;
1911 if (orinoco_lock(priv, &flags) != 0)
1912 /* When the hardware becomes available again, whatever
1913 * detects that is responsible for re-initializing
1914 * it. So no need for anything further */
1917 netif_stop_queue(dev);
1919 /* Shut off interrupts. Depending on what state the hardware
1920 * is in, this might not work, but we'll try anyway */
1921 hermes_set_irqmask(hw, 0);
1922 hermes_write_regn(hw, EVACK, 0xffff);
1924 priv->hw_unavailable++;
1925 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1926 netif_carrier_off(dev);
1928 orinoco_unlock(priv, &flags);
1930 /* Scanning support: Cleanup of driver struct */
1931 kfree(priv->scan_result);
1932 priv->scan_result = NULL;
1933 priv->scan_inprogress = 0;
1935 if (priv->hard_reset) {
1936 err = (*priv->hard_reset)(priv);
1938 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1939 "performing hard reset\n", dev->name, err);
1944 err = orinoco_reinit_firmware(dev);
1946 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1951 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1953 priv->hw_unavailable--;
1955 /* priv->open or priv->hw_unavailable might have changed while
1956 * we dropped the lock */
1957 if (priv->open && (! priv->hw_unavailable)) {
1958 err = __orinoco_up(dev);
1960 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1963 dev->trans_start = jiffies;
1966 spin_unlock_irq(&priv->lock);
1970 hermes_set_irqmask(hw, 0);
1971 netif_device_detach(dev);
1972 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1975 /********************************************************************/
1976 /* Interrupt handler */
1977 /********************************************************************/
1979 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1981 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1984 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1986 /* This seems to happen a fair bit under load, but ignoring it
1987 seems to work fine...*/
1988 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1992 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1994 struct net_device *dev = (struct net_device *)dev_id;
1995 struct orinoco_private *priv = netdev_priv(dev);
1996 hermes_t *hw = &priv->hw;
1997 int count = MAX_IRQLOOPS_PER_IRQ;
1999 /* These are used to detect a runaway interrupt situation */
2000 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2001 * we panic and shut down the hardware */
2002 static int last_irq_jiffy = 0; /* jiffies value the last time
2004 static int loops_this_jiffy = 0;
2005 unsigned long flags;
2007 if (orinoco_lock(priv, &flags) != 0) {
2008 /* If hw is unavailable - we don't know if the irq was
2013 evstat = hermes_read_regn(hw, EVSTAT);
2014 events = evstat & hw->inten;
2016 orinoco_unlock(priv, &flags);
2020 if (jiffies != last_irq_jiffy)
2021 loops_this_jiffy = 0;
2022 last_irq_jiffy = jiffies;
2024 while (events && count--) {
2025 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2026 printk(KERN_WARNING "%s: IRQ handler is looping too "
2027 "much! Resetting.\n", dev->name);
2028 /* Disable interrupts for now */
2029 hermes_set_irqmask(hw, 0);
2030 schedule_work(&priv->reset_work);
2034 /* Check the card hasn't been removed */
2035 if (! hermes_present(hw)) {
2036 DEBUG(0, "orinoco_interrupt(): card removed\n");
2040 if (events & HERMES_EV_TICK)
2041 __orinoco_ev_tick(dev, hw);
2042 if (events & HERMES_EV_WTERR)
2043 __orinoco_ev_wterr(dev, hw);
2044 if (events & HERMES_EV_INFDROP)
2045 __orinoco_ev_infdrop(dev, hw);
2046 if (events & HERMES_EV_INFO)
2047 __orinoco_ev_info(dev, hw);
2048 if (events & HERMES_EV_RX)
2049 __orinoco_ev_rx(dev, hw);
2050 if (events & HERMES_EV_TXEXC)
2051 __orinoco_ev_txexc(dev, hw);
2052 if (events & HERMES_EV_TX)
2053 __orinoco_ev_tx(dev, hw);
2054 if (events & HERMES_EV_ALLOC)
2055 __orinoco_ev_alloc(dev, hw);
2057 hermes_write_regn(hw, EVACK, evstat);
2059 evstat = hermes_read_regn(hw, EVSTAT);
2060 events = evstat & hw->inten;
2063 orinoco_unlock(priv, &flags);
2067 /********************************************************************/
2068 /* Initialization */
2069 /********************************************************************/
2072 u16 id, variant, major, minor;
2073 } __attribute__ ((packed));
2075 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2077 if (nic_id->id < 0x8000)
2078 return FIRMWARE_TYPE_AGERE;
2079 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2080 return FIRMWARE_TYPE_SYMBOL;
2082 return FIRMWARE_TYPE_INTERSIL;
2085 /* Set priv->firmware type, determine firmware properties */
2086 static int determine_firmware(struct net_device *dev)
2088 struct orinoco_private *priv = netdev_priv(dev);
2089 hermes_t *hw = &priv->hw;
2091 struct comp_id nic_id, sta_id;
2092 unsigned int firmver;
2093 char tmp[SYMBOL_MAX_VER_LEN+1];
2095 /* Get the hardware version */
2096 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2098 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2103 le16_to_cpus(&nic_id.id);
2104 le16_to_cpus(&nic_id.variant);
2105 le16_to_cpus(&nic_id.major);
2106 le16_to_cpus(&nic_id.minor);
2107 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2108 dev->name, nic_id.id, nic_id.variant,
2109 nic_id.major, nic_id.minor);
2111 priv->firmware_type = determine_firmware_type(&nic_id);
2113 /* Get the firmware version */
2114 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2116 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2121 le16_to_cpus(&sta_id.id);
2122 le16_to_cpus(&sta_id.variant);
2123 le16_to_cpus(&sta_id.major);
2124 le16_to_cpus(&sta_id.minor);
2125 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2126 dev->name, sta_id.id, sta_id.variant,
2127 sta_id.major, sta_id.minor);
2129 switch (sta_id.id) {
2131 printk(KERN_ERR "%s: Primary firmware is active\n",
2135 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2138 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2139 case 0x21: /* Symbol Spectrum24 Trilogy */
2142 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2147 /* Default capabilities */
2148 priv->has_sensitivity = 1;
2150 priv->has_preamble = 0;
2151 priv->has_port3 = 1;
2154 priv->has_big_wep = 0;
2156 /* Determine capabilities from the firmware version */
2157 switch (priv->firmware_type) {
2158 case FIRMWARE_TYPE_AGERE:
2159 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2160 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2161 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2162 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2164 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2166 priv->has_ibss = (firmver >= 0x60006);
2167 priv->has_wep = (firmver >= 0x40020);
2168 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2169 Gold cards from the others? */
2170 priv->has_mwo = (firmver >= 0x60000);
2171 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2172 priv->ibss_port = 1;
2173 priv->has_hostscan = (firmver >= 0x8000a);
2174 priv->broken_monitor = (firmver >= 0x80000);
2176 /* Tested with Agere firmware :
2177 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2178 * Tested CableTron firmware : 4.32 => Anton */
2180 case FIRMWARE_TYPE_SYMBOL:
2181 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2182 /* Intel MAC : 00:02:B3:* */
2183 /* 3Com MAC : 00:50:DA:* */
2184 memset(tmp, 0, sizeof(tmp));
2185 /* Get the Symbol firmware version */
2186 err = hermes_read_ltv(hw, USER_BAP,
2187 HERMES_RID_SECONDARYVERSION_SYMBOL,
2188 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2191 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2196 /* The firmware revision is a string, the format is
2197 * something like : "V2.20-01".
2198 * Quick and dirty parsing... - Jean II
2200 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2201 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2204 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2207 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2210 priv->has_ibss = (firmver >= 0x20000);
2211 priv->has_wep = (firmver >= 0x15012);
2212 priv->has_big_wep = (firmver >= 0x20000);
2213 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2214 (firmver >= 0x29000 && firmver < 0x30000) ||
2216 priv->has_preamble = (firmver >= 0x20000);
2217 priv->ibss_port = 4;
2218 priv->broken_disableport = (firmver == 0x25013) ||
2219 (firmver >= 0x30000 && firmver <= 0x31000);
2220 priv->has_hostscan = (firmver >= 0x31001) ||
2221 (firmver >= 0x29057 && firmver < 0x30000);
2222 /* Tested with Intel firmware : 0x20015 => Jean II */
2223 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2225 case FIRMWARE_TYPE_INTERSIL:
2226 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2227 * Samsung, Compaq 100/200 and Proxim are slightly
2228 * different and less well tested */
2229 /* D-Link MAC : 00:40:05:* */
2230 /* Addtron MAC : 00:90:D1:* */
2231 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2232 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2235 firmver = ((unsigned long)sta_id.major << 16) |
2236 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2238 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2239 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2240 priv->has_pm = (firmver >= 0x000700);
2241 priv->has_hostscan = (firmver >= 0x010301);
2243 if (firmver >= 0x000800)
2244 priv->ibss_port = 0;
2246 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2247 "than v0.8.x - several features not supported\n",
2249 priv->ibss_port = 1;
2253 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2259 static int orinoco_init(struct net_device *dev)
2261 struct orinoco_private *priv = netdev_priv(dev);
2262 hermes_t *hw = &priv->hw;
2264 struct hermes_idstring nickbuf;
2268 /* No need to lock, the hw_unavailable flag is already set in
2269 * alloc_orinocodev() */
2270 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2272 /* Initialize the firmware */
2273 err = orinoco_reinit_firmware(dev);
2275 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2280 err = determine_firmware(dev);
2282 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2287 if (priv->has_port3)
2288 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2290 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2292 if (priv->has_wep) {
2293 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2294 if (priv->has_big_wep)
2295 printk("104-bit key\n");
2297 printk("40-bit key\n");
2300 /* Get the MAC address */
2301 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2302 ETH_ALEN, NULL, dev->dev_addr);
2304 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2309 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2310 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2311 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2314 /* Get the station name */
2315 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2316 sizeof(nickbuf), &reclen, &nickbuf);
2318 printk(KERN_ERR "%s: failed to read station name\n",
2323 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2325 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2326 memcpy(priv->nick, &nickbuf.val, len);
2327 priv->nick[len] = '\0';
2329 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2331 /* Get allowed channels */
2332 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2333 &priv->channel_mask);
2335 printk(KERN_ERR "%s: failed to read channel list!\n",
2340 /* Get initial AP density */
2341 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2343 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2344 priv->has_sensitivity = 0;
2347 /* Get initial RTS threshold */
2348 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2351 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2356 /* Get initial fragmentation settings */
2358 err = hermes_read_wordrec(hw, USER_BAP,
2359 HERMES_RID_CNFMWOROBUST_AGERE,
2362 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2363 &priv->frag_thresh);
2365 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2370 /* Power management setup */
2374 err = hermes_read_wordrec(hw, USER_BAP,
2375 HERMES_RID_CNFMAXSLEEPDURATION,
2378 printk(KERN_ERR "%s: failed to read power management period!\n",
2382 err = hermes_read_wordrec(hw, USER_BAP,
2383 HERMES_RID_CNFPMHOLDOVERDURATION,
2386 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2392 /* Preamble setup */
2393 if (priv->has_preamble) {
2394 err = hermes_read_wordrec(hw, USER_BAP,
2395 HERMES_RID_CNFPREAMBLE_SYMBOL,
2401 /* Set up the default configuration */
2402 priv->iw_mode = IW_MODE_INFRA;
2403 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2404 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2405 set_port_type(priv);
2406 priv->channel = 0; /* use firmware default */
2408 priv->promiscuous = 0;
2412 /* Make the hardware available, as long as it hasn't been
2413 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2414 spin_lock_irq(&priv->lock);
2415 priv->hw_unavailable--;
2416 spin_unlock_irq(&priv->lock);
2418 printk(KERN_DEBUG "%s: ready\n", dev->name);
2424 struct net_device *alloc_orinocodev(int sizeof_card,
2425 int (*hard_reset)(struct orinoco_private *))
2427 struct net_device *dev;
2428 struct orinoco_private *priv;
2430 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2433 priv = netdev_priv(dev);
2436 priv->card = (void *)((unsigned long)priv
2437 + sizeof(struct orinoco_private));
2441 /* Setup / override net_device fields */
2442 dev->init = orinoco_init;
2443 dev->hard_start_xmit = orinoco_xmit;
2444 dev->tx_timeout = orinoco_tx_timeout;
2445 dev->watchdog_timeo = HZ; /* 1 second timeout */
2446 dev->get_stats = orinoco_get_stats;
2447 dev->ethtool_ops = &orinoco_ethtool_ops;
2448 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2450 priv->wireless_data.spy_data = &priv->spy_data;
2451 dev->wireless_data = &priv->wireless_data;
2453 dev->change_mtu = orinoco_change_mtu;
2454 dev->set_multicast_list = orinoco_set_multicast_list;
2455 /* we use the default eth_mac_addr for setting the MAC addr */
2457 /* Set up default callbacks */
2458 dev->open = orinoco_open;
2459 dev->stop = orinoco_stop;
2460 priv->hard_reset = hard_reset;
2462 spin_lock_init(&priv->lock);
2464 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2465 * before anything else touches the
2467 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2468 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2469 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2471 netif_carrier_off(dev);
2472 priv->last_linkstatus = 0xffff;
2478 void free_orinocodev(struct net_device *dev)
2480 struct orinoco_private *priv = netdev_priv(dev);
2482 kfree(priv->scan_result);
2486 /********************************************************************/
2487 /* Wireless extensions */
2488 /********************************************************************/
2490 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2491 char buf[IW_ESSID_MAX_SIZE+1])
2493 hermes_t *hw = &priv->hw;
2495 struct hermes_idstring essidbuf;
2496 char *p = (char *)(&essidbuf.val);
2498 unsigned long flags;
2500 if (orinoco_lock(priv, &flags) != 0)
2503 if (strlen(priv->desired_essid) > 0) {
2504 /* We read the desired SSID from the hardware rather
2505 than from priv->desired_essid, just in case the
2506 firmware is allowed to change it on us. I'm not
2508 /* My guess is that the OWNSSID should always be whatever
2509 * we set to the card, whereas CURRENT_SSID is the one that
2510 * may change... - Jean II */
2515 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2516 HERMES_RID_CNFDESIREDSSID;
2518 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2525 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2526 sizeof(essidbuf), NULL, &essidbuf);
2531 len = le16_to_cpu(essidbuf.len);
2532 BUG_ON(len > IW_ESSID_MAX_SIZE);
2534 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2535 memcpy(buf, p, len);
2539 orinoco_unlock(priv, &flags);
2544 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2547 hermes_t *hw = &priv->hw;
2551 unsigned long flags;
2553 if (orinoco_lock(priv, &flags) != 0)
2556 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2560 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2566 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2567 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2568 priv->ndev->name, channel);
2573 freq = channel_frequency[channel-1] * 100000;
2576 orinoco_unlock(priv, &flags);
2580 return err ? err : freq;
2583 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2584 int *numrates, s32 *rates, int max)
2586 hermes_t *hw = &priv->hw;
2587 struct hermes_idstring list;
2588 unsigned char *p = (unsigned char *)&list.val;
2592 unsigned long flags;
2594 if (orinoco_lock(priv, &flags) != 0)
2597 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2598 sizeof(list), NULL, &list);
2599 orinoco_unlock(priv, &flags);
2604 num = le16_to_cpu(list.len);
2606 num = min(num, max);
2608 for (i = 0; i < num; i++) {
2609 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2615 static int orinoco_ioctl_getname(struct net_device *dev,
2616 struct iw_request_info *info,
2620 struct orinoco_private *priv = netdev_priv(dev);
2624 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2626 if (!err && (numrates > 2))
2627 strcpy(name, "IEEE 802.11b");
2629 strcpy(name, "IEEE 802.11-DS");
2634 static int orinoco_ioctl_setwap(struct net_device *dev,
2635 struct iw_request_info *info,
2636 struct sockaddr *ap_addr,
2639 struct orinoco_private *priv = netdev_priv(dev);
2640 int err = -EINPROGRESS; /* Call commit handler */
2641 unsigned long flags;
2642 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2643 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2645 if (orinoco_lock(priv, &flags) != 0)
2648 /* Enable automatic roaming - no sanity checks are needed */
2649 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2650 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2651 priv->bssid_fixed = 0;
2652 memset(priv->desired_bssid, 0, ETH_ALEN);
2654 /* "off" means keep existing connection */
2655 if (ap_addr->sa_data[0] == 0) {
2656 __orinoco_hw_set_wap(priv);
2662 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2663 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2664 "support manual roaming\n",
2670 if (priv->iw_mode != IW_MODE_INFRA) {
2671 printk(KERN_WARNING "%s: Manual roaming supported only in "
2672 "managed mode\n", dev->name);
2677 /* Intersil firmware hangs without Desired ESSID */
2678 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2679 strlen(priv->desired_essid) == 0) {
2680 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2681 "manual roaming\n", dev->name);
2686 /* Finally, enable manual roaming */
2687 priv->bssid_fixed = 1;
2688 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2691 orinoco_unlock(priv, &flags);
2695 static int orinoco_ioctl_getwap(struct net_device *dev,
2696 struct iw_request_info *info,
2697 struct sockaddr *ap_addr,
2700 struct orinoco_private *priv = netdev_priv(dev);
2702 hermes_t *hw = &priv->hw;
2704 unsigned long flags;
2706 if (orinoco_lock(priv, &flags) != 0)
2709 ap_addr->sa_family = ARPHRD_ETHER;
2710 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2711 ETH_ALEN, NULL, ap_addr->sa_data);
2713 orinoco_unlock(priv, &flags);
2718 static int orinoco_ioctl_setmode(struct net_device *dev,
2719 struct iw_request_info *info,
2723 struct orinoco_private *priv = netdev_priv(dev);
2724 int err = -EINPROGRESS; /* Call commit handler */
2725 unsigned long flags;
2727 if (priv->iw_mode == *mode)
2730 if (orinoco_lock(priv, &flags) != 0)
2735 if (!priv->has_ibss && !priv->has_port3)
2742 case IW_MODE_MONITOR:
2743 if (priv->broken_monitor && !force_monitor) {
2744 printk(KERN_WARNING "%s: Monitor mode support is "
2745 "buggy in this firmware, not enabling\n",
2756 if (err == -EINPROGRESS) {
2757 priv->iw_mode = *mode;
2758 set_port_type(priv);
2761 orinoco_unlock(priv, &flags);
2766 static int orinoco_ioctl_getmode(struct net_device *dev,
2767 struct iw_request_info *info,
2771 struct orinoco_private *priv = netdev_priv(dev);
2773 *mode = priv->iw_mode;
2777 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2778 struct iw_request_info *info,
2779 struct iw_point *rrq,
2782 struct orinoco_private *priv = netdev_priv(dev);
2784 struct iw_range *range = (struct iw_range *) extra;
2788 rrq->length = sizeof(struct iw_range);
2789 memset(range, 0, sizeof(struct iw_range));
2791 range->we_version_compiled = WIRELESS_EXT;
2792 range->we_version_source = 14;
2794 /* Set available channels/frequencies */
2795 range->num_channels = NUM_CHANNELS;
2797 for (i = 0; i < NUM_CHANNELS; i++) {
2798 if (priv->channel_mask & (1 << i)) {
2799 range->freq[k].i = i + 1;
2800 range->freq[k].m = channel_frequency[i] * 100000;
2801 range->freq[k].e = 1;
2805 if (k >= IW_MAX_FREQUENCIES)
2808 range->num_frequency = k;
2809 range->sensitivity = 3;
2811 if (priv->has_wep) {
2812 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2813 range->encoding_size[0] = SMALL_KEY_SIZE;
2814 range->num_encoding_sizes = 1;
2816 if (priv->has_big_wep) {
2817 range->encoding_size[1] = LARGE_KEY_SIZE;
2818 range->num_encoding_sizes = 2;
2822 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2823 /* Quality stats meaningless in ad-hoc mode */
2825 range->max_qual.qual = 0x8b - 0x2f;
2826 range->max_qual.level = 0x2f - 0x95 - 1;
2827 range->max_qual.noise = 0x2f - 0x95 - 1;
2828 /* Need to get better values */
2829 range->avg_qual.qual = 0x24;
2830 range->avg_qual.level = 0xC2;
2831 range->avg_qual.noise = 0x9E;
2834 err = orinoco_hw_get_bitratelist(priv, &numrates,
2835 range->bitrate, IW_MAX_BITRATES);
2838 range->num_bitrates = numrates;
2840 /* Set an indication of the max TCP throughput in bit/s that we can
2841 * expect using this interface. May be use for QoS stuff...
2844 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2846 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2849 range->max_rts = 2347;
2850 range->min_frag = 256;
2851 range->max_frag = 2346;
2854 range->max_pmp = 65535000;
2856 range->max_pmt = 65535 * 1000; /* ??? */
2857 range->pmp_flags = IW_POWER_PERIOD;
2858 range->pmt_flags = IW_POWER_TIMEOUT;
2859 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2861 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2862 range->retry_flags = IW_RETRY_LIMIT;
2863 range->r_time_flags = IW_RETRY_LIFETIME;
2864 range->min_retry = 0;
2865 range->max_retry = 65535; /* ??? */
2866 range->min_r_time = 0;
2867 range->max_r_time = 65535 * 1000; /* ??? */
2869 /* Event capability (kernel) */
2870 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2871 /* Event capability (driver) */
2872 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2873 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2874 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2875 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2880 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2881 struct iw_request_info *info,
2882 struct iw_point *erq,
2885 struct orinoco_private *priv = netdev_priv(dev);
2886 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2887 int setindex = priv->tx_key;
2888 int enable = priv->wep_on;
2889 int restricted = priv->wep_restrict;
2891 int err = -EINPROGRESS; /* Call commit handler */
2892 unsigned long flags;
2894 if (! priv->has_wep)
2898 /* We actually have a key to set - check its length */
2899 if (erq->length > LARGE_KEY_SIZE)
2902 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2906 if (orinoco_lock(priv, &flags) != 0)
2910 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2911 index = priv->tx_key;
2913 /* Adjust key length to a supported value */
2914 if (erq->length > SMALL_KEY_SIZE) {
2915 xlen = LARGE_KEY_SIZE;
2916 } else if (erq->length > 0) {
2917 xlen = SMALL_KEY_SIZE;
2921 /* Switch on WEP if off */
2922 if ((!enable) && (xlen > 0)) {
2927 /* Important note : if the user do "iwconfig eth0 enc off",
2928 * we will arrive there with an index of -1. This is valid
2929 * but need to be taken care off... Jean II */
2930 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2931 if((index != -1) || (erq->flags == 0)) {
2936 /* Set the index : Check that the key is valid */
2937 if(priv->keys[index].len == 0) {
2945 if (erq->flags & IW_ENCODE_DISABLED)
2947 if (erq->flags & IW_ENCODE_OPEN)
2949 if (erq->flags & IW_ENCODE_RESTRICTED)
2953 priv->keys[index].len = cpu_to_le16(xlen);
2954 memset(priv->keys[index].data, 0,
2955 sizeof(priv->keys[index].data));
2956 memcpy(priv->keys[index].data, keybuf, erq->length);
2958 priv->tx_key = setindex;
2960 /* Try fast key change if connected and only keys are changed */
2961 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2962 netif_carrier_ok(dev)) {
2963 err = __orinoco_hw_setup_wepkeys(priv);
2964 /* No need to commit if successful */
2968 priv->wep_on = enable;
2969 priv->wep_restrict = restricted;
2972 orinoco_unlock(priv, &flags);
2977 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2978 struct iw_request_info *info,
2979 struct iw_point *erq,
2982 struct orinoco_private *priv = netdev_priv(dev);
2983 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2985 unsigned long flags;
2987 if (! priv->has_wep)
2990 if (orinoco_lock(priv, &flags) != 0)
2993 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2994 index = priv->tx_key;
2998 erq->flags |= IW_ENCODE_DISABLED;
2999 erq->flags |= index + 1;
3001 if (priv->wep_restrict)
3002 erq->flags |= IW_ENCODE_RESTRICTED;
3004 erq->flags |= IW_ENCODE_OPEN;
3006 xlen = le16_to_cpu(priv->keys[index].len);
3010 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3012 orinoco_unlock(priv, &flags);
3016 static int orinoco_ioctl_setessid(struct net_device *dev,
3017 struct iw_request_info *info,
3018 struct iw_point *erq,
3021 struct orinoco_private *priv = netdev_priv(dev);
3022 unsigned long flags;
3024 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3025 * anyway... - Jean II */
3027 /* Hum... Should not use Wireless Extension constant (may change),
3028 * should use our own... - Jean II */
3029 if (erq->length > IW_ESSID_MAX_SIZE)
3032 if (orinoco_lock(priv, &flags) != 0)
3035 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3036 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3038 /* If not ANY, get the new ESSID */
3040 memcpy(priv->desired_essid, essidbuf, erq->length);
3043 orinoco_unlock(priv, &flags);
3045 return -EINPROGRESS; /* Call commit handler */
3048 static int orinoco_ioctl_getessid(struct net_device *dev,
3049 struct iw_request_info *info,
3050 struct iw_point *erq,
3053 struct orinoco_private *priv = netdev_priv(dev);
3056 unsigned long flags;
3058 if (netif_running(dev)) {
3059 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3063 if (orinoco_lock(priv, &flags) != 0)
3065 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3066 orinoco_unlock(priv, &flags);
3070 erq->length = strlen(essidbuf) + 1;
3075 static int orinoco_ioctl_setnick(struct net_device *dev,
3076 struct iw_request_info *info,
3077 struct iw_point *nrq,
3080 struct orinoco_private *priv = netdev_priv(dev);
3081 unsigned long flags;
3083 if (nrq->length > IW_ESSID_MAX_SIZE)
3086 if (orinoco_lock(priv, &flags) != 0)
3089 memset(priv->nick, 0, sizeof(priv->nick));
3090 memcpy(priv->nick, nickbuf, nrq->length);
3092 orinoco_unlock(priv, &flags);
3094 return -EINPROGRESS; /* Call commit handler */
3097 static int orinoco_ioctl_getnick(struct net_device *dev,
3098 struct iw_request_info *info,
3099 struct iw_point *nrq,
3102 struct orinoco_private *priv = netdev_priv(dev);
3103 unsigned long flags;
3105 if (orinoco_lock(priv, &flags) != 0)
3108 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3109 orinoco_unlock(priv, &flags);
3111 nrq->length = strlen(nickbuf)+1;
3116 static int orinoco_ioctl_setfreq(struct net_device *dev,
3117 struct iw_request_info *info,
3118 struct iw_freq *frq,
3121 struct orinoco_private *priv = netdev_priv(dev);
3123 unsigned long flags;
3124 int err = -EINPROGRESS; /* Call commit handler */
3126 /* In infrastructure mode the AP sets the channel */
3127 if (priv->iw_mode == IW_MODE_INFRA)
3130 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3131 /* Setting by channel number */
3134 /* Setting by frequency - search the table */
3138 for (i = 0; i < (6 - frq->e); i++)
3141 for (i = 0; i < NUM_CHANNELS; i++)
3142 if (frq->m == (channel_frequency[i] * mult))
3146 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3147 ! (priv->channel_mask & (1 << (chan-1)) ) )
3150 if (orinoco_lock(priv, &flags) != 0)
3153 priv->channel = chan;
3154 if (priv->iw_mode == IW_MODE_MONITOR) {
3155 /* Fast channel change - no commit if successful */
3156 hermes_t *hw = &priv->hw;
3157 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3158 HERMES_TEST_SET_CHANNEL,
3161 orinoco_unlock(priv, &flags);
3166 static int orinoco_ioctl_getfreq(struct net_device *dev,
3167 struct iw_request_info *info,
3168 struct iw_freq *frq,
3171 struct orinoco_private *priv = netdev_priv(dev);
3174 /* Locking done in there */
3175 tmp = orinoco_hw_get_freq(priv);
3186 static int orinoco_ioctl_getsens(struct net_device *dev,
3187 struct iw_request_info *info,
3188 struct iw_param *srq,
3191 struct orinoco_private *priv = netdev_priv(dev);
3192 hermes_t *hw = &priv->hw;
3195 unsigned long flags;
3197 if (!priv->has_sensitivity)
3200 if (orinoco_lock(priv, &flags) != 0)
3202 err = hermes_read_wordrec(hw, USER_BAP,
3203 HERMES_RID_CNFSYSTEMSCALE, &val);
3204 orinoco_unlock(priv, &flags);
3210 srq->fixed = 0; /* auto */
3215 static int orinoco_ioctl_setsens(struct net_device *dev,
3216 struct iw_request_info *info,
3217 struct iw_param *srq,
3220 struct orinoco_private *priv = netdev_priv(dev);
3221 int val = srq->value;
3222 unsigned long flags;
3224 if (!priv->has_sensitivity)
3227 if ((val < 1) || (val > 3))
3230 if (orinoco_lock(priv, &flags) != 0)
3232 priv->ap_density = val;
3233 orinoco_unlock(priv, &flags);
3235 return -EINPROGRESS; /* Call commit handler */
3238 static int orinoco_ioctl_setrts(struct net_device *dev,
3239 struct iw_request_info *info,
3240 struct iw_param *rrq,
3243 struct orinoco_private *priv = netdev_priv(dev);
3244 int val = rrq->value;
3245 unsigned long flags;
3250 if ( (val < 0) || (val > 2347) )
3253 if (orinoco_lock(priv, &flags) != 0)
3256 priv->rts_thresh = val;
3257 orinoco_unlock(priv, &flags);
3259 return -EINPROGRESS; /* Call commit handler */
3262 static int orinoco_ioctl_getrts(struct net_device *dev,
3263 struct iw_request_info *info,
3264 struct iw_param *rrq,
3267 struct orinoco_private *priv = netdev_priv(dev);
3269 rrq->value = priv->rts_thresh;
3270 rrq->disabled = (rrq->value == 2347);
3276 static int orinoco_ioctl_setfrag(struct net_device *dev,
3277 struct iw_request_info *info,
3278 struct iw_param *frq,
3281 struct orinoco_private *priv = netdev_priv(dev);
3282 int err = -EINPROGRESS; /* Call commit handler */
3283 unsigned long flags;
3285 if (orinoco_lock(priv, &flags) != 0)
3288 if (priv->has_mwo) {
3290 priv->mwo_robust = 0;
3293 printk(KERN_WARNING "%s: Fixed fragmentation is "
3294 "not supported on this firmware. "
3295 "Using MWO robust instead.\n", dev->name);
3296 priv->mwo_robust = 1;
3300 priv->frag_thresh = 2346;
3302 if ( (frq->value < 256) || (frq->value > 2346) )
3305 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3309 orinoco_unlock(priv, &flags);
3314 static int orinoco_ioctl_getfrag(struct net_device *dev,
3315 struct iw_request_info *info,
3316 struct iw_param *frq,
3319 struct orinoco_private *priv = netdev_priv(dev);
3320 hermes_t *hw = &priv->hw;
3323 unsigned long flags;
3325 if (orinoco_lock(priv, &flags) != 0)
3328 if (priv->has_mwo) {
3329 err = hermes_read_wordrec(hw, USER_BAP,
3330 HERMES_RID_CNFMWOROBUST_AGERE,
3335 frq->value = val ? 2347 : 0;
3336 frq->disabled = ! val;
3339 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3345 frq->disabled = (val >= 2346);
3349 orinoco_unlock(priv, &flags);
3354 static int orinoco_ioctl_setrate(struct net_device *dev,
3355 struct iw_request_info *info,
3356 struct iw_param *rrq,
3359 struct orinoco_private *priv = netdev_priv(dev);
3361 int bitrate; /* 100s of kilobits */
3363 unsigned long flags;
3365 /* As the user space doesn't know our highest rate, it uses -1
3366 * to ask us to set the highest rate. Test it using "iwconfig
3367 * ethX rate auto" - Jean II */
3368 if (rrq->value == -1)
3371 if (rrq->value % 100000)
3373 bitrate = rrq->value / 100000;
3376 if ( (bitrate != 10) && (bitrate != 20) &&
3377 (bitrate != 55) && (bitrate != 110) )
3380 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3381 if ( (bitrate_table[i].bitrate == bitrate) &&
3382 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3390 if (orinoco_lock(priv, &flags) != 0)
3392 priv->bitratemode = ratemode;
3393 orinoco_unlock(priv, &flags);
3395 return -EINPROGRESS;
3398 static int orinoco_ioctl_getrate(struct net_device *dev,
3399 struct iw_request_info *info,
3400 struct iw_param *rrq,
3403 struct orinoco_private *priv = netdev_priv(dev);
3404 hermes_t *hw = &priv->hw;
3409 unsigned long flags;
3411 if (orinoco_lock(priv, &flags) != 0)
3414 ratemode = priv->bitratemode;
3416 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3418 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3419 rrq->fixed = ! bitrate_table[ratemode].automatic;
3422 /* If the interface is running we try to find more about the
3424 if (netif_running(dev)) {
3425 err = hermes_read_wordrec(hw, USER_BAP,
3426 HERMES_RID_CURRENTTXRATE, &val);
3430 switch (priv->firmware_type) {
3431 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3432 /* Note : in Lucent firmware, the return value of
3433 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3434 * and therefore is totally different from the
3435 * encoding of HERMES_RID_CNFTXRATECONTROL.
3436 * Don't forget that 6Mb/s is really 5.5Mb/s */
3438 rrq->value = 5500000;
3440 rrq->value = val * 1000000;
3442 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3443 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3444 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3445 if (bitrate_table[i].intersil_txratectrl == val) {
3449 if (i >= BITRATE_TABLE_SIZE)
3450 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3453 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3461 orinoco_unlock(priv, &flags);
3466 static int orinoco_ioctl_setpower(struct net_device *dev,
3467 struct iw_request_info *info,
3468 struct iw_param *prq,
3471 struct orinoco_private *priv = netdev_priv(dev);
3472 int err = -EINPROGRESS; /* Call commit handler */
3473 unsigned long flags;
3475 if (orinoco_lock(priv, &flags) != 0)
3478 if (prq->disabled) {
3481 switch (prq->flags & IW_POWER_MODE) {
3482 case IW_POWER_UNICAST_R:
3486 case IW_POWER_ALL_R:
3491 /* No flags : but we may have a value - Jean II */
3498 if (prq->flags & IW_POWER_TIMEOUT) {
3500 priv->pm_timeout = prq->value / 1000;
3502 if (prq->flags & IW_POWER_PERIOD) {
3504 priv->pm_period = prq->value / 1000;
3506 /* It's valid to not have a value if we are just toggling
3507 * the flags... Jean II */
3515 orinoco_unlock(priv, &flags);
3520 static int orinoco_ioctl_getpower(struct net_device *dev,
3521 struct iw_request_info *info,
3522 struct iw_param *prq,
3525 struct orinoco_private *priv = netdev_priv(dev);
3526 hermes_t *hw = &priv->hw;
3528 u16 enable, period, timeout, mcast;
3529 unsigned long flags;
3531 if (orinoco_lock(priv, &flags) != 0)
3534 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3538 err = hermes_read_wordrec(hw, USER_BAP,
3539 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3543 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3547 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3551 prq->disabled = !enable;
3552 /* Note : by default, display the period */
3553 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3554 prq->flags = IW_POWER_TIMEOUT;
3555 prq->value = timeout * 1000;
3557 prq->flags = IW_POWER_PERIOD;
3558 prq->value = period * 1000;
3561 prq->flags |= IW_POWER_ALL_R;
3563 prq->flags |= IW_POWER_UNICAST_R;
3566 orinoco_unlock(priv, &flags);
3571 static int orinoco_ioctl_getretry(struct net_device *dev,
3572 struct iw_request_info *info,
3573 struct iw_param *rrq,
3576 struct orinoco_private *priv = netdev_priv(dev);
3577 hermes_t *hw = &priv->hw;
3579 u16 short_limit, long_limit, lifetime;
3580 unsigned long flags;
3582 if (orinoco_lock(priv, &flags) != 0)
3585 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3590 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3595 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3600 rrq->disabled = 0; /* Can't be disabled */
3602 /* Note : by default, display the retry number */
3603 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3604 rrq->flags = IW_RETRY_LIFETIME;
3605 rrq->value = lifetime * 1000; /* ??? */
3607 /* By default, display the min number */
3608 if ((rrq->flags & IW_RETRY_MAX)) {
3609 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3610 rrq->value = long_limit;
3612 rrq->flags = IW_RETRY_LIMIT;
3613 rrq->value = short_limit;
3614 if(short_limit != long_limit)
3615 rrq->flags |= IW_RETRY_MIN;
3620 orinoco_unlock(priv, &flags);
3625 static int orinoco_ioctl_reset(struct net_device *dev,
3626 struct iw_request_info *info,
3630 struct orinoco_private *priv = netdev_priv(dev);
3632 if (! capable(CAP_NET_ADMIN))
3635 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3636 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3638 /* Firmware reset */
3641 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3643 schedule_work(&priv->reset_work);
3649 static int orinoco_ioctl_setibssport(struct net_device *dev,
3650 struct iw_request_info *info,
3655 struct orinoco_private *priv = netdev_priv(dev);
3656 int val = *( (int *) extra );
3657 unsigned long flags;
3659 if (orinoco_lock(priv, &flags) != 0)
3662 priv->ibss_port = val ;
3664 /* Actually update the mode we are using */
3665 set_port_type(priv);
3667 orinoco_unlock(priv, &flags);
3668 return -EINPROGRESS; /* Call commit handler */
3671 static int orinoco_ioctl_getibssport(struct net_device *dev,
3672 struct iw_request_info *info,
3676 struct orinoco_private *priv = netdev_priv(dev);
3677 int *val = (int *) extra;
3679 *val = priv->ibss_port;
3683 static int orinoco_ioctl_setport3(struct net_device *dev,
3684 struct iw_request_info *info,
3688 struct orinoco_private *priv = netdev_priv(dev);
3689 int val = *( (int *) extra );
3691 unsigned long flags;
3693 if (orinoco_lock(priv, &flags) != 0)
3697 case 0: /* Try to do IEEE ad-hoc mode */
3698 if (! priv->has_ibss) {
3702 priv->prefer_port3 = 0;
3706 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3707 if (! priv->has_port3) {
3711 priv->prefer_port3 = 1;
3719 /* Actually update the mode we are using */
3720 set_port_type(priv);
3724 orinoco_unlock(priv, &flags);
3729 static int orinoco_ioctl_getport3(struct net_device *dev,
3730 struct iw_request_info *info,
3734 struct orinoco_private *priv = netdev_priv(dev);
3735 int *val = (int *) extra;
3737 *val = priv->prefer_port3;
3741 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3742 struct iw_request_info *info,
3746 struct orinoco_private *priv = netdev_priv(dev);
3747 unsigned long flags;
3750 if (! priv->has_preamble)
3753 /* 802.11b has recently defined some short preamble.
3754 * Basically, the Phy header has been reduced in size.
3755 * This increase performance, especially at high rates
3756 * (the preamble is transmitted at 1Mb/s), unfortunately
3757 * this give compatibility troubles... - Jean II */
3758 val = *( (int *) extra );
3760 if (orinoco_lock(priv, &flags) != 0)
3768 orinoco_unlock(priv, &flags);
3770 return -EINPROGRESS; /* Call commit handler */
3773 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3774 struct iw_request_info *info,
3778 struct orinoco_private *priv = netdev_priv(dev);
3779 int *val = (int *) extra;
3781 if (! priv->has_preamble)
3784 *val = priv->preamble;
3788 /* ioctl interface to hermes_read_ltv()
3789 * To use with iwpriv, pass the RID as the token argument, e.g.
3790 * iwpriv get_rid [0xfc00]
3791 * At least Wireless Tools 25 is required to use iwpriv.
3792 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3793 static int orinoco_ioctl_getrid(struct net_device *dev,
3794 struct iw_request_info *info,
3795 struct iw_point *data,
3798 struct orinoco_private *priv = netdev_priv(dev);
3799 hermes_t *hw = &priv->hw;
3800 int rid = data->flags;
3803 unsigned long flags;
3805 /* It's a "get" function, but we don't want users to access the
3806 * WEP key and other raw firmware data */
3807 if (! capable(CAP_NET_ADMIN))
3810 if (rid < 0xfc00 || rid > 0xffff)
3813 if (orinoco_lock(priv, &flags) != 0)
3816 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3821 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3825 orinoco_unlock(priv, &flags);
3829 /* Trigger a scan (look for other cells in the vicinity */
3830 static int orinoco_ioctl_setscan(struct net_device *dev,
3831 struct iw_request_info *info,
3832 struct iw_param *srq,
3835 struct orinoco_private *priv = netdev_priv(dev);
3836 hermes_t *hw = &priv->hw;
3838 unsigned long flags;
3840 /* Note : you may have realised that, as this is a SET operation,
3841 * this is privileged and therefore a normal user can't
3843 * This is not an error, while the device perform scanning,
3844 * traffic doesn't flow, so it's a perfect DoS...
3847 if (orinoco_lock(priv, &flags) != 0)
3850 /* Scanning with port 0 disabled would fail */
3851 if (!netif_running(dev)) {
3856 /* In monitor mode, the scan results are always empty.
3857 * Probe responses are passed to the driver as received
3858 * frames and could be processed in software. */
3859 if (priv->iw_mode == IW_MODE_MONITOR) {
3864 /* Note : because we don't lock out the irq handler, the way
3865 * we access scan variables in priv is critical.
3866 * o scan_inprogress : not touched by irq handler
3867 * o scan_mode : not touched by irq handler
3868 * o scan_result : irq is strict producer, non-irq is strict
3870 * o scan_len : synchronised with scan_result
3871 * Before modifying anything on those variables, please think hard !
3874 /* If there is still some left-over scan results, get rid of it */
3875 if (priv->scan_result != NULL) {
3876 /* What's likely is that a client did crash or was killed
3877 * between triggering the scan request and reading the
3878 * results, so we need to reset everything.
3879 * Some clients that are too slow may suffer from that...
3881 kfree(priv->scan_result);
3882 priv->scan_result = NULL;
3886 priv->scan_mode = srq->flags;
3888 /* Always trigger scanning, even if it's in progress.
3889 * This way, if the info frame get lost, we will recover somewhat
3890 * gracefully - Jean II */
3892 if (priv->has_hostscan) {
3893 switch (priv->firmware_type) {
3894 case FIRMWARE_TYPE_SYMBOL:
3895 err = hermes_write_wordrec(hw, USER_BAP,
3896 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3897 HERMES_HOSTSCAN_SYMBOL_ONCE |
3898 HERMES_HOSTSCAN_SYMBOL_BCAST);
3900 case FIRMWARE_TYPE_INTERSIL: {
3903 req[0] = cpu_to_le16(0x3fff); /* All channels */
3904 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3905 req[2] = 0; /* Any ESSID */
3906 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3907 HERMES_RID_CNFHOSTSCAN, &req);
3910 case FIRMWARE_TYPE_AGERE:
3911 err = hermes_write_wordrec(hw, USER_BAP,
3912 HERMES_RID_CNFSCANSSID_AGERE,
3917 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3921 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3923 /* One more client */
3925 priv->scan_inprogress = 1;
3928 orinoco_unlock(priv, &flags);
3932 /* Translate scan data returned from the card to a card independant
3933 * format that the Wireless Tools will understand - Jean II
3934 * Return message length or -errno for fatal errors */
3935 static inline int orinoco_translate_scan(struct net_device *dev,
3940 struct orinoco_private *priv = netdev_priv(dev);
3941 int offset; /* In the scan data */
3942 union hermes_scan_info *atom;
3946 struct iw_event iwe; /* Temporary buffer */
3947 char * current_ev = buffer;
3948 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3950 switch (priv->firmware_type) {
3951 case FIRMWARE_TYPE_AGERE:
3952 atom_len = sizeof(struct agere_scan_apinfo);
3955 case FIRMWARE_TYPE_SYMBOL:
3956 /* Lack of documentation necessitates this hack.
3957 * Different firmwares have 68 or 76 byte long atoms.
3958 * We try modulo first. If the length divides by both,
3959 * we check what would be the channel in the second
3960 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3961 * Valid channel cannot be 0. */
3964 else if (scan_len % 68)
3966 else if (scan_len >= 1292 && scan[68] == 0)
3972 case FIRMWARE_TYPE_INTERSIL:
3974 if (priv->has_hostscan) {
3975 atom_len = le16_to_cpup((__le16 *)scan);
3976 /* Sanity check for atom_len */
3977 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3978 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3979 dev->name, atom_len);
3983 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3989 /* Check that we got an whole number of atoms */
3990 if ((scan_len - offset) % atom_len) {
3991 printk(KERN_ERR "%s: Unexpected scan data length %d, "
3992 "atom_len %d, offset %d\n", dev->name, scan_len,
3997 /* Read the entries one by one */
3998 for (; offset + atom_len <= scan_len; offset += atom_len) {
4000 atom = (union hermes_scan_info *) (scan + offset);
4002 /* First entry *MUST* be the AP MAC address */
4003 iwe.cmd = SIOCGIWAP;
4004 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4005 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4006 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4008 /* Other entries will be displayed in the order we give them */
4011 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4012 if (iwe.u.data.length > 32)
4013 iwe.u.data.length = 32;
4014 iwe.cmd = SIOCGIWESSID;
4015 iwe.u.data.flags = 1;
4016 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4019 iwe.cmd = SIOCGIWMODE;
4020 capabilities = le16_to_cpu(atom->a.capabilities);
4021 if (capabilities & 0x3) {
4022 if (capabilities & 0x1)
4023 iwe.u.mode = IW_MODE_MASTER;
4025 iwe.u.mode = IW_MODE_ADHOC;
4026 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4029 channel = atom->s.channel;
4030 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4032 iwe.cmd = SIOCGIWFREQ;
4033 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4035 current_ev = iwe_stream_add_event(current_ev, end_buf,
4036 &iwe, IW_EV_FREQ_LEN);
4039 /* Add quality statistics */
4041 iwe.u.qual.updated = 0x10; /* no link quality */
4042 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4043 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4044 /* Wireless tools prior to 27.pre22 will show link quality
4045 * anyway, so we provide a reasonable value. */
4046 if (iwe.u.qual.level > iwe.u.qual.noise)
4047 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4049 iwe.u.qual.qual = 0;
4050 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4052 /* Add encryption capability */
4053 iwe.cmd = SIOCGIWENCODE;
4054 if (capabilities & 0x10)
4055 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4057 iwe.u.data.flags = IW_ENCODE_DISABLED;
4058 iwe.u.data.length = 0;
4059 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4061 /* Bit rate is not available in Lucent/Agere firmwares */
4062 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4063 char * current_val = current_ev + IW_EV_LCP_LEN;
4067 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4072 iwe.cmd = SIOCGIWRATE;
4073 /* Those two flags are ignored... */
4074 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4076 for (i = 0; i < 10; i += step) {
4077 /* NULL terminated */
4078 if (atom->p.rates[i] == 0x0)
4080 /* Bit rate given in 500 kb/s units (+ 0x80) */
4081 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4082 current_val = iwe_stream_add_value(current_ev, current_val,
4086 /* Check if we added any event */
4087 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4088 current_ev = current_val;
4091 /* The other data in the scan result are not really
4092 * interesting, so for now drop it - Jean II */
4094 return current_ev - buffer;
4097 /* Return results of a scan */
4098 static int orinoco_ioctl_getscan(struct net_device *dev,
4099 struct iw_request_info *info,
4100 struct iw_point *srq,
4103 struct orinoco_private *priv = netdev_priv(dev);
4105 unsigned long flags;
4107 if (orinoco_lock(priv, &flags) != 0)
4110 /* If no results yet, ask to try again later */
4111 if (priv->scan_result == NULL) {
4112 if (priv->scan_inprogress)
4113 /* Important note : we don't want to block the caller
4114 * until results are ready for various reasons.
4115 * First, managing wait queues is complex and racy.
4116 * Second, we grab some rtnetlink lock before comming
4117 * here (in dev_ioctl()).
4118 * Third, we generate an Wireless Event, so the
4119 * caller can wait itself on that - Jean II */
4122 /* Client error, no scan results...
4123 * The caller need to restart the scan. */
4126 /* We have some results to push back to user space */
4128 /* Translate to WE format */
4129 int ret = orinoco_translate_scan(dev, extra,
4135 kfree(priv->scan_result);
4136 priv->scan_result = NULL;
4141 srq->flags = (__u16) priv->scan_mode;
4143 /* In any case, Scan results will be cleaned up in the
4144 * reset function and when exiting the driver.
4145 * The person triggering the scanning may never come to
4146 * pick the results, so we need to do it in those places.
4149 #ifdef SCAN_SINGLE_READ
4150 /* If you enable this option, only one client (the first
4151 * one) will be able to read the result (and only one
4152 * time). If there is multiple concurent clients that
4153 * want to read scan results, this behavior is not
4154 * advisable - Jean II */
4155 kfree(priv->scan_result);
4156 priv->scan_result = NULL;
4157 #endif /* SCAN_SINGLE_READ */
4158 /* Here, if too much time has elapsed since last scan,
4159 * we may want to clean up scan results... - Jean II */
4162 /* Scan is no longer in progress */
4163 priv->scan_inprogress = 0;
4166 orinoco_unlock(priv, &flags);
4170 /* Commit handler, called after set operations */
4171 static int orinoco_ioctl_commit(struct net_device *dev,
4172 struct iw_request_info *info,
4176 struct orinoco_private *priv = netdev_priv(dev);
4177 struct hermes *hw = &priv->hw;
4178 unsigned long flags;
4184 if (priv->broken_disableport) {
4189 if (orinoco_lock(priv, &flags) != 0)
4192 err = hermes_disable_port(hw, 0);
4194 printk(KERN_WARNING "%s: Unable to disable port "
4195 "while reconfiguring card\n", dev->name);
4196 priv->broken_disableport = 1;
4200 err = __orinoco_program_rids(dev);
4202 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4207 err = hermes_enable_port(hw, 0);
4209 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4216 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4217 schedule_work(&priv->reset_work);
4221 orinoco_unlock(priv, &flags);
4225 static const struct iw_priv_args orinoco_privtab[] = {
4226 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4227 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4228 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4230 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4232 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4233 0, "set_preamble" },
4234 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4236 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4237 0, "set_ibssport" },
4238 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4240 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4246 * Structures to export the Wireless Handlers
4249 static const iw_handler orinoco_handler[] = {
4250 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4251 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4252 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4253 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4254 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4255 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4256 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4257 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4258 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4259 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4260 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4261 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4262 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4263 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4264 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4265 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4266 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4267 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4268 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4269 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4270 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4271 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4272 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4273 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4274 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4275 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4276 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4277 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4278 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4279 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4280 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4281 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4286 Added typecasting since we no longer use iwreq_data -- Moustafa
4288 static const iw_handler orinoco_private_handler[] = {
4289 [0] = (iw_handler) orinoco_ioctl_reset,
4290 [1] = (iw_handler) orinoco_ioctl_reset,
4291 [2] = (iw_handler) orinoco_ioctl_setport3,
4292 [3] = (iw_handler) orinoco_ioctl_getport3,
4293 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4294 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4295 [6] = (iw_handler) orinoco_ioctl_setibssport,
4296 [7] = (iw_handler) orinoco_ioctl_getibssport,
4297 [9] = (iw_handler) orinoco_ioctl_getrid,
4300 static const struct iw_handler_def orinoco_handler_def = {
4301 .num_standard = ARRAY_SIZE(orinoco_handler),
4302 .num_private = ARRAY_SIZE(orinoco_private_handler),
4303 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4304 .standard = orinoco_handler,
4305 .private = orinoco_private_handler,
4306 .private_args = orinoco_privtab,
4307 .get_wireless_stats = orinoco_get_wireless_stats,
4310 static void orinoco_get_drvinfo(struct net_device *dev,
4311 struct ethtool_drvinfo *info)
4313 struct orinoco_private *priv = netdev_priv(dev);
4315 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4316 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4317 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4318 if (dev->class_dev.dev)
4319 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4320 sizeof(info->bus_info) - 1);
4322 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4323 "PCMCIA %p", priv->hw.iobase);
4326 static struct ethtool_ops orinoco_ethtool_ops = {
4327 .get_drvinfo = orinoco_get_drvinfo,
4328 .get_link = ethtool_op_get_link,
4331 /********************************************************************/
4332 /* Module initialization */
4333 /********************************************************************/
4335 EXPORT_SYMBOL(alloc_orinocodev);
4336 EXPORT_SYMBOL(free_orinocodev);
4338 EXPORT_SYMBOL(__orinoco_up);
4339 EXPORT_SYMBOL(__orinoco_down);
4340 EXPORT_SYMBOL(orinoco_reinit_firmware);
4342 EXPORT_SYMBOL(orinoco_interrupt);
4344 /* Can't be declared "const" or the whole __initdata section will
4346 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4347 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4348 "Pavel Roskin <proski@gnu.org>, et al)";
4350 static int __init init_orinoco(void)
4352 printk(KERN_DEBUG "%s\n", version);
4356 static void __exit exit_orinoco(void)
4360 module_init(init_orinoco);
4361 module_exit(exit_orinoco);