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 /* Length of the packet body */
507 /* FIXME: what if the skb is smaller than this? */
508 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
510 eh = (struct ethhdr *)skb->data;
512 memset(&desc, 0, sizeof(desc));
513 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
514 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
517 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
518 "to BAP\n", dev->name, err);
523 /* Clear the 802.11 header and data length fields - some
524 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
525 * if this isn't done. */
526 hermes_clear_words(hw, HERMES_DATA0,
527 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
529 /* Encapsulate Ethernet-II frames */
530 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
531 struct header_struct hdr;
533 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
534 p = skb->data + ETH_HLEN;
537 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
538 memcpy(hdr.src, eh->h_source, ETH_ALEN);
539 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
542 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
544 hdr.ethertype = eh->h_proto;
545 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
546 txfid, HERMES_802_3_OFFSET);
549 printk(KERN_ERR "%s: Error %d writing packet "
550 "header to BAP\n", dev->name, err);
554 } else { /* IEEE 802.3 frame */
555 data_len = len + ETH_HLEN;
556 data_off = HERMES_802_3_OFFSET;
560 /* Round up for odd length packets */
561 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
564 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
570 /* Finally, we actually initiate the send */
571 netif_stop_queue(dev);
573 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
576 netif_start_queue(dev);
577 printk(KERN_ERR "%s: Error %d transmitting packet\n",
583 dev->trans_start = jiffies;
584 stats->tx_bytes += data_off + data_len;
586 orinoco_unlock(priv, &flags);
590 TRACE_EXIT(dev->name);
594 TRACE_EXIT(dev->name);
596 orinoco_unlock(priv, &flags);
600 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
602 struct orinoco_private *priv = netdev_priv(dev);
603 u16 fid = hermes_read_regn(hw, ALLOCFID);
605 if (fid != priv->txfid) {
606 if (fid != DUMMY_FID)
607 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
612 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
615 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
617 struct orinoco_private *priv = netdev_priv(dev);
618 struct net_device_stats *stats = &priv->stats;
622 netif_wake_queue(dev);
624 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
627 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
629 struct orinoco_private *priv = netdev_priv(dev);
630 struct net_device_stats *stats = &priv->stats;
631 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
632 struct hermes_tx_descriptor_802_11 hdr;
635 if (fid == DUMMY_FID)
636 return; /* Nothing's really happened */
638 /* Read the frame header */
639 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
640 sizeof(struct hermes_tx_descriptor) +
641 sizeof(struct ieee80211_hdr),
644 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
648 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
649 "(FID=%04X error %d)\n",
650 dev->name, fid, err);
654 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
657 /* We produce a TXDROP event only for retry or lifetime
658 * exceeded, because that's the only status that really mean
659 * that this particular node went away.
660 * Other errors means that *we* screwed up. - Jean II */
661 hdr.status = le16_to_cpu(hdr.status);
662 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
663 union iwreq_data wrqu;
665 /* Copy 802.11 dest address.
666 * We use the 802.11 header because the frame may
667 * not be 802.3 or may be mangled...
668 * In Ad-Hoc mode, it will be the node address.
669 * In managed mode, it will be most likely the AP addr
670 * User space will figure out how to convert it to
671 * whatever it needs (IP address or else).
673 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
674 wrqu.addr.sa_family = ARPHRD_ETHER;
676 /* Send event to user space */
677 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
680 netif_wake_queue(dev);
683 static void orinoco_tx_timeout(struct net_device *dev)
685 struct orinoco_private *priv = netdev_priv(dev);
686 struct net_device_stats *stats = &priv->stats;
687 struct hermes *hw = &priv->hw;
689 printk(KERN_WARNING "%s: Tx timeout! "
690 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
691 dev->name, hermes_read_regn(hw, ALLOCFID),
692 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
696 schedule_work(&priv->reset_work);
699 /********************************************************************/
700 /* Rx path (data frames) */
701 /********************************************************************/
703 /* Does the frame have a SNAP header indicating it should be
704 * de-encapsulated to Ethernet-II? */
705 static inline int is_ethersnap(void *_hdr)
709 /* We de-encapsulate all packets which, a) have SNAP headers
710 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
711 * and where b) the OUI of the SNAP header is 00:00:00 or
712 * 00:00:f8 - we need both because different APs appear to use
713 * different OUIs for some reason */
714 return (memcmp(hdr, &encaps_hdr, 5) == 0)
715 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
718 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
719 int level, int noise)
721 struct orinoco_private *priv = netdev_priv(dev);
724 /* Gather wireless spy statistics: for each packet, compare the
725 * source address with out list, and if match, get the stats... */
726 for (i = 0; i < priv->spy_number; i++)
727 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
728 priv->spy_stat[i].level = level - 0x95;
729 priv->spy_stat[i].noise = noise - 0x95;
730 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
731 priv->spy_stat[i].updated = 7;
735 static void orinoco_stat_gather(struct net_device *dev,
737 struct hermes_rx_descriptor *desc)
739 struct orinoco_private *priv = netdev_priv(dev);
741 /* Using spy support with lots of Rx packets, like in an
742 * infrastructure (AP), will really slow down everything, because
743 * the MAC address must be compared to each entry of the spy list.
744 * If the user really asks for it (set some address in the
745 * spy list), we do it, but he will pay the price.
746 * Note that to get here, you need both WIRELESS_SPY
747 * compiled in AND some addresses in the list !!!
749 /* Note : gcc will optimise the whole section away if
750 * WIRELESS_SPY is not defined... - Jean II */
751 if (SPY_NUMBER(priv)) {
752 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
753 desc->signal, desc->silence);
758 * orinoco_rx_monitor - handle received monitor frames.
763 * desc rx descriptor of the frame
765 * Call context: interrupt
767 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
768 struct hermes_rx_descriptor *desc)
770 u32 hdrlen = 30; /* return full header by default */
776 struct orinoco_private *priv = netdev_priv(dev);
777 struct net_device_stats *stats = &priv->stats;
778 hermes_t *hw = &priv->hw;
780 len = le16_to_cpu(desc->data_len);
782 /* Determine the size of the header and the data */
783 fc = le16_to_cpu(desc->frame_ctl);
784 switch (fc & IEEE80211_FCTL_FTYPE) {
785 case IEEE80211_FTYPE_DATA:
786 if ((fc & IEEE80211_FCTL_TODS)
787 && (fc & IEEE80211_FCTL_FROMDS))
793 case IEEE80211_FTYPE_MGMT:
797 case IEEE80211_FTYPE_CTL:
798 switch (fc & IEEE80211_FCTL_STYPE) {
799 case IEEE80211_STYPE_PSPOLL:
800 case IEEE80211_STYPE_RTS:
801 case IEEE80211_STYPE_CFEND:
802 case IEEE80211_STYPE_CFENDACK:
805 case IEEE80211_STYPE_CTS:
806 case IEEE80211_STYPE_ACK:
812 /* Unknown frame type */
816 /* sanity check the length */
817 if (datalen > IEEE80211_DATA_LEN + 12) {
818 printk(KERN_DEBUG "%s: oversized monitor frame, "
819 "data length = %d\n", dev->name, datalen);
821 stats->rx_length_errors++;
825 skb = dev_alloc_skb(hdrlen + datalen);
827 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
833 /* Copy the 802.11 header to the skb */
834 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
835 skb->mac.raw = skb->data;
837 /* If any, copy the data from the card to the skb */
839 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
840 ALIGN(datalen, 2), rxfid,
841 HERMES_802_2_OFFSET);
843 printk(KERN_ERR "%s: error %d reading monitor frame\n",
850 skb->ip_summed = CHECKSUM_NONE;
851 skb->pkt_type = PACKET_OTHERHOST;
852 skb->protocol = __constant_htons(ETH_P_802_2);
854 dev->last_rx = jiffies;
856 stats->rx_bytes += skb->len;
862 dev_kfree_skb_irq(skb);
868 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
870 struct orinoco_private *priv = netdev_priv(dev);
871 struct net_device_stats *stats = &priv->stats;
872 struct iw_statistics *wstats = &priv->wstats;
873 struct sk_buff *skb = NULL;
874 u16 rxfid, status, fc;
876 struct hermes_rx_descriptor desc;
880 rxfid = hermes_read_regn(hw, RXFID);
882 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
885 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
886 "Frame dropped.\n", dev->name, err);
890 status = le16_to_cpu(desc.status);
892 if (status & HERMES_RXSTAT_BADCRC) {
893 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
895 stats->rx_crc_errors++;
899 /* Handle frames in monitor mode */
900 if (priv->iw_mode == IW_MODE_MONITOR) {
901 orinoco_rx_monitor(dev, rxfid, &desc);
905 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
906 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
908 wstats->discard.code++;
912 length = le16_to_cpu(desc.data_len);
913 fc = le16_to_cpu(desc.frame_ctl);
916 if (length < 3) { /* No for even an 802.2 LLC header */
917 /* At least on Symbol firmware with PCF we get quite a
918 lot of these legitimately - Poll frames with no
922 if (length > IEEE80211_DATA_LEN) {
923 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
925 stats->rx_length_errors++;
929 /* We need space for the packet data itself, plus an ethernet
930 header, plus 2 bytes so we can align the IP header on a
931 32bit boundary, plus 1 byte so we can read in odd length
932 packets from the card, which has an IO granularity of 16
934 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
936 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
941 /* We'll prepend the header, so reserve space for it. The worst
942 case is no decapsulation, when 802.3 header is prepended and
943 nothing is removed. 2 is for aligning the IP header. */
944 skb_reserve(skb, ETH_HLEN + 2);
946 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
947 ALIGN(length, 2), rxfid,
948 HERMES_802_2_OFFSET);
950 printk(KERN_ERR "%s: error %d reading frame. "
951 "Frame dropped.\n", dev->name, err);
955 /* Handle decapsulation
956 * In most cases, the firmware tell us about SNAP frames.
957 * For some reason, the SNAP frames sent by LinkSys APs
958 * are not properly recognised by most firmwares.
959 * So, check ourselves */
960 if (length >= ENCAPS_OVERHEAD &&
961 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
962 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
963 is_ethersnap(skb->data))) {
964 /* These indicate a SNAP within 802.2 LLC within
965 802.11 frame which we'll need to de-encapsulate to
966 the original EthernetII frame. */
967 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
969 /* 802.3 frame - prepend 802.3 header as is */
970 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
971 hdr->h_proto = htons(length);
973 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
974 if (fc & IEEE80211_FCTL_FROMDS)
975 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
977 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
979 dev->last_rx = jiffies;
981 skb->protocol = eth_type_trans(skb, dev);
982 skb->ip_summed = CHECKSUM_NONE;
983 if (fc & IEEE80211_FCTL_TODS)
984 skb->pkt_type = PACKET_OTHERHOST;
986 /* Process the wireless stats if needed */
987 orinoco_stat_gather(dev, skb, &desc);
989 /* Pass the packet to the networking stack */
992 stats->rx_bytes += length;
997 dev_kfree_skb_irq(skb);
1000 stats->rx_dropped++;
1003 /********************************************************************/
1004 /* Rx path (info frames) */
1005 /********************************************************************/
1007 static void print_linkstatus(struct net_device *dev, u16 status)
1011 if (suppress_linkstatus)
1015 case HERMES_LINKSTATUS_NOT_CONNECTED:
1016 s = "Not Connected";
1018 case HERMES_LINKSTATUS_CONNECTED:
1021 case HERMES_LINKSTATUS_DISCONNECTED:
1024 case HERMES_LINKSTATUS_AP_CHANGE:
1027 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1028 s = "AP Out of Range";
1030 case HERMES_LINKSTATUS_AP_IN_RANGE:
1033 case HERMES_LINKSTATUS_ASSOC_FAILED:
1034 s = "Association Failed";
1040 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1041 dev->name, s, status);
1044 /* Search scan results for requested BSSID, join it if found */
1045 static void orinoco_join_ap(struct net_device *dev)
1047 struct orinoco_private *priv = netdev_priv(dev);
1048 struct hermes *hw = &priv->hw;
1050 unsigned long flags;
1054 } __attribute__ ((packed)) req;
1055 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1056 struct prism2_scan_apinfo *atom = NULL;
1062 /* Allocate buffer for scan results */
1063 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1067 if (orinoco_lock(priv, &flags) != 0)
1070 /* Sanity checks in case user changed something in the meantime */
1071 if (! priv->bssid_fixed)
1074 if (strlen(priv->desired_essid) == 0)
1077 /* Read scan results from the firmware */
1078 err = hermes_read_ltv(hw, USER_BAP,
1079 HERMES_RID_SCANRESULTSTABLE,
1080 MAX_SCAN_LEN, &len, buf);
1082 printk(KERN_ERR "%s: Cannot read scan results\n",
1087 len = HERMES_RECLEN_TO_BYTES(len);
1089 /* Go through the scan results looking for the channel of the AP
1090 * we were requested to join */
1091 for (; offset + atom_len <= len; offset += atom_len) {
1092 atom = (struct prism2_scan_apinfo *) (buf + offset);
1093 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1100 DEBUG(1, "%s: Requested AP not found in scan results\n",
1105 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1106 req.channel = atom->channel; /* both are little-endian */
1107 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1110 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1114 orinoco_unlock(priv, &flags);
1117 /* Send new BSSID to userspace */
1118 static void orinoco_send_wevents(struct net_device *dev)
1120 struct orinoco_private *priv = netdev_priv(dev);
1121 struct hermes *hw = &priv->hw;
1122 union iwreq_data wrqu;
1124 unsigned long flags;
1126 if (orinoco_lock(priv, &flags) != 0)
1129 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1130 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1134 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1136 /* Send event to user space */
1137 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1138 orinoco_unlock(priv, &flags);
1141 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1143 struct orinoco_private *priv = netdev_priv(dev);
1148 } __attribute__ ((packed)) info;
1152 /* This is an answer to an INQUIRE command that we did earlier,
1153 * or an information "event" generated by the card
1154 * The controller return to us a pseudo frame containing
1155 * the information in question - Jean II */
1156 infofid = hermes_read_regn(hw, INFOFID);
1158 /* Read the info frame header - don't try too hard */
1159 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1162 printk(KERN_ERR "%s: error %d reading info frame. "
1163 "Frame dropped.\n", dev->name, err);
1167 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1168 type = le16_to_cpu(info.type);
1171 case HERMES_INQ_TALLIES: {
1172 struct hermes_tallies_frame tallies;
1173 struct iw_statistics *wstats = &priv->wstats;
1175 if (len > sizeof(tallies)) {
1176 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1178 len = sizeof(tallies);
1181 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1182 infofid, sizeof(info));
1186 /* Increment our various counters */
1187 /* wstats->discard.nwid - no wrong BSSID stuff */
1188 wstats->discard.code +=
1189 le16_to_cpu(tallies.RxWEPUndecryptable);
1190 if (len == sizeof(tallies))
1191 wstats->discard.code +=
1192 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1193 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1194 wstats->discard.misc +=
1195 le16_to_cpu(tallies.TxDiscardsWrongSA);
1196 wstats->discard.fragment +=
1197 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1198 wstats->discard.retries +=
1199 le16_to_cpu(tallies.TxRetryLimitExceeded);
1200 /* wstats->miss.beacon - no match */
1203 case HERMES_INQ_LINKSTATUS: {
1204 struct hermes_linkstatus linkstatus;
1208 if (priv->iw_mode == IW_MODE_MONITOR)
1211 if (len != sizeof(linkstatus)) {
1212 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1217 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1218 infofid, sizeof(info));
1221 newstatus = le16_to_cpu(linkstatus.linkstatus);
1223 /* Symbol firmware uses "out of range" to signal that
1224 * the hostscan frame can be requested. */
1225 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1226 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1227 priv->has_hostscan && priv->scan_inprogress) {
1228 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1232 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1233 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1234 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1237 netif_carrier_on(dev);
1238 else if (!ignore_disconnect)
1239 netif_carrier_off(dev);
1241 if (newstatus != priv->last_linkstatus) {
1242 priv->last_linkstatus = newstatus;
1243 print_linkstatus(dev, newstatus);
1244 /* The info frame contains only one word which is the
1245 * status (see hermes.h). The status is pretty boring
1246 * in itself, that's why we export the new BSSID...
1248 schedule_work(&priv->wevent_work);
1252 case HERMES_INQ_SCAN:
1253 if (!priv->scan_inprogress && priv->bssid_fixed &&
1254 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1255 schedule_work(&priv->join_work);
1259 case HERMES_INQ_HOSTSCAN:
1260 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1261 /* Result of a scanning. Contains information about
1262 * cells in the vicinity - Jean II */
1263 union iwreq_data wrqu;
1268 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1273 /* We are a strict producer. If the previous scan results
1274 * have not been consumed, we just have to drop this
1275 * frame. We can't remove the previous results ourselves,
1276 * that would be *very* racy... Jean II */
1277 if (priv->scan_result != NULL) {
1278 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1282 /* Allocate buffer for results */
1283 buf = kmalloc(len, GFP_ATOMIC);
1285 /* No memory, so can't printk()... */
1288 /* Read scan data */
1289 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1290 infofid, sizeof(info));
1296 #ifdef ORINOCO_DEBUG
1299 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1300 for(i = 1; i < (len * 2); i++)
1301 printk(":%02X", buf[i]);
1304 #endif /* ORINOCO_DEBUG */
1306 /* Allow the clients to access the results */
1307 priv->scan_len = len;
1308 priv->scan_result = buf;
1310 /* Send an empty event to user space.
1311 * We don't send the received data on the event because
1312 * it would require us to do complex transcoding, and
1313 * we want to minimise the work done in the irq handler
1314 * Use a request to extract the data - Jean II */
1315 wrqu.data.length = 0;
1316 wrqu.data.flags = 0;
1317 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1320 case HERMES_INQ_SEC_STAT_AGERE:
1321 /* Security status (Agere specific) */
1322 /* Ignore this frame for now */
1323 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1327 printk(KERN_DEBUG "%s: Unknown information frame received: "
1328 "type 0x%04x, length %d\n", dev->name, type, len);
1329 /* We don't actually do anything about it */
1334 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1336 if (net_ratelimit())
1337 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1340 /********************************************************************/
1341 /* Internal hardware control routines */
1342 /********************************************************************/
1344 int __orinoco_up(struct net_device *dev)
1346 struct orinoco_private *priv = netdev_priv(dev);
1347 struct hermes *hw = &priv->hw;
1350 netif_carrier_off(dev); /* just to make sure */
1352 err = __orinoco_program_rids(dev);
1354 printk(KERN_ERR "%s: Error %d configuring card\n",
1359 /* Fire things up again */
1360 hermes_set_irqmask(hw, ORINOCO_INTEN);
1361 err = hermes_enable_port(hw, 0);
1363 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1368 netif_start_queue(dev);
1373 int __orinoco_down(struct net_device *dev)
1375 struct orinoco_private *priv = netdev_priv(dev);
1376 struct hermes *hw = &priv->hw;
1379 netif_stop_queue(dev);
1381 if (! priv->hw_unavailable) {
1382 if (! priv->broken_disableport) {
1383 err = hermes_disable_port(hw, 0);
1385 /* Some firmwares (e.g. Intersil 1.3.x) seem
1386 * to have problems disabling the port, oh
1388 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1390 priv->broken_disableport = 1;
1393 hermes_set_irqmask(hw, 0);
1394 hermes_write_regn(hw, EVACK, 0xffff);
1397 /* firmware will have to reassociate */
1398 netif_carrier_off(dev);
1399 priv->last_linkstatus = 0xffff;
1404 int orinoco_reinit_firmware(struct net_device *dev)
1406 struct orinoco_private *priv = netdev_priv(dev);
1407 struct hermes *hw = &priv->hw;
1410 err = hermes_init(hw);
1414 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1415 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1416 /* Try workaround for old Symbol firmware bug */
1417 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1418 "(old Symbol firmware?). Trying to work around... ",
1421 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1422 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1424 printk("failed!\n");
1432 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1434 hermes_t *hw = &priv->hw;
1437 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1438 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1439 priv->ndev->name, priv->bitratemode);
1443 switch (priv->firmware_type) {
1444 case FIRMWARE_TYPE_AGERE:
1445 err = hermes_write_wordrec(hw, USER_BAP,
1446 HERMES_RID_CNFTXRATECONTROL,
1447 bitrate_table[priv->bitratemode].agere_txratectrl);
1449 case FIRMWARE_TYPE_INTERSIL:
1450 case FIRMWARE_TYPE_SYMBOL:
1451 err = hermes_write_wordrec(hw, USER_BAP,
1452 HERMES_RID_CNFTXRATECONTROL,
1453 bitrate_table[priv->bitratemode].intersil_txratectrl);
1462 /* Set fixed AP address */
1463 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1467 hermes_t *hw = &priv->hw;
1469 switch (priv->firmware_type) {
1470 case FIRMWARE_TYPE_AGERE:
1473 case FIRMWARE_TYPE_INTERSIL:
1474 if (priv->bssid_fixed)
1479 err = hermes_write_wordrec(hw, USER_BAP,
1480 HERMES_RID_CNFROAMINGMODE,
1483 case FIRMWARE_TYPE_SYMBOL:
1484 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1485 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1486 &priv->desired_bssid);
1492 /* Change the WEP keys and/or the current keys. Can be called
1493 * either from __orinoco_hw_setup_wep() or directly from
1494 * orinoco_ioctl_setiwencode(). In the later case the association
1495 * with the AP is not broken (if the firmware can handle it),
1496 * which is needed for 802.1x implementations. */
1497 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1499 hermes_t *hw = &priv->hw;
1502 switch (priv->firmware_type) {
1503 case FIRMWARE_TYPE_AGERE:
1504 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1505 HERMES_RID_CNFWEPKEYS_AGERE,
1509 err = hermes_write_wordrec(hw, USER_BAP,
1510 HERMES_RID_CNFTXKEY_AGERE,
1515 case FIRMWARE_TYPE_INTERSIL:
1516 case FIRMWARE_TYPE_SYMBOL:
1521 /* Force uniform key length to work around firmware bugs */
1522 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1524 if (keylen > LARGE_KEY_SIZE) {
1525 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1526 priv->ndev->name, priv->tx_key, keylen);
1530 /* Write all 4 keys */
1531 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1532 err = hermes_write_ltv(hw, USER_BAP,
1533 HERMES_RID_CNFDEFAULTKEY0 + i,
1534 HERMES_BYTES_TO_RECLEN(keylen),
1535 priv->keys[i].data);
1540 /* Write the index of the key used in transmission */
1541 err = hermes_write_wordrec(hw, USER_BAP,
1542 HERMES_RID_CNFWEPDEFAULTKEYID,
1553 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1555 hermes_t *hw = &priv->hw;
1557 int master_wep_flag;
1561 __orinoco_hw_setup_wepkeys(priv);
1563 if (priv->wep_restrict)
1564 auth_flag = HERMES_AUTH_SHARED_KEY;
1566 auth_flag = HERMES_AUTH_OPEN;
1568 switch (priv->firmware_type) {
1569 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1571 /* Enable the shared-key authentication. */
1572 err = hermes_write_wordrec(hw, USER_BAP,
1573 HERMES_RID_CNFAUTHENTICATION_AGERE,
1576 err = hermes_write_wordrec(hw, USER_BAP,
1577 HERMES_RID_CNFWEPENABLED_AGERE,
1583 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1584 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1586 if (priv->wep_restrict ||
1587 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1588 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1589 HERMES_WEP_EXCL_UNENCRYPTED;
1591 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1593 err = hermes_write_wordrec(hw, USER_BAP,
1594 HERMES_RID_CNFAUTHENTICATION,
1599 master_wep_flag = 0;
1601 if (priv->iw_mode == IW_MODE_MONITOR)
1602 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1604 /* Master WEP setting : on/off */
1605 err = hermes_write_wordrec(hw, USER_BAP,
1606 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1617 static int __orinoco_program_rids(struct net_device *dev)
1619 struct orinoco_private *priv = netdev_priv(dev);
1620 hermes_t *hw = &priv->hw;
1622 struct hermes_idstring idbuf;
1624 /* Set the MAC address */
1625 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1626 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1628 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1633 /* Set up the link mode */
1634 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1637 printk(KERN_ERR "%s: Error %d setting port type\n",
1641 /* Set the channel/frequency */
1642 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1643 err = hermes_write_wordrec(hw, USER_BAP,
1644 HERMES_RID_CNFOWNCHANNEL,
1647 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1648 dev->name, err, priv->channel);
1653 if (priv->has_ibss) {
1656 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1657 printk(KERN_WARNING "%s: This firmware requires an "
1658 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1659 /* With wvlan_cs, in this case, we would crash.
1660 * hopefully, this driver will behave better...
1664 createibss = priv->createibss;
1667 err = hermes_write_wordrec(hw, USER_BAP,
1668 HERMES_RID_CNFCREATEIBSS,
1671 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1677 /* Set the desired BSSID */
1678 err = __orinoco_hw_set_wap(priv);
1680 printk(KERN_ERR "%s: Error %d setting AP address\n",
1684 /* Set the desired ESSID */
1685 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1686 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1687 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1688 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1689 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1692 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1696 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1697 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1700 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1705 /* Set the station name */
1706 idbuf.len = cpu_to_le16(strlen(priv->nick));
1707 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1708 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1709 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1712 printk(KERN_ERR "%s: Error %d setting nickname\n",
1717 /* Set AP density */
1718 if (priv->has_sensitivity) {
1719 err = hermes_write_wordrec(hw, USER_BAP,
1720 HERMES_RID_CNFSYSTEMSCALE,
1723 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1724 "Disabling sensitivity control\n",
1727 priv->has_sensitivity = 0;
1731 /* Set RTS threshold */
1732 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1735 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1740 /* Set fragmentation threshold or MWO robustness */
1742 err = hermes_write_wordrec(hw, USER_BAP,
1743 HERMES_RID_CNFMWOROBUST_AGERE,
1746 err = hermes_write_wordrec(hw, USER_BAP,
1747 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1750 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1756 err = __orinoco_hw_set_bitrate(priv);
1758 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1763 /* Set power management */
1765 err = hermes_write_wordrec(hw, USER_BAP,
1766 HERMES_RID_CNFPMENABLED,
1769 printk(KERN_ERR "%s: Error %d setting up PM\n",
1774 err = hermes_write_wordrec(hw, USER_BAP,
1775 HERMES_RID_CNFMULTICASTRECEIVE,
1778 printk(KERN_ERR "%s: Error %d setting up PM\n",
1782 err = hermes_write_wordrec(hw, USER_BAP,
1783 HERMES_RID_CNFMAXSLEEPDURATION,
1786 printk(KERN_ERR "%s: Error %d setting up PM\n",
1790 err = hermes_write_wordrec(hw, USER_BAP,
1791 HERMES_RID_CNFPMHOLDOVERDURATION,
1794 printk(KERN_ERR "%s: Error %d setting up PM\n",
1800 /* Set preamble - only for Symbol so far... */
1801 if (priv->has_preamble) {
1802 err = hermes_write_wordrec(hw, USER_BAP,
1803 HERMES_RID_CNFPREAMBLE_SYMBOL,
1806 printk(KERN_ERR "%s: Error %d setting preamble\n",
1812 /* Set up encryption */
1813 if (priv->has_wep) {
1814 err = __orinoco_hw_setup_wep(priv);
1816 printk(KERN_ERR "%s: Error %d activating WEP\n",
1822 if (priv->iw_mode == IW_MODE_MONITOR) {
1823 /* Enable monitor mode */
1824 dev->type = ARPHRD_IEEE80211;
1825 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1826 HERMES_TEST_MONITOR, 0, NULL);
1828 /* Disable monitor mode */
1829 dev->type = ARPHRD_ETHER;
1830 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1831 HERMES_TEST_STOP, 0, NULL);
1836 /* Set promiscuity / multicast*/
1837 priv->promiscuous = 0;
1839 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1844 /* FIXME: return int? */
1846 __orinoco_set_multicast_list(struct net_device *dev)
1848 struct orinoco_private *priv = netdev_priv(dev);
1849 hermes_t *hw = &priv->hw;
1851 int promisc, mc_count;
1853 /* The Hermes doesn't seem to have an allmulti mode, so we go
1854 * into promiscuous mode and let the upper levels deal. */
1855 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1856 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1861 mc_count = dev->mc_count;
1864 if (promisc != priv->promiscuous) {
1865 err = hermes_write_wordrec(hw, USER_BAP,
1866 HERMES_RID_CNFPROMISCUOUSMODE,
1869 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1872 priv->promiscuous = promisc;
1875 if (! promisc && (mc_count || priv->mc_count) ) {
1876 struct dev_mc_list *p = dev->mc_list;
1877 struct hermes_multicast mclist;
1880 for (i = 0; i < mc_count; i++) {
1881 /* paranoia: is list shorter than mc_count? */
1883 /* paranoia: bad address size in list? */
1884 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1886 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1891 printk(KERN_WARNING "%s: Multicast list is "
1892 "longer than mc_count\n", dev->name);
1894 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1895 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1898 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1901 priv->mc_count = mc_count;
1904 /* Since we can set the promiscuous flag when it wasn't asked
1905 for, make sure the net_device knows about it. */
1906 if (priv->promiscuous)
1907 dev->flags |= IFF_PROMISC;
1909 dev->flags &= ~IFF_PROMISC;
1912 /* This must be called from user context, without locks held - use
1913 * schedule_work() */
1914 static void orinoco_reset(struct net_device *dev)
1916 struct orinoco_private *priv = netdev_priv(dev);
1917 struct hermes *hw = &priv->hw;
1919 unsigned long flags;
1921 if (orinoco_lock(priv, &flags) != 0)
1922 /* When the hardware becomes available again, whatever
1923 * detects that is responsible for re-initializing
1924 * it. So no need for anything further */
1927 netif_stop_queue(dev);
1929 /* Shut off interrupts. Depending on what state the hardware
1930 * is in, this might not work, but we'll try anyway */
1931 hermes_set_irqmask(hw, 0);
1932 hermes_write_regn(hw, EVACK, 0xffff);
1934 priv->hw_unavailable++;
1935 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1936 netif_carrier_off(dev);
1938 orinoco_unlock(priv, &flags);
1940 /* Scanning support: Cleanup of driver struct */
1941 kfree(priv->scan_result);
1942 priv->scan_result = NULL;
1943 priv->scan_inprogress = 0;
1945 if (priv->hard_reset) {
1946 err = (*priv->hard_reset)(priv);
1948 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1949 "performing hard reset\n", dev->name, err);
1954 err = orinoco_reinit_firmware(dev);
1956 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1961 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1963 priv->hw_unavailable--;
1965 /* priv->open or priv->hw_unavailable might have changed while
1966 * we dropped the lock */
1967 if (priv->open && (! priv->hw_unavailable)) {
1968 err = __orinoco_up(dev);
1970 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1973 dev->trans_start = jiffies;
1976 spin_unlock_irq(&priv->lock);
1980 hermes_set_irqmask(hw, 0);
1981 netif_device_detach(dev);
1982 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1985 /********************************************************************/
1986 /* Interrupt handler */
1987 /********************************************************************/
1989 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1991 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1994 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1996 /* This seems to happen a fair bit under load, but ignoring it
1997 seems to work fine...*/
1998 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2002 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2004 struct net_device *dev = (struct net_device *)dev_id;
2005 struct orinoco_private *priv = netdev_priv(dev);
2006 hermes_t *hw = &priv->hw;
2007 int count = MAX_IRQLOOPS_PER_IRQ;
2009 /* These are used to detect a runaway interrupt situation */
2010 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2011 * we panic and shut down the hardware */
2012 static int last_irq_jiffy = 0; /* jiffies value the last time
2014 static int loops_this_jiffy = 0;
2015 unsigned long flags;
2017 if (orinoco_lock(priv, &flags) != 0) {
2018 /* If hw is unavailable - we don't know if the irq was
2023 evstat = hermes_read_regn(hw, EVSTAT);
2024 events = evstat & hw->inten;
2026 orinoco_unlock(priv, &flags);
2030 if (jiffies != last_irq_jiffy)
2031 loops_this_jiffy = 0;
2032 last_irq_jiffy = jiffies;
2034 while (events && count--) {
2035 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2036 printk(KERN_WARNING "%s: IRQ handler is looping too "
2037 "much! Resetting.\n", dev->name);
2038 /* Disable interrupts for now */
2039 hermes_set_irqmask(hw, 0);
2040 schedule_work(&priv->reset_work);
2044 /* Check the card hasn't been removed */
2045 if (! hermes_present(hw)) {
2046 DEBUG(0, "orinoco_interrupt(): card removed\n");
2050 if (events & HERMES_EV_TICK)
2051 __orinoco_ev_tick(dev, hw);
2052 if (events & HERMES_EV_WTERR)
2053 __orinoco_ev_wterr(dev, hw);
2054 if (events & HERMES_EV_INFDROP)
2055 __orinoco_ev_infdrop(dev, hw);
2056 if (events & HERMES_EV_INFO)
2057 __orinoco_ev_info(dev, hw);
2058 if (events & HERMES_EV_RX)
2059 __orinoco_ev_rx(dev, hw);
2060 if (events & HERMES_EV_TXEXC)
2061 __orinoco_ev_txexc(dev, hw);
2062 if (events & HERMES_EV_TX)
2063 __orinoco_ev_tx(dev, hw);
2064 if (events & HERMES_EV_ALLOC)
2065 __orinoco_ev_alloc(dev, hw);
2067 hermes_write_regn(hw, EVACK, evstat);
2069 evstat = hermes_read_regn(hw, EVSTAT);
2070 events = evstat & hw->inten;
2073 orinoco_unlock(priv, &flags);
2077 /********************************************************************/
2078 /* Initialization */
2079 /********************************************************************/
2082 u16 id, variant, major, minor;
2083 } __attribute__ ((packed));
2085 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2087 if (nic_id->id < 0x8000)
2088 return FIRMWARE_TYPE_AGERE;
2089 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2090 return FIRMWARE_TYPE_SYMBOL;
2092 return FIRMWARE_TYPE_INTERSIL;
2095 /* Set priv->firmware type, determine firmware properties */
2096 static int determine_firmware(struct net_device *dev)
2098 struct orinoco_private *priv = netdev_priv(dev);
2099 hermes_t *hw = &priv->hw;
2101 struct comp_id nic_id, sta_id;
2102 unsigned int firmver;
2103 char tmp[SYMBOL_MAX_VER_LEN+1];
2105 /* Get the hardware version */
2106 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2108 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2113 le16_to_cpus(&nic_id.id);
2114 le16_to_cpus(&nic_id.variant);
2115 le16_to_cpus(&nic_id.major);
2116 le16_to_cpus(&nic_id.minor);
2117 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2118 dev->name, nic_id.id, nic_id.variant,
2119 nic_id.major, nic_id.minor);
2121 priv->firmware_type = determine_firmware_type(&nic_id);
2123 /* Get the firmware version */
2124 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2126 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2131 le16_to_cpus(&sta_id.id);
2132 le16_to_cpus(&sta_id.variant);
2133 le16_to_cpus(&sta_id.major);
2134 le16_to_cpus(&sta_id.minor);
2135 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2136 dev->name, sta_id.id, sta_id.variant,
2137 sta_id.major, sta_id.minor);
2139 switch (sta_id.id) {
2141 printk(KERN_ERR "%s: Primary firmware is active\n",
2145 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2148 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2149 case 0x21: /* Symbol Spectrum24 Trilogy */
2152 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2157 /* Default capabilities */
2158 priv->has_sensitivity = 1;
2160 priv->has_preamble = 0;
2161 priv->has_port3 = 1;
2164 priv->has_big_wep = 0;
2166 /* Determine capabilities from the firmware version */
2167 switch (priv->firmware_type) {
2168 case FIRMWARE_TYPE_AGERE:
2169 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2170 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2171 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2172 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2174 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2176 priv->has_ibss = (firmver >= 0x60006);
2177 priv->has_wep = (firmver >= 0x40020);
2178 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2179 Gold cards from the others? */
2180 priv->has_mwo = (firmver >= 0x60000);
2181 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2182 priv->ibss_port = 1;
2183 priv->has_hostscan = (firmver >= 0x8000a);
2184 priv->broken_monitor = (firmver >= 0x80000);
2186 /* Tested with Agere firmware :
2187 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2188 * Tested CableTron firmware : 4.32 => Anton */
2190 case FIRMWARE_TYPE_SYMBOL:
2191 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2192 /* Intel MAC : 00:02:B3:* */
2193 /* 3Com MAC : 00:50:DA:* */
2194 memset(tmp, 0, sizeof(tmp));
2195 /* Get the Symbol firmware version */
2196 err = hermes_read_ltv(hw, USER_BAP,
2197 HERMES_RID_SECONDARYVERSION_SYMBOL,
2198 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2201 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2206 /* The firmware revision is a string, the format is
2207 * something like : "V2.20-01".
2208 * Quick and dirty parsing... - Jean II
2210 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2211 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2214 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2217 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2220 priv->has_ibss = (firmver >= 0x20000);
2221 priv->has_wep = (firmver >= 0x15012);
2222 priv->has_big_wep = (firmver >= 0x20000);
2223 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2224 (firmver >= 0x29000 && firmver < 0x30000) ||
2226 priv->has_preamble = (firmver >= 0x20000);
2227 priv->ibss_port = 4;
2228 priv->broken_disableport = (firmver == 0x25013) ||
2229 (firmver >= 0x30000 && firmver <= 0x31000);
2230 priv->has_hostscan = (firmver >= 0x31001) ||
2231 (firmver >= 0x29057 && firmver < 0x30000);
2232 /* Tested with Intel firmware : 0x20015 => Jean II */
2233 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2235 case FIRMWARE_TYPE_INTERSIL:
2236 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2237 * Samsung, Compaq 100/200 and Proxim are slightly
2238 * different and less well tested */
2239 /* D-Link MAC : 00:40:05:* */
2240 /* Addtron MAC : 00:90:D1:* */
2241 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2242 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2245 firmver = ((unsigned long)sta_id.major << 16) |
2246 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2248 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2249 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2250 priv->has_pm = (firmver >= 0x000700);
2251 priv->has_hostscan = (firmver >= 0x010301);
2253 if (firmver >= 0x000800)
2254 priv->ibss_port = 0;
2256 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2257 "than v0.8.x - several features not supported\n",
2259 priv->ibss_port = 1;
2263 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2269 static int orinoco_init(struct net_device *dev)
2271 struct orinoco_private *priv = netdev_priv(dev);
2272 hermes_t *hw = &priv->hw;
2274 struct hermes_idstring nickbuf;
2278 TRACE_ENTER(dev->name);
2280 /* No need to lock, the hw_unavailable flag is already set in
2281 * alloc_orinocodev() */
2282 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2284 /* Initialize the firmware */
2285 err = orinoco_reinit_firmware(dev);
2287 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2292 err = determine_firmware(dev);
2294 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2299 if (priv->has_port3)
2300 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2302 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2304 if (priv->has_wep) {
2305 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2306 if (priv->has_big_wep)
2307 printk("104-bit key\n");
2309 printk("40-bit key\n");
2312 /* Get the MAC address */
2313 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2314 ETH_ALEN, NULL, dev->dev_addr);
2316 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2321 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2322 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2323 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2326 /* Get the station name */
2327 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2328 sizeof(nickbuf), &reclen, &nickbuf);
2330 printk(KERN_ERR "%s: failed to read station name\n",
2335 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2337 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2338 memcpy(priv->nick, &nickbuf.val, len);
2339 priv->nick[len] = '\0';
2341 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2343 /* Get allowed channels */
2344 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2345 &priv->channel_mask);
2347 printk(KERN_ERR "%s: failed to read channel list!\n",
2352 /* Get initial AP density */
2353 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2355 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2356 priv->has_sensitivity = 0;
2359 /* Get initial RTS threshold */
2360 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2363 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2368 /* Get initial fragmentation settings */
2370 err = hermes_read_wordrec(hw, USER_BAP,
2371 HERMES_RID_CNFMWOROBUST_AGERE,
2374 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2375 &priv->frag_thresh);
2377 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2382 /* Power management setup */
2386 err = hermes_read_wordrec(hw, USER_BAP,
2387 HERMES_RID_CNFMAXSLEEPDURATION,
2390 printk(KERN_ERR "%s: failed to read power management period!\n",
2394 err = hermes_read_wordrec(hw, USER_BAP,
2395 HERMES_RID_CNFPMHOLDOVERDURATION,
2398 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2404 /* Preamble setup */
2405 if (priv->has_preamble) {
2406 err = hermes_read_wordrec(hw, USER_BAP,
2407 HERMES_RID_CNFPREAMBLE_SYMBOL,
2413 /* Set up the default configuration */
2414 priv->iw_mode = IW_MODE_INFRA;
2415 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2416 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2417 set_port_type(priv);
2418 priv->channel = 0; /* use firmware default */
2420 priv->promiscuous = 0;
2424 /* Make the hardware available, as long as it hasn't been
2425 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2426 spin_lock_irq(&priv->lock);
2427 priv->hw_unavailable--;
2428 spin_unlock_irq(&priv->lock);
2430 printk(KERN_DEBUG "%s: ready\n", dev->name);
2433 TRACE_EXIT(dev->name);
2437 struct net_device *alloc_orinocodev(int sizeof_card,
2438 int (*hard_reset)(struct orinoco_private *))
2440 struct net_device *dev;
2441 struct orinoco_private *priv;
2443 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2446 priv = netdev_priv(dev);
2449 priv->card = (void *)((unsigned long)priv
2450 + sizeof(struct orinoco_private));
2454 /* Setup / override net_device fields */
2455 dev->init = orinoco_init;
2456 dev->hard_start_xmit = orinoco_xmit;
2457 dev->tx_timeout = orinoco_tx_timeout;
2458 dev->watchdog_timeo = HZ; /* 1 second timeout */
2459 dev->get_stats = orinoco_get_stats;
2460 dev->ethtool_ops = &orinoco_ethtool_ops;
2461 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2462 dev->change_mtu = orinoco_change_mtu;
2463 dev->set_multicast_list = orinoco_set_multicast_list;
2464 /* we use the default eth_mac_addr for setting the MAC addr */
2466 /* Set up default callbacks */
2467 dev->open = orinoco_open;
2468 dev->stop = orinoco_stop;
2469 priv->hard_reset = hard_reset;
2471 spin_lock_init(&priv->lock);
2473 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2474 * before anything else touches the
2476 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2477 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2478 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2480 netif_carrier_off(dev);
2481 priv->last_linkstatus = 0xffff;
2487 void free_orinocodev(struct net_device *dev)
2489 struct orinoco_private *priv = netdev_priv(dev);
2491 kfree(priv->scan_result);
2495 /********************************************************************/
2496 /* Wireless extensions */
2497 /********************************************************************/
2499 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2500 char buf[IW_ESSID_MAX_SIZE+1])
2502 hermes_t *hw = &priv->hw;
2504 struct hermes_idstring essidbuf;
2505 char *p = (char *)(&essidbuf.val);
2507 unsigned long flags;
2509 if (orinoco_lock(priv, &flags) != 0)
2512 if (strlen(priv->desired_essid) > 0) {
2513 /* We read the desired SSID from the hardware rather
2514 than from priv->desired_essid, just in case the
2515 firmware is allowed to change it on us. I'm not
2517 /* My guess is that the OWNSSID should always be whatever
2518 * we set to the card, whereas CURRENT_SSID is the one that
2519 * may change... - Jean II */
2524 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2525 HERMES_RID_CNFDESIREDSSID;
2527 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2534 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2535 sizeof(essidbuf), NULL, &essidbuf);
2540 len = le16_to_cpu(essidbuf.len);
2541 BUG_ON(len > IW_ESSID_MAX_SIZE);
2543 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2544 memcpy(buf, p, len);
2548 orinoco_unlock(priv, &flags);
2553 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2556 hermes_t *hw = &priv->hw;
2560 unsigned long flags;
2562 if (orinoco_lock(priv, &flags) != 0)
2565 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2569 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2575 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2576 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2577 priv->ndev->name, channel);
2582 freq = channel_frequency[channel-1] * 100000;
2585 orinoco_unlock(priv, &flags);
2589 return err ? err : freq;
2592 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2593 int *numrates, s32 *rates, int max)
2595 hermes_t *hw = &priv->hw;
2596 struct hermes_idstring list;
2597 unsigned char *p = (unsigned char *)&list.val;
2601 unsigned long flags;
2603 if (orinoco_lock(priv, &flags) != 0)
2606 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2607 sizeof(list), NULL, &list);
2608 orinoco_unlock(priv, &flags);
2613 num = le16_to_cpu(list.len);
2615 num = min(num, max);
2617 for (i = 0; i < num; i++) {
2618 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2624 static int orinoco_ioctl_getname(struct net_device *dev,
2625 struct iw_request_info *info,
2629 struct orinoco_private *priv = netdev_priv(dev);
2633 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2635 if (!err && (numrates > 2))
2636 strcpy(name, "IEEE 802.11b");
2638 strcpy(name, "IEEE 802.11-DS");
2643 static int orinoco_ioctl_setwap(struct net_device *dev,
2644 struct iw_request_info *info,
2645 struct sockaddr *ap_addr,
2648 struct orinoco_private *priv = netdev_priv(dev);
2649 int err = -EINPROGRESS; /* Call commit handler */
2650 unsigned long flags;
2651 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2652 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2654 if (orinoco_lock(priv, &flags) != 0)
2657 /* Enable automatic roaming - no sanity checks are needed */
2658 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2659 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2660 priv->bssid_fixed = 0;
2661 memset(priv->desired_bssid, 0, ETH_ALEN);
2663 /* "off" means keep existing connection */
2664 if (ap_addr->sa_data[0] == 0) {
2665 __orinoco_hw_set_wap(priv);
2671 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2672 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2673 "support manual roaming\n",
2679 if (priv->iw_mode != IW_MODE_INFRA) {
2680 printk(KERN_WARNING "%s: Manual roaming supported only in "
2681 "managed mode\n", dev->name);
2686 /* Intersil firmware hangs without Desired ESSID */
2687 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2688 strlen(priv->desired_essid) == 0) {
2689 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2690 "manual roaming\n", dev->name);
2695 /* Finally, enable manual roaming */
2696 priv->bssid_fixed = 1;
2697 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2700 orinoco_unlock(priv, &flags);
2704 static int orinoco_ioctl_getwap(struct net_device *dev,
2705 struct iw_request_info *info,
2706 struct sockaddr *ap_addr,
2709 struct orinoco_private *priv = netdev_priv(dev);
2711 hermes_t *hw = &priv->hw;
2713 unsigned long flags;
2715 if (orinoco_lock(priv, &flags) != 0)
2718 ap_addr->sa_family = ARPHRD_ETHER;
2719 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2720 ETH_ALEN, NULL, ap_addr->sa_data);
2722 orinoco_unlock(priv, &flags);
2727 static int orinoco_ioctl_setmode(struct net_device *dev,
2728 struct iw_request_info *info,
2732 struct orinoco_private *priv = netdev_priv(dev);
2733 int err = -EINPROGRESS; /* Call commit handler */
2734 unsigned long flags;
2736 if (priv->iw_mode == *mode)
2739 if (orinoco_lock(priv, &flags) != 0)
2744 if (!priv->has_ibss && !priv->has_port3)
2751 case IW_MODE_MONITOR:
2752 if (priv->broken_monitor && !force_monitor) {
2753 printk(KERN_WARNING "%s: Monitor mode support is "
2754 "buggy in this firmware, not enabling\n",
2765 if (err == -EINPROGRESS) {
2766 priv->iw_mode = *mode;
2767 set_port_type(priv);
2770 orinoco_unlock(priv, &flags);
2775 static int orinoco_ioctl_getmode(struct net_device *dev,
2776 struct iw_request_info *info,
2780 struct orinoco_private *priv = netdev_priv(dev);
2782 *mode = priv->iw_mode;
2786 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2787 struct iw_request_info *info,
2788 struct iw_point *rrq,
2791 struct orinoco_private *priv = netdev_priv(dev);
2793 struct iw_range *range = (struct iw_range *) extra;
2797 TRACE_ENTER(dev->name);
2799 rrq->length = sizeof(struct iw_range);
2800 memset(range, 0, sizeof(struct iw_range));
2802 range->we_version_compiled = WIRELESS_EXT;
2803 range->we_version_source = 14;
2805 /* Set available channels/frequencies */
2806 range->num_channels = NUM_CHANNELS;
2808 for (i = 0; i < NUM_CHANNELS; i++) {
2809 if (priv->channel_mask & (1 << i)) {
2810 range->freq[k].i = i + 1;
2811 range->freq[k].m = channel_frequency[i] * 100000;
2812 range->freq[k].e = 1;
2816 if (k >= IW_MAX_FREQUENCIES)
2819 range->num_frequency = k;
2820 range->sensitivity = 3;
2822 if (priv->has_wep) {
2823 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2824 range->encoding_size[0] = SMALL_KEY_SIZE;
2825 range->num_encoding_sizes = 1;
2827 if (priv->has_big_wep) {
2828 range->encoding_size[1] = LARGE_KEY_SIZE;
2829 range->num_encoding_sizes = 2;
2833 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2834 /* Quality stats meaningless in ad-hoc mode */
2836 range->max_qual.qual = 0x8b - 0x2f;
2837 range->max_qual.level = 0x2f - 0x95 - 1;
2838 range->max_qual.noise = 0x2f - 0x95 - 1;
2839 /* Need to get better values */
2840 range->avg_qual.qual = 0x24;
2841 range->avg_qual.level = 0xC2;
2842 range->avg_qual.noise = 0x9E;
2845 err = orinoco_hw_get_bitratelist(priv, &numrates,
2846 range->bitrate, IW_MAX_BITRATES);
2849 range->num_bitrates = numrates;
2851 /* Set an indication of the max TCP throughput in bit/s that we can
2852 * expect using this interface. May be use for QoS stuff...
2855 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2857 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2860 range->max_rts = 2347;
2861 range->min_frag = 256;
2862 range->max_frag = 2346;
2865 range->max_pmp = 65535000;
2867 range->max_pmt = 65535 * 1000; /* ??? */
2868 range->pmp_flags = IW_POWER_PERIOD;
2869 range->pmt_flags = IW_POWER_TIMEOUT;
2870 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2872 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2873 range->retry_flags = IW_RETRY_LIMIT;
2874 range->r_time_flags = IW_RETRY_LIFETIME;
2875 range->min_retry = 0;
2876 range->max_retry = 65535; /* ??? */
2877 range->min_r_time = 0;
2878 range->max_r_time = 65535 * 1000; /* ??? */
2880 TRACE_EXIT(dev->name);
2885 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2886 struct iw_request_info *info,
2887 struct iw_point *erq,
2890 struct orinoco_private *priv = netdev_priv(dev);
2891 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2892 int setindex = priv->tx_key;
2893 int enable = priv->wep_on;
2894 int restricted = priv->wep_restrict;
2896 int err = -EINPROGRESS; /* Call commit handler */
2897 unsigned long flags;
2899 if (! priv->has_wep)
2903 /* We actually have a key to set - check its length */
2904 if (erq->length > LARGE_KEY_SIZE)
2907 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2911 if (orinoco_lock(priv, &flags) != 0)
2915 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2916 index = priv->tx_key;
2918 /* Adjust key length to a supported value */
2919 if (erq->length > SMALL_KEY_SIZE) {
2920 xlen = LARGE_KEY_SIZE;
2921 } else if (erq->length > 0) {
2922 xlen = SMALL_KEY_SIZE;
2926 /* Switch on WEP if off */
2927 if ((!enable) && (xlen > 0)) {
2932 /* Important note : if the user do "iwconfig eth0 enc off",
2933 * we will arrive there with an index of -1. This is valid
2934 * but need to be taken care off... Jean II */
2935 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2936 if((index != -1) || (erq->flags == 0)) {
2941 /* Set the index : Check that the key is valid */
2942 if(priv->keys[index].len == 0) {
2950 if (erq->flags & IW_ENCODE_DISABLED)
2952 if (erq->flags & IW_ENCODE_OPEN)
2954 if (erq->flags & IW_ENCODE_RESTRICTED)
2958 priv->keys[index].len = cpu_to_le16(xlen);
2959 memset(priv->keys[index].data, 0,
2960 sizeof(priv->keys[index].data));
2961 memcpy(priv->keys[index].data, keybuf, erq->length);
2963 priv->tx_key = setindex;
2965 /* Try fast key change if connected and only keys are changed */
2966 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2967 netif_carrier_ok(dev)) {
2968 err = __orinoco_hw_setup_wepkeys(priv);
2969 /* No need to commit if successful */
2973 priv->wep_on = enable;
2974 priv->wep_restrict = restricted;
2977 orinoco_unlock(priv, &flags);
2982 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2983 struct iw_request_info *info,
2984 struct iw_point *erq,
2987 struct orinoco_private *priv = netdev_priv(dev);
2988 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2990 unsigned long flags;
2992 if (! priv->has_wep)
2995 if (orinoco_lock(priv, &flags) != 0)
2998 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2999 index = priv->tx_key;
3003 erq->flags |= IW_ENCODE_DISABLED;
3004 erq->flags |= index + 1;
3006 if (priv->wep_restrict)
3007 erq->flags |= IW_ENCODE_RESTRICTED;
3009 erq->flags |= IW_ENCODE_OPEN;
3011 xlen = le16_to_cpu(priv->keys[index].len);
3015 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3017 orinoco_unlock(priv, &flags);
3021 static int orinoco_ioctl_setessid(struct net_device *dev,
3022 struct iw_request_info *info,
3023 struct iw_point *erq,
3026 struct orinoco_private *priv = netdev_priv(dev);
3027 unsigned long flags;
3029 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3030 * anyway... - Jean II */
3032 /* Hum... Should not use Wireless Extension constant (may change),
3033 * should use our own... - Jean II */
3034 if (erq->length > IW_ESSID_MAX_SIZE)
3037 if (orinoco_lock(priv, &flags) != 0)
3040 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3041 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3043 /* If not ANY, get the new ESSID */
3045 memcpy(priv->desired_essid, essidbuf, erq->length);
3048 orinoco_unlock(priv, &flags);
3050 return -EINPROGRESS; /* Call commit handler */
3053 static int orinoco_ioctl_getessid(struct net_device *dev,
3054 struct iw_request_info *info,
3055 struct iw_point *erq,
3058 struct orinoco_private *priv = netdev_priv(dev);
3061 unsigned long flags;
3063 TRACE_ENTER(dev->name);
3065 if (netif_running(dev)) {
3066 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3070 if (orinoco_lock(priv, &flags) != 0)
3072 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3073 orinoco_unlock(priv, &flags);
3077 erq->length = strlen(essidbuf) + 1;
3079 TRACE_EXIT(dev->name);
3084 static int orinoco_ioctl_setnick(struct net_device *dev,
3085 struct iw_request_info *info,
3086 struct iw_point *nrq,
3089 struct orinoco_private *priv = netdev_priv(dev);
3090 unsigned long flags;
3092 if (nrq->length > IW_ESSID_MAX_SIZE)
3095 if (orinoco_lock(priv, &flags) != 0)
3098 memset(priv->nick, 0, sizeof(priv->nick));
3099 memcpy(priv->nick, nickbuf, nrq->length);
3101 orinoco_unlock(priv, &flags);
3103 return -EINPROGRESS; /* Call commit handler */
3106 static int orinoco_ioctl_getnick(struct net_device *dev,
3107 struct iw_request_info *info,
3108 struct iw_point *nrq,
3111 struct orinoco_private *priv = netdev_priv(dev);
3112 unsigned long flags;
3114 if (orinoco_lock(priv, &flags) != 0)
3117 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3118 orinoco_unlock(priv, &flags);
3120 nrq->length = strlen(nickbuf)+1;
3125 static int orinoco_ioctl_setfreq(struct net_device *dev,
3126 struct iw_request_info *info,
3127 struct iw_freq *frq,
3130 struct orinoco_private *priv = netdev_priv(dev);
3132 unsigned long flags;
3133 int err = -EINPROGRESS; /* Call commit handler */
3135 /* In infrastructure mode the AP sets the channel */
3136 if (priv->iw_mode == IW_MODE_INFRA)
3139 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3140 /* Setting by channel number */
3143 /* Setting by frequency - search the table */
3147 for (i = 0; i < (6 - frq->e); i++)
3150 for (i = 0; i < NUM_CHANNELS; i++)
3151 if (frq->m == (channel_frequency[i] * mult))
3155 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3156 ! (priv->channel_mask & (1 << (chan-1)) ) )
3159 if (orinoco_lock(priv, &flags) != 0)
3162 priv->channel = chan;
3163 if (priv->iw_mode == IW_MODE_MONITOR) {
3164 /* Fast channel change - no commit if successful */
3165 hermes_t *hw = &priv->hw;
3166 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3167 HERMES_TEST_SET_CHANNEL,
3170 orinoco_unlock(priv, &flags);
3175 static int orinoco_ioctl_getfreq(struct net_device *dev,
3176 struct iw_request_info *info,
3177 struct iw_freq *frq,
3180 struct orinoco_private *priv = netdev_priv(dev);
3183 /* Locking done in there */
3184 tmp = orinoco_hw_get_freq(priv);
3195 static int orinoco_ioctl_getsens(struct net_device *dev,
3196 struct iw_request_info *info,
3197 struct iw_param *srq,
3200 struct orinoco_private *priv = netdev_priv(dev);
3201 hermes_t *hw = &priv->hw;
3204 unsigned long flags;
3206 if (!priv->has_sensitivity)
3209 if (orinoco_lock(priv, &flags) != 0)
3211 err = hermes_read_wordrec(hw, USER_BAP,
3212 HERMES_RID_CNFSYSTEMSCALE, &val);
3213 orinoco_unlock(priv, &flags);
3219 srq->fixed = 0; /* auto */
3224 static int orinoco_ioctl_setsens(struct net_device *dev,
3225 struct iw_request_info *info,
3226 struct iw_param *srq,
3229 struct orinoco_private *priv = netdev_priv(dev);
3230 int val = srq->value;
3231 unsigned long flags;
3233 if (!priv->has_sensitivity)
3236 if ((val < 1) || (val > 3))
3239 if (orinoco_lock(priv, &flags) != 0)
3241 priv->ap_density = val;
3242 orinoco_unlock(priv, &flags);
3244 return -EINPROGRESS; /* Call commit handler */
3247 static int orinoco_ioctl_setrts(struct net_device *dev,
3248 struct iw_request_info *info,
3249 struct iw_param *rrq,
3252 struct orinoco_private *priv = netdev_priv(dev);
3253 int val = rrq->value;
3254 unsigned long flags;
3259 if ( (val < 0) || (val > 2347) )
3262 if (orinoco_lock(priv, &flags) != 0)
3265 priv->rts_thresh = val;
3266 orinoco_unlock(priv, &flags);
3268 return -EINPROGRESS; /* Call commit handler */
3271 static int orinoco_ioctl_getrts(struct net_device *dev,
3272 struct iw_request_info *info,
3273 struct iw_param *rrq,
3276 struct orinoco_private *priv = netdev_priv(dev);
3278 rrq->value = priv->rts_thresh;
3279 rrq->disabled = (rrq->value == 2347);
3285 static int orinoco_ioctl_setfrag(struct net_device *dev,
3286 struct iw_request_info *info,
3287 struct iw_param *frq,
3290 struct orinoco_private *priv = netdev_priv(dev);
3291 int err = -EINPROGRESS; /* Call commit handler */
3292 unsigned long flags;
3294 if (orinoco_lock(priv, &flags) != 0)
3297 if (priv->has_mwo) {
3299 priv->mwo_robust = 0;
3302 printk(KERN_WARNING "%s: Fixed fragmentation is "
3303 "not supported on this firmware. "
3304 "Using MWO robust instead.\n", dev->name);
3305 priv->mwo_robust = 1;
3309 priv->frag_thresh = 2346;
3311 if ( (frq->value < 256) || (frq->value > 2346) )
3314 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3318 orinoco_unlock(priv, &flags);
3323 static int orinoco_ioctl_getfrag(struct net_device *dev,
3324 struct iw_request_info *info,
3325 struct iw_param *frq,
3328 struct orinoco_private *priv = netdev_priv(dev);
3329 hermes_t *hw = &priv->hw;
3332 unsigned long flags;
3334 if (orinoco_lock(priv, &flags) != 0)
3337 if (priv->has_mwo) {
3338 err = hermes_read_wordrec(hw, USER_BAP,
3339 HERMES_RID_CNFMWOROBUST_AGERE,
3344 frq->value = val ? 2347 : 0;
3345 frq->disabled = ! val;
3348 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3354 frq->disabled = (val >= 2346);
3358 orinoco_unlock(priv, &flags);
3363 static int orinoco_ioctl_setrate(struct net_device *dev,
3364 struct iw_request_info *info,
3365 struct iw_param *rrq,
3368 struct orinoco_private *priv = netdev_priv(dev);
3370 int bitrate; /* 100s of kilobits */
3372 unsigned long flags;
3374 /* As the user space doesn't know our highest rate, it uses -1
3375 * to ask us to set the highest rate. Test it using "iwconfig
3376 * ethX rate auto" - Jean II */
3377 if (rrq->value == -1)
3380 if (rrq->value % 100000)
3382 bitrate = rrq->value / 100000;
3385 if ( (bitrate != 10) && (bitrate != 20) &&
3386 (bitrate != 55) && (bitrate != 110) )
3389 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3390 if ( (bitrate_table[i].bitrate == bitrate) &&
3391 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3399 if (orinoco_lock(priv, &flags) != 0)
3401 priv->bitratemode = ratemode;
3402 orinoco_unlock(priv, &flags);
3404 return -EINPROGRESS;
3407 static int orinoco_ioctl_getrate(struct net_device *dev,
3408 struct iw_request_info *info,
3409 struct iw_param *rrq,
3412 struct orinoco_private *priv = netdev_priv(dev);
3413 hermes_t *hw = &priv->hw;
3418 unsigned long flags;
3420 if (orinoco_lock(priv, &flags) != 0)
3423 ratemode = priv->bitratemode;
3425 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3427 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3428 rrq->fixed = ! bitrate_table[ratemode].automatic;
3431 /* If the interface is running we try to find more about the
3433 if (netif_running(dev)) {
3434 err = hermes_read_wordrec(hw, USER_BAP,
3435 HERMES_RID_CURRENTTXRATE, &val);
3439 switch (priv->firmware_type) {
3440 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3441 /* Note : in Lucent firmware, the return value of
3442 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3443 * and therefore is totally different from the
3444 * encoding of HERMES_RID_CNFTXRATECONTROL.
3445 * Don't forget that 6Mb/s is really 5.5Mb/s */
3447 rrq->value = 5500000;
3449 rrq->value = val * 1000000;
3451 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3452 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3453 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3454 if (bitrate_table[i].intersil_txratectrl == val) {
3458 if (i >= BITRATE_TABLE_SIZE)
3459 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3462 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3470 orinoco_unlock(priv, &flags);
3475 static int orinoco_ioctl_setpower(struct net_device *dev,
3476 struct iw_request_info *info,
3477 struct iw_param *prq,
3480 struct orinoco_private *priv = netdev_priv(dev);
3481 int err = -EINPROGRESS; /* Call commit handler */
3482 unsigned long flags;
3484 if (orinoco_lock(priv, &flags) != 0)
3487 if (prq->disabled) {
3490 switch (prq->flags & IW_POWER_MODE) {
3491 case IW_POWER_UNICAST_R:
3495 case IW_POWER_ALL_R:
3500 /* No flags : but we may have a value - Jean II */
3508 if (prq->flags & IW_POWER_TIMEOUT) {
3510 priv->pm_timeout = prq->value / 1000;
3512 if (prq->flags & IW_POWER_PERIOD) {
3514 priv->pm_period = prq->value / 1000;
3516 /* It's valid to not have a value if we are just toggling
3517 * the flags... Jean II */
3525 orinoco_unlock(priv, &flags);
3530 static int orinoco_ioctl_getpower(struct net_device *dev,
3531 struct iw_request_info *info,
3532 struct iw_param *prq,
3535 struct orinoco_private *priv = netdev_priv(dev);
3536 hermes_t *hw = &priv->hw;
3538 u16 enable, period, timeout, mcast;
3539 unsigned long flags;
3541 if (orinoco_lock(priv, &flags) != 0)
3544 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3548 err = hermes_read_wordrec(hw, USER_BAP,
3549 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3553 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3557 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3561 prq->disabled = !enable;
3562 /* Note : by default, display the period */
3563 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3564 prq->flags = IW_POWER_TIMEOUT;
3565 prq->value = timeout * 1000;
3567 prq->flags = IW_POWER_PERIOD;
3568 prq->value = period * 1000;
3571 prq->flags |= IW_POWER_ALL_R;
3573 prq->flags |= IW_POWER_UNICAST_R;
3576 orinoco_unlock(priv, &flags);
3581 static int orinoco_ioctl_getretry(struct net_device *dev,
3582 struct iw_request_info *info,
3583 struct iw_param *rrq,
3586 struct orinoco_private *priv = netdev_priv(dev);
3587 hermes_t *hw = &priv->hw;
3589 u16 short_limit, long_limit, lifetime;
3590 unsigned long flags;
3592 if (orinoco_lock(priv, &flags) != 0)
3595 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3600 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3605 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3610 rrq->disabled = 0; /* Can't be disabled */
3612 /* Note : by default, display the retry number */
3613 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3614 rrq->flags = IW_RETRY_LIFETIME;
3615 rrq->value = lifetime * 1000; /* ??? */
3617 /* By default, display the min number */
3618 if ((rrq->flags & IW_RETRY_MAX)) {
3619 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3620 rrq->value = long_limit;
3622 rrq->flags = IW_RETRY_LIMIT;
3623 rrq->value = short_limit;
3624 if(short_limit != long_limit)
3625 rrq->flags |= IW_RETRY_MIN;
3630 orinoco_unlock(priv, &flags);
3635 static int orinoco_ioctl_reset(struct net_device *dev,
3636 struct iw_request_info *info,
3640 struct orinoco_private *priv = netdev_priv(dev);
3642 if (! capable(CAP_NET_ADMIN))
3645 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3646 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3648 /* Firmware reset */
3651 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3653 schedule_work(&priv->reset_work);
3659 static int orinoco_ioctl_setibssport(struct net_device *dev,
3660 struct iw_request_info *info,
3665 struct orinoco_private *priv = netdev_priv(dev);
3666 int val = *( (int *) extra );
3667 unsigned long flags;
3669 if (orinoco_lock(priv, &flags) != 0)
3672 priv->ibss_port = val ;
3674 /* Actually update the mode we are using */
3675 set_port_type(priv);
3677 orinoco_unlock(priv, &flags);
3678 return -EINPROGRESS; /* Call commit handler */
3681 static int orinoco_ioctl_getibssport(struct net_device *dev,
3682 struct iw_request_info *info,
3686 struct orinoco_private *priv = netdev_priv(dev);
3687 int *val = (int *) extra;
3689 *val = priv->ibss_port;
3693 static int orinoco_ioctl_setport3(struct net_device *dev,
3694 struct iw_request_info *info,
3698 struct orinoco_private *priv = netdev_priv(dev);
3699 int val = *( (int *) extra );
3701 unsigned long flags;
3703 if (orinoco_lock(priv, &flags) != 0)
3707 case 0: /* Try to do IEEE ad-hoc mode */
3708 if (! priv->has_ibss) {
3712 priv->prefer_port3 = 0;
3716 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3717 if (! priv->has_port3) {
3721 priv->prefer_port3 = 1;
3729 /* Actually update the mode we are using */
3730 set_port_type(priv);
3734 orinoco_unlock(priv, &flags);
3739 static int orinoco_ioctl_getport3(struct net_device *dev,
3740 struct iw_request_info *info,
3744 struct orinoco_private *priv = netdev_priv(dev);
3745 int *val = (int *) extra;
3747 *val = priv->prefer_port3;
3751 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3752 struct iw_request_info *info,
3756 struct orinoco_private *priv = netdev_priv(dev);
3757 unsigned long flags;
3760 if (! priv->has_preamble)
3763 /* 802.11b has recently defined some short preamble.
3764 * Basically, the Phy header has been reduced in size.
3765 * This increase performance, especially at high rates
3766 * (the preamble is transmitted at 1Mb/s), unfortunately
3767 * this give compatibility troubles... - Jean II */
3768 val = *( (int *) extra );
3770 if (orinoco_lock(priv, &flags) != 0)
3778 orinoco_unlock(priv, &flags);
3780 return -EINPROGRESS; /* Call commit handler */
3783 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3784 struct iw_request_info *info,
3788 struct orinoco_private *priv = netdev_priv(dev);
3789 int *val = (int *) extra;
3791 if (! priv->has_preamble)
3794 *val = priv->preamble;
3798 /* ioctl interface to hermes_read_ltv()
3799 * To use with iwpriv, pass the RID as the token argument, e.g.
3800 * iwpriv get_rid [0xfc00]
3801 * At least Wireless Tools 25 is required to use iwpriv.
3802 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3803 static int orinoco_ioctl_getrid(struct net_device *dev,
3804 struct iw_request_info *info,
3805 struct iw_point *data,
3808 struct orinoco_private *priv = netdev_priv(dev);
3809 hermes_t *hw = &priv->hw;
3810 int rid = data->flags;
3813 unsigned long flags;
3815 /* It's a "get" function, but we don't want users to access the
3816 * WEP key and other raw firmware data */
3817 if (! capable(CAP_NET_ADMIN))
3820 if (rid < 0xfc00 || rid > 0xffff)
3823 if (orinoco_lock(priv, &flags) != 0)
3826 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3831 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3835 orinoco_unlock(priv, &flags);
3839 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3841 static int orinoco_ioctl_setspy(struct net_device *dev,
3842 struct iw_request_info *info,
3843 struct iw_point *srq,
3847 struct orinoco_private *priv = netdev_priv(dev);
3848 struct sockaddr *address = (struct sockaddr *) extra;
3849 int number = srq->length;
3851 unsigned long flags;
3853 /* Make sure nobody mess with the structure while we do */
3854 if (orinoco_lock(priv, &flags) != 0)
3857 /* orinoco_lock() doesn't disable interrupts, so make sure the
3858 * interrupt rx path don't get confused while we copy */
3859 priv->spy_number = 0;
3862 /* Extract the addresses */
3863 for (i = 0; i < number; i++)
3864 memcpy(priv->spy_address[i], address[i].sa_data,
3867 memset(priv->spy_stat, 0,
3868 sizeof(struct iw_quality) * IW_MAX_SPY);
3869 /* Set number of addresses */
3870 priv->spy_number = number;
3873 /* Now, let the others play */
3874 orinoco_unlock(priv, &flags);
3876 /* Do NOT call commit handler */
3880 static int orinoco_ioctl_getspy(struct net_device *dev,
3881 struct iw_request_info *info,
3882 struct iw_point *srq,
3885 struct orinoco_private *priv = netdev_priv(dev);
3886 struct sockaddr *address = (struct sockaddr *) extra;
3889 unsigned long flags;
3891 if (orinoco_lock(priv, &flags) != 0)
3894 number = priv->spy_number;
3895 /* Create address struct */
3896 for (i = 0; i < number; i++) {
3897 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3898 address[i].sa_family = AF_UNIX;
3901 /* Create address struct */
3902 for (i = 0; i < number; i++) {
3903 memcpy(address[i].sa_data, priv->spy_address[i],
3905 address[i].sa_family = AF_UNIX;
3908 /* In theory, we should disable irqs while copying the stats
3909 * because the rx path might update it in the middle...
3910 * Bah, who care ? - Jean II */
3911 memcpy(extra + (sizeof(struct sockaddr) * number),
3912 priv->spy_stat, sizeof(struct iw_quality) * number);
3914 /* Reset updated flags. */
3915 for (i = 0; i < number; i++)
3916 priv->spy_stat[i].updated = 0;
3918 orinoco_unlock(priv, &flags);
3920 srq->length = number;
3925 /* Trigger a scan (look for other cells in the vicinity */
3926 static int orinoco_ioctl_setscan(struct net_device *dev,
3927 struct iw_request_info *info,
3928 struct iw_param *srq,
3931 struct orinoco_private *priv = netdev_priv(dev);
3932 hermes_t *hw = &priv->hw;
3934 unsigned long flags;
3936 /* Note : you may have realised that, as this is a SET operation,
3937 * this is priviledged and therefore a normal user can't
3939 * This is not an error, while the device perform scanning,
3940 * traffic doesn't flow, so it's a perfect DoS...
3943 if (orinoco_lock(priv, &flags) != 0)
3946 /* Scanning with port 0 disabled would fail */
3947 if (!netif_running(dev)) {
3952 /* In monitor mode, the scan results are always empty.
3953 * Probe responses are passed to the driver as received
3954 * frames and could be processed in software. */
3955 if (priv->iw_mode == IW_MODE_MONITOR) {
3960 /* Note : because we don't lock out the irq handler, the way
3961 * we access scan variables in priv is critical.
3962 * o scan_inprogress : not touched by irq handler
3963 * o scan_mode : not touched by irq handler
3964 * o scan_result : irq is strict producer, non-irq is strict
3966 * o scan_len : synchronised with scan_result
3967 * Before modifying anything on those variables, please think hard !
3970 /* If there is still some left-over scan results, get rid of it */
3971 if (priv->scan_result != NULL) {
3972 /* What's likely is that a client did crash or was killed
3973 * between triggering the scan request and reading the
3974 * results, so we need to reset everything.
3975 * Some clients that are too slow may suffer from that...
3977 kfree(priv->scan_result);
3978 priv->scan_result = NULL;
3982 priv->scan_mode = srq->flags;
3984 /* Always trigger scanning, even if it's in progress.
3985 * This way, if the info frame get lost, we will recover somewhat
3986 * gracefully - Jean II */
3988 if (priv->has_hostscan) {
3989 switch (priv->firmware_type) {
3990 case FIRMWARE_TYPE_SYMBOL:
3991 err = hermes_write_wordrec(hw, USER_BAP,
3992 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3993 HERMES_HOSTSCAN_SYMBOL_ONCE |
3994 HERMES_HOSTSCAN_SYMBOL_BCAST);
3996 case FIRMWARE_TYPE_INTERSIL: {
3999 req[0] = cpu_to_le16(0x3fff); /* All channels */
4000 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4001 req[2] = 0; /* Any ESSID */
4002 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4003 HERMES_RID_CNFHOSTSCAN, &req);
4006 case FIRMWARE_TYPE_AGERE:
4007 err = hermes_write_wordrec(hw, USER_BAP,
4008 HERMES_RID_CNFSCANSSID_AGERE,
4013 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4017 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4019 /* One more client */
4021 priv->scan_inprogress = 1;
4024 orinoco_unlock(priv, &flags);
4028 /* Translate scan data returned from the card to a card independant
4029 * format that the Wireless Tools will understand - Jean II
4030 * Return message length or -errno for fatal errors */
4031 static inline int orinoco_translate_scan(struct net_device *dev,
4036 struct orinoco_private *priv = netdev_priv(dev);
4037 int offset; /* In the scan data */
4038 union hermes_scan_info *atom;
4042 struct iw_event iwe; /* Temporary buffer */
4043 char * current_ev = buffer;
4044 char * end_buf = buffer + IW_SCAN_MAX_DATA;
4046 switch (priv->firmware_type) {
4047 case FIRMWARE_TYPE_AGERE:
4048 atom_len = sizeof(struct agere_scan_apinfo);
4051 case FIRMWARE_TYPE_SYMBOL:
4052 /* Lack of documentation necessitates this hack.
4053 * Different firmwares have 68 or 76 byte long atoms.
4054 * We try modulo first. If the length divides by both,
4055 * we check what would be the channel in the second
4056 * frame for a 68-byte atom. 76-byte atoms have 0 there.
4057 * Valid channel cannot be 0. */
4060 else if (scan_len % 68)
4062 else if (scan_len >= 1292 && scan[68] == 0)
4068 case FIRMWARE_TYPE_INTERSIL:
4070 if (priv->has_hostscan) {
4071 atom_len = le16_to_cpup((u16 *)scan);
4072 /* Sanity check for atom_len */
4073 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
4074 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
4075 dev->name, atom_len);
4079 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4085 /* Check that we got an whole number of atoms */
4086 if ((scan_len - offset) % atom_len) {
4087 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4088 "atom_len %d, offset %d\n", dev->name, scan_len,
4093 /* Read the entries one by one */
4094 for (; offset + atom_len <= scan_len; offset += atom_len) {
4096 atom = (union hermes_scan_info *) (scan + offset);
4098 /* First entry *MUST* be the AP MAC address */
4099 iwe.cmd = SIOCGIWAP;
4100 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4101 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4102 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4104 /* Other entries will be displayed in the order we give them */
4107 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4108 if (iwe.u.data.length > 32)
4109 iwe.u.data.length = 32;
4110 iwe.cmd = SIOCGIWESSID;
4111 iwe.u.data.flags = 1;
4112 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4115 iwe.cmd = SIOCGIWMODE;
4116 capabilities = le16_to_cpu(atom->a.capabilities);
4117 if (capabilities & 0x3) {
4118 if (capabilities & 0x1)
4119 iwe.u.mode = IW_MODE_MASTER;
4121 iwe.u.mode = IW_MODE_ADHOC;
4122 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4125 channel = atom->s.channel;
4126 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4128 iwe.cmd = SIOCGIWFREQ;
4129 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4131 current_ev = iwe_stream_add_event(current_ev, end_buf,
4132 &iwe, IW_EV_FREQ_LEN);
4135 /* Add quality statistics */
4137 iwe.u.qual.updated = 0x10; /* no link quality */
4138 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4139 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4140 /* Wireless tools prior to 27.pre22 will show link quality
4141 * anyway, so we provide a reasonable value. */
4142 if (iwe.u.qual.level > iwe.u.qual.noise)
4143 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4145 iwe.u.qual.qual = 0;
4146 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4148 /* Add encryption capability */
4149 iwe.cmd = SIOCGIWENCODE;
4150 if (capabilities & 0x10)
4151 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4153 iwe.u.data.flags = IW_ENCODE_DISABLED;
4154 iwe.u.data.length = 0;
4155 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4157 /* Bit rate is not available in Lucent/Agere firmwares */
4158 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4159 char * current_val = current_ev + IW_EV_LCP_LEN;
4163 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4168 iwe.cmd = SIOCGIWRATE;
4169 /* Those two flags are ignored... */
4170 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4172 for (i = 0; i < 10; i += step) {
4173 /* NULL terminated */
4174 if (atom->p.rates[i] == 0x0)
4176 /* Bit rate given in 500 kb/s units (+ 0x80) */
4177 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4178 current_val = iwe_stream_add_value(current_ev, current_val,
4182 /* Check if we added any event */
4183 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4184 current_ev = current_val;
4187 /* The other data in the scan result are not really
4188 * interesting, so for now drop it - Jean II */
4190 return current_ev - buffer;
4193 /* Return results of a scan */
4194 static int orinoco_ioctl_getscan(struct net_device *dev,
4195 struct iw_request_info *info,
4196 struct iw_point *srq,
4199 struct orinoco_private *priv = netdev_priv(dev);
4201 unsigned long flags;
4203 if (orinoco_lock(priv, &flags) != 0)
4206 /* If no results yet, ask to try again later */
4207 if (priv->scan_result == NULL) {
4208 if (priv->scan_inprogress)
4209 /* Important note : we don't want to block the caller
4210 * until results are ready for various reasons.
4211 * First, managing wait queues is complex and racy.
4212 * Second, we grab some rtnetlink lock before comming
4213 * here (in dev_ioctl()).
4214 * Third, we generate an Wireless Event, so the
4215 * caller can wait itself on that - Jean II */
4218 /* Client error, no scan results...
4219 * The caller need to restart the scan. */
4222 /* We have some results to push back to user space */
4224 /* Translate to WE format */
4225 int ret = orinoco_translate_scan(dev, extra,
4231 kfree(priv->scan_result);
4232 priv->scan_result = NULL;
4237 srq->flags = (__u16) priv->scan_mode;
4239 /* In any case, Scan results will be cleaned up in the
4240 * reset function and when exiting the driver.
4241 * The person triggering the scanning may never come to
4242 * pick the results, so we need to do it in those places.
4245 #ifdef SCAN_SINGLE_READ
4246 /* If you enable this option, only one client (the first
4247 * one) will be able to read the result (and only one
4248 * time). If there is multiple concurent clients that
4249 * want to read scan results, this behavior is not
4250 * advisable - Jean II */
4251 kfree(priv->scan_result);
4252 priv->scan_result = NULL;
4253 #endif /* SCAN_SINGLE_READ */
4254 /* Here, if too much time has elapsed since last scan,
4255 * we may want to clean up scan results... - Jean II */
4258 /* Scan is no longer in progress */
4259 priv->scan_inprogress = 0;
4262 orinoco_unlock(priv, &flags);
4266 /* Commit handler, called after set operations */
4267 static int orinoco_ioctl_commit(struct net_device *dev,
4268 struct iw_request_info *info,
4272 struct orinoco_private *priv = netdev_priv(dev);
4273 struct hermes *hw = &priv->hw;
4274 unsigned long flags;
4280 if (priv->broken_disableport) {
4285 if (orinoco_lock(priv, &flags) != 0)
4288 err = hermes_disable_port(hw, 0);
4290 printk(KERN_WARNING "%s: Unable to disable port "
4291 "while reconfiguring card\n", dev->name);
4292 priv->broken_disableport = 1;
4296 err = __orinoco_program_rids(dev);
4298 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4303 err = hermes_enable_port(hw, 0);
4305 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4312 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4313 schedule_work(&priv->reset_work);
4317 orinoco_unlock(priv, &flags);
4321 static const struct iw_priv_args orinoco_privtab[] = {
4322 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4323 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4324 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4326 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4328 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4329 0, "set_preamble" },
4330 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4332 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4333 0, "set_ibssport" },
4334 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4336 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4342 * Structures to export the Wireless Handlers
4345 static const iw_handler orinoco_handler[] = {
4346 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4347 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4348 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4349 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4350 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4351 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4352 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4353 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4354 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4355 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy,
4356 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy,
4357 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4358 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4359 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4360 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4361 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4362 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4363 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4364 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4365 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4366 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4367 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4368 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4369 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4370 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4371 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4372 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4373 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4374 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4375 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4380 Added typecasting since we no longer use iwreq_data -- Moustafa
4382 static const iw_handler orinoco_private_handler[] = {
4383 [0] = (iw_handler) orinoco_ioctl_reset,
4384 [1] = (iw_handler) orinoco_ioctl_reset,
4385 [2] = (iw_handler) orinoco_ioctl_setport3,
4386 [3] = (iw_handler) orinoco_ioctl_getport3,
4387 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4388 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4389 [6] = (iw_handler) orinoco_ioctl_setibssport,
4390 [7] = (iw_handler) orinoco_ioctl_getibssport,
4391 [9] = (iw_handler) orinoco_ioctl_getrid,
4394 static const struct iw_handler_def orinoco_handler_def = {
4395 .num_standard = ARRAY_SIZE(orinoco_handler),
4396 .num_private = ARRAY_SIZE(orinoco_private_handler),
4397 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4398 .standard = orinoco_handler,
4399 .private = orinoco_private_handler,
4400 .private_args = orinoco_privtab,
4401 .get_wireless_stats = orinoco_get_wireless_stats,
4404 static void orinoco_get_drvinfo(struct net_device *dev,
4405 struct ethtool_drvinfo *info)
4407 struct orinoco_private *priv = netdev_priv(dev);
4409 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4410 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4411 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4412 if (dev->class_dev.dev)
4413 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4414 sizeof(info->bus_info) - 1);
4416 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4417 "PCMCIA %p", priv->hw.iobase);
4420 static struct ethtool_ops orinoco_ethtool_ops = {
4421 .get_drvinfo = orinoco_get_drvinfo,
4422 .get_link = ethtool_op_get_link,
4425 /********************************************************************/
4427 /********************************************************************/
4430 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4432 printk(KERN_DEBUG "RX descriptor:\n");
4433 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4434 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4435 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4436 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4437 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4438 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4439 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4441 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4442 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4443 frame->p80211.frame_ctl);
4444 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4445 frame->p80211.duration_id);
4446 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4447 frame->p80211.addr1[0], frame->p80211.addr1[1],
4448 frame->p80211.addr1[2], frame->p80211.addr1[3],
4449 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4450 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4451 frame->p80211.addr2[0], frame->p80211.addr2[1],
4452 frame->p80211.addr2[2], frame->p80211.addr2[3],
4453 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4454 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4455 frame->p80211.addr3[0], frame->p80211.addr3[1],
4456 frame->p80211.addr3[2], frame->p80211.addr3[3],
4457 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4458 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4459 frame->p80211.seq_ctl);
4460 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4461 frame->p80211.addr4[0], frame->p80211.addr4[1],
4462 frame->p80211.addr4[2], frame->p80211.addr4[3],
4463 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4464 printk(KERN_DEBUG " data_len = 0x%04x\n",
4465 frame->p80211.data_len);
4467 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4468 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4469 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4470 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4471 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4472 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4473 frame->p8023.h_source[0], frame->p8023.h_source[1],
4474 frame->p8023.h_source[2], frame->p8023.h_source[3],
4475 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4476 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4478 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4479 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4480 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4481 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4482 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4483 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4484 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4488 /********************************************************************/
4489 /* Module initialization */
4490 /********************************************************************/
4492 EXPORT_SYMBOL(alloc_orinocodev);
4493 EXPORT_SYMBOL(free_orinocodev);
4495 EXPORT_SYMBOL(__orinoco_up);
4496 EXPORT_SYMBOL(__orinoco_down);
4497 EXPORT_SYMBOL(orinoco_reinit_firmware);
4499 EXPORT_SYMBOL(orinoco_interrupt);
4501 /* Can't be declared "const" or the whole __initdata section will
4503 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4504 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4505 "Pavel Roskin <proski@gnu.org>, et al)";
4507 static int __init init_orinoco(void)
4509 printk(KERN_DEBUG "%s\n", version);
4513 static void __exit exit_orinoco(void)
4517 module_init(init_orinoco);
4518 module_exit(exit_orinoco);