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;
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 TRACE_ENTER(dev->name);
461 if (! netif_running(dev)) {
462 printk(KERN_ERR "%s: Tx on stopped device!\n",
464 TRACE_EXIT(dev->name);
468 if (netif_queue_stopped(dev)) {
469 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
471 TRACE_EXIT(dev->name);
475 if (orinoco_lock(priv, &flags) != 0) {
476 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
478 TRACE_EXIT(dev->name);
482 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
483 /* Oops, the firmware hasn't established a connection,
484 silently drop the packet (this seems to be the
487 orinoco_unlock(priv, &flags);
489 TRACE_EXIT(dev->name);
493 /* Length of the packet body */
494 /* FIXME: what if the skb is smaller than this? */
495 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
496 skb = skb_padto(skb, len);
501 eh = (struct ethhdr *)skb->data;
503 memset(&desc, 0, sizeof(desc));
504 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
505 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
508 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
509 "to BAP\n", dev->name, err);
514 /* Clear the 802.11 header and data length fields - some
515 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
516 * if this isn't done. */
517 hermes_clear_words(hw, HERMES_DATA0,
518 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
520 /* Encapsulate Ethernet-II frames */
521 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
522 struct header_struct hdr;
524 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
525 p = skb->data + ETH_HLEN;
528 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
529 memcpy(hdr.src, eh->h_source, ETH_ALEN);
530 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
533 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
535 hdr.ethertype = eh->h_proto;
536 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
537 txfid, HERMES_802_3_OFFSET);
540 printk(KERN_ERR "%s: Error %d writing packet "
541 "header to BAP\n", dev->name, err);
545 } else { /* IEEE 802.3 frame */
546 data_len = len + ETH_HLEN;
547 data_off = HERMES_802_3_OFFSET;
551 /* Round up for odd length packets */
552 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
555 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
561 /* Finally, we actually initiate the send */
562 netif_stop_queue(dev);
564 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
567 netif_start_queue(dev);
569 printk(KERN_ERR "%s: Error %d transmitting packet\n",
575 dev->trans_start = jiffies;
576 stats->tx_bytes += data_off + data_len;
578 orinoco_unlock(priv, &flags);
582 TRACE_EXIT(dev->name);
586 TRACE_EXIT(dev->name);
588 orinoco_unlock(priv, &flags);
592 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
594 struct orinoco_private *priv = netdev_priv(dev);
595 u16 fid = hermes_read_regn(hw, ALLOCFID);
597 if (fid != priv->txfid) {
598 if (fid != DUMMY_FID)
599 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
604 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
607 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
609 struct orinoco_private *priv = netdev_priv(dev);
610 struct net_device_stats *stats = &priv->stats;
614 netif_wake_queue(dev);
616 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
619 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
621 struct orinoco_private *priv = netdev_priv(dev);
622 struct net_device_stats *stats = &priv->stats;
623 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
625 struct hermes_tx_descriptor_802_11 hdr;
628 if (fid == DUMMY_FID)
629 return; /* Nothing's really happened */
631 /* Read part of the frame header - we need status and addr1 */
632 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
633 offsetof(struct hermes_tx_descriptor_802_11,
637 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
641 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
642 "(FID=%04X error %d)\n",
643 dev->name, fid, err);
647 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
650 /* We produce a TXDROP event only for retry or lifetime
651 * exceeded, because that's the only status that really mean
652 * that this particular node went away.
653 * Other errors means that *we* screwed up. - Jean II */
654 status = le16_to_cpu(hdr.status);
655 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
656 union iwreq_data wrqu;
658 /* Copy 802.11 dest address.
659 * We use the 802.11 header because the frame may
660 * not be 802.3 or may be mangled...
661 * In Ad-Hoc mode, it will be the node address.
662 * In managed mode, it will be most likely the AP addr
663 * User space will figure out how to convert it to
664 * whatever it needs (IP address or else).
666 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
667 wrqu.addr.sa_family = ARPHRD_ETHER;
669 /* Send event to user space */
670 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
673 netif_wake_queue(dev);
676 static void orinoco_tx_timeout(struct net_device *dev)
678 struct orinoco_private *priv = netdev_priv(dev);
679 struct net_device_stats *stats = &priv->stats;
680 struct hermes *hw = &priv->hw;
682 printk(KERN_WARNING "%s: Tx timeout! "
683 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
684 dev->name, hermes_read_regn(hw, ALLOCFID),
685 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
689 schedule_work(&priv->reset_work);
692 /********************************************************************/
693 /* Rx path (data frames) */
694 /********************************************************************/
696 /* Does the frame have a SNAP header indicating it should be
697 * de-encapsulated to Ethernet-II? */
698 static inline int is_ethersnap(void *_hdr)
702 /* We de-encapsulate all packets which, a) have SNAP headers
703 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
704 * and where b) the OUI of the SNAP header is 00:00:00 or
705 * 00:00:f8 - we need both because different APs appear to use
706 * different OUIs for some reason */
707 return (memcmp(hdr, &encaps_hdr, 5) == 0)
708 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
711 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
712 int level, int noise)
714 struct iw_quality wstats;
715 wstats.level = level - 0x95;
716 wstats.noise = noise - 0x95;
717 wstats.qual = (level > noise) ? (level - noise) : 0;
719 /* Update spy records */
720 wireless_spy_update(dev, mac, &wstats);
723 static void orinoco_stat_gather(struct net_device *dev,
725 struct hermes_rx_descriptor *desc)
727 struct orinoco_private *priv = netdev_priv(dev);
729 /* Using spy support with lots of Rx packets, like in an
730 * infrastructure (AP), will really slow down everything, because
731 * the MAC address must be compared to each entry of the spy list.
732 * If the user really asks for it (set some address in the
733 * spy list), we do it, but he will pay the price.
734 * Note that to get here, you need both WIRELESS_SPY
735 * compiled in AND some addresses in the list !!!
737 /* Note : gcc will optimise the whole section away if
738 * WIRELESS_SPY is not defined... - Jean II */
739 if (SPY_NUMBER(priv)) {
740 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
741 desc->signal, desc->silence);
746 * orinoco_rx_monitor - handle received monitor frames.
751 * desc rx descriptor of the frame
753 * Call context: interrupt
755 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
756 struct hermes_rx_descriptor *desc)
758 u32 hdrlen = 30; /* return full header by default */
764 struct orinoco_private *priv = netdev_priv(dev);
765 struct net_device_stats *stats = &priv->stats;
766 hermes_t *hw = &priv->hw;
768 len = le16_to_cpu(desc->data_len);
770 /* Determine the size of the header and the data */
771 fc = le16_to_cpu(desc->frame_ctl);
772 switch (fc & IEEE80211_FCTL_FTYPE) {
773 case IEEE80211_FTYPE_DATA:
774 if ((fc & IEEE80211_FCTL_TODS)
775 && (fc & IEEE80211_FCTL_FROMDS))
781 case IEEE80211_FTYPE_MGMT:
785 case IEEE80211_FTYPE_CTL:
786 switch (fc & IEEE80211_FCTL_STYPE) {
787 case IEEE80211_STYPE_PSPOLL:
788 case IEEE80211_STYPE_RTS:
789 case IEEE80211_STYPE_CFEND:
790 case IEEE80211_STYPE_CFENDACK:
793 case IEEE80211_STYPE_CTS:
794 case IEEE80211_STYPE_ACK:
800 /* Unknown frame type */
804 /* sanity check the length */
805 if (datalen > IEEE80211_DATA_LEN + 12) {
806 printk(KERN_DEBUG "%s: oversized monitor frame, "
807 "data length = %d\n", dev->name, datalen);
809 stats->rx_length_errors++;
813 skb = dev_alloc_skb(hdrlen + datalen);
815 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
821 /* Copy the 802.11 header to the skb */
822 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
823 skb->mac.raw = skb->data;
825 /* If any, copy the data from the card to the skb */
827 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
828 ALIGN(datalen, 2), rxfid,
829 HERMES_802_2_OFFSET);
831 printk(KERN_ERR "%s: error %d reading monitor frame\n",
838 skb->ip_summed = CHECKSUM_NONE;
839 skb->pkt_type = PACKET_OTHERHOST;
840 skb->protocol = __constant_htons(ETH_P_802_2);
842 dev->last_rx = jiffies;
844 stats->rx_bytes += skb->len;
850 dev_kfree_skb_irq(skb);
856 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
858 struct orinoco_private *priv = netdev_priv(dev);
859 struct net_device_stats *stats = &priv->stats;
860 struct iw_statistics *wstats = &priv->wstats;
861 struct sk_buff *skb = NULL;
862 u16 rxfid, status, fc;
864 struct hermes_rx_descriptor desc;
868 rxfid = hermes_read_regn(hw, RXFID);
870 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
873 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
874 "Frame dropped.\n", dev->name, err);
878 status = le16_to_cpu(desc.status);
880 if (status & HERMES_RXSTAT_BADCRC) {
881 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
883 stats->rx_crc_errors++;
887 /* Handle frames in monitor mode */
888 if (priv->iw_mode == IW_MODE_MONITOR) {
889 orinoco_rx_monitor(dev, rxfid, &desc);
893 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
894 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
896 wstats->discard.code++;
900 length = le16_to_cpu(desc.data_len);
901 fc = le16_to_cpu(desc.frame_ctl);
904 if (length < 3) { /* No for even an 802.2 LLC header */
905 /* At least on Symbol firmware with PCF we get quite a
906 lot of these legitimately - Poll frames with no
910 if (length > IEEE80211_DATA_LEN) {
911 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
913 stats->rx_length_errors++;
917 /* We need space for the packet data itself, plus an ethernet
918 header, plus 2 bytes so we can align the IP header on a
919 32bit boundary, plus 1 byte so we can read in odd length
920 packets from the card, which has an IO granularity of 16
922 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
924 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
929 /* We'll prepend the header, so reserve space for it. The worst
930 case is no decapsulation, when 802.3 header is prepended and
931 nothing is removed. 2 is for aligning the IP header. */
932 skb_reserve(skb, ETH_HLEN + 2);
934 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
935 ALIGN(length, 2), rxfid,
936 HERMES_802_2_OFFSET);
938 printk(KERN_ERR "%s: error %d reading frame. "
939 "Frame dropped.\n", dev->name, err);
943 /* Handle decapsulation
944 * In most cases, the firmware tell us about SNAP frames.
945 * For some reason, the SNAP frames sent by LinkSys APs
946 * are not properly recognised by most firmwares.
947 * So, check ourselves */
948 if (length >= ENCAPS_OVERHEAD &&
949 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
950 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
951 is_ethersnap(skb->data))) {
952 /* These indicate a SNAP within 802.2 LLC within
953 802.11 frame which we'll need to de-encapsulate to
954 the original EthernetII frame. */
955 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
957 /* 802.3 frame - prepend 802.3 header as is */
958 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
959 hdr->h_proto = htons(length);
961 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
962 if (fc & IEEE80211_FCTL_FROMDS)
963 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
965 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
967 dev->last_rx = jiffies;
969 skb->protocol = eth_type_trans(skb, dev);
970 skb->ip_summed = CHECKSUM_NONE;
971 if (fc & IEEE80211_FCTL_TODS)
972 skb->pkt_type = PACKET_OTHERHOST;
974 /* Process the wireless stats if needed */
975 orinoco_stat_gather(dev, skb, &desc);
977 /* Pass the packet to the networking stack */
980 stats->rx_bytes += length;
985 dev_kfree_skb_irq(skb);
991 /********************************************************************/
992 /* Rx path (info frames) */
993 /********************************************************************/
995 static void print_linkstatus(struct net_device *dev, u16 status)
999 if (suppress_linkstatus)
1003 case HERMES_LINKSTATUS_NOT_CONNECTED:
1004 s = "Not Connected";
1006 case HERMES_LINKSTATUS_CONNECTED:
1009 case HERMES_LINKSTATUS_DISCONNECTED:
1012 case HERMES_LINKSTATUS_AP_CHANGE:
1015 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1016 s = "AP Out of Range";
1018 case HERMES_LINKSTATUS_AP_IN_RANGE:
1021 case HERMES_LINKSTATUS_ASSOC_FAILED:
1022 s = "Association Failed";
1028 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1029 dev->name, s, status);
1032 /* Search scan results for requested BSSID, join it if found */
1033 static void orinoco_join_ap(struct net_device *dev)
1035 struct orinoco_private *priv = netdev_priv(dev);
1036 struct hermes *hw = &priv->hw;
1038 unsigned long flags;
1042 } __attribute__ ((packed)) req;
1043 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1044 struct prism2_scan_apinfo *atom = NULL;
1050 /* Allocate buffer for scan results */
1051 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1055 if (orinoco_lock(priv, &flags) != 0)
1058 /* Sanity checks in case user changed something in the meantime */
1059 if (! priv->bssid_fixed)
1062 if (strlen(priv->desired_essid) == 0)
1065 /* Read scan results from the firmware */
1066 err = hermes_read_ltv(hw, USER_BAP,
1067 HERMES_RID_SCANRESULTSTABLE,
1068 MAX_SCAN_LEN, &len, buf);
1070 printk(KERN_ERR "%s: Cannot read scan results\n",
1075 len = HERMES_RECLEN_TO_BYTES(len);
1077 /* Go through the scan results looking for the channel of the AP
1078 * we were requested to join */
1079 for (; offset + atom_len <= len; offset += atom_len) {
1080 atom = (struct prism2_scan_apinfo *) (buf + offset);
1081 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1088 DEBUG(1, "%s: Requested AP not found in scan results\n",
1093 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1094 req.channel = atom->channel; /* both are little-endian */
1095 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1098 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1101 orinoco_unlock(priv, &flags);
1107 /* Send new BSSID to userspace */
1108 static void orinoco_send_wevents(struct net_device *dev)
1110 struct orinoco_private *priv = netdev_priv(dev);
1111 struct hermes *hw = &priv->hw;
1112 union iwreq_data wrqu;
1114 unsigned long flags;
1116 if (orinoco_lock(priv, &flags) != 0)
1119 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1120 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1124 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1126 /* Send event to user space */
1127 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1130 orinoco_unlock(priv, &flags);
1133 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1135 struct orinoco_private *priv = netdev_priv(dev);
1140 } __attribute__ ((packed)) info;
1144 /* This is an answer to an INQUIRE command that we did earlier,
1145 * or an information "event" generated by the card
1146 * The controller return to us a pseudo frame containing
1147 * the information in question - Jean II */
1148 infofid = hermes_read_regn(hw, INFOFID);
1150 /* Read the info frame header - don't try too hard */
1151 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1154 printk(KERN_ERR "%s: error %d reading info frame. "
1155 "Frame dropped.\n", dev->name, err);
1159 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1160 type = le16_to_cpu(info.type);
1163 case HERMES_INQ_TALLIES: {
1164 struct hermes_tallies_frame tallies;
1165 struct iw_statistics *wstats = &priv->wstats;
1167 if (len > sizeof(tallies)) {
1168 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1170 len = sizeof(tallies);
1173 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1174 infofid, sizeof(info));
1178 /* Increment our various counters */
1179 /* wstats->discard.nwid - no wrong BSSID stuff */
1180 wstats->discard.code +=
1181 le16_to_cpu(tallies.RxWEPUndecryptable);
1182 if (len == sizeof(tallies))
1183 wstats->discard.code +=
1184 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1185 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1186 wstats->discard.misc +=
1187 le16_to_cpu(tallies.TxDiscardsWrongSA);
1188 wstats->discard.fragment +=
1189 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1190 wstats->discard.retries +=
1191 le16_to_cpu(tallies.TxRetryLimitExceeded);
1192 /* wstats->miss.beacon - no match */
1195 case HERMES_INQ_LINKSTATUS: {
1196 struct hermes_linkstatus linkstatus;
1200 if (priv->iw_mode == IW_MODE_MONITOR)
1203 if (len != sizeof(linkstatus)) {
1204 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1209 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1210 infofid, sizeof(info));
1213 newstatus = le16_to_cpu(linkstatus.linkstatus);
1215 /* Symbol firmware uses "out of range" to signal that
1216 * the hostscan frame can be requested. */
1217 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1218 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1219 priv->has_hostscan && priv->scan_inprogress) {
1220 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1224 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1225 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1226 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1229 netif_carrier_on(dev);
1230 else if (!ignore_disconnect)
1231 netif_carrier_off(dev);
1233 if (newstatus != priv->last_linkstatus) {
1234 priv->last_linkstatus = newstatus;
1235 print_linkstatus(dev, newstatus);
1236 /* The info frame contains only one word which is the
1237 * status (see hermes.h). The status is pretty boring
1238 * in itself, that's why we export the new BSSID...
1240 schedule_work(&priv->wevent_work);
1244 case HERMES_INQ_SCAN:
1245 if (!priv->scan_inprogress && priv->bssid_fixed &&
1246 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1247 schedule_work(&priv->join_work);
1251 case HERMES_INQ_HOSTSCAN:
1252 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1253 /* Result of a scanning. Contains information about
1254 * cells in the vicinity - Jean II */
1255 union iwreq_data wrqu;
1260 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1265 /* We are a strict producer. If the previous scan results
1266 * have not been consumed, we just have to drop this
1267 * frame. We can't remove the previous results ourselves,
1268 * that would be *very* racy... Jean II */
1269 if (priv->scan_result != NULL) {
1270 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1274 /* Allocate buffer for results */
1275 buf = kmalloc(len, GFP_ATOMIC);
1277 /* No memory, so can't printk()... */
1280 /* Read scan data */
1281 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1282 infofid, sizeof(info));
1288 #ifdef ORINOCO_DEBUG
1291 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1292 for(i = 1; i < (len * 2); i++)
1293 printk(":%02X", buf[i]);
1296 #endif /* ORINOCO_DEBUG */
1298 /* Allow the clients to access the results */
1299 priv->scan_len = len;
1300 priv->scan_result = buf;
1302 /* Send an empty event to user space.
1303 * We don't send the received data on the event because
1304 * it would require us to do complex transcoding, and
1305 * we want to minimise the work done in the irq handler
1306 * Use a request to extract the data - Jean II */
1307 wrqu.data.length = 0;
1308 wrqu.data.flags = 0;
1309 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1312 case HERMES_INQ_SEC_STAT_AGERE:
1313 /* Security status (Agere specific) */
1314 /* Ignore this frame for now */
1315 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1319 printk(KERN_DEBUG "%s: Unknown information frame received: "
1320 "type 0x%04x, length %d\n", dev->name, type, len);
1321 /* We don't actually do anything about it */
1326 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1328 if (net_ratelimit())
1329 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1332 /********************************************************************/
1333 /* Internal hardware control routines */
1334 /********************************************************************/
1336 int __orinoco_up(struct net_device *dev)
1338 struct orinoco_private *priv = netdev_priv(dev);
1339 struct hermes *hw = &priv->hw;
1342 netif_carrier_off(dev); /* just to make sure */
1344 err = __orinoco_program_rids(dev);
1346 printk(KERN_ERR "%s: Error %d configuring card\n",
1351 /* Fire things up again */
1352 hermes_set_irqmask(hw, ORINOCO_INTEN);
1353 err = hermes_enable_port(hw, 0);
1355 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1360 netif_start_queue(dev);
1365 int __orinoco_down(struct net_device *dev)
1367 struct orinoco_private *priv = netdev_priv(dev);
1368 struct hermes *hw = &priv->hw;
1371 netif_stop_queue(dev);
1373 if (! priv->hw_unavailable) {
1374 if (! priv->broken_disableport) {
1375 err = hermes_disable_port(hw, 0);
1377 /* Some firmwares (e.g. Intersil 1.3.x) seem
1378 * to have problems disabling the port, oh
1380 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1382 priv->broken_disableport = 1;
1385 hermes_set_irqmask(hw, 0);
1386 hermes_write_regn(hw, EVACK, 0xffff);
1389 /* firmware will have to reassociate */
1390 netif_carrier_off(dev);
1391 priv->last_linkstatus = 0xffff;
1396 int orinoco_reinit_firmware(struct net_device *dev)
1398 struct orinoco_private *priv = netdev_priv(dev);
1399 struct hermes *hw = &priv->hw;
1402 err = hermes_init(hw);
1406 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1407 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1408 /* Try workaround for old Symbol firmware bug */
1409 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1410 "(old Symbol firmware?). Trying to work around... ",
1413 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1414 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1416 printk("failed!\n");
1424 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1426 hermes_t *hw = &priv->hw;
1429 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1430 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1431 priv->ndev->name, priv->bitratemode);
1435 switch (priv->firmware_type) {
1436 case FIRMWARE_TYPE_AGERE:
1437 err = hermes_write_wordrec(hw, USER_BAP,
1438 HERMES_RID_CNFTXRATECONTROL,
1439 bitrate_table[priv->bitratemode].agere_txratectrl);
1441 case FIRMWARE_TYPE_INTERSIL:
1442 case FIRMWARE_TYPE_SYMBOL:
1443 err = hermes_write_wordrec(hw, USER_BAP,
1444 HERMES_RID_CNFTXRATECONTROL,
1445 bitrate_table[priv->bitratemode].intersil_txratectrl);
1454 /* Set fixed AP address */
1455 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1459 hermes_t *hw = &priv->hw;
1461 switch (priv->firmware_type) {
1462 case FIRMWARE_TYPE_AGERE:
1465 case FIRMWARE_TYPE_INTERSIL:
1466 if (priv->bssid_fixed)
1471 err = hermes_write_wordrec(hw, USER_BAP,
1472 HERMES_RID_CNFROAMINGMODE,
1475 case FIRMWARE_TYPE_SYMBOL:
1476 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1477 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1478 &priv->desired_bssid);
1484 /* Change the WEP keys and/or the current keys. Can be called
1485 * either from __orinoco_hw_setup_wep() or directly from
1486 * orinoco_ioctl_setiwencode(). In the later case the association
1487 * with the AP is not broken (if the firmware can handle it),
1488 * which is needed for 802.1x implementations. */
1489 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1491 hermes_t *hw = &priv->hw;
1494 switch (priv->firmware_type) {
1495 case FIRMWARE_TYPE_AGERE:
1496 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1497 HERMES_RID_CNFWEPKEYS_AGERE,
1501 err = hermes_write_wordrec(hw, USER_BAP,
1502 HERMES_RID_CNFTXKEY_AGERE,
1507 case FIRMWARE_TYPE_INTERSIL:
1508 case FIRMWARE_TYPE_SYMBOL:
1513 /* Force uniform key length to work around firmware bugs */
1514 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1516 if (keylen > LARGE_KEY_SIZE) {
1517 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1518 priv->ndev->name, priv->tx_key, keylen);
1522 /* Write all 4 keys */
1523 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1524 err = hermes_write_ltv(hw, USER_BAP,
1525 HERMES_RID_CNFDEFAULTKEY0 + i,
1526 HERMES_BYTES_TO_RECLEN(keylen),
1527 priv->keys[i].data);
1532 /* Write the index of the key used in transmission */
1533 err = hermes_write_wordrec(hw, USER_BAP,
1534 HERMES_RID_CNFWEPDEFAULTKEYID,
1545 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1547 hermes_t *hw = &priv->hw;
1549 int master_wep_flag;
1553 __orinoco_hw_setup_wepkeys(priv);
1555 if (priv->wep_restrict)
1556 auth_flag = HERMES_AUTH_SHARED_KEY;
1558 auth_flag = HERMES_AUTH_OPEN;
1560 switch (priv->firmware_type) {
1561 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1563 /* Enable the shared-key authentication. */
1564 err = hermes_write_wordrec(hw, USER_BAP,
1565 HERMES_RID_CNFAUTHENTICATION_AGERE,
1568 err = hermes_write_wordrec(hw, USER_BAP,
1569 HERMES_RID_CNFWEPENABLED_AGERE,
1575 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1576 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1578 if (priv->wep_restrict ||
1579 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1580 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1581 HERMES_WEP_EXCL_UNENCRYPTED;
1583 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1585 err = hermes_write_wordrec(hw, USER_BAP,
1586 HERMES_RID_CNFAUTHENTICATION,
1591 master_wep_flag = 0;
1593 if (priv->iw_mode == IW_MODE_MONITOR)
1594 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1596 /* Master WEP setting : on/off */
1597 err = hermes_write_wordrec(hw, USER_BAP,
1598 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1609 static int __orinoco_program_rids(struct net_device *dev)
1611 struct orinoco_private *priv = netdev_priv(dev);
1612 hermes_t *hw = &priv->hw;
1614 struct hermes_idstring idbuf;
1616 /* Set the MAC address */
1617 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1618 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1620 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1625 /* Set up the link mode */
1626 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1629 printk(KERN_ERR "%s: Error %d setting port type\n",
1633 /* Set the channel/frequency */
1634 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1635 err = hermes_write_wordrec(hw, USER_BAP,
1636 HERMES_RID_CNFOWNCHANNEL,
1639 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1640 dev->name, err, priv->channel);
1645 if (priv->has_ibss) {
1648 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1649 printk(KERN_WARNING "%s: This firmware requires an "
1650 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1651 /* With wvlan_cs, in this case, we would crash.
1652 * hopefully, this driver will behave better...
1656 createibss = priv->createibss;
1659 err = hermes_write_wordrec(hw, USER_BAP,
1660 HERMES_RID_CNFCREATEIBSS,
1663 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1669 /* Set the desired BSSID */
1670 err = __orinoco_hw_set_wap(priv);
1672 printk(KERN_ERR "%s: Error %d setting AP address\n",
1676 /* Set the desired ESSID */
1677 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1678 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1679 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1680 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1681 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1684 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1688 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1689 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1692 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1697 /* Set the station name */
1698 idbuf.len = cpu_to_le16(strlen(priv->nick));
1699 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1700 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1701 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1704 printk(KERN_ERR "%s: Error %d setting nickname\n",
1709 /* Set AP density */
1710 if (priv->has_sensitivity) {
1711 err = hermes_write_wordrec(hw, USER_BAP,
1712 HERMES_RID_CNFSYSTEMSCALE,
1715 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1716 "Disabling sensitivity control\n",
1719 priv->has_sensitivity = 0;
1723 /* Set RTS threshold */
1724 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1727 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1732 /* Set fragmentation threshold or MWO robustness */
1734 err = hermes_write_wordrec(hw, USER_BAP,
1735 HERMES_RID_CNFMWOROBUST_AGERE,
1738 err = hermes_write_wordrec(hw, USER_BAP,
1739 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1742 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1748 err = __orinoco_hw_set_bitrate(priv);
1750 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1755 /* Set power management */
1757 err = hermes_write_wordrec(hw, USER_BAP,
1758 HERMES_RID_CNFPMENABLED,
1761 printk(KERN_ERR "%s: Error %d setting up PM\n",
1766 err = hermes_write_wordrec(hw, USER_BAP,
1767 HERMES_RID_CNFMULTICASTRECEIVE,
1770 printk(KERN_ERR "%s: Error %d setting up PM\n",
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFMAXSLEEPDURATION,
1778 printk(KERN_ERR "%s: Error %d setting up PM\n",
1782 err = hermes_write_wordrec(hw, USER_BAP,
1783 HERMES_RID_CNFPMHOLDOVERDURATION,
1786 printk(KERN_ERR "%s: Error %d setting up PM\n",
1792 /* Set preamble - only for Symbol so far... */
1793 if (priv->has_preamble) {
1794 err = hermes_write_wordrec(hw, USER_BAP,
1795 HERMES_RID_CNFPREAMBLE_SYMBOL,
1798 printk(KERN_ERR "%s: Error %d setting preamble\n",
1804 /* Set up encryption */
1805 if (priv->has_wep) {
1806 err = __orinoco_hw_setup_wep(priv);
1808 printk(KERN_ERR "%s: Error %d activating WEP\n",
1814 if (priv->iw_mode == IW_MODE_MONITOR) {
1815 /* Enable monitor mode */
1816 dev->type = ARPHRD_IEEE80211;
1817 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1818 HERMES_TEST_MONITOR, 0, NULL);
1820 /* Disable monitor mode */
1821 dev->type = ARPHRD_ETHER;
1822 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1823 HERMES_TEST_STOP, 0, NULL);
1828 /* Set promiscuity / multicast*/
1829 priv->promiscuous = 0;
1831 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1836 /* FIXME: return int? */
1838 __orinoco_set_multicast_list(struct net_device *dev)
1840 struct orinoco_private *priv = netdev_priv(dev);
1841 hermes_t *hw = &priv->hw;
1843 int promisc, mc_count;
1845 /* The Hermes doesn't seem to have an allmulti mode, so we go
1846 * into promiscuous mode and let the upper levels deal. */
1847 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1848 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1853 mc_count = dev->mc_count;
1856 if (promisc != priv->promiscuous) {
1857 err = hermes_write_wordrec(hw, USER_BAP,
1858 HERMES_RID_CNFPROMISCUOUSMODE,
1861 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1864 priv->promiscuous = promisc;
1867 if (! promisc && (mc_count || priv->mc_count) ) {
1868 struct dev_mc_list *p = dev->mc_list;
1869 struct hermes_multicast mclist;
1872 for (i = 0; i < mc_count; i++) {
1873 /* paranoia: is list shorter than mc_count? */
1875 /* paranoia: bad address size in list? */
1876 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1878 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1883 printk(KERN_WARNING "%s: Multicast list is "
1884 "longer than mc_count\n", dev->name);
1886 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1887 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1890 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1893 priv->mc_count = mc_count;
1896 /* Since we can set the promiscuous flag when it wasn't asked
1897 for, make sure the net_device knows about it. */
1898 if (priv->promiscuous)
1899 dev->flags |= IFF_PROMISC;
1901 dev->flags &= ~IFF_PROMISC;
1904 /* This must be called from user context, without locks held - use
1905 * schedule_work() */
1906 static void orinoco_reset(struct net_device *dev)
1908 struct orinoco_private *priv = netdev_priv(dev);
1909 struct hermes *hw = &priv->hw;
1911 unsigned long flags;
1913 if (orinoco_lock(priv, &flags) != 0)
1914 /* When the hardware becomes available again, whatever
1915 * detects that is responsible for re-initializing
1916 * it. So no need for anything further */
1919 netif_stop_queue(dev);
1921 /* Shut off interrupts. Depending on what state the hardware
1922 * is in, this might not work, but we'll try anyway */
1923 hermes_set_irqmask(hw, 0);
1924 hermes_write_regn(hw, EVACK, 0xffff);
1926 priv->hw_unavailable++;
1927 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1928 netif_carrier_off(dev);
1930 orinoco_unlock(priv, &flags);
1932 /* Scanning support: Cleanup of driver struct */
1933 kfree(priv->scan_result);
1934 priv->scan_result = NULL;
1935 priv->scan_inprogress = 0;
1937 if (priv->hard_reset) {
1938 err = (*priv->hard_reset)(priv);
1940 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1941 "performing hard reset\n", dev->name, err);
1946 err = orinoco_reinit_firmware(dev);
1948 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1953 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1955 priv->hw_unavailable--;
1957 /* priv->open or priv->hw_unavailable might have changed while
1958 * we dropped the lock */
1959 if (priv->open && (! priv->hw_unavailable)) {
1960 err = __orinoco_up(dev);
1962 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1965 dev->trans_start = jiffies;
1968 spin_unlock_irq(&priv->lock);
1972 hermes_set_irqmask(hw, 0);
1973 netif_device_detach(dev);
1974 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1977 /********************************************************************/
1978 /* Interrupt handler */
1979 /********************************************************************/
1981 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1983 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1986 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1988 /* This seems to happen a fair bit under load, but ignoring it
1989 seems to work fine...*/
1990 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1994 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1996 struct net_device *dev = (struct net_device *)dev_id;
1997 struct orinoco_private *priv = netdev_priv(dev);
1998 hermes_t *hw = &priv->hw;
1999 int count = MAX_IRQLOOPS_PER_IRQ;
2001 /* These are used to detect a runaway interrupt situation */
2002 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2003 * we panic and shut down the hardware */
2004 static int last_irq_jiffy = 0; /* jiffies value the last time
2006 static int loops_this_jiffy = 0;
2007 unsigned long flags;
2009 if (orinoco_lock(priv, &flags) != 0) {
2010 /* If hw is unavailable - we don't know if the irq was
2015 evstat = hermes_read_regn(hw, EVSTAT);
2016 events = evstat & hw->inten;
2018 orinoco_unlock(priv, &flags);
2022 if (jiffies != last_irq_jiffy)
2023 loops_this_jiffy = 0;
2024 last_irq_jiffy = jiffies;
2026 while (events && count--) {
2027 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2028 printk(KERN_WARNING "%s: IRQ handler is looping too "
2029 "much! Resetting.\n", dev->name);
2030 /* Disable interrupts for now */
2031 hermes_set_irqmask(hw, 0);
2032 schedule_work(&priv->reset_work);
2036 /* Check the card hasn't been removed */
2037 if (! hermes_present(hw)) {
2038 DEBUG(0, "orinoco_interrupt(): card removed\n");
2042 if (events & HERMES_EV_TICK)
2043 __orinoco_ev_tick(dev, hw);
2044 if (events & HERMES_EV_WTERR)
2045 __orinoco_ev_wterr(dev, hw);
2046 if (events & HERMES_EV_INFDROP)
2047 __orinoco_ev_infdrop(dev, hw);
2048 if (events & HERMES_EV_INFO)
2049 __orinoco_ev_info(dev, hw);
2050 if (events & HERMES_EV_RX)
2051 __orinoco_ev_rx(dev, hw);
2052 if (events & HERMES_EV_TXEXC)
2053 __orinoco_ev_txexc(dev, hw);
2054 if (events & HERMES_EV_TX)
2055 __orinoco_ev_tx(dev, hw);
2056 if (events & HERMES_EV_ALLOC)
2057 __orinoco_ev_alloc(dev, hw);
2059 hermes_write_regn(hw, EVACK, evstat);
2061 evstat = hermes_read_regn(hw, EVSTAT);
2062 events = evstat & hw->inten;
2065 orinoco_unlock(priv, &flags);
2069 /********************************************************************/
2070 /* Initialization */
2071 /********************************************************************/
2074 u16 id, variant, major, minor;
2075 } __attribute__ ((packed));
2077 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2079 if (nic_id->id < 0x8000)
2080 return FIRMWARE_TYPE_AGERE;
2081 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2082 return FIRMWARE_TYPE_SYMBOL;
2084 return FIRMWARE_TYPE_INTERSIL;
2087 /* Set priv->firmware type, determine firmware properties */
2088 static int determine_firmware(struct net_device *dev)
2090 struct orinoco_private *priv = netdev_priv(dev);
2091 hermes_t *hw = &priv->hw;
2093 struct comp_id nic_id, sta_id;
2094 unsigned int firmver;
2095 char tmp[SYMBOL_MAX_VER_LEN+1];
2097 /* Get the hardware version */
2098 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2100 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2105 le16_to_cpus(&nic_id.id);
2106 le16_to_cpus(&nic_id.variant);
2107 le16_to_cpus(&nic_id.major);
2108 le16_to_cpus(&nic_id.minor);
2109 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2110 dev->name, nic_id.id, nic_id.variant,
2111 nic_id.major, nic_id.minor);
2113 priv->firmware_type = determine_firmware_type(&nic_id);
2115 /* Get the firmware version */
2116 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2118 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2123 le16_to_cpus(&sta_id.id);
2124 le16_to_cpus(&sta_id.variant);
2125 le16_to_cpus(&sta_id.major);
2126 le16_to_cpus(&sta_id.minor);
2127 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2128 dev->name, sta_id.id, sta_id.variant,
2129 sta_id.major, sta_id.minor);
2131 switch (sta_id.id) {
2133 printk(KERN_ERR "%s: Primary firmware is active\n",
2137 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2140 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2141 case 0x21: /* Symbol Spectrum24 Trilogy */
2144 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2149 /* Default capabilities */
2150 priv->has_sensitivity = 1;
2152 priv->has_preamble = 0;
2153 priv->has_port3 = 1;
2156 priv->has_big_wep = 0;
2158 /* Determine capabilities from the firmware version */
2159 switch (priv->firmware_type) {
2160 case FIRMWARE_TYPE_AGERE:
2161 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2162 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2163 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2164 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2166 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2168 priv->has_ibss = (firmver >= 0x60006);
2169 priv->has_wep = (firmver >= 0x40020);
2170 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2171 Gold cards from the others? */
2172 priv->has_mwo = (firmver >= 0x60000);
2173 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2174 priv->ibss_port = 1;
2175 priv->has_hostscan = (firmver >= 0x8000a);
2176 priv->broken_monitor = (firmver >= 0x80000);
2178 /* Tested with Agere firmware :
2179 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2180 * Tested CableTron firmware : 4.32 => Anton */
2182 case FIRMWARE_TYPE_SYMBOL:
2183 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2184 /* Intel MAC : 00:02:B3:* */
2185 /* 3Com MAC : 00:50:DA:* */
2186 memset(tmp, 0, sizeof(tmp));
2187 /* Get the Symbol firmware version */
2188 err = hermes_read_ltv(hw, USER_BAP,
2189 HERMES_RID_SECONDARYVERSION_SYMBOL,
2190 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2193 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2198 /* The firmware revision is a string, the format is
2199 * something like : "V2.20-01".
2200 * Quick and dirty parsing... - Jean II
2202 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2203 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2206 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2209 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2212 priv->has_ibss = (firmver >= 0x20000);
2213 priv->has_wep = (firmver >= 0x15012);
2214 priv->has_big_wep = (firmver >= 0x20000);
2215 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2216 (firmver >= 0x29000 && firmver < 0x30000) ||
2218 priv->has_preamble = (firmver >= 0x20000);
2219 priv->ibss_port = 4;
2220 priv->broken_disableport = (firmver == 0x25013) ||
2221 (firmver >= 0x30000 && firmver <= 0x31000);
2222 priv->has_hostscan = (firmver >= 0x31001) ||
2223 (firmver >= 0x29057 && firmver < 0x30000);
2224 /* Tested with Intel firmware : 0x20015 => Jean II */
2225 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2227 case FIRMWARE_TYPE_INTERSIL:
2228 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2229 * Samsung, Compaq 100/200 and Proxim are slightly
2230 * different and less well tested */
2231 /* D-Link MAC : 00:40:05:* */
2232 /* Addtron MAC : 00:90:D1:* */
2233 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2234 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2237 firmver = ((unsigned long)sta_id.major << 16) |
2238 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2240 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2241 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2242 priv->has_pm = (firmver >= 0x000700);
2243 priv->has_hostscan = (firmver >= 0x010301);
2245 if (firmver >= 0x000800)
2246 priv->ibss_port = 0;
2248 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2249 "than v0.8.x - several features not supported\n",
2251 priv->ibss_port = 1;
2255 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2261 static int orinoco_init(struct net_device *dev)
2263 struct orinoco_private *priv = netdev_priv(dev);
2264 hermes_t *hw = &priv->hw;
2266 struct hermes_idstring nickbuf;
2270 TRACE_ENTER(dev->name);
2272 /* No need to lock, the hw_unavailable flag is already set in
2273 * alloc_orinocodev() */
2274 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2276 /* Initialize the firmware */
2277 err = orinoco_reinit_firmware(dev);
2279 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2284 err = determine_firmware(dev);
2286 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2291 if (priv->has_port3)
2292 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2294 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2296 if (priv->has_wep) {
2297 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2298 if (priv->has_big_wep)
2299 printk("104-bit key\n");
2301 printk("40-bit key\n");
2304 /* Get the MAC address */
2305 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2306 ETH_ALEN, NULL, dev->dev_addr);
2308 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2313 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2314 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2315 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2318 /* Get the station name */
2319 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2320 sizeof(nickbuf), &reclen, &nickbuf);
2322 printk(KERN_ERR "%s: failed to read station name\n",
2327 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2329 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2330 memcpy(priv->nick, &nickbuf.val, len);
2331 priv->nick[len] = '\0';
2333 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2335 /* Get allowed channels */
2336 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2337 &priv->channel_mask);
2339 printk(KERN_ERR "%s: failed to read channel list!\n",
2344 /* Get initial AP density */
2345 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2347 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2348 priv->has_sensitivity = 0;
2351 /* Get initial RTS threshold */
2352 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2355 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2360 /* Get initial fragmentation settings */
2362 err = hermes_read_wordrec(hw, USER_BAP,
2363 HERMES_RID_CNFMWOROBUST_AGERE,
2366 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2367 &priv->frag_thresh);
2369 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2374 /* Power management setup */
2378 err = hermes_read_wordrec(hw, USER_BAP,
2379 HERMES_RID_CNFMAXSLEEPDURATION,
2382 printk(KERN_ERR "%s: failed to read power management period!\n",
2386 err = hermes_read_wordrec(hw, USER_BAP,
2387 HERMES_RID_CNFPMHOLDOVERDURATION,
2390 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2396 /* Preamble setup */
2397 if (priv->has_preamble) {
2398 err = hermes_read_wordrec(hw, USER_BAP,
2399 HERMES_RID_CNFPREAMBLE_SYMBOL,
2405 /* Set up the default configuration */
2406 priv->iw_mode = IW_MODE_INFRA;
2407 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2408 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2409 set_port_type(priv);
2410 priv->channel = 0; /* use firmware default */
2412 priv->promiscuous = 0;
2416 /* Make the hardware available, as long as it hasn't been
2417 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2418 spin_lock_irq(&priv->lock);
2419 priv->hw_unavailable--;
2420 spin_unlock_irq(&priv->lock);
2422 printk(KERN_DEBUG "%s: ready\n", dev->name);
2425 TRACE_EXIT(dev->name);
2429 struct net_device *alloc_orinocodev(int sizeof_card,
2430 int (*hard_reset)(struct orinoco_private *))
2432 struct net_device *dev;
2433 struct orinoco_private *priv;
2435 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2438 priv = netdev_priv(dev);
2441 priv->card = (void *)((unsigned long)priv
2442 + sizeof(struct orinoco_private));
2446 /* Setup / override net_device fields */
2447 dev->init = orinoco_init;
2448 dev->hard_start_xmit = orinoco_xmit;
2449 dev->tx_timeout = orinoco_tx_timeout;
2450 dev->watchdog_timeo = HZ; /* 1 second timeout */
2451 dev->get_stats = orinoco_get_stats;
2452 dev->ethtool_ops = &orinoco_ethtool_ops;
2453 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2455 priv->wireless_data.spy_data = &priv->spy_data;
2456 dev->wireless_data = &priv->wireless_data;
2458 dev->change_mtu = orinoco_change_mtu;
2459 dev->set_multicast_list = orinoco_set_multicast_list;
2460 /* we use the default eth_mac_addr for setting the MAC addr */
2462 /* Set up default callbacks */
2463 dev->open = orinoco_open;
2464 dev->stop = orinoco_stop;
2465 priv->hard_reset = hard_reset;
2467 spin_lock_init(&priv->lock);
2469 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2470 * before anything else touches the
2472 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2473 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2474 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2476 netif_carrier_off(dev);
2477 priv->last_linkstatus = 0xffff;
2483 void free_orinocodev(struct net_device *dev)
2485 struct orinoco_private *priv = netdev_priv(dev);
2487 kfree(priv->scan_result);
2491 /********************************************************************/
2492 /* Wireless extensions */
2493 /********************************************************************/
2495 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2496 char buf[IW_ESSID_MAX_SIZE+1])
2498 hermes_t *hw = &priv->hw;
2500 struct hermes_idstring essidbuf;
2501 char *p = (char *)(&essidbuf.val);
2503 unsigned long flags;
2505 if (orinoco_lock(priv, &flags) != 0)
2508 if (strlen(priv->desired_essid) > 0) {
2509 /* We read the desired SSID from the hardware rather
2510 than from priv->desired_essid, just in case the
2511 firmware is allowed to change it on us. I'm not
2513 /* My guess is that the OWNSSID should always be whatever
2514 * we set to the card, whereas CURRENT_SSID is the one that
2515 * may change... - Jean II */
2520 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2521 HERMES_RID_CNFDESIREDSSID;
2523 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2530 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2531 sizeof(essidbuf), NULL, &essidbuf);
2536 len = le16_to_cpu(essidbuf.len);
2537 BUG_ON(len > IW_ESSID_MAX_SIZE);
2539 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2540 memcpy(buf, p, len);
2544 orinoco_unlock(priv, &flags);
2549 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2552 hermes_t *hw = &priv->hw;
2556 unsigned long flags;
2558 if (orinoco_lock(priv, &flags) != 0)
2561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2565 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2571 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2572 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2573 priv->ndev->name, channel);
2578 freq = channel_frequency[channel-1] * 100000;
2581 orinoco_unlock(priv, &flags);
2585 return err ? err : freq;
2588 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2589 int *numrates, s32 *rates, int max)
2591 hermes_t *hw = &priv->hw;
2592 struct hermes_idstring list;
2593 unsigned char *p = (unsigned char *)&list.val;
2597 unsigned long flags;
2599 if (orinoco_lock(priv, &flags) != 0)
2602 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2603 sizeof(list), NULL, &list);
2604 orinoco_unlock(priv, &flags);
2609 num = le16_to_cpu(list.len);
2611 num = min(num, max);
2613 for (i = 0; i < num; i++) {
2614 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2620 static int orinoco_ioctl_getname(struct net_device *dev,
2621 struct iw_request_info *info,
2625 struct orinoco_private *priv = netdev_priv(dev);
2629 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2631 if (!err && (numrates > 2))
2632 strcpy(name, "IEEE 802.11b");
2634 strcpy(name, "IEEE 802.11-DS");
2639 static int orinoco_ioctl_setwap(struct net_device *dev,
2640 struct iw_request_info *info,
2641 struct sockaddr *ap_addr,
2644 struct orinoco_private *priv = netdev_priv(dev);
2645 int err = -EINPROGRESS; /* Call commit handler */
2646 unsigned long flags;
2647 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2648 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2650 if (orinoco_lock(priv, &flags) != 0)
2653 /* Enable automatic roaming - no sanity checks are needed */
2654 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2655 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2656 priv->bssid_fixed = 0;
2657 memset(priv->desired_bssid, 0, ETH_ALEN);
2659 /* "off" means keep existing connection */
2660 if (ap_addr->sa_data[0] == 0) {
2661 __orinoco_hw_set_wap(priv);
2667 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2668 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2669 "support manual roaming\n",
2675 if (priv->iw_mode != IW_MODE_INFRA) {
2676 printk(KERN_WARNING "%s: Manual roaming supported only in "
2677 "managed mode\n", dev->name);
2682 /* Intersil firmware hangs without Desired ESSID */
2683 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2684 strlen(priv->desired_essid) == 0) {
2685 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2686 "manual roaming\n", dev->name);
2691 /* Finally, enable manual roaming */
2692 priv->bssid_fixed = 1;
2693 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2696 orinoco_unlock(priv, &flags);
2700 static int orinoco_ioctl_getwap(struct net_device *dev,
2701 struct iw_request_info *info,
2702 struct sockaddr *ap_addr,
2705 struct orinoco_private *priv = netdev_priv(dev);
2707 hermes_t *hw = &priv->hw;
2709 unsigned long flags;
2711 if (orinoco_lock(priv, &flags) != 0)
2714 ap_addr->sa_family = ARPHRD_ETHER;
2715 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2716 ETH_ALEN, NULL, ap_addr->sa_data);
2718 orinoco_unlock(priv, &flags);
2723 static int orinoco_ioctl_setmode(struct net_device *dev,
2724 struct iw_request_info *info,
2728 struct orinoco_private *priv = netdev_priv(dev);
2729 int err = -EINPROGRESS; /* Call commit handler */
2730 unsigned long flags;
2732 if (priv->iw_mode == *mode)
2735 if (orinoco_lock(priv, &flags) != 0)
2740 if (!priv->has_ibss && !priv->has_port3)
2747 case IW_MODE_MONITOR:
2748 if (priv->broken_monitor && !force_monitor) {
2749 printk(KERN_WARNING "%s: Monitor mode support is "
2750 "buggy in this firmware, not enabling\n",
2761 if (err == -EINPROGRESS) {
2762 priv->iw_mode = *mode;
2763 set_port_type(priv);
2766 orinoco_unlock(priv, &flags);
2771 static int orinoco_ioctl_getmode(struct net_device *dev,
2772 struct iw_request_info *info,
2776 struct orinoco_private *priv = netdev_priv(dev);
2778 *mode = priv->iw_mode;
2782 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2783 struct iw_request_info *info,
2784 struct iw_point *rrq,
2787 struct orinoco_private *priv = netdev_priv(dev);
2789 struct iw_range *range = (struct iw_range *) extra;
2793 TRACE_ENTER(dev->name);
2795 rrq->length = sizeof(struct iw_range);
2796 memset(range, 0, sizeof(struct iw_range));
2798 range->we_version_compiled = WIRELESS_EXT;
2799 range->we_version_source = 14;
2801 /* Set available channels/frequencies */
2802 range->num_channels = NUM_CHANNELS;
2804 for (i = 0; i < NUM_CHANNELS; i++) {
2805 if (priv->channel_mask & (1 << i)) {
2806 range->freq[k].i = i + 1;
2807 range->freq[k].m = channel_frequency[i] * 100000;
2808 range->freq[k].e = 1;
2812 if (k >= IW_MAX_FREQUENCIES)
2815 range->num_frequency = k;
2816 range->sensitivity = 3;
2818 if (priv->has_wep) {
2819 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2820 range->encoding_size[0] = SMALL_KEY_SIZE;
2821 range->num_encoding_sizes = 1;
2823 if (priv->has_big_wep) {
2824 range->encoding_size[1] = LARGE_KEY_SIZE;
2825 range->num_encoding_sizes = 2;
2829 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2830 /* Quality stats meaningless in ad-hoc mode */
2832 range->max_qual.qual = 0x8b - 0x2f;
2833 range->max_qual.level = 0x2f - 0x95 - 1;
2834 range->max_qual.noise = 0x2f - 0x95 - 1;
2835 /* Need to get better values */
2836 range->avg_qual.qual = 0x24;
2837 range->avg_qual.level = 0xC2;
2838 range->avg_qual.noise = 0x9E;
2841 err = orinoco_hw_get_bitratelist(priv, &numrates,
2842 range->bitrate, IW_MAX_BITRATES);
2845 range->num_bitrates = numrates;
2847 /* Set an indication of the max TCP throughput in bit/s that we can
2848 * expect using this interface. May be use for QoS stuff...
2851 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2853 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2856 range->max_rts = 2347;
2857 range->min_frag = 256;
2858 range->max_frag = 2346;
2861 range->max_pmp = 65535000;
2863 range->max_pmt = 65535 * 1000; /* ??? */
2864 range->pmp_flags = IW_POWER_PERIOD;
2865 range->pmt_flags = IW_POWER_TIMEOUT;
2866 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2868 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2869 range->retry_flags = IW_RETRY_LIMIT;
2870 range->r_time_flags = IW_RETRY_LIFETIME;
2871 range->min_retry = 0;
2872 range->max_retry = 65535; /* ??? */
2873 range->min_r_time = 0;
2874 range->max_r_time = 65535 * 1000; /* ??? */
2876 /* Event capability (kernel) */
2877 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2878 /* Event capability (driver) */
2879 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2880 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2881 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2882 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2884 TRACE_EXIT(dev->name);
2889 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2890 struct iw_request_info *info,
2891 struct iw_point *erq,
2894 struct orinoco_private *priv = netdev_priv(dev);
2895 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2896 int setindex = priv->tx_key;
2897 int enable = priv->wep_on;
2898 int restricted = priv->wep_restrict;
2900 int err = -EINPROGRESS; /* Call commit handler */
2901 unsigned long flags;
2903 if (! priv->has_wep)
2907 /* We actually have a key to set - check its length */
2908 if (erq->length > LARGE_KEY_SIZE)
2911 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2915 if (orinoco_lock(priv, &flags) != 0)
2919 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2920 index = priv->tx_key;
2922 /* Adjust key length to a supported value */
2923 if (erq->length > SMALL_KEY_SIZE) {
2924 xlen = LARGE_KEY_SIZE;
2925 } else if (erq->length > 0) {
2926 xlen = SMALL_KEY_SIZE;
2930 /* Switch on WEP if off */
2931 if ((!enable) && (xlen > 0)) {
2936 /* Important note : if the user do "iwconfig eth0 enc off",
2937 * we will arrive there with an index of -1. This is valid
2938 * but need to be taken care off... Jean II */
2939 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2940 if((index != -1) || (erq->flags == 0)) {
2945 /* Set the index : Check that the key is valid */
2946 if(priv->keys[index].len == 0) {
2954 if (erq->flags & IW_ENCODE_DISABLED)
2956 if (erq->flags & IW_ENCODE_OPEN)
2958 if (erq->flags & IW_ENCODE_RESTRICTED)
2962 priv->keys[index].len = cpu_to_le16(xlen);
2963 memset(priv->keys[index].data, 0,
2964 sizeof(priv->keys[index].data));
2965 memcpy(priv->keys[index].data, keybuf, erq->length);
2967 priv->tx_key = setindex;
2969 /* Try fast key change if connected and only keys are changed */
2970 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2971 netif_carrier_ok(dev)) {
2972 err = __orinoco_hw_setup_wepkeys(priv);
2973 /* No need to commit if successful */
2977 priv->wep_on = enable;
2978 priv->wep_restrict = restricted;
2981 orinoco_unlock(priv, &flags);
2986 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2987 struct iw_request_info *info,
2988 struct iw_point *erq,
2991 struct orinoco_private *priv = netdev_priv(dev);
2992 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2994 unsigned long flags;
2996 if (! priv->has_wep)
2999 if (orinoco_lock(priv, &flags) != 0)
3002 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3003 index = priv->tx_key;
3007 erq->flags |= IW_ENCODE_DISABLED;
3008 erq->flags |= index + 1;
3010 if (priv->wep_restrict)
3011 erq->flags |= IW_ENCODE_RESTRICTED;
3013 erq->flags |= IW_ENCODE_OPEN;
3015 xlen = le16_to_cpu(priv->keys[index].len);
3019 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3021 orinoco_unlock(priv, &flags);
3025 static int orinoco_ioctl_setessid(struct net_device *dev,
3026 struct iw_request_info *info,
3027 struct iw_point *erq,
3030 struct orinoco_private *priv = netdev_priv(dev);
3031 unsigned long flags;
3033 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3034 * anyway... - Jean II */
3036 /* Hum... Should not use Wireless Extension constant (may change),
3037 * should use our own... - Jean II */
3038 if (erq->length > IW_ESSID_MAX_SIZE)
3041 if (orinoco_lock(priv, &flags) != 0)
3044 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3045 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3047 /* If not ANY, get the new ESSID */
3049 memcpy(priv->desired_essid, essidbuf, erq->length);
3052 orinoco_unlock(priv, &flags);
3054 return -EINPROGRESS; /* Call commit handler */
3057 static int orinoco_ioctl_getessid(struct net_device *dev,
3058 struct iw_request_info *info,
3059 struct iw_point *erq,
3062 struct orinoco_private *priv = netdev_priv(dev);
3065 unsigned long flags;
3067 TRACE_ENTER(dev->name);
3069 if (netif_running(dev)) {
3070 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3074 if (orinoco_lock(priv, &flags) != 0)
3076 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3077 orinoco_unlock(priv, &flags);
3081 erq->length = strlen(essidbuf) + 1;
3083 TRACE_EXIT(dev->name);
3088 static int orinoco_ioctl_setnick(struct net_device *dev,
3089 struct iw_request_info *info,
3090 struct iw_point *nrq,
3093 struct orinoco_private *priv = netdev_priv(dev);
3094 unsigned long flags;
3096 if (nrq->length > IW_ESSID_MAX_SIZE)
3099 if (orinoco_lock(priv, &flags) != 0)
3102 memset(priv->nick, 0, sizeof(priv->nick));
3103 memcpy(priv->nick, nickbuf, nrq->length);
3105 orinoco_unlock(priv, &flags);
3107 return -EINPROGRESS; /* Call commit handler */
3110 static int orinoco_ioctl_getnick(struct net_device *dev,
3111 struct iw_request_info *info,
3112 struct iw_point *nrq,
3115 struct orinoco_private *priv = netdev_priv(dev);
3116 unsigned long flags;
3118 if (orinoco_lock(priv, &flags) != 0)
3121 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3122 orinoco_unlock(priv, &flags);
3124 nrq->length = strlen(nickbuf)+1;
3129 static int orinoco_ioctl_setfreq(struct net_device *dev,
3130 struct iw_request_info *info,
3131 struct iw_freq *frq,
3134 struct orinoco_private *priv = netdev_priv(dev);
3136 unsigned long flags;
3137 int err = -EINPROGRESS; /* Call commit handler */
3139 /* In infrastructure mode the AP sets the channel */
3140 if (priv->iw_mode == IW_MODE_INFRA)
3143 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3144 /* Setting by channel number */
3147 /* Setting by frequency - search the table */
3151 for (i = 0; i < (6 - frq->e); i++)
3154 for (i = 0; i < NUM_CHANNELS; i++)
3155 if (frq->m == (channel_frequency[i] * mult))
3159 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3160 ! (priv->channel_mask & (1 << (chan-1)) ) )
3163 if (orinoco_lock(priv, &flags) != 0)
3166 priv->channel = chan;
3167 if (priv->iw_mode == IW_MODE_MONITOR) {
3168 /* Fast channel change - no commit if successful */
3169 hermes_t *hw = &priv->hw;
3170 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3171 HERMES_TEST_SET_CHANNEL,
3174 orinoco_unlock(priv, &flags);
3179 static int orinoco_ioctl_getfreq(struct net_device *dev,
3180 struct iw_request_info *info,
3181 struct iw_freq *frq,
3184 struct orinoco_private *priv = netdev_priv(dev);
3187 /* Locking done in there */
3188 tmp = orinoco_hw_get_freq(priv);
3199 static int orinoco_ioctl_getsens(struct net_device *dev,
3200 struct iw_request_info *info,
3201 struct iw_param *srq,
3204 struct orinoco_private *priv = netdev_priv(dev);
3205 hermes_t *hw = &priv->hw;
3208 unsigned long flags;
3210 if (!priv->has_sensitivity)
3213 if (orinoco_lock(priv, &flags) != 0)
3215 err = hermes_read_wordrec(hw, USER_BAP,
3216 HERMES_RID_CNFSYSTEMSCALE, &val);
3217 orinoco_unlock(priv, &flags);
3223 srq->fixed = 0; /* auto */
3228 static int orinoco_ioctl_setsens(struct net_device *dev,
3229 struct iw_request_info *info,
3230 struct iw_param *srq,
3233 struct orinoco_private *priv = netdev_priv(dev);
3234 int val = srq->value;
3235 unsigned long flags;
3237 if (!priv->has_sensitivity)
3240 if ((val < 1) || (val > 3))
3243 if (orinoco_lock(priv, &flags) != 0)
3245 priv->ap_density = val;
3246 orinoco_unlock(priv, &flags);
3248 return -EINPROGRESS; /* Call commit handler */
3251 static int orinoco_ioctl_setrts(struct net_device *dev,
3252 struct iw_request_info *info,
3253 struct iw_param *rrq,
3256 struct orinoco_private *priv = netdev_priv(dev);
3257 int val = rrq->value;
3258 unsigned long flags;
3263 if ( (val < 0) || (val > 2347) )
3266 if (orinoco_lock(priv, &flags) != 0)
3269 priv->rts_thresh = val;
3270 orinoco_unlock(priv, &flags);
3272 return -EINPROGRESS; /* Call commit handler */
3275 static int orinoco_ioctl_getrts(struct net_device *dev,
3276 struct iw_request_info *info,
3277 struct iw_param *rrq,
3280 struct orinoco_private *priv = netdev_priv(dev);
3282 rrq->value = priv->rts_thresh;
3283 rrq->disabled = (rrq->value == 2347);
3289 static int orinoco_ioctl_setfrag(struct net_device *dev,
3290 struct iw_request_info *info,
3291 struct iw_param *frq,
3294 struct orinoco_private *priv = netdev_priv(dev);
3295 int err = -EINPROGRESS; /* Call commit handler */
3296 unsigned long flags;
3298 if (orinoco_lock(priv, &flags) != 0)
3301 if (priv->has_mwo) {
3303 priv->mwo_robust = 0;
3306 printk(KERN_WARNING "%s: Fixed fragmentation is "
3307 "not supported on this firmware. "
3308 "Using MWO robust instead.\n", dev->name);
3309 priv->mwo_robust = 1;
3313 priv->frag_thresh = 2346;
3315 if ( (frq->value < 256) || (frq->value > 2346) )
3318 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3322 orinoco_unlock(priv, &flags);
3327 static int orinoco_ioctl_getfrag(struct net_device *dev,
3328 struct iw_request_info *info,
3329 struct iw_param *frq,
3332 struct orinoco_private *priv = netdev_priv(dev);
3333 hermes_t *hw = &priv->hw;
3336 unsigned long flags;
3338 if (orinoco_lock(priv, &flags) != 0)
3341 if (priv->has_mwo) {
3342 err = hermes_read_wordrec(hw, USER_BAP,
3343 HERMES_RID_CNFMWOROBUST_AGERE,
3348 frq->value = val ? 2347 : 0;
3349 frq->disabled = ! val;
3352 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3358 frq->disabled = (val >= 2346);
3362 orinoco_unlock(priv, &flags);
3367 static int orinoco_ioctl_setrate(struct net_device *dev,
3368 struct iw_request_info *info,
3369 struct iw_param *rrq,
3372 struct orinoco_private *priv = netdev_priv(dev);
3374 int bitrate; /* 100s of kilobits */
3376 unsigned long flags;
3378 /* As the user space doesn't know our highest rate, it uses -1
3379 * to ask us to set the highest rate. Test it using "iwconfig
3380 * ethX rate auto" - Jean II */
3381 if (rrq->value == -1)
3384 if (rrq->value % 100000)
3386 bitrate = rrq->value / 100000;
3389 if ( (bitrate != 10) && (bitrate != 20) &&
3390 (bitrate != 55) && (bitrate != 110) )
3393 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3394 if ( (bitrate_table[i].bitrate == bitrate) &&
3395 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3403 if (orinoco_lock(priv, &flags) != 0)
3405 priv->bitratemode = ratemode;
3406 orinoco_unlock(priv, &flags);
3408 return -EINPROGRESS;
3411 static int orinoco_ioctl_getrate(struct net_device *dev,
3412 struct iw_request_info *info,
3413 struct iw_param *rrq,
3416 struct orinoco_private *priv = netdev_priv(dev);
3417 hermes_t *hw = &priv->hw;
3422 unsigned long flags;
3424 if (orinoco_lock(priv, &flags) != 0)
3427 ratemode = priv->bitratemode;
3429 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3431 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3432 rrq->fixed = ! bitrate_table[ratemode].automatic;
3435 /* If the interface is running we try to find more about the
3437 if (netif_running(dev)) {
3438 err = hermes_read_wordrec(hw, USER_BAP,
3439 HERMES_RID_CURRENTTXRATE, &val);
3443 switch (priv->firmware_type) {
3444 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3445 /* Note : in Lucent firmware, the return value of
3446 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3447 * and therefore is totally different from the
3448 * encoding of HERMES_RID_CNFTXRATECONTROL.
3449 * Don't forget that 6Mb/s is really 5.5Mb/s */
3451 rrq->value = 5500000;
3453 rrq->value = val * 1000000;
3455 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3456 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3457 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3458 if (bitrate_table[i].intersil_txratectrl == val) {
3462 if (i >= BITRATE_TABLE_SIZE)
3463 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3466 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3474 orinoco_unlock(priv, &flags);
3479 static int orinoco_ioctl_setpower(struct net_device *dev,
3480 struct iw_request_info *info,
3481 struct iw_param *prq,
3484 struct orinoco_private *priv = netdev_priv(dev);
3485 int err = -EINPROGRESS; /* Call commit handler */
3486 unsigned long flags;
3488 if (orinoco_lock(priv, &flags) != 0)
3491 if (prq->disabled) {
3494 switch (prq->flags & IW_POWER_MODE) {
3495 case IW_POWER_UNICAST_R:
3499 case IW_POWER_ALL_R:
3504 /* No flags : but we may have a value - Jean II */
3512 if (prq->flags & IW_POWER_TIMEOUT) {
3514 priv->pm_timeout = prq->value / 1000;
3516 if (prq->flags & IW_POWER_PERIOD) {
3518 priv->pm_period = prq->value / 1000;
3520 /* It's valid to not have a value if we are just toggling
3521 * the flags... Jean II */
3529 orinoco_unlock(priv, &flags);
3534 static int orinoco_ioctl_getpower(struct net_device *dev,
3535 struct iw_request_info *info,
3536 struct iw_param *prq,
3539 struct orinoco_private *priv = netdev_priv(dev);
3540 hermes_t *hw = &priv->hw;
3542 u16 enable, period, timeout, mcast;
3543 unsigned long flags;
3545 if (orinoco_lock(priv, &flags) != 0)
3548 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3552 err = hermes_read_wordrec(hw, USER_BAP,
3553 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3557 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3565 prq->disabled = !enable;
3566 /* Note : by default, display the period */
3567 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3568 prq->flags = IW_POWER_TIMEOUT;
3569 prq->value = timeout * 1000;
3571 prq->flags = IW_POWER_PERIOD;
3572 prq->value = period * 1000;
3575 prq->flags |= IW_POWER_ALL_R;
3577 prq->flags |= IW_POWER_UNICAST_R;
3580 orinoco_unlock(priv, &flags);
3585 static int orinoco_ioctl_getretry(struct net_device *dev,
3586 struct iw_request_info *info,
3587 struct iw_param *rrq,
3590 struct orinoco_private *priv = netdev_priv(dev);
3591 hermes_t *hw = &priv->hw;
3593 u16 short_limit, long_limit, lifetime;
3594 unsigned long flags;
3596 if (orinoco_lock(priv, &flags) != 0)
3599 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3604 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3609 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3614 rrq->disabled = 0; /* Can't be disabled */
3616 /* Note : by default, display the retry number */
3617 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3618 rrq->flags = IW_RETRY_LIFETIME;
3619 rrq->value = lifetime * 1000; /* ??? */
3621 /* By default, display the min number */
3622 if ((rrq->flags & IW_RETRY_MAX)) {
3623 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3624 rrq->value = long_limit;
3626 rrq->flags = IW_RETRY_LIMIT;
3627 rrq->value = short_limit;
3628 if(short_limit != long_limit)
3629 rrq->flags |= IW_RETRY_MIN;
3634 orinoco_unlock(priv, &flags);
3639 static int orinoco_ioctl_reset(struct net_device *dev,
3640 struct iw_request_info *info,
3644 struct orinoco_private *priv = netdev_priv(dev);
3646 if (! capable(CAP_NET_ADMIN))
3649 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3650 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3652 /* Firmware reset */
3655 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3657 schedule_work(&priv->reset_work);
3663 static int orinoco_ioctl_setibssport(struct net_device *dev,
3664 struct iw_request_info *info,
3669 struct orinoco_private *priv = netdev_priv(dev);
3670 int val = *( (int *) extra );
3671 unsigned long flags;
3673 if (orinoco_lock(priv, &flags) != 0)
3676 priv->ibss_port = val ;
3678 /* Actually update the mode we are using */
3679 set_port_type(priv);
3681 orinoco_unlock(priv, &flags);
3682 return -EINPROGRESS; /* Call commit handler */
3685 static int orinoco_ioctl_getibssport(struct net_device *dev,
3686 struct iw_request_info *info,
3690 struct orinoco_private *priv = netdev_priv(dev);
3691 int *val = (int *) extra;
3693 *val = priv->ibss_port;
3697 static int orinoco_ioctl_setport3(struct net_device *dev,
3698 struct iw_request_info *info,
3702 struct orinoco_private *priv = netdev_priv(dev);
3703 int val = *( (int *) extra );
3705 unsigned long flags;
3707 if (orinoco_lock(priv, &flags) != 0)
3711 case 0: /* Try to do IEEE ad-hoc mode */
3712 if (! priv->has_ibss) {
3716 priv->prefer_port3 = 0;
3720 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3721 if (! priv->has_port3) {
3725 priv->prefer_port3 = 1;
3733 /* Actually update the mode we are using */
3734 set_port_type(priv);
3738 orinoco_unlock(priv, &flags);
3743 static int orinoco_ioctl_getport3(struct net_device *dev,
3744 struct iw_request_info *info,
3748 struct orinoco_private *priv = netdev_priv(dev);
3749 int *val = (int *) extra;
3751 *val = priv->prefer_port3;
3755 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3756 struct iw_request_info *info,
3760 struct orinoco_private *priv = netdev_priv(dev);
3761 unsigned long flags;
3764 if (! priv->has_preamble)
3767 /* 802.11b has recently defined some short preamble.
3768 * Basically, the Phy header has been reduced in size.
3769 * This increase performance, especially at high rates
3770 * (the preamble is transmitted at 1Mb/s), unfortunately
3771 * this give compatibility troubles... - Jean II */
3772 val = *( (int *) extra );
3774 if (orinoco_lock(priv, &flags) != 0)
3782 orinoco_unlock(priv, &flags);
3784 return -EINPROGRESS; /* Call commit handler */
3787 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3788 struct iw_request_info *info,
3792 struct orinoco_private *priv = netdev_priv(dev);
3793 int *val = (int *) extra;
3795 if (! priv->has_preamble)
3798 *val = priv->preamble;
3802 /* ioctl interface to hermes_read_ltv()
3803 * To use with iwpriv, pass the RID as the token argument, e.g.
3804 * iwpriv get_rid [0xfc00]
3805 * At least Wireless Tools 25 is required to use iwpriv.
3806 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3807 static int orinoco_ioctl_getrid(struct net_device *dev,
3808 struct iw_request_info *info,
3809 struct iw_point *data,
3812 struct orinoco_private *priv = netdev_priv(dev);
3813 hermes_t *hw = &priv->hw;
3814 int rid = data->flags;
3817 unsigned long flags;
3819 /* It's a "get" function, but we don't want users to access the
3820 * WEP key and other raw firmware data */
3821 if (! capable(CAP_NET_ADMIN))
3824 if (rid < 0xfc00 || rid > 0xffff)
3827 if (orinoco_lock(priv, &flags) != 0)
3830 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3835 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3839 orinoco_unlock(priv, &flags);
3843 /* Trigger a scan (look for other cells in the vicinity */
3844 static int orinoco_ioctl_setscan(struct net_device *dev,
3845 struct iw_request_info *info,
3846 struct iw_param *srq,
3849 struct orinoco_private *priv = netdev_priv(dev);
3850 hermes_t *hw = &priv->hw;
3852 unsigned long flags;
3854 /* Note : you may have realised that, as this is a SET operation,
3855 * this is priviledged and therefore a normal user can't
3857 * This is not an error, while the device perform scanning,
3858 * traffic doesn't flow, so it's a perfect DoS...
3861 if (orinoco_lock(priv, &flags) != 0)
3864 /* Scanning with port 0 disabled would fail */
3865 if (!netif_running(dev)) {
3870 /* In monitor mode, the scan results are always empty.
3871 * Probe responses are passed to the driver as received
3872 * frames and could be processed in software. */
3873 if (priv->iw_mode == IW_MODE_MONITOR) {
3878 /* Note : because we don't lock out the irq handler, the way
3879 * we access scan variables in priv is critical.
3880 * o scan_inprogress : not touched by irq handler
3881 * o scan_mode : not touched by irq handler
3882 * o scan_result : irq is strict producer, non-irq is strict
3884 * o scan_len : synchronised with scan_result
3885 * Before modifying anything on those variables, please think hard !
3888 /* If there is still some left-over scan results, get rid of it */
3889 if (priv->scan_result != NULL) {
3890 /* What's likely is that a client did crash or was killed
3891 * between triggering the scan request and reading the
3892 * results, so we need to reset everything.
3893 * Some clients that are too slow may suffer from that...
3895 kfree(priv->scan_result);
3896 priv->scan_result = NULL;
3900 priv->scan_mode = srq->flags;
3902 /* Always trigger scanning, even if it's in progress.
3903 * This way, if the info frame get lost, we will recover somewhat
3904 * gracefully - Jean II */
3906 if (priv->has_hostscan) {
3907 switch (priv->firmware_type) {
3908 case FIRMWARE_TYPE_SYMBOL:
3909 err = hermes_write_wordrec(hw, USER_BAP,
3910 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3911 HERMES_HOSTSCAN_SYMBOL_ONCE |
3912 HERMES_HOSTSCAN_SYMBOL_BCAST);
3914 case FIRMWARE_TYPE_INTERSIL: {
3917 req[0] = cpu_to_le16(0x3fff); /* All channels */
3918 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3919 req[2] = 0; /* Any ESSID */
3920 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3921 HERMES_RID_CNFHOSTSCAN, &req);
3924 case FIRMWARE_TYPE_AGERE:
3925 err = hermes_write_wordrec(hw, USER_BAP,
3926 HERMES_RID_CNFSCANSSID_AGERE,
3931 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3935 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3937 /* One more client */
3939 priv->scan_inprogress = 1;
3942 orinoco_unlock(priv, &flags);
3946 /* Translate scan data returned from the card to a card independant
3947 * format that the Wireless Tools will understand - Jean II
3948 * Return message length or -errno for fatal errors */
3949 static inline int orinoco_translate_scan(struct net_device *dev,
3954 struct orinoco_private *priv = netdev_priv(dev);
3955 int offset; /* In the scan data */
3956 union hermes_scan_info *atom;
3960 struct iw_event iwe; /* Temporary buffer */
3961 char * current_ev = buffer;
3962 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3964 switch (priv->firmware_type) {
3965 case FIRMWARE_TYPE_AGERE:
3966 atom_len = sizeof(struct agere_scan_apinfo);
3969 case FIRMWARE_TYPE_SYMBOL:
3970 /* Lack of documentation necessitates this hack.
3971 * Different firmwares have 68 or 76 byte long atoms.
3972 * We try modulo first. If the length divides by both,
3973 * we check what would be the channel in the second
3974 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3975 * Valid channel cannot be 0. */
3978 else if (scan_len % 68)
3980 else if (scan_len >= 1292 && scan[68] == 0)
3986 case FIRMWARE_TYPE_INTERSIL:
3988 if (priv->has_hostscan) {
3989 atom_len = le16_to_cpup((__le16 *)scan);
3990 /* Sanity check for atom_len */
3991 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3992 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3993 dev->name, atom_len);
3997 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4003 /* Check that we got an whole number of atoms */
4004 if ((scan_len - offset) % atom_len) {
4005 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4006 "atom_len %d, offset %d\n", dev->name, scan_len,
4011 /* Read the entries one by one */
4012 for (; offset + atom_len <= scan_len; offset += atom_len) {
4014 atom = (union hermes_scan_info *) (scan + offset);
4016 /* First entry *MUST* be the AP MAC address */
4017 iwe.cmd = SIOCGIWAP;
4018 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4019 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4020 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4022 /* Other entries will be displayed in the order we give them */
4025 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4026 if (iwe.u.data.length > 32)
4027 iwe.u.data.length = 32;
4028 iwe.cmd = SIOCGIWESSID;
4029 iwe.u.data.flags = 1;
4030 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4033 iwe.cmd = SIOCGIWMODE;
4034 capabilities = le16_to_cpu(atom->a.capabilities);
4035 if (capabilities & 0x3) {
4036 if (capabilities & 0x1)
4037 iwe.u.mode = IW_MODE_MASTER;
4039 iwe.u.mode = IW_MODE_ADHOC;
4040 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4043 channel = atom->s.channel;
4044 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4046 iwe.cmd = SIOCGIWFREQ;
4047 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4049 current_ev = iwe_stream_add_event(current_ev, end_buf,
4050 &iwe, IW_EV_FREQ_LEN);
4053 /* Add quality statistics */
4055 iwe.u.qual.updated = 0x10; /* no link quality */
4056 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4057 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4058 /* Wireless tools prior to 27.pre22 will show link quality
4059 * anyway, so we provide a reasonable value. */
4060 if (iwe.u.qual.level > iwe.u.qual.noise)
4061 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4063 iwe.u.qual.qual = 0;
4064 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4066 /* Add encryption capability */
4067 iwe.cmd = SIOCGIWENCODE;
4068 if (capabilities & 0x10)
4069 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4071 iwe.u.data.flags = IW_ENCODE_DISABLED;
4072 iwe.u.data.length = 0;
4073 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4075 /* Bit rate is not available in Lucent/Agere firmwares */
4076 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4077 char * current_val = current_ev + IW_EV_LCP_LEN;
4081 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4086 iwe.cmd = SIOCGIWRATE;
4087 /* Those two flags are ignored... */
4088 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4090 for (i = 0; i < 10; i += step) {
4091 /* NULL terminated */
4092 if (atom->p.rates[i] == 0x0)
4094 /* Bit rate given in 500 kb/s units (+ 0x80) */
4095 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4096 current_val = iwe_stream_add_value(current_ev, current_val,
4100 /* Check if we added any event */
4101 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4102 current_ev = current_val;
4105 /* The other data in the scan result are not really
4106 * interesting, so for now drop it - Jean II */
4108 return current_ev - buffer;
4111 /* Return results of a scan */
4112 static int orinoco_ioctl_getscan(struct net_device *dev,
4113 struct iw_request_info *info,
4114 struct iw_point *srq,
4117 struct orinoco_private *priv = netdev_priv(dev);
4119 unsigned long flags;
4121 if (orinoco_lock(priv, &flags) != 0)
4124 /* If no results yet, ask to try again later */
4125 if (priv->scan_result == NULL) {
4126 if (priv->scan_inprogress)
4127 /* Important note : we don't want to block the caller
4128 * until results are ready for various reasons.
4129 * First, managing wait queues is complex and racy.
4130 * Second, we grab some rtnetlink lock before comming
4131 * here (in dev_ioctl()).
4132 * Third, we generate an Wireless Event, so the
4133 * caller can wait itself on that - Jean II */
4136 /* Client error, no scan results...
4137 * The caller need to restart the scan. */
4140 /* We have some results to push back to user space */
4142 /* Translate to WE format */
4143 int ret = orinoco_translate_scan(dev, extra,
4149 kfree(priv->scan_result);
4150 priv->scan_result = NULL;
4155 srq->flags = (__u16) priv->scan_mode;
4157 /* In any case, Scan results will be cleaned up in the
4158 * reset function and when exiting the driver.
4159 * The person triggering the scanning may never come to
4160 * pick the results, so we need to do it in those places.
4163 #ifdef SCAN_SINGLE_READ
4164 /* If you enable this option, only one client (the first
4165 * one) will be able to read the result (and only one
4166 * time). If there is multiple concurent clients that
4167 * want to read scan results, this behavior is not
4168 * advisable - Jean II */
4169 kfree(priv->scan_result);
4170 priv->scan_result = NULL;
4171 #endif /* SCAN_SINGLE_READ */
4172 /* Here, if too much time has elapsed since last scan,
4173 * we may want to clean up scan results... - Jean II */
4176 /* Scan is no longer in progress */
4177 priv->scan_inprogress = 0;
4180 orinoco_unlock(priv, &flags);
4184 /* Commit handler, called after set operations */
4185 static int orinoco_ioctl_commit(struct net_device *dev,
4186 struct iw_request_info *info,
4190 struct orinoco_private *priv = netdev_priv(dev);
4191 struct hermes *hw = &priv->hw;
4192 unsigned long flags;
4198 if (priv->broken_disableport) {
4203 if (orinoco_lock(priv, &flags) != 0)
4206 err = hermes_disable_port(hw, 0);
4208 printk(KERN_WARNING "%s: Unable to disable port "
4209 "while reconfiguring card\n", dev->name);
4210 priv->broken_disableport = 1;
4214 err = __orinoco_program_rids(dev);
4216 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4221 err = hermes_enable_port(hw, 0);
4223 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4230 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4231 schedule_work(&priv->reset_work);
4235 orinoco_unlock(priv, &flags);
4239 static const struct iw_priv_args orinoco_privtab[] = {
4240 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4241 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4242 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4244 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4246 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4247 0, "set_preamble" },
4248 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4250 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4251 0, "set_ibssport" },
4252 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4254 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4260 * Structures to export the Wireless Handlers
4263 static const iw_handler orinoco_handler[] = {
4264 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4265 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4266 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4267 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4268 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4269 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4270 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4271 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4272 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4273 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4274 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4275 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4276 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4277 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4278 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4279 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4280 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4281 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4282 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4283 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4284 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4285 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4286 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4287 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4288 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4289 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4290 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4291 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4292 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4293 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4294 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4295 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4300 Added typecasting since we no longer use iwreq_data -- Moustafa
4302 static const iw_handler orinoco_private_handler[] = {
4303 [0] = (iw_handler) orinoco_ioctl_reset,
4304 [1] = (iw_handler) orinoco_ioctl_reset,
4305 [2] = (iw_handler) orinoco_ioctl_setport3,
4306 [3] = (iw_handler) orinoco_ioctl_getport3,
4307 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4308 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4309 [6] = (iw_handler) orinoco_ioctl_setibssport,
4310 [7] = (iw_handler) orinoco_ioctl_getibssport,
4311 [9] = (iw_handler) orinoco_ioctl_getrid,
4314 static const struct iw_handler_def orinoco_handler_def = {
4315 .num_standard = ARRAY_SIZE(orinoco_handler),
4316 .num_private = ARRAY_SIZE(orinoco_private_handler),
4317 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4318 .standard = orinoco_handler,
4319 .private = orinoco_private_handler,
4320 .private_args = orinoco_privtab,
4321 .get_wireless_stats = orinoco_get_wireless_stats,
4324 static void orinoco_get_drvinfo(struct net_device *dev,
4325 struct ethtool_drvinfo *info)
4327 struct orinoco_private *priv = netdev_priv(dev);
4329 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4330 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4331 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4332 if (dev->class_dev.dev)
4333 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4334 sizeof(info->bus_info) - 1);
4336 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4337 "PCMCIA %p", priv->hw.iobase);
4340 static struct ethtool_ops orinoco_ethtool_ops = {
4341 .get_drvinfo = orinoco_get_drvinfo,
4342 .get_link = ethtool_op_get_link,
4345 /********************************************************************/
4347 /********************************************************************/
4350 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4352 printk(KERN_DEBUG "RX descriptor:\n");
4353 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4354 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4355 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4356 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4357 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4358 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4359 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4361 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4362 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4363 frame->p80211.frame_ctl);
4364 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4365 frame->p80211.duration_id);
4366 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4367 frame->p80211.addr1[0], frame->p80211.addr1[1],
4368 frame->p80211.addr1[2], frame->p80211.addr1[3],
4369 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4370 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4371 frame->p80211.addr2[0], frame->p80211.addr2[1],
4372 frame->p80211.addr2[2], frame->p80211.addr2[3],
4373 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4374 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4375 frame->p80211.addr3[0], frame->p80211.addr3[1],
4376 frame->p80211.addr3[2], frame->p80211.addr3[3],
4377 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4378 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4379 frame->p80211.seq_ctl);
4380 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4381 frame->p80211.addr4[0], frame->p80211.addr4[1],
4382 frame->p80211.addr4[2], frame->p80211.addr4[3],
4383 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4384 printk(KERN_DEBUG " data_len = 0x%04x\n",
4385 frame->p80211.data_len);
4387 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4388 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4389 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4390 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4391 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4392 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4393 frame->p8023.h_source[0], frame->p8023.h_source[1],
4394 frame->p8023.h_source[2], frame->p8023.h_source[3],
4395 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4396 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4398 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4399 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4400 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4401 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4402 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4403 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4404 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4408 /********************************************************************/
4409 /* Module initialization */
4410 /********************************************************************/
4412 EXPORT_SYMBOL(alloc_orinocodev);
4413 EXPORT_SYMBOL(free_orinocodev);
4415 EXPORT_SYMBOL(__orinoco_up);
4416 EXPORT_SYMBOL(__orinoco_down);
4417 EXPORT_SYMBOL(orinoco_reinit_firmware);
4419 EXPORT_SYMBOL(orinoco_interrupt);
4421 /* Can't be declared "const" or the whole __initdata section will
4423 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4424 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4425 "Pavel Roskin <proski@gnu.org>, et al)";
4427 static int __init init_orinoco(void)
4429 printk(KERN_DEBUG "%s\n", version);
4433 static void __exit exit_orinoco(void)
4437 module_init(init_orinoco);
4438 module_exit(exit_orinoco);