1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/config.h>
80 #include <linux/module.h>
81 #include <linux/kernel.h>
82 #include <linux/init.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.h>
86 #include <linux/wireless.h>
87 #include <net/iw_handler.h>
88 #include <net/ieee80211.h>
90 #include "hermes_rid.h"
93 /********************************************************************/
94 /* Module information */
95 /********************************************************************/
97 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
98 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
99 MODULE_LICENSE("Dual MPL/GPL");
101 /* Level of debugging. Used in the macros in orinoco.h */
103 int orinoco_debug = ORINOCO_DEBUG;
104 module_param(orinoco_debug, int, 0644);
105 MODULE_PARM_DESC(orinoco_debug, "Debug level");
106 EXPORT_SYMBOL(orinoco_debug);
109 static int suppress_linkstatus; /* = 0 */
110 module_param(suppress_linkstatus, bool, 0644);
111 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
112 static int ignore_disconnect; /* = 0 */
113 module_param(ignore_disconnect, int, 0644);
114 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
116 static int force_monitor; /* = 0 */
117 module_param(force_monitor, int, 0644);
118 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
120 /********************************************************************/
121 /* Compile time configuration and compatibility stuff */
122 /********************************************************************/
124 /* We do this this way to avoid ifdefs in the actual code */
126 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
128 #define SPY_NUMBER(priv) 0
129 #endif /* WIRELESS_SPY */
131 /********************************************************************/
132 /* Internal constants */
133 /********************************************************************/
135 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
136 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
137 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
139 #define ORINOCO_MIN_MTU 256
140 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
142 #define SYMBOL_MAX_VER_LEN (14)
145 #define MAX_IRQLOOPS_PER_IRQ 10
146 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
149 * legitimately generate */
150 #define SMALL_KEY_SIZE 5
151 #define LARGE_KEY_SIZE 13
152 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
154 #define DUMMY_FID 0xFFFF
156 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
160 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
163 | HERMES_EV_INFDROP )
165 #define MAX_RID_LEN 1024
167 static const struct iw_handler_def orinoco_handler_def;
168 static struct ethtool_ops orinoco_ethtool_ops;
170 /********************************************************************/
172 /********************************************************************/
174 /* The frequency of each channel in MHz */
175 static const long channel_frequency[] = {
176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
177 2447, 2452, 2457, 2462, 2467, 2472, 2484
179 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
181 /* This tables gives the actual meanings of the bitrate IDs returned
182 * by the firmware. */
184 int bitrate; /* in 100s of kilobits */
186 u16 agere_txratectrl;
187 u16 intersil_txratectrl;
188 } bitrate_table[] = {
189 {110, 1, 3, 15}, /* Entry 0 is the default */
198 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
200 /********************************************************************/
202 /********************************************************************/
204 /* Used in Event handling.
205 * We avoid nested structures as they break on ARM -- Moustafa */
206 struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
229 u8 h_source[ETH_ALEN]; /* source ether addr */
230 __be16 h_proto; /* packet type ID field */
239 } __attribute__ ((packed));
241 /* Rx frame header except compatibility 802.3 header */
242 struct hermes_rx_descriptor {
263 } __attribute__ ((packed));
265 /********************************************************************/
266 /* Function prototypes */
267 /********************************************************************/
269 static int __orinoco_program_rids(struct net_device *dev);
270 static void __orinoco_set_multicast_list(struct net_device *dev);
272 /********************************************************************/
273 /* Internal helper functions */
274 /********************************************************************/
276 static inline void set_port_type(struct orinoco_private *priv)
278 switch (priv->iw_mode) {
281 priv->createibss = 0;
284 if (priv->prefer_port3) {
286 priv->createibss = 0;
288 priv->port_type = priv->ibss_port;
289 priv->createibss = 1;
292 case IW_MODE_MONITOR:
294 priv->createibss = 0;
297 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
302 /********************************************************************/
304 /********************************************************************/
306 static int orinoco_open(struct net_device *dev)
308 struct orinoco_private *priv = netdev_priv(dev);
312 if (orinoco_lock(priv, &flags) != 0)
315 err = __orinoco_up(dev);
320 orinoco_unlock(priv, &flags);
325 static int orinoco_stop(struct net_device *dev)
327 struct orinoco_private *priv = netdev_priv(dev);
330 /* We mustn't use orinoco_lock() here, because we need to be
331 able to close the interface even if hw_unavailable is set
332 (e.g. as we're released after a PC Card removal) */
333 spin_lock_irq(&priv->lock);
337 err = __orinoco_down(dev);
339 spin_unlock_irq(&priv->lock);
344 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
346 struct orinoco_private *priv = netdev_priv(dev);
351 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
353 struct orinoco_private *priv = netdev_priv(dev);
354 hermes_t *hw = &priv->hw;
355 struct iw_statistics *wstats = &priv->wstats;
359 if (! netif_device_present(dev)) {
360 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
362 return NULL; /* FIXME: Can we do better than this? */
365 /* If busy, return the old stats. Returning NULL may cause
366 * the interface to disappear from /proc/net/wireless */
367 if (orinoco_lock(priv, &flags) != 0)
370 /* We can't really wait for the tallies inquiry command to
371 * complete, so we just use the previous results and trigger
372 * a new tallies inquiry command for next time - Jean II */
373 /* FIXME: Really we should wait for the inquiry to come back -
374 * as it is the stats we give don't make a whole lot of sense.
375 * Unfortunately, it's not clear how to do that within the
376 * wireless extensions framework: I think we're in user
377 * context, but a lock seems to be held by the time we get in
378 * here so we're not safe to sleep here. */
379 hermes_inquire(hw, HERMES_INQ_TALLIES);
381 if (priv->iw_mode == IW_MODE_ADHOC) {
382 memset(&wstats->qual, 0, sizeof(wstats->qual));
383 /* If a spy address is defined, we report stats of the
384 * first spy address - Jean II */
385 if (SPY_NUMBER(priv)) {
386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
393 __le16 qual, signal, noise, unused;
394 } __attribute__ ((packed)) cq;
396 err = HERMES_READ_RECORD(hw, USER_BAP,
397 HERMES_RID_COMMSQUALITY, &cq);
400 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
401 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
402 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
403 wstats->qual.updated = 7;
407 orinoco_unlock(priv, &flags);
411 static void orinoco_set_multicast_list(struct net_device *dev)
413 struct orinoco_private *priv = netdev_priv(dev);
416 if (orinoco_lock(priv, &flags) != 0) {
417 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
418 "called when hw_unavailable\n", dev->name);
422 __orinoco_set_multicast_list(dev);
423 orinoco_unlock(priv, &flags);
426 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
428 struct orinoco_private *priv = netdev_priv(dev);
430 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
433 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
434 (priv->nicbuf_size - ETH_HLEN) )
442 /********************************************************************/
444 /********************************************************************/
446 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
448 struct orinoco_private *priv = netdev_priv(dev);
449 struct net_device_stats *stats = &priv->stats;
450 hermes_t *hw = &priv->hw;
452 u16 txfid = priv->txfid;
455 int len, data_len, data_off;
456 struct hermes_tx_descriptor desc;
459 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 /* Actual xfer length - allow for padding */
546 len = ALIGN(data_len, 2);
547 if (len < ETH_ZLEN - ETH_HLEN)
548 len = ETH_ZLEN - ETH_HLEN;
549 } else { /* IEEE 802.3 frame */
550 data_len = len + ETH_HLEN;
551 data_off = HERMES_802_3_OFFSET;
553 /* Actual xfer length - round up for odd length packets */
554 len = ALIGN(data_len, 2);
559 err = hermes_bap_pwrite_pad(hw, USER_BAP, p, data_len, len,
562 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
568 /* Finally, we actually initiate the send */
569 netif_stop_queue(dev);
571 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
574 netif_start_queue(dev);
576 printk(KERN_ERR "%s: Error %d transmitting packet\n",
582 dev->trans_start = jiffies;
583 stats->tx_bytes += data_off + data_len;
585 orinoco_unlock(priv, &flags);
589 TRACE_EXIT(dev->name);
593 TRACE_EXIT(dev->name);
595 orinoco_unlock(priv, &flags);
599 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
601 struct orinoco_private *priv = netdev_priv(dev);
602 u16 fid = hermes_read_regn(hw, ALLOCFID);
604 if (fid != priv->txfid) {
605 if (fid != DUMMY_FID)
606 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
611 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
614 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
616 struct orinoco_private *priv = netdev_priv(dev);
617 struct net_device_stats *stats = &priv->stats;
621 netif_wake_queue(dev);
623 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
626 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
628 struct orinoco_private *priv = netdev_priv(dev);
629 struct net_device_stats *stats = &priv->stats;
630 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
632 struct hermes_tx_descriptor_802_11 hdr;
635 if (fid == DUMMY_FID)
636 return; /* Nothing's really happened */
638 /* Read part of the frame header - we need status and addr1 */
639 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
640 offsetof(struct hermes_tx_descriptor_802_11,
644 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
648 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
649 "(FID=%04X error %d)\n",
650 dev->name, fid, err);
654 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
657 /* We produce a TXDROP event only for retry or lifetime
658 * exceeded, because that's the only status that really mean
659 * that this particular node went away.
660 * Other errors means that *we* screwed up. - Jean II */
661 status = le16_to_cpu(hdr.status);
662 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
663 union iwreq_data wrqu;
665 /* Copy 802.11 dest address.
666 * We use the 802.11 header because the frame may
667 * not be 802.3 or may be mangled...
668 * In Ad-Hoc mode, it will be the node address.
669 * In managed mode, it will be most likely the AP addr
670 * User space will figure out how to convert it to
671 * whatever it needs (IP address or else).
673 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
674 wrqu.addr.sa_family = ARPHRD_ETHER;
676 /* Send event to user space */
677 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
680 netif_wake_queue(dev);
683 static void orinoco_tx_timeout(struct net_device *dev)
685 struct orinoco_private *priv = netdev_priv(dev);
686 struct net_device_stats *stats = &priv->stats;
687 struct hermes *hw = &priv->hw;
689 printk(KERN_WARNING "%s: Tx timeout! "
690 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
691 dev->name, hermes_read_regn(hw, ALLOCFID),
692 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
696 schedule_work(&priv->reset_work);
699 /********************************************************************/
700 /* Rx path (data frames) */
701 /********************************************************************/
703 /* Does the frame have a SNAP header indicating it should be
704 * de-encapsulated to Ethernet-II? */
705 static inline int is_ethersnap(void *_hdr)
709 /* We de-encapsulate all packets which, a) have SNAP headers
710 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
711 * and where b) the OUI of the SNAP header is 00:00:00 or
712 * 00:00:f8 - we need both because different APs appear to use
713 * different OUIs for some reason */
714 return (memcmp(hdr, &encaps_hdr, 5) == 0)
715 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
718 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
719 int level, int noise)
721 struct iw_quality wstats;
722 wstats.level = level - 0x95;
723 wstats.noise = noise - 0x95;
724 wstats.qual = (level > noise) ? (level - noise) : 0;
726 /* Update spy records */
727 wireless_spy_update(dev, mac, &wstats);
730 static void orinoco_stat_gather(struct net_device *dev,
732 struct hermes_rx_descriptor *desc)
734 struct orinoco_private *priv = netdev_priv(dev);
736 /* Using spy support with lots of Rx packets, like in an
737 * infrastructure (AP), will really slow down everything, because
738 * the MAC address must be compared to each entry of the spy list.
739 * If the user really asks for it (set some address in the
740 * spy list), we do it, but he will pay the price.
741 * Note that to get here, you need both WIRELESS_SPY
742 * compiled in AND some addresses in the list !!!
744 /* Note : gcc will optimise the whole section away if
745 * WIRELESS_SPY is not defined... - Jean II */
746 if (SPY_NUMBER(priv)) {
747 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
748 desc->signal, desc->silence);
753 * orinoco_rx_monitor - handle received monitor frames.
758 * desc rx descriptor of the frame
760 * Call context: interrupt
762 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
763 struct hermes_rx_descriptor *desc)
765 u32 hdrlen = 30; /* return full header by default */
771 struct orinoco_private *priv = netdev_priv(dev);
772 struct net_device_stats *stats = &priv->stats;
773 hermes_t *hw = &priv->hw;
775 len = le16_to_cpu(desc->data_len);
777 /* Determine the size of the header and the data */
778 fc = le16_to_cpu(desc->frame_ctl);
779 switch (fc & IEEE80211_FCTL_FTYPE) {
780 case IEEE80211_FTYPE_DATA:
781 if ((fc & IEEE80211_FCTL_TODS)
782 && (fc & IEEE80211_FCTL_FROMDS))
788 case IEEE80211_FTYPE_MGMT:
792 case IEEE80211_FTYPE_CTL:
793 switch (fc & IEEE80211_FCTL_STYPE) {
794 case IEEE80211_STYPE_PSPOLL:
795 case IEEE80211_STYPE_RTS:
796 case IEEE80211_STYPE_CFEND:
797 case IEEE80211_STYPE_CFENDACK:
800 case IEEE80211_STYPE_CTS:
801 case IEEE80211_STYPE_ACK:
807 /* Unknown frame type */
811 /* sanity check the length */
812 if (datalen > IEEE80211_DATA_LEN + 12) {
813 printk(KERN_DEBUG "%s: oversized monitor frame, "
814 "data length = %d\n", dev->name, datalen);
815 stats->rx_length_errors++;
819 skb = dev_alloc_skb(hdrlen + datalen);
821 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
826 /* Copy the 802.11 header to the skb */
827 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
828 skb->mac.raw = skb->data;
830 /* If any, copy the data from the card to the skb */
832 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
833 ALIGN(datalen, 2), rxfid,
834 HERMES_802_2_OFFSET);
836 printk(KERN_ERR "%s: error %d reading monitor frame\n",
843 skb->ip_summed = CHECKSUM_NONE;
844 skb->pkt_type = PACKET_OTHERHOST;
845 skb->protocol = __constant_htons(ETH_P_802_2);
847 dev->last_rx = jiffies;
849 stats->rx_bytes += skb->len;
855 dev_kfree_skb_irq(skb);
861 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
863 struct orinoco_private *priv = netdev_priv(dev);
864 struct net_device_stats *stats = &priv->stats;
865 struct iw_statistics *wstats = &priv->wstats;
866 struct sk_buff *skb = NULL;
867 u16 rxfid, status, fc;
869 struct hermes_rx_descriptor desc;
873 rxfid = hermes_read_regn(hw, RXFID);
875 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
878 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
879 "Frame dropped.\n", dev->name, err);
883 status = le16_to_cpu(desc.status);
885 if (status & HERMES_RXSTAT_BADCRC) {
886 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
888 stats->rx_crc_errors++;
892 /* Handle frames in monitor mode */
893 if (priv->iw_mode == IW_MODE_MONITOR) {
894 orinoco_rx_monitor(dev, rxfid, &desc);
898 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
899 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
901 wstats->discard.code++;
905 length = le16_to_cpu(desc.data_len);
906 fc = le16_to_cpu(desc.frame_ctl);
909 if (length < 3) { /* No for even an 802.2 LLC header */
910 /* At least on Symbol firmware with PCF we get quite a
911 lot of these legitimately - Poll frames with no
915 if (length > IEEE80211_DATA_LEN) {
916 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
918 stats->rx_length_errors++;
922 /* We need space for the packet data itself, plus an ethernet
923 header, plus 2 bytes so we can align the IP header on a
924 32bit boundary, plus 1 byte so we can read in odd length
925 packets from the card, which has an IO granularity of 16
927 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
929 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
934 /* We'll prepend the header, so reserve space for it. The worst
935 case is no decapsulation, when 802.3 header is prepended and
936 nothing is removed. 2 is for aligning the IP header. */
937 skb_reserve(skb, ETH_HLEN + 2);
939 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
940 ALIGN(length, 2), rxfid,
941 HERMES_802_2_OFFSET);
943 printk(KERN_ERR "%s: error %d reading frame. "
944 "Frame dropped.\n", dev->name, err);
948 /* Handle decapsulation
949 * In most cases, the firmware tell us about SNAP frames.
950 * For some reason, the SNAP frames sent by LinkSys APs
951 * are not properly recognised by most firmwares.
952 * So, check ourselves */
953 if (length >= ENCAPS_OVERHEAD &&
954 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
955 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
956 is_ethersnap(skb->data))) {
957 /* These indicate a SNAP within 802.2 LLC within
958 802.11 frame which we'll need to de-encapsulate to
959 the original EthernetII frame. */
960 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
962 /* 802.3 frame - prepend 802.3 header as is */
963 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
964 hdr->h_proto = htons(length);
966 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
967 if (fc & IEEE80211_FCTL_FROMDS)
968 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
970 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
972 dev->last_rx = jiffies;
974 skb->protocol = eth_type_trans(skb, dev);
975 skb->ip_summed = CHECKSUM_NONE;
976 if (fc & IEEE80211_FCTL_TODS)
977 skb->pkt_type = PACKET_OTHERHOST;
979 /* Process the wireless stats if needed */
980 orinoco_stat_gather(dev, skb, &desc);
982 /* Pass the packet to the networking stack */
985 stats->rx_bytes += length;
990 dev_kfree_skb_irq(skb);
996 /********************************************************************/
997 /* Rx path (info frames) */
998 /********************************************************************/
1000 static void print_linkstatus(struct net_device *dev, u16 status)
1004 if (suppress_linkstatus)
1008 case HERMES_LINKSTATUS_NOT_CONNECTED:
1009 s = "Not Connected";
1011 case HERMES_LINKSTATUS_CONNECTED:
1014 case HERMES_LINKSTATUS_DISCONNECTED:
1017 case HERMES_LINKSTATUS_AP_CHANGE:
1020 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1021 s = "AP Out of Range";
1023 case HERMES_LINKSTATUS_AP_IN_RANGE:
1026 case HERMES_LINKSTATUS_ASSOC_FAILED:
1027 s = "Association Failed";
1033 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1034 dev->name, s, status);
1037 /* Search scan results for requested BSSID, join it if found */
1038 static void orinoco_join_ap(struct net_device *dev)
1040 struct orinoco_private *priv = netdev_priv(dev);
1041 struct hermes *hw = &priv->hw;
1043 unsigned long flags;
1047 } __attribute__ ((packed)) req;
1048 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1049 struct prism2_scan_apinfo *atom = NULL;
1055 /* Allocate buffer for scan results */
1056 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1060 if (orinoco_lock(priv, &flags) != 0)
1063 /* Sanity checks in case user changed something in the meantime */
1064 if (! priv->bssid_fixed)
1067 if (strlen(priv->desired_essid) == 0)
1070 /* Read scan results from the firmware */
1071 err = hermes_read_ltv(hw, USER_BAP,
1072 HERMES_RID_SCANRESULTSTABLE,
1073 MAX_SCAN_LEN, &len, buf);
1075 printk(KERN_ERR "%s: Cannot read scan results\n",
1080 len = HERMES_RECLEN_TO_BYTES(len);
1082 /* Go through the scan results looking for the channel of the AP
1083 * we were requested to join */
1084 for (; offset + atom_len <= len; offset += atom_len) {
1085 atom = (struct prism2_scan_apinfo *) (buf + offset);
1086 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1093 DEBUG(1, "%s: Requested AP not found in scan results\n",
1098 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1099 req.channel = atom->channel; /* both are little-endian */
1100 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1103 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1106 orinoco_unlock(priv, &flags);
1112 /* Send new BSSID to userspace */
1113 static void orinoco_send_wevents(struct net_device *dev)
1115 struct orinoco_private *priv = netdev_priv(dev);
1116 struct hermes *hw = &priv->hw;
1117 union iwreq_data wrqu;
1119 unsigned long flags;
1121 if (orinoco_lock(priv, &flags) != 0)
1124 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1125 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1129 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1131 /* Send event to user space */
1132 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1135 orinoco_unlock(priv, &flags);
1138 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1140 struct orinoco_private *priv = netdev_priv(dev);
1145 } __attribute__ ((packed)) info;
1149 /* This is an answer to an INQUIRE command that we did earlier,
1150 * or an information "event" generated by the card
1151 * The controller return to us a pseudo frame containing
1152 * the information in question - Jean II */
1153 infofid = hermes_read_regn(hw, INFOFID);
1155 /* Read the info frame header - don't try too hard */
1156 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1159 printk(KERN_ERR "%s: error %d reading info frame. "
1160 "Frame dropped.\n", dev->name, err);
1164 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1165 type = le16_to_cpu(info.type);
1168 case HERMES_INQ_TALLIES: {
1169 struct hermes_tallies_frame tallies;
1170 struct iw_statistics *wstats = &priv->wstats;
1172 if (len > sizeof(tallies)) {
1173 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1175 len = sizeof(tallies);
1178 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1179 infofid, sizeof(info));
1183 /* Increment our various counters */
1184 /* wstats->discard.nwid - no wrong BSSID stuff */
1185 wstats->discard.code +=
1186 le16_to_cpu(tallies.RxWEPUndecryptable);
1187 if (len == sizeof(tallies))
1188 wstats->discard.code +=
1189 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1190 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1191 wstats->discard.misc +=
1192 le16_to_cpu(tallies.TxDiscardsWrongSA);
1193 wstats->discard.fragment +=
1194 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1195 wstats->discard.retries +=
1196 le16_to_cpu(tallies.TxRetryLimitExceeded);
1197 /* wstats->miss.beacon - no match */
1200 case HERMES_INQ_LINKSTATUS: {
1201 struct hermes_linkstatus linkstatus;
1205 if (priv->iw_mode == IW_MODE_MONITOR)
1208 if (len != sizeof(linkstatus)) {
1209 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1214 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1215 infofid, sizeof(info));
1218 newstatus = le16_to_cpu(linkstatus.linkstatus);
1220 /* Symbol firmware uses "out of range" to signal that
1221 * the hostscan frame can be requested. */
1222 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1223 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1224 priv->has_hostscan && priv->scan_inprogress) {
1225 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1229 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1230 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1231 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1234 netif_carrier_on(dev);
1235 else if (!ignore_disconnect)
1236 netif_carrier_off(dev);
1238 if (newstatus != priv->last_linkstatus) {
1239 priv->last_linkstatus = newstatus;
1240 print_linkstatus(dev, newstatus);
1241 /* The info frame contains only one word which is the
1242 * status (see hermes.h). The status is pretty boring
1243 * in itself, that's why we export the new BSSID...
1245 schedule_work(&priv->wevent_work);
1249 case HERMES_INQ_SCAN:
1250 if (!priv->scan_inprogress && priv->bssid_fixed &&
1251 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1252 schedule_work(&priv->join_work);
1256 case HERMES_INQ_HOSTSCAN:
1257 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1258 /* Result of a scanning. Contains information about
1259 * cells in the vicinity - Jean II */
1260 union iwreq_data wrqu;
1265 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1270 /* We are a strict producer. If the previous scan results
1271 * have not been consumed, we just have to drop this
1272 * frame. We can't remove the previous results ourselves,
1273 * that would be *very* racy... Jean II */
1274 if (priv->scan_result != NULL) {
1275 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1279 /* Allocate buffer for results */
1280 buf = kmalloc(len, GFP_ATOMIC);
1282 /* No memory, so can't printk()... */
1285 /* Read scan data */
1286 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1287 infofid, sizeof(info));
1293 #ifdef ORINOCO_DEBUG
1296 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1297 for(i = 1; i < (len * 2); i++)
1298 printk(":%02X", buf[i]);
1301 #endif /* ORINOCO_DEBUG */
1303 /* Allow the clients to access the results */
1304 priv->scan_len = len;
1305 priv->scan_result = buf;
1307 /* Send an empty event to user space.
1308 * We don't send the received data on the event because
1309 * it would require us to do complex transcoding, and
1310 * we want to minimise the work done in the irq handler
1311 * Use a request to extract the data - Jean II */
1312 wrqu.data.length = 0;
1313 wrqu.data.flags = 0;
1314 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1317 case HERMES_INQ_SEC_STAT_AGERE:
1318 /* Security status (Agere specific) */
1319 /* Ignore this frame for now */
1320 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1324 printk(KERN_DEBUG "%s: Unknown information frame received: "
1325 "type 0x%04x, length %d\n", dev->name, type, len);
1326 /* We don't actually do anything about it */
1331 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1333 if (net_ratelimit())
1334 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1337 /********************************************************************/
1338 /* Internal hardware control routines */
1339 /********************************************************************/
1341 int __orinoco_up(struct net_device *dev)
1343 struct orinoco_private *priv = netdev_priv(dev);
1344 struct hermes *hw = &priv->hw;
1347 netif_carrier_off(dev); /* just to make sure */
1349 err = __orinoco_program_rids(dev);
1351 printk(KERN_ERR "%s: Error %d configuring card\n",
1356 /* Fire things up again */
1357 hermes_set_irqmask(hw, ORINOCO_INTEN);
1358 err = hermes_enable_port(hw, 0);
1360 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1365 netif_start_queue(dev);
1370 int __orinoco_down(struct net_device *dev)
1372 struct orinoco_private *priv = netdev_priv(dev);
1373 struct hermes *hw = &priv->hw;
1376 netif_stop_queue(dev);
1378 if (! priv->hw_unavailable) {
1379 if (! priv->broken_disableport) {
1380 err = hermes_disable_port(hw, 0);
1382 /* Some firmwares (e.g. Intersil 1.3.x) seem
1383 * to have problems disabling the port, oh
1385 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1387 priv->broken_disableport = 1;
1390 hermes_set_irqmask(hw, 0);
1391 hermes_write_regn(hw, EVACK, 0xffff);
1394 /* firmware will have to reassociate */
1395 netif_carrier_off(dev);
1396 priv->last_linkstatus = 0xffff;
1401 int orinoco_reinit_firmware(struct net_device *dev)
1403 struct orinoco_private *priv = netdev_priv(dev);
1404 struct hermes *hw = &priv->hw;
1407 err = hermes_init(hw);
1411 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1412 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1413 /* Try workaround for old Symbol firmware bug */
1414 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1415 "(old Symbol firmware?). Trying to work around... ",
1418 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1419 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1421 printk("failed!\n");
1429 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1431 hermes_t *hw = &priv->hw;
1434 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1435 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1436 priv->ndev->name, priv->bitratemode);
1440 switch (priv->firmware_type) {
1441 case FIRMWARE_TYPE_AGERE:
1442 err = hermes_write_wordrec(hw, USER_BAP,
1443 HERMES_RID_CNFTXRATECONTROL,
1444 bitrate_table[priv->bitratemode].agere_txratectrl);
1446 case FIRMWARE_TYPE_INTERSIL:
1447 case FIRMWARE_TYPE_SYMBOL:
1448 err = hermes_write_wordrec(hw, USER_BAP,
1449 HERMES_RID_CNFTXRATECONTROL,
1450 bitrate_table[priv->bitratemode].intersil_txratectrl);
1459 /* Set fixed AP address */
1460 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1464 hermes_t *hw = &priv->hw;
1466 switch (priv->firmware_type) {
1467 case FIRMWARE_TYPE_AGERE:
1470 case FIRMWARE_TYPE_INTERSIL:
1471 if (priv->bssid_fixed)
1476 err = hermes_write_wordrec(hw, USER_BAP,
1477 HERMES_RID_CNFROAMINGMODE,
1480 case FIRMWARE_TYPE_SYMBOL:
1481 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1482 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1483 &priv->desired_bssid);
1489 /* Change the WEP keys and/or the current keys. Can be called
1490 * either from __orinoco_hw_setup_wep() or directly from
1491 * orinoco_ioctl_setiwencode(). In the later case the association
1492 * with the AP is not broken (if the firmware can handle it),
1493 * which is needed for 802.1x implementations. */
1494 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1496 hermes_t *hw = &priv->hw;
1499 switch (priv->firmware_type) {
1500 case FIRMWARE_TYPE_AGERE:
1501 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1502 HERMES_RID_CNFWEPKEYS_AGERE,
1506 err = hermes_write_wordrec(hw, USER_BAP,
1507 HERMES_RID_CNFTXKEY_AGERE,
1512 case FIRMWARE_TYPE_INTERSIL:
1513 case FIRMWARE_TYPE_SYMBOL:
1518 /* Force uniform key length to work around firmware bugs */
1519 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1521 if (keylen > LARGE_KEY_SIZE) {
1522 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1523 priv->ndev->name, priv->tx_key, keylen);
1527 /* Write all 4 keys */
1528 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1529 err = hermes_write_ltv(hw, USER_BAP,
1530 HERMES_RID_CNFDEFAULTKEY0 + i,
1531 HERMES_BYTES_TO_RECLEN(keylen),
1532 priv->keys[i].data);
1537 /* Write the index of the key used in transmission */
1538 err = hermes_write_wordrec(hw, USER_BAP,
1539 HERMES_RID_CNFWEPDEFAULTKEYID,
1550 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1552 hermes_t *hw = &priv->hw;
1554 int master_wep_flag;
1558 __orinoco_hw_setup_wepkeys(priv);
1560 if (priv->wep_restrict)
1561 auth_flag = HERMES_AUTH_SHARED_KEY;
1563 auth_flag = HERMES_AUTH_OPEN;
1565 switch (priv->firmware_type) {
1566 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1568 /* Enable the shared-key authentication. */
1569 err = hermes_write_wordrec(hw, USER_BAP,
1570 HERMES_RID_CNFAUTHENTICATION_AGERE,
1573 err = hermes_write_wordrec(hw, USER_BAP,
1574 HERMES_RID_CNFWEPENABLED_AGERE,
1580 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1581 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1583 if (priv->wep_restrict ||
1584 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1585 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1586 HERMES_WEP_EXCL_UNENCRYPTED;
1588 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1590 err = hermes_write_wordrec(hw, USER_BAP,
1591 HERMES_RID_CNFAUTHENTICATION,
1596 master_wep_flag = 0;
1598 if (priv->iw_mode == IW_MODE_MONITOR)
1599 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1601 /* Master WEP setting : on/off */
1602 err = hermes_write_wordrec(hw, USER_BAP,
1603 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1614 static int __orinoco_program_rids(struct net_device *dev)
1616 struct orinoco_private *priv = netdev_priv(dev);
1617 hermes_t *hw = &priv->hw;
1619 struct hermes_idstring idbuf;
1621 /* Set the MAC address */
1622 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1623 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1625 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1630 /* Set up the link mode */
1631 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1634 printk(KERN_ERR "%s: Error %d setting port type\n",
1638 /* Set the channel/frequency */
1639 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1640 err = hermes_write_wordrec(hw, USER_BAP,
1641 HERMES_RID_CNFOWNCHANNEL,
1644 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1645 dev->name, err, priv->channel);
1650 if (priv->has_ibss) {
1653 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1654 printk(KERN_WARNING "%s: This firmware requires an "
1655 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1656 /* With wvlan_cs, in this case, we would crash.
1657 * hopefully, this driver will behave better...
1661 createibss = priv->createibss;
1664 err = hermes_write_wordrec(hw, USER_BAP,
1665 HERMES_RID_CNFCREATEIBSS,
1668 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1674 /* Set the desired BSSID */
1675 err = __orinoco_hw_set_wap(priv);
1677 printk(KERN_ERR "%s: Error %d setting AP address\n",
1681 /* Set the desired ESSID */
1682 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1683 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1684 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1685 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1686 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1689 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1693 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1694 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1697 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1702 /* Set the station name */
1703 idbuf.len = cpu_to_le16(strlen(priv->nick));
1704 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1705 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1706 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1709 printk(KERN_ERR "%s: Error %d setting nickname\n",
1714 /* Set AP density */
1715 if (priv->has_sensitivity) {
1716 err = hermes_write_wordrec(hw, USER_BAP,
1717 HERMES_RID_CNFSYSTEMSCALE,
1720 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1721 "Disabling sensitivity control\n",
1724 priv->has_sensitivity = 0;
1728 /* Set RTS threshold */
1729 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1732 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1737 /* Set fragmentation threshold or MWO robustness */
1739 err = hermes_write_wordrec(hw, USER_BAP,
1740 HERMES_RID_CNFMWOROBUST_AGERE,
1743 err = hermes_write_wordrec(hw, USER_BAP,
1744 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1747 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1753 err = __orinoco_hw_set_bitrate(priv);
1755 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1760 /* Set power management */
1762 err = hermes_write_wordrec(hw, USER_BAP,
1763 HERMES_RID_CNFPMENABLED,
1766 printk(KERN_ERR "%s: Error %d setting up PM\n",
1771 err = hermes_write_wordrec(hw, USER_BAP,
1772 HERMES_RID_CNFMULTICASTRECEIVE,
1775 printk(KERN_ERR "%s: Error %d setting up PM\n",
1779 err = hermes_write_wordrec(hw, USER_BAP,
1780 HERMES_RID_CNFMAXSLEEPDURATION,
1783 printk(KERN_ERR "%s: Error %d setting up PM\n",
1787 err = hermes_write_wordrec(hw, USER_BAP,
1788 HERMES_RID_CNFPMHOLDOVERDURATION,
1791 printk(KERN_ERR "%s: Error %d setting up PM\n",
1797 /* Set preamble - only for Symbol so far... */
1798 if (priv->has_preamble) {
1799 err = hermes_write_wordrec(hw, USER_BAP,
1800 HERMES_RID_CNFPREAMBLE_SYMBOL,
1803 printk(KERN_ERR "%s: Error %d setting preamble\n",
1809 /* Set up encryption */
1810 if (priv->has_wep) {
1811 err = __orinoco_hw_setup_wep(priv);
1813 printk(KERN_ERR "%s: Error %d activating WEP\n",
1819 if (priv->iw_mode == IW_MODE_MONITOR) {
1820 /* Enable monitor mode */
1821 dev->type = ARPHRD_IEEE80211;
1822 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1823 HERMES_TEST_MONITOR, 0, NULL);
1825 /* Disable monitor mode */
1826 dev->type = ARPHRD_ETHER;
1827 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1828 HERMES_TEST_STOP, 0, NULL);
1833 /* Set promiscuity / multicast*/
1834 priv->promiscuous = 0;
1836 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1841 /* FIXME: return int? */
1843 __orinoco_set_multicast_list(struct net_device *dev)
1845 struct orinoco_private *priv = netdev_priv(dev);
1846 hermes_t *hw = &priv->hw;
1848 int promisc, mc_count;
1850 /* The Hermes doesn't seem to have an allmulti mode, so we go
1851 * into promiscuous mode and let the upper levels deal. */
1852 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1853 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1858 mc_count = dev->mc_count;
1861 if (promisc != priv->promiscuous) {
1862 err = hermes_write_wordrec(hw, USER_BAP,
1863 HERMES_RID_CNFPROMISCUOUSMODE,
1866 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1869 priv->promiscuous = promisc;
1872 if (! promisc && (mc_count || priv->mc_count) ) {
1873 struct dev_mc_list *p = dev->mc_list;
1874 struct hermes_multicast mclist;
1877 for (i = 0; i < mc_count; i++) {
1878 /* paranoia: is list shorter than mc_count? */
1880 /* paranoia: bad address size in list? */
1881 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1883 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1888 printk(KERN_WARNING "%s: Multicast list is "
1889 "longer than mc_count\n", dev->name);
1891 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1892 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1895 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1898 priv->mc_count = mc_count;
1901 /* Since we can set the promiscuous flag when it wasn't asked
1902 for, make sure the net_device knows about it. */
1903 if (priv->promiscuous)
1904 dev->flags |= IFF_PROMISC;
1906 dev->flags &= ~IFF_PROMISC;
1909 /* This must be called from user context, without locks held - use
1910 * schedule_work() */
1911 static void orinoco_reset(struct net_device *dev)
1913 struct orinoco_private *priv = netdev_priv(dev);
1914 struct hermes *hw = &priv->hw;
1916 unsigned long flags;
1918 if (orinoco_lock(priv, &flags) != 0)
1919 /* When the hardware becomes available again, whatever
1920 * detects that is responsible for re-initializing
1921 * it. So no need for anything further */
1924 netif_stop_queue(dev);
1926 /* Shut off interrupts. Depending on what state the hardware
1927 * is in, this might not work, but we'll try anyway */
1928 hermes_set_irqmask(hw, 0);
1929 hermes_write_regn(hw, EVACK, 0xffff);
1931 priv->hw_unavailable++;
1932 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1933 netif_carrier_off(dev);
1935 orinoco_unlock(priv, &flags);
1937 /* Scanning support: Cleanup of driver struct */
1938 kfree(priv->scan_result);
1939 priv->scan_result = NULL;
1940 priv->scan_inprogress = 0;
1942 if (priv->hard_reset) {
1943 err = (*priv->hard_reset)(priv);
1945 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1946 "performing hard reset\n", dev->name, err);
1951 err = orinoco_reinit_firmware(dev);
1953 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1958 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1960 priv->hw_unavailable--;
1962 /* priv->open or priv->hw_unavailable might have changed while
1963 * we dropped the lock */
1964 if (priv->open && (! priv->hw_unavailable)) {
1965 err = __orinoco_up(dev);
1967 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1970 dev->trans_start = jiffies;
1973 spin_unlock_irq(&priv->lock);
1977 hermes_set_irqmask(hw, 0);
1978 netif_device_detach(dev);
1979 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1982 /********************************************************************/
1983 /* Interrupt handler */
1984 /********************************************************************/
1986 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1988 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1991 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1993 /* This seems to happen a fair bit under load, but ignoring it
1994 seems to work fine...*/
1995 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1999 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2001 struct net_device *dev = (struct net_device *)dev_id;
2002 struct orinoco_private *priv = netdev_priv(dev);
2003 hermes_t *hw = &priv->hw;
2004 int count = MAX_IRQLOOPS_PER_IRQ;
2006 /* These are used to detect a runaway interrupt situation */
2007 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2008 * we panic and shut down the hardware */
2009 static int last_irq_jiffy = 0; /* jiffies value the last time
2011 static int loops_this_jiffy = 0;
2012 unsigned long flags;
2014 if (orinoco_lock(priv, &flags) != 0) {
2015 /* If hw is unavailable - we don't know if the irq was
2020 evstat = hermes_read_regn(hw, EVSTAT);
2021 events = evstat & hw->inten;
2023 orinoco_unlock(priv, &flags);
2027 if (jiffies != last_irq_jiffy)
2028 loops_this_jiffy = 0;
2029 last_irq_jiffy = jiffies;
2031 while (events && count--) {
2032 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2033 printk(KERN_WARNING "%s: IRQ handler is looping too "
2034 "much! Resetting.\n", dev->name);
2035 /* Disable interrupts for now */
2036 hermes_set_irqmask(hw, 0);
2037 schedule_work(&priv->reset_work);
2041 /* Check the card hasn't been removed */
2042 if (! hermes_present(hw)) {
2043 DEBUG(0, "orinoco_interrupt(): card removed\n");
2047 if (events & HERMES_EV_TICK)
2048 __orinoco_ev_tick(dev, hw);
2049 if (events & HERMES_EV_WTERR)
2050 __orinoco_ev_wterr(dev, hw);
2051 if (events & HERMES_EV_INFDROP)
2052 __orinoco_ev_infdrop(dev, hw);
2053 if (events & HERMES_EV_INFO)
2054 __orinoco_ev_info(dev, hw);
2055 if (events & HERMES_EV_RX)
2056 __orinoco_ev_rx(dev, hw);
2057 if (events & HERMES_EV_TXEXC)
2058 __orinoco_ev_txexc(dev, hw);
2059 if (events & HERMES_EV_TX)
2060 __orinoco_ev_tx(dev, hw);
2061 if (events & HERMES_EV_ALLOC)
2062 __orinoco_ev_alloc(dev, hw);
2064 hermes_write_regn(hw, EVACK, evstat);
2066 evstat = hermes_read_regn(hw, EVSTAT);
2067 events = evstat & hw->inten;
2070 orinoco_unlock(priv, &flags);
2074 /********************************************************************/
2075 /* Initialization */
2076 /********************************************************************/
2079 u16 id, variant, major, minor;
2080 } __attribute__ ((packed));
2082 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2084 if (nic_id->id < 0x8000)
2085 return FIRMWARE_TYPE_AGERE;
2086 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2087 return FIRMWARE_TYPE_SYMBOL;
2089 return FIRMWARE_TYPE_INTERSIL;
2092 /* Set priv->firmware type, determine firmware properties */
2093 static int determine_firmware(struct net_device *dev)
2095 struct orinoco_private *priv = netdev_priv(dev);
2096 hermes_t *hw = &priv->hw;
2098 struct comp_id nic_id, sta_id;
2099 unsigned int firmver;
2100 char tmp[SYMBOL_MAX_VER_LEN+1];
2102 /* Get the hardware version */
2103 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2105 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2110 le16_to_cpus(&nic_id.id);
2111 le16_to_cpus(&nic_id.variant);
2112 le16_to_cpus(&nic_id.major);
2113 le16_to_cpus(&nic_id.minor);
2114 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2115 dev->name, nic_id.id, nic_id.variant,
2116 nic_id.major, nic_id.minor);
2118 priv->firmware_type = determine_firmware_type(&nic_id);
2120 /* Get the firmware version */
2121 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2123 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2128 le16_to_cpus(&sta_id.id);
2129 le16_to_cpus(&sta_id.variant);
2130 le16_to_cpus(&sta_id.major);
2131 le16_to_cpus(&sta_id.minor);
2132 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2133 dev->name, sta_id.id, sta_id.variant,
2134 sta_id.major, sta_id.minor);
2136 switch (sta_id.id) {
2138 printk(KERN_ERR "%s: Primary firmware is active\n",
2142 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2145 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2146 case 0x21: /* Symbol Spectrum24 Trilogy */
2149 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2154 /* Default capabilities */
2155 priv->has_sensitivity = 1;
2157 priv->has_preamble = 0;
2158 priv->has_port3 = 1;
2161 priv->has_big_wep = 0;
2163 /* Determine capabilities from the firmware version */
2164 switch (priv->firmware_type) {
2165 case FIRMWARE_TYPE_AGERE:
2166 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2167 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2168 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2169 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2171 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2173 priv->has_ibss = (firmver >= 0x60006);
2174 priv->has_wep = (firmver >= 0x40020);
2175 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2176 Gold cards from the others? */
2177 priv->has_mwo = (firmver >= 0x60000);
2178 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2179 priv->ibss_port = 1;
2180 priv->has_hostscan = (firmver >= 0x8000a);
2181 priv->broken_monitor = (firmver >= 0x80000);
2183 /* Tested with Agere firmware :
2184 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2185 * Tested CableTron firmware : 4.32 => Anton */
2187 case FIRMWARE_TYPE_SYMBOL:
2188 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2189 /* Intel MAC : 00:02:B3:* */
2190 /* 3Com MAC : 00:50:DA:* */
2191 memset(tmp, 0, sizeof(tmp));
2192 /* Get the Symbol firmware version */
2193 err = hermes_read_ltv(hw, USER_BAP,
2194 HERMES_RID_SECONDARYVERSION_SYMBOL,
2195 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2198 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2203 /* The firmware revision is a string, the format is
2204 * something like : "V2.20-01".
2205 * Quick and dirty parsing... - Jean II
2207 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2208 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2211 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2214 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2217 priv->has_ibss = (firmver >= 0x20000);
2218 priv->has_wep = (firmver >= 0x15012);
2219 priv->has_big_wep = (firmver >= 0x20000);
2220 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2221 (firmver >= 0x29000 && firmver < 0x30000) ||
2223 priv->has_preamble = (firmver >= 0x20000);
2224 priv->ibss_port = 4;
2225 priv->broken_disableport = (firmver == 0x25013) ||
2226 (firmver >= 0x30000 && firmver <= 0x31000);
2227 priv->has_hostscan = (firmver >= 0x31001) ||
2228 (firmver >= 0x29057 && firmver < 0x30000);
2229 /* Tested with Intel firmware : 0x20015 => Jean II */
2230 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2232 case FIRMWARE_TYPE_INTERSIL:
2233 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2234 * Samsung, Compaq 100/200 and Proxim are slightly
2235 * different and less well tested */
2236 /* D-Link MAC : 00:40:05:* */
2237 /* Addtron MAC : 00:90:D1:* */
2238 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2239 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2242 firmver = ((unsigned long)sta_id.major << 16) |
2243 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2245 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2246 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2247 priv->has_pm = (firmver >= 0x000700);
2248 priv->has_hostscan = (firmver >= 0x010301);
2250 if (firmver >= 0x000800)
2251 priv->ibss_port = 0;
2253 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2254 "than v0.8.x - several features not supported\n",
2256 priv->ibss_port = 1;
2260 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2266 static int orinoco_init(struct net_device *dev)
2268 struct orinoco_private *priv = netdev_priv(dev);
2269 hermes_t *hw = &priv->hw;
2271 struct hermes_idstring nickbuf;
2275 TRACE_ENTER(dev->name);
2277 /* No need to lock, the hw_unavailable flag is already set in
2278 * alloc_orinocodev() */
2279 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2281 /* Initialize the firmware */
2282 err = orinoco_reinit_firmware(dev);
2284 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2289 err = determine_firmware(dev);
2291 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2296 if (priv->has_port3)
2297 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2299 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2301 if (priv->has_wep) {
2302 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2303 if (priv->has_big_wep)
2304 printk("104-bit key\n");
2306 printk("40-bit key\n");
2309 /* Get the MAC address */
2310 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2311 ETH_ALEN, NULL, dev->dev_addr);
2313 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2318 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2319 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2320 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2323 /* Get the station name */
2324 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2325 sizeof(nickbuf), &reclen, &nickbuf);
2327 printk(KERN_ERR "%s: failed to read station name\n",
2332 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2334 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2335 memcpy(priv->nick, &nickbuf.val, len);
2336 priv->nick[len] = '\0';
2338 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2340 /* Get allowed channels */
2341 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2342 &priv->channel_mask);
2344 printk(KERN_ERR "%s: failed to read channel list!\n",
2349 /* Get initial AP density */
2350 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2352 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2353 priv->has_sensitivity = 0;
2356 /* Get initial RTS threshold */
2357 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2360 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2365 /* Get initial fragmentation settings */
2367 err = hermes_read_wordrec(hw, USER_BAP,
2368 HERMES_RID_CNFMWOROBUST_AGERE,
2371 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2372 &priv->frag_thresh);
2374 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2379 /* Power management setup */
2383 err = hermes_read_wordrec(hw, USER_BAP,
2384 HERMES_RID_CNFMAXSLEEPDURATION,
2387 printk(KERN_ERR "%s: failed to read power management period!\n",
2391 err = hermes_read_wordrec(hw, USER_BAP,
2392 HERMES_RID_CNFPMHOLDOVERDURATION,
2395 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2401 /* Preamble setup */
2402 if (priv->has_preamble) {
2403 err = hermes_read_wordrec(hw, USER_BAP,
2404 HERMES_RID_CNFPREAMBLE_SYMBOL,
2410 /* Set up the default configuration */
2411 priv->iw_mode = IW_MODE_INFRA;
2412 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2413 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2414 set_port_type(priv);
2415 priv->channel = 0; /* use firmware default */
2417 priv->promiscuous = 0;
2421 /* Make the hardware available, as long as it hasn't been
2422 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2423 spin_lock_irq(&priv->lock);
2424 priv->hw_unavailable--;
2425 spin_unlock_irq(&priv->lock);
2427 printk(KERN_DEBUG "%s: ready\n", dev->name);
2430 TRACE_EXIT(dev->name);
2434 struct net_device *alloc_orinocodev(int sizeof_card,
2435 int (*hard_reset)(struct orinoco_private *))
2437 struct net_device *dev;
2438 struct orinoco_private *priv;
2440 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2443 priv = netdev_priv(dev);
2446 priv->card = (void *)((unsigned long)priv
2447 + sizeof(struct orinoco_private));
2451 /* Setup / override net_device fields */
2452 dev->init = orinoco_init;
2453 dev->hard_start_xmit = orinoco_xmit;
2454 dev->tx_timeout = orinoco_tx_timeout;
2455 dev->watchdog_timeo = HZ; /* 1 second timeout */
2456 dev->get_stats = orinoco_get_stats;
2457 dev->ethtool_ops = &orinoco_ethtool_ops;
2458 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2460 priv->wireless_data.spy_data = &priv->spy_data;
2461 dev->wireless_data = &priv->wireless_data;
2463 dev->change_mtu = orinoco_change_mtu;
2464 dev->set_multicast_list = orinoco_set_multicast_list;
2465 /* we use the default eth_mac_addr for setting the MAC addr */
2467 /* Set up default callbacks */
2468 dev->open = orinoco_open;
2469 dev->stop = orinoco_stop;
2470 priv->hard_reset = hard_reset;
2472 spin_lock_init(&priv->lock);
2474 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2475 * before anything else touches the
2477 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2478 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2479 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2481 netif_carrier_off(dev);
2482 priv->last_linkstatus = 0xffff;
2488 void free_orinocodev(struct net_device *dev)
2490 struct orinoco_private *priv = netdev_priv(dev);
2492 kfree(priv->scan_result);
2496 /********************************************************************/
2497 /* Wireless extensions */
2498 /********************************************************************/
2500 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2501 char buf[IW_ESSID_MAX_SIZE+1])
2503 hermes_t *hw = &priv->hw;
2505 struct hermes_idstring essidbuf;
2506 char *p = (char *)(&essidbuf.val);
2508 unsigned long flags;
2510 if (orinoco_lock(priv, &flags) != 0)
2513 if (strlen(priv->desired_essid) > 0) {
2514 /* We read the desired SSID from the hardware rather
2515 than from priv->desired_essid, just in case the
2516 firmware is allowed to change it on us. I'm not
2518 /* My guess is that the OWNSSID should always be whatever
2519 * we set to the card, whereas CURRENT_SSID is the one that
2520 * may change... - Jean II */
2525 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2526 HERMES_RID_CNFDESIREDSSID;
2528 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2535 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2536 sizeof(essidbuf), NULL, &essidbuf);
2541 len = le16_to_cpu(essidbuf.len);
2542 BUG_ON(len > IW_ESSID_MAX_SIZE);
2544 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2545 memcpy(buf, p, len);
2549 orinoco_unlock(priv, &flags);
2554 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2557 hermes_t *hw = &priv->hw;
2561 unsigned long flags;
2563 if (orinoco_lock(priv, &flags) != 0)
2566 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2570 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2576 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2577 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2578 priv->ndev->name, channel);
2583 freq = channel_frequency[channel-1] * 100000;
2586 orinoco_unlock(priv, &flags);
2590 return err ? err : freq;
2593 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2594 int *numrates, s32 *rates, int max)
2596 hermes_t *hw = &priv->hw;
2597 struct hermes_idstring list;
2598 unsigned char *p = (unsigned char *)&list.val;
2602 unsigned long flags;
2604 if (orinoco_lock(priv, &flags) != 0)
2607 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2608 sizeof(list), NULL, &list);
2609 orinoco_unlock(priv, &flags);
2614 num = le16_to_cpu(list.len);
2616 num = min(num, max);
2618 for (i = 0; i < num; i++) {
2619 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2625 static int orinoco_ioctl_getname(struct net_device *dev,
2626 struct iw_request_info *info,
2630 struct orinoco_private *priv = netdev_priv(dev);
2634 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2636 if (!err && (numrates > 2))
2637 strcpy(name, "IEEE 802.11b");
2639 strcpy(name, "IEEE 802.11-DS");
2644 static int orinoco_ioctl_setwap(struct net_device *dev,
2645 struct iw_request_info *info,
2646 struct sockaddr *ap_addr,
2649 struct orinoco_private *priv = netdev_priv(dev);
2650 int err = -EINPROGRESS; /* Call commit handler */
2651 unsigned long flags;
2652 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2653 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2655 if (orinoco_lock(priv, &flags) != 0)
2658 /* Enable automatic roaming - no sanity checks are needed */
2659 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2660 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2661 priv->bssid_fixed = 0;
2662 memset(priv->desired_bssid, 0, ETH_ALEN);
2664 /* "off" means keep existing connection */
2665 if (ap_addr->sa_data[0] == 0) {
2666 __orinoco_hw_set_wap(priv);
2672 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2673 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2674 "support manual roaming\n",
2680 if (priv->iw_mode != IW_MODE_INFRA) {
2681 printk(KERN_WARNING "%s: Manual roaming supported only in "
2682 "managed mode\n", dev->name);
2687 /* Intersil firmware hangs without Desired ESSID */
2688 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2689 strlen(priv->desired_essid) == 0) {
2690 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2691 "manual roaming\n", dev->name);
2696 /* Finally, enable manual roaming */
2697 priv->bssid_fixed = 1;
2698 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2701 orinoco_unlock(priv, &flags);
2705 static int orinoco_ioctl_getwap(struct net_device *dev,
2706 struct iw_request_info *info,
2707 struct sockaddr *ap_addr,
2710 struct orinoco_private *priv = netdev_priv(dev);
2712 hermes_t *hw = &priv->hw;
2714 unsigned long flags;
2716 if (orinoco_lock(priv, &flags) != 0)
2719 ap_addr->sa_family = ARPHRD_ETHER;
2720 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2721 ETH_ALEN, NULL, ap_addr->sa_data);
2723 orinoco_unlock(priv, &flags);
2728 static int orinoco_ioctl_setmode(struct net_device *dev,
2729 struct iw_request_info *info,
2733 struct orinoco_private *priv = netdev_priv(dev);
2734 int err = -EINPROGRESS; /* Call commit handler */
2735 unsigned long flags;
2737 if (priv->iw_mode == *mode)
2740 if (orinoco_lock(priv, &flags) != 0)
2745 if (!priv->has_ibss && !priv->has_port3)
2752 case IW_MODE_MONITOR:
2753 if (priv->broken_monitor && !force_monitor) {
2754 printk(KERN_WARNING "%s: Monitor mode support is "
2755 "buggy in this firmware, not enabling\n",
2766 if (err == -EINPROGRESS) {
2767 priv->iw_mode = *mode;
2768 set_port_type(priv);
2771 orinoco_unlock(priv, &flags);
2776 static int orinoco_ioctl_getmode(struct net_device *dev,
2777 struct iw_request_info *info,
2781 struct orinoco_private *priv = netdev_priv(dev);
2783 *mode = priv->iw_mode;
2787 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2788 struct iw_request_info *info,
2789 struct iw_point *rrq,
2792 struct orinoco_private *priv = netdev_priv(dev);
2794 struct iw_range *range = (struct iw_range *) extra;
2798 TRACE_ENTER(dev->name);
2800 rrq->length = sizeof(struct iw_range);
2801 memset(range, 0, sizeof(struct iw_range));
2803 range->we_version_compiled = WIRELESS_EXT;
2804 range->we_version_source = 14;
2806 /* Set available channels/frequencies */
2807 range->num_channels = NUM_CHANNELS;
2809 for (i = 0; i < NUM_CHANNELS; i++) {
2810 if (priv->channel_mask & (1 << i)) {
2811 range->freq[k].i = i + 1;
2812 range->freq[k].m = channel_frequency[i] * 100000;
2813 range->freq[k].e = 1;
2817 if (k >= IW_MAX_FREQUENCIES)
2820 range->num_frequency = k;
2821 range->sensitivity = 3;
2823 if (priv->has_wep) {
2824 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2825 range->encoding_size[0] = SMALL_KEY_SIZE;
2826 range->num_encoding_sizes = 1;
2828 if (priv->has_big_wep) {
2829 range->encoding_size[1] = LARGE_KEY_SIZE;
2830 range->num_encoding_sizes = 2;
2834 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2835 /* Quality stats meaningless in ad-hoc mode */
2837 range->max_qual.qual = 0x8b - 0x2f;
2838 range->max_qual.level = 0x2f - 0x95 - 1;
2839 range->max_qual.noise = 0x2f - 0x95 - 1;
2840 /* Need to get better values */
2841 range->avg_qual.qual = 0x24;
2842 range->avg_qual.level = 0xC2;
2843 range->avg_qual.noise = 0x9E;
2846 err = orinoco_hw_get_bitratelist(priv, &numrates,
2847 range->bitrate, IW_MAX_BITRATES);
2850 range->num_bitrates = numrates;
2852 /* Set an indication of the max TCP throughput in bit/s that we can
2853 * expect using this interface. May be use for QoS stuff...
2856 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2858 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2861 range->max_rts = 2347;
2862 range->min_frag = 256;
2863 range->max_frag = 2346;
2866 range->max_pmp = 65535000;
2868 range->max_pmt = 65535 * 1000; /* ??? */
2869 range->pmp_flags = IW_POWER_PERIOD;
2870 range->pmt_flags = IW_POWER_TIMEOUT;
2871 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2873 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2874 range->retry_flags = IW_RETRY_LIMIT;
2875 range->r_time_flags = IW_RETRY_LIFETIME;
2876 range->min_retry = 0;
2877 range->max_retry = 65535; /* ??? */
2878 range->min_r_time = 0;
2879 range->max_r_time = 65535 * 1000; /* ??? */
2881 /* Event capability (kernel) */
2882 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2883 /* Event capability (driver) */
2884 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2885 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2886 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2887 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2889 TRACE_EXIT(dev->name);
2894 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2895 struct iw_request_info *info,
2896 struct iw_point *erq,
2899 struct orinoco_private *priv = netdev_priv(dev);
2900 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2901 int setindex = priv->tx_key;
2902 int enable = priv->wep_on;
2903 int restricted = priv->wep_restrict;
2905 int err = -EINPROGRESS; /* Call commit handler */
2906 unsigned long flags;
2908 if (! priv->has_wep)
2912 /* We actually have a key to set - check its length */
2913 if (erq->length > LARGE_KEY_SIZE)
2916 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2920 if (orinoco_lock(priv, &flags) != 0)
2924 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2925 index = priv->tx_key;
2927 /* Adjust key length to a supported value */
2928 if (erq->length > SMALL_KEY_SIZE) {
2929 xlen = LARGE_KEY_SIZE;
2930 } else if (erq->length > 0) {
2931 xlen = SMALL_KEY_SIZE;
2935 /* Switch on WEP if off */
2936 if ((!enable) && (xlen > 0)) {
2941 /* Important note : if the user do "iwconfig eth0 enc off",
2942 * we will arrive there with an index of -1. This is valid
2943 * but need to be taken care off... Jean II */
2944 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2945 if((index != -1) || (erq->flags == 0)) {
2950 /* Set the index : Check that the key is valid */
2951 if(priv->keys[index].len == 0) {
2959 if (erq->flags & IW_ENCODE_DISABLED)
2961 if (erq->flags & IW_ENCODE_OPEN)
2963 if (erq->flags & IW_ENCODE_RESTRICTED)
2967 priv->keys[index].len = cpu_to_le16(xlen);
2968 memset(priv->keys[index].data, 0,
2969 sizeof(priv->keys[index].data));
2970 memcpy(priv->keys[index].data, keybuf, erq->length);
2972 priv->tx_key = setindex;
2974 /* Try fast key change if connected and only keys are changed */
2975 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2976 netif_carrier_ok(dev)) {
2977 err = __orinoco_hw_setup_wepkeys(priv);
2978 /* No need to commit if successful */
2982 priv->wep_on = enable;
2983 priv->wep_restrict = restricted;
2986 orinoco_unlock(priv, &flags);
2991 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2992 struct iw_request_info *info,
2993 struct iw_point *erq,
2996 struct orinoco_private *priv = netdev_priv(dev);
2997 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2999 unsigned long flags;
3001 if (! priv->has_wep)
3004 if (orinoco_lock(priv, &flags) != 0)
3007 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3008 index = priv->tx_key;
3012 erq->flags |= IW_ENCODE_DISABLED;
3013 erq->flags |= index + 1;
3015 if (priv->wep_restrict)
3016 erq->flags |= IW_ENCODE_RESTRICTED;
3018 erq->flags |= IW_ENCODE_OPEN;
3020 xlen = le16_to_cpu(priv->keys[index].len);
3024 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3026 orinoco_unlock(priv, &flags);
3030 static int orinoco_ioctl_setessid(struct net_device *dev,
3031 struct iw_request_info *info,
3032 struct iw_point *erq,
3035 struct orinoco_private *priv = netdev_priv(dev);
3036 unsigned long flags;
3038 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3039 * anyway... - Jean II */
3041 /* Hum... Should not use Wireless Extension constant (may change),
3042 * should use our own... - Jean II */
3043 if (erq->length > IW_ESSID_MAX_SIZE)
3046 if (orinoco_lock(priv, &flags) != 0)
3049 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3050 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3052 /* If not ANY, get the new ESSID */
3054 memcpy(priv->desired_essid, essidbuf, erq->length);
3057 orinoco_unlock(priv, &flags);
3059 return -EINPROGRESS; /* Call commit handler */
3062 static int orinoco_ioctl_getessid(struct net_device *dev,
3063 struct iw_request_info *info,
3064 struct iw_point *erq,
3067 struct orinoco_private *priv = netdev_priv(dev);
3070 unsigned long flags;
3072 TRACE_ENTER(dev->name);
3074 if (netif_running(dev)) {
3075 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3079 if (orinoco_lock(priv, &flags) != 0)
3081 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3082 orinoco_unlock(priv, &flags);
3086 erq->length = strlen(essidbuf) + 1;
3088 TRACE_EXIT(dev->name);
3093 static int orinoco_ioctl_setnick(struct net_device *dev,
3094 struct iw_request_info *info,
3095 struct iw_point *nrq,
3098 struct orinoco_private *priv = netdev_priv(dev);
3099 unsigned long flags;
3101 if (nrq->length > IW_ESSID_MAX_SIZE)
3104 if (orinoco_lock(priv, &flags) != 0)
3107 memset(priv->nick, 0, sizeof(priv->nick));
3108 memcpy(priv->nick, nickbuf, nrq->length);
3110 orinoco_unlock(priv, &flags);
3112 return -EINPROGRESS; /* Call commit handler */
3115 static int orinoco_ioctl_getnick(struct net_device *dev,
3116 struct iw_request_info *info,
3117 struct iw_point *nrq,
3120 struct orinoco_private *priv = netdev_priv(dev);
3121 unsigned long flags;
3123 if (orinoco_lock(priv, &flags) != 0)
3126 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3127 orinoco_unlock(priv, &flags);
3129 nrq->length = strlen(nickbuf)+1;
3134 static int orinoco_ioctl_setfreq(struct net_device *dev,
3135 struct iw_request_info *info,
3136 struct iw_freq *frq,
3139 struct orinoco_private *priv = netdev_priv(dev);
3141 unsigned long flags;
3142 int err = -EINPROGRESS; /* Call commit handler */
3144 /* In infrastructure mode the AP sets the channel */
3145 if (priv->iw_mode == IW_MODE_INFRA)
3148 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3149 /* Setting by channel number */
3152 /* Setting by frequency - search the table */
3156 for (i = 0; i < (6 - frq->e); i++)
3159 for (i = 0; i < NUM_CHANNELS; i++)
3160 if (frq->m == (channel_frequency[i] * mult))
3164 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3165 ! (priv->channel_mask & (1 << (chan-1)) ) )
3168 if (orinoco_lock(priv, &flags) != 0)
3171 priv->channel = chan;
3172 if (priv->iw_mode == IW_MODE_MONITOR) {
3173 /* Fast channel change - no commit if successful */
3174 hermes_t *hw = &priv->hw;
3175 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3176 HERMES_TEST_SET_CHANNEL,
3179 orinoco_unlock(priv, &flags);
3184 static int orinoco_ioctl_getfreq(struct net_device *dev,
3185 struct iw_request_info *info,
3186 struct iw_freq *frq,
3189 struct orinoco_private *priv = netdev_priv(dev);
3192 /* Locking done in there */
3193 tmp = orinoco_hw_get_freq(priv);
3204 static int orinoco_ioctl_getsens(struct net_device *dev,
3205 struct iw_request_info *info,
3206 struct iw_param *srq,
3209 struct orinoco_private *priv = netdev_priv(dev);
3210 hermes_t *hw = &priv->hw;
3213 unsigned long flags;
3215 if (!priv->has_sensitivity)
3218 if (orinoco_lock(priv, &flags) != 0)
3220 err = hermes_read_wordrec(hw, USER_BAP,
3221 HERMES_RID_CNFSYSTEMSCALE, &val);
3222 orinoco_unlock(priv, &flags);
3228 srq->fixed = 0; /* auto */
3233 static int orinoco_ioctl_setsens(struct net_device *dev,
3234 struct iw_request_info *info,
3235 struct iw_param *srq,
3238 struct orinoco_private *priv = netdev_priv(dev);
3239 int val = srq->value;
3240 unsigned long flags;
3242 if (!priv->has_sensitivity)
3245 if ((val < 1) || (val > 3))
3248 if (orinoco_lock(priv, &flags) != 0)
3250 priv->ap_density = val;
3251 orinoco_unlock(priv, &flags);
3253 return -EINPROGRESS; /* Call commit handler */
3256 static int orinoco_ioctl_setrts(struct net_device *dev,
3257 struct iw_request_info *info,
3258 struct iw_param *rrq,
3261 struct orinoco_private *priv = netdev_priv(dev);
3262 int val = rrq->value;
3263 unsigned long flags;
3268 if ( (val < 0) || (val > 2347) )
3271 if (orinoco_lock(priv, &flags) != 0)
3274 priv->rts_thresh = val;
3275 orinoco_unlock(priv, &flags);
3277 return -EINPROGRESS; /* Call commit handler */
3280 static int orinoco_ioctl_getrts(struct net_device *dev,
3281 struct iw_request_info *info,
3282 struct iw_param *rrq,
3285 struct orinoco_private *priv = netdev_priv(dev);
3287 rrq->value = priv->rts_thresh;
3288 rrq->disabled = (rrq->value == 2347);
3294 static int orinoco_ioctl_setfrag(struct net_device *dev,
3295 struct iw_request_info *info,
3296 struct iw_param *frq,
3299 struct orinoco_private *priv = netdev_priv(dev);
3300 int err = -EINPROGRESS; /* Call commit handler */
3301 unsigned long flags;
3303 if (orinoco_lock(priv, &flags) != 0)
3306 if (priv->has_mwo) {
3308 priv->mwo_robust = 0;
3311 printk(KERN_WARNING "%s: Fixed fragmentation is "
3312 "not supported on this firmware. "
3313 "Using MWO robust instead.\n", dev->name);
3314 priv->mwo_robust = 1;
3318 priv->frag_thresh = 2346;
3320 if ( (frq->value < 256) || (frq->value > 2346) )
3323 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3327 orinoco_unlock(priv, &flags);
3332 static int orinoco_ioctl_getfrag(struct net_device *dev,
3333 struct iw_request_info *info,
3334 struct iw_param *frq,
3337 struct orinoco_private *priv = netdev_priv(dev);
3338 hermes_t *hw = &priv->hw;
3341 unsigned long flags;
3343 if (orinoco_lock(priv, &flags) != 0)
3346 if (priv->has_mwo) {
3347 err = hermes_read_wordrec(hw, USER_BAP,
3348 HERMES_RID_CNFMWOROBUST_AGERE,
3353 frq->value = val ? 2347 : 0;
3354 frq->disabled = ! val;
3357 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3363 frq->disabled = (val >= 2346);
3367 orinoco_unlock(priv, &flags);
3372 static int orinoco_ioctl_setrate(struct net_device *dev,
3373 struct iw_request_info *info,
3374 struct iw_param *rrq,
3377 struct orinoco_private *priv = netdev_priv(dev);
3379 int bitrate; /* 100s of kilobits */
3381 unsigned long flags;
3383 /* As the user space doesn't know our highest rate, it uses -1
3384 * to ask us to set the highest rate. Test it using "iwconfig
3385 * ethX rate auto" - Jean II */
3386 if (rrq->value == -1)
3389 if (rrq->value % 100000)
3391 bitrate = rrq->value / 100000;
3394 if ( (bitrate != 10) && (bitrate != 20) &&
3395 (bitrate != 55) && (bitrate != 110) )
3398 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3399 if ( (bitrate_table[i].bitrate == bitrate) &&
3400 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3408 if (orinoco_lock(priv, &flags) != 0)
3410 priv->bitratemode = ratemode;
3411 orinoco_unlock(priv, &flags);
3413 return -EINPROGRESS;
3416 static int orinoco_ioctl_getrate(struct net_device *dev,
3417 struct iw_request_info *info,
3418 struct iw_param *rrq,
3421 struct orinoco_private *priv = netdev_priv(dev);
3422 hermes_t *hw = &priv->hw;
3427 unsigned long flags;
3429 if (orinoco_lock(priv, &flags) != 0)
3432 ratemode = priv->bitratemode;
3434 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3436 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3437 rrq->fixed = ! bitrate_table[ratemode].automatic;
3440 /* If the interface is running we try to find more about the
3442 if (netif_running(dev)) {
3443 err = hermes_read_wordrec(hw, USER_BAP,
3444 HERMES_RID_CURRENTTXRATE, &val);
3448 switch (priv->firmware_type) {
3449 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3450 /* Note : in Lucent firmware, the return value of
3451 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3452 * and therefore is totally different from the
3453 * encoding of HERMES_RID_CNFTXRATECONTROL.
3454 * Don't forget that 6Mb/s is really 5.5Mb/s */
3456 rrq->value = 5500000;
3458 rrq->value = val * 1000000;
3460 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3461 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3462 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3463 if (bitrate_table[i].intersil_txratectrl == val) {
3467 if (i >= BITRATE_TABLE_SIZE)
3468 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3471 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3479 orinoco_unlock(priv, &flags);
3484 static int orinoco_ioctl_setpower(struct net_device *dev,
3485 struct iw_request_info *info,
3486 struct iw_param *prq,
3489 struct orinoco_private *priv = netdev_priv(dev);
3490 int err = -EINPROGRESS; /* Call commit handler */
3491 unsigned long flags;
3493 if (orinoco_lock(priv, &flags) != 0)
3496 if (prq->disabled) {
3499 switch (prq->flags & IW_POWER_MODE) {
3500 case IW_POWER_UNICAST_R:
3504 case IW_POWER_ALL_R:
3509 /* No flags : but we may have a value - Jean II */
3516 if (prq->flags & IW_POWER_TIMEOUT) {
3518 priv->pm_timeout = prq->value / 1000;
3520 if (prq->flags & IW_POWER_PERIOD) {
3522 priv->pm_period = prq->value / 1000;
3524 /* It's valid to not have a value if we are just toggling
3525 * the flags... Jean II */
3533 orinoco_unlock(priv, &flags);
3538 static int orinoco_ioctl_getpower(struct net_device *dev,
3539 struct iw_request_info *info,
3540 struct iw_param *prq,
3543 struct orinoco_private *priv = netdev_priv(dev);
3544 hermes_t *hw = &priv->hw;
3546 u16 enable, period, timeout, mcast;
3547 unsigned long flags;
3549 if (orinoco_lock(priv, &flags) != 0)
3552 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3556 err = hermes_read_wordrec(hw, USER_BAP,
3557 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3565 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3569 prq->disabled = !enable;
3570 /* Note : by default, display the period */
3571 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3572 prq->flags = IW_POWER_TIMEOUT;
3573 prq->value = timeout * 1000;
3575 prq->flags = IW_POWER_PERIOD;
3576 prq->value = period * 1000;
3579 prq->flags |= IW_POWER_ALL_R;
3581 prq->flags |= IW_POWER_UNICAST_R;
3584 orinoco_unlock(priv, &flags);
3589 static int orinoco_ioctl_getretry(struct net_device *dev,
3590 struct iw_request_info *info,
3591 struct iw_param *rrq,
3594 struct orinoco_private *priv = netdev_priv(dev);
3595 hermes_t *hw = &priv->hw;
3597 u16 short_limit, long_limit, lifetime;
3598 unsigned long flags;
3600 if (orinoco_lock(priv, &flags) != 0)
3603 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3608 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3613 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3618 rrq->disabled = 0; /* Can't be disabled */
3620 /* Note : by default, display the retry number */
3621 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3622 rrq->flags = IW_RETRY_LIFETIME;
3623 rrq->value = lifetime * 1000; /* ??? */
3625 /* By default, display the min number */
3626 if ((rrq->flags & IW_RETRY_MAX)) {
3627 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3628 rrq->value = long_limit;
3630 rrq->flags = IW_RETRY_LIMIT;
3631 rrq->value = short_limit;
3632 if(short_limit != long_limit)
3633 rrq->flags |= IW_RETRY_MIN;
3638 orinoco_unlock(priv, &flags);
3643 static int orinoco_ioctl_reset(struct net_device *dev,
3644 struct iw_request_info *info,
3648 struct orinoco_private *priv = netdev_priv(dev);
3650 if (! capable(CAP_NET_ADMIN))
3653 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3654 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3656 /* Firmware reset */
3659 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3661 schedule_work(&priv->reset_work);
3667 static int orinoco_ioctl_setibssport(struct net_device *dev,
3668 struct iw_request_info *info,
3673 struct orinoco_private *priv = netdev_priv(dev);
3674 int val = *( (int *) extra );
3675 unsigned long flags;
3677 if (orinoco_lock(priv, &flags) != 0)
3680 priv->ibss_port = val ;
3682 /* Actually update the mode we are using */
3683 set_port_type(priv);
3685 orinoco_unlock(priv, &flags);
3686 return -EINPROGRESS; /* Call commit handler */
3689 static int orinoco_ioctl_getibssport(struct net_device *dev,
3690 struct iw_request_info *info,
3694 struct orinoco_private *priv = netdev_priv(dev);
3695 int *val = (int *) extra;
3697 *val = priv->ibss_port;
3701 static int orinoco_ioctl_setport3(struct net_device *dev,
3702 struct iw_request_info *info,
3706 struct orinoco_private *priv = netdev_priv(dev);
3707 int val = *( (int *) extra );
3709 unsigned long flags;
3711 if (orinoco_lock(priv, &flags) != 0)
3715 case 0: /* Try to do IEEE ad-hoc mode */
3716 if (! priv->has_ibss) {
3720 priv->prefer_port3 = 0;
3724 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3725 if (! priv->has_port3) {
3729 priv->prefer_port3 = 1;
3737 /* Actually update the mode we are using */
3738 set_port_type(priv);
3742 orinoco_unlock(priv, &flags);
3747 static int orinoco_ioctl_getport3(struct net_device *dev,
3748 struct iw_request_info *info,
3752 struct orinoco_private *priv = netdev_priv(dev);
3753 int *val = (int *) extra;
3755 *val = priv->prefer_port3;
3759 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3760 struct iw_request_info *info,
3764 struct orinoco_private *priv = netdev_priv(dev);
3765 unsigned long flags;
3768 if (! priv->has_preamble)
3771 /* 802.11b has recently defined some short preamble.
3772 * Basically, the Phy header has been reduced in size.
3773 * This increase performance, especially at high rates
3774 * (the preamble is transmitted at 1Mb/s), unfortunately
3775 * this give compatibility troubles... - Jean II */
3776 val = *( (int *) extra );
3778 if (orinoco_lock(priv, &flags) != 0)
3786 orinoco_unlock(priv, &flags);
3788 return -EINPROGRESS; /* Call commit handler */
3791 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3792 struct iw_request_info *info,
3796 struct orinoco_private *priv = netdev_priv(dev);
3797 int *val = (int *) extra;
3799 if (! priv->has_preamble)
3802 *val = priv->preamble;
3806 /* ioctl interface to hermes_read_ltv()
3807 * To use with iwpriv, pass the RID as the token argument, e.g.
3808 * iwpriv get_rid [0xfc00]
3809 * At least Wireless Tools 25 is required to use iwpriv.
3810 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3811 static int orinoco_ioctl_getrid(struct net_device *dev,
3812 struct iw_request_info *info,
3813 struct iw_point *data,
3816 struct orinoco_private *priv = netdev_priv(dev);
3817 hermes_t *hw = &priv->hw;
3818 int rid = data->flags;
3821 unsigned long flags;
3823 /* It's a "get" function, but we don't want users to access the
3824 * WEP key and other raw firmware data */
3825 if (! capable(CAP_NET_ADMIN))
3828 if (rid < 0xfc00 || rid > 0xffff)
3831 if (orinoco_lock(priv, &flags) != 0)
3834 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3839 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3843 orinoco_unlock(priv, &flags);
3847 /* Trigger a scan (look for other cells in the vicinity */
3848 static int orinoco_ioctl_setscan(struct net_device *dev,
3849 struct iw_request_info *info,
3850 struct iw_param *srq,
3853 struct orinoco_private *priv = netdev_priv(dev);
3854 hermes_t *hw = &priv->hw;
3856 unsigned long flags;
3858 /* Note : you may have realised that, as this is a SET operation,
3859 * this is privileged and therefore a normal user can't
3861 * This is not an error, while the device perform scanning,
3862 * traffic doesn't flow, so it's a perfect DoS...
3865 if (orinoco_lock(priv, &flags) != 0)
3868 /* Scanning with port 0 disabled would fail */
3869 if (!netif_running(dev)) {
3874 /* In monitor mode, the scan results are always empty.
3875 * Probe responses are passed to the driver as received
3876 * frames and could be processed in software. */
3877 if (priv->iw_mode == IW_MODE_MONITOR) {
3882 /* Note : because we don't lock out the irq handler, the way
3883 * we access scan variables in priv is critical.
3884 * o scan_inprogress : not touched by irq handler
3885 * o scan_mode : not touched by irq handler
3886 * o scan_result : irq is strict producer, non-irq is strict
3888 * o scan_len : synchronised with scan_result
3889 * Before modifying anything on those variables, please think hard !
3892 /* If there is still some left-over scan results, get rid of it */
3893 if (priv->scan_result != NULL) {
3894 /* What's likely is that a client did crash or was killed
3895 * between triggering the scan request and reading the
3896 * results, so we need to reset everything.
3897 * Some clients that are too slow may suffer from that...
3899 kfree(priv->scan_result);
3900 priv->scan_result = NULL;
3904 priv->scan_mode = srq->flags;
3906 /* Always trigger scanning, even if it's in progress.
3907 * This way, if the info frame get lost, we will recover somewhat
3908 * gracefully - Jean II */
3910 if (priv->has_hostscan) {
3911 switch (priv->firmware_type) {
3912 case FIRMWARE_TYPE_SYMBOL:
3913 err = hermes_write_wordrec(hw, USER_BAP,
3914 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3915 HERMES_HOSTSCAN_SYMBOL_ONCE |
3916 HERMES_HOSTSCAN_SYMBOL_BCAST);
3918 case FIRMWARE_TYPE_INTERSIL: {
3921 req[0] = cpu_to_le16(0x3fff); /* All channels */
3922 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3923 req[2] = 0; /* Any ESSID */
3924 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3925 HERMES_RID_CNFHOSTSCAN, &req);
3928 case FIRMWARE_TYPE_AGERE:
3929 err = hermes_write_wordrec(hw, USER_BAP,
3930 HERMES_RID_CNFSCANSSID_AGERE,
3935 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3939 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3941 /* One more client */
3943 priv->scan_inprogress = 1;
3946 orinoco_unlock(priv, &flags);
3950 /* Translate scan data returned from the card to a card independant
3951 * format that the Wireless Tools will understand - Jean II
3952 * Return message length or -errno for fatal errors */
3953 static inline int orinoco_translate_scan(struct net_device *dev,
3958 struct orinoco_private *priv = netdev_priv(dev);
3959 int offset; /* In the scan data */
3960 union hermes_scan_info *atom;
3964 struct iw_event iwe; /* Temporary buffer */
3965 char * current_ev = buffer;
3966 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3968 switch (priv->firmware_type) {
3969 case FIRMWARE_TYPE_AGERE:
3970 atom_len = sizeof(struct agere_scan_apinfo);
3973 case FIRMWARE_TYPE_SYMBOL:
3974 /* Lack of documentation necessitates this hack.
3975 * Different firmwares have 68 or 76 byte long atoms.
3976 * We try modulo first. If the length divides by both,
3977 * we check what would be the channel in the second
3978 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3979 * Valid channel cannot be 0. */
3982 else if (scan_len % 68)
3984 else if (scan_len >= 1292 && scan[68] == 0)
3990 case FIRMWARE_TYPE_INTERSIL:
3992 if (priv->has_hostscan) {
3993 atom_len = le16_to_cpup((__le16 *)scan);
3994 /* Sanity check for atom_len */
3995 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3996 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3997 dev->name, atom_len);
4001 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4007 /* Check that we got an whole number of atoms */
4008 if ((scan_len - offset) % atom_len) {
4009 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4010 "atom_len %d, offset %d\n", dev->name, scan_len,
4015 /* Read the entries one by one */
4016 for (; offset + atom_len <= scan_len; offset += atom_len) {
4018 atom = (union hermes_scan_info *) (scan + offset);
4020 /* First entry *MUST* be the AP MAC address */
4021 iwe.cmd = SIOCGIWAP;
4022 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4023 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4024 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4026 /* Other entries will be displayed in the order we give them */
4029 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4030 if (iwe.u.data.length > 32)
4031 iwe.u.data.length = 32;
4032 iwe.cmd = SIOCGIWESSID;
4033 iwe.u.data.flags = 1;
4034 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4037 iwe.cmd = SIOCGIWMODE;
4038 capabilities = le16_to_cpu(atom->a.capabilities);
4039 if (capabilities & 0x3) {
4040 if (capabilities & 0x1)
4041 iwe.u.mode = IW_MODE_MASTER;
4043 iwe.u.mode = IW_MODE_ADHOC;
4044 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4047 channel = atom->s.channel;
4048 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4050 iwe.cmd = SIOCGIWFREQ;
4051 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4053 current_ev = iwe_stream_add_event(current_ev, end_buf,
4054 &iwe, IW_EV_FREQ_LEN);
4057 /* Add quality statistics */
4059 iwe.u.qual.updated = 0x10; /* no link quality */
4060 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4061 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4062 /* Wireless tools prior to 27.pre22 will show link quality
4063 * anyway, so we provide a reasonable value. */
4064 if (iwe.u.qual.level > iwe.u.qual.noise)
4065 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4067 iwe.u.qual.qual = 0;
4068 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4070 /* Add encryption capability */
4071 iwe.cmd = SIOCGIWENCODE;
4072 if (capabilities & 0x10)
4073 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4075 iwe.u.data.flags = IW_ENCODE_DISABLED;
4076 iwe.u.data.length = 0;
4077 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4079 /* Bit rate is not available in Lucent/Agere firmwares */
4080 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4081 char * current_val = current_ev + IW_EV_LCP_LEN;
4085 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4090 iwe.cmd = SIOCGIWRATE;
4091 /* Those two flags are ignored... */
4092 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4094 for (i = 0; i < 10; i += step) {
4095 /* NULL terminated */
4096 if (atom->p.rates[i] == 0x0)
4098 /* Bit rate given in 500 kb/s units (+ 0x80) */
4099 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4100 current_val = iwe_stream_add_value(current_ev, current_val,
4104 /* Check if we added any event */
4105 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4106 current_ev = current_val;
4109 /* The other data in the scan result are not really
4110 * interesting, so for now drop it - Jean II */
4112 return current_ev - buffer;
4115 /* Return results of a scan */
4116 static int orinoco_ioctl_getscan(struct net_device *dev,
4117 struct iw_request_info *info,
4118 struct iw_point *srq,
4121 struct orinoco_private *priv = netdev_priv(dev);
4123 unsigned long flags;
4125 if (orinoco_lock(priv, &flags) != 0)
4128 /* If no results yet, ask to try again later */
4129 if (priv->scan_result == NULL) {
4130 if (priv->scan_inprogress)
4131 /* Important note : we don't want to block the caller
4132 * until results are ready for various reasons.
4133 * First, managing wait queues is complex and racy.
4134 * Second, we grab some rtnetlink lock before comming
4135 * here (in dev_ioctl()).
4136 * Third, we generate an Wireless Event, so the
4137 * caller can wait itself on that - Jean II */
4140 /* Client error, no scan results...
4141 * The caller need to restart the scan. */
4144 /* We have some results to push back to user space */
4146 /* Translate to WE format */
4147 int ret = orinoco_translate_scan(dev, extra,
4153 kfree(priv->scan_result);
4154 priv->scan_result = NULL;
4159 srq->flags = (__u16) priv->scan_mode;
4161 /* In any case, Scan results will be cleaned up in the
4162 * reset function and when exiting the driver.
4163 * The person triggering the scanning may never come to
4164 * pick the results, so we need to do it in those places.
4167 #ifdef SCAN_SINGLE_READ
4168 /* If you enable this option, only one client (the first
4169 * one) will be able to read the result (and only one
4170 * time). If there is multiple concurent clients that
4171 * want to read scan results, this behavior is not
4172 * advisable - Jean II */
4173 kfree(priv->scan_result);
4174 priv->scan_result = NULL;
4175 #endif /* SCAN_SINGLE_READ */
4176 /* Here, if too much time has elapsed since last scan,
4177 * we may want to clean up scan results... - Jean II */
4180 /* Scan is no longer in progress */
4181 priv->scan_inprogress = 0;
4184 orinoco_unlock(priv, &flags);
4188 /* Commit handler, called after set operations */
4189 static int orinoco_ioctl_commit(struct net_device *dev,
4190 struct iw_request_info *info,
4194 struct orinoco_private *priv = netdev_priv(dev);
4195 struct hermes *hw = &priv->hw;
4196 unsigned long flags;
4202 if (priv->broken_disableport) {
4207 if (orinoco_lock(priv, &flags) != 0)
4210 err = hermes_disable_port(hw, 0);
4212 printk(KERN_WARNING "%s: Unable to disable port "
4213 "while reconfiguring card\n", dev->name);
4214 priv->broken_disableport = 1;
4218 err = __orinoco_program_rids(dev);
4220 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4225 err = hermes_enable_port(hw, 0);
4227 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4234 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4235 schedule_work(&priv->reset_work);
4239 orinoco_unlock(priv, &flags);
4243 static const struct iw_priv_args orinoco_privtab[] = {
4244 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4245 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4246 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4248 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4250 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4251 0, "set_preamble" },
4252 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4254 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4255 0, "set_ibssport" },
4256 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4258 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4264 * Structures to export the Wireless Handlers
4267 static const iw_handler orinoco_handler[] = {
4268 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4269 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4270 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4271 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4272 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4273 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4274 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4275 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4276 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4277 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4278 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4279 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4280 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4281 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4282 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4283 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4284 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4285 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4286 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4287 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4288 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4289 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4290 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4291 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4292 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4293 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4294 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4295 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4296 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4297 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4298 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4299 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4304 Added typecasting since we no longer use iwreq_data -- Moustafa
4306 static const iw_handler orinoco_private_handler[] = {
4307 [0] = (iw_handler) orinoco_ioctl_reset,
4308 [1] = (iw_handler) orinoco_ioctl_reset,
4309 [2] = (iw_handler) orinoco_ioctl_setport3,
4310 [3] = (iw_handler) orinoco_ioctl_getport3,
4311 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4312 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4313 [6] = (iw_handler) orinoco_ioctl_setibssport,
4314 [7] = (iw_handler) orinoco_ioctl_getibssport,
4315 [9] = (iw_handler) orinoco_ioctl_getrid,
4318 static const struct iw_handler_def orinoco_handler_def = {
4319 .num_standard = ARRAY_SIZE(orinoco_handler),
4320 .num_private = ARRAY_SIZE(orinoco_private_handler),
4321 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4322 .standard = orinoco_handler,
4323 .private = orinoco_private_handler,
4324 .private_args = orinoco_privtab,
4325 .get_wireless_stats = orinoco_get_wireless_stats,
4328 static void orinoco_get_drvinfo(struct net_device *dev,
4329 struct ethtool_drvinfo *info)
4331 struct orinoco_private *priv = netdev_priv(dev);
4333 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4334 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4335 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4336 if (dev->class_dev.dev)
4337 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4338 sizeof(info->bus_info) - 1);
4340 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4341 "PCMCIA %p", priv->hw.iobase);
4344 static struct ethtool_ops orinoco_ethtool_ops = {
4345 .get_drvinfo = orinoco_get_drvinfo,
4346 .get_link = ethtool_op_get_link,
4349 /********************************************************************/
4351 /********************************************************************/
4354 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4356 printk(KERN_DEBUG "RX descriptor:\n");
4357 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4358 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4359 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4360 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4361 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4362 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4363 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4365 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4366 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4367 frame->p80211.frame_ctl);
4368 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4369 frame->p80211.duration_id);
4370 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4371 frame->p80211.addr1[0], frame->p80211.addr1[1],
4372 frame->p80211.addr1[2], frame->p80211.addr1[3],
4373 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4374 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4375 frame->p80211.addr2[0], frame->p80211.addr2[1],
4376 frame->p80211.addr2[2], frame->p80211.addr2[3],
4377 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4378 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4379 frame->p80211.addr3[0], frame->p80211.addr3[1],
4380 frame->p80211.addr3[2], frame->p80211.addr3[3],
4381 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4382 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4383 frame->p80211.seq_ctl);
4384 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4385 frame->p80211.addr4[0], frame->p80211.addr4[1],
4386 frame->p80211.addr4[2], frame->p80211.addr4[3],
4387 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4388 printk(KERN_DEBUG " data_len = 0x%04x\n",
4389 frame->p80211.data_len);
4391 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4392 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4393 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4394 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4395 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4396 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4397 frame->p8023.h_source[0], frame->p8023.h_source[1],
4398 frame->p8023.h_source[2], frame->p8023.h_source[3],
4399 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4400 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4402 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4403 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4404 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4405 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4406 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4407 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4408 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4412 /********************************************************************/
4413 /* Module initialization */
4414 /********************************************************************/
4416 EXPORT_SYMBOL(alloc_orinocodev);
4417 EXPORT_SYMBOL(free_orinocodev);
4419 EXPORT_SYMBOL(__orinoco_up);
4420 EXPORT_SYMBOL(__orinoco_down);
4421 EXPORT_SYMBOL(orinoco_reinit_firmware);
4423 EXPORT_SYMBOL(orinoco_interrupt);
4425 /* Can't be declared "const" or the whole __initdata section will
4427 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4428 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4429 "Pavel Roskin <proski@gnu.org>, et al)";
4431 static int __init init_orinoco(void)
4433 printk(KERN_DEBUG "%s\n", version);
4437 static void __exit exit_orinoco(void)
4441 module_init(init_orinoco);
4442 module_exit(exit_orinoco);