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>
81 #include <linux/module.h>
82 #include <linux/kernel.h>
83 #include <linux/init.h>
84 #include <linux/ptrace.h>
85 #include <linux/slab.h>
86 #include <linux/string.h>
87 #include <linux/timer.h>
88 #include <linux/ioport.h>
89 #include <linux/netdevice.h>
90 #include <linux/if_arp.h>
91 #include <linux/etherdevice.h>
92 #include <linux/ethtool.h>
93 #include <linux/wireless.h>
94 #include <net/iw_handler.h>
95 #include <net/ieee80211.h>
97 #include <net/ieee80211.h>
99 #include <asm/uaccess.h>
101 #include <asm/system.h>
104 #include "hermes_rid.h"
107 /********************************************************************/
108 /* Module information */
109 /********************************************************************/
111 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
112 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
113 MODULE_LICENSE("Dual MPL/GPL");
115 /* Level of debugging. Used in the macros in orinoco.h */
117 int orinoco_debug = ORINOCO_DEBUG;
118 module_param(orinoco_debug, int, 0644);
119 MODULE_PARM_DESC(orinoco_debug, "Debug level");
120 EXPORT_SYMBOL(orinoco_debug);
123 static int suppress_linkstatus; /* = 0 */
124 module_param(suppress_linkstatus, bool, 0644);
125 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
126 static int ignore_disconnect; /* = 0 */
127 module_param(ignore_disconnect, int, 0644);
128 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
130 static int force_monitor; /* = 0 */
131 module_param(force_monitor, int, 0644);
132 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
134 /********************************************************************/
135 /* Compile time configuration and compatibility stuff */
136 /********************************************************************/
138 /* We do this this way to avoid ifdefs in the actual code */
140 #define SPY_NUMBER(priv) (priv->spy_number)
142 #define SPY_NUMBER(priv) 0
143 #endif /* WIRELESS_SPY */
145 /********************************************************************/
146 /* Internal constants */
147 /********************************************************************/
149 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
150 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
151 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
153 #define ORINOCO_MIN_MTU 256
154 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
156 #define SYMBOL_MAX_VER_LEN (14)
159 #define MAX_IRQLOOPS_PER_IRQ 10
160 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
161 * how many events the
163 * legitimately generate */
164 #define SMALL_KEY_SIZE 5
165 #define LARGE_KEY_SIZE 13
166 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
168 #define DUMMY_FID 0xFFFF
170 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
171 HERMES_MAX_MULTICAST : 0)*/
172 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
174 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
175 | HERMES_EV_TX | HERMES_EV_TXEXC \
176 | HERMES_EV_WTERR | HERMES_EV_INFO \
177 | HERMES_EV_INFDROP )
179 #define MAX_RID_LEN 1024
181 static const struct iw_handler_def orinoco_handler_def;
182 static struct ethtool_ops orinoco_ethtool_ops;
184 /********************************************************************/
186 /********************************************************************/
188 /* The frequency of each channel in MHz */
189 static const long channel_frequency[] = {
190 2412, 2417, 2422, 2427, 2432, 2437, 2442,
191 2447, 2452, 2457, 2462, 2467, 2472, 2484
193 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
195 /* This tables gives the actual meanings of the bitrate IDs returned
196 * by the firmware. */
198 int bitrate; /* in 100s of kilobits */
200 u16 agere_txratectrl;
201 u16 intersil_txratectrl;
202 } bitrate_table[] = {
203 {110, 1, 3, 15}, /* Entry 0 is the default */
212 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
214 /********************************************************************/
216 /********************************************************************/
218 /* Used in Event handling.
219 * We avoid nested structres as they break on ARM -- Moustafa */
220 struct hermes_tx_descriptor_802_11 {
221 /* hermes_tx_descriptor */
241 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
242 unsigned char h_source[ETH_ALEN]; /* source ether addr */
243 unsigned short h_proto; /* packet type ID field */
252 } __attribute__ ((packed));
254 /* Rx frame header except compatibility 802.3 header */
255 struct hermes_rx_descriptor {
276 } __attribute__ ((packed));
278 /********************************************************************/
279 /* Function prototypes */
280 /********************************************************************/
282 static int __orinoco_program_rids(struct net_device *dev);
283 static void __orinoco_set_multicast_list(struct net_device *dev);
285 /********************************************************************/
286 /* Internal helper functions */
287 /********************************************************************/
289 static inline void set_port_type(struct orinoco_private *priv)
291 switch (priv->iw_mode) {
294 priv->createibss = 0;
297 if (priv->prefer_port3) {
299 priv->createibss = 0;
301 priv->port_type = priv->ibss_port;
302 priv->createibss = 1;
305 case IW_MODE_MONITOR:
307 priv->createibss = 0;
310 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
315 /********************************************************************/
317 /********************************************************************/
319 static int orinoco_open(struct net_device *dev)
321 struct orinoco_private *priv = netdev_priv(dev);
325 if (orinoco_lock(priv, &flags) != 0)
328 err = __orinoco_up(dev);
333 orinoco_unlock(priv, &flags);
338 static int orinoco_stop(struct net_device *dev)
340 struct orinoco_private *priv = netdev_priv(dev);
343 /* We mustn't use orinoco_lock() here, because we need to be
344 able to close the interface even if hw_unavailable is set
345 (e.g. as we're released after a PC Card removal) */
346 spin_lock_irq(&priv->lock);
350 err = __orinoco_down(dev);
352 spin_unlock_irq(&priv->lock);
357 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
359 struct orinoco_private *priv = netdev_priv(dev);
364 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
366 struct orinoco_private *priv = netdev_priv(dev);
367 hermes_t *hw = &priv->hw;
368 struct iw_statistics *wstats = &priv->wstats;
372 if (! netif_device_present(dev)) {
373 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
375 return NULL; /* FIXME: Can we do better than this? */
378 /* If busy, return the old stats. Returning NULL may cause
379 * the interface to disappear from /proc/net/wireless */
380 if (orinoco_lock(priv, &flags) != 0)
383 /* We can't really wait for the tallies inquiry command to
384 * complete, so we just use the previous results and trigger
385 * a new tallies inquiry command for next time - Jean II */
386 /* FIXME: Really we should wait for the inquiry to come back -
387 * as it is the stats we give don't make a whole lot of sense.
388 * Unfortunately, it's not clear how to do that within the
389 * wireless extensions framework: I think we're in user
390 * context, but a lock seems to be held by the time we get in
391 * here so we're not safe to sleep here. */
392 hermes_inquire(hw, HERMES_INQ_TALLIES);
394 if (priv->iw_mode == IW_MODE_ADHOC) {
395 memset(&wstats->qual, 0, sizeof(wstats->qual));
396 /* If a spy address is defined, we report stats of the
397 * first spy address - Jean II */
398 if (SPY_NUMBER(priv)) {
399 wstats->qual.qual = priv->spy_stat[0].qual;
400 wstats->qual.level = priv->spy_stat[0].level;
401 wstats->qual.noise = priv->spy_stat[0].noise;
402 wstats->qual.updated = priv->spy_stat[0].updated;
406 u16 qual, signal, noise;
407 } __attribute__ ((packed)) cq;
409 err = HERMES_READ_RECORD(hw, USER_BAP,
410 HERMES_RID_COMMSQUALITY, &cq);
413 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
414 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
415 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
416 wstats->qual.updated = 7;
420 orinoco_unlock(priv, &flags);
424 static void orinoco_set_multicast_list(struct net_device *dev)
426 struct orinoco_private *priv = netdev_priv(dev);
429 if (orinoco_lock(priv, &flags) != 0) {
430 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
431 "called when hw_unavailable\n", dev->name);
435 __orinoco_set_multicast_list(dev);
436 orinoco_unlock(priv, &flags);
439 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
441 struct orinoco_private *priv = netdev_priv(dev);
443 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
446 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
447 (priv->nicbuf_size - ETH_HLEN) )
455 /********************************************************************/
457 /********************************************************************/
459 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
461 struct orinoco_private *priv = netdev_priv(dev);
462 struct net_device_stats *stats = &priv->stats;
463 hermes_t *hw = &priv->hw;
465 u16 txfid = priv->txfid;
468 int len, data_len, data_off;
469 struct hermes_tx_descriptor desc;
472 TRACE_ENTER(dev->name);
474 if (! netif_running(dev)) {
475 printk(KERN_ERR "%s: Tx on stopped device!\n",
477 TRACE_EXIT(dev->name);
481 if (netif_queue_stopped(dev)) {
482 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
484 TRACE_EXIT(dev->name);
488 if (orinoco_lock(priv, &flags) != 0) {
489 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
491 TRACE_EXIT(dev->name);
495 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
496 /* Oops, the firmware hasn't established a connection,
497 silently drop the packet (this seems to be the
500 orinoco_unlock(priv, &flags);
502 TRACE_EXIT(dev->name);
506 /* Check packet length, pad short packets, round up odd length */
507 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
508 if (skb->len < len) {
509 skb = skb_padto(skb, len);
515 eh = (struct ethhdr *)skb->data;
517 memset(&desc, 0, sizeof(desc));
518 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
519 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
522 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
523 "to BAP\n", dev->name, err);
528 /* Clear the 802.11 header and data length fields - some
529 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
530 * if this isn't done. */
531 hermes_clear_words(hw, HERMES_DATA0,
532 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
534 /* Encapsulate Ethernet-II frames */
535 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
536 struct header_struct hdr;
538 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
539 p = skb->data + ETH_HLEN;
542 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
543 memcpy(hdr.src, eh->h_source, ETH_ALEN);
544 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
547 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
549 hdr.ethertype = eh->h_proto;
550 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
551 txfid, HERMES_802_3_OFFSET);
554 printk(KERN_ERR "%s: Error %d writing packet "
555 "header to BAP\n", dev->name, err);
559 } else { /* IEEE 802.3 frame */
560 data_len = len + ETH_HLEN;
561 data_off = HERMES_802_3_OFFSET;
565 err = hermes_bap_pwrite(hw, USER_BAP, p, data_len,
568 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
574 /* Finally, we actually initiate the send */
575 netif_stop_queue(dev);
577 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
580 netif_start_queue(dev);
581 printk(KERN_ERR "%s: Error %d transmitting packet\n",
587 dev->trans_start = jiffies;
588 stats->tx_bytes += data_off + data_len;
590 orinoco_unlock(priv, &flags);
594 TRACE_EXIT(dev->name);
598 TRACE_EXIT(dev->name);
600 orinoco_unlock(priv, &flags);
604 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
606 struct orinoco_private *priv = netdev_priv(dev);
607 u16 fid = hermes_read_regn(hw, ALLOCFID);
609 if (fid != priv->txfid) {
610 if (fid != DUMMY_FID)
611 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
616 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
619 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
621 struct orinoco_private *priv = netdev_priv(dev);
622 struct net_device_stats *stats = &priv->stats;
626 netif_wake_queue(dev);
628 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
631 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
633 struct orinoco_private *priv = netdev_priv(dev);
634 struct net_device_stats *stats = &priv->stats;
635 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
636 struct hermes_tx_descriptor_802_11 hdr;
639 if (fid == DUMMY_FID)
640 return; /* Nothing's really happened */
642 /* Read the frame header */
643 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
644 sizeof(struct hermes_tx_descriptor) +
645 sizeof(struct ieee80211_hdr),
648 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
652 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
653 "(FID=%04X error %d)\n",
654 dev->name, fid, err);
658 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
661 /* We produce a TXDROP event only for retry or lifetime
662 * exceeded, because that's the only status that really mean
663 * that this particular node went away.
664 * Other errors means that *we* screwed up. - Jean II */
665 hdr.status = le16_to_cpu(hdr.status);
666 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
667 union iwreq_data wrqu;
669 /* Copy 802.11 dest address.
670 * We use the 802.11 header because the frame may
671 * not be 802.3 or may be mangled...
672 * In Ad-Hoc mode, it will be the node address.
673 * In managed mode, it will be most likely the AP addr
674 * User space will figure out how to convert it to
675 * whatever it needs (IP address or else).
677 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
678 wrqu.addr.sa_family = ARPHRD_ETHER;
680 /* Send event to user space */
681 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
684 netif_wake_queue(dev);
687 static void orinoco_tx_timeout(struct net_device *dev)
689 struct orinoco_private *priv = netdev_priv(dev);
690 struct net_device_stats *stats = &priv->stats;
691 struct hermes *hw = &priv->hw;
693 printk(KERN_WARNING "%s: Tx timeout! "
694 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
695 dev->name, hermes_read_regn(hw, ALLOCFID),
696 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
700 schedule_work(&priv->reset_work);
703 /********************************************************************/
704 /* Rx path (data frames) */
705 /********************************************************************/
707 /* Does the frame have a SNAP header indicating it should be
708 * de-encapsulated to Ethernet-II? */
709 static inline int is_ethersnap(void *_hdr)
713 /* We de-encapsulate all packets which, a) have SNAP headers
714 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
715 * and where b) the OUI of the SNAP header is 00:00:00 or
716 * 00:00:f8 - we need both because different APs appear to use
717 * different OUIs for some reason */
718 return (memcmp(hdr, &encaps_hdr, 5) == 0)
719 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
722 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
723 int level, int noise)
725 struct orinoco_private *priv = netdev_priv(dev);
728 /* Gather wireless spy statistics: for each packet, compare the
729 * source address with out list, and if match, get the stats... */
730 for (i = 0; i < priv->spy_number; i++)
731 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
732 priv->spy_stat[i].level = level - 0x95;
733 priv->spy_stat[i].noise = noise - 0x95;
734 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
735 priv->spy_stat[i].updated = 7;
739 static void orinoco_stat_gather(struct net_device *dev,
741 struct hermes_rx_descriptor *desc)
743 struct orinoco_private *priv = netdev_priv(dev);
745 /* Using spy support with lots of Rx packets, like in an
746 * infrastructure (AP), will really slow down everything, because
747 * the MAC address must be compared to each entry of the spy list.
748 * If the user really asks for it (set some address in the
749 * spy list), we do it, but he will pay the price.
750 * Note that to get here, you need both WIRELESS_SPY
751 * compiled in AND some addresses in the list !!!
753 /* Note : gcc will optimise the whole section away if
754 * WIRELESS_SPY is not defined... - Jean II */
755 if (SPY_NUMBER(priv)) {
756 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
757 desc->signal, desc->silence);
762 * orinoco_rx_monitor - handle received monitor frames.
767 * desc rx descriptor of the frame
769 * Call context: interrupt
771 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
772 struct hermes_rx_descriptor *desc)
774 u32 hdrlen = 30; /* return full header by default */
780 struct orinoco_private *priv = netdev_priv(dev);
781 struct net_device_stats *stats = &priv->stats;
782 hermes_t *hw = &priv->hw;
784 len = le16_to_cpu(desc->data_len);
786 /* Determine the size of the header and the data */
787 fc = le16_to_cpu(desc->frame_ctl);
788 switch (fc & IEEE80211_FCTL_FTYPE) {
789 case IEEE80211_FTYPE_DATA:
790 if ((fc & IEEE80211_FCTL_TODS)
791 && (fc & IEEE80211_FCTL_FROMDS))
797 case IEEE80211_FTYPE_MGMT:
801 case IEEE80211_FTYPE_CTL:
802 switch (fc & IEEE80211_FCTL_STYPE) {
803 case IEEE80211_STYPE_PSPOLL:
804 case IEEE80211_STYPE_RTS:
805 case IEEE80211_STYPE_CFEND:
806 case IEEE80211_STYPE_CFENDACK:
809 case IEEE80211_STYPE_CTS:
810 case IEEE80211_STYPE_ACK:
816 /* Unknown frame type */
820 /* sanity check the length */
821 if (datalen > IEEE80211_DATA_LEN + 12) {
822 printk(KERN_DEBUG "%s: oversized monitor frame, "
823 "data length = %d\n", dev->name, datalen);
825 stats->rx_length_errors++;
829 skb = dev_alloc_skb(hdrlen + datalen);
831 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
837 /* Copy the 802.11 header to the skb */
838 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
839 skb->mac.raw = skb->data;
841 /* If any, copy the data from the card to the skb */
843 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
844 ALIGN(datalen, 2), rxfid,
845 HERMES_802_2_OFFSET);
847 printk(KERN_ERR "%s: error %d reading monitor frame\n",
854 skb->ip_summed = CHECKSUM_NONE;
855 skb->pkt_type = PACKET_OTHERHOST;
856 skb->protocol = __constant_htons(ETH_P_802_2);
858 dev->last_rx = jiffies;
860 stats->rx_bytes += skb->len;
866 dev_kfree_skb_irq(skb);
872 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
874 struct orinoco_private *priv = netdev_priv(dev);
875 struct net_device_stats *stats = &priv->stats;
876 struct iw_statistics *wstats = &priv->wstats;
877 struct sk_buff *skb = NULL;
878 u16 rxfid, status, fc;
880 struct hermes_rx_descriptor desc;
884 rxfid = hermes_read_regn(hw, RXFID);
886 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
889 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
890 "Frame dropped.\n", dev->name, err);
894 status = le16_to_cpu(desc.status);
896 if (status & HERMES_RXSTAT_BADCRC) {
897 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
899 stats->rx_crc_errors++;
903 /* Handle frames in monitor mode */
904 if (priv->iw_mode == IW_MODE_MONITOR) {
905 orinoco_rx_monitor(dev, rxfid, &desc);
909 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
910 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
912 wstats->discard.code++;
916 length = le16_to_cpu(desc.data_len);
917 fc = le16_to_cpu(desc.frame_ctl);
920 if (length < 3) { /* No for even an 802.2 LLC header */
921 /* At least on Symbol firmware with PCF we get quite a
922 lot of these legitimately - Poll frames with no
926 if (length > IEEE80211_DATA_LEN) {
927 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
929 stats->rx_length_errors++;
933 /* We need space for the packet data itself, plus an ethernet
934 header, plus 2 bytes so we can align the IP header on a
935 32bit boundary, plus 1 byte so we can read in odd length
936 packets from the card, which has an IO granularity of 16
938 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
940 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
945 /* We'll prepend the header, so reserve space for it. The worst
946 case is no decapsulation, when 802.3 header is prepended and
947 nothing is removed. 2 is for aligning the IP header. */
948 skb_reserve(skb, ETH_HLEN + 2);
950 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
951 ALIGN(length, 2), rxfid,
952 HERMES_802_2_OFFSET);
954 printk(KERN_ERR "%s: error %d reading frame. "
955 "Frame dropped.\n", dev->name, err);
959 /* Handle decapsulation
960 * In most cases, the firmware tell us about SNAP frames.
961 * For some reason, the SNAP frames sent by LinkSys APs
962 * are not properly recognised by most firmwares.
963 * So, check ourselves */
964 if (length >= ENCAPS_OVERHEAD &&
965 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
966 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
967 is_ethersnap(skb->data))) {
968 /* These indicate a SNAP within 802.2 LLC within
969 802.11 frame which we'll need to de-encapsulate to
970 the original EthernetII frame. */
971 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
973 /* 802.3 frame - prepend 802.3 header as is */
974 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
975 hdr->h_proto = htons(length);
977 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
978 if (fc & IEEE80211_FCTL_FROMDS)
979 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
981 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
983 dev->last_rx = jiffies;
985 skb->protocol = eth_type_trans(skb, dev);
986 skb->ip_summed = CHECKSUM_NONE;
987 if (fc & IEEE80211_FCTL_TODS)
988 skb->pkt_type = PACKET_OTHERHOST;
990 /* Process the wireless stats if needed */
991 orinoco_stat_gather(dev, skb, &desc);
993 /* Pass the packet to the networking stack */
996 stats->rx_bytes += length;
1001 dev_kfree_skb_irq(skb);
1004 stats->rx_dropped++;
1007 /********************************************************************/
1008 /* Rx path (info frames) */
1009 /********************************************************************/
1011 static void print_linkstatus(struct net_device *dev, u16 status)
1015 if (suppress_linkstatus)
1019 case HERMES_LINKSTATUS_NOT_CONNECTED:
1020 s = "Not Connected";
1022 case HERMES_LINKSTATUS_CONNECTED:
1025 case HERMES_LINKSTATUS_DISCONNECTED:
1028 case HERMES_LINKSTATUS_AP_CHANGE:
1031 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1032 s = "AP Out of Range";
1034 case HERMES_LINKSTATUS_AP_IN_RANGE:
1037 case HERMES_LINKSTATUS_ASSOC_FAILED:
1038 s = "Association Failed";
1044 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1045 dev->name, s, status);
1048 /* Search scan results for requested BSSID, join it if found */
1049 static void orinoco_join_ap(struct net_device *dev)
1051 struct orinoco_private *priv = netdev_priv(dev);
1052 struct hermes *hw = &priv->hw;
1054 unsigned long flags;
1058 } __attribute__ ((packed)) req;
1059 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1060 struct prism2_scan_apinfo *atom = NULL;
1066 /* Allocate buffer for scan results */
1067 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1071 if (orinoco_lock(priv, &flags) != 0)
1074 /* Sanity checks in case user changed something in the meantime */
1075 if (! priv->bssid_fixed)
1078 if (strlen(priv->desired_essid) == 0)
1081 /* Read scan results from the firmware */
1082 err = hermes_read_ltv(hw, USER_BAP,
1083 HERMES_RID_SCANRESULTSTABLE,
1084 MAX_SCAN_LEN, &len, buf);
1086 printk(KERN_ERR "%s: Cannot read scan results\n",
1091 len = HERMES_RECLEN_TO_BYTES(len);
1093 /* Go through the scan results looking for the channel of the AP
1094 * we were requested to join */
1095 for (; offset + atom_len <= len; offset += atom_len) {
1096 atom = (struct prism2_scan_apinfo *) (buf + offset);
1097 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1104 DEBUG(1, "%s: Requested AP not found in scan results\n",
1109 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1110 req.channel = atom->channel; /* both are little-endian */
1111 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1114 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1118 orinoco_unlock(priv, &flags);
1121 /* Send new BSSID to userspace */
1122 static void orinoco_send_wevents(struct net_device *dev)
1124 struct orinoco_private *priv = netdev_priv(dev);
1125 struct hermes *hw = &priv->hw;
1126 union iwreq_data wrqu;
1128 unsigned long flags;
1130 if (orinoco_lock(priv, &flags) != 0)
1133 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1134 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1138 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1140 /* Send event to user space */
1141 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1142 orinoco_unlock(priv, &flags);
1145 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1147 struct orinoco_private *priv = netdev_priv(dev);
1152 } __attribute__ ((packed)) info;
1156 /* This is an answer to an INQUIRE command that we did earlier,
1157 * or an information "event" generated by the card
1158 * The controller return to us a pseudo frame containing
1159 * the information in question - Jean II */
1160 infofid = hermes_read_regn(hw, INFOFID);
1162 /* Read the info frame header - don't try too hard */
1163 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1166 printk(KERN_ERR "%s: error %d reading info frame. "
1167 "Frame dropped.\n", dev->name, err);
1171 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1172 type = le16_to_cpu(info.type);
1175 case HERMES_INQ_TALLIES: {
1176 struct hermes_tallies_frame tallies;
1177 struct iw_statistics *wstats = &priv->wstats;
1179 if (len > sizeof(tallies)) {
1180 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1182 len = sizeof(tallies);
1185 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1186 infofid, sizeof(info));
1190 /* Increment our various counters */
1191 /* wstats->discard.nwid - no wrong BSSID stuff */
1192 wstats->discard.code +=
1193 le16_to_cpu(tallies.RxWEPUndecryptable);
1194 if (len == sizeof(tallies))
1195 wstats->discard.code +=
1196 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1197 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1198 wstats->discard.misc +=
1199 le16_to_cpu(tallies.TxDiscardsWrongSA);
1200 wstats->discard.fragment +=
1201 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1202 wstats->discard.retries +=
1203 le16_to_cpu(tallies.TxRetryLimitExceeded);
1204 /* wstats->miss.beacon - no match */
1207 case HERMES_INQ_LINKSTATUS: {
1208 struct hermes_linkstatus linkstatus;
1212 if (priv->iw_mode == IW_MODE_MONITOR)
1215 if (len != sizeof(linkstatus)) {
1216 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1221 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1222 infofid, sizeof(info));
1225 newstatus = le16_to_cpu(linkstatus.linkstatus);
1227 /* Symbol firmware uses "out of range" to signal that
1228 * the hostscan frame can be requested. */
1229 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1230 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1231 priv->has_hostscan && priv->scan_inprogress) {
1232 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1236 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1237 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1238 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1241 netif_carrier_on(dev);
1242 else if (!ignore_disconnect)
1243 netif_carrier_off(dev);
1245 if (newstatus != priv->last_linkstatus) {
1246 priv->last_linkstatus = newstatus;
1247 print_linkstatus(dev, newstatus);
1248 /* The info frame contains only one word which is the
1249 * status (see hermes.h). The status is pretty boring
1250 * in itself, that's why we export the new BSSID...
1252 schedule_work(&priv->wevent_work);
1256 case HERMES_INQ_SCAN:
1257 if (!priv->scan_inprogress && priv->bssid_fixed &&
1258 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1259 schedule_work(&priv->join_work);
1263 case HERMES_INQ_HOSTSCAN:
1264 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1265 /* Result of a scanning. Contains information about
1266 * cells in the vicinity - Jean II */
1267 union iwreq_data wrqu;
1272 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1277 /* We are a strict producer. If the previous scan results
1278 * have not been consumed, we just have to drop this
1279 * frame. We can't remove the previous results ourselves,
1280 * that would be *very* racy... Jean II */
1281 if (priv->scan_result != NULL) {
1282 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1286 /* Allocate buffer for results */
1287 buf = kmalloc(len, GFP_ATOMIC);
1289 /* No memory, so can't printk()... */
1292 /* Read scan data */
1293 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1294 infofid, sizeof(info));
1300 #ifdef ORINOCO_DEBUG
1303 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1304 for(i = 1; i < (len * 2); i++)
1305 printk(":%02X", buf[i]);
1308 #endif /* ORINOCO_DEBUG */
1310 /* Allow the clients to access the results */
1311 priv->scan_len = len;
1312 priv->scan_result = buf;
1314 /* Send an empty event to user space.
1315 * We don't send the received data on the event because
1316 * it would require us to do complex transcoding, and
1317 * we want to minimise the work done in the irq handler
1318 * Use a request to extract the data - Jean II */
1319 wrqu.data.length = 0;
1320 wrqu.data.flags = 0;
1321 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1324 case HERMES_INQ_SEC_STAT_AGERE:
1325 /* Security status (Agere specific) */
1326 /* Ignore this frame for now */
1327 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1331 printk(KERN_DEBUG "%s: Unknown information frame received: "
1332 "type 0x%04x, length %d\n", dev->name, type, len);
1333 /* We don't actually do anything about it */
1338 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1340 if (net_ratelimit())
1341 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1344 /********************************************************************/
1345 /* Internal hardware control routines */
1346 /********************************************************************/
1348 int __orinoco_up(struct net_device *dev)
1350 struct orinoco_private *priv = netdev_priv(dev);
1351 struct hermes *hw = &priv->hw;
1354 netif_carrier_off(dev); /* just to make sure */
1356 err = __orinoco_program_rids(dev);
1358 printk(KERN_ERR "%s: Error %d configuring card\n",
1363 /* Fire things up again */
1364 hermes_set_irqmask(hw, ORINOCO_INTEN);
1365 err = hermes_enable_port(hw, 0);
1367 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1372 netif_start_queue(dev);
1377 int __orinoco_down(struct net_device *dev)
1379 struct orinoco_private *priv = netdev_priv(dev);
1380 struct hermes *hw = &priv->hw;
1383 netif_stop_queue(dev);
1385 if (! priv->hw_unavailable) {
1386 if (! priv->broken_disableport) {
1387 err = hermes_disable_port(hw, 0);
1389 /* Some firmwares (e.g. Intersil 1.3.x) seem
1390 * to have problems disabling the port, oh
1392 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1394 priv->broken_disableport = 1;
1397 hermes_set_irqmask(hw, 0);
1398 hermes_write_regn(hw, EVACK, 0xffff);
1401 /* firmware will have to reassociate */
1402 netif_carrier_off(dev);
1403 priv->last_linkstatus = 0xffff;
1408 int orinoco_reinit_firmware(struct net_device *dev)
1410 struct orinoco_private *priv = netdev_priv(dev);
1411 struct hermes *hw = &priv->hw;
1414 err = hermes_init(hw);
1418 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1419 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1420 /* Try workaround for old Symbol firmware bug */
1421 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1422 "(old Symbol firmware?). Trying to work around... ",
1425 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1426 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1428 printk("failed!\n");
1436 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1438 hermes_t *hw = &priv->hw;
1441 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1442 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1443 priv->ndev->name, priv->bitratemode);
1447 switch (priv->firmware_type) {
1448 case FIRMWARE_TYPE_AGERE:
1449 err = hermes_write_wordrec(hw, USER_BAP,
1450 HERMES_RID_CNFTXRATECONTROL,
1451 bitrate_table[priv->bitratemode].agere_txratectrl);
1453 case FIRMWARE_TYPE_INTERSIL:
1454 case FIRMWARE_TYPE_SYMBOL:
1455 err = hermes_write_wordrec(hw, USER_BAP,
1456 HERMES_RID_CNFTXRATECONTROL,
1457 bitrate_table[priv->bitratemode].intersil_txratectrl);
1466 /* Set fixed AP address */
1467 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1471 hermes_t *hw = &priv->hw;
1473 switch (priv->firmware_type) {
1474 case FIRMWARE_TYPE_AGERE:
1477 case FIRMWARE_TYPE_INTERSIL:
1478 if (priv->bssid_fixed)
1483 err = hermes_write_wordrec(hw, USER_BAP,
1484 HERMES_RID_CNFROAMINGMODE,
1487 case FIRMWARE_TYPE_SYMBOL:
1488 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1489 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1490 &priv->desired_bssid);
1496 /* Change the WEP keys and/or the current keys. Can be called
1497 * either from __orinoco_hw_setup_wep() or directly from
1498 * orinoco_ioctl_setiwencode(). In the later case the association
1499 * with the AP is not broken (if the firmware can handle it),
1500 * which is needed for 802.1x implementations. */
1501 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1503 hermes_t *hw = &priv->hw;
1506 switch (priv->firmware_type) {
1507 case FIRMWARE_TYPE_AGERE:
1508 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1509 HERMES_RID_CNFWEPKEYS_AGERE,
1513 err = hermes_write_wordrec(hw, USER_BAP,
1514 HERMES_RID_CNFTXKEY_AGERE,
1519 case FIRMWARE_TYPE_INTERSIL:
1520 case FIRMWARE_TYPE_SYMBOL:
1525 /* Force uniform key length to work around firmware bugs */
1526 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1528 if (keylen > LARGE_KEY_SIZE) {
1529 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1530 priv->ndev->name, priv->tx_key, keylen);
1534 /* Write all 4 keys */
1535 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1536 err = hermes_write_ltv(hw, USER_BAP,
1537 HERMES_RID_CNFDEFAULTKEY0 + i,
1538 HERMES_BYTES_TO_RECLEN(keylen),
1539 priv->keys[i].data);
1544 /* Write the index of the key used in transmission */
1545 err = hermes_write_wordrec(hw, USER_BAP,
1546 HERMES_RID_CNFWEPDEFAULTKEYID,
1557 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1559 hermes_t *hw = &priv->hw;
1561 int master_wep_flag;
1565 __orinoco_hw_setup_wepkeys(priv);
1567 if (priv->wep_restrict)
1568 auth_flag = HERMES_AUTH_SHARED_KEY;
1570 auth_flag = HERMES_AUTH_OPEN;
1572 switch (priv->firmware_type) {
1573 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1575 /* Enable the shared-key authentication. */
1576 err = hermes_write_wordrec(hw, USER_BAP,
1577 HERMES_RID_CNFAUTHENTICATION_AGERE,
1580 err = hermes_write_wordrec(hw, USER_BAP,
1581 HERMES_RID_CNFWEPENABLED_AGERE,
1587 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1588 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1590 if (priv->wep_restrict ||
1591 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1592 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1593 HERMES_WEP_EXCL_UNENCRYPTED;
1595 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1597 err = hermes_write_wordrec(hw, USER_BAP,
1598 HERMES_RID_CNFAUTHENTICATION,
1603 master_wep_flag = 0;
1605 if (priv->iw_mode == IW_MODE_MONITOR)
1606 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1608 /* Master WEP setting : on/off */
1609 err = hermes_write_wordrec(hw, USER_BAP,
1610 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1621 static int __orinoco_program_rids(struct net_device *dev)
1623 struct orinoco_private *priv = netdev_priv(dev);
1624 hermes_t *hw = &priv->hw;
1626 struct hermes_idstring idbuf;
1628 /* Set the MAC address */
1629 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1630 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1632 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1637 /* Set up the link mode */
1638 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1641 printk(KERN_ERR "%s: Error %d setting port type\n",
1645 /* Set the channel/frequency */
1646 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1647 err = hermes_write_wordrec(hw, USER_BAP,
1648 HERMES_RID_CNFOWNCHANNEL,
1651 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1652 dev->name, err, priv->channel);
1657 if (priv->has_ibss) {
1660 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1661 printk(KERN_WARNING "%s: This firmware requires an "
1662 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1663 /* With wvlan_cs, in this case, we would crash.
1664 * hopefully, this driver will behave better...
1668 createibss = priv->createibss;
1671 err = hermes_write_wordrec(hw, USER_BAP,
1672 HERMES_RID_CNFCREATEIBSS,
1675 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1681 /* Set the desired BSSID */
1682 err = __orinoco_hw_set_wap(priv);
1684 printk(KERN_ERR "%s: Error %d setting AP address\n",
1688 /* Set the desired ESSID */
1689 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1690 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1691 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1692 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1693 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1696 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1700 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1701 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1704 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1709 /* Set the station name */
1710 idbuf.len = cpu_to_le16(strlen(priv->nick));
1711 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1712 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1713 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1716 printk(KERN_ERR "%s: Error %d setting nickname\n",
1721 /* Set AP density */
1722 if (priv->has_sensitivity) {
1723 err = hermes_write_wordrec(hw, USER_BAP,
1724 HERMES_RID_CNFSYSTEMSCALE,
1727 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1728 "Disabling sensitivity control\n",
1731 priv->has_sensitivity = 0;
1735 /* Set RTS threshold */
1736 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1739 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1744 /* Set fragmentation threshold or MWO robustness */
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFMWOROBUST_AGERE,
1750 err = hermes_write_wordrec(hw, USER_BAP,
1751 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1754 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1760 err = __orinoco_hw_set_bitrate(priv);
1762 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1767 /* Set power management */
1769 err = hermes_write_wordrec(hw, USER_BAP,
1770 HERMES_RID_CNFPMENABLED,
1773 printk(KERN_ERR "%s: Error %d setting up PM\n",
1778 err = hermes_write_wordrec(hw, USER_BAP,
1779 HERMES_RID_CNFMULTICASTRECEIVE,
1782 printk(KERN_ERR "%s: Error %d setting up PM\n",
1786 err = hermes_write_wordrec(hw, USER_BAP,
1787 HERMES_RID_CNFMAXSLEEPDURATION,
1790 printk(KERN_ERR "%s: Error %d setting up PM\n",
1794 err = hermes_write_wordrec(hw, USER_BAP,
1795 HERMES_RID_CNFPMHOLDOVERDURATION,
1798 printk(KERN_ERR "%s: Error %d setting up PM\n",
1804 /* Set preamble - only for Symbol so far... */
1805 if (priv->has_preamble) {
1806 err = hermes_write_wordrec(hw, USER_BAP,
1807 HERMES_RID_CNFPREAMBLE_SYMBOL,
1810 printk(KERN_ERR "%s: Error %d setting preamble\n",
1816 /* Set up encryption */
1817 if (priv->has_wep) {
1818 err = __orinoco_hw_setup_wep(priv);
1820 printk(KERN_ERR "%s: Error %d activating WEP\n",
1826 if (priv->iw_mode == IW_MODE_MONITOR) {
1827 /* Enable monitor mode */
1828 dev->type = ARPHRD_IEEE80211;
1829 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1830 HERMES_TEST_MONITOR, 0, NULL);
1832 /* Disable monitor mode */
1833 dev->type = ARPHRD_ETHER;
1834 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1835 HERMES_TEST_STOP, 0, NULL);
1840 /* Set promiscuity / multicast*/
1841 priv->promiscuous = 0;
1843 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1848 /* FIXME: return int? */
1850 __orinoco_set_multicast_list(struct net_device *dev)
1852 struct orinoco_private *priv = netdev_priv(dev);
1853 hermes_t *hw = &priv->hw;
1855 int promisc, mc_count;
1857 /* The Hermes doesn't seem to have an allmulti mode, so we go
1858 * into promiscuous mode and let the upper levels deal. */
1859 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1860 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1865 mc_count = dev->mc_count;
1868 if (promisc != priv->promiscuous) {
1869 err = hermes_write_wordrec(hw, USER_BAP,
1870 HERMES_RID_CNFPROMISCUOUSMODE,
1873 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1876 priv->promiscuous = promisc;
1879 if (! promisc && (mc_count || priv->mc_count) ) {
1880 struct dev_mc_list *p = dev->mc_list;
1881 struct hermes_multicast mclist;
1884 for (i = 0; i < mc_count; i++) {
1885 /* paranoia: is list shorter than mc_count? */
1887 /* paranoia: bad address size in list? */
1888 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1890 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1895 printk(KERN_WARNING "%s: Multicast list is "
1896 "longer than mc_count\n", dev->name);
1898 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1899 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1902 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1905 priv->mc_count = mc_count;
1908 /* Since we can set the promiscuous flag when it wasn't asked
1909 for, make sure the net_device knows about it. */
1910 if (priv->promiscuous)
1911 dev->flags |= IFF_PROMISC;
1913 dev->flags &= ~IFF_PROMISC;
1916 /* This must be called from user context, without locks held - use
1917 * schedule_work() */
1918 static void orinoco_reset(struct net_device *dev)
1920 struct orinoco_private *priv = netdev_priv(dev);
1921 struct hermes *hw = &priv->hw;
1923 unsigned long flags;
1925 if (orinoco_lock(priv, &flags) != 0)
1926 /* When the hardware becomes available again, whatever
1927 * detects that is responsible for re-initializing
1928 * it. So no need for anything further */
1931 netif_stop_queue(dev);
1933 /* Shut off interrupts. Depending on what state the hardware
1934 * is in, this might not work, but we'll try anyway */
1935 hermes_set_irqmask(hw, 0);
1936 hermes_write_regn(hw, EVACK, 0xffff);
1938 priv->hw_unavailable++;
1939 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1940 netif_carrier_off(dev);
1942 orinoco_unlock(priv, &flags);
1944 /* Scanning support: Cleanup of driver struct */
1945 kfree(priv->scan_result);
1946 priv->scan_result = NULL;
1947 priv->scan_inprogress = 0;
1949 if (priv->hard_reset) {
1950 err = (*priv->hard_reset)(priv);
1952 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1953 "performing hard reset\n", dev->name, err);
1958 err = orinoco_reinit_firmware(dev);
1960 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1965 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1967 priv->hw_unavailable--;
1969 /* priv->open or priv->hw_unavailable might have changed while
1970 * we dropped the lock */
1971 if (priv->open && (! priv->hw_unavailable)) {
1972 err = __orinoco_up(dev);
1974 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1977 dev->trans_start = jiffies;
1980 spin_unlock_irq(&priv->lock);
1984 hermes_set_irqmask(hw, 0);
1985 netif_device_detach(dev);
1986 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1989 /********************************************************************/
1990 /* Interrupt handler */
1991 /********************************************************************/
1993 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1995 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1998 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2000 /* This seems to happen a fair bit under load, but ignoring it
2001 seems to work fine...*/
2002 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2006 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2008 struct net_device *dev = (struct net_device *)dev_id;
2009 struct orinoco_private *priv = netdev_priv(dev);
2010 hermes_t *hw = &priv->hw;
2011 int count = MAX_IRQLOOPS_PER_IRQ;
2013 /* These are used to detect a runaway interrupt situation */
2014 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2015 * we panic and shut down the hardware */
2016 static int last_irq_jiffy = 0; /* jiffies value the last time
2018 static int loops_this_jiffy = 0;
2019 unsigned long flags;
2021 if (orinoco_lock(priv, &flags) != 0) {
2022 /* If hw is unavailable - we don't know if the irq was
2027 evstat = hermes_read_regn(hw, EVSTAT);
2028 events = evstat & hw->inten;
2030 orinoco_unlock(priv, &flags);
2034 if (jiffies != last_irq_jiffy)
2035 loops_this_jiffy = 0;
2036 last_irq_jiffy = jiffies;
2038 while (events && count--) {
2039 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2040 printk(KERN_WARNING "%s: IRQ handler is looping too "
2041 "much! Resetting.\n", dev->name);
2042 /* Disable interrupts for now */
2043 hermes_set_irqmask(hw, 0);
2044 schedule_work(&priv->reset_work);
2048 /* Check the card hasn't been removed */
2049 if (! hermes_present(hw)) {
2050 DEBUG(0, "orinoco_interrupt(): card removed\n");
2054 if (events & HERMES_EV_TICK)
2055 __orinoco_ev_tick(dev, hw);
2056 if (events & HERMES_EV_WTERR)
2057 __orinoco_ev_wterr(dev, hw);
2058 if (events & HERMES_EV_INFDROP)
2059 __orinoco_ev_infdrop(dev, hw);
2060 if (events & HERMES_EV_INFO)
2061 __orinoco_ev_info(dev, hw);
2062 if (events & HERMES_EV_RX)
2063 __orinoco_ev_rx(dev, hw);
2064 if (events & HERMES_EV_TXEXC)
2065 __orinoco_ev_txexc(dev, hw);
2066 if (events & HERMES_EV_TX)
2067 __orinoco_ev_tx(dev, hw);
2068 if (events & HERMES_EV_ALLOC)
2069 __orinoco_ev_alloc(dev, hw);
2071 hermes_write_regn(hw, EVACK, evstat);
2073 evstat = hermes_read_regn(hw, EVSTAT);
2074 events = evstat & hw->inten;
2077 orinoco_unlock(priv, &flags);
2081 /********************************************************************/
2082 /* Initialization */
2083 /********************************************************************/
2086 u16 id, variant, major, minor;
2087 } __attribute__ ((packed));
2089 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2091 if (nic_id->id < 0x8000)
2092 return FIRMWARE_TYPE_AGERE;
2093 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2094 return FIRMWARE_TYPE_SYMBOL;
2096 return FIRMWARE_TYPE_INTERSIL;
2099 /* Set priv->firmware type, determine firmware properties */
2100 static int determine_firmware(struct net_device *dev)
2102 struct orinoco_private *priv = netdev_priv(dev);
2103 hermes_t *hw = &priv->hw;
2105 struct comp_id nic_id, sta_id;
2106 unsigned int firmver;
2107 char tmp[SYMBOL_MAX_VER_LEN+1];
2109 /* Get the hardware version */
2110 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2112 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2117 le16_to_cpus(&nic_id.id);
2118 le16_to_cpus(&nic_id.variant);
2119 le16_to_cpus(&nic_id.major);
2120 le16_to_cpus(&nic_id.minor);
2121 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2122 dev->name, nic_id.id, nic_id.variant,
2123 nic_id.major, nic_id.minor);
2125 priv->firmware_type = determine_firmware_type(&nic_id);
2127 /* Get the firmware version */
2128 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2130 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2135 le16_to_cpus(&sta_id.id);
2136 le16_to_cpus(&sta_id.variant);
2137 le16_to_cpus(&sta_id.major);
2138 le16_to_cpus(&sta_id.minor);
2139 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2140 dev->name, sta_id.id, sta_id.variant,
2141 sta_id.major, sta_id.minor);
2143 switch (sta_id.id) {
2145 printk(KERN_ERR "%s: Primary firmware is active\n",
2149 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2152 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2153 case 0x21: /* Symbol Spectrum24 Trilogy */
2156 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2161 /* Default capabilities */
2162 priv->has_sensitivity = 1;
2164 priv->has_preamble = 0;
2165 priv->has_port3 = 1;
2168 priv->has_big_wep = 0;
2170 /* Determine capabilities from the firmware version */
2171 switch (priv->firmware_type) {
2172 case FIRMWARE_TYPE_AGERE:
2173 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2174 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2175 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2176 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2178 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2180 priv->has_ibss = (firmver >= 0x60006);
2181 priv->has_wep = (firmver >= 0x40020);
2182 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2183 Gold cards from the others? */
2184 priv->has_mwo = (firmver >= 0x60000);
2185 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2186 priv->ibss_port = 1;
2187 priv->has_hostscan = (firmver >= 0x8000a);
2188 priv->broken_monitor = (firmver >= 0x80000);
2190 /* Tested with Agere firmware :
2191 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2192 * Tested CableTron firmware : 4.32 => Anton */
2194 case FIRMWARE_TYPE_SYMBOL:
2195 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2196 /* Intel MAC : 00:02:B3:* */
2197 /* 3Com MAC : 00:50:DA:* */
2198 memset(tmp, 0, sizeof(tmp));
2199 /* Get the Symbol firmware version */
2200 err = hermes_read_ltv(hw, USER_BAP,
2201 HERMES_RID_SECONDARYVERSION_SYMBOL,
2202 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2205 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2210 /* The firmware revision is a string, the format is
2211 * something like : "V2.20-01".
2212 * Quick and dirty parsing... - Jean II
2214 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2215 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2218 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2221 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2224 priv->has_ibss = (firmver >= 0x20000);
2225 priv->has_wep = (firmver >= 0x15012);
2226 priv->has_big_wep = (firmver >= 0x20000);
2227 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2228 (firmver >= 0x29000 && firmver < 0x30000) ||
2230 priv->has_preamble = (firmver >= 0x20000);
2231 priv->ibss_port = 4;
2232 priv->broken_disableport = (firmver == 0x25013) ||
2233 (firmver >= 0x30000 && firmver <= 0x31000);
2234 priv->has_hostscan = (firmver >= 0x31001) ||
2235 (firmver >= 0x29057 && firmver < 0x30000);
2236 /* Tested with Intel firmware : 0x20015 => Jean II */
2237 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2239 case FIRMWARE_TYPE_INTERSIL:
2240 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2241 * Samsung, Compaq 100/200 and Proxim are slightly
2242 * different and less well tested */
2243 /* D-Link MAC : 00:40:05:* */
2244 /* Addtron MAC : 00:90:D1:* */
2245 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2246 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2249 firmver = ((unsigned long)sta_id.major << 16) |
2250 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2252 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2253 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2254 priv->has_pm = (firmver >= 0x000700);
2255 priv->has_hostscan = (firmver >= 0x010301);
2257 if (firmver >= 0x000800)
2258 priv->ibss_port = 0;
2260 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2261 "than v0.8.x - several features not supported\n",
2263 priv->ibss_port = 1;
2267 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2273 static int orinoco_init(struct net_device *dev)
2275 struct orinoco_private *priv = netdev_priv(dev);
2276 hermes_t *hw = &priv->hw;
2278 struct hermes_idstring nickbuf;
2282 TRACE_ENTER(dev->name);
2284 /* No need to lock, the hw_unavailable flag is already set in
2285 * alloc_orinocodev() */
2286 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2288 /* Initialize the firmware */
2289 err = orinoco_reinit_firmware(dev);
2291 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2296 err = determine_firmware(dev);
2298 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2303 if (priv->has_port3)
2304 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2306 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2308 if (priv->has_wep) {
2309 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2310 if (priv->has_big_wep)
2311 printk("104-bit key\n");
2313 printk("40-bit key\n");
2316 /* Get the MAC address */
2317 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2318 ETH_ALEN, NULL, dev->dev_addr);
2320 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2325 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2326 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2327 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2330 /* Get the station name */
2331 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2332 sizeof(nickbuf), &reclen, &nickbuf);
2334 printk(KERN_ERR "%s: failed to read station name\n",
2339 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2341 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2342 memcpy(priv->nick, &nickbuf.val, len);
2343 priv->nick[len] = '\0';
2345 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2347 /* Get allowed channels */
2348 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2349 &priv->channel_mask);
2351 printk(KERN_ERR "%s: failed to read channel list!\n",
2356 /* Get initial AP density */
2357 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2359 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2360 priv->has_sensitivity = 0;
2363 /* Get initial RTS threshold */
2364 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2367 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2372 /* Get initial fragmentation settings */
2374 err = hermes_read_wordrec(hw, USER_BAP,
2375 HERMES_RID_CNFMWOROBUST_AGERE,
2378 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2379 &priv->frag_thresh);
2381 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2386 /* Power management setup */
2390 err = hermes_read_wordrec(hw, USER_BAP,
2391 HERMES_RID_CNFMAXSLEEPDURATION,
2394 printk(KERN_ERR "%s: failed to read power management period!\n",
2398 err = hermes_read_wordrec(hw, USER_BAP,
2399 HERMES_RID_CNFPMHOLDOVERDURATION,
2402 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2408 /* Preamble setup */
2409 if (priv->has_preamble) {
2410 err = hermes_read_wordrec(hw, USER_BAP,
2411 HERMES_RID_CNFPREAMBLE_SYMBOL,
2417 /* Set up the default configuration */
2418 priv->iw_mode = IW_MODE_INFRA;
2419 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2420 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2421 set_port_type(priv);
2422 priv->channel = 0; /* use firmware default */
2424 priv->promiscuous = 0;
2428 /* Make the hardware available, as long as it hasn't been
2429 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2430 spin_lock_irq(&priv->lock);
2431 priv->hw_unavailable--;
2432 spin_unlock_irq(&priv->lock);
2434 printk(KERN_DEBUG "%s: ready\n", dev->name);
2437 TRACE_EXIT(dev->name);
2441 struct net_device *alloc_orinocodev(int sizeof_card,
2442 int (*hard_reset)(struct orinoco_private *))
2444 struct net_device *dev;
2445 struct orinoco_private *priv;
2447 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2450 priv = netdev_priv(dev);
2453 priv->card = (void *)((unsigned long)priv
2454 + sizeof(struct orinoco_private));
2458 /* Setup / override net_device fields */
2459 dev->init = orinoco_init;
2460 dev->hard_start_xmit = orinoco_xmit;
2461 dev->tx_timeout = orinoco_tx_timeout;
2462 dev->watchdog_timeo = HZ; /* 1 second timeout */
2463 dev->get_stats = orinoco_get_stats;
2464 dev->ethtool_ops = &orinoco_ethtool_ops;
2465 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2466 dev->change_mtu = orinoco_change_mtu;
2467 dev->set_multicast_list = orinoco_set_multicast_list;
2468 /* we use the default eth_mac_addr for setting the MAC addr */
2470 /* Set up default callbacks */
2471 dev->open = orinoco_open;
2472 dev->stop = orinoco_stop;
2473 priv->hard_reset = hard_reset;
2475 spin_lock_init(&priv->lock);
2477 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2478 * before anything else touches the
2480 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2481 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2482 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2484 netif_carrier_off(dev);
2485 priv->last_linkstatus = 0xffff;
2491 void free_orinocodev(struct net_device *dev)
2493 struct orinoco_private *priv = netdev_priv(dev);
2495 kfree(priv->scan_result);
2499 /********************************************************************/
2500 /* Wireless extensions */
2501 /********************************************************************/
2503 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2504 char buf[IW_ESSID_MAX_SIZE+1])
2506 hermes_t *hw = &priv->hw;
2508 struct hermes_idstring essidbuf;
2509 char *p = (char *)(&essidbuf.val);
2511 unsigned long flags;
2513 if (orinoco_lock(priv, &flags) != 0)
2516 if (strlen(priv->desired_essid) > 0) {
2517 /* We read the desired SSID from the hardware rather
2518 than from priv->desired_essid, just in case the
2519 firmware is allowed to change it on us. I'm not
2521 /* My guess is that the OWNSSID should always be whatever
2522 * we set to the card, whereas CURRENT_SSID is the one that
2523 * may change... - Jean II */
2528 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2529 HERMES_RID_CNFDESIREDSSID;
2531 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2538 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2539 sizeof(essidbuf), NULL, &essidbuf);
2544 len = le16_to_cpu(essidbuf.len);
2545 BUG_ON(len > IW_ESSID_MAX_SIZE);
2547 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2548 memcpy(buf, p, len);
2552 orinoco_unlock(priv, &flags);
2557 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2560 hermes_t *hw = &priv->hw;
2564 unsigned long flags;
2566 if (orinoco_lock(priv, &flags) != 0)
2569 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2573 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2579 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2580 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2581 priv->ndev->name, channel);
2586 freq = channel_frequency[channel-1] * 100000;
2589 orinoco_unlock(priv, &flags);
2593 return err ? err : freq;
2596 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2597 int *numrates, s32 *rates, int max)
2599 hermes_t *hw = &priv->hw;
2600 struct hermes_idstring list;
2601 unsigned char *p = (unsigned char *)&list.val;
2605 unsigned long flags;
2607 if (orinoco_lock(priv, &flags) != 0)
2610 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2611 sizeof(list), NULL, &list);
2612 orinoco_unlock(priv, &flags);
2617 num = le16_to_cpu(list.len);
2619 num = min(num, max);
2621 for (i = 0; i < num; i++) {
2622 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2628 static int orinoco_ioctl_getname(struct net_device *dev,
2629 struct iw_request_info *info,
2633 struct orinoco_private *priv = netdev_priv(dev);
2637 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2639 if (!err && (numrates > 2))
2640 strcpy(name, "IEEE 802.11b");
2642 strcpy(name, "IEEE 802.11-DS");
2647 static int orinoco_ioctl_setwap(struct net_device *dev,
2648 struct iw_request_info *info,
2649 struct sockaddr *ap_addr,
2652 struct orinoco_private *priv = netdev_priv(dev);
2653 int err = -EINPROGRESS; /* Call commit handler */
2654 unsigned long flags;
2655 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2656 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2658 if (orinoco_lock(priv, &flags) != 0)
2661 /* Enable automatic roaming - no sanity checks are needed */
2662 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2663 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2664 priv->bssid_fixed = 0;
2665 memset(priv->desired_bssid, 0, ETH_ALEN);
2667 /* "off" means keep existing connection */
2668 if (ap_addr->sa_data[0] == 0) {
2669 __orinoco_hw_set_wap(priv);
2675 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2676 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2677 "support manual roaming\n",
2683 if (priv->iw_mode != IW_MODE_INFRA) {
2684 printk(KERN_WARNING "%s: Manual roaming supported only in "
2685 "managed mode\n", dev->name);
2690 /* Intersil firmware hangs without Desired ESSID */
2691 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2692 strlen(priv->desired_essid) == 0) {
2693 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2694 "manual roaming\n", dev->name);
2699 /* Finally, enable manual roaming */
2700 priv->bssid_fixed = 1;
2701 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2704 orinoco_unlock(priv, &flags);
2708 static int orinoco_ioctl_getwap(struct net_device *dev,
2709 struct iw_request_info *info,
2710 struct sockaddr *ap_addr,
2713 struct orinoco_private *priv = netdev_priv(dev);
2715 hermes_t *hw = &priv->hw;
2717 unsigned long flags;
2719 if (orinoco_lock(priv, &flags) != 0)
2722 ap_addr->sa_family = ARPHRD_ETHER;
2723 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2724 ETH_ALEN, NULL, ap_addr->sa_data);
2726 orinoco_unlock(priv, &flags);
2731 static int orinoco_ioctl_setmode(struct net_device *dev,
2732 struct iw_request_info *info,
2736 struct orinoco_private *priv = netdev_priv(dev);
2737 int err = -EINPROGRESS; /* Call commit handler */
2738 unsigned long flags;
2740 if (priv->iw_mode == *mode)
2743 if (orinoco_lock(priv, &flags) != 0)
2748 if (!priv->has_ibss && !priv->has_port3)
2755 case IW_MODE_MONITOR:
2756 if (priv->broken_monitor && !force_monitor) {
2757 printk(KERN_WARNING "%s: Monitor mode support is "
2758 "buggy in this firmware, not enabling\n",
2769 if (err == -EINPROGRESS) {
2770 priv->iw_mode = *mode;
2771 set_port_type(priv);
2774 orinoco_unlock(priv, &flags);
2779 static int orinoco_ioctl_getmode(struct net_device *dev,
2780 struct iw_request_info *info,
2784 struct orinoco_private *priv = netdev_priv(dev);
2786 *mode = priv->iw_mode;
2790 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2791 struct iw_request_info *info,
2792 struct iw_point *rrq,
2795 struct orinoco_private *priv = netdev_priv(dev);
2797 struct iw_range *range = (struct iw_range *) extra;
2801 TRACE_ENTER(dev->name);
2803 rrq->length = sizeof(struct iw_range);
2804 memset(range, 0, sizeof(struct iw_range));
2806 range->we_version_compiled = WIRELESS_EXT;
2807 range->we_version_source = 14;
2809 /* Set available channels/frequencies */
2810 range->num_channels = NUM_CHANNELS;
2812 for (i = 0; i < NUM_CHANNELS; i++) {
2813 if (priv->channel_mask & (1 << i)) {
2814 range->freq[k].i = i + 1;
2815 range->freq[k].m = channel_frequency[i] * 100000;
2816 range->freq[k].e = 1;
2820 if (k >= IW_MAX_FREQUENCIES)
2823 range->num_frequency = k;
2824 range->sensitivity = 3;
2826 if (priv->has_wep) {
2827 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2828 range->encoding_size[0] = SMALL_KEY_SIZE;
2829 range->num_encoding_sizes = 1;
2831 if (priv->has_big_wep) {
2832 range->encoding_size[1] = LARGE_KEY_SIZE;
2833 range->num_encoding_sizes = 2;
2837 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2838 /* Quality stats meaningless in ad-hoc mode */
2840 range->max_qual.qual = 0x8b - 0x2f;
2841 range->max_qual.level = 0x2f - 0x95 - 1;
2842 range->max_qual.noise = 0x2f - 0x95 - 1;
2843 /* Need to get better values */
2844 range->avg_qual.qual = 0x24;
2845 range->avg_qual.level = 0xC2;
2846 range->avg_qual.noise = 0x9E;
2849 err = orinoco_hw_get_bitratelist(priv, &numrates,
2850 range->bitrate, IW_MAX_BITRATES);
2853 range->num_bitrates = numrates;
2855 /* Set an indication of the max TCP throughput in bit/s that we can
2856 * expect using this interface. May be use for QoS stuff...
2859 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2861 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2864 range->max_rts = 2347;
2865 range->min_frag = 256;
2866 range->max_frag = 2346;
2869 range->max_pmp = 65535000;
2871 range->max_pmt = 65535 * 1000; /* ??? */
2872 range->pmp_flags = IW_POWER_PERIOD;
2873 range->pmt_flags = IW_POWER_TIMEOUT;
2874 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2876 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2877 range->retry_flags = IW_RETRY_LIMIT;
2878 range->r_time_flags = IW_RETRY_LIFETIME;
2879 range->min_retry = 0;
2880 range->max_retry = 65535; /* ??? */
2881 range->min_r_time = 0;
2882 range->max_r_time = 65535 * 1000; /* ??? */
2884 TRACE_EXIT(dev->name);
2889 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2890 struct iw_request_info *info,
2891 struct iw_point *erq,
2894 struct orinoco_private *priv = netdev_priv(dev);
2895 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2896 int setindex = priv->tx_key;
2897 int enable = priv->wep_on;
2898 int restricted = priv->wep_restrict;
2900 int err = -EINPROGRESS; /* Call commit handler */
2901 unsigned long flags;
2903 if (! priv->has_wep)
2907 /* We actually have a key to set - check its length */
2908 if (erq->length > LARGE_KEY_SIZE)
2911 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2915 if (orinoco_lock(priv, &flags) != 0)
2919 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2920 index = priv->tx_key;
2922 /* Adjust key length to a supported value */
2923 if (erq->length > SMALL_KEY_SIZE) {
2924 xlen = LARGE_KEY_SIZE;
2925 } else if (erq->length > 0) {
2926 xlen = SMALL_KEY_SIZE;
2930 /* Switch on WEP if off */
2931 if ((!enable) && (xlen > 0)) {
2936 /* Important note : if the user do "iwconfig eth0 enc off",
2937 * we will arrive there with an index of -1. This is valid
2938 * but need to be taken care off... Jean II */
2939 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2940 if((index != -1) || (erq->flags == 0)) {
2945 /* Set the index : Check that the key is valid */
2946 if(priv->keys[index].len == 0) {
2954 if (erq->flags & IW_ENCODE_DISABLED)
2956 if (erq->flags & IW_ENCODE_OPEN)
2958 if (erq->flags & IW_ENCODE_RESTRICTED)
2962 priv->keys[index].len = cpu_to_le16(xlen);
2963 memset(priv->keys[index].data, 0,
2964 sizeof(priv->keys[index].data));
2965 memcpy(priv->keys[index].data, keybuf, erq->length);
2967 priv->tx_key = setindex;
2969 /* Try fast key change if connected and only keys are changed */
2970 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2971 netif_carrier_ok(dev)) {
2972 err = __orinoco_hw_setup_wepkeys(priv);
2973 /* No need to commit if successful */
2977 priv->wep_on = enable;
2978 priv->wep_restrict = restricted;
2981 orinoco_unlock(priv, &flags);
2986 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2987 struct iw_request_info *info,
2988 struct iw_point *erq,
2991 struct orinoco_private *priv = netdev_priv(dev);
2992 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2994 unsigned long flags;
2996 if (! priv->has_wep)
2999 if (orinoco_lock(priv, &flags) != 0)
3002 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3003 index = priv->tx_key;
3007 erq->flags |= IW_ENCODE_DISABLED;
3008 erq->flags |= index + 1;
3010 if (priv->wep_restrict)
3011 erq->flags |= IW_ENCODE_RESTRICTED;
3013 erq->flags |= IW_ENCODE_OPEN;
3015 xlen = le16_to_cpu(priv->keys[index].len);
3019 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3021 orinoco_unlock(priv, &flags);
3025 static int orinoco_ioctl_setessid(struct net_device *dev,
3026 struct iw_request_info *info,
3027 struct iw_point *erq,
3030 struct orinoco_private *priv = netdev_priv(dev);
3031 unsigned long flags;
3033 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3034 * anyway... - Jean II */
3036 /* Hum... Should not use Wireless Extension constant (may change),
3037 * should use our own... - Jean II */
3038 if (erq->length > IW_ESSID_MAX_SIZE)
3041 if (orinoco_lock(priv, &flags) != 0)
3044 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3045 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3047 /* If not ANY, get the new ESSID */
3049 memcpy(priv->desired_essid, essidbuf, erq->length);
3052 orinoco_unlock(priv, &flags);
3054 return -EINPROGRESS; /* Call commit handler */
3057 static int orinoco_ioctl_getessid(struct net_device *dev,
3058 struct iw_request_info *info,
3059 struct iw_point *erq,
3062 struct orinoco_private *priv = netdev_priv(dev);
3065 unsigned long flags;
3067 TRACE_ENTER(dev->name);
3069 if (netif_running(dev)) {
3070 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3074 if (orinoco_lock(priv, &flags) != 0)
3076 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3077 orinoco_unlock(priv, &flags);
3081 erq->length = strlen(essidbuf) + 1;
3083 TRACE_EXIT(dev->name);
3088 static int orinoco_ioctl_setnick(struct net_device *dev,
3089 struct iw_request_info *info,
3090 struct iw_point *nrq,
3093 struct orinoco_private *priv = netdev_priv(dev);
3094 unsigned long flags;
3096 if (nrq->length > IW_ESSID_MAX_SIZE)
3099 if (orinoco_lock(priv, &flags) != 0)
3102 memset(priv->nick, 0, sizeof(priv->nick));
3103 memcpy(priv->nick, nickbuf, nrq->length);
3105 orinoco_unlock(priv, &flags);
3107 return -EINPROGRESS; /* Call commit handler */
3110 static int orinoco_ioctl_getnick(struct net_device *dev,
3111 struct iw_request_info *info,
3112 struct iw_point *nrq,
3115 struct orinoco_private *priv = netdev_priv(dev);
3116 unsigned long flags;
3118 if (orinoco_lock(priv, &flags) != 0)
3121 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3122 orinoco_unlock(priv, &flags);
3124 nrq->length = strlen(nickbuf)+1;
3129 static int orinoco_ioctl_setfreq(struct net_device *dev,
3130 struct iw_request_info *info,
3131 struct iw_freq *frq,
3134 struct orinoco_private *priv = netdev_priv(dev);
3136 unsigned long flags;
3137 int err = -EINPROGRESS; /* Call commit handler */
3139 /* In infrastructure mode the AP sets the channel */
3140 if (priv->iw_mode == IW_MODE_INFRA)
3143 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3144 /* Setting by channel number */
3147 /* Setting by frequency - search the table */
3151 for (i = 0; i < (6 - frq->e); i++)
3154 for (i = 0; i < NUM_CHANNELS; i++)
3155 if (frq->m == (channel_frequency[i] * mult))
3159 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3160 ! (priv->channel_mask & (1 << (chan-1)) ) )
3163 if (orinoco_lock(priv, &flags) != 0)
3166 priv->channel = chan;
3167 if (priv->iw_mode == IW_MODE_MONITOR) {
3168 /* Fast channel change - no commit if successful */
3169 hermes_t *hw = &priv->hw;
3170 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3171 HERMES_TEST_SET_CHANNEL,
3174 orinoco_unlock(priv, &flags);
3179 static int orinoco_ioctl_getfreq(struct net_device *dev,
3180 struct iw_request_info *info,
3181 struct iw_freq *frq,
3184 struct orinoco_private *priv = netdev_priv(dev);
3187 /* Locking done in there */
3188 tmp = orinoco_hw_get_freq(priv);
3199 static int orinoco_ioctl_getsens(struct net_device *dev,
3200 struct iw_request_info *info,
3201 struct iw_param *srq,
3204 struct orinoco_private *priv = netdev_priv(dev);
3205 hermes_t *hw = &priv->hw;
3208 unsigned long flags;
3210 if (!priv->has_sensitivity)
3213 if (orinoco_lock(priv, &flags) != 0)
3215 err = hermes_read_wordrec(hw, USER_BAP,
3216 HERMES_RID_CNFSYSTEMSCALE, &val);
3217 orinoco_unlock(priv, &flags);
3223 srq->fixed = 0; /* auto */
3228 static int orinoco_ioctl_setsens(struct net_device *dev,
3229 struct iw_request_info *info,
3230 struct iw_param *srq,
3233 struct orinoco_private *priv = netdev_priv(dev);
3234 int val = srq->value;
3235 unsigned long flags;
3237 if (!priv->has_sensitivity)
3240 if ((val < 1) || (val > 3))
3243 if (orinoco_lock(priv, &flags) != 0)
3245 priv->ap_density = val;
3246 orinoco_unlock(priv, &flags);
3248 return -EINPROGRESS; /* Call commit handler */
3251 static int orinoco_ioctl_setrts(struct net_device *dev,
3252 struct iw_request_info *info,
3253 struct iw_param *rrq,
3256 struct orinoco_private *priv = netdev_priv(dev);
3257 int val = rrq->value;
3258 unsigned long flags;
3263 if ( (val < 0) || (val > 2347) )
3266 if (orinoco_lock(priv, &flags) != 0)
3269 priv->rts_thresh = val;
3270 orinoco_unlock(priv, &flags);
3272 return -EINPROGRESS; /* Call commit handler */
3275 static int orinoco_ioctl_getrts(struct net_device *dev,
3276 struct iw_request_info *info,
3277 struct iw_param *rrq,
3280 struct orinoco_private *priv = netdev_priv(dev);
3282 rrq->value = priv->rts_thresh;
3283 rrq->disabled = (rrq->value == 2347);
3289 static int orinoco_ioctl_setfrag(struct net_device *dev,
3290 struct iw_request_info *info,
3291 struct iw_param *frq,
3294 struct orinoco_private *priv = netdev_priv(dev);
3295 int err = -EINPROGRESS; /* Call commit handler */
3296 unsigned long flags;
3298 if (orinoco_lock(priv, &flags) != 0)
3301 if (priv->has_mwo) {
3303 priv->mwo_robust = 0;
3306 printk(KERN_WARNING "%s: Fixed fragmentation is "
3307 "not supported on this firmware. "
3308 "Using MWO robust instead.\n", dev->name);
3309 priv->mwo_robust = 1;
3313 priv->frag_thresh = 2346;
3315 if ( (frq->value < 256) || (frq->value > 2346) )
3318 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3322 orinoco_unlock(priv, &flags);
3327 static int orinoco_ioctl_getfrag(struct net_device *dev,
3328 struct iw_request_info *info,
3329 struct iw_param *frq,
3332 struct orinoco_private *priv = netdev_priv(dev);
3333 hermes_t *hw = &priv->hw;
3336 unsigned long flags;
3338 if (orinoco_lock(priv, &flags) != 0)
3341 if (priv->has_mwo) {
3342 err = hermes_read_wordrec(hw, USER_BAP,
3343 HERMES_RID_CNFMWOROBUST_AGERE,
3348 frq->value = val ? 2347 : 0;
3349 frq->disabled = ! val;
3352 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3358 frq->disabled = (val >= 2346);
3362 orinoco_unlock(priv, &flags);
3367 static int orinoco_ioctl_setrate(struct net_device *dev,
3368 struct iw_request_info *info,
3369 struct iw_param *rrq,
3372 struct orinoco_private *priv = netdev_priv(dev);
3374 int bitrate; /* 100s of kilobits */
3376 unsigned long flags;
3378 /* As the user space doesn't know our highest rate, it uses -1
3379 * to ask us to set the highest rate. Test it using "iwconfig
3380 * ethX rate auto" - Jean II */
3381 if (rrq->value == -1)
3384 if (rrq->value % 100000)
3386 bitrate = rrq->value / 100000;
3389 if ( (bitrate != 10) && (bitrate != 20) &&
3390 (bitrate != 55) && (bitrate != 110) )
3393 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3394 if ( (bitrate_table[i].bitrate == bitrate) &&
3395 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3403 if (orinoco_lock(priv, &flags) != 0)
3405 priv->bitratemode = ratemode;
3406 orinoco_unlock(priv, &flags);
3408 return -EINPROGRESS;
3411 static int orinoco_ioctl_getrate(struct net_device *dev,
3412 struct iw_request_info *info,
3413 struct iw_param *rrq,
3416 struct orinoco_private *priv = netdev_priv(dev);
3417 hermes_t *hw = &priv->hw;
3422 unsigned long flags;
3424 if (orinoco_lock(priv, &flags) != 0)
3427 ratemode = priv->bitratemode;
3429 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3431 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3432 rrq->fixed = ! bitrate_table[ratemode].automatic;
3435 /* If the interface is running we try to find more about the
3437 if (netif_running(dev)) {
3438 err = hermes_read_wordrec(hw, USER_BAP,
3439 HERMES_RID_CURRENTTXRATE, &val);
3443 switch (priv->firmware_type) {
3444 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3445 /* Note : in Lucent firmware, the return value of
3446 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3447 * and therefore is totally different from the
3448 * encoding of HERMES_RID_CNFTXRATECONTROL.
3449 * Don't forget that 6Mb/s is really 5.5Mb/s */
3451 rrq->value = 5500000;
3453 rrq->value = val * 1000000;
3455 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3456 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3457 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3458 if (bitrate_table[i].intersil_txratectrl == val) {
3462 if (i >= BITRATE_TABLE_SIZE)
3463 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3466 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3474 orinoco_unlock(priv, &flags);
3479 static int orinoco_ioctl_setpower(struct net_device *dev,
3480 struct iw_request_info *info,
3481 struct iw_param *prq,
3484 struct orinoco_private *priv = netdev_priv(dev);
3485 int err = -EINPROGRESS; /* Call commit handler */
3486 unsigned long flags;
3488 if (orinoco_lock(priv, &flags) != 0)
3491 if (prq->disabled) {
3494 switch (prq->flags & IW_POWER_MODE) {
3495 case IW_POWER_UNICAST_R:
3499 case IW_POWER_ALL_R:
3504 /* No flags : but we may have a value - Jean II */
3512 if (prq->flags & IW_POWER_TIMEOUT) {
3514 priv->pm_timeout = prq->value / 1000;
3516 if (prq->flags & IW_POWER_PERIOD) {
3518 priv->pm_period = prq->value / 1000;
3520 /* It's valid to not have a value if we are just toggling
3521 * the flags... Jean II */
3529 orinoco_unlock(priv, &flags);
3534 static int orinoco_ioctl_getpower(struct net_device *dev,
3535 struct iw_request_info *info,
3536 struct iw_param *prq,
3539 struct orinoco_private *priv = netdev_priv(dev);
3540 hermes_t *hw = &priv->hw;
3542 u16 enable, period, timeout, mcast;
3543 unsigned long flags;
3545 if (orinoco_lock(priv, &flags) != 0)
3548 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3552 err = hermes_read_wordrec(hw, USER_BAP,
3553 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3557 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3565 prq->disabled = !enable;
3566 /* Note : by default, display the period */
3567 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3568 prq->flags = IW_POWER_TIMEOUT;
3569 prq->value = timeout * 1000;
3571 prq->flags = IW_POWER_PERIOD;
3572 prq->value = period * 1000;
3575 prq->flags |= IW_POWER_ALL_R;
3577 prq->flags |= IW_POWER_UNICAST_R;
3580 orinoco_unlock(priv, &flags);
3585 static int orinoco_ioctl_getretry(struct net_device *dev,
3586 struct iw_request_info *info,
3587 struct iw_param *rrq,
3590 struct orinoco_private *priv = netdev_priv(dev);
3591 hermes_t *hw = &priv->hw;
3593 u16 short_limit, long_limit, lifetime;
3594 unsigned long flags;
3596 if (orinoco_lock(priv, &flags) != 0)
3599 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3604 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3609 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3614 rrq->disabled = 0; /* Can't be disabled */
3616 /* Note : by default, display the retry number */
3617 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3618 rrq->flags = IW_RETRY_LIFETIME;
3619 rrq->value = lifetime * 1000; /* ??? */
3621 /* By default, display the min number */
3622 if ((rrq->flags & IW_RETRY_MAX)) {
3623 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3624 rrq->value = long_limit;
3626 rrq->flags = IW_RETRY_LIMIT;
3627 rrq->value = short_limit;
3628 if(short_limit != long_limit)
3629 rrq->flags |= IW_RETRY_MIN;
3634 orinoco_unlock(priv, &flags);
3639 static int orinoco_ioctl_reset(struct net_device *dev,
3640 struct iw_request_info *info,
3644 struct orinoco_private *priv = netdev_priv(dev);
3646 if (! capable(CAP_NET_ADMIN))
3649 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3650 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3652 /* Firmware reset */
3655 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3657 schedule_work(&priv->reset_work);
3663 static int orinoco_ioctl_setibssport(struct net_device *dev,
3664 struct iw_request_info *info,
3669 struct orinoco_private *priv = netdev_priv(dev);
3670 int val = *( (int *) extra );
3671 unsigned long flags;
3673 if (orinoco_lock(priv, &flags) != 0)
3676 priv->ibss_port = val ;
3678 /* Actually update the mode we are using */
3679 set_port_type(priv);
3681 orinoco_unlock(priv, &flags);
3682 return -EINPROGRESS; /* Call commit handler */
3685 static int orinoco_ioctl_getibssport(struct net_device *dev,
3686 struct iw_request_info *info,
3690 struct orinoco_private *priv = netdev_priv(dev);
3691 int *val = (int *) extra;
3693 *val = priv->ibss_port;
3697 static int orinoco_ioctl_setport3(struct net_device *dev,
3698 struct iw_request_info *info,
3702 struct orinoco_private *priv = netdev_priv(dev);
3703 int val = *( (int *) extra );
3705 unsigned long flags;
3707 if (orinoco_lock(priv, &flags) != 0)
3711 case 0: /* Try to do IEEE ad-hoc mode */
3712 if (! priv->has_ibss) {
3716 priv->prefer_port3 = 0;
3720 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3721 if (! priv->has_port3) {
3725 priv->prefer_port3 = 1;
3733 /* Actually update the mode we are using */
3734 set_port_type(priv);
3738 orinoco_unlock(priv, &flags);
3743 static int orinoco_ioctl_getport3(struct net_device *dev,
3744 struct iw_request_info *info,
3748 struct orinoco_private *priv = netdev_priv(dev);
3749 int *val = (int *) extra;
3751 *val = priv->prefer_port3;
3755 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3756 struct iw_request_info *info,
3760 struct orinoco_private *priv = netdev_priv(dev);
3761 unsigned long flags;
3764 if (! priv->has_preamble)
3767 /* 802.11b has recently defined some short preamble.
3768 * Basically, the Phy header has been reduced in size.
3769 * This increase performance, especially at high rates
3770 * (the preamble is transmitted at 1Mb/s), unfortunately
3771 * this give compatibility troubles... - Jean II */
3772 val = *( (int *) extra );
3774 if (orinoco_lock(priv, &flags) != 0)
3782 orinoco_unlock(priv, &flags);
3784 return -EINPROGRESS; /* Call commit handler */
3787 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3788 struct iw_request_info *info,
3792 struct orinoco_private *priv = netdev_priv(dev);
3793 int *val = (int *) extra;
3795 if (! priv->has_preamble)
3798 *val = priv->preamble;
3802 /* ioctl interface to hermes_read_ltv()
3803 * To use with iwpriv, pass the RID as the token argument, e.g.
3804 * iwpriv get_rid [0xfc00]
3805 * At least Wireless Tools 25 is required to use iwpriv.
3806 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3807 static int orinoco_ioctl_getrid(struct net_device *dev,
3808 struct iw_request_info *info,
3809 struct iw_point *data,
3812 struct orinoco_private *priv = netdev_priv(dev);
3813 hermes_t *hw = &priv->hw;
3814 int rid = data->flags;
3817 unsigned long flags;
3819 /* It's a "get" function, but we don't want users to access the
3820 * WEP key and other raw firmware data */
3821 if (! capable(CAP_NET_ADMIN))
3824 if (rid < 0xfc00 || rid > 0xffff)
3827 if (orinoco_lock(priv, &flags) != 0)
3830 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3835 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3839 orinoco_unlock(priv, &flags);
3843 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3845 static int orinoco_ioctl_setspy(struct net_device *dev,
3846 struct iw_request_info *info,
3847 struct iw_point *srq,
3851 struct orinoco_private *priv = netdev_priv(dev);
3852 struct sockaddr *address = (struct sockaddr *) extra;
3853 int number = srq->length;
3855 unsigned long flags;
3857 /* Make sure nobody mess with the structure while we do */
3858 if (orinoco_lock(priv, &flags) != 0)
3861 /* orinoco_lock() doesn't disable interrupts, so make sure the
3862 * interrupt rx path don't get confused while we copy */
3863 priv->spy_number = 0;
3866 /* Extract the addresses */
3867 for (i = 0; i < number; i++)
3868 memcpy(priv->spy_address[i], address[i].sa_data,
3871 memset(priv->spy_stat, 0,
3872 sizeof(struct iw_quality) * IW_MAX_SPY);
3873 /* Set number of addresses */
3874 priv->spy_number = number;
3877 /* Now, let the others play */
3878 orinoco_unlock(priv, &flags);
3880 /* Do NOT call commit handler */
3884 static int orinoco_ioctl_getspy(struct net_device *dev,
3885 struct iw_request_info *info,
3886 struct iw_point *srq,
3889 struct orinoco_private *priv = netdev_priv(dev);
3890 struct sockaddr *address = (struct sockaddr *) extra;
3893 unsigned long flags;
3895 if (orinoco_lock(priv, &flags) != 0)
3898 number = priv->spy_number;
3899 /* Create address struct */
3900 for (i = 0; i < number; i++) {
3901 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3902 address[i].sa_family = AF_UNIX;
3905 /* Create address struct */
3906 for (i = 0; i < number; i++) {
3907 memcpy(address[i].sa_data, priv->spy_address[i],
3909 address[i].sa_family = AF_UNIX;
3912 /* In theory, we should disable irqs while copying the stats
3913 * because the rx path might update it in the middle...
3914 * Bah, who care ? - Jean II */
3915 memcpy(extra + (sizeof(struct sockaddr) * number),
3916 priv->spy_stat, sizeof(struct iw_quality) * number);
3918 /* Reset updated flags. */
3919 for (i = 0; i < number; i++)
3920 priv->spy_stat[i].updated = 0;
3922 orinoco_unlock(priv, &flags);
3924 srq->length = number;
3929 /* Trigger a scan (look for other cells in the vicinity */
3930 static int orinoco_ioctl_setscan(struct net_device *dev,
3931 struct iw_request_info *info,
3932 struct iw_param *srq,
3935 struct orinoco_private *priv = netdev_priv(dev);
3936 hermes_t *hw = &priv->hw;
3938 unsigned long flags;
3940 /* Note : you may have realised that, as this is a SET operation,
3941 * this is priviledged and therefore a normal user can't
3943 * This is not an error, while the device perform scanning,
3944 * traffic doesn't flow, so it's a perfect DoS...
3947 if (orinoco_lock(priv, &flags) != 0)
3950 /* Scanning with port 0 disabled would fail */
3951 if (!netif_running(dev)) {
3956 /* In monitor mode, the scan results are always empty.
3957 * Probe responses are passed to the driver as received
3958 * frames and could be processed in software. */
3959 if (priv->iw_mode == IW_MODE_MONITOR) {
3964 /* Note : because we don't lock out the irq handler, the way
3965 * we access scan variables in priv is critical.
3966 * o scan_inprogress : not touched by irq handler
3967 * o scan_mode : not touched by irq handler
3968 * o scan_result : irq is strict producer, non-irq is strict
3970 * o scan_len : synchronised with scan_result
3971 * Before modifying anything on those variables, please think hard !
3974 /* If there is still some left-over scan results, get rid of it */
3975 if (priv->scan_result != NULL) {
3976 /* What's likely is that a client did crash or was killed
3977 * between triggering the scan request and reading the
3978 * results, so we need to reset everything.
3979 * Some clients that are too slow may suffer from that...
3981 kfree(priv->scan_result);
3982 priv->scan_result = NULL;
3986 priv->scan_mode = srq->flags;
3988 /* Always trigger scanning, even if it's in progress.
3989 * This way, if the info frame get lost, we will recover somewhat
3990 * gracefully - Jean II */
3992 if (priv->has_hostscan) {
3993 switch (priv->firmware_type) {
3994 case FIRMWARE_TYPE_SYMBOL:
3995 err = hermes_write_wordrec(hw, USER_BAP,
3996 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3997 HERMES_HOSTSCAN_SYMBOL_ONCE |
3998 HERMES_HOSTSCAN_SYMBOL_BCAST);
4000 case FIRMWARE_TYPE_INTERSIL: {
4003 req[0] = cpu_to_le16(0x3fff); /* All channels */
4004 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4005 req[2] = 0; /* Any ESSID */
4006 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4007 HERMES_RID_CNFHOSTSCAN, &req);
4010 case FIRMWARE_TYPE_AGERE:
4011 err = hermes_write_wordrec(hw, USER_BAP,
4012 HERMES_RID_CNFSCANSSID_AGERE,
4017 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4021 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4023 /* One more client */
4025 priv->scan_inprogress = 1;
4028 orinoco_unlock(priv, &flags);
4032 /* Translate scan data returned from the card to a card independant
4033 * format that the Wireless Tools will understand - Jean II
4034 * Return message length or -errno for fatal errors */
4035 static inline int orinoco_translate_scan(struct net_device *dev,
4040 struct orinoco_private *priv = netdev_priv(dev);
4041 int offset; /* In the scan data */
4042 union hermes_scan_info *atom;
4046 struct iw_event iwe; /* Temporary buffer */
4047 char * current_ev = buffer;
4048 char * end_buf = buffer + IW_SCAN_MAX_DATA;
4050 switch (priv->firmware_type) {
4051 case FIRMWARE_TYPE_AGERE:
4052 atom_len = sizeof(struct agere_scan_apinfo);
4055 case FIRMWARE_TYPE_SYMBOL:
4056 /* Lack of documentation necessitates this hack.
4057 * Different firmwares have 68 or 76 byte long atoms.
4058 * We try modulo first. If the length divides by both,
4059 * we check what would be the channel in the second
4060 * frame for a 68-byte atom. 76-byte atoms have 0 there.
4061 * Valid channel cannot be 0. */
4064 else if (scan_len % 68)
4066 else if (scan_len >= 1292 && scan[68] == 0)
4072 case FIRMWARE_TYPE_INTERSIL:
4074 if (priv->has_hostscan) {
4075 atom_len = le16_to_cpup((u16 *)scan);
4076 /* Sanity check for atom_len */
4077 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
4078 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
4079 dev->name, atom_len);
4083 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4089 /* Check that we got an whole number of atoms */
4090 if ((scan_len - offset) % atom_len) {
4091 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4092 "atom_len %d, offset %d\n", dev->name, scan_len,
4097 /* Read the entries one by one */
4098 for (; offset + atom_len <= scan_len; offset += atom_len) {
4100 atom = (union hermes_scan_info *) (scan + offset);
4102 /* First entry *MUST* be the AP MAC address */
4103 iwe.cmd = SIOCGIWAP;
4104 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4105 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4106 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4108 /* Other entries will be displayed in the order we give them */
4111 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4112 if (iwe.u.data.length > 32)
4113 iwe.u.data.length = 32;
4114 iwe.cmd = SIOCGIWESSID;
4115 iwe.u.data.flags = 1;
4116 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4119 iwe.cmd = SIOCGIWMODE;
4120 capabilities = le16_to_cpu(atom->a.capabilities);
4121 if (capabilities & 0x3) {
4122 if (capabilities & 0x1)
4123 iwe.u.mode = IW_MODE_MASTER;
4125 iwe.u.mode = IW_MODE_ADHOC;
4126 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4129 channel = atom->s.channel;
4130 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4132 iwe.cmd = SIOCGIWFREQ;
4133 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4135 current_ev = iwe_stream_add_event(current_ev, end_buf,
4136 &iwe, IW_EV_FREQ_LEN);
4139 /* Add quality statistics */
4141 iwe.u.qual.updated = 0x10; /* no link quality */
4142 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4143 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4144 /* Wireless tools prior to 27.pre22 will show link quality
4145 * anyway, so we provide a reasonable value. */
4146 if (iwe.u.qual.level > iwe.u.qual.noise)
4147 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4149 iwe.u.qual.qual = 0;
4150 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4152 /* Add encryption capability */
4153 iwe.cmd = SIOCGIWENCODE;
4154 if (capabilities & 0x10)
4155 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4157 iwe.u.data.flags = IW_ENCODE_DISABLED;
4158 iwe.u.data.length = 0;
4159 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4161 /* Bit rate is not available in Lucent/Agere firmwares */
4162 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4163 char * current_val = current_ev + IW_EV_LCP_LEN;
4167 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4172 iwe.cmd = SIOCGIWRATE;
4173 /* Those two flags are ignored... */
4174 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4176 for (i = 0; i < 10; i += step) {
4177 /* NULL terminated */
4178 if (atom->p.rates[i] == 0x0)
4180 /* Bit rate given in 500 kb/s units (+ 0x80) */
4181 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4182 current_val = iwe_stream_add_value(current_ev, current_val,
4186 /* Check if we added any event */
4187 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4188 current_ev = current_val;
4191 /* The other data in the scan result are not really
4192 * interesting, so for now drop it - Jean II */
4194 return current_ev - buffer;
4197 /* Return results of a scan */
4198 static int orinoco_ioctl_getscan(struct net_device *dev,
4199 struct iw_request_info *info,
4200 struct iw_point *srq,
4203 struct orinoco_private *priv = netdev_priv(dev);
4205 unsigned long flags;
4207 if (orinoco_lock(priv, &flags) != 0)
4210 /* If no results yet, ask to try again later */
4211 if (priv->scan_result == NULL) {
4212 if (priv->scan_inprogress)
4213 /* Important note : we don't want to block the caller
4214 * until results are ready for various reasons.
4215 * First, managing wait queues is complex and racy.
4216 * Second, we grab some rtnetlink lock before comming
4217 * here (in dev_ioctl()).
4218 * Third, we generate an Wireless Event, so the
4219 * caller can wait itself on that - Jean II */
4222 /* Client error, no scan results...
4223 * The caller need to restart the scan. */
4226 /* We have some results to push back to user space */
4228 /* Translate to WE format */
4229 int ret = orinoco_translate_scan(dev, extra,
4235 kfree(priv->scan_result);
4236 priv->scan_result = NULL;
4241 srq->flags = (__u16) priv->scan_mode;
4243 /* In any case, Scan results will be cleaned up in the
4244 * reset function and when exiting the driver.
4245 * The person triggering the scanning may never come to
4246 * pick the results, so we need to do it in those places.
4249 #ifdef SCAN_SINGLE_READ
4250 /* If you enable this option, only one client (the first
4251 * one) will be able to read the result (and only one
4252 * time). If there is multiple concurent clients that
4253 * want to read scan results, this behavior is not
4254 * advisable - Jean II */
4255 kfree(priv->scan_result);
4256 priv->scan_result = NULL;
4257 #endif /* SCAN_SINGLE_READ */
4258 /* Here, if too much time has elapsed since last scan,
4259 * we may want to clean up scan results... - Jean II */
4262 /* Scan is no longer in progress */
4263 priv->scan_inprogress = 0;
4266 orinoco_unlock(priv, &flags);
4270 /* Commit handler, called after set operations */
4271 static int orinoco_ioctl_commit(struct net_device *dev,
4272 struct iw_request_info *info,
4276 struct orinoco_private *priv = netdev_priv(dev);
4277 struct hermes *hw = &priv->hw;
4278 unsigned long flags;
4284 if (priv->broken_disableport) {
4289 if (orinoco_lock(priv, &flags) != 0)
4292 err = hermes_disable_port(hw, 0);
4294 printk(KERN_WARNING "%s: Unable to disable port "
4295 "while reconfiguring card\n", dev->name);
4296 priv->broken_disableport = 1;
4300 err = __orinoco_program_rids(dev);
4302 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4307 err = hermes_enable_port(hw, 0);
4309 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4316 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4317 schedule_work(&priv->reset_work);
4321 orinoco_unlock(priv, &flags);
4325 static const struct iw_priv_args orinoco_privtab[] = {
4326 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4327 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4328 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4330 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4332 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4333 0, "set_preamble" },
4334 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4336 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4337 0, "set_ibssport" },
4338 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4340 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4346 * Structures to export the Wireless Handlers
4349 static const iw_handler orinoco_handler[] = {
4350 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4351 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4352 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4353 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4354 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4355 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4356 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4357 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4358 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4359 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy,
4360 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy,
4361 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4362 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4363 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4364 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4365 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4366 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4367 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4368 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4369 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4370 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4371 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4372 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4373 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4374 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4375 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4376 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4377 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4378 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4379 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4384 Added typecasting since we no longer use iwreq_data -- Moustafa
4386 static const iw_handler orinoco_private_handler[] = {
4387 [0] = (iw_handler) orinoco_ioctl_reset,
4388 [1] = (iw_handler) orinoco_ioctl_reset,
4389 [2] = (iw_handler) orinoco_ioctl_setport3,
4390 [3] = (iw_handler) orinoco_ioctl_getport3,
4391 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4392 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4393 [6] = (iw_handler) orinoco_ioctl_setibssport,
4394 [7] = (iw_handler) orinoco_ioctl_getibssport,
4395 [9] = (iw_handler) orinoco_ioctl_getrid,
4398 static const struct iw_handler_def orinoco_handler_def = {
4399 .num_standard = ARRAY_SIZE(orinoco_handler),
4400 .num_private = ARRAY_SIZE(orinoco_private_handler),
4401 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4402 .standard = orinoco_handler,
4403 .private = orinoco_private_handler,
4404 .private_args = orinoco_privtab,
4405 .get_wireless_stats = orinoco_get_wireless_stats,
4408 static void orinoco_get_drvinfo(struct net_device *dev,
4409 struct ethtool_drvinfo *info)
4411 struct orinoco_private *priv = netdev_priv(dev);
4413 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4414 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4415 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4416 if (dev->class_dev.dev)
4417 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4418 sizeof(info->bus_info) - 1);
4420 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4421 "PCMCIA %p", priv->hw.iobase);
4424 static struct ethtool_ops orinoco_ethtool_ops = {
4425 .get_drvinfo = orinoco_get_drvinfo,
4426 .get_link = ethtool_op_get_link,
4429 /********************************************************************/
4431 /********************************************************************/
4434 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4436 printk(KERN_DEBUG "RX descriptor:\n");
4437 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4438 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4439 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4440 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4441 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4442 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4443 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4445 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4446 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4447 frame->p80211.frame_ctl);
4448 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4449 frame->p80211.duration_id);
4450 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4451 frame->p80211.addr1[0], frame->p80211.addr1[1],
4452 frame->p80211.addr1[2], frame->p80211.addr1[3],
4453 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4454 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4455 frame->p80211.addr2[0], frame->p80211.addr2[1],
4456 frame->p80211.addr2[2], frame->p80211.addr2[3],
4457 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4458 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4459 frame->p80211.addr3[0], frame->p80211.addr3[1],
4460 frame->p80211.addr3[2], frame->p80211.addr3[3],
4461 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4462 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4463 frame->p80211.seq_ctl);
4464 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4465 frame->p80211.addr4[0], frame->p80211.addr4[1],
4466 frame->p80211.addr4[2], frame->p80211.addr4[3],
4467 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4468 printk(KERN_DEBUG " data_len = 0x%04x\n",
4469 frame->p80211.data_len);
4471 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4472 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4473 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4474 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4475 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4476 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4477 frame->p8023.h_source[0], frame->p8023.h_source[1],
4478 frame->p8023.h_source[2], frame->p8023.h_source[3],
4479 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4480 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4482 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4483 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4484 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4485 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4486 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4487 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4488 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4492 /********************************************************************/
4493 /* Module initialization */
4494 /********************************************************************/
4496 EXPORT_SYMBOL(alloc_orinocodev);
4497 EXPORT_SYMBOL(free_orinocodev);
4499 EXPORT_SYMBOL(__orinoco_up);
4500 EXPORT_SYMBOL(__orinoco_down);
4501 EXPORT_SYMBOL(orinoco_reinit_firmware);
4503 EXPORT_SYMBOL(orinoco_interrupt);
4505 /* Can't be declared "const" or the whole __initdata section will
4507 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4508 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4509 "Pavel Roskin <proski@gnu.org>, et al)";
4511 static int __init init_orinoco(void)
4513 printk(KERN_DEBUG "%s\n", version);
4517 static void __exit exit_orinoco(void)
4521 module_init(init_orinoco);
4522 module_exit(exit_orinoco);