1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/config.h>
81 #include <linux/module.h>
82 #include <linux/kernel.h>
83 #include <linux/init.h>
84 #include <linux/ptrace.h>
85 #include <linux/slab.h>
86 #include <linux/string.h>
87 #include <linux/timer.h>
88 #include <linux/ioport.h>
89 #include <linux/netdevice.h>
90 #include <linux/if_arp.h>
91 #include <linux/etherdevice.h>
92 #include <linux/ethtool.h>
93 #include <linux/wireless.h>
94 #include <net/iw_handler.h>
95 #include <net/ieee80211.h>
97 #include <net/ieee80211.h>
99 #include <asm/uaccess.h>
101 #include <asm/system.h>
104 #include "hermes_rid.h"
107 /********************************************************************/
108 /* Module information */
109 /********************************************************************/
111 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
112 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
113 MODULE_LICENSE("Dual MPL/GPL");
115 /* Level of debugging. Used in the macros in orinoco.h */
117 int orinoco_debug = ORINOCO_DEBUG;
118 module_param(orinoco_debug, int, 0644);
119 MODULE_PARM_DESC(orinoco_debug, "Debug level");
120 EXPORT_SYMBOL(orinoco_debug);
123 static int suppress_linkstatus; /* = 0 */
124 module_param(suppress_linkstatus, bool, 0644);
125 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
126 static int ignore_disconnect; /* = 0 */
127 module_param(ignore_disconnect, int, 0644);
128 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
130 static int force_monitor; /* = 0 */
131 module_param(force_monitor, int, 0644);
132 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
134 /********************************************************************/
135 /* Compile time configuration and compatibility stuff */
136 /********************************************************************/
138 /* We do this this way to avoid ifdefs in the actual code */
140 #define SPY_NUMBER(priv) (priv->spy_number)
142 #define SPY_NUMBER(priv) 0
143 #endif /* WIRELESS_SPY */
145 /********************************************************************/
146 /* Internal constants */
147 /********************************************************************/
149 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
150 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
151 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
153 #define ORINOCO_MIN_MTU 256
154 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
156 #define SYMBOL_MAX_VER_LEN (14)
159 #define MAX_IRQLOOPS_PER_IRQ 10
160 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
161 * how many events the
163 * legitimately generate */
164 #define SMALL_KEY_SIZE 5
165 #define LARGE_KEY_SIZE 13
166 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
168 #define DUMMY_FID 0xFFFF
170 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
171 HERMES_MAX_MULTICAST : 0)*/
172 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
174 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
175 | HERMES_EV_TX | HERMES_EV_TXEXC \
176 | HERMES_EV_WTERR | HERMES_EV_INFO \
177 | HERMES_EV_INFDROP )
179 #define MAX_RID_LEN 1024
181 static const struct iw_handler_def orinoco_handler_def;
182 static struct ethtool_ops orinoco_ethtool_ops;
184 /********************************************************************/
186 /********************************************************************/
188 /* The frequency of each channel in MHz */
189 static const long channel_frequency[] = {
190 2412, 2417, 2422, 2427, 2432, 2437, 2442,
191 2447, 2452, 2457, 2462, 2467, 2472, 2484
193 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
195 /* This tables gives the actual meanings of the bitrate IDs returned
196 * by the firmware. */
198 int bitrate; /* in 100s of kilobits */
200 u16 agere_txratectrl;
201 u16 intersil_txratectrl;
202 } bitrate_table[] = {
203 {110, 1, 3, 15}, /* Entry 0 is the default */
212 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
214 /********************************************************************/
216 /********************************************************************/
218 /* Used in Event handling.
219 * We avoid nested structres as they break on ARM -- Moustafa */
220 struct hermes_tx_descriptor_802_11 {
221 /* hermes_tx_descriptor */
241 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
242 unsigned char h_source[ETH_ALEN]; /* source ether addr */
243 unsigned short h_proto; /* packet type ID field */
252 } __attribute__ ((packed));
254 /* Rx frame header except compatibility 802.3 header */
255 struct hermes_rx_descriptor {
276 } __attribute__ ((packed));
278 /********************************************************************/
279 /* Function prototypes */
280 /********************************************************************/
282 static int __orinoco_program_rids(struct net_device *dev);
283 static void __orinoco_set_multicast_list(struct net_device *dev);
285 /********************************************************************/
286 /* Internal helper functions */
287 /********************************************************************/
289 static inline void set_port_type(struct orinoco_private *priv)
291 switch (priv->iw_mode) {
294 priv->createibss = 0;
297 if (priv->prefer_port3) {
299 priv->createibss = 0;
301 priv->port_type = priv->ibss_port;
302 priv->createibss = 1;
305 case IW_MODE_MONITOR:
307 priv->createibss = 0;
310 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
315 /********************************************************************/
317 /********************************************************************/
319 static int orinoco_open(struct net_device *dev)
321 struct orinoco_private *priv = netdev_priv(dev);
325 if (orinoco_lock(priv, &flags) != 0)
328 err = __orinoco_up(dev);
333 orinoco_unlock(priv, &flags);
338 static int orinoco_stop(struct net_device *dev)
340 struct orinoco_private *priv = netdev_priv(dev);
343 /* We mustn't use orinoco_lock() here, because we need to be
344 able to close the interface even if hw_unavailable is set
345 (e.g. as we're released after a PC Card removal) */
346 spin_lock_irq(&priv->lock);
350 err = __orinoco_down(dev);
352 spin_unlock_irq(&priv->lock);
357 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
359 struct orinoco_private *priv = netdev_priv(dev);
364 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
366 struct orinoco_private *priv = netdev_priv(dev);
367 hermes_t *hw = &priv->hw;
368 struct iw_statistics *wstats = &priv->wstats;
372 if (! netif_device_present(dev)) {
373 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
375 return NULL; /* FIXME: Can we do better than this? */
378 /* If busy, return the old stats. Returning NULL may cause
379 * the interface to disappear from /proc/net/wireless */
380 if (orinoco_lock(priv, &flags) != 0)
383 /* We can't really wait for the tallies inquiry command to
384 * complete, so we just use the previous results and trigger
385 * a new tallies inquiry command for next time - Jean II */
386 /* FIXME: Really we should wait for the inquiry to come back -
387 * as it is the stats we give don't make a whole lot of sense.
388 * Unfortunately, it's not clear how to do that within the
389 * wireless extensions framework: I think we're in user
390 * context, but a lock seems to be held by the time we get in
391 * here so we're not safe to sleep here. */
392 hermes_inquire(hw, HERMES_INQ_TALLIES);
394 if (priv->iw_mode == IW_MODE_ADHOC) {
395 memset(&wstats->qual, 0, sizeof(wstats->qual));
396 /* If a spy address is defined, we report stats of the
397 * first spy address - Jean II */
398 if (SPY_NUMBER(priv)) {
399 wstats->qual.qual = priv->spy_stat[0].qual;
400 wstats->qual.level = priv->spy_stat[0].level;
401 wstats->qual.noise = priv->spy_stat[0].noise;
402 wstats->qual.updated = priv->spy_stat[0].updated;
406 u16 qual, signal, noise;
407 } __attribute__ ((packed)) cq;
409 err = HERMES_READ_RECORD(hw, USER_BAP,
410 HERMES_RID_COMMSQUALITY, &cq);
413 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
414 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
415 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
416 wstats->qual.updated = 7;
420 orinoco_unlock(priv, &flags);
424 static void orinoco_set_multicast_list(struct net_device *dev)
426 struct orinoco_private *priv = netdev_priv(dev);
429 if (orinoco_lock(priv, &flags) != 0) {
430 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
431 "called when hw_unavailable\n", dev->name);
435 __orinoco_set_multicast_list(dev);
436 orinoco_unlock(priv, &flags);
439 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
441 struct orinoco_private *priv = netdev_priv(dev);
443 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
446 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
447 (priv->nicbuf_size - ETH_HLEN) )
455 /********************************************************************/
457 /********************************************************************/
459 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
461 struct orinoco_private *priv = netdev_priv(dev);
462 struct net_device_stats *stats = &priv->stats;
463 hermes_t *hw = &priv->hw;
465 u16 txfid = priv->txfid;
468 int len, data_len, data_off;
469 struct hermes_tx_descriptor desc;
472 TRACE_ENTER(dev->name);
474 if (! netif_running(dev)) {
475 printk(KERN_ERR "%s: Tx on stopped device!\n",
477 TRACE_EXIT(dev->name);
481 if (netif_queue_stopped(dev)) {
482 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
484 TRACE_EXIT(dev->name);
488 if (orinoco_lock(priv, &flags) != 0) {
489 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
491 TRACE_EXIT(dev->name);
495 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
496 /* Oops, the firmware hasn't established a connection,
497 silently drop the packet (this seems to be the
500 orinoco_unlock(priv, &flags);
502 TRACE_EXIT(dev->name);
506 /* Check packet length, pad short packets, round up odd length */
507 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
508 if (skb->len < len) {
509 skb = skb_padto(skb, len);
515 eh = (struct ethhdr *)skb->data;
517 memset(&desc, 0, sizeof(desc));
518 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
519 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
522 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
523 "to BAP\n", dev->name, err);
528 /* Clear the 802.11 header and data length fields - some
529 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
530 * if this isn't done. */
531 hermes_clear_words(hw, HERMES_DATA0,
532 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
534 /* Encapsulate Ethernet-II frames */
535 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
536 struct header_struct hdr;
538 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
539 p = skb->data + ETH_HLEN;
542 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
543 memcpy(hdr.src, eh->h_source, ETH_ALEN);
544 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
547 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
549 hdr.ethertype = eh->h_proto;
550 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
551 txfid, HERMES_802_3_OFFSET);
554 printk(KERN_ERR "%s: Error %d writing packet "
555 "header to BAP\n", dev->name, err);
559 } else { /* IEEE 802.3 frame */
560 data_len = len + ETH_HLEN;
561 data_off = HERMES_802_3_OFFSET;
565 err = hermes_bap_pwrite(hw, USER_BAP, p, data_len,
568 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
574 /* Finally, we actually initiate the send */
575 netif_stop_queue(dev);
577 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
580 netif_start_queue(dev);
582 printk(KERN_ERR "%s: Error %d transmitting packet\n",
588 dev->trans_start = jiffies;
589 stats->tx_bytes += data_off + data_len;
591 orinoco_unlock(priv, &flags);
595 TRACE_EXIT(dev->name);
599 TRACE_EXIT(dev->name);
601 orinoco_unlock(priv, &flags);
605 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
607 struct orinoco_private *priv = netdev_priv(dev);
608 u16 fid = hermes_read_regn(hw, ALLOCFID);
610 if (fid != priv->txfid) {
611 if (fid != DUMMY_FID)
612 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
617 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
620 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
622 struct orinoco_private *priv = netdev_priv(dev);
623 struct net_device_stats *stats = &priv->stats;
627 netif_wake_queue(dev);
629 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
632 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
634 struct orinoco_private *priv = netdev_priv(dev);
635 struct net_device_stats *stats = &priv->stats;
636 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
637 struct hermes_tx_descriptor_802_11 hdr;
640 if (fid == DUMMY_FID)
641 return; /* Nothing's really happened */
643 /* Read the frame header */
644 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
645 sizeof(struct hermes_tx_descriptor) +
646 sizeof(struct ieee80211_hdr),
649 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
653 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
654 "(FID=%04X error %d)\n",
655 dev->name, fid, err);
659 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
662 /* We produce a TXDROP event only for retry or lifetime
663 * exceeded, because that's the only status that really mean
664 * that this particular node went away.
665 * Other errors means that *we* screwed up. - Jean II */
666 hdr.status = le16_to_cpu(hdr.status);
667 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
668 union iwreq_data wrqu;
670 /* Copy 802.11 dest address.
671 * We use the 802.11 header because the frame may
672 * not be 802.3 or may be mangled...
673 * In Ad-Hoc mode, it will be the node address.
674 * In managed mode, it will be most likely the AP addr
675 * User space will figure out how to convert it to
676 * whatever it needs (IP address or else).
678 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
679 wrqu.addr.sa_family = ARPHRD_ETHER;
681 /* Send event to user space */
682 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
685 netif_wake_queue(dev);
688 static void orinoco_tx_timeout(struct net_device *dev)
690 struct orinoco_private *priv = netdev_priv(dev);
691 struct net_device_stats *stats = &priv->stats;
692 struct hermes *hw = &priv->hw;
694 printk(KERN_WARNING "%s: Tx timeout! "
695 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
696 dev->name, hermes_read_regn(hw, ALLOCFID),
697 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
701 schedule_work(&priv->reset_work);
704 /********************************************************************/
705 /* Rx path (data frames) */
706 /********************************************************************/
708 /* Does the frame have a SNAP header indicating it should be
709 * de-encapsulated to Ethernet-II? */
710 static inline int is_ethersnap(void *_hdr)
714 /* We de-encapsulate all packets which, a) have SNAP headers
715 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
716 * and where b) the OUI of the SNAP header is 00:00:00 or
717 * 00:00:f8 - we need both because different APs appear to use
718 * different OUIs for some reason */
719 return (memcmp(hdr, &encaps_hdr, 5) == 0)
720 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
723 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
724 int level, int noise)
726 struct orinoco_private *priv = netdev_priv(dev);
729 /* Gather wireless spy statistics: for each packet, compare the
730 * source address with out list, and if match, get the stats... */
731 for (i = 0; i < priv->spy_number; i++)
732 if (!memcmp(mac, priv->spy_address[i], ETH_ALEN)) {
733 priv->spy_stat[i].level = level - 0x95;
734 priv->spy_stat[i].noise = noise - 0x95;
735 priv->spy_stat[i].qual = (level > noise) ? (level - noise) : 0;
736 priv->spy_stat[i].updated = 7;
740 static void orinoco_stat_gather(struct net_device *dev,
742 struct hermes_rx_descriptor *desc)
744 struct orinoco_private *priv = netdev_priv(dev);
746 /* Using spy support with lots of Rx packets, like in an
747 * infrastructure (AP), will really slow down everything, because
748 * the MAC address must be compared to each entry of the spy list.
749 * If the user really asks for it (set some address in the
750 * spy list), we do it, but he will pay the price.
751 * Note that to get here, you need both WIRELESS_SPY
752 * compiled in AND some addresses in the list !!!
754 /* Note : gcc will optimise the whole section away if
755 * WIRELESS_SPY is not defined... - Jean II */
756 if (SPY_NUMBER(priv)) {
757 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
758 desc->signal, desc->silence);
763 * orinoco_rx_monitor - handle received monitor frames.
768 * desc rx descriptor of the frame
770 * Call context: interrupt
772 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
773 struct hermes_rx_descriptor *desc)
775 u32 hdrlen = 30; /* return full header by default */
781 struct orinoco_private *priv = netdev_priv(dev);
782 struct net_device_stats *stats = &priv->stats;
783 hermes_t *hw = &priv->hw;
785 len = le16_to_cpu(desc->data_len);
787 /* Determine the size of the header and the data */
788 fc = le16_to_cpu(desc->frame_ctl);
789 switch (fc & IEEE80211_FCTL_FTYPE) {
790 case IEEE80211_FTYPE_DATA:
791 if ((fc & IEEE80211_FCTL_TODS)
792 && (fc & IEEE80211_FCTL_FROMDS))
798 case IEEE80211_FTYPE_MGMT:
802 case IEEE80211_FTYPE_CTL:
803 switch (fc & IEEE80211_FCTL_STYPE) {
804 case IEEE80211_STYPE_PSPOLL:
805 case IEEE80211_STYPE_RTS:
806 case IEEE80211_STYPE_CFEND:
807 case IEEE80211_STYPE_CFENDACK:
810 case IEEE80211_STYPE_CTS:
811 case IEEE80211_STYPE_ACK:
817 /* Unknown frame type */
821 /* sanity check the length */
822 if (datalen > IEEE80211_DATA_LEN + 12) {
823 printk(KERN_DEBUG "%s: oversized monitor frame, "
824 "data length = %d\n", dev->name, datalen);
826 stats->rx_length_errors++;
830 skb = dev_alloc_skb(hdrlen + datalen);
832 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
838 /* Copy the 802.11 header to the skb */
839 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
840 skb->mac.raw = skb->data;
842 /* If any, copy the data from the card to the skb */
844 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
845 ALIGN(datalen, 2), rxfid,
846 HERMES_802_2_OFFSET);
848 printk(KERN_ERR "%s: error %d reading monitor frame\n",
855 skb->ip_summed = CHECKSUM_NONE;
856 skb->pkt_type = PACKET_OTHERHOST;
857 skb->protocol = __constant_htons(ETH_P_802_2);
859 dev->last_rx = jiffies;
861 stats->rx_bytes += skb->len;
867 dev_kfree_skb_irq(skb);
873 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
875 struct orinoco_private *priv = netdev_priv(dev);
876 struct net_device_stats *stats = &priv->stats;
877 struct iw_statistics *wstats = &priv->wstats;
878 struct sk_buff *skb = NULL;
879 u16 rxfid, status, fc;
881 struct hermes_rx_descriptor desc;
885 rxfid = hermes_read_regn(hw, RXFID);
887 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
890 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
891 "Frame dropped.\n", dev->name, err);
895 status = le16_to_cpu(desc.status);
897 if (status & HERMES_RXSTAT_BADCRC) {
898 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
900 stats->rx_crc_errors++;
904 /* Handle frames in monitor mode */
905 if (priv->iw_mode == IW_MODE_MONITOR) {
906 orinoco_rx_monitor(dev, rxfid, &desc);
910 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
911 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
913 wstats->discard.code++;
917 length = le16_to_cpu(desc.data_len);
918 fc = le16_to_cpu(desc.frame_ctl);
921 if (length < 3) { /* No for even an 802.2 LLC header */
922 /* At least on Symbol firmware with PCF we get quite a
923 lot of these legitimately - Poll frames with no
927 if (length > IEEE80211_DATA_LEN) {
928 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
930 stats->rx_length_errors++;
934 /* We need space for the packet data itself, plus an ethernet
935 header, plus 2 bytes so we can align the IP header on a
936 32bit boundary, plus 1 byte so we can read in odd length
937 packets from the card, which has an IO granularity of 16
939 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
941 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
946 /* We'll prepend the header, so reserve space for it. The worst
947 case is no decapsulation, when 802.3 header is prepended and
948 nothing is removed. 2 is for aligning the IP header. */
949 skb_reserve(skb, ETH_HLEN + 2);
951 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
952 ALIGN(length, 2), rxfid,
953 HERMES_802_2_OFFSET);
955 printk(KERN_ERR "%s: error %d reading frame. "
956 "Frame dropped.\n", dev->name, err);
960 /* Handle decapsulation
961 * In most cases, the firmware tell us about SNAP frames.
962 * For some reason, the SNAP frames sent by LinkSys APs
963 * are not properly recognised by most firmwares.
964 * So, check ourselves */
965 if (length >= ENCAPS_OVERHEAD &&
966 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
967 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
968 is_ethersnap(skb->data))) {
969 /* These indicate a SNAP within 802.2 LLC within
970 802.11 frame which we'll need to de-encapsulate to
971 the original EthernetII frame. */
972 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
974 /* 802.3 frame - prepend 802.3 header as is */
975 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
976 hdr->h_proto = htons(length);
978 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
979 if (fc & IEEE80211_FCTL_FROMDS)
980 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
982 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
984 dev->last_rx = jiffies;
986 skb->protocol = eth_type_trans(skb, dev);
987 skb->ip_summed = CHECKSUM_NONE;
988 if (fc & IEEE80211_FCTL_TODS)
989 skb->pkt_type = PACKET_OTHERHOST;
991 /* Process the wireless stats if needed */
992 orinoco_stat_gather(dev, skb, &desc);
994 /* Pass the packet to the networking stack */
997 stats->rx_bytes += length;
1002 dev_kfree_skb_irq(skb);
1005 stats->rx_dropped++;
1008 /********************************************************************/
1009 /* Rx path (info frames) */
1010 /********************************************************************/
1012 static void print_linkstatus(struct net_device *dev, u16 status)
1016 if (suppress_linkstatus)
1020 case HERMES_LINKSTATUS_NOT_CONNECTED:
1021 s = "Not Connected";
1023 case HERMES_LINKSTATUS_CONNECTED:
1026 case HERMES_LINKSTATUS_DISCONNECTED:
1029 case HERMES_LINKSTATUS_AP_CHANGE:
1032 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1033 s = "AP Out of Range";
1035 case HERMES_LINKSTATUS_AP_IN_RANGE:
1038 case HERMES_LINKSTATUS_ASSOC_FAILED:
1039 s = "Association Failed";
1045 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1046 dev->name, s, status);
1049 /* Search scan results for requested BSSID, join it if found */
1050 static void orinoco_join_ap(struct net_device *dev)
1052 struct orinoco_private *priv = netdev_priv(dev);
1053 struct hermes *hw = &priv->hw;
1055 unsigned long flags;
1059 } __attribute__ ((packed)) req;
1060 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1061 struct prism2_scan_apinfo *atom = NULL;
1067 /* Allocate buffer for scan results */
1068 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1072 if (orinoco_lock(priv, &flags) != 0)
1075 /* Sanity checks in case user changed something in the meantime */
1076 if (! priv->bssid_fixed)
1079 if (strlen(priv->desired_essid) == 0)
1082 /* Read scan results from the firmware */
1083 err = hermes_read_ltv(hw, USER_BAP,
1084 HERMES_RID_SCANRESULTSTABLE,
1085 MAX_SCAN_LEN, &len, buf);
1087 printk(KERN_ERR "%s: Cannot read scan results\n",
1092 len = HERMES_RECLEN_TO_BYTES(len);
1094 /* Go through the scan results looking for the channel of the AP
1095 * we were requested to join */
1096 for (; offset + atom_len <= len; offset += atom_len) {
1097 atom = (struct prism2_scan_apinfo *) (buf + offset);
1098 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1105 DEBUG(1, "%s: Requested AP not found in scan results\n",
1110 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1111 req.channel = atom->channel; /* both are little-endian */
1112 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1115 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1119 orinoco_unlock(priv, &flags);
1122 /* Send new BSSID to userspace */
1123 static void orinoco_send_wevents(struct net_device *dev)
1125 struct orinoco_private *priv = netdev_priv(dev);
1126 struct hermes *hw = &priv->hw;
1127 union iwreq_data wrqu;
1129 unsigned long flags;
1131 if (orinoco_lock(priv, &flags) != 0)
1134 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1135 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1139 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1141 /* Send event to user space */
1142 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1143 orinoco_unlock(priv, &flags);
1146 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1148 struct orinoco_private *priv = netdev_priv(dev);
1153 } __attribute__ ((packed)) info;
1157 /* This is an answer to an INQUIRE command that we did earlier,
1158 * or an information "event" generated by the card
1159 * The controller return to us a pseudo frame containing
1160 * the information in question - Jean II */
1161 infofid = hermes_read_regn(hw, INFOFID);
1163 /* Read the info frame header - don't try too hard */
1164 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1167 printk(KERN_ERR "%s: error %d reading info frame. "
1168 "Frame dropped.\n", dev->name, err);
1172 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1173 type = le16_to_cpu(info.type);
1176 case HERMES_INQ_TALLIES: {
1177 struct hermes_tallies_frame tallies;
1178 struct iw_statistics *wstats = &priv->wstats;
1180 if (len > sizeof(tallies)) {
1181 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1183 len = sizeof(tallies);
1186 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1187 infofid, sizeof(info));
1191 /* Increment our various counters */
1192 /* wstats->discard.nwid - no wrong BSSID stuff */
1193 wstats->discard.code +=
1194 le16_to_cpu(tallies.RxWEPUndecryptable);
1195 if (len == sizeof(tallies))
1196 wstats->discard.code +=
1197 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1198 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1199 wstats->discard.misc +=
1200 le16_to_cpu(tallies.TxDiscardsWrongSA);
1201 wstats->discard.fragment +=
1202 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1203 wstats->discard.retries +=
1204 le16_to_cpu(tallies.TxRetryLimitExceeded);
1205 /* wstats->miss.beacon - no match */
1208 case HERMES_INQ_LINKSTATUS: {
1209 struct hermes_linkstatus linkstatus;
1213 if (priv->iw_mode == IW_MODE_MONITOR)
1216 if (len != sizeof(linkstatus)) {
1217 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1222 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1223 infofid, sizeof(info));
1226 newstatus = le16_to_cpu(linkstatus.linkstatus);
1228 /* Symbol firmware uses "out of range" to signal that
1229 * the hostscan frame can be requested. */
1230 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1231 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1232 priv->has_hostscan && priv->scan_inprogress) {
1233 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1237 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1238 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1239 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1242 netif_carrier_on(dev);
1243 else if (!ignore_disconnect)
1244 netif_carrier_off(dev);
1246 if (newstatus != priv->last_linkstatus) {
1247 priv->last_linkstatus = newstatus;
1248 print_linkstatus(dev, newstatus);
1249 /* The info frame contains only one word which is the
1250 * status (see hermes.h). The status is pretty boring
1251 * in itself, that's why we export the new BSSID...
1253 schedule_work(&priv->wevent_work);
1257 case HERMES_INQ_SCAN:
1258 if (!priv->scan_inprogress && priv->bssid_fixed &&
1259 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1260 schedule_work(&priv->join_work);
1264 case HERMES_INQ_HOSTSCAN:
1265 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1266 /* Result of a scanning. Contains information about
1267 * cells in the vicinity - Jean II */
1268 union iwreq_data wrqu;
1273 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1278 /* We are a strict producer. If the previous scan results
1279 * have not been consumed, we just have to drop this
1280 * frame. We can't remove the previous results ourselves,
1281 * that would be *very* racy... Jean II */
1282 if (priv->scan_result != NULL) {
1283 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1287 /* Allocate buffer for results */
1288 buf = kmalloc(len, GFP_ATOMIC);
1290 /* No memory, so can't printk()... */
1293 /* Read scan data */
1294 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1295 infofid, sizeof(info));
1301 #ifdef ORINOCO_DEBUG
1304 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1305 for(i = 1; i < (len * 2); i++)
1306 printk(":%02X", buf[i]);
1309 #endif /* ORINOCO_DEBUG */
1311 /* Allow the clients to access the results */
1312 priv->scan_len = len;
1313 priv->scan_result = buf;
1315 /* Send an empty event to user space.
1316 * We don't send the received data on the event because
1317 * it would require us to do complex transcoding, and
1318 * we want to minimise the work done in the irq handler
1319 * Use a request to extract the data - Jean II */
1320 wrqu.data.length = 0;
1321 wrqu.data.flags = 0;
1322 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1325 case HERMES_INQ_SEC_STAT_AGERE:
1326 /* Security status (Agere specific) */
1327 /* Ignore this frame for now */
1328 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1332 printk(KERN_DEBUG "%s: Unknown information frame received: "
1333 "type 0x%04x, length %d\n", dev->name, type, len);
1334 /* We don't actually do anything about it */
1339 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1341 if (net_ratelimit())
1342 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1345 /********************************************************************/
1346 /* Internal hardware control routines */
1347 /********************************************************************/
1349 int __orinoco_up(struct net_device *dev)
1351 struct orinoco_private *priv = netdev_priv(dev);
1352 struct hermes *hw = &priv->hw;
1355 netif_carrier_off(dev); /* just to make sure */
1357 err = __orinoco_program_rids(dev);
1359 printk(KERN_ERR "%s: Error %d configuring card\n",
1364 /* Fire things up again */
1365 hermes_set_irqmask(hw, ORINOCO_INTEN);
1366 err = hermes_enable_port(hw, 0);
1368 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1373 netif_start_queue(dev);
1378 int __orinoco_down(struct net_device *dev)
1380 struct orinoco_private *priv = netdev_priv(dev);
1381 struct hermes *hw = &priv->hw;
1384 netif_stop_queue(dev);
1386 if (! priv->hw_unavailable) {
1387 if (! priv->broken_disableport) {
1388 err = hermes_disable_port(hw, 0);
1390 /* Some firmwares (e.g. Intersil 1.3.x) seem
1391 * to have problems disabling the port, oh
1393 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1395 priv->broken_disableport = 1;
1398 hermes_set_irqmask(hw, 0);
1399 hermes_write_regn(hw, EVACK, 0xffff);
1402 /* firmware will have to reassociate */
1403 netif_carrier_off(dev);
1404 priv->last_linkstatus = 0xffff;
1409 int orinoco_reinit_firmware(struct net_device *dev)
1411 struct orinoco_private *priv = netdev_priv(dev);
1412 struct hermes *hw = &priv->hw;
1415 err = hermes_init(hw);
1419 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1420 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1421 /* Try workaround for old Symbol firmware bug */
1422 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1423 "(old Symbol firmware?). Trying to work around... ",
1426 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1427 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1429 printk("failed!\n");
1437 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1439 hermes_t *hw = &priv->hw;
1442 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1443 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1444 priv->ndev->name, priv->bitratemode);
1448 switch (priv->firmware_type) {
1449 case FIRMWARE_TYPE_AGERE:
1450 err = hermes_write_wordrec(hw, USER_BAP,
1451 HERMES_RID_CNFTXRATECONTROL,
1452 bitrate_table[priv->bitratemode].agere_txratectrl);
1454 case FIRMWARE_TYPE_INTERSIL:
1455 case FIRMWARE_TYPE_SYMBOL:
1456 err = hermes_write_wordrec(hw, USER_BAP,
1457 HERMES_RID_CNFTXRATECONTROL,
1458 bitrate_table[priv->bitratemode].intersil_txratectrl);
1467 /* Set fixed AP address */
1468 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1472 hermes_t *hw = &priv->hw;
1474 switch (priv->firmware_type) {
1475 case FIRMWARE_TYPE_AGERE:
1478 case FIRMWARE_TYPE_INTERSIL:
1479 if (priv->bssid_fixed)
1484 err = hermes_write_wordrec(hw, USER_BAP,
1485 HERMES_RID_CNFROAMINGMODE,
1488 case FIRMWARE_TYPE_SYMBOL:
1489 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1490 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1491 &priv->desired_bssid);
1497 /* Change the WEP keys and/or the current keys. Can be called
1498 * either from __orinoco_hw_setup_wep() or directly from
1499 * orinoco_ioctl_setiwencode(). In the later case the association
1500 * with the AP is not broken (if the firmware can handle it),
1501 * which is needed for 802.1x implementations. */
1502 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1504 hermes_t *hw = &priv->hw;
1507 switch (priv->firmware_type) {
1508 case FIRMWARE_TYPE_AGERE:
1509 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1510 HERMES_RID_CNFWEPKEYS_AGERE,
1514 err = hermes_write_wordrec(hw, USER_BAP,
1515 HERMES_RID_CNFTXKEY_AGERE,
1520 case FIRMWARE_TYPE_INTERSIL:
1521 case FIRMWARE_TYPE_SYMBOL:
1526 /* Force uniform key length to work around firmware bugs */
1527 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1529 if (keylen > LARGE_KEY_SIZE) {
1530 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1531 priv->ndev->name, priv->tx_key, keylen);
1535 /* Write all 4 keys */
1536 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1537 err = hermes_write_ltv(hw, USER_BAP,
1538 HERMES_RID_CNFDEFAULTKEY0 + i,
1539 HERMES_BYTES_TO_RECLEN(keylen),
1540 priv->keys[i].data);
1545 /* Write the index of the key used in transmission */
1546 err = hermes_write_wordrec(hw, USER_BAP,
1547 HERMES_RID_CNFWEPDEFAULTKEYID,
1558 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1560 hermes_t *hw = &priv->hw;
1562 int master_wep_flag;
1566 __orinoco_hw_setup_wepkeys(priv);
1568 if (priv->wep_restrict)
1569 auth_flag = HERMES_AUTH_SHARED_KEY;
1571 auth_flag = HERMES_AUTH_OPEN;
1573 switch (priv->firmware_type) {
1574 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1576 /* Enable the shared-key authentication. */
1577 err = hermes_write_wordrec(hw, USER_BAP,
1578 HERMES_RID_CNFAUTHENTICATION_AGERE,
1581 err = hermes_write_wordrec(hw, USER_BAP,
1582 HERMES_RID_CNFWEPENABLED_AGERE,
1588 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1589 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1591 if (priv->wep_restrict ||
1592 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1593 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1594 HERMES_WEP_EXCL_UNENCRYPTED;
1596 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1598 err = hermes_write_wordrec(hw, USER_BAP,
1599 HERMES_RID_CNFAUTHENTICATION,
1604 master_wep_flag = 0;
1606 if (priv->iw_mode == IW_MODE_MONITOR)
1607 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1609 /* Master WEP setting : on/off */
1610 err = hermes_write_wordrec(hw, USER_BAP,
1611 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1622 static int __orinoco_program_rids(struct net_device *dev)
1624 struct orinoco_private *priv = netdev_priv(dev);
1625 hermes_t *hw = &priv->hw;
1627 struct hermes_idstring idbuf;
1629 /* Set the MAC address */
1630 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1631 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1633 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1638 /* Set up the link mode */
1639 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1642 printk(KERN_ERR "%s: Error %d setting port type\n",
1646 /* Set the channel/frequency */
1647 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1648 err = hermes_write_wordrec(hw, USER_BAP,
1649 HERMES_RID_CNFOWNCHANNEL,
1652 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1653 dev->name, err, priv->channel);
1658 if (priv->has_ibss) {
1661 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1662 printk(KERN_WARNING "%s: This firmware requires an "
1663 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1664 /* With wvlan_cs, in this case, we would crash.
1665 * hopefully, this driver will behave better...
1669 createibss = priv->createibss;
1672 err = hermes_write_wordrec(hw, USER_BAP,
1673 HERMES_RID_CNFCREATEIBSS,
1676 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1682 /* Set the desired BSSID */
1683 err = __orinoco_hw_set_wap(priv);
1685 printk(KERN_ERR "%s: Error %d setting AP address\n",
1689 /* Set the desired ESSID */
1690 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1691 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1692 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1693 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1694 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1697 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1701 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1702 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1705 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1710 /* Set the station name */
1711 idbuf.len = cpu_to_le16(strlen(priv->nick));
1712 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1713 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1714 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1717 printk(KERN_ERR "%s: Error %d setting nickname\n",
1722 /* Set AP density */
1723 if (priv->has_sensitivity) {
1724 err = hermes_write_wordrec(hw, USER_BAP,
1725 HERMES_RID_CNFSYSTEMSCALE,
1728 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1729 "Disabling sensitivity control\n",
1732 priv->has_sensitivity = 0;
1736 /* Set RTS threshold */
1737 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1740 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1745 /* Set fragmentation threshold or MWO robustness */
1747 err = hermes_write_wordrec(hw, USER_BAP,
1748 HERMES_RID_CNFMWOROBUST_AGERE,
1751 err = hermes_write_wordrec(hw, USER_BAP,
1752 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1755 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1761 err = __orinoco_hw_set_bitrate(priv);
1763 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1768 /* Set power management */
1770 err = hermes_write_wordrec(hw, USER_BAP,
1771 HERMES_RID_CNFPMENABLED,
1774 printk(KERN_ERR "%s: Error %d setting up PM\n",
1779 err = hermes_write_wordrec(hw, USER_BAP,
1780 HERMES_RID_CNFMULTICASTRECEIVE,
1783 printk(KERN_ERR "%s: Error %d setting up PM\n",
1787 err = hermes_write_wordrec(hw, USER_BAP,
1788 HERMES_RID_CNFMAXSLEEPDURATION,
1791 printk(KERN_ERR "%s: Error %d setting up PM\n",
1795 err = hermes_write_wordrec(hw, USER_BAP,
1796 HERMES_RID_CNFPMHOLDOVERDURATION,
1799 printk(KERN_ERR "%s: Error %d setting up PM\n",
1805 /* Set preamble - only for Symbol so far... */
1806 if (priv->has_preamble) {
1807 err = hermes_write_wordrec(hw, USER_BAP,
1808 HERMES_RID_CNFPREAMBLE_SYMBOL,
1811 printk(KERN_ERR "%s: Error %d setting preamble\n",
1817 /* Set up encryption */
1818 if (priv->has_wep) {
1819 err = __orinoco_hw_setup_wep(priv);
1821 printk(KERN_ERR "%s: Error %d activating WEP\n",
1827 if (priv->iw_mode == IW_MODE_MONITOR) {
1828 /* Enable monitor mode */
1829 dev->type = ARPHRD_IEEE80211;
1830 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1831 HERMES_TEST_MONITOR, 0, NULL);
1833 /* Disable monitor mode */
1834 dev->type = ARPHRD_ETHER;
1835 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1836 HERMES_TEST_STOP, 0, NULL);
1841 /* Set promiscuity / multicast*/
1842 priv->promiscuous = 0;
1844 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1849 /* FIXME: return int? */
1851 __orinoco_set_multicast_list(struct net_device *dev)
1853 struct orinoco_private *priv = netdev_priv(dev);
1854 hermes_t *hw = &priv->hw;
1856 int promisc, mc_count;
1858 /* The Hermes doesn't seem to have an allmulti mode, so we go
1859 * into promiscuous mode and let the upper levels deal. */
1860 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1861 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1866 mc_count = dev->mc_count;
1869 if (promisc != priv->promiscuous) {
1870 err = hermes_write_wordrec(hw, USER_BAP,
1871 HERMES_RID_CNFPROMISCUOUSMODE,
1874 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1877 priv->promiscuous = promisc;
1880 if (! promisc && (mc_count || priv->mc_count) ) {
1881 struct dev_mc_list *p = dev->mc_list;
1882 struct hermes_multicast mclist;
1885 for (i = 0; i < mc_count; i++) {
1886 /* paranoia: is list shorter than mc_count? */
1888 /* paranoia: bad address size in list? */
1889 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1891 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1896 printk(KERN_WARNING "%s: Multicast list is "
1897 "longer than mc_count\n", dev->name);
1899 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1900 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1903 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1906 priv->mc_count = mc_count;
1909 /* Since we can set the promiscuous flag when it wasn't asked
1910 for, make sure the net_device knows about it. */
1911 if (priv->promiscuous)
1912 dev->flags |= IFF_PROMISC;
1914 dev->flags &= ~IFF_PROMISC;
1917 /* This must be called from user context, without locks held - use
1918 * schedule_work() */
1919 static void orinoco_reset(struct net_device *dev)
1921 struct orinoco_private *priv = netdev_priv(dev);
1922 struct hermes *hw = &priv->hw;
1924 unsigned long flags;
1926 if (orinoco_lock(priv, &flags) != 0)
1927 /* When the hardware becomes available again, whatever
1928 * detects that is responsible for re-initializing
1929 * it. So no need for anything further */
1932 netif_stop_queue(dev);
1934 /* Shut off interrupts. Depending on what state the hardware
1935 * is in, this might not work, but we'll try anyway */
1936 hermes_set_irqmask(hw, 0);
1937 hermes_write_regn(hw, EVACK, 0xffff);
1939 priv->hw_unavailable++;
1940 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1941 netif_carrier_off(dev);
1943 orinoco_unlock(priv, &flags);
1945 /* Scanning support: Cleanup of driver struct */
1946 kfree(priv->scan_result);
1947 priv->scan_result = NULL;
1948 priv->scan_inprogress = 0;
1950 if (priv->hard_reset) {
1951 err = (*priv->hard_reset)(priv);
1953 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1954 "performing hard reset\n", dev->name, err);
1959 err = orinoco_reinit_firmware(dev);
1961 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1966 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1968 priv->hw_unavailable--;
1970 /* priv->open or priv->hw_unavailable might have changed while
1971 * we dropped the lock */
1972 if (priv->open && (! priv->hw_unavailable)) {
1973 err = __orinoco_up(dev);
1975 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1978 dev->trans_start = jiffies;
1981 spin_unlock_irq(&priv->lock);
1985 hermes_set_irqmask(hw, 0);
1986 netif_device_detach(dev);
1987 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1990 /********************************************************************/
1991 /* Interrupt handler */
1992 /********************************************************************/
1994 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1996 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1999 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2001 /* This seems to happen a fair bit under load, but ignoring it
2002 seems to work fine...*/
2003 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2007 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2009 struct net_device *dev = (struct net_device *)dev_id;
2010 struct orinoco_private *priv = netdev_priv(dev);
2011 hermes_t *hw = &priv->hw;
2012 int count = MAX_IRQLOOPS_PER_IRQ;
2014 /* These are used to detect a runaway interrupt situation */
2015 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2016 * we panic and shut down the hardware */
2017 static int last_irq_jiffy = 0; /* jiffies value the last time
2019 static int loops_this_jiffy = 0;
2020 unsigned long flags;
2022 if (orinoco_lock(priv, &flags) != 0) {
2023 /* If hw is unavailable - we don't know if the irq was
2028 evstat = hermes_read_regn(hw, EVSTAT);
2029 events = evstat & hw->inten;
2031 orinoco_unlock(priv, &flags);
2035 if (jiffies != last_irq_jiffy)
2036 loops_this_jiffy = 0;
2037 last_irq_jiffy = jiffies;
2039 while (events && count--) {
2040 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2041 printk(KERN_WARNING "%s: IRQ handler is looping too "
2042 "much! Resetting.\n", dev->name);
2043 /* Disable interrupts for now */
2044 hermes_set_irqmask(hw, 0);
2045 schedule_work(&priv->reset_work);
2049 /* Check the card hasn't been removed */
2050 if (! hermes_present(hw)) {
2051 DEBUG(0, "orinoco_interrupt(): card removed\n");
2055 if (events & HERMES_EV_TICK)
2056 __orinoco_ev_tick(dev, hw);
2057 if (events & HERMES_EV_WTERR)
2058 __orinoco_ev_wterr(dev, hw);
2059 if (events & HERMES_EV_INFDROP)
2060 __orinoco_ev_infdrop(dev, hw);
2061 if (events & HERMES_EV_INFO)
2062 __orinoco_ev_info(dev, hw);
2063 if (events & HERMES_EV_RX)
2064 __orinoco_ev_rx(dev, hw);
2065 if (events & HERMES_EV_TXEXC)
2066 __orinoco_ev_txexc(dev, hw);
2067 if (events & HERMES_EV_TX)
2068 __orinoco_ev_tx(dev, hw);
2069 if (events & HERMES_EV_ALLOC)
2070 __orinoco_ev_alloc(dev, hw);
2072 hermes_write_regn(hw, EVACK, evstat);
2074 evstat = hermes_read_regn(hw, EVSTAT);
2075 events = evstat & hw->inten;
2078 orinoco_unlock(priv, &flags);
2082 /********************************************************************/
2083 /* Initialization */
2084 /********************************************************************/
2087 u16 id, variant, major, minor;
2088 } __attribute__ ((packed));
2090 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2092 if (nic_id->id < 0x8000)
2093 return FIRMWARE_TYPE_AGERE;
2094 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2095 return FIRMWARE_TYPE_SYMBOL;
2097 return FIRMWARE_TYPE_INTERSIL;
2100 /* Set priv->firmware type, determine firmware properties */
2101 static int determine_firmware(struct net_device *dev)
2103 struct orinoco_private *priv = netdev_priv(dev);
2104 hermes_t *hw = &priv->hw;
2106 struct comp_id nic_id, sta_id;
2107 unsigned int firmver;
2108 char tmp[SYMBOL_MAX_VER_LEN+1];
2110 /* Get the hardware version */
2111 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2113 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2118 le16_to_cpus(&nic_id.id);
2119 le16_to_cpus(&nic_id.variant);
2120 le16_to_cpus(&nic_id.major);
2121 le16_to_cpus(&nic_id.minor);
2122 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2123 dev->name, nic_id.id, nic_id.variant,
2124 nic_id.major, nic_id.minor);
2126 priv->firmware_type = determine_firmware_type(&nic_id);
2128 /* Get the firmware version */
2129 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2131 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2136 le16_to_cpus(&sta_id.id);
2137 le16_to_cpus(&sta_id.variant);
2138 le16_to_cpus(&sta_id.major);
2139 le16_to_cpus(&sta_id.minor);
2140 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2141 dev->name, sta_id.id, sta_id.variant,
2142 sta_id.major, sta_id.minor);
2144 switch (sta_id.id) {
2146 printk(KERN_ERR "%s: Primary firmware is active\n",
2150 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2153 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2154 case 0x21: /* Symbol Spectrum24 Trilogy */
2157 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2162 /* Default capabilities */
2163 priv->has_sensitivity = 1;
2165 priv->has_preamble = 0;
2166 priv->has_port3 = 1;
2169 priv->has_big_wep = 0;
2171 /* Determine capabilities from the firmware version */
2172 switch (priv->firmware_type) {
2173 case FIRMWARE_TYPE_AGERE:
2174 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2175 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2176 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2177 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2179 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2181 priv->has_ibss = (firmver >= 0x60006);
2182 priv->has_wep = (firmver >= 0x40020);
2183 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2184 Gold cards from the others? */
2185 priv->has_mwo = (firmver >= 0x60000);
2186 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2187 priv->ibss_port = 1;
2188 priv->has_hostscan = (firmver >= 0x8000a);
2189 priv->broken_monitor = (firmver >= 0x80000);
2191 /* Tested with Agere firmware :
2192 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2193 * Tested CableTron firmware : 4.32 => Anton */
2195 case FIRMWARE_TYPE_SYMBOL:
2196 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2197 /* Intel MAC : 00:02:B3:* */
2198 /* 3Com MAC : 00:50:DA:* */
2199 memset(tmp, 0, sizeof(tmp));
2200 /* Get the Symbol firmware version */
2201 err = hermes_read_ltv(hw, USER_BAP,
2202 HERMES_RID_SECONDARYVERSION_SYMBOL,
2203 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2206 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2211 /* The firmware revision is a string, the format is
2212 * something like : "V2.20-01".
2213 * Quick and dirty parsing... - Jean II
2215 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2216 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2219 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2222 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2225 priv->has_ibss = (firmver >= 0x20000);
2226 priv->has_wep = (firmver >= 0x15012);
2227 priv->has_big_wep = (firmver >= 0x20000);
2228 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2229 (firmver >= 0x29000 && firmver < 0x30000) ||
2231 priv->has_preamble = (firmver >= 0x20000);
2232 priv->ibss_port = 4;
2233 priv->broken_disableport = (firmver == 0x25013) ||
2234 (firmver >= 0x30000 && firmver <= 0x31000);
2235 priv->has_hostscan = (firmver >= 0x31001) ||
2236 (firmver >= 0x29057 && firmver < 0x30000);
2237 /* Tested with Intel firmware : 0x20015 => Jean II */
2238 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2240 case FIRMWARE_TYPE_INTERSIL:
2241 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2242 * Samsung, Compaq 100/200 and Proxim are slightly
2243 * different and less well tested */
2244 /* D-Link MAC : 00:40:05:* */
2245 /* Addtron MAC : 00:90:D1:* */
2246 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2247 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2250 firmver = ((unsigned long)sta_id.major << 16) |
2251 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2253 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2254 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2255 priv->has_pm = (firmver >= 0x000700);
2256 priv->has_hostscan = (firmver >= 0x010301);
2258 if (firmver >= 0x000800)
2259 priv->ibss_port = 0;
2261 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2262 "than v0.8.x - several features not supported\n",
2264 priv->ibss_port = 1;
2268 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2274 static int orinoco_init(struct net_device *dev)
2276 struct orinoco_private *priv = netdev_priv(dev);
2277 hermes_t *hw = &priv->hw;
2279 struct hermes_idstring nickbuf;
2283 TRACE_ENTER(dev->name);
2285 /* No need to lock, the hw_unavailable flag is already set in
2286 * alloc_orinocodev() */
2287 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2289 /* Initialize the firmware */
2290 err = orinoco_reinit_firmware(dev);
2292 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2297 err = determine_firmware(dev);
2299 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2304 if (priv->has_port3)
2305 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2307 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2309 if (priv->has_wep) {
2310 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2311 if (priv->has_big_wep)
2312 printk("104-bit key\n");
2314 printk("40-bit key\n");
2317 /* Get the MAC address */
2318 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2319 ETH_ALEN, NULL, dev->dev_addr);
2321 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2326 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2327 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2328 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2331 /* Get the station name */
2332 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2333 sizeof(nickbuf), &reclen, &nickbuf);
2335 printk(KERN_ERR "%s: failed to read station name\n",
2340 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2342 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2343 memcpy(priv->nick, &nickbuf.val, len);
2344 priv->nick[len] = '\0';
2346 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2348 /* Get allowed channels */
2349 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2350 &priv->channel_mask);
2352 printk(KERN_ERR "%s: failed to read channel list!\n",
2357 /* Get initial AP density */
2358 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2360 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2361 priv->has_sensitivity = 0;
2364 /* Get initial RTS threshold */
2365 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2368 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2373 /* Get initial fragmentation settings */
2375 err = hermes_read_wordrec(hw, USER_BAP,
2376 HERMES_RID_CNFMWOROBUST_AGERE,
2379 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2380 &priv->frag_thresh);
2382 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2387 /* Power management setup */
2391 err = hermes_read_wordrec(hw, USER_BAP,
2392 HERMES_RID_CNFMAXSLEEPDURATION,
2395 printk(KERN_ERR "%s: failed to read power management period!\n",
2399 err = hermes_read_wordrec(hw, USER_BAP,
2400 HERMES_RID_CNFPMHOLDOVERDURATION,
2403 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2409 /* Preamble setup */
2410 if (priv->has_preamble) {
2411 err = hermes_read_wordrec(hw, USER_BAP,
2412 HERMES_RID_CNFPREAMBLE_SYMBOL,
2418 /* Set up the default configuration */
2419 priv->iw_mode = IW_MODE_INFRA;
2420 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2421 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2422 set_port_type(priv);
2423 priv->channel = 0; /* use firmware default */
2425 priv->promiscuous = 0;
2429 /* Make the hardware available, as long as it hasn't been
2430 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2431 spin_lock_irq(&priv->lock);
2432 priv->hw_unavailable--;
2433 spin_unlock_irq(&priv->lock);
2435 printk(KERN_DEBUG "%s: ready\n", dev->name);
2438 TRACE_EXIT(dev->name);
2442 struct net_device *alloc_orinocodev(int sizeof_card,
2443 int (*hard_reset)(struct orinoco_private *))
2445 struct net_device *dev;
2446 struct orinoco_private *priv;
2448 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2451 priv = netdev_priv(dev);
2454 priv->card = (void *)((unsigned long)priv
2455 + sizeof(struct orinoco_private));
2459 /* Setup / override net_device fields */
2460 dev->init = orinoco_init;
2461 dev->hard_start_xmit = orinoco_xmit;
2462 dev->tx_timeout = orinoco_tx_timeout;
2463 dev->watchdog_timeo = HZ; /* 1 second timeout */
2464 dev->get_stats = orinoco_get_stats;
2465 dev->ethtool_ops = &orinoco_ethtool_ops;
2466 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2467 dev->change_mtu = orinoco_change_mtu;
2468 dev->set_multicast_list = orinoco_set_multicast_list;
2469 /* we use the default eth_mac_addr for setting the MAC addr */
2471 /* Set up default callbacks */
2472 dev->open = orinoco_open;
2473 dev->stop = orinoco_stop;
2474 priv->hard_reset = hard_reset;
2476 spin_lock_init(&priv->lock);
2478 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2479 * before anything else touches the
2481 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2482 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2483 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2485 netif_carrier_off(dev);
2486 priv->last_linkstatus = 0xffff;
2492 void free_orinocodev(struct net_device *dev)
2494 struct orinoco_private *priv = netdev_priv(dev);
2496 kfree(priv->scan_result);
2500 /********************************************************************/
2501 /* Wireless extensions */
2502 /********************************************************************/
2504 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2505 char buf[IW_ESSID_MAX_SIZE+1])
2507 hermes_t *hw = &priv->hw;
2509 struct hermes_idstring essidbuf;
2510 char *p = (char *)(&essidbuf.val);
2512 unsigned long flags;
2514 if (orinoco_lock(priv, &flags) != 0)
2517 if (strlen(priv->desired_essid) > 0) {
2518 /* We read the desired SSID from the hardware rather
2519 than from priv->desired_essid, just in case the
2520 firmware is allowed to change it on us. I'm not
2522 /* My guess is that the OWNSSID should always be whatever
2523 * we set to the card, whereas CURRENT_SSID is the one that
2524 * may change... - Jean II */
2529 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2530 HERMES_RID_CNFDESIREDSSID;
2532 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2539 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2540 sizeof(essidbuf), NULL, &essidbuf);
2545 len = le16_to_cpu(essidbuf.len);
2546 BUG_ON(len > IW_ESSID_MAX_SIZE);
2548 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2549 memcpy(buf, p, len);
2553 orinoco_unlock(priv, &flags);
2558 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2561 hermes_t *hw = &priv->hw;
2565 unsigned long flags;
2567 if (orinoco_lock(priv, &flags) != 0)
2570 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2574 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2580 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2581 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2582 priv->ndev->name, channel);
2587 freq = channel_frequency[channel-1] * 100000;
2590 orinoco_unlock(priv, &flags);
2594 return err ? err : freq;
2597 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2598 int *numrates, s32 *rates, int max)
2600 hermes_t *hw = &priv->hw;
2601 struct hermes_idstring list;
2602 unsigned char *p = (unsigned char *)&list.val;
2606 unsigned long flags;
2608 if (orinoco_lock(priv, &flags) != 0)
2611 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2612 sizeof(list), NULL, &list);
2613 orinoco_unlock(priv, &flags);
2618 num = le16_to_cpu(list.len);
2620 num = min(num, max);
2622 for (i = 0; i < num; i++) {
2623 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2629 static int orinoco_ioctl_getname(struct net_device *dev,
2630 struct iw_request_info *info,
2634 struct orinoco_private *priv = netdev_priv(dev);
2638 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2640 if (!err && (numrates > 2))
2641 strcpy(name, "IEEE 802.11b");
2643 strcpy(name, "IEEE 802.11-DS");
2648 static int orinoco_ioctl_setwap(struct net_device *dev,
2649 struct iw_request_info *info,
2650 struct sockaddr *ap_addr,
2653 struct orinoco_private *priv = netdev_priv(dev);
2654 int err = -EINPROGRESS; /* Call commit handler */
2655 unsigned long flags;
2656 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2657 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2659 if (orinoco_lock(priv, &flags) != 0)
2662 /* Enable automatic roaming - no sanity checks are needed */
2663 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2664 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2665 priv->bssid_fixed = 0;
2666 memset(priv->desired_bssid, 0, ETH_ALEN);
2668 /* "off" means keep existing connection */
2669 if (ap_addr->sa_data[0] == 0) {
2670 __orinoco_hw_set_wap(priv);
2676 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2677 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2678 "support manual roaming\n",
2684 if (priv->iw_mode != IW_MODE_INFRA) {
2685 printk(KERN_WARNING "%s: Manual roaming supported only in "
2686 "managed mode\n", dev->name);
2691 /* Intersil firmware hangs without Desired ESSID */
2692 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2693 strlen(priv->desired_essid) == 0) {
2694 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2695 "manual roaming\n", dev->name);
2700 /* Finally, enable manual roaming */
2701 priv->bssid_fixed = 1;
2702 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2705 orinoco_unlock(priv, &flags);
2709 static int orinoco_ioctl_getwap(struct net_device *dev,
2710 struct iw_request_info *info,
2711 struct sockaddr *ap_addr,
2714 struct orinoco_private *priv = netdev_priv(dev);
2716 hermes_t *hw = &priv->hw;
2718 unsigned long flags;
2720 if (orinoco_lock(priv, &flags) != 0)
2723 ap_addr->sa_family = ARPHRD_ETHER;
2724 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2725 ETH_ALEN, NULL, ap_addr->sa_data);
2727 orinoco_unlock(priv, &flags);
2732 static int orinoco_ioctl_setmode(struct net_device *dev,
2733 struct iw_request_info *info,
2737 struct orinoco_private *priv = netdev_priv(dev);
2738 int err = -EINPROGRESS; /* Call commit handler */
2739 unsigned long flags;
2741 if (priv->iw_mode == *mode)
2744 if (orinoco_lock(priv, &flags) != 0)
2749 if (!priv->has_ibss && !priv->has_port3)
2756 case IW_MODE_MONITOR:
2757 if (priv->broken_monitor && !force_monitor) {
2758 printk(KERN_WARNING "%s: Monitor mode support is "
2759 "buggy in this firmware, not enabling\n",
2770 if (err == -EINPROGRESS) {
2771 priv->iw_mode = *mode;
2772 set_port_type(priv);
2775 orinoco_unlock(priv, &flags);
2780 static int orinoco_ioctl_getmode(struct net_device *dev,
2781 struct iw_request_info *info,
2785 struct orinoco_private *priv = netdev_priv(dev);
2787 *mode = priv->iw_mode;
2791 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2792 struct iw_request_info *info,
2793 struct iw_point *rrq,
2796 struct orinoco_private *priv = netdev_priv(dev);
2798 struct iw_range *range = (struct iw_range *) extra;
2802 TRACE_ENTER(dev->name);
2804 rrq->length = sizeof(struct iw_range);
2805 memset(range, 0, sizeof(struct iw_range));
2807 range->we_version_compiled = WIRELESS_EXT;
2808 range->we_version_source = 14;
2810 /* Set available channels/frequencies */
2811 range->num_channels = NUM_CHANNELS;
2813 for (i = 0; i < NUM_CHANNELS; i++) {
2814 if (priv->channel_mask & (1 << i)) {
2815 range->freq[k].i = i + 1;
2816 range->freq[k].m = channel_frequency[i] * 100000;
2817 range->freq[k].e = 1;
2821 if (k >= IW_MAX_FREQUENCIES)
2824 range->num_frequency = k;
2825 range->sensitivity = 3;
2827 if (priv->has_wep) {
2828 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2829 range->encoding_size[0] = SMALL_KEY_SIZE;
2830 range->num_encoding_sizes = 1;
2832 if (priv->has_big_wep) {
2833 range->encoding_size[1] = LARGE_KEY_SIZE;
2834 range->num_encoding_sizes = 2;
2838 if ((priv->iw_mode == IW_MODE_ADHOC) && (priv->spy_number == 0)){
2839 /* Quality stats meaningless in ad-hoc mode */
2841 range->max_qual.qual = 0x8b - 0x2f;
2842 range->max_qual.level = 0x2f - 0x95 - 1;
2843 range->max_qual.noise = 0x2f - 0x95 - 1;
2844 /* Need to get better values */
2845 range->avg_qual.qual = 0x24;
2846 range->avg_qual.level = 0xC2;
2847 range->avg_qual.noise = 0x9E;
2850 err = orinoco_hw_get_bitratelist(priv, &numrates,
2851 range->bitrate, IW_MAX_BITRATES);
2854 range->num_bitrates = numrates;
2856 /* Set an indication of the max TCP throughput in bit/s that we can
2857 * expect using this interface. May be use for QoS stuff...
2860 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2862 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2865 range->max_rts = 2347;
2866 range->min_frag = 256;
2867 range->max_frag = 2346;
2870 range->max_pmp = 65535000;
2872 range->max_pmt = 65535 * 1000; /* ??? */
2873 range->pmp_flags = IW_POWER_PERIOD;
2874 range->pmt_flags = IW_POWER_TIMEOUT;
2875 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2877 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2878 range->retry_flags = IW_RETRY_LIMIT;
2879 range->r_time_flags = IW_RETRY_LIFETIME;
2880 range->min_retry = 0;
2881 range->max_retry = 65535; /* ??? */
2882 range->min_r_time = 0;
2883 range->max_r_time = 65535 * 1000; /* ??? */
2885 TRACE_EXIT(dev->name);
2890 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2891 struct iw_request_info *info,
2892 struct iw_point *erq,
2895 struct orinoco_private *priv = netdev_priv(dev);
2896 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2897 int setindex = priv->tx_key;
2898 int enable = priv->wep_on;
2899 int restricted = priv->wep_restrict;
2901 int err = -EINPROGRESS; /* Call commit handler */
2902 unsigned long flags;
2904 if (! priv->has_wep)
2908 /* We actually have a key to set - check its length */
2909 if (erq->length > LARGE_KEY_SIZE)
2912 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2916 if (orinoco_lock(priv, &flags) != 0)
2920 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2921 index = priv->tx_key;
2923 /* Adjust key length to a supported value */
2924 if (erq->length > SMALL_KEY_SIZE) {
2925 xlen = LARGE_KEY_SIZE;
2926 } else if (erq->length > 0) {
2927 xlen = SMALL_KEY_SIZE;
2931 /* Switch on WEP if off */
2932 if ((!enable) && (xlen > 0)) {
2937 /* Important note : if the user do "iwconfig eth0 enc off",
2938 * we will arrive there with an index of -1. This is valid
2939 * but need to be taken care off... Jean II */
2940 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2941 if((index != -1) || (erq->flags == 0)) {
2946 /* Set the index : Check that the key is valid */
2947 if(priv->keys[index].len == 0) {
2955 if (erq->flags & IW_ENCODE_DISABLED)
2957 if (erq->flags & IW_ENCODE_OPEN)
2959 if (erq->flags & IW_ENCODE_RESTRICTED)
2963 priv->keys[index].len = cpu_to_le16(xlen);
2964 memset(priv->keys[index].data, 0,
2965 sizeof(priv->keys[index].data));
2966 memcpy(priv->keys[index].data, keybuf, erq->length);
2968 priv->tx_key = setindex;
2970 /* Try fast key change if connected and only keys are changed */
2971 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2972 netif_carrier_ok(dev)) {
2973 err = __orinoco_hw_setup_wepkeys(priv);
2974 /* No need to commit if successful */
2978 priv->wep_on = enable;
2979 priv->wep_restrict = restricted;
2982 orinoco_unlock(priv, &flags);
2987 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2988 struct iw_request_info *info,
2989 struct iw_point *erq,
2992 struct orinoco_private *priv = netdev_priv(dev);
2993 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2995 unsigned long flags;
2997 if (! priv->has_wep)
3000 if (orinoco_lock(priv, &flags) != 0)
3003 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3004 index = priv->tx_key;
3008 erq->flags |= IW_ENCODE_DISABLED;
3009 erq->flags |= index + 1;
3011 if (priv->wep_restrict)
3012 erq->flags |= IW_ENCODE_RESTRICTED;
3014 erq->flags |= IW_ENCODE_OPEN;
3016 xlen = le16_to_cpu(priv->keys[index].len);
3020 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3022 orinoco_unlock(priv, &flags);
3026 static int orinoco_ioctl_setessid(struct net_device *dev,
3027 struct iw_request_info *info,
3028 struct iw_point *erq,
3031 struct orinoco_private *priv = netdev_priv(dev);
3032 unsigned long flags;
3034 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3035 * anyway... - Jean II */
3037 /* Hum... Should not use Wireless Extension constant (may change),
3038 * should use our own... - Jean II */
3039 if (erq->length > IW_ESSID_MAX_SIZE)
3042 if (orinoco_lock(priv, &flags) != 0)
3045 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3046 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3048 /* If not ANY, get the new ESSID */
3050 memcpy(priv->desired_essid, essidbuf, erq->length);
3053 orinoco_unlock(priv, &flags);
3055 return -EINPROGRESS; /* Call commit handler */
3058 static int orinoco_ioctl_getessid(struct net_device *dev,
3059 struct iw_request_info *info,
3060 struct iw_point *erq,
3063 struct orinoco_private *priv = netdev_priv(dev);
3066 unsigned long flags;
3068 TRACE_ENTER(dev->name);
3070 if (netif_running(dev)) {
3071 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3075 if (orinoco_lock(priv, &flags) != 0)
3077 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3078 orinoco_unlock(priv, &flags);
3082 erq->length = strlen(essidbuf) + 1;
3084 TRACE_EXIT(dev->name);
3089 static int orinoco_ioctl_setnick(struct net_device *dev,
3090 struct iw_request_info *info,
3091 struct iw_point *nrq,
3094 struct orinoco_private *priv = netdev_priv(dev);
3095 unsigned long flags;
3097 if (nrq->length > IW_ESSID_MAX_SIZE)
3100 if (orinoco_lock(priv, &flags) != 0)
3103 memset(priv->nick, 0, sizeof(priv->nick));
3104 memcpy(priv->nick, nickbuf, nrq->length);
3106 orinoco_unlock(priv, &flags);
3108 return -EINPROGRESS; /* Call commit handler */
3111 static int orinoco_ioctl_getnick(struct net_device *dev,
3112 struct iw_request_info *info,
3113 struct iw_point *nrq,
3116 struct orinoco_private *priv = netdev_priv(dev);
3117 unsigned long flags;
3119 if (orinoco_lock(priv, &flags) != 0)
3122 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3123 orinoco_unlock(priv, &flags);
3125 nrq->length = strlen(nickbuf)+1;
3130 static int orinoco_ioctl_setfreq(struct net_device *dev,
3131 struct iw_request_info *info,
3132 struct iw_freq *frq,
3135 struct orinoco_private *priv = netdev_priv(dev);
3137 unsigned long flags;
3138 int err = -EINPROGRESS; /* Call commit handler */
3140 /* In infrastructure mode the AP sets the channel */
3141 if (priv->iw_mode == IW_MODE_INFRA)
3144 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3145 /* Setting by channel number */
3148 /* Setting by frequency - search the table */
3152 for (i = 0; i < (6 - frq->e); i++)
3155 for (i = 0; i < NUM_CHANNELS; i++)
3156 if (frq->m == (channel_frequency[i] * mult))
3160 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3161 ! (priv->channel_mask & (1 << (chan-1)) ) )
3164 if (orinoco_lock(priv, &flags) != 0)
3167 priv->channel = chan;
3168 if (priv->iw_mode == IW_MODE_MONITOR) {
3169 /* Fast channel change - no commit if successful */
3170 hermes_t *hw = &priv->hw;
3171 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3172 HERMES_TEST_SET_CHANNEL,
3175 orinoco_unlock(priv, &flags);
3180 static int orinoco_ioctl_getfreq(struct net_device *dev,
3181 struct iw_request_info *info,
3182 struct iw_freq *frq,
3185 struct orinoco_private *priv = netdev_priv(dev);
3188 /* Locking done in there */
3189 tmp = orinoco_hw_get_freq(priv);
3200 static int orinoco_ioctl_getsens(struct net_device *dev,
3201 struct iw_request_info *info,
3202 struct iw_param *srq,
3205 struct orinoco_private *priv = netdev_priv(dev);
3206 hermes_t *hw = &priv->hw;
3209 unsigned long flags;
3211 if (!priv->has_sensitivity)
3214 if (orinoco_lock(priv, &flags) != 0)
3216 err = hermes_read_wordrec(hw, USER_BAP,
3217 HERMES_RID_CNFSYSTEMSCALE, &val);
3218 orinoco_unlock(priv, &flags);
3224 srq->fixed = 0; /* auto */
3229 static int orinoco_ioctl_setsens(struct net_device *dev,
3230 struct iw_request_info *info,
3231 struct iw_param *srq,
3234 struct orinoco_private *priv = netdev_priv(dev);
3235 int val = srq->value;
3236 unsigned long flags;
3238 if (!priv->has_sensitivity)
3241 if ((val < 1) || (val > 3))
3244 if (orinoco_lock(priv, &flags) != 0)
3246 priv->ap_density = val;
3247 orinoco_unlock(priv, &flags);
3249 return -EINPROGRESS; /* Call commit handler */
3252 static int orinoco_ioctl_setrts(struct net_device *dev,
3253 struct iw_request_info *info,
3254 struct iw_param *rrq,
3257 struct orinoco_private *priv = netdev_priv(dev);
3258 int val = rrq->value;
3259 unsigned long flags;
3264 if ( (val < 0) || (val > 2347) )
3267 if (orinoco_lock(priv, &flags) != 0)
3270 priv->rts_thresh = val;
3271 orinoco_unlock(priv, &flags);
3273 return -EINPROGRESS; /* Call commit handler */
3276 static int orinoco_ioctl_getrts(struct net_device *dev,
3277 struct iw_request_info *info,
3278 struct iw_param *rrq,
3281 struct orinoco_private *priv = netdev_priv(dev);
3283 rrq->value = priv->rts_thresh;
3284 rrq->disabled = (rrq->value == 2347);
3290 static int orinoco_ioctl_setfrag(struct net_device *dev,
3291 struct iw_request_info *info,
3292 struct iw_param *frq,
3295 struct orinoco_private *priv = netdev_priv(dev);
3296 int err = -EINPROGRESS; /* Call commit handler */
3297 unsigned long flags;
3299 if (orinoco_lock(priv, &flags) != 0)
3302 if (priv->has_mwo) {
3304 priv->mwo_robust = 0;
3307 printk(KERN_WARNING "%s: Fixed fragmentation is "
3308 "not supported on this firmware. "
3309 "Using MWO robust instead.\n", dev->name);
3310 priv->mwo_robust = 1;
3314 priv->frag_thresh = 2346;
3316 if ( (frq->value < 256) || (frq->value > 2346) )
3319 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3323 orinoco_unlock(priv, &flags);
3328 static int orinoco_ioctl_getfrag(struct net_device *dev,
3329 struct iw_request_info *info,
3330 struct iw_param *frq,
3333 struct orinoco_private *priv = netdev_priv(dev);
3334 hermes_t *hw = &priv->hw;
3337 unsigned long flags;
3339 if (orinoco_lock(priv, &flags) != 0)
3342 if (priv->has_mwo) {
3343 err = hermes_read_wordrec(hw, USER_BAP,
3344 HERMES_RID_CNFMWOROBUST_AGERE,
3349 frq->value = val ? 2347 : 0;
3350 frq->disabled = ! val;
3353 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3359 frq->disabled = (val >= 2346);
3363 orinoco_unlock(priv, &flags);
3368 static int orinoco_ioctl_setrate(struct net_device *dev,
3369 struct iw_request_info *info,
3370 struct iw_param *rrq,
3373 struct orinoco_private *priv = netdev_priv(dev);
3375 int bitrate; /* 100s of kilobits */
3377 unsigned long flags;
3379 /* As the user space doesn't know our highest rate, it uses -1
3380 * to ask us to set the highest rate. Test it using "iwconfig
3381 * ethX rate auto" - Jean II */
3382 if (rrq->value == -1)
3385 if (rrq->value % 100000)
3387 bitrate = rrq->value / 100000;
3390 if ( (bitrate != 10) && (bitrate != 20) &&
3391 (bitrate != 55) && (bitrate != 110) )
3394 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3395 if ( (bitrate_table[i].bitrate == bitrate) &&
3396 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3404 if (orinoco_lock(priv, &flags) != 0)
3406 priv->bitratemode = ratemode;
3407 orinoco_unlock(priv, &flags);
3409 return -EINPROGRESS;
3412 static int orinoco_ioctl_getrate(struct net_device *dev,
3413 struct iw_request_info *info,
3414 struct iw_param *rrq,
3417 struct orinoco_private *priv = netdev_priv(dev);
3418 hermes_t *hw = &priv->hw;
3423 unsigned long flags;
3425 if (orinoco_lock(priv, &flags) != 0)
3428 ratemode = priv->bitratemode;
3430 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3432 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3433 rrq->fixed = ! bitrate_table[ratemode].automatic;
3436 /* If the interface is running we try to find more about the
3438 if (netif_running(dev)) {
3439 err = hermes_read_wordrec(hw, USER_BAP,
3440 HERMES_RID_CURRENTTXRATE, &val);
3444 switch (priv->firmware_type) {
3445 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3446 /* Note : in Lucent firmware, the return value of
3447 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3448 * and therefore is totally different from the
3449 * encoding of HERMES_RID_CNFTXRATECONTROL.
3450 * Don't forget that 6Mb/s is really 5.5Mb/s */
3452 rrq->value = 5500000;
3454 rrq->value = val * 1000000;
3456 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3457 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3458 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3459 if (bitrate_table[i].intersil_txratectrl == val) {
3463 if (i >= BITRATE_TABLE_SIZE)
3464 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3467 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3475 orinoco_unlock(priv, &flags);
3480 static int orinoco_ioctl_setpower(struct net_device *dev,
3481 struct iw_request_info *info,
3482 struct iw_param *prq,
3485 struct orinoco_private *priv = netdev_priv(dev);
3486 int err = -EINPROGRESS; /* Call commit handler */
3487 unsigned long flags;
3489 if (orinoco_lock(priv, &flags) != 0)
3492 if (prq->disabled) {
3495 switch (prq->flags & IW_POWER_MODE) {
3496 case IW_POWER_UNICAST_R:
3500 case IW_POWER_ALL_R:
3505 /* No flags : but we may have a value - Jean II */
3513 if (prq->flags & IW_POWER_TIMEOUT) {
3515 priv->pm_timeout = prq->value / 1000;
3517 if (prq->flags & IW_POWER_PERIOD) {
3519 priv->pm_period = prq->value / 1000;
3521 /* It's valid to not have a value if we are just toggling
3522 * the flags... Jean II */
3530 orinoco_unlock(priv, &flags);
3535 static int orinoco_ioctl_getpower(struct net_device *dev,
3536 struct iw_request_info *info,
3537 struct iw_param *prq,
3540 struct orinoco_private *priv = netdev_priv(dev);
3541 hermes_t *hw = &priv->hw;
3543 u16 enable, period, timeout, mcast;
3544 unsigned long flags;
3546 if (orinoco_lock(priv, &flags) != 0)
3549 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3553 err = hermes_read_wordrec(hw, USER_BAP,
3554 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3558 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3562 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3566 prq->disabled = !enable;
3567 /* Note : by default, display the period */
3568 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3569 prq->flags = IW_POWER_TIMEOUT;
3570 prq->value = timeout * 1000;
3572 prq->flags = IW_POWER_PERIOD;
3573 prq->value = period * 1000;
3576 prq->flags |= IW_POWER_ALL_R;
3578 prq->flags |= IW_POWER_UNICAST_R;
3581 orinoco_unlock(priv, &flags);
3586 static int orinoco_ioctl_getretry(struct net_device *dev,
3587 struct iw_request_info *info,
3588 struct iw_param *rrq,
3591 struct orinoco_private *priv = netdev_priv(dev);
3592 hermes_t *hw = &priv->hw;
3594 u16 short_limit, long_limit, lifetime;
3595 unsigned long flags;
3597 if (orinoco_lock(priv, &flags) != 0)
3600 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3605 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3610 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3615 rrq->disabled = 0; /* Can't be disabled */
3617 /* Note : by default, display the retry number */
3618 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3619 rrq->flags = IW_RETRY_LIFETIME;
3620 rrq->value = lifetime * 1000; /* ??? */
3622 /* By default, display the min number */
3623 if ((rrq->flags & IW_RETRY_MAX)) {
3624 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3625 rrq->value = long_limit;
3627 rrq->flags = IW_RETRY_LIMIT;
3628 rrq->value = short_limit;
3629 if(short_limit != long_limit)
3630 rrq->flags |= IW_RETRY_MIN;
3635 orinoco_unlock(priv, &flags);
3640 static int orinoco_ioctl_reset(struct net_device *dev,
3641 struct iw_request_info *info,
3645 struct orinoco_private *priv = netdev_priv(dev);
3647 if (! capable(CAP_NET_ADMIN))
3650 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3651 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3653 /* Firmware reset */
3656 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3658 schedule_work(&priv->reset_work);
3664 static int orinoco_ioctl_setibssport(struct net_device *dev,
3665 struct iw_request_info *info,
3670 struct orinoco_private *priv = netdev_priv(dev);
3671 int val = *( (int *) extra );
3672 unsigned long flags;
3674 if (orinoco_lock(priv, &flags) != 0)
3677 priv->ibss_port = val ;
3679 /* Actually update the mode we are using */
3680 set_port_type(priv);
3682 orinoco_unlock(priv, &flags);
3683 return -EINPROGRESS; /* Call commit handler */
3686 static int orinoco_ioctl_getibssport(struct net_device *dev,
3687 struct iw_request_info *info,
3691 struct orinoco_private *priv = netdev_priv(dev);
3692 int *val = (int *) extra;
3694 *val = priv->ibss_port;
3698 static int orinoco_ioctl_setport3(struct net_device *dev,
3699 struct iw_request_info *info,
3703 struct orinoco_private *priv = netdev_priv(dev);
3704 int val = *( (int *) extra );
3706 unsigned long flags;
3708 if (orinoco_lock(priv, &flags) != 0)
3712 case 0: /* Try to do IEEE ad-hoc mode */
3713 if (! priv->has_ibss) {
3717 priv->prefer_port3 = 0;
3721 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3722 if (! priv->has_port3) {
3726 priv->prefer_port3 = 1;
3734 /* Actually update the mode we are using */
3735 set_port_type(priv);
3739 orinoco_unlock(priv, &flags);
3744 static int orinoco_ioctl_getport3(struct net_device *dev,
3745 struct iw_request_info *info,
3749 struct orinoco_private *priv = netdev_priv(dev);
3750 int *val = (int *) extra;
3752 *val = priv->prefer_port3;
3756 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3757 struct iw_request_info *info,
3761 struct orinoco_private *priv = netdev_priv(dev);
3762 unsigned long flags;
3765 if (! priv->has_preamble)
3768 /* 802.11b has recently defined some short preamble.
3769 * Basically, the Phy header has been reduced in size.
3770 * This increase performance, especially at high rates
3771 * (the preamble is transmitted at 1Mb/s), unfortunately
3772 * this give compatibility troubles... - Jean II */
3773 val = *( (int *) extra );
3775 if (orinoco_lock(priv, &flags) != 0)
3783 orinoco_unlock(priv, &flags);
3785 return -EINPROGRESS; /* Call commit handler */
3788 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3789 struct iw_request_info *info,
3793 struct orinoco_private *priv = netdev_priv(dev);
3794 int *val = (int *) extra;
3796 if (! priv->has_preamble)
3799 *val = priv->preamble;
3803 /* ioctl interface to hermes_read_ltv()
3804 * To use with iwpriv, pass the RID as the token argument, e.g.
3805 * iwpriv get_rid [0xfc00]
3806 * At least Wireless Tools 25 is required to use iwpriv.
3807 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3808 static int orinoco_ioctl_getrid(struct net_device *dev,
3809 struct iw_request_info *info,
3810 struct iw_point *data,
3813 struct orinoco_private *priv = netdev_priv(dev);
3814 hermes_t *hw = &priv->hw;
3815 int rid = data->flags;
3818 unsigned long flags;
3820 /* It's a "get" function, but we don't want users to access the
3821 * WEP key and other raw firmware data */
3822 if (! capable(CAP_NET_ADMIN))
3825 if (rid < 0xfc00 || rid > 0xffff)
3828 if (orinoco_lock(priv, &flags) != 0)
3831 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3836 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3840 orinoco_unlock(priv, &flags);
3844 /* Spy is used for link quality/strength measurements in Ad-Hoc mode
3846 static int orinoco_ioctl_setspy(struct net_device *dev,
3847 struct iw_request_info *info,
3848 struct iw_point *srq,
3852 struct orinoco_private *priv = netdev_priv(dev);
3853 struct sockaddr *address = (struct sockaddr *) extra;
3854 int number = srq->length;
3856 unsigned long flags;
3858 /* Make sure nobody mess with the structure while we do */
3859 if (orinoco_lock(priv, &flags) != 0)
3862 /* orinoco_lock() doesn't disable interrupts, so make sure the
3863 * interrupt rx path don't get confused while we copy */
3864 priv->spy_number = 0;
3867 /* Extract the addresses */
3868 for (i = 0; i < number; i++)
3869 memcpy(priv->spy_address[i], address[i].sa_data,
3872 memset(priv->spy_stat, 0,
3873 sizeof(struct iw_quality) * IW_MAX_SPY);
3874 /* Set number of addresses */
3875 priv->spy_number = number;
3878 /* Now, let the others play */
3879 orinoco_unlock(priv, &flags);
3881 /* Do NOT call commit handler */
3885 static int orinoco_ioctl_getspy(struct net_device *dev,
3886 struct iw_request_info *info,
3887 struct iw_point *srq,
3890 struct orinoco_private *priv = netdev_priv(dev);
3891 struct sockaddr *address = (struct sockaddr *) extra;
3894 unsigned long flags;
3896 if (orinoco_lock(priv, &flags) != 0)
3899 number = priv->spy_number;
3900 /* Create address struct */
3901 for (i = 0; i < number; i++) {
3902 memcpy(address[i].sa_data, priv->spy_address[i], ETH_ALEN);
3903 address[i].sa_family = AF_UNIX;
3906 /* Create address struct */
3907 for (i = 0; i < number; i++) {
3908 memcpy(address[i].sa_data, priv->spy_address[i],
3910 address[i].sa_family = AF_UNIX;
3913 /* In theory, we should disable irqs while copying the stats
3914 * because the rx path might update it in the middle...
3915 * Bah, who care ? - Jean II */
3916 memcpy(extra + (sizeof(struct sockaddr) * number),
3917 priv->spy_stat, sizeof(struct iw_quality) * number);
3919 /* Reset updated flags. */
3920 for (i = 0; i < number; i++)
3921 priv->spy_stat[i].updated = 0;
3923 orinoco_unlock(priv, &flags);
3925 srq->length = number;
3930 /* Trigger a scan (look for other cells in the vicinity */
3931 static int orinoco_ioctl_setscan(struct net_device *dev,
3932 struct iw_request_info *info,
3933 struct iw_param *srq,
3936 struct orinoco_private *priv = netdev_priv(dev);
3937 hermes_t *hw = &priv->hw;
3939 unsigned long flags;
3941 /* Note : you may have realised that, as this is a SET operation,
3942 * this is priviledged and therefore a normal user can't
3944 * This is not an error, while the device perform scanning,
3945 * traffic doesn't flow, so it's a perfect DoS...
3948 if (orinoco_lock(priv, &flags) != 0)
3951 /* Scanning with port 0 disabled would fail */
3952 if (!netif_running(dev)) {
3957 /* In monitor mode, the scan results are always empty.
3958 * Probe responses are passed to the driver as received
3959 * frames and could be processed in software. */
3960 if (priv->iw_mode == IW_MODE_MONITOR) {
3965 /* Note : because we don't lock out the irq handler, the way
3966 * we access scan variables in priv is critical.
3967 * o scan_inprogress : not touched by irq handler
3968 * o scan_mode : not touched by irq handler
3969 * o scan_result : irq is strict producer, non-irq is strict
3971 * o scan_len : synchronised with scan_result
3972 * Before modifying anything on those variables, please think hard !
3975 /* If there is still some left-over scan results, get rid of it */
3976 if (priv->scan_result != NULL) {
3977 /* What's likely is that a client did crash or was killed
3978 * between triggering the scan request and reading the
3979 * results, so we need to reset everything.
3980 * Some clients that are too slow may suffer from that...
3982 kfree(priv->scan_result);
3983 priv->scan_result = NULL;
3987 priv->scan_mode = srq->flags;
3989 /* Always trigger scanning, even if it's in progress.
3990 * This way, if the info frame get lost, we will recover somewhat
3991 * gracefully - Jean II */
3993 if (priv->has_hostscan) {
3994 switch (priv->firmware_type) {
3995 case FIRMWARE_TYPE_SYMBOL:
3996 err = hermes_write_wordrec(hw, USER_BAP,
3997 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3998 HERMES_HOSTSCAN_SYMBOL_ONCE |
3999 HERMES_HOSTSCAN_SYMBOL_BCAST);
4001 case FIRMWARE_TYPE_INTERSIL: {
4004 req[0] = cpu_to_le16(0x3fff); /* All channels */
4005 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4006 req[2] = 0; /* Any ESSID */
4007 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4008 HERMES_RID_CNFHOSTSCAN, &req);
4011 case FIRMWARE_TYPE_AGERE:
4012 err = hermes_write_wordrec(hw, USER_BAP,
4013 HERMES_RID_CNFSCANSSID_AGERE,
4018 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4022 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4024 /* One more client */
4026 priv->scan_inprogress = 1;
4029 orinoco_unlock(priv, &flags);
4033 /* Translate scan data returned from the card to a card independant
4034 * format that the Wireless Tools will understand - Jean II
4035 * Return message length or -errno for fatal errors */
4036 static inline int orinoco_translate_scan(struct net_device *dev,
4041 struct orinoco_private *priv = netdev_priv(dev);
4042 int offset; /* In the scan data */
4043 union hermes_scan_info *atom;
4047 struct iw_event iwe; /* Temporary buffer */
4048 char * current_ev = buffer;
4049 char * end_buf = buffer + IW_SCAN_MAX_DATA;
4051 switch (priv->firmware_type) {
4052 case FIRMWARE_TYPE_AGERE:
4053 atom_len = sizeof(struct agere_scan_apinfo);
4056 case FIRMWARE_TYPE_SYMBOL:
4057 /* Lack of documentation necessitates this hack.
4058 * Different firmwares have 68 or 76 byte long atoms.
4059 * We try modulo first. If the length divides by both,
4060 * we check what would be the channel in the second
4061 * frame for a 68-byte atom. 76-byte atoms have 0 there.
4062 * Valid channel cannot be 0. */
4065 else if (scan_len % 68)
4067 else if (scan_len >= 1292 && scan[68] == 0)
4073 case FIRMWARE_TYPE_INTERSIL:
4075 if (priv->has_hostscan) {
4076 atom_len = le16_to_cpup((u16 *)scan);
4077 /* Sanity check for atom_len */
4078 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
4079 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
4080 dev->name, atom_len);
4084 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4090 /* Check that we got an whole number of atoms */
4091 if ((scan_len - offset) % atom_len) {
4092 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4093 "atom_len %d, offset %d\n", dev->name, scan_len,
4098 /* Read the entries one by one */
4099 for (; offset + atom_len <= scan_len; offset += atom_len) {
4101 atom = (union hermes_scan_info *) (scan + offset);
4103 /* First entry *MUST* be the AP MAC address */
4104 iwe.cmd = SIOCGIWAP;
4105 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4106 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4107 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4109 /* Other entries will be displayed in the order we give them */
4112 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4113 if (iwe.u.data.length > 32)
4114 iwe.u.data.length = 32;
4115 iwe.cmd = SIOCGIWESSID;
4116 iwe.u.data.flags = 1;
4117 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4120 iwe.cmd = SIOCGIWMODE;
4121 capabilities = le16_to_cpu(atom->a.capabilities);
4122 if (capabilities & 0x3) {
4123 if (capabilities & 0x1)
4124 iwe.u.mode = IW_MODE_MASTER;
4126 iwe.u.mode = IW_MODE_ADHOC;
4127 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4130 channel = atom->s.channel;
4131 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4133 iwe.cmd = SIOCGIWFREQ;
4134 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4136 current_ev = iwe_stream_add_event(current_ev, end_buf,
4137 &iwe, IW_EV_FREQ_LEN);
4140 /* Add quality statistics */
4142 iwe.u.qual.updated = 0x10; /* no link quality */
4143 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4144 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4145 /* Wireless tools prior to 27.pre22 will show link quality
4146 * anyway, so we provide a reasonable value. */
4147 if (iwe.u.qual.level > iwe.u.qual.noise)
4148 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4150 iwe.u.qual.qual = 0;
4151 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4153 /* Add encryption capability */
4154 iwe.cmd = SIOCGIWENCODE;
4155 if (capabilities & 0x10)
4156 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4158 iwe.u.data.flags = IW_ENCODE_DISABLED;
4159 iwe.u.data.length = 0;
4160 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4162 /* Bit rate is not available in Lucent/Agere firmwares */
4163 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4164 char * current_val = current_ev + IW_EV_LCP_LEN;
4168 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4173 iwe.cmd = SIOCGIWRATE;
4174 /* Those two flags are ignored... */
4175 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4177 for (i = 0; i < 10; i += step) {
4178 /* NULL terminated */
4179 if (atom->p.rates[i] == 0x0)
4181 /* Bit rate given in 500 kb/s units (+ 0x80) */
4182 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4183 current_val = iwe_stream_add_value(current_ev, current_val,
4187 /* Check if we added any event */
4188 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4189 current_ev = current_val;
4192 /* The other data in the scan result are not really
4193 * interesting, so for now drop it - Jean II */
4195 return current_ev - buffer;
4198 /* Return results of a scan */
4199 static int orinoco_ioctl_getscan(struct net_device *dev,
4200 struct iw_request_info *info,
4201 struct iw_point *srq,
4204 struct orinoco_private *priv = netdev_priv(dev);
4206 unsigned long flags;
4208 if (orinoco_lock(priv, &flags) != 0)
4211 /* If no results yet, ask to try again later */
4212 if (priv->scan_result == NULL) {
4213 if (priv->scan_inprogress)
4214 /* Important note : we don't want to block the caller
4215 * until results are ready for various reasons.
4216 * First, managing wait queues is complex and racy.
4217 * Second, we grab some rtnetlink lock before comming
4218 * here (in dev_ioctl()).
4219 * Third, we generate an Wireless Event, so the
4220 * caller can wait itself on that - Jean II */
4223 /* Client error, no scan results...
4224 * The caller need to restart the scan. */
4227 /* We have some results to push back to user space */
4229 /* Translate to WE format */
4230 int ret = orinoco_translate_scan(dev, extra,
4236 kfree(priv->scan_result);
4237 priv->scan_result = NULL;
4242 srq->flags = (__u16) priv->scan_mode;
4244 /* In any case, Scan results will be cleaned up in the
4245 * reset function and when exiting the driver.
4246 * The person triggering the scanning may never come to
4247 * pick the results, so we need to do it in those places.
4250 #ifdef SCAN_SINGLE_READ
4251 /* If you enable this option, only one client (the first
4252 * one) will be able to read the result (and only one
4253 * time). If there is multiple concurent clients that
4254 * want to read scan results, this behavior is not
4255 * advisable - Jean II */
4256 kfree(priv->scan_result);
4257 priv->scan_result = NULL;
4258 #endif /* SCAN_SINGLE_READ */
4259 /* Here, if too much time has elapsed since last scan,
4260 * we may want to clean up scan results... - Jean II */
4263 /* Scan is no longer in progress */
4264 priv->scan_inprogress = 0;
4267 orinoco_unlock(priv, &flags);
4271 /* Commit handler, called after set operations */
4272 static int orinoco_ioctl_commit(struct net_device *dev,
4273 struct iw_request_info *info,
4277 struct orinoco_private *priv = netdev_priv(dev);
4278 struct hermes *hw = &priv->hw;
4279 unsigned long flags;
4285 if (priv->broken_disableport) {
4290 if (orinoco_lock(priv, &flags) != 0)
4293 err = hermes_disable_port(hw, 0);
4295 printk(KERN_WARNING "%s: Unable to disable port "
4296 "while reconfiguring card\n", dev->name);
4297 priv->broken_disableport = 1;
4301 err = __orinoco_program_rids(dev);
4303 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4308 err = hermes_enable_port(hw, 0);
4310 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4317 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4318 schedule_work(&priv->reset_work);
4322 orinoco_unlock(priv, &flags);
4326 static const struct iw_priv_args orinoco_privtab[] = {
4327 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4328 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4329 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4331 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4333 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4334 0, "set_preamble" },
4335 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4337 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4338 0, "set_ibssport" },
4339 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4341 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4347 * Structures to export the Wireless Handlers
4350 static const iw_handler orinoco_handler[] = {
4351 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4352 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4353 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4354 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4355 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4356 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4357 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4358 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4359 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4360 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setspy,
4361 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getspy,
4362 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4363 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4364 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4365 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4366 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4367 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4368 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4369 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4370 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4371 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4372 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4373 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4374 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4375 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4376 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4377 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4378 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4379 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4380 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4385 Added typecasting since we no longer use iwreq_data -- Moustafa
4387 static const iw_handler orinoco_private_handler[] = {
4388 [0] = (iw_handler) orinoco_ioctl_reset,
4389 [1] = (iw_handler) orinoco_ioctl_reset,
4390 [2] = (iw_handler) orinoco_ioctl_setport3,
4391 [3] = (iw_handler) orinoco_ioctl_getport3,
4392 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4393 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4394 [6] = (iw_handler) orinoco_ioctl_setibssport,
4395 [7] = (iw_handler) orinoco_ioctl_getibssport,
4396 [9] = (iw_handler) orinoco_ioctl_getrid,
4399 static const struct iw_handler_def orinoco_handler_def = {
4400 .num_standard = ARRAY_SIZE(orinoco_handler),
4401 .num_private = ARRAY_SIZE(orinoco_private_handler),
4402 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4403 .standard = orinoco_handler,
4404 .private = orinoco_private_handler,
4405 .private_args = orinoco_privtab,
4406 .get_wireless_stats = orinoco_get_wireless_stats,
4409 static void orinoco_get_drvinfo(struct net_device *dev,
4410 struct ethtool_drvinfo *info)
4412 struct orinoco_private *priv = netdev_priv(dev);
4414 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4415 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4416 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4417 if (dev->class_dev.dev)
4418 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4419 sizeof(info->bus_info) - 1);
4421 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4422 "PCMCIA %p", priv->hw.iobase);
4425 static struct ethtool_ops orinoco_ethtool_ops = {
4426 .get_drvinfo = orinoco_get_drvinfo,
4427 .get_link = ethtool_op_get_link,
4430 /********************************************************************/
4432 /********************************************************************/
4435 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4437 printk(KERN_DEBUG "RX descriptor:\n");
4438 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4439 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4440 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4441 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4442 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4443 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4444 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4446 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4447 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4448 frame->p80211.frame_ctl);
4449 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4450 frame->p80211.duration_id);
4451 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4452 frame->p80211.addr1[0], frame->p80211.addr1[1],
4453 frame->p80211.addr1[2], frame->p80211.addr1[3],
4454 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4455 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4456 frame->p80211.addr2[0], frame->p80211.addr2[1],
4457 frame->p80211.addr2[2], frame->p80211.addr2[3],
4458 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4459 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4460 frame->p80211.addr3[0], frame->p80211.addr3[1],
4461 frame->p80211.addr3[2], frame->p80211.addr3[3],
4462 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4463 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4464 frame->p80211.seq_ctl);
4465 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4466 frame->p80211.addr4[0], frame->p80211.addr4[1],
4467 frame->p80211.addr4[2], frame->p80211.addr4[3],
4468 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4469 printk(KERN_DEBUG " data_len = 0x%04x\n",
4470 frame->p80211.data_len);
4472 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4473 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4474 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4475 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4476 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4477 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4478 frame->p8023.h_source[0], frame->p8023.h_source[1],
4479 frame->p8023.h_source[2], frame->p8023.h_source[3],
4480 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4481 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4483 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4484 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4485 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4486 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4487 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4488 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4489 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4493 /********************************************************************/
4494 /* Module initialization */
4495 /********************************************************************/
4497 EXPORT_SYMBOL(alloc_orinocodev);
4498 EXPORT_SYMBOL(free_orinocodev);
4500 EXPORT_SYMBOL(__orinoco_up);
4501 EXPORT_SYMBOL(__orinoco_down);
4502 EXPORT_SYMBOL(orinoco_reinit_firmware);
4504 EXPORT_SYMBOL(orinoco_interrupt);
4506 /* Can't be declared "const" or the whole __initdata section will
4508 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4509 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4510 "Pavel Roskin <proski@gnu.org>, et al)";
4512 static int __init init_orinoco(void)
4514 printk(KERN_DEBUG "%s\n", version);
4518 static void __exit exit_orinoco(void)
4522 module_init(init_orinoco);
4523 module_exit(exit_orinoco);