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;
1061 /* Allocate buffer for scan results */
1062 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1066 if (orinoco_lock(priv, &flags) != 0)
1069 /* Sanity checks in case user changed something in the meantime */
1070 if (! priv->bssid_fixed)
1073 if (strlen(priv->desired_essid) == 0)
1076 /* Read scan results from the firmware */
1077 err = hermes_read_ltv(hw, USER_BAP,
1078 HERMES_RID_SCANRESULTSTABLE,
1079 MAX_SCAN_LEN, &len, buf);
1081 printk(KERN_ERR "%s: Cannot read scan results\n",
1086 len = HERMES_RECLEN_TO_BYTES(len);
1088 /* Go through the scan results looking for the channel of the AP
1089 * we were requested to join */
1090 for (; offset + atom_len <= len; offset += atom_len) {
1091 atom = (struct prism2_scan_apinfo *) (buf + offset);
1092 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0)
1096 DEBUG(1, "%s: Requested AP not found in scan results\n",
1101 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1102 req.channel = atom->channel; /* both are little-endian */
1103 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1106 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1110 orinoco_unlock(priv, &flags);
1113 /* Send new BSSID to userspace */
1114 static void orinoco_send_wevents(struct net_device *dev)
1116 struct orinoco_private *priv = netdev_priv(dev);
1117 struct hermes *hw = &priv->hw;
1118 union iwreq_data wrqu;
1120 unsigned long flags;
1122 if (orinoco_lock(priv, &flags) != 0)
1125 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1126 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1130 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1132 /* Send event to user space */
1133 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1134 orinoco_unlock(priv, &flags);
1137 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1139 struct orinoco_private *priv = netdev_priv(dev);
1144 } __attribute__ ((packed)) info;
1148 /* This is an answer to an INQUIRE command that we did earlier,
1149 * or an information "event" generated by the card
1150 * The controller return to us a pseudo frame containing
1151 * the information in question - Jean II */
1152 infofid = hermes_read_regn(hw, INFOFID);
1154 /* Read the info frame header - don't try too hard */
1155 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1158 printk(KERN_ERR "%s: error %d reading info frame. "
1159 "Frame dropped.\n", dev->name, err);
1163 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1164 type = le16_to_cpu(info.type);
1167 case HERMES_INQ_TALLIES: {
1168 struct hermes_tallies_frame tallies;
1169 struct iw_statistics *wstats = &priv->wstats;
1171 if (len > sizeof(tallies)) {
1172 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1174 len = sizeof(tallies);
1177 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1178 infofid, sizeof(info));
1182 /* Increment our various counters */
1183 /* wstats->discard.nwid - no wrong BSSID stuff */
1184 wstats->discard.code +=
1185 le16_to_cpu(tallies.RxWEPUndecryptable);
1186 if (len == sizeof(tallies))
1187 wstats->discard.code +=
1188 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1189 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1190 wstats->discard.misc +=
1191 le16_to_cpu(tallies.TxDiscardsWrongSA);
1192 wstats->discard.fragment +=
1193 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1194 wstats->discard.retries +=
1195 le16_to_cpu(tallies.TxRetryLimitExceeded);
1196 /* wstats->miss.beacon - no match */
1199 case HERMES_INQ_LINKSTATUS: {
1200 struct hermes_linkstatus linkstatus;
1204 if (priv->iw_mode == IW_MODE_MONITOR)
1207 if (len != sizeof(linkstatus)) {
1208 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1213 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1214 infofid, sizeof(info));
1217 newstatus = le16_to_cpu(linkstatus.linkstatus);
1219 /* Symbol firmware uses "out of range" to signal that
1220 * the hostscan frame can be requested. */
1221 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1222 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1223 priv->has_hostscan && priv->scan_inprogress) {
1224 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1228 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1229 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1230 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1233 netif_carrier_on(dev);
1234 else if (!ignore_disconnect)
1235 netif_carrier_off(dev);
1237 if (newstatus != priv->last_linkstatus) {
1238 priv->last_linkstatus = newstatus;
1239 print_linkstatus(dev, newstatus);
1240 /* The info frame contains only one word which is the
1241 * status (see hermes.h). The status is pretty boring
1242 * in itself, that's why we export the new BSSID...
1244 schedule_work(&priv->wevent_work);
1248 case HERMES_INQ_SCAN:
1249 if (!priv->scan_inprogress && priv->bssid_fixed &&
1250 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1251 schedule_work(&priv->join_work);
1255 case HERMES_INQ_HOSTSCAN:
1256 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1257 /* Result of a scanning. Contains information about
1258 * cells in the vicinity - Jean II */
1259 union iwreq_data wrqu;
1264 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1269 /* We are a strict producer. If the previous scan results
1270 * have not been consumed, we just have to drop this
1271 * frame. We can't remove the previous results ourselves,
1272 * that would be *very* racy... Jean II */
1273 if (priv->scan_result != NULL) {
1274 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1278 /* Allocate buffer for results */
1279 buf = kmalloc(len, GFP_ATOMIC);
1281 /* No memory, so can't printk()... */
1284 /* Read scan data */
1285 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1286 infofid, sizeof(info));
1290 #ifdef ORINOCO_DEBUG
1293 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1294 for(i = 1; i < (len * 2); i++)
1295 printk(":%02X", buf[i]);
1298 #endif /* ORINOCO_DEBUG */
1300 /* Allow the clients to access the results */
1301 priv->scan_len = len;
1302 priv->scan_result = buf;
1304 /* Send an empty event to user space.
1305 * We don't send the received data on the event because
1306 * it would require us to do complex transcoding, and
1307 * we want to minimise the work done in the irq handler
1308 * Use a request to extract the data - Jean II */
1309 wrqu.data.length = 0;
1310 wrqu.data.flags = 0;
1311 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1314 case HERMES_INQ_SEC_STAT_AGERE:
1315 /* Security status (Agere specific) */
1316 /* Ignore this frame for now */
1317 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1321 printk(KERN_DEBUG "%s: Unknown information frame received: "
1322 "type 0x%04x, length %d\n", dev->name, type, len);
1323 /* We don't actually do anything about it */
1328 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1330 if (net_ratelimit())
1331 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1334 /********************************************************************/
1335 /* Internal hardware control routines */
1336 /********************************************************************/
1338 int __orinoco_up(struct net_device *dev)
1340 struct orinoco_private *priv = netdev_priv(dev);
1341 struct hermes *hw = &priv->hw;
1344 netif_carrier_off(dev); /* just to make sure */
1346 err = __orinoco_program_rids(dev);
1348 printk(KERN_ERR "%s: Error %d configuring card\n",
1353 /* Fire things up again */
1354 hermes_set_irqmask(hw, ORINOCO_INTEN);
1355 err = hermes_enable_port(hw, 0);
1357 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1362 netif_start_queue(dev);
1367 int __orinoco_down(struct net_device *dev)
1369 struct orinoco_private *priv = netdev_priv(dev);
1370 struct hermes *hw = &priv->hw;
1373 netif_stop_queue(dev);
1375 if (! priv->hw_unavailable) {
1376 if (! priv->broken_disableport) {
1377 err = hermes_disable_port(hw, 0);
1379 /* Some firmwares (e.g. Intersil 1.3.x) seem
1380 * to have problems disabling the port, oh
1382 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1384 priv->broken_disableport = 1;
1387 hermes_set_irqmask(hw, 0);
1388 hermes_write_regn(hw, EVACK, 0xffff);
1391 /* firmware will have to reassociate */
1392 netif_carrier_off(dev);
1393 priv->last_linkstatus = 0xffff;
1398 int orinoco_reinit_firmware(struct net_device *dev)
1400 struct orinoco_private *priv = netdev_priv(dev);
1401 struct hermes *hw = &priv->hw;
1404 err = hermes_init(hw);
1408 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1409 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1410 /* Try workaround for old Symbol firmware bug */
1411 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1412 "(old Symbol firmware?). Trying to work around... ",
1415 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1416 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1418 printk("failed!\n");
1426 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1428 hermes_t *hw = &priv->hw;
1431 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1432 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1433 priv->ndev->name, priv->bitratemode);
1437 switch (priv->firmware_type) {
1438 case FIRMWARE_TYPE_AGERE:
1439 err = hermes_write_wordrec(hw, USER_BAP,
1440 HERMES_RID_CNFTXRATECONTROL,
1441 bitrate_table[priv->bitratemode].agere_txratectrl);
1443 case FIRMWARE_TYPE_INTERSIL:
1444 case FIRMWARE_TYPE_SYMBOL:
1445 err = hermes_write_wordrec(hw, USER_BAP,
1446 HERMES_RID_CNFTXRATECONTROL,
1447 bitrate_table[priv->bitratemode].intersil_txratectrl);
1456 /* Set fixed AP address */
1457 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1461 hermes_t *hw = &priv->hw;
1463 switch (priv->firmware_type) {
1464 case FIRMWARE_TYPE_AGERE:
1467 case FIRMWARE_TYPE_INTERSIL:
1468 if (priv->bssid_fixed)
1473 err = hermes_write_wordrec(hw, USER_BAP,
1474 HERMES_RID_CNFROAMINGMODE,
1477 case FIRMWARE_TYPE_SYMBOL:
1478 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1479 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1480 &priv->desired_bssid);
1486 /* Change the WEP keys and/or the current keys. Can be called
1487 * either from __orinoco_hw_setup_wep() or directly from
1488 * orinoco_ioctl_setiwencode(). In the later case the association
1489 * with the AP is not broken (if the firmware can handle it),
1490 * which is needed for 802.1x implementations. */
1491 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1493 hermes_t *hw = &priv->hw;
1496 switch (priv->firmware_type) {
1497 case FIRMWARE_TYPE_AGERE:
1498 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1499 HERMES_RID_CNFWEPKEYS_AGERE,
1503 err = hermes_write_wordrec(hw, USER_BAP,
1504 HERMES_RID_CNFTXKEY_AGERE,
1509 case FIRMWARE_TYPE_INTERSIL:
1510 case FIRMWARE_TYPE_SYMBOL:
1515 /* Force uniform key length to work around firmware bugs */
1516 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1518 if (keylen > LARGE_KEY_SIZE) {
1519 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1520 priv->ndev->name, priv->tx_key, keylen);
1524 /* Write all 4 keys */
1525 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1526 err = hermes_write_ltv(hw, USER_BAP,
1527 HERMES_RID_CNFDEFAULTKEY0 + i,
1528 HERMES_BYTES_TO_RECLEN(keylen),
1529 priv->keys[i].data);
1534 /* Write the index of the key used in transmission */
1535 err = hermes_write_wordrec(hw, USER_BAP,
1536 HERMES_RID_CNFWEPDEFAULTKEYID,
1547 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1549 hermes_t *hw = &priv->hw;
1551 int master_wep_flag;
1555 __orinoco_hw_setup_wepkeys(priv);
1557 if (priv->wep_restrict)
1558 auth_flag = HERMES_AUTH_SHARED_KEY;
1560 auth_flag = HERMES_AUTH_OPEN;
1562 switch (priv->firmware_type) {
1563 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1565 /* Enable the shared-key authentication. */
1566 err = hermes_write_wordrec(hw, USER_BAP,
1567 HERMES_RID_CNFAUTHENTICATION_AGERE,
1570 err = hermes_write_wordrec(hw, USER_BAP,
1571 HERMES_RID_CNFWEPENABLED_AGERE,
1577 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1578 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1580 if (priv->wep_restrict ||
1581 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1582 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1583 HERMES_WEP_EXCL_UNENCRYPTED;
1585 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1587 err = hermes_write_wordrec(hw, USER_BAP,
1588 HERMES_RID_CNFAUTHENTICATION,
1593 master_wep_flag = 0;
1595 if (priv->iw_mode == IW_MODE_MONITOR)
1596 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1598 /* Master WEP setting : on/off */
1599 err = hermes_write_wordrec(hw, USER_BAP,
1600 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1611 static int __orinoco_program_rids(struct net_device *dev)
1613 struct orinoco_private *priv = netdev_priv(dev);
1614 hermes_t *hw = &priv->hw;
1616 struct hermes_idstring idbuf;
1618 /* Set the MAC address */
1619 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1620 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1622 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1627 /* Set up the link mode */
1628 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1631 printk(KERN_ERR "%s: Error %d setting port type\n",
1635 /* Set the channel/frequency */
1636 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1637 err = hermes_write_wordrec(hw, USER_BAP,
1638 HERMES_RID_CNFOWNCHANNEL,
1641 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1642 dev->name, err, priv->channel);
1647 if (priv->has_ibss) {
1650 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1651 printk(KERN_WARNING "%s: This firmware requires an "
1652 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1653 /* With wvlan_cs, in this case, we would crash.
1654 * hopefully, this driver will behave better...
1658 createibss = priv->createibss;
1661 err = hermes_write_wordrec(hw, USER_BAP,
1662 HERMES_RID_CNFCREATEIBSS,
1665 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1671 /* Set the desired BSSID */
1672 err = __orinoco_hw_set_wap(priv);
1674 printk(KERN_ERR "%s: Error %d setting AP address\n",
1678 /* Set the desired ESSID */
1679 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1680 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1681 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1682 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1683 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1686 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1690 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1691 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1694 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1699 /* Set the station name */
1700 idbuf.len = cpu_to_le16(strlen(priv->nick));
1701 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1702 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1703 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1706 printk(KERN_ERR "%s: Error %d setting nickname\n",
1711 /* Set AP density */
1712 if (priv->has_sensitivity) {
1713 err = hermes_write_wordrec(hw, USER_BAP,
1714 HERMES_RID_CNFSYSTEMSCALE,
1717 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1718 "Disabling sensitivity control\n",
1721 priv->has_sensitivity = 0;
1725 /* Set RTS threshold */
1726 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1729 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1734 /* Set fragmentation threshold or MWO robustness */
1736 err = hermes_write_wordrec(hw, USER_BAP,
1737 HERMES_RID_CNFMWOROBUST_AGERE,
1740 err = hermes_write_wordrec(hw, USER_BAP,
1741 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1744 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1750 err = __orinoco_hw_set_bitrate(priv);
1752 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1757 /* Set power management */
1759 err = hermes_write_wordrec(hw, USER_BAP,
1760 HERMES_RID_CNFPMENABLED,
1763 printk(KERN_ERR "%s: Error %d setting up PM\n",
1768 err = hermes_write_wordrec(hw, USER_BAP,
1769 HERMES_RID_CNFMULTICASTRECEIVE,
1772 printk(KERN_ERR "%s: Error %d setting up PM\n",
1776 err = hermes_write_wordrec(hw, USER_BAP,
1777 HERMES_RID_CNFMAXSLEEPDURATION,
1780 printk(KERN_ERR "%s: Error %d setting up PM\n",
1784 err = hermes_write_wordrec(hw, USER_BAP,
1785 HERMES_RID_CNFPMHOLDOVERDURATION,
1788 printk(KERN_ERR "%s: Error %d setting up PM\n",
1794 /* Set preamble - only for Symbol so far... */
1795 if (priv->has_preamble) {
1796 err = hermes_write_wordrec(hw, USER_BAP,
1797 HERMES_RID_CNFPREAMBLE_SYMBOL,
1800 printk(KERN_ERR "%s: Error %d setting preamble\n",
1806 /* Set up encryption */
1807 if (priv->has_wep) {
1808 err = __orinoco_hw_setup_wep(priv);
1810 printk(KERN_ERR "%s: Error %d activating WEP\n",
1816 if (priv->iw_mode == IW_MODE_MONITOR) {
1817 /* Enable monitor mode */
1818 dev->type = ARPHRD_IEEE80211;
1819 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1820 HERMES_TEST_MONITOR, 0, NULL);
1822 /* Disable monitor mode */
1823 dev->type = ARPHRD_ETHER;
1824 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1825 HERMES_TEST_STOP, 0, NULL);
1830 /* Set promiscuity / multicast*/
1831 priv->promiscuous = 0;
1833 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1838 /* FIXME: return int? */
1840 __orinoco_set_multicast_list(struct net_device *dev)
1842 struct orinoco_private *priv = netdev_priv(dev);
1843 hermes_t *hw = &priv->hw;
1845 int promisc, mc_count;
1847 /* The Hermes doesn't seem to have an allmulti mode, so we go
1848 * into promiscuous mode and let the upper levels deal. */
1849 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1850 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1855 mc_count = dev->mc_count;
1858 if (promisc != priv->promiscuous) {
1859 err = hermes_write_wordrec(hw, USER_BAP,
1860 HERMES_RID_CNFPROMISCUOUSMODE,
1863 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1866 priv->promiscuous = promisc;
1869 if (! promisc && (mc_count || priv->mc_count) ) {
1870 struct dev_mc_list *p = dev->mc_list;
1871 struct hermes_multicast mclist;
1874 for (i = 0; i < mc_count; i++) {
1875 /* paranoia: is list shorter than mc_count? */
1877 /* paranoia: bad address size in list? */
1878 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1880 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1885 printk(KERN_WARNING "%s: Multicast list is "
1886 "longer than mc_count\n", dev->name);
1888 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1889 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1892 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1895 priv->mc_count = mc_count;
1898 /* Since we can set the promiscuous flag when it wasn't asked
1899 for, make sure the net_device knows about it. */
1900 if (priv->promiscuous)
1901 dev->flags |= IFF_PROMISC;
1903 dev->flags &= ~IFF_PROMISC;
1906 /* This must be called from user context, without locks held - use
1907 * schedule_work() */
1908 static void orinoco_reset(struct net_device *dev)
1910 struct orinoco_private *priv = netdev_priv(dev);
1911 struct hermes *hw = &priv->hw;
1913 unsigned long flags;
1915 if (orinoco_lock(priv, &flags) != 0)
1916 /* When the hardware becomes available again, whatever
1917 * detects that is responsible for re-initializing
1918 * it. So no need for anything further */
1921 netif_stop_queue(dev);
1923 /* Shut off interrupts. Depending on what state the hardware
1924 * is in, this might not work, but we'll try anyway */
1925 hermes_set_irqmask(hw, 0);
1926 hermes_write_regn(hw, EVACK, 0xffff);
1928 priv->hw_unavailable++;
1929 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1930 netif_carrier_off(dev);
1932 orinoco_unlock(priv, &flags);
1934 /* Scanning support: Cleanup of driver struct */
1935 kfree(priv->scan_result);
1936 priv->scan_result = NULL;
1937 priv->scan_inprogress = 0;
1939 if (priv->hard_reset) {
1940 err = (*priv->hard_reset)(priv);
1942 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1943 "performing hard reset\n", dev->name, err);
1948 err = orinoco_reinit_firmware(dev);
1950 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1955 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1957 priv->hw_unavailable--;
1959 /* priv->open or priv->hw_unavailable might have changed while
1960 * we dropped the lock */
1961 if (priv->open && (! priv->hw_unavailable)) {
1962 err = __orinoco_up(dev);
1964 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1967 dev->trans_start = jiffies;
1970 spin_unlock_irq(&priv->lock);
1974 hermes_set_irqmask(hw, 0);
1975 netif_device_detach(dev);
1976 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1979 /********************************************************************/
1980 /* Interrupt handler */
1981 /********************************************************************/
1983 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1985 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1988 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1990 /* This seems to happen a fair bit under load, but ignoring it
1991 seems to work fine...*/
1992 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1996 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1998 struct net_device *dev = (struct net_device *)dev_id;
1999 struct orinoco_private *priv = netdev_priv(dev);
2000 hermes_t *hw = &priv->hw;
2001 int count = MAX_IRQLOOPS_PER_IRQ;
2003 /* These are used to detect a runaway interrupt situation */
2004 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2005 * we panic and shut down the hardware */
2006 static int last_irq_jiffy = 0; /* jiffies value the last time
2008 static int loops_this_jiffy = 0;
2009 unsigned long flags;
2011 if (orinoco_lock(priv, &flags) != 0) {
2012 /* If hw is unavailable - we don't know if the irq was
2017 evstat = hermes_read_regn(hw, EVSTAT);
2018 events = evstat & hw->inten;
2020 orinoco_unlock(priv, &flags);
2024 if (jiffies != last_irq_jiffy)
2025 loops_this_jiffy = 0;
2026 last_irq_jiffy = jiffies;
2028 while (events && count--) {
2029 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2030 printk(KERN_WARNING "%s: IRQ handler is looping too "
2031 "much! Resetting.\n", dev->name);
2032 /* Disable interrupts for now */
2033 hermes_set_irqmask(hw, 0);
2034 schedule_work(&priv->reset_work);
2038 /* Check the card hasn't been removed */
2039 if (! hermes_present(hw)) {
2040 DEBUG(0, "orinoco_interrupt(): card removed\n");
2044 if (events & HERMES_EV_TICK)
2045 __orinoco_ev_tick(dev, hw);
2046 if (events & HERMES_EV_WTERR)
2047 __orinoco_ev_wterr(dev, hw);
2048 if (events & HERMES_EV_INFDROP)
2049 __orinoco_ev_infdrop(dev, hw);
2050 if (events & HERMES_EV_INFO)
2051 __orinoco_ev_info(dev, hw);
2052 if (events & HERMES_EV_RX)
2053 __orinoco_ev_rx(dev, hw);
2054 if (events & HERMES_EV_TXEXC)
2055 __orinoco_ev_txexc(dev, hw);
2056 if (events & HERMES_EV_TX)
2057 __orinoco_ev_tx(dev, hw);
2058 if (events & HERMES_EV_ALLOC)
2059 __orinoco_ev_alloc(dev, hw);
2061 hermes_write_regn(hw, EVACK, evstat);
2063 evstat = hermes_read_regn(hw, EVSTAT);
2064 events = evstat & hw->inten;
2067 orinoco_unlock(priv, &flags);
2071 /********************************************************************/
2072 /* Initialization */
2073 /********************************************************************/
2076 u16 id, variant, major, minor;
2077 } __attribute__ ((packed));
2079 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2081 if (nic_id->id < 0x8000)
2082 return FIRMWARE_TYPE_AGERE;
2083 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2084 return FIRMWARE_TYPE_SYMBOL;
2086 return FIRMWARE_TYPE_INTERSIL;
2089 /* Set priv->firmware type, determine firmware properties */
2090 static int determine_firmware(struct net_device *dev)
2092 struct orinoco_private *priv = netdev_priv(dev);
2093 hermes_t *hw = &priv->hw;
2095 struct comp_id nic_id, sta_id;
2096 unsigned int firmver;
2097 char tmp[SYMBOL_MAX_VER_LEN+1];
2099 /* Get the hardware version */
2100 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2102 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2107 le16_to_cpus(&nic_id.id);
2108 le16_to_cpus(&nic_id.variant);
2109 le16_to_cpus(&nic_id.major);
2110 le16_to_cpus(&nic_id.minor);
2111 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2112 dev->name, nic_id.id, nic_id.variant,
2113 nic_id.major, nic_id.minor);
2115 priv->firmware_type = determine_firmware_type(&nic_id);
2117 /* Get the firmware version */
2118 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2120 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2125 le16_to_cpus(&sta_id.id);
2126 le16_to_cpus(&sta_id.variant);
2127 le16_to_cpus(&sta_id.major);
2128 le16_to_cpus(&sta_id.minor);
2129 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2130 dev->name, sta_id.id, sta_id.variant,
2131 sta_id.major, sta_id.minor);
2133 switch (sta_id.id) {
2135 printk(KERN_ERR "%s: Primary firmware is active\n",
2139 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2142 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2143 case 0x21: /* Symbol Spectrum24 Trilogy */
2146 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2151 /* Default capabilities */
2152 priv->has_sensitivity = 1;
2154 priv->has_preamble = 0;
2155 priv->has_port3 = 1;
2158 priv->has_big_wep = 0;
2160 /* Determine capabilities from the firmware version */
2161 switch (priv->firmware_type) {
2162 case FIRMWARE_TYPE_AGERE:
2163 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2164 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2165 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2166 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2168 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2170 priv->has_ibss = (firmver >= 0x60006);
2171 priv->has_wep = (firmver >= 0x40020);
2172 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2173 Gold cards from the others? */
2174 priv->has_mwo = (firmver >= 0x60000);
2175 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2176 priv->ibss_port = 1;
2177 priv->has_hostscan = (firmver >= 0x8000a);
2178 priv->broken_monitor = (firmver >= 0x80000);
2180 /* Tested with Agere firmware :
2181 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2182 * Tested CableTron firmware : 4.32 => Anton */
2184 case FIRMWARE_TYPE_SYMBOL:
2185 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2186 /* Intel MAC : 00:02:B3:* */
2187 /* 3Com MAC : 00:50:DA:* */
2188 memset(tmp, 0, sizeof(tmp));
2189 /* Get the Symbol firmware version */
2190 err = hermes_read_ltv(hw, USER_BAP,
2191 HERMES_RID_SECONDARYVERSION_SYMBOL,
2192 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2195 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2200 /* The firmware revision is a string, the format is
2201 * something like : "V2.20-01".
2202 * Quick and dirty parsing... - Jean II
2204 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2205 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2208 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2211 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2214 priv->has_ibss = (firmver >= 0x20000);
2215 priv->has_wep = (firmver >= 0x15012);
2216 priv->has_big_wep = (firmver >= 0x20000);
2217 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2218 (firmver >= 0x29000 && firmver < 0x30000) ||
2220 priv->has_preamble = (firmver >= 0x20000);
2221 priv->ibss_port = 4;
2222 priv->broken_disableport = (firmver == 0x25013) ||
2223 (firmver >= 0x30000 && firmver <= 0x31000);
2224 priv->has_hostscan = (firmver >= 0x31001) ||
2225 (firmver >= 0x29057 && firmver < 0x30000);
2226 /* Tested with Intel firmware : 0x20015 => Jean II */
2227 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2229 case FIRMWARE_TYPE_INTERSIL:
2230 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2231 * Samsung, Compaq 100/200 and Proxim are slightly
2232 * different and less well tested */
2233 /* D-Link MAC : 00:40:05:* */
2234 /* Addtron MAC : 00:90:D1:* */
2235 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2236 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2239 firmver = ((unsigned long)sta_id.major << 16) |
2240 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2242 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2243 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2244 priv->has_pm = (firmver >= 0x000700);
2245 priv->has_hostscan = (firmver >= 0x010301);
2247 if (firmver >= 0x000800)
2248 priv->ibss_port = 0;
2250 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2251 "than v0.8.x - several features not supported\n",
2253 priv->ibss_port = 1;
2257 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2263 static int orinoco_init(struct net_device *dev)
2265 struct orinoco_private *priv = netdev_priv(dev);
2266 hermes_t *hw = &priv->hw;
2268 struct hermes_idstring nickbuf;
2272 TRACE_ENTER(dev->name);
2274 /* No need to lock, the hw_unavailable flag is already set in
2275 * alloc_orinocodev() */
2276 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2278 /* Initialize the firmware */
2279 err = orinoco_reinit_firmware(dev);
2281 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2286 err = determine_firmware(dev);
2288 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2293 if (priv->has_port3)
2294 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2296 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2298 if (priv->has_wep) {
2299 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2300 if (priv->has_big_wep)
2301 printk("104-bit key\n");
2303 printk("40-bit key\n");
2306 /* Get the MAC address */
2307 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2308 ETH_ALEN, NULL, dev->dev_addr);
2310 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2315 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2316 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2317 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2320 /* Get the station name */
2321 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2322 sizeof(nickbuf), &reclen, &nickbuf);
2324 printk(KERN_ERR "%s: failed to read station name\n",
2329 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2331 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2332 memcpy(priv->nick, &nickbuf.val, len);
2333 priv->nick[len] = '\0';
2335 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2337 /* Get allowed channels */
2338 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2339 &priv->channel_mask);
2341 printk(KERN_ERR "%s: failed to read channel list!\n",
2346 /* Get initial AP density */
2347 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2349 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2350 priv->has_sensitivity = 0;
2353 /* Get initial RTS threshold */
2354 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2357 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2362 /* Get initial fragmentation settings */
2364 err = hermes_read_wordrec(hw, USER_BAP,
2365 HERMES_RID_CNFMWOROBUST_AGERE,
2368 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2369 &priv->frag_thresh);
2371 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2376 /* Power management setup */
2380 err = hermes_read_wordrec(hw, USER_BAP,
2381 HERMES_RID_CNFMAXSLEEPDURATION,
2384 printk(KERN_ERR "%s: failed to read power management period!\n",
2388 err = hermes_read_wordrec(hw, USER_BAP,
2389 HERMES_RID_CNFPMHOLDOVERDURATION,
2392 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2398 /* Preamble setup */
2399 if (priv->has_preamble) {
2400 err = hermes_read_wordrec(hw, USER_BAP,
2401 HERMES_RID_CNFPREAMBLE_SYMBOL,
2407 /* Set up the default configuration */
2408 priv->iw_mode = IW_MODE_INFRA;
2409 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2410 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2411 set_port_type(priv);
2412 priv->channel = 0; /* use firmware default */
2414 priv->promiscuous = 0;
2418 /* Make the hardware available, as long as it hasn't been
2419 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2420 spin_lock_irq(&priv->lock);
2421 priv->hw_unavailable--;
2422 spin_unlock_irq(&priv->lock);
2424 printk(KERN_DEBUG "%s: ready\n", dev->name);
2427 TRACE_EXIT(dev->name);
2431 struct net_device *alloc_orinocodev(int sizeof_card,
2432 int (*hard_reset)(struct orinoco_private *))
2434 struct net_device *dev;
2435 struct orinoco_private *priv;
2437 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2440 priv = netdev_priv(dev);
2443 priv->card = (void *)((unsigned long)priv
2444 + sizeof(struct orinoco_private));
2448 /* Setup / override net_device fields */
2449 dev->init = orinoco_init;
2450 dev->hard_start_xmit = orinoco_xmit;
2451 dev->tx_timeout = orinoco_tx_timeout;
2452 dev->watchdog_timeo = HZ; /* 1 second timeout */
2453 dev->get_stats = orinoco_get_stats;
2454 dev->ethtool_ops = &orinoco_ethtool_ops;
2455 dev->get_wireless_stats = orinoco_get_wireless_stats;
2456 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2457 dev->change_mtu = orinoco_change_mtu;
2458 dev->set_multicast_list = orinoco_set_multicast_list;
2459 /* we use the default eth_mac_addr for setting the MAC addr */
2461 /* Set up default callbacks */
2462 dev->open = orinoco_open;
2463 dev->stop = orinoco_stop;
2464 priv->hard_reset = hard_reset;
2466 spin_lock_init(&priv->lock);
2468 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2469 * before anything else touches the
2471 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2472 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2473 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2475 netif_carrier_off(dev);
2476 priv->last_linkstatus = 0xffff;
2482 void free_orinocodev(struct net_device *dev)
2484 struct orinoco_private *priv = netdev_priv(dev);
2486 kfree(priv->scan_result);
2490 /********************************************************************/
2491 /* Wireless extensions */
2492 /********************************************************************/
2494 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2495 char buf[IW_ESSID_MAX_SIZE+1])
2497 hermes_t *hw = &priv->hw;
2499 struct hermes_idstring essidbuf;
2500 char *p = (char *)(&essidbuf.val);
2502 unsigned long flags;
2504 if (orinoco_lock(priv, &flags) != 0)
2507 if (strlen(priv->desired_essid) > 0) {
2508 /* We read the desired SSID from the hardware rather
2509 than from priv->desired_essid, just in case the
2510 firmware is allowed to change it on us. I'm not
2512 /* My guess is that the OWNSSID should always be whatever
2513 * we set to the card, whereas CURRENT_SSID is the one that
2514 * may change... - Jean II */
2519 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2520 HERMES_RID_CNFDESIREDSSID;
2522 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2529 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2530 sizeof(essidbuf), NULL, &essidbuf);
2535 len = le16_to_cpu(essidbuf.len);
2536 BUG_ON(len > IW_ESSID_MAX_SIZE);
2538 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2539 memcpy(buf, p, len);
2543 orinoco_unlock(priv, &flags);
2548 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2551 hermes_t *hw = &priv->hw;
2555 unsigned long flags;
2557 if (orinoco_lock(priv, &flags) != 0)
2560 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2564 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2570 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2571 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2572 priv->ndev->name, channel);
2577 freq = channel_frequency[channel-1] * 100000;
2580 orinoco_unlock(priv, &flags);
2584 return err ? err : freq;
2587 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2588 int *numrates, s32 *rates, int max)
2590 hermes_t *hw = &priv->hw;
2591 struct hermes_idstring list;
2592 unsigned char *p = (unsigned char *)&list.val;
2596 unsigned long flags;
2598 if (orinoco_lock(priv, &flags) != 0)
2601 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2602 sizeof(list), NULL, &list);
2603 orinoco_unlock(priv, &flags);
2608 num = le16_to_cpu(list.len);
2610 num = min(num, max);
2612 for (i = 0; i < num; i++) {
2613 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2619 static int orinoco_ioctl_getname(struct net_device *dev,
2620 struct iw_request_info *info,
2624 struct orinoco_private *priv = netdev_priv(dev);
2628 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2630 if (!err && (numrates > 2))
2631 strcpy(name, "IEEE 802.11b");
2633 strcpy(name, "IEEE 802.11-DS");
2638 static int orinoco_ioctl_setwap(struct net_device *dev,
2639 struct iw_request_info *info,
2640 struct sockaddr *ap_addr,
2643 struct orinoco_private *priv = netdev_priv(dev);
2644 int err = -EINPROGRESS; /* Call commit handler */
2645 unsigned long flags;
2646 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2647 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2649 if (orinoco_lock(priv, &flags) != 0)
2652 /* Enable automatic roaming - no sanity checks are needed */
2653 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2654 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2655 priv->bssid_fixed = 0;
2656 memset(priv->desired_bssid, 0, ETH_ALEN);
2658 /* "off" means keep existing connection */
2659 if (ap_addr->sa_data[0] == 0) {
2660 __orinoco_hw_set_wap(priv);
2666 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2667 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2668 "support manual roaming\n",
2674 if (priv->iw_mode != IW_MODE_INFRA) {
2675 printk(KERN_WARNING "%s: Manual roaming supported only in "
2676 "managed mode\n", dev->name);
2681 /* Intersil firmware hangs without Desired ESSID */
2682 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2683 strlen(priv->desired_essid) == 0) {
2684 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2685 "manual roaming\n", dev->name);
2690 /* Finally, enable manual roaming */
2691 priv->bssid_fixed = 1;
2692 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2695 orinoco_unlock(priv, &flags);
2699 static int orinoco_ioctl_getwap(struct net_device *dev,
2700 struct iw_request_info *info,
2701 struct sockaddr *ap_addr,
2704 struct orinoco_private *priv = netdev_priv(dev);
2706 hermes_t *hw = &priv->hw;
2708 unsigned long flags;
2710 if (orinoco_lock(priv, &flags) != 0)
2713 ap_addr->sa_family = ARPHRD_ETHER;
2714 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2715 ETH_ALEN, NULL, ap_addr->sa_data);
2717 orinoco_unlock(priv, &flags);
2722 static int orinoco_ioctl_setmode(struct net_device *dev,
2723 struct iw_request_info *info,
2727 struct orinoco_private *priv = netdev_priv(dev);
2728 int err = -EINPROGRESS; /* Call commit handler */
2729 unsigned long flags;
2731 if (priv->iw_mode == *mode)
2734 if (orinoco_lock(priv, &flags) != 0)
2739 if (!priv->has_ibss && !priv->has_port3)
2746 case IW_MODE_MONITOR:
2747 if (priv->broken_monitor && !force_monitor) {
2748 printk(KERN_WARNING "%s: Monitor mode support is "
2749 "buggy in this firmware, not enabling\n",
2760 if (err == -EINPROGRESS) {
2761 priv->iw_mode = *mode;
2762 set_port_type(priv);
2765 orinoco_unlock(priv, &flags);
2770 static int orinoco_ioctl_getmode(struct net_device *dev,
2771 struct iw_request_info *info,
2775 struct orinoco_private *priv = netdev_priv(dev);
2777 *mode = priv->iw_mode;
2781 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2782 struct iw_request_info *info,
2783 struct iw_point *rrq,
2786 struct orinoco_private *priv = netdev_priv(dev);
2788 struct iw_range *range = (struct iw_range *) extra;
2792 TRACE_ENTER(dev->name);
2794 rrq->length = sizeof(struct iw_range);
2795 memset(range, 0, sizeof(struct iw_range));
2797 range->we_version_compiled = WIRELESS_EXT;
2798 range->we_version_source = 14;
2800 /* Set available channels/frequencies */
2801 range->num_channels = NUM_CHANNELS;
2803 for (i = 0; i < NUM_CHANNELS; i++) {
2804 if (priv->channel_mask & (1 << i)) {
2805 range->freq[k].i = i + 1;
2806 range->freq[k].m = channel_frequency[i] * 100000;
2807 range->freq[k].e = 1;
2811 if (k >= IW_MAX_FREQUENCIES)
2814 range->num_frequency = k;
2815 range->sensitivity = 3;
2817 if (priv->has_wep) {
2818 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2819 range->encoding_size[0] = SMALL_KEY_SIZE;
2820 range->num_encoding_sizes = 1;
2822 if (priv->has_big_wep) {
2823 range->encoding_size[1] = LARGE_KEY_SIZE;
2824 range->num_encoding_sizes = 2;
2828 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2829 /* Quality stats meaningless in ad-hoc mode */
2831 range->max_qual.qual = 0x8b - 0x2f;
2832 range->max_qual.level = 0x2f - 0x95 - 1;
2833 range->max_qual.noise = 0x2f - 0x95 - 1;
2834 /* Need to get better values */
2835 range->avg_qual.qual = 0x24;
2836 range->avg_qual.level = 0xC2;
2837 range->avg_qual.noise = 0x9E;
2840 err = orinoco_hw_get_bitratelist(priv, &numrates,
2841 range->bitrate, IW_MAX_BITRATES);
2844 range->num_bitrates = numrates;
2846 /* Set an indication of the max TCP throughput in bit/s that we can
2847 * expect using this interface. May be use for QoS stuff...
2850 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2852 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2855 range->max_rts = 2347;
2856 range->min_frag = 256;
2857 range->max_frag = 2346;
2860 range->max_pmp = 65535000;
2862 range->max_pmt = 65535 * 1000; /* ??? */
2863 range->pmp_flags = IW_POWER_PERIOD;
2864 range->pmt_flags = IW_POWER_TIMEOUT;
2865 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2867 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2868 range->retry_flags = IW_RETRY_LIMIT;
2869 range->r_time_flags = IW_RETRY_LIFETIME;
2870 range->min_retry = 0;
2871 range->max_retry = 65535; /* ??? */
2872 range->min_r_time = 0;
2873 range->max_r_time = 65535 * 1000; /* ??? */
2875 TRACE_EXIT(dev->name);
2880 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2881 struct iw_request_info *info,
2882 struct iw_point *erq,
2885 struct orinoco_private *priv = netdev_priv(dev);
2886 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2887 int setindex = priv->tx_key;
2888 int enable = priv->wep_on;
2889 int restricted = priv->wep_restrict;
2891 int err = -EINPROGRESS; /* Call commit handler */
2892 unsigned long flags;
2894 if (! priv->has_wep)
2898 /* We actually have a key to set - check its length */
2899 if (erq->length > LARGE_KEY_SIZE)
2902 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2906 if (orinoco_lock(priv, &flags) != 0)
2910 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2911 index = priv->tx_key;
2913 /* Adjust key length to a supported value */
2914 if (erq->length > SMALL_KEY_SIZE) {
2915 xlen = LARGE_KEY_SIZE;
2916 } else if (erq->length > 0) {
2917 xlen = SMALL_KEY_SIZE;
2921 /* Switch on WEP if off */
2922 if ((!enable) && (xlen > 0)) {
2927 /* Important note : if the user do "iwconfig eth0 enc off",
2928 * we will arrive there with an index of -1. This is valid
2929 * but need to be taken care off... Jean II */
2930 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2931 if((index != -1) || (erq->flags == 0)) {
2936 /* Set the index : Check that the key is valid */
2937 if(priv->keys[index].len == 0) {
2945 if (erq->flags & IW_ENCODE_DISABLED)
2947 if (erq->flags & IW_ENCODE_OPEN)
2949 if (erq->flags & IW_ENCODE_RESTRICTED)
2953 priv->keys[index].len = cpu_to_le16(xlen);
2954 memset(priv->keys[index].data, 0,
2955 sizeof(priv->keys[index].data));
2956 memcpy(priv->keys[index].data, keybuf, erq->length);
2958 priv->tx_key = setindex;
2960 /* Try fast key change if connected and only keys are changed */
2961 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2962 netif_carrier_ok(dev)) {
2963 err = __orinoco_hw_setup_wepkeys(priv);
2964 /* No need to commit if successful */
2968 priv->wep_on = enable;
2969 priv->wep_restrict = restricted;
2972 orinoco_unlock(priv, &flags);
2977 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2978 struct iw_request_info *info,
2979 struct iw_point *erq,
2982 struct orinoco_private *priv = netdev_priv(dev);
2983 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2985 unsigned long flags;
2987 if (! priv->has_wep)
2990 if (orinoco_lock(priv, &flags) != 0)
2993 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2994 index = priv->tx_key;
2998 erq->flags |= IW_ENCODE_DISABLED;
2999 erq->flags |= index + 1;
3001 if (priv->wep_restrict)
3002 erq->flags |= IW_ENCODE_RESTRICTED;
3004 erq->flags |= IW_ENCODE_OPEN;
3006 xlen = le16_to_cpu(priv->keys[index].len);
3010 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3012 orinoco_unlock(priv, &flags);
3016 static int orinoco_ioctl_setessid(struct net_device *dev,
3017 struct iw_request_info *info,
3018 struct iw_point *erq,
3021 struct orinoco_private *priv = netdev_priv(dev);
3022 unsigned long flags;
3024 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3025 * anyway... - Jean II */
3027 /* Hum... Should not use Wireless Extension constant (may change),
3028 * should use our own... - Jean II */
3029 if (erq->length > IW_ESSID_MAX_SIZE)
3032 if (orinoco_lock(priv, &flags) != 0)
3035 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3036 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3038 /* If not ANY, get the new ESSID */
3040 memcpy(priv->desired_essid, essidbuf, erq->length);
3043 orinoco_unlock(priv, &flags);
3045 return -EINPROGRESS; /* Call commit handler */
3048 static int orinoco_ioctl_getessid(struct net_device *dev,
3049 struct iw_request_info *info,
3050 struct iw_point *erq,
3053 struct orinoco_private *priv = netdev_priv(dev);
3056 unsigned long flags;
3058 TRACE_ENTER(dev->name);
3060 if (netif_running(dev)) {
3061 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3065 if (orinoco_lock(priv, &flags) != 0)
3067 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3068 orinoco_unlock(priv, &flags);
3072 erq->length = strlen(essidbuf) + 1;
3074 TRACE_EXIT(dev->name);
3079 static int orinoco_ioctl_setnick(struct net_device *dev,
3080 struct iw_request_info *info,
3081 struct iw_point *nrq,
3084 struct orinoco_private *priv = netdev_priv(dev);
3085 unsigned long flags;
3087 if (nrq->length > IW_ESSID_MAX_SIZE)
3090 if (orinoco_lock(priv, &flags) != 0)
3093 memset(priv->nick, 0, sizeof(priv->nick));
3094 memcpy(priv->nick, nickbuf, nrq->length);
3096 orinoco_unlock(priv, &flags);
3098 return -EINPROGRESS; /* Call commit handler */
3101 static int orinoco_ioctl_getnick(struct net_device *dev,
3102 struct iw_request_info *info,
3103 struct iw_point *nrq,
3106 struct orinoco_private *priv = netdev_priv(dev);
3107 unsigned long flags;
3109 if (orinoco_lock(priv, &flags) != 0)
3112 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3113 orinoco_unlock(priv, &flags);
3115 nrq->length = strlen(nickbuf)+1;
3120 static int orinoco_ioctl_setfreq(struct net_device *dev,
3121 struct iw_request_info *info,
3122 struct iw_freq *frq,
3125 struct orinoco_private *priv = netdev_priv(dev);
3127 unsigned long flags;
3128 int err = -EINPROGRESS; /* Call commit handler */
3130 /* In infrastructure mode the AP sets the channel */
3131 if (priv->iw_mode == IW_MODE_INFRA)
3134 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3135 /* Setting by channel number */
3138 /* Setting by frequency - search the table */
3142 for (i = 0; i < (6 - frq->e); i++)
3145 for (i = 0; i < NUM_CHANNELS; i++)
3146 if (frq->m == (channel_frequency[i] * mult))
3150 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3151 ! (priv->channel_mask & (1 << (chan-1)) ) )
3154 if (orinoco_lock(priv, &flags) != 0)
3157 priv->channel = chan;
3158 if (priv->iw_mode == IW_MODE_MONITOR) {
3159 /* Fast channel change - no commit if successful */
3160 hermes_t *hw = &priv->hw;
3161 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3162 HERMES_TEST_SET_CHANNEL,
3165 orinoco_unlock(priv, &flags);
3170 static int orinoco_ioctl_getfreq(struct net_device *dev,
3171 struct iw_request_info *info,
3172 struct iw_freq *frq,
3175 struct orinoco_private *priv = netdev_priv(dev);
3178 /* Locking done in there */
3179 tmp = orinoco_hw_get_freq(priv);
3190 static int orinoco_ioctl_getsens(struct net_device *dev,
3191 struct iw_request_info *info,
3192 struct iw_param *srq,
3195 struct orinoco_private *priv = netdev_priv(dev);
3196 hermes_t *hw = &priv->hw;
3199 unsigned long flags;
3201 if (!priv->has_sensitivity)
3204 if (orinoco_lock(priv, &flags) != 0)
3206 err = hermes_read_wordrec(hw, USER_BAP,
3207 HERMES_RID_CNFSYSTEMSCALE, &val);
3208 orinoco_unlock(priv, &flags);
3214 srq->fixed = 0; /* auto */
3219 static int orinoco_ioctl_setsens(struct net_device *dev,
3220 struct iw_request_info *info,
3221 struct iw_param *srq,
3224 struct orinoco_private *priv = netdev_priv(dev);
3225 int val = srq->value;
3226 unsigned long flags;
3228 if (!priv->has_sensitivity)
3231 if ((val < 1) || (val > 3))
3234 if (orinoco_lock(priv, &flags) != 0)
3236 priv->ap_density = val;
3237 orinoco_unlock(priv, &flags);
3239 return -EINPROGRESS; /* Call commit handler */
3242 static int orinoco_ioctl_setrts(struct net_device *dev,
3243 struct iw_request_info *info,
3244 struct iw_param *rrq,
3247 struct orinoco_private *priv = netdev_priv(dev);
3248 int val = rrq->value;
3249 unsigned long flags;
3254 if ( (val < 0) || (val > 2347) )
3257 if (orinoco_lock(priv, &flags) != 0)
3260 priv->rts_thresh = val;
3261 orinoco_unlock(priv, &flags);
3263 return -EINPROGRESS; /* Call commit handler */
3266 static int orinoco_ioctl_getrts(struct net_device *dev,
3267 struct iw_request_info *info,
3268 struct iw_param *rrq,
3271 struct orinoco_private *priv = netdev_priv(dev);
3273 rrq->value = priv->rts_thresh;
3274 rrq->disabled = (rrq->value == 2347);
3280 static int orinoco_ioctl_setfrag(struct net_device *dev,
3281 struct iw_request_info *info,
3282 struct iw_param *frq,
3285 struct orinoco_private *priv = netdev_priv(dev);
3286 int err = -EINPROGRESS; /* Call commit handler */
3287 unsigned long flags;
3289 if (orinoco_lock(priv, &flags) != 0)
3292 if (priv->has_mwo) {
3294 priv->mwo_robust = 0;
3297 printk(KERN_WARNING "%s: Fixed fragmentation is "
3298 "not supported on this firmware. "
3299 "Using MWO robust instead.\n", dev->name);
3300 priv->mwo_robust = 1;
3304 priv->frag_thresh = 2346;
3306 if ( (frq->value < 256) || (frq->value > 2346) )
3309 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3313 orinoco_unlock(priv, &flags);
3318 static int orinoco_ioctl_getfrag(struct net_device *dev,
3319 struct iw_request_info *info,
3320 struct iw_param *frq,
3323 struct orinoco_private *priv = netdev_priv(dev);
3324 hermes_t *hw = &priv->hw;
3327 unsigned long flags;
3329 if (orinoco_lock(priv, &flags) != 0)
3332 if (priv->has_mwo) {
3333 err = hermes_read_wordrec(hw, USER_BAP,
3334 HERMES_RID_CNFMWOROBUST_AGERE,
3339 frq->value = val ? 2347 : 0;
3340 frq->disabled = ! val;
3343 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3349 frq->disabled = (val >= 2346);
3353 orinoco_unlock(priv, &flags);
3358 static int orinoco_ioctl_setrate(struct net_device *dev,
3359 struct iw_request_info *info,
3360 struct iw_param *rrq,
3363 struct orinoco_private *priv = netdev_priv(dev);
3365 int bitrate; /* 100s of kilobits */
3367 unsigned long flags;
3369 /* As the user space doesn't know our highest rate, it uses -1
3370 * to ask us to set the highest rate. Test it using "iwconfig
3371 * ethX rate auto" - Jean II */
3372 if (rrq->value == -1)
3375 if (rrq->value % 100000)
3377 bitrate = rrq->value / 100000;
3380 if ( (bitrate != 10) && (bitrate != 20) &&
3381 (bitrate != 55) && (bitrate != 110) )
3384 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3385 if ( (bitrate_table[i].bitrate == bitrate) &&
3386 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3394 if (orinoco_lock(priv, &flags) != 0)
3396 priv->bitratemode = ratemode;
3397 orinoco_unlock(priv, &flags);
3399 return -EINPROGRESS;
3402 static int orinoco_ioctl_getrate(struct net_device *dev,
3403 struct iw_request_info *info,
3404 struct iw_param *rrq,
3407 struct orinoco_private *priv = netdev_priv(dev);
3408 hermes_t *hw = &priv->hw;
3413 unsigned long flags;
3415 if (orinoco_lock(priv, &flags) != 0)
3418 ratemode = priv->bitratemode;
3420 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3422 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3423 rrq->fixed = ! bitrate_table[ratemode].automatic;
3426 /* If the interface is running we try to find more about the
3428 if (netif_running(dev)) {
3429 err = hermes_read_wordrec(hw, USER_BAP,
3430 HERMES_RID_CURRENTTXRATE, &val);
3434 switch (priv->firmware_type) {
3435 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3436 /* Note : in Lucent firmware, the return value of
3437 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3438 * and therefore is totally different from the
3439 * encoding of HERMES_RID_CNFTXRATECONTROL.
3440 * Don't forget that 6Mb/s is really 5.5Mb/s */
3442 rrq->value = 5500000;
3444 rrq->value = val * 1000000;
3446 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3447 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3448 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3449 if (bitrate_table[i].intersil_txratectrl == val) {
3453 if (i >= BITRATE_TABLE_SIZE)
3454 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3457 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3465 orinoco_unlock(priv, &flags);
3470 static int orinoco_ioctl_setpower(struct net_device *dev,
3471 struct iw_request_info *info,
3472 struct iw_param *prq,
3475 struct orinoco_private *priv = netdev_priv(dev);
3476 int err = -EINPROGRESS; /* Call commit handler */
3477 unsigned long flags;
3479 if (orinoco_lock(priv, &flags) != 0)
3482 if (prq->disabled) {
3485 switch (prq->flags & IW_POWER_MODE) {
3486 case IW_POWER_UNICAST_R:
3490 case IW_POWER_ALL_R:
3495 /* No flags : but we may have a value - Jean II */
3503 if (prq->flags & IW_POWER_TIMEOUT) {
3505 priv->pm_timeout = prq->value / 1000;
3507 if (prq->flags & IW_POWER_PERIOD) {
3509 priv->pm_period = prq->value / 1000;
3511 /* It's valid to not have a value if we are just toggling
3512 * the flags... Jean II */
3520 orinoco_unlock(priv, &flags);
3525 static int orinoco_ioctl_getpower(struct net_device *dev,
3526 struct iw_request_info *info,
3527 struct iw_param *prq,
3530 struct orinoco_private *priv = netdev_priv(dev);
3531 hermes_t *hw = &priv->hw;
3533 u16 enable, period, timeout, mcast;
3534 unsigned long flags;
3536 if (orinoco_lock(priv, &flags) != 0)
3539 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3543 err = hermes_read_wordrec(hw, USER_BAP,
3544 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3548 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3552 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3556 prq->disabled = !enable;
3557 /* Note : by default, display the period */
3558 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3559 prq->flags = IW_POWER_TIMEOUT;
3560 prq->value = timeout * 1000;
3562 prq->flags = IW_POWER_PERIOD;
3563 prq->value = period * 1000;
3566 prq->flags |= IW_POWER_ALL_R;
3568 prq->flags |= IW_POWER_UNICAST_R;
3571 orinoco_unlock(priv, &flags);
3576 static int orinoco_ioctl_getretry(struct net_device *dev,
3577 struct iw_request_info *info,
3578 struct iw_param *rrq,
3581 struct orinoco_private *priv = netdev_priv(dev);
3582 hermes_t *hw = &priv->hw;
3584 u16 short_limit, long_limit, lifetime;
3585 unsigned long flags;
3587 if (orinoco_lock(priv, &flags) != 0)
3590 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3595 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3600 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3605 rrq->disabled = 0; /* Can't be disabled */
3607 /* Note : by default, display the retry number */
3608 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3609 rrq->flags = IW_RETRY_LIFETIME;
3610 rrq->value = lifetime * 1000; /* ??? */
3612 /* By default, display the min number */
3613 if ((rrq->flags & IW_RETRY_MAX)) {
3614 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3615 rrq->value = long_limit;
3617 rrq->flags = IW_RETRY_LIMIT;
3618 rrq->value = short_limit;
3619 if(short_limit != long_limit)
3620 rrq->flags |= IW_RETRY_MIN;
3625 orinoco_unlock(priv, &flags);
3630 static int orinoco_ioctl_reset(struct net_device *dev,
3631 struct iw_request_info *info,
3635 struct orinoco_private *priv = netdev_priv(dev);
3637 if (! capable(CAP_NET_ADMIN))
3640 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3641 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3643 /* Firmware reset */
3646 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3648 schedule_work(&priv->reset_work);
3654 static int orinoco_ioctl_setibssport(struct net_device *dev,
3655 struct iw_request_info *info,
3660 struct orinoco_private *priv = netdev_priv(dev);
3661 int val = *( (int *) extra );
3662 unsigned long flags;
3664 if (orinoco_lock(priv, &flags) != 0)
3667 priv->ibss_port = val ;
3669 /* Actually update the mode we are using */
3670 set_port_type(priv);
3672 orinoco_unlock(priv, &flags);
3673 return -EINPROGRESS; /* Call commit handler */
3676 static int orinoco_ioctl_getibssport(struct net_device *dev,
3677 struct iw_request_info *info,
3681 struct orinoco_private *priv = netdev_priv(dev);
3682 int *val = (int *) extra;
3684 *val = priv->ibss_port;
3688 static int orinoco_ioctl_setport3(struct net_device *dev,
3689 struct iw_request_info *info,
3693 struct orinoco_private *priv = netdev_priv(dev);
3694 int val = *( (int *) extra );
3696 unsigned long flags;
3698 if (orinoco_lock(priv, &flags) != 0)
3702 case 0: /* Try to do IEEE ad-hoc mode */
3703 if (! priv->has_ibss) {
3707 priv->prefer_port3 = 0;
3711 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3712 if (! priv->has_port3) {
3716 priv->prefer_port3 = 1;
3724 /* Actually update the mode we are using */
3725 set_port_type(priv);
3729 orinoco_unlock(priv, &flags);
3734 static int orinoco_ioctl_getport3(struct net_device *dev,
3735 struct iw_request_info *info,
3739 struct orinoco_private *priv = netdev_priv(dev);
3740 int *val = (int *) extra;
3742 *val = priv->prefer_port3;
3746 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3747 struct iw_request_info *info,
3751 struct orinoco_private *priv = netdev_priv(dev);
3752 unsigned long flags;
3755 if (! priv->has_preamble)
3758 /* 802.11b has recently defined some short preamble.
3759 * Basically, the Phy header has been reduced in size.
3760 * This increase performance, especially at high rates
3761 * (the preamble is transmitted at 1Mb/s), unfortunately
3762 * this give compatibility troubles... - Jean II */
3763 val = *( (int *) extra );
3765 if (orinoco_lock(priv, &flags) != 0)
3773 orinoco_unlock(priv, &flags);
3775 return -EINPROGRESS; /* Call commit handler */
3778 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3779 struct iw_request_info *info,
3783 struct orinoco_private *priv = netdev_priv(dev);
3784 int *val = (int *) extra;
3786 if (! priv->has_preamble)
3789 *val = priv->preamble;
3793 /* ioctl interface to hermes_read_ltv()
3794 * To use with iwpriv, pass the RID as the token argument, e.g.
3795 * iwpriv get_rid [0xfc00]
3796 * At least Wireless Tools 25 is required to use iwpriv.
3797 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3798 static int orinoco_ioctl_getrid(struct net_device *dev,
3799 struct iw_request_info *info,
3800 struct iw_point *data,
3803 struct orinoco_private *priv = netdev_priv(dev);
3804 hermes_t *hw = &priv->hw;
3805 int rid = data->flags;
3808 unsigned long flags;
3810 /* It's a "get" function, but we don't want users to access the
3811 * WEP key and other raw firmware data */
3812 if (! capable(CAP_NET_ADMIN))
3815 if (rid < 0xfc00 || rid > 0xffff)
3818 if (orinoco_lock(priv, &flags) != 0)
3821 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3826 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3830 orinoco_unlock(priv, &flags);
3834 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3836 static int orinoco_ioctl_setspy(struct net_device *dev,
3837 struct iw_request_info *info,
3838 struct iw_point *srq,
3842 struct orinoco_private *priv = netdev_priv(dev);
3843 struct sockaddr *address = (struct sockaddr *) extra;
3844 int number = srq->length;
3846 unsigned long flags;
3848 /* Make sure nobody mess with the structure while we do */
3849 if (orinoco_lock(priv, &flags) != 0)
3852 /* orinoco_lock() doesn't disable interrupts, so make sure the
3853 * interrupt rx path don't get confused while we copy */
3854 priv->spy_number = 0;
3857 /* Extract the addresses */
3858 for (i = 0; i < number; i++)
3859 memcpy(priv->spy_address[i], address[i].sa_data,
3862 memset(priv->spy_stat, 0,
3863 sizeof(struct iw_quality) * IW_MAX_SPY);
3864 /* Set number of addresses */
3865 priv->spy_number = number;
3868 /* Now, let the others play */
3869 orinoco_unlock(priv, &flags);
3871 /* Do NOT call commit handler */
3875 static int orinoco_ioctl_getspy(struct net_device *dev,
3876 struct iw_request_info *info,
3877 struct iw_point *srq,
3880 struct orinoco_private *priv = netdev_priv(dev);
3881 struct sockaddr *address = (struct sockaddr *) extra;
3884 unsigned long flags;
3886 if (orinoco_lock(priv, &flags) != 0)
3889 number = priv->spy_number;
3890 /* Create address struct */
3891 for (i = 0; i < number; i++) {
3892 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3893 address[i].sa_family = AF_UNIX;
3896 /* Create address struct */
3897 for (i = 0; i < number; i++) {
3898 memcpy(address[i].sa_data, priv->spy_address[i],
3900 address[i].sa_family = AF_UNIX;
3903 /* In theory, we should disable irqs while copying the stats
3904 * because the rx path might update it in the middle...
3905 * Bah, who care ? - Jean II */
3906 memcpy(extra + (sizeof(struct sockaddr) * number),
3907 priv->spy_stat, sizeof(struct iw_quality) * number);
3909 /* Reset updated flags. */
3910 for (i = 0; i < number; i++)
3911 priv->spy_stat[i].updated = 0;
3913 orinoco_unlock(priv, &flags);
3915 srq->length = number;
3920 /* Trigger a scan (look for other cells in the vicinity */
3921 static int orinoco_ioctl_setscan(struct net_device *dev,
3922 struct iw_request_info *info,
3923 struct iw_param *srq,
3926 struct orinoco_private *priv = netdev_priv(dev);
3927 hermes_t *hw = &priv->hw;
3929 unsigned long flags;
3931 /* Note : you may have realised that, as this is a SET operation,
3932 * this is priviledged and therefore a normal user can't
3934 * This is not an error, while the device perform scanning,
3935 * traffic doesn't flow, so it's a perfect DoS...
3938 if (orinoco_lock(priv, &flags) != 0)
3941 /* Scanning with port 0 disabled would fail */
3942 if (!netif_running(dev)) {
3947 /* In monitor mode, the scan results are always empty.
3948 * Probe responses are passed to the driver as received
3949 * frames and could be processed in software. */
3950 if (priv->iw_mode == IW_MODE_MONITOR) {
3955 /* Note : because we don't lock out the irq handler, the way
3956 * we access scan variables in priv is critical.
3957 * o scan_inprogress : not touched by irq handler
3958 * o scan_mode : not touched by irq handler
3959 * o scan_result : irq is strict producer, non-irq is strict
3961 * o scan_len : synchronised with scan_result
3962 * Before modifying anything on those variables, please think hard !
3965 /* If there is still some left-over scan results, get rid of it */
3966 if (priv->scan_result != NULL) {
3967 /* What's likely is that a client did crash or was killed
3968 * between triggering the scan request and reading the
3969 * results, so we need to reset everything.
3970 * Some clients that are too slow may suffer from that...
3972 kfree(priv->scan_result);
3973 priv->scan_result = NULL;
3977 priv->scan_mode = srq->flags;
3979 /* Always trigger scanning, even if it's in progress.
3980 * This way, if the info frame get lost, we will recover somewhat
3981 * gracefully - Jean II */
3983 if (priv->has_hostscan) {
3984 switch (priv->firmware_type) {
3985 case FIRMWARE_TYPE_SYMBOL:
3986 err = hermes_write_wordrec(hw, USER_BAP,
3987 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3988 HERMES_HOSTSCAN_SYMBOL_ONCE |
3989 HERMES_HOSTSCAN_SYMBOL_BCAST);
3991 case FIRMWARE_TYPE_INTERSIL: {
3994 req[0] = cpu_to_le16(0x3fff); /* All channels */
3995 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3996 req[2] = 0; /* Any ESSID */
3997 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3998 HERMES_RID_CNFHOSTSCAN, &req);
4001 case FIRMWARE_TYPE_AGERE:
4002 err = hermes_write_wordrec(hw, USER_BAP,
4003 HERMES_RID_CNFSCANSSID_AGERE,
4008 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4012 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4014 /* One more client */
4016 priv->scan_inprogress = 1;
4019 orinoco_unlock(priv, &flags);
4023 /* Translate scan data returned from the card to a card independant
4024 * format that the Wireless Tools will understand - Jean II */
4025 static inline int orinoco_translate_scan(struct net_device *dev,
4030 struct orinoco_private *priv = netdev_priv(dev);
4031 int offset; /* In the scan data */
4032 union hermes_scan_info *atom;
4036 struct iw_event iwe; /* Temporary buffer */
4037 char * current_ev = buffer;
4038 char * end_buf = buffer + IW_SCAN_MAX_DATA;
4040 switch (priv->firmware_type) {
4041 case FIRMWARE_TYPE_AGERE:
4042 atom_len = sizeof(struct agere_scan_apinfo);
4045 case FIRMWARE_TYPE_SYMBOL:
4046 /* Lack of documentation necessitates this hack.
4047 * Different firmwares have 68 or 76 byte long atoms.
4048 * We try modulo first. If the length divides by both,
4049 * we check what would be the channel in the second
4050 * frame for a 68-byte atom. 76-byte atoms have 0 there.
4051 * Valid channel cannot be 0. */
4054 else if (scan_len % 68)
4056 else if (scan_len >= 1292 && scan[68] == 0)
4062 case FIRMWARE_TYPE_INTERSIL:
4064 if (priv->has_hostscan)
4065 atom_len = scan[0] + (scan[1] << 8);
4067 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4073 /* Check that we got an whole number of atoms */
4074 if ((scan_len - offset) % atom_len) {
4075 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4076 "atom_len %d, offset %d\n", dev->name, scan_len,
4081 /* Read the entries one by one */
4082 for (; offset + atom_len <= scan_len; offset += atom_len) {
4084 atom = (union hermes_scan_info *) (scan + offset);
4086 /* First entry *MUST* be the AP MAC address */
4087 iwe.cmd = SIOCGIWAP;
4088 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4089 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4090 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4092 /* Other entries will be displayed in the order we give them */
4095 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4096 if (iwe.u.data.length > 32)
4097 iwe.u.data.length = 32;
4098 iwe.cmd = SIOCGIWESSID;
4099 iwe.u.data.flags = 1;
4100 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4103 iwe.cmd = SIOCGIWMODE;
4104 capabilities = le16_to_cpu(atom->a.capabilities);
4105 if (capabilities & 0x3) {
4106 if (capabilities & 0x1)
4107 iwe.u.mode = IW_MODE_MASTER;
4109 iwe.u.mode = IW_MODE_ADHOC;
4110 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4113 channel = atom->s.channel;
4114 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4116 iwe.cmd = SIOCGIWFREQ;
4117 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4119 current_ev = iwe_stream_add_event(current_ev, end_buf,
4120 &iwe, IW_EV_FREQ_LEN);
4123 /* Add quality statistics */
4125 iwe.u.qual.updated = 0x10; /* no link quality */
4126 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4127 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4128 /* Wireless tools prior to 27.pre22 will show link quality
4129 * anyway, so we provide a reasonable value. */
4130 if (iwe.u.qual.level > iwe.u.qual.noise)
4131 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4133 iwe.u.qual.qual = 0;
4134 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4136 /* Add encryption capability */
4137 iwe.cmd = SIOCGIWENCODE;
4138 if (capabilities & 0x10)
4139 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4141 iwe.u.data.flags = IW_ENCODE_DISABLED;
4142 iwe.u.data.length = 0;
4143 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4145 /* Bit rate is not available in Lucent/Agere firmwares */
4146 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4147 char * current_val = current_ev + IW_EV_LCP_LEN;
4151 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4156 iwe.cmd = SIOCGIWRATE;
4157 /* Those two flags are ignored... */
4158 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4160 for (i = 0; i < 10; i += step) {
4161 /* NULL terminated */
4162 if (atom->p.rates[i] == 0x0)
4164 /* Bit rate given in 500 kb/s units (+ 0x80) */
4165 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4166 current_val = iwe_stream_add_value(current_ev, current_val,
4170 /* Check if we added any event */
4171 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4172 current_ev = current_val;
4175 /* The other data in the scan result are not really
4176 * interesting, so for now drop it - Jean II */
4178 return current_ev - buffer;
4181 /* Return results of a scan */
4182 static int orinoco_ioctl_getscan(struct net_device *dev,
4183 struct iw_request_info *info,
4184 struct iw_point *srq,
4187 struct orinoco_private *priv = netdev_priv(dev);
4189 unsigned long flags;
4191 if (orinoco_lock(priv, &flags) != 0)
4194 /* If no results yet, ask to try again later */
4195 if (priv->scan_result == NULL) {
4196 if (priv->scan_inprogress)
4197 /* Important note : we don't want to block the caller
4198 * until results are ready for various reasons.
4199 * First, managing wait queues is complex and racy.
4200 * Second, we grab some rtnetlink lock before comming
4201 * here (in dev_ioctl()).
4202 * Third, we generate an Wireless Event, so the
4203 * caller can wait itself on that - Jean II */
4206 /* Client error, no scan results...
4207 * The caller need to restart the scan. */
4210 /* We have some results to push back to user space */
4212 /* Translate to WE format */
4213 srq->length = orinoco_translate_scan(dev, extra,
4218 srq->flags = (__u16) priv->scan_mode;
4220 /* Results are here, so scan no longer in progress */
4221 priv->scan_inprogress = 0;
4223 /* In any case, Scan results will be cleaned up in the
4224 * reset function and when exiting the driver.
4225 * The person triggering the scanning may never come to
4226 * pick the results, so we need to do it in those places.
4229 #ifdef SCAN_SINGLE_READ
4230 /* If you enable this option, only one client (the first
4231 * one) will be able to read the result (and only one
4232 * time). If there is multiple concurent clients that
4233 * want to read scan results, this behavior is not
4234 * advisable - Jean II */
4235 kfree(priv->scan_result);
4236 priv->scan_result = NULL;
4237 #endif /* SCAN_SINGLE_READ */
4238 /* Here, if too much time has elapsed since last scan,
4239 * we may want to clean up scan results... - Jean II */
4242 orinoco_unlock(priv, &flags);
4246 /* Commit handler, called after set operations */
4247 static int orinoco_ioctl_commit(struct net_device *dev,
4248 struct iw_request_info *info,
4252 struct orinoco_private *priv = netdev_priv(dev);
4253 struct hermes *hw = &priv->hw;
4254 unsigned long flags;
4260 if (priv->broken_disableport) {
4265 if (orinoco_lock(priv, &flags) != 0)
4268 err = hermes_disable_port(hw, 0);
4270 printk(KERN_WARNING "%s: Unable to disable port "
4271 "while reconfiguring card\n", dev->name);
4272 priv->broken_disableport = 1;
4276 err = __orinoco_program_rids(dev);
4278 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4283 err = hermes_enable_port(hw, 0);
4285 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4292 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4293 schedule_work(&priv->reset_work);
4297 orinoco_unlock(priv, &flags);
4301 static const struct iw_priv_args orinoco_privtab[] = {
4302 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4303 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4304 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4306 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4308 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4309 0, "set_preamble" },
4310 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4312 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4313 0, "set_ibssport" },
4314 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4316 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4322 * Structures to export the Wireless Handlers
4325 static const iw_handler orinoco_handler[] = {
4326 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4327 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4328 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4329 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4330 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4331 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4332 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4333 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4334 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4335 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy,
4336 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy,
4337 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4338 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4339 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4340 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4341 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4342 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4343 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4344 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4345 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4346 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4347 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4348 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4349 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4350 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4351 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4352 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4353 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4354 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4355 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4360 Added typecasting since we no longer use iwreq_data -- Moustafa
4362 static const iw_handler orinoco_private_handler[] = {
4363 [0] = (iw_handler) orinoco_ioctl_reset,
4364 [1] = (iw_handler) orinoco_ioctl_reset,
4365 [2] = (iw_handler) orinoco_ioctl_setport3,
4366 [3] = (iw_handler) orinoco_ioctl_getport3,
4367 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4368 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4369 [6] = (iw_handler) orinoco_ioctl_setibssport,
4370 [7] = (iw_handler) orinoco_ioctl_getibssport,
4371 [9] = (iw_handler) orinoco_ioctl_getrid,
4374 static const struct iw_handler_def orinoco_handler_def = {
4375 .num_standard = ARRAY_SIZE(orinoco_handler),
4376 .num_private = ARRAY_SIZE(orinoco_private_handler),
4377 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4378 .standard = orinoco_handler,
4379 .private = orinoco_private_handler,
4380 .private_args = orinoco_privtab,
4383 static void orinoco_get_drvinfo(struct net_device *dev,
4384 struct ethtool_drvinfo *info)
4386 struct orinoco_private *priv = netdev_priv(dev);
4388 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4389 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4390 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4391 if (dev->class_dev.dev)
4392 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4393 sizeof(info->bus_info) - 1);
4395 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4396 "PCMCIA %p", priv->hw.iobase);
4399 static struct ethtool_ops orinoco_ethtool_ops = {
4400 .get_drvinfo = orinoco_get_drvinfo,
4401 .get_link = ethtool_op_get_link,
4404 /********************************************************************/
4406 /********************************************************************/
4409 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4411 printk(KERN_DEBUG "RX descriptor:\n");
4412 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4413 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4414 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4415 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4416 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4417 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4418 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4420 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4421 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4422 frame->p80211.frame_ctl);
4423 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4424 frame->p80211.duration_id);
4425 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4426 frame->p80211.addr1[0], frame->p80211.addr1[1],
4427 frame->p80211.addr1[2], frame->p80211.addr1[3],
4428 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4429 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4430 frame->p80211.addr2[0], frame->p80211.addr2[1],
4431 frame->p80211.addr2[2], frame->p80211.addr2[3],
4432 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4433 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4434 frame->p80211.addr3[0], frame->p80211.addr3[1],
4435 frame->p80211.addr3[2], frame->p80211.addr3[3],
4436 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4437 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4438 frame->p80211.seq_ctl);
4439 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4440 frame->p80211.addr4[0], frame->p80211.addr4[1],
4441 frame->p80211.addr4[2], frame->p80211.addr4[3],
4442 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4443 printk(KERN_DEBUG " data_len = 0x%04x\n",
4444 frame->p80211.data_len);
4446 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4447 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4448 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4449 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4450 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4451 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4452 frame->p8023.h_source[0], frame->p8023.h_source[1],
4453 frame->p8023.h_source[2], frame->p8023.h_source[3],
4454 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4455 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4457 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4458 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4459 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4460 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4461 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4462 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4463 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4467 /********************************************************************/
4468 /* Module initialization */
4469 /********************************************************************/
4471 EXPORT_SYMBOL(alloc_orinocodev);
4472 EXPORT_SYMBOL(free_orinocodev);
4474 EXPORT_SYMBOL(__orinoco_up);
4475 EXPORT_SYMBOL(__orinoco_down);
4476 EXPORT_SYMBOL(orinoco_reinit_firmware);
4478 EXPORT_SYMBOL(orinoco_interrupt);
4480 /* Can't be declared "const" or the whole __initdata section will
4482 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4483 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4484 "Pavel Roskin <proski@gnu.org>, et al)";
4486 static int __init init_orinoco(void)
4488 printk(KERN_DEBUG "%s\n", version);
4492 static void __exit exit_orinoco(void)
4496 module_init(init_orinoco);
4497 module_exit(exit_orinoco);