1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/config.h>
80 #include <linux/module.h>
81 #include <linux/kernel.h>
82 #include <linux/init.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.h>
86 #include <linux/wireless.h>
87 #include <net/iw_handler.h>
88 #include <net/ieee80211.h>
90 #include "hermes_rid.h"
93 /********************************************************************/
94 /* Module information */
95 /********************************************************************/
97 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
98 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
99 MODULE_LICENSE("Dual MPL/GPL");
101 /* Level of debugging. Used in the macros in orinoco.h */
103 int orinoco_debug = ORINOCO_DEBUG;
104 module_param(orinoco_debug, int, 0644);
105 MODULE_PARM_DESC(orinoco_debug, "Debug level");
106 EXPORT_SYMBOL(orinoco_debug);
109 static int suppress_linkstatus; /* = 0 */
110 module_param(suppress_linkstatus, bool, 0644);
111 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
112 static int ignore_disconnect; /* = 0 */
113 module_param(ignore_disconnect, int, 0644);
114 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
116 static int force_monitor; /* = 0 */
117 module_param(force_monitor, int, 0644);
118 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
120 /********************************************************************/
121 /* Compile time configuration and compatibility stuff */
122 /********************************************************************/
124 /* We do this this way to avoid ifdefs in the actual code */
126 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
128 #define SPY_NUMBER(priv) 0
129 #endif /* WIRELESS_SPY */
131 /********************************************************************/
132 /* Internal constants */
133 /********************************************************************/
135 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
136 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
137 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
139 #define ORINOCO_MIN_MTU 256
140 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
142 #define SYMBOL_MAX_VER_LEN (14)
145 #define MAX_IRQLOOPS_PER_IRQ 10
146 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
147 * how many events the
149 * legitimately generate */
150 #define SMALL_KEY_SIZE 5
151 #define LARGE_KEY_SIZE 13
152 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
154 #define DUMMY_FID 0xFFFF
156 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
157 HERMES_MAX_MULTICAST : 0)*/
158 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
160 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
161 | HERMES_EV_TX | HERMES_EV_TXEXC \
162 | HERMES_EV_WTERR | HERMES_EV_INFO \
163 | HERMES_EV_INFDROP )
165 #define MAX_RID_LEN 1024
167 static const struct iw_handler_def orinoco_handler_def;
168 static struct ethtool_ops orinoco_ethtool_ops;
170 /********************************************************************/
172 /********************************************************************/
174 /* The frequency of each channel in MHz */
175 static const long channel_frequency[] = {
176 2412, 2417, 2422, 2427, 2432, 2437, 2442,
177 2447, 2452, 2457, 2462, 2467, 2472, 2484
179 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
181 /* This tables gives the actual meanings of the bitrate IDs returned
182 * by the firmware. */
184 int bitrate; /* in 100s of kilobits */
186 u16 agere_txratectrl;
187 u16 intersil_txratectrl;
188 } bitrate_table[] = {
189 {110, 1, 3, 15}, /* Entry 0 is the default */
198 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
200 /********************************************************************/
202 /********************************************************************/
204 /* Used in Event handling.
205 * We avoid nested structres as they break on ARM -- Moustafa */
206 struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
227 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
228 unsigned char h_source[ETH_ALEN]; /* source ether addr */
229 unsigned short h_proto; /* packet type ID field */
238 } __attribute__ ((packed));
240 /* Rx frame header except compatibility 802.3 header */
241 struct hermes_rx_descriptor {
262 } __attribute__ ((packed));
264 /********************************************************************/
265 /* Function prototypes */
266 /********************************************************************/
268 static int __orinoco_program_rids(struct net_device *dev);
269 static void __orinoco_set_multicast_list(struct net_device *dev);
271 /********************************************************************/
272 /* Internal helper functions */
273 /********************************************************************/
275 static inline void set_port_type(struct orinoco_private *priv)
277 switch (priv->iw_mode) {
280 priv->createibss = 0;
283 if (priv->prefer_port3) {
285 priv->createibss = 0;
287 priv->port_type = priv->ibss_port;
288 priv->createibss = 1;
291 case IW_MODE_MONITOR:
293 priv->createibss = 0;
296 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
301 /********************************************************************/
303 /********************************************************************/
305 static int orinoco_open(struct net_device *dev)
307 struct orinoco_private *priv = netdev_priv(dev);
311 if (orinoco_lock(priv, &flags) != 0)
314 err = __orinoco_up(dev);
319 orinoco_unlock(priv, &flags);
324 static int orinoco_stop(struct net_device *dev)
326 struct orinoco_private *priv = netdev_priv(dev);
329 /* We mustn't use orinoco_lock() here, because we need to be
330 able to close the interface even if hw_unavailable is set
331 (e.g. as we're released after a PC Card removal) */
332 spin_lock_irq(&priv->lock);
336 err = __orinoco_down(dev);
338 spin_unlock_irq(&priv->lock);
343 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
345 struct orinoco_private *priv = netdev_priv(dev);
350 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
352 struct orinoco_private *priv = netdev_priv(dev);
353 hermes_t *hw = &priv->hw;
354 struct iw_statistics *wstats = &priv->wstats;
358 if (! netif_device_present(dev)) {
359 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
361 return NULL; /* FIXME: Can we do better than this? */
364 /* If busy, return the old stats. Returning NULL may cause
365 * the interface to disappear from /proc/net/wireless */
366 if (orinoco_lock(priv, &flags) != 0)
369 /* We can't really wait for the tallies inquiry command to
370 * complete, so we just use the previous results and trigger
371 * a new tallies inquiry command for next time - Jean II */
372 /* FIXME: Really we should wait for the inquiry to come back -
373 * as it is the stats we give don't make a whole lot of sense.
374 * Unfortunately, it's not clear how to do that within the
375 * wireless extensions framework: I think we're in user
376 * context, but a lock seems to be held by the time we get in
377 * here so we're not safe to sleep here. */
378 hermes_inquire(hw, HERMES_INQ_TALLIES);
380 if (priv->iw_mode == IW_MODE_ADHOC) {
381 memset(&wstats->qual, 0, sizeof(wstats->qual));
382 /* If a spy address is defined, we report stats of the
383 * first spy address - Jean II */
384 if (SPY_NUMBER(priv)) {
385 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
386 wstats->qual.level = priv->spy_data.spy_stat[0].level;
387 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
388 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
392 u16 qual, signal, noise;
393 } __attribute__ ((packed)) cq;
395 err = HERMES_READ_RECORD(hw, USER_BAP,
396 HERMES_RID_COMMSQUALITY, &cq);
399 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
400 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
401 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
402 wstats->qual.updated = 7;
406 orinoco_unlock(priv, &flags);
410 static void orinoco_set_multicast_list(struct net_device *dev)
412 struct orinoco_private *priv = netdev_priv(dev);
415 if (orinoco_lock(priv, &flags) != 0) {
416 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
417 "called when hw_unavailable\n", dev->name);
421 __orinoco_set_multicast_list(dev);
422 orinoco_unlock(priv, &flags);
425 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
427 struct orinoco_private *priv = netdev_priv(dev);
429 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
432 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
433 (priv->nicbuf_size - ETH_HLEN) )
441 /********************************************************************/
443 /********************************************************************/
445 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
447 struct orinoco_private *priv = netdev_priv(dev);
448 struct net_device_stats *stats = &priv->stats;
449 hermes_t *hw = &priv->hw;
451 u16 txfid = priv->txfid;
454 int len, data_len, data_off;
455 struct hermes_tx_descriptor desc;
458 TRACE_ENTER(dev->name);
460 if (! netif_running(dev)) {
461 printk(KERN_ERR "%s: Tx on stopped device!\n",
463 TRACE_EXIT(dev->name);
467 if (netif_queue_stopped(dev)) {
468 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
470 TRACE_EXIT(dev->name);
474 if (orinoco_lock(priv, &flags) != 0) {
475 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
477 TRACE_EXIT(dev->name);
481 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
482 /* Oops, the firmware hasn't established a connection,
483 silently drop the packet (this seems to be the
486 orinoco_unlock(priv, &flags);
488 TRACE_EXIT(dev->name);
492 /* Length of the packet body */
493 /* FIXME: what if the skb is smaller than this? */
494 len = max_t(int,skb->len - ETH_HLEN, ETH_ZLEN - ETH_HLEN);
496 eh = (struct ethhdr *)skb->data;
498 memset(&desc, 0, sizeof(desc));
499 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
500 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
503 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
504 "to BAP\n", dev->name, err);
509 /* Clear the 802.11 header and data length fields - some
510 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
511 * if this isn't done. */
512 hermes_clear_words(hw, HERMES_DATA0,
513 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
515 /* Encapsulate Ethernet-II frames */
516 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
517 struct header_struct hdr;
519 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
520 p = skb->data + ETH_HLEN;
523 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
524 memcpy(hdr.src, eh->h_source, ETH_ALEN);
525 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
528 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
530 hdr.ethertype = eh->h_proto;
531 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
532 txfid, HERMES_802_3_OFFSET);
535 printk(KERN_ERR "%s: Error %d writing packet "
536 "header to BAP\n", dev->name, err);
540 } else { /* IEEE 802.3 frame */
541 data_len = len + ETH_HLEN;
542 data_off = HERMES_802_3_OFFSET;
546 /* Round up for odd length packets */
547 err = hermes_bap_pwrite(hw, USER_BAP, p, ALIGN(data_len, 2),
550 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
556 /* Finally, we actually initiate the send */
557 netif_stop_queue(dev);
559 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
562 netif_start_queue(dev);
563 printk(KERN_ERR "%s: Error %d transmitting packet\n",
569 dev->trans_start = jiffies;
570 stats->tx_bytes += data_off + data_len;
572 orinoco_unlock(priv, &flags);
576 TRACE_EXIT(dev->name);
580 TRACE_EXIT(dev->name);
582 orinoco_unlock(priv, &flags);
586 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
588 struct orinoco_private *priv = netdev_priv(dev);
589 u16 fid = hermes_read_regn(hw, ALLOCFID);
591 if (fid != priv->txfid) {
592 if (fid != DUMMY_FID)
593 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
598 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
601 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
603 struct orinoco_private *priv = netdev_priv(dev);
604 struct net_device_stats *stats = &priv->stats;
608 netif_wake_queue(dev);
610 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
613 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
615 struct orinoco_private *priv = netdev_priv(dev);
616 struct net_device_stats *stats = &priv->stats;
617 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
618 struct hermes_tx_descriptor_802_11 hdr;
621 if (fid == DUMMY_FID)
622 return; /* Nothing's really happened */
624 /* Read the frame header */
625 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
626 sizeof(struct hermes_tx_descriptor) +
627 sizeof(struct ieee80211_hdr_4addr),
630 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
634 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
635 "(FID=%04X error %d)\n",
636 dev->name, fid, err);
640 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
643 /* We produce a TXDROP event only for retry or lifetime
644 * exceeded, because that's the only status that really mean
645 * that this particular node went away.
646 * Other errors means that *we* screwed up. - Jean II */
647 hdr.status = le16_to_cpu(hdr.status);
648 if (hdr.status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
649 union iwreq_data wrqu;
651 /* Copy 802.11 dest address.
652 * We use the 802.11 header because the frame may
653 * not be 802.3 or may be mangled...
654 * In Ad-Hoc mode, it will be the node address.
655 * In managed mode, it will be most likely the AP addr
656 * User space will figure out how to convert it to
657 * whatever it needs (IP address or else).
659 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
660 wrqu.addr.sa_family = ARPHRD_ETHER;
662 /* Send event to user space */
663 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
666 netif_wake_queue(dev);
669 static void orinoco_tx_timeout(struct net_device *dev)
671 struct orinoco_private *priv = netdev_priv(dev);
672 struct net_device_stats *stats = &priv->stats;
673 struct hermes *hw = &priv->hw;
675 printk(KERN_WARNING "%s: Tx timeout! "
676 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
677 dev->name, hermes_read_regn(hw, ALLOCFID),
678 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
682 schedule_work(&priv->reset_work);
685 /********************************************************************/
686 /* Rx path (data frames) */
687 /********************************************************************/
689 /* Does the frame have a SNAP header indicating it should be
690 * de-encapsulated to Ethernet-II? */
691 static inline int is_ethersnap(void *_hdr)
695 /* We de-encapsulate all packets which, a) have SNAP headers
696 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
697 * and where b) the OUI of the SNAP header is 00:00:00 or
698 * 00:00:f8 - we need both because different APs appear to use
699 * different OUIs for some reason */
700 return (memcmp(hdr, &encaps_hdr, 5) == 0)
701 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
704 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
705 int level, int noise)
707 struct iw_quality wstats;
708 wstats.level = level - 0x95;
709 wstats.noise = noise - 0x95;
710 wstats.qual = (level > noise) ? (level - noise) : 0;
712 /* Update spy records */
713 wireless_spy_update(dev, mac, &wstats);
716 static void orinoco_stat_gather(struct net_device *dev,
718 struct hermes_rx_descriptor *desc)
720 struct orinoco_private *priv = netdev_priv(dev);
722 /* Using spy support with lots of Rx packets, like in an
723 * infrastructure (AP), will really slow down everything, because
724 * the MAC address must be compared to each entry of the spy list.
725 * If the user really asks for it (set some address in the
726 * spy list), we do it, but he will pay the price.
727 * Note that to get here, you need both WIRELESS_SPY
728 * compiled in AND some addresses in the list !!!
730 /* Note : gcc will optimise the whole section away if
731 * WIRELESS_SPY is not defined... - Jean II */
732 if (SPY_NUMBER(priv)) {
733 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
734 desc->signal, desc->silence);
739 * orinoco_rx_monitor - handle received monitor frames.
744 * desc rx descriptor of the frame
746 * Call context: interrupt
748 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
749 struct hermes_rx_descriptor *desc)
751 u32 hdrlen = 30; /* return full header by default */
757 struct orinoco_private *priv = netdev_priv(dev);
758 struct net_device_stats *stats = &priv->stats;
759 hermes_t *hw = &priv->hw;
761 len = le16_to_cpu(desc->data_len);
763 /* Determine the size of the header and the data */
764 fc = le16_to_cpu(desc->frame_ctl);
765 switch (fc & IEEE80211_FCTL_FTYPE) {
766 case IEEE80211_FTYPE_DATA:
767 if ((fc & IEEE80211_FCTL_TODS)
768 && (fc & IEEE80211_FCTL_FROMDS))
774 case IEEE80211_FTYPE_MGMT:
778 case IEEE80211_FTYPE_CTL:
779 switch (fc & IEEE80211_FCTL_STYPE) {
780 case IEEE80211_STYPE_PSPOLL:
781 case IEEE80211_STYPE_RTS:
782 case IEEE80211_STYPE_CFEND:
783 case IEEE80211_STYPE_CFENDACK:
786 case IEEE80211_STYPE_CTS:
787 case IEEE80211_STYPE_ACK:
793 /* Unknown frame type */
797 /* sanity check the length */
798 if (datalen > IEEE80211_DATA_LEN + 12) {
799 printk(KERN_DEBUG "%s: oversized monitor frame, "
800 "data length = %d\n", dev->name, datalen);
802 stats->rx_length_errors++;
806 skb = dev_alloc_skb(hdrlen + datalen);
808 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
814 /* Copy the 802.11 header to the skb */
815 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
816 skb->mac.raw = skb->data;
818 /* If any, copy the data from the card to the skb */
820 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
821 ALIGN(datalen, 2), rxfid,
822 HERMES_802_2_OFFSET);
824 printk(KERN_ERR "%s: error %d reading monitor frame\n",
831 skb->ip_summed = CHECKSUM_NONE;
832 skb->pkt_type = PACKET_OTHERHOST;
833 skb->protocol = __constant_htons(ETH_P_802_2);
835 dev->last_rx = jiffies;
837 stats->rx_bytes += skb->len;
843 dev_kfree_skb_irq(skb);
849 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
851 struct orinoco_private *priv = netdev_priv(dev);
852 struct net_device_stats *stats = &priv->stats;
853 struct iw_statistics *wstats = &priv->wstats;
854 struct sk_buff *skb = NULL;
855 u16 rxfid, status, fc;
857 struct hermes_rx_descriptor desc;
861 rxfid = hermes_read_regn(hw, RXFID);
863 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
866 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
867 "Frame dropped.\n", dev->name, err);
871 status = le16_to_cpu(desc.status);
873 if (status & HERMES_RXSTAT_BADCRC) {
874 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
876 stats->rx_crc_errors++;
880 /* Handle frames in monitor mode */
881 if (priv->iw_mode == IW_MODE_MONITOR) {
882 orinoco_rx_monitor(dev, rxfid, &desc);
886 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
887 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
889 wstats->discard.code++;
893 length = le16_to_cpu(desc.data_len);
894 fc = le16_to_cpu(desc.frame_ctl);
897 if (length < 3) { /* No for even an 802.2 LLC header */
898 /* At least on Symbol firmware with PCF we get quite a
899 lot of these legitimately - Poll frames with no
903 if (length > IEEE80211_DATA_LEN) {
904 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
906 stats->rx_length_errors++;
910 /* We need space for the packet data itself, plus an ethernet
911 header, plus 2 bytes so we can align the IP header on a
912 32bit boundary, plus 1 byte so we can read in odd length
913 packets from the card, which has an IO granularity of 16
915 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
917 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
922 /* We'll prepend the header, so reserve space for it. The worst
923 case is no decapsulation, when 802.3 header is prepended and
924 nothing is removed. 2 is for aligning the IP header. */
925 skb_reserve(skb, ETH_HLEN + 2);
927 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
928 ALIGN(length, 2), rxfid,
929 HERMES_802_2_OFFSET);
931 printk(KERN_ERR "%s: error %d reading frame. "
932 "Frame dropped.\n", dev->name, err);
936 /* Handle decapsulation
937 * In most cases, the firmware tell us about SNAP frames.
938 * For some reason, the SNAP frames sent by LinkSys APs
939 * are not properly recognised by most firmwares.
940 * So, check ourselves */
941 if (length >= ENCAPS_OVERHEAD &&
942 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
943 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
944 is_ethersnap(skb->data))) {
945 /* These indicate a SNAP within 802.2 LLC within
946 802.11 frame which we'll need to de-encapsulate to
947 the original EthernetII frame. */
948 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
950 /* 802.3 frame - prepend 802.3 header as is */
951 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
952 hdr->h_proto = htons(length);
954 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
955 if (fc & IEEE80211_FCTL_FROMDS)
956 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
958 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
960 dev->last_rx = jiffies;
962 skb->protocol = eth_type_trans(skb, dev);
963 skb->ip_summed = CHECKSUM_NONE;
964 if (fc & IEEE80211_FCTL_TODS)
965 skb->pkt_type = PACKET_OTHERHOST;
967 /* Process the wireless stats if needed */
968 orinoco_stat_gather(dev, skb, &desc);
970 /* Pass the packet to the networking stack */
973 stats->rx_bytes += length;
978 dev_kfree_skb_irq(skb);
984 /********************************************************************/
985 /* Rx path (info frames) */
986 /********************************************************************/
988 static void print_linkstatus(struct net_device *dev, u16 status)
992 if (suppress_linkstatus)
996 case HERMES_LINKSTATUS_NOT_CONNECTED:
999 case HERMES_LINKSTATUS_CONNECTED:
1002 case HERMES_LINKSTATUS_DISCONNECTED:
1005 case HERMES_LINKSTATUS_AP_CHANGE:
1008 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1009 s = "AP Out of Range";
1011 case HERMES_LINKSTATUS_AP_IN_RANGE:
1014 case HERMES_LINKSTATUS_ASSOC_FAILED:
1015 s = "Association Failed";
1021 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1022 dev->name, s, status);
1025 /* Search scan results for requested BSSID, join it if found */
1026 static void orinoco_join_ap(struct net_device *dev)
1028 struct orinoco_private *priv = netdev_priv(dev);
1029 struct hermes *hw = &priv->hw;
1031 unsigned long flags;
1035 } __attribute__ ((packed)) req;
1036 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1037 struct prism2_scan_apinfo *atom = NULL;
1043 /* Allocate buffer for scan results */
1044 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1048 if (orinoco_lock(priv, &flags) != 0)
1051 /* Sanity checks in case user changed something in the meantime */
1052 if (! priv->bssid_fixed)
1055 if (strlen(priv->desired_essid) == 0)
1058 /* Read scan results from the firmware */
1059 err = hermes_read_ltv(hw, USER_BAP,
1060 HERMES_RID_SCANRESULTSTABLE,
1061 MAX_SCAN_LEN, &len, buf);
1063 printk(KERN_ERR "%s: Cannot read scan results\n",
1068 len = HERMES_RECLEN_TO_BYTES(len);
1070 /* Go through the scan results looking for the channel of the AP
1071 * we were requested to join */
1072 for (; offset + atom_len <= len; offset += atom_len) {
1073 atom = (struct prism2_scan_apinfo *) (buf + offset);
1074 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1081 DEBUG(1, "%s: Requested AP not found in scan results\n",
1086 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1087 req.channel = atom->channel; /* both are little-endian */
1088 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1091 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1094 orinoco_unlock(priv, &flags);
1100 /* Send new BSSID to userspace */
1101 static void orinoco_send_wevents(struct net_device *dev)
1103 struct orinoco_private *priv = netdev_priv(dev);
1104 struct hermes *hw = &priv->hw;
1105 union iwreq_data wrqu;
1107 unsigned long flags;
1109 if (orinoco_lock(priv, &flags) != 0)
1112 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1113 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1117 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1119 /* Send event to user space */
1120 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1121 orinoco_unlock(priv, &flags);
1124 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1126 struct orinoco_private *priv = netdev_priv(dev);
1131 } __attribute__ ((packed)) info;
1135 /* This is an answer to an INQUIRE command that we did earlier,
1136 * or an information "event" generated by the card
1137 * The controller return to us a pseudo frame containing
1138 * the information in question - Jean II */
1139 infofid = hermes_read_regn(hw, INFOFID);
1141 /* Read the info frame header - don't try too hard */
1142 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1145 printk(KERN_ERR "%s: error %d reading info frame. "
1146 "Frame dropped.\n", dev->name, err);
1150 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1151 type = le16_to_cpu(info.type);
1154 case HERMES_INQ_TALLIES: {
1155 struct hermes_tallies_frame tallies;
1156 struct iw_statistics *wstats = &priv->wstats;
1158 if (len > sizeof(tallies)) {
1159 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1161 len = sizeof(tallies);
1164 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1165 infofid, sizeof(info));
1169 /* Increment our various counters */
1170 /* wstats->discard.nwid - no wrong BSSID stuff */
1171 wstats->discard.code +=
1172 le16_to_cpu(tallies.RxWEPUndecryptable);
1173 if (len == sizeof(tallies))
1174 wstats->discard.code +=
1175 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1176 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1177 wstats->discard.misc +=
1178 le16_to_cpu(tallies.TxDiscardsWrongSA);
1179 wstats->discard.fragment +=
1180 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1181 wstats->discard.retries +=
1182 le16_to_cpu(tallies.TxRetryLimitExceeded);
1183 /* wstats->miss.beacon - no match */
1186 case HERMES_INQ_LINKSTATUS: {
1187 struct hermes_linkstatus linkstatus;
1191 if (priv->iw_mode == IW_MODE_MONITOR)
1194 if (len != sizeof(linkstatus)) {
1195 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1200 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1201 infofid, sizeof(info));
1204 newstatus = le16_to_cpu(linkstatus.linkstatus);
1206 /* Symbol firmware uses "out of range" to signal that
1207 * the hostscan frame can be requested. */
1208 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1209 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1210 priv->has_hostscan && priv->scan_inprogress) {
1211 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1215 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1216 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1217 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1220 netif_carrier_on(dev);
1221 else if (!ignore_disconnect)
1222 netif_carrier_off(dev);
1224 if (newstatus != priv->last_linkstatus) {
1225 priv->last_linkstatus = newstatus;
1226 print_linkstatus(dev, newstatus);
1227 /* The info frame contains only one word which is the
1228 * status (see hermes.h). The status is pretty boring
1229 * in itself, that's why we export the new BSSID...
1231 schedule_work(&priv->wevent_work);
1235 case HERMES_INQ_SCAN:
1236 if (!priv->scan_inprogress && priv->bssid_fixed &&
1237 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1238 schedule_work(&priv->join_work);
1242 case HERMES_INQ_HOSTSCAN:
1243 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1244 /* Result of a scanning. Contains information about
1245 * cells in the vicinity - Jean II */
1246 union iwreq_data wrqu;
1251 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1256 /* We are a strict producer. If the previous scan results
1257 * have not been consumed, we just have to drop this
1258 * frame. We can't remove the previous results ourselves,
1259 * that would be *very* racy... Jean II */
1260 if (priv->scan_result != NULL) {
1261 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1265 /* Allocate buffer for results */
1266 buf = kmalloc(len, GFP_ATOMIC);
1268 /* No memory, so can't printk()... */
1271 /* Read scan data */
1272 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1273 infofid, sizeof(info));
1279 #ifdef ORINOCO_DEBUG
1282 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1283 for(i = 1; i < (len * 2); i++)
1284 printk(":%02X", buf[i]);
1287 #endif /* ORINOCO_DEBUG */
1289 /* Allow the clients to access the results */
1290 priv->scan_len = len;
1291 priv->scan_result = buf;
1293 /* Send an empty event to user space.
1294 * We don't send the received data on the event because
1295 * it would require us to do complex transcoding, and
1296 * we want to minimise the work done in the irq handler
1297 * Use a request to extract the data - Jean II */
1298 wrqu.data.length = 0;
1299 wrqu.data.flags = 0;
1300 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1303 case HERMES_INQ_SEC_STAT_AGERE:
1304 /* Security status (Agere specific) */
1305 /* Ignore this frame for now */
1306 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1310 printk(KERN_DEBUG "%s: Unknown information frame received: "
1311 "type 0x%04x, length %d\n", dev->name, type, len);
1312 /* We don't actually do anything about it */
1317 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1319 if (net_ratelimit())
1320 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1323 /********************************************************************/
1324 /* Internal hardware control routines */
1325 /********************************************************************/
1327 int __orinoco_up(struct net_device *dev)
1329 struct orinoco_private *priv = netdev_priv(dev);
1330 struct hermes *hw = &priv->hw;
1333 netif_carrier_off(dev); /* just to make sure */
1335 err = __orinoco_program_rids(dev);
1337 printk(KERN_ERR "%s: Error %d configuring card\n",
1342 /* Fire things up again */
1343 hermes_set_irqmask(hw, ORINOCO_INTEN);
1344 err = hermes_enable_port(hw, 0);
1346 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1351 netif_start_queue(dev);
1356 int __orinoco_down(struct net_device *dev)
1358 struct orinoco_private *priv = netdev_priv(dev);
1359 struct hermes *hw = &priv->hw;
1362 netif_stop_queue(dev);
1364 if (! priv->hw_unavailable) {
1365 if (! priv->broken_disableport) {
1366 err = hermes_disable_port(hw, 0);
1368 /* Some firmwares (e.g. Intersil 1.3.x) seem
1369 * to have problems disabling the port, oh
1371 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1373 priv->broken_disableport = 1;
1376 hermes_set_irqmask(hw, 0);
1377 hermes_write_regn(hw, EVACK, 0xffff);
1380 /* firmware will have to reassociate */
1381 netif_carrier_off(dev);
1382 priv->last_linkstatus = 0xffff;
1387 int orinoco_reinit_firmware(struct net_device *dev)
1389 struct orinoco_private *priv = netdev_priv(dev);
1390 struct hermes *hw = &priv->hw;
1393 err = hermes_init(hw);
1397 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1398 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1399 /* Try workaround for old Symbol firmware bug */
1400 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1401 "(old Symbol firmware?). Trying to work around... ",
1404 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1405 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1407 printk("failed!\n");
1415 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1417 hermes_t *hw = &priv->hw;
1420 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1421 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1422 priv->ndev->name, priv->bitratemode);
1426 switch (priv->firmware_type) {
1427 case FIRMWARE_TYPE_AGERE:
1428 err = hermes_write_wordrec(hw, USER_BAP,
1429 HERMES_RID_CNFTXRATECONTROL,
1430 bitrate_table[priv->bitratemode].agere_txratectrl);
1432 case FIRMWARE_TYPE_INTERSIL:
1433 case FIRMWARE_TYPE_SYMBOL:
1434 err = hermes_write_wordrec(hw, USER_BAP,
1435 HERMES_RID_CNFTXRATECONTROL,
1436 bitrate_table[priv->bitratemode].intersil_txratectrl);
1445 /* Set fixed AP address */
1446 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1450 hermes_t *hw = &priv->hw;
1452 switch (priv->firmware_type) {
1453 case FIRMWARE_TYPE_AGERE:
1456 case FIRMWARE_TYPE_INTERSIL:
1457 if (priv->bssid_fixed)
1462 err = hermes_write_wordrec(hw, USER_BAP,
1463 HERMES_RID_CNFROAMINGMODE,
1466 case FIRMWARE_TYPE_SYMBOL:
1467 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1468 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1469 &priv->desired_bssid);
1475 /* Change the WEP keys and/or the current keys. Can be called
1476 * either from __orinoco_hw_setup_wep() or directly from
1477 * orinoco_ioctl_setiwencode(). In the later case the association
1478 * with the AP is not broken (if the firmware can handle it),
1479 * which is needed for 802.1x implementations. */
1480 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1482 hermes_t *hw = &priv->hw;
1485 switch (priv->firmware_type) {
1486 case FIRMWARE_TYPE_AGERE:
1487 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1488 HERMES_RID_CNFWEPKEYS_AGERE,
1492 err = hermes_write_wordrec(hw, USER_BAP,
1493 HERMES_RID_CNFTXKEY_AGERE,
1498 case FIRMWARE_TYPE_INTERSIL:
1499 case FIRMWARE_TYPE_SYMBOL:
1504 /* Force uniform key length to work around firmware bugs */
1505 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1507 if (keylen > LARGE_KEY_SIZE) {
1508 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1509 priv->ndev->name, priv->tx_key, keylen);
1513 /* Write all 4 keys */
1514 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1515 err = hermes_write_ltv(hw, USER_BAP,
1516 HERMES_RID_CNFDEFAULTKEY0 + i,
1517 HERMES_BYTES_TO_RECLEN(keylen),
1518 priv->keys[i].data);
1523 /* Write the index of the key used in transmission */
1524 err = hermes_write_wordrec(hw, USER_BAP,
1525 HERMES_RID_CNFWEPDEFAULTKEYID,
1536 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1538 hermes_t *hw = &priv->hw;
1540 int master_wep_flag;
1544 __orinoco_hw_setup_wepkeys(priv);
1546 if (priv->wep_restrict)
1547 auth_flag = HERMES_AUTH_SHARED_KEY;
1549 auth_flag = HERMES_AUTH_OPEN;
1551 switch (priv->firmware_type) {
1552 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1554 /* Enable the shared-key authentication. */
1555 err = hermes_write_wordrec(hw, USER_BAP,
1556 HERMES_RID_CNFAUTHENTICATION_AGERE,
1559 err = hermes_write_wordrec(hw, USER_BAP,
1560 HERMES_RID_CNFWEPENABLED_AGERE,
1566 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1567 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1569 if (priv->wep_restrict ||
1570 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1571 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1572 HERMES_WEP_EXCL_UNENCRYPTED;
1574 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1576 err = hermes_write_wordrec(hw, USER_BAP,
1577 HERMES_RID_CNFAUTHENTICATION,
1582 master_wep_flag = 0;
1584 if (priv->iw_mode == IW_MODE_MONITOR)
1585 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1587 /* Master WEP setting : on/off */
1588 err = hermes_write_wordrec(hw, USER_BAP,
1589 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1600 static int __orinoco_program_rids(struct net_device *dev)
1602 struct orinoco_private *priv = netdev_priv(dev);
1603 hermes_t *hw = &priv->hw;
1605 struct hermes_idstring idbuf;
1607 /* Set the MAC address */
1608 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1609 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1611 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1616 /* Set up the link mode */
1617 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1620 printk(KERN_ERR "%s: Error %d setting port type\n",
1624 /* Set the channel/frequency */
1625 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1626 err = hermes_write_wordrec(hw, USER_BAP,
1627 HERMES_RID_CNFOWNCHANNEL,
1630 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1631 dev->name, err, priv->channel);
1636 if (priv->has_ibss) {
1639 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1640 printk(KERN_WARNING "%s: This firmware requires an "
1641 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1642 /* With wvlan_cs, in this case, we would crash.
1643 * hopefully, this driver will behave better...
1647 createibss = priv->createibss;
1650 err = hermes_write_wordrec(hw, USER_BAP,
1651 HERMES_RID_CNFCREATEIBSS,
1654 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1660 /* Set the desired BSSID */
1661 err = __orinoco_hw_set_wap(priv);
1663 printk(KERN_ERR "%s: Error %d setting AP address\n",
1667 /* Set the desired ESSID */
1668 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1669 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1670 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1671 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1672 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1675 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1679 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1680 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1683 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1688 /* Set the station name */
1689 idbuf.len = cpu_to_le16(strlen(priv->nick));
1690 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1691 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1692 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1695 printk(KERN_ERR "%s: Error %d setting nickname\n",
1700 /* Set AP density */
1701 if (priv->has_sensitivity) {
1702 err = hermes_write_wordrec(hw, USER_BAP,
1703 HERMES_RID_CNFSYSTEMSCALE,
1706 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1707 "Disabling sensitivity control\n",
1710 priv->has_sensitivity = 0;
1714 /* Set RTS threshold */
1715 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1718 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1723 /* Set fragmentation threshold or MWO robustness */
1725 err = hermes_write_wordrec(hw, USER_BAP,
1726 HERMES_RID_CNFMWOROBUST_AGERE,
1729 err = hermes_write_wordrec(hw, USER_BAP,
1730 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1733 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1739 err = __orinoco_hw_set_bitrate(priv);
1741 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1746 /* Set power management */
1748 err = hermes_write_wordrec(hw, USER_BAP,
1749 HERMES_RID_CNFPMENABLED,
1752 printk(KERN_ERR "%s: Error %d setting up PM\n",
1757 err = hermes_write_wordrec(hw, USER_BAP,
1758 HERMES_RID_CNFMULTICASTRECEIVE,
1761 printk(KERN_ERR "%s: Error %d setting up PM\n",
1765 err = hermes_write_wordrec(hw, USER_BAP,
1766 HERMES_RID_CNFMAXSLEEPDURATION,
1769 printk(KERN_ERR "%s: Error %d setting up PM\n",
1773 err = hermes_write_wordrec(hw, USER_BAP,
1774 HERMES_RID_CNFPMHOLDOVERDURATION,
1777 printk(KERN_ERR "%s: Error %d setting up PM\n",
1783 /* Set preamble - only for Symbol so far... */
1784 if (priv->has_preamble) {
1785 err = hermes_write_wordrec(hw, USER_BAP,
1786 HERMES_RID_CNFPREAMBLE_SYMBOL,
1789 printk(KERN_ERR "%s: Error %d setting preamble\n",
1795 /* Set up encryption */
1796 if (priv->has_wep) {
1797 err = __orinoco_hw_setup_wep(priv);
1799 printk(KERN_ERR "%s: Error %d activating WEP\n",
1805 if (priv->iw_mode == IW_MODE_MONITOR) {
1806 /* Enable monitor mode */
1807 dev->type = ARPHRD_IEEE80211;
1808 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1809 HERMES_TEST_MONITOR, 0, NULL);
1811 /* Disable monitor mode */
1812 dev->type = ARPHRD_ETHER;
1813 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1814 HERMES_TEST_STOP, 0, NULL);
1819 /* Set promiscuity / multicast*/
1820 priv->promiscuous = 0;
1822 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1827 /* FIXME: return int? */
1829 __orinoco_set_multicast_list(struct net_device *dev)
1831 struct orinoco_private *priv = netdev_priv(dev);
1832 hermes_t *hw = &priv->hw;
1834 int promisc, mc_count;
1836 /* The Hermes doesn't seem to have an allmulti mode, so we go
1837 * into promiscuous mode and let the upper levels deal. */
1838 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1839 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1844 mc_count = dev->mc_count;
1847 if (promisc != priv->promiscuous) {
1848 err = hermes_write_wordrec(hw, USER_BAP,
1849 HERMES_RID_CNFPROMISCUOUSMODE,
1852 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1855 priv->promiscuous = promisc;
1858 if (! promisc && (mc_count || priv->mc_count) ) {
1859 struct dev_mc_list *p = dev->mc_list;
1860 struct hermes_multicast mclist;
1863 for (i = 0; i < mc_count; i++) {
1864 /* paranoia: is list shorter than mc_count? */
1866 /* paranoia: bad address size in list? */
1867 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1869 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1874 printk(KERN_WARNING "%s: Multicast list is "
1875 "longer than mc_count\n", dev->name);
1877 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1878 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1881 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1884 priv->mc_count = mc_count;
1887 /* Since we can set the promiscuous flag when it wasn't asked
1888 for, make sure the net_device knows about it. */
1889 if (priv->promiscuous)
1890 dev->flags |= IFF_PROMISC;
1892 dev->flags &= ~IFF_PROMISC;
1895 /* This must be called from user context, without locks held - use
1896 * schedule_work() */
1897 static void orinoco_reset(struct net_device *dev)
1899 struct orinoco_private *priv = netdev_priv(dev);
1900 struct hermes *hw = &priv->hw;
1902 unsigned long flags;
1904 if (orinoco_lock(priv, &flags) != 0)
1905 /* When the hardware becomes available again, whatever
1906 * detects that is responsible for re-initializing
1907 * it. So no need for anything further */
1910 netif_stop_queue(dev);
1912 /* Shut off interrupts. Depending on what state the hardware
1913 * is in, this might not work, but we'll try anyway */
1914 hermes_set_irqmask(hw, 0);
1915 hermes_write_regn(hw, EVACK, 0xffff);
1917 priv->hw_unavailable++;
1918 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1919 netif_carrier_off(dev);
1921 orinoco_unlock(priv, &flags);
1923 /* Scanning support: Cleanup of driver struct */
1924 kfree(priv->scan_result);
1925 priv->scan_result = NULL;
1926 priv->scan_inprogress = 0;
1928 if (priv->hard_reset) {
1929 err = (*priv->hard_reset)(priv);
1931 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1932 "performing hard reset\n", dev->name, err);
1937 err = orinoco_reinit_firmware(dev);
1939 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1944 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1946 priv->hw_unavailable--;
1948 /* priv->open or priv->hw_unavailable might have changed while
1949 * we dropped the lock */
1950 if (priv->open && (! priv->hw_unavailable)) {
1951 err = __orinoco_up(dev);
1953 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1956 dev->trans_start = jiffies;
1959 spin_unlock_irq(&priv->lock);
1963 hermes_set_irqmask(hw, 0);
1964 netif_device_detach(dev);
1965 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1968 /********************************************************************/
1969 /* Interrupt handler */
1970 /********************************************************************/
1972 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1974 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1977 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1979 /* This seems to happen a fair bit under load, but ignoring it
1980 seems to work fine...*/
1981 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1985 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1987 struct net_device *dev = (struct net_device *)dev_id;
1988 struct orinoco_private *priv = netdev_priv(dev);
1989 hermes_t *hw = &priv->hw;
1990 int count = MAX_IRQLOOPS_PER_IRQ;
1992 /* These are used to detect a runaway interrupt situation */
1993 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1994 * we panic and shut down the hardware */
1995 static int last_irq_jiffy = 0; /* jiffies value the last time
1997 static int loops_this_jiffy = 0;
1998 unsigned long flags;
2000 if (orinoco_lock(priv, &flags) != 0) {
2001 /* If hw is unavailable - we don't know if the irq was
2006 evstat = hermes_read_regn(hw, EVSTAT);
2007 events = evstat & hw->inten;
2009 orinoco_unlock(priv, &flags);
2013 if (jiffies != last_irq_jiffy)
2014 loops_this_jiffy = 0;
2015 last_irq_jiffy = jiffies;
2017 while (events && count--) {
2018 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2019 printk(KERN_WARNING "%s: IRQ handler is looping too "
2020 "much! Resetting.\n", dev->name);
2021 /* Disable interrupts for now */
2022 hermes_set_irqmask(hw, 0);
2023 schedule_work(&priv->reset_work);
2027 /* Check the card hasn't been removed */
2028 if (! hermes_present(hw)) {
2029 DEBUG(0, "orinoco_interrupt(): card removed\n");
2033 if (events & HERMES_EV_TICK)
2034 __orinoco_ev_tick(dev, hw);
2035 if (events & HERMES_EV_WTERR)
2036 __orinoco_ev_wterr(dev, hw);
2037 if (events & HERMES_EV_INFDROP)
2038 __orinoco_ev_infdrop(dev, hw);
2039 if (events & HERMES_EV_INFO)
2040 __orinoco_ev_info(dev, hw);
2041 if (events & HERMES_EV_RX)
2042 __orinoco_ev_rx(dev, hw);
2043 if (events & HERMES_EV_TXEXC)
2044 __orinoco_ev_txexc(dev, hw);
2045 if (events & HERMES_EV_TX)
2046 __orinoco_ev_tx(dev, hw);
2047 if (events & HERMES_EV_ALLOC)
2048 __orinoco_ev_alloc(dev, hw);
2050 hermes_write_regn(hw, EVACK, evstat);
2052 evstat = hermes_read_regn(hw, EVSTAT);
2053 events = evstat & hw->inten;
2056 orinoco_unlock(priv, &flags);
2060 /********************************************************************/
2061 /* Initialization */
2062 /********************************************************************/
2065 u16 id, variant, major, minor;
2066 } __attribute__ ((packed));
2068 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2070 if (nic_id->id < 0x8000)
2071 return FIRMWARE_TYPE_AGERE;
2072 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2073 return FIRMWARE_TYPE_SYMBOL;
2075 return FIRMWARE_TYPE_INTERSIL;
2078 /* Set priv->firmware type, determine firmware properties */
2079 static int determine_firmware(struct net_device *dev)
2081 struct orinoco_private *priv = netdev_priv(dev);
2082 hermes_t *hw = &priv->hw;
2084 struct comp_id nic_id, sta_id;
2085 unsigned int firmver;
2086 char tmp[SYMBOL_MAX_VER_LEN+1];
2088 /* Get the hardware version */
2089 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2091 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2096 le16_to_cpus(&nic_id.id);
2097 le16_to_cpus(&nic_id.variant);
2098 le16_to_cpus(&nic_id.major);
2099 le16_to_cpus(&nic_id.minor);
2100 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2101 dev->name, nic_id.id, nic_id.variant,
2102 nic_id.major, nic_id.minor);
2104 priv->firmware_type = determine_firmware_type(&nic_id);
2106 /* Get the firmware version */
2107 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2109 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2114 le16_to_cpus(&sta_id.id);
2115 le16_to_cpus(&sta_id.variant);
2116 le16_to_cpus(&sta_id.major);
2117 le16_to_cpus(&sta_id.minor);
2118 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2119 dev->name, sta_id.id, sta_id.variant,
2120 sta_id.major, sta_id.minor);
2122 switch (sta_id.id) {
2124 printk(KERN_ERR "%s: Primary firmware is active\n",
2128 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2131 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2132 case 0x21: /* Symbol Spectrum24 Trilogy */
2135 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2140 /* Default capabilities */
2141 priv->has_sensitivity = 1;
2143 priv->has_preamble = 0;
2144 priv->has_port3 = 1;
2147 priv->has_big_wep = 0;
2149 /* Determine capabilities from the firmware version */
2150 switch (priv->firmware_type) {
2151 case FIRMWARE_TYPE_AGERE:
2152 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2153 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2154 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2155 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2157 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2159 priv->has_ibss = (firmver >= 0x60006);
2160 priv->has_wep = (firmver >= 0x40020);
2161 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2162 Gold cards from the others? */
2163 priv->has_mwo = (firmver >= 0x60000);
2164 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2165 priv->ibss_port = 1;
2166 priv->has_hostscan = (firmver >= 0x8000a);
2167 priv->broken_monitor = (firmver >= 0x80000);
2169 /* Tested with Agere firmware :
2170 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2171 * Tested CableTron firmware : 4.32 => Anton */
2173 case FIRMWARE_TYPE_SYMBOL:
2174 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2175 /* Intel MAC : 00:02:B3:* */
2176 /* 3Com MAC : 00:50:DA:* */
2177 memset(tmp, 0, sizeof(tmp));
2178 /* Get the Symbol firmware version */
2179 err = hermes_read_ltv(hw, USER_BAP,
2180 HERMES_RID_SECONDARYVERSION_SYMBOL,
2181 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2184 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2189 /* The firmware revision is a string, the format is
2190 * something like : "V2.20-01".
2191 * Quick and dirty parsing... - Jean II
2193 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2194 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2197 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2200 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2203 priv->has_ibss = (firmver >= 0x20000);
2204 priv->has_wep = (firmver >= 0x15012);
2205 priv->has_big_wep = (firmver >= 0x20000);
2206 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2207 (firmver >= 0x29000 && firmver < 0x30000) ||
2209 priv->has_preamble = (firmver >= 0x20000);
2210 priv->ibss_port = 4;
2211 priv->broken_disableport = (firmver == 0x25013) ||
2212 (firmver >= 0x30000 && firmver <= 0x31000);
2213 priv->has_hostscan = (firmver >= 0x31001) ||
2214 (firmver >= 0x29057 && firmver < 0x30000);
2215 /* Tested with Intel firmware : 0x20015 => Jean II */
2216 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2218 case FIRMWARE_TYPE_INTERSIL:
2219 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2220 * Samsung, Compaq 100/200 and Proxim are slightly
2221 * different and less well tested */
2222 /* D-Link MAC : 00:40:05:* */
2223 /* Addtron MAC : 00:90:D1:* */
2224 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2225 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2228 firmver = ((unsigned long)sta_id.major << 16) |
2229 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2231 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2232 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2233 priv->has_pm = (firmver >= 0x000700);
2234 priv->has_hostscan = (firmver >= 0x010301);
2236 if (firmver >= 0x000800)
2237 priv->ibss_port = 0;
2239 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2240 "than v0.8.x - several features not supported\n",
2242 priv->ibss_port = 1;
2246 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2252 static int orinoco_init(struct net_device *dev)
2254 struct orinoco_private *priv = netdev_priv(dev);
2255 hermes_t *hw = &priv->hw;
2257 struct hermes_idstring nickbuf;
2261 TRACE_ENTER(dev->name);
2263 /* No need to lock, the hw_unavailable flag is already set in
2264 * alloc_orinocodev() */
2265 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2267 /* Initialize the firmware */
2268 err = orinoco_reinit_firmware(dev);
2270 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2275 err = determine_firmware(dev);
2277 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2282 if (priv->has_port3)
2283 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2285 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2287 if (priv->has_wep) {
2288 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2289 if (priv->has_big_wep)
2290 printk("104-bit key\n");
2292 printk("40-bit key\n");
2295 /* Get the MAC address */
2296 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2297 ETH_ALEN, NULL, dev->dev_addr);
2299 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2304 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2305 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2306 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2309 /* Get the station name */
2310 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2311 sizeof(nickbuf), &reclen, &nickbuf);
2313 printk(KERN_ERR "%s: failed to read station name\n",
2318 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2320 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2321 memcpy(priv->nick, &nickbuf.val, len);
2322 priv->nick[len] = '\0';
2324 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2326 /* Get allowed channels */
2327 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2328 &priv->channel_mask);
2330 printk(KERN_ERR "%s: failed to read channel list!\n",
2335 /* Get initial AP density */
2336 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2338 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2339 priv->has_sensitivity = 0;
2342 /* Get initial RTS threshold */
2343 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2346 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2351 /* Get initial fragmentation settings */
2353 err = hermes_read_wordrec(hw, USER_BAP,
2354 HERMES_RID_CNFMWOROBUST_AGERE,
2357 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2358 &priv->frag_thresh);
2360 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2365 /* Power management setup */
2369 err = hermes_read_wordrec(hw, USER_BAP,
2370 HERMES_RID_CNFMAXSLEEPDURATION,
2373 printk(KERN_ERR "%s: failed to read power management period!\n",
2377 err = hermes_read_wordrec(hw, USER_BAP,
2378 HERMES_RID_CNFPMHOLDOVERDURATION,
2381 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2387 /* Preamble setup */
2388 if (priv->has_preamble) {
2389 err = hermes_read_wordrec(hw, USER_BAP,
2390 HERMES_RID_CNFPREAMBLE_SYMBOL,
2396 /* Set up the default configuration */
2397 priv->iw_mode = IW_MODE_INFRA;
2398 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2399 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2400 set_port_type(priv);
2401 priv->channel = 0; /* use firmware default */
2403 priv->promiscuous = 0;
2407 /* Make the hardware available, as long as it hasn't been
2408 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2409 spin_lock_irq(&priv->lock);
2410 priv->hw_unavailable--;
2411 spin_unlock_irq(&priv->lock);
2413 printk(KERN_DEBUG "%s: ready\n", dev->name);
2416 TRACE_EXIT(dev->name);
2420 struct net_device *alloc_orinocodev(int sizeof_card,
2421 int (*hard_reset)(struct orinoco_private *))
2423 struct net_device *dev;
2424 struct orinoco_private *priv;
2426 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2429 priv = netdev_priv(dev);
2432 priv->card = (void *)((unsigned long)priv
2433 + sizeof(struct orinoco_private));
2437 /* Setup / override net_device fields */
2438 dev->init = orinoco_init;
2439 dev->hard_start_xmit = orinoco_xmit;
2440 dev->tx_timeout = orinoco_tx_timeout;
2441 dev->watchdog_timeo = HZ; /* 1 second timeout */
2442 dev->get_stats = orinoco_get_stats;
2443 dev->ethtool_ops = &orinoco_ethtool_ops;
2444 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2446 priv->wireless_data.spy_data = &priv->spy_data;
2447 dev->wireless_data = &priv->wireless_data;
2449 dev->change_mtu = orinoco_change_mtu;
2450 dev->set_multicast_list = orinoco_set_multicast_list;
2451 /* we use the default eth_mac_addr for setting the MAC addr */
2453 /* Set up default callbacks */
2454 dev->open = orinoco_open;
2455 dev->stop = orinoco_stop;
2456 priv->hard_reset = hard_reset;
2458 spin_lock_init(&priv->lock);
2460 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2461 * before anything else touches the
2463 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2464 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2465 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2467 netif_carrier_off(dev);
2468 priv->last_linkstatus = 0xffff;
2474 void free_orinocodev(struct net_device *dev)
2476 struct orinoco_private *priv = netdev_priv(dev);
2478 kfree(priv->scan_result);
2482 /********************************************************************/
2483 /* Wireless extensions */
2484 /********************************************************************/
2486 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2487 char buf[IW_ESSID_MAX_SIZE+1])
2489 hermes_t *hw = &priv->hw;
2491 struct hermes_idstring essidbuf;
2492 char *p = (char *)(&essidbuf.val);
2494 unsigned long flags;
2496 if (orinoco_lock(priv, &flags) != 0)
2499 if (strlen(priv->desired_essid) > 0) {
2500 /* We read the desired SSID from the hardware rather
2501 than from priv->desired_essid, just in case the
2502 firmware is allowed to change it on us. I'm not
2504 /* My guess is that the OWNSSID should always be whatever
2505 * we set to the card, whereas CURRENT_SSID is the one that
2506 * may change... - Jean II */
2511 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2512 HERMES_RID_CNFDESIREDSSID;
2514 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2521 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2522 sizeof(essidbuf), NULL, &essidbuf);
2527 len = le16_to_cpu(essidbuf.len);
2528 BUG_ON(len > IW_ESSID_MAX_SIZE);
2530 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2531 memcpy(buf, p, len);
2535 orinoco_unlock(priv, &flags);
2540 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2543 hermes_t *hw = &priv->hw;
2547 unsigned long flags;
2549 if (orinoco_lock(priv, &flags) != 0)
2552 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2556 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2562 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2563 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2564 priv->ndev->name, channel);
2569 freq = channel_frequency[channel-1] * 100000;
2572 orinoco_unlock(priv, &flags);
2576 return err ? err : freq;
2579 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2580 int *numrates, s32 *rates, int max)
2582 hermes_t *hw = &priv->hw;
2583 struct hermes_idstring list;
2584 unsigned char *p = (unsigned char *)&list.val;
2588 unsigned long flags;
2590 if (orinoco_lock(priv, &flags) != 0)
2593 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2594 sizeof(list), NULL, &list);
2595 orinoco_unlock(priv, &flags);
2600 num = le16_to_cpu(list.len);
2602 num = min(num, max);
2604 for (i = 0; i < num; i++) {
2605 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2611 static int orinoco_ioctl_getname(struct net_device *dev,
2612 struct iw_request_info *info,
2616 struct orinoco_private *priv = netdev_priv(dev);
2620 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2622 if (!err && (numrates > 2))
2623 strcpy(name, "IEEE 802.11b");
2625 strcpy(name, "IEEE 802.11-DS");
2630 static int orinoco_ioctl_setwap(struct net_device *dev,
2631 struct iw_request_info *info,
2632 struct sockaddr *ap_addr,
2635 struct orinoco_private *priv = netdev_priv(dev);
2636 int err = -EINPROGRESS; /* Call commit handler */
2637 unsigned long flags;
2638 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2639 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2641 if (orinoco_lock(priv, &flags) != 0)
2644 /* Enable automatic roaming - no sanity checks are needed */
2645 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2646 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2647 priv->bssid_fixed = 0;
2648 memset(priv->desired_bssid, 0, ETH_ALEN);
2650 /* "off" means keep existing connection */
2651 if (ap_addr->sa_data[0] == 0) {
2652 __orinoco_hw_set_wap(priv);
2658 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2659 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2660 "support manual roaming\n",
2666 if (priv->iw_mode != IW_MODE_INFRA) {
2667 printk(KERN_WARNING "%s: Manual roaming supported only in "
2668 "managed mode\n", dev->name);
2673 /* Intersil firmware hangs without Desired ESSID */
2674 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2675 strlen(priv->desired_essid) == 0) {
2676 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2677 "manual roaming\n", dev->name);
2682 /* Finally, enable manual roaming */
2683 priv->bssid_fixed = 1;
2684 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2687 orinoco_unlock(priv, &flags);
2691 static int orinoco_ioctl_getwap(struct net_device *dev,
2692 struct iw_request_info *info,
2693 struct sockaddr *ap_addr,
2696 struct orinoco_private *priv = netdev_priv(dev);
2698 hermes_t *hw = &priv->hw;
2700 unsigned long flags;
2702 if (orinoco_lock(priv, &flags) != 0)
2705 ap_addr->sa_family = ARPHRD_ETHER;
2706 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2707 ETH_ALEN, NULL, ap_addr->sa_data);
2709 orinoco_unlock(priv, &flags);
2714 static int orinoco_ioctl_setmode(struct net_device *dev,
2715 struct iw_request_info *info,
2719 struct orinoco_private *priv = netdev_priv(dev);
2720 int err = -EINPROGRESS; /* Call commit handler */
2721 unsigned long flags;
2723 if (priv->iw_mode == *mode)
2726 if (orinoco_lock(priv, &flags) != 0)
2731 if (!priv->has_ibss && !priv->has_port3)
2738 case IW_MODE_MONITOR:
2739 if (priv->broken_monitor && !force_monitor) {
2740 printk(KERN_WARNING "%s: Monitor mode support is "
2741 "buggy in this firmware, not enabling\n",
2752 if (err == -EINPROGRESS) {
2753 priv->iw_mode = *mode;
2754 set_port_type(priv);
2757 orinoco_unlock(priv, &flags);
2762 static int orinoco_ioctl_getmode(struct net_device *dev,
2763 struct iw_request_info *info,
2767 struct orinoco_private *priv = netdev_priv(dev);
2769 *mode = priv->iw_mode;
2773 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2774 struct iw_request_info *info,
2775 struct iw_point *rrq,
2778 struct orinoco_private *priv = netdev_priv(dev);
2780 struct iw_range *range = (struct iw_range *) extra;
2784 TRACE_ENTER(dev->name);
2786 rrq->length = sizeof(struct iw_range);
2787 memset(range, 0, sizeof(struct iw_range));
2789 range->we_version_compiled = WIRELESS_EXT;
2790 range->we_version_source = 14;
2792 /* Set available channels/frequencies */
2793 range->num_channels = NUM_CHANNELS;
2795 for (i = 0; i < NUM_CHANNELS; i++) {
2796 if (priv->channel_mask & (1 << i)) {
2797 range->freq[k].i = i + 1;
2798 range->freq[k].m = channel_frequency[i] * 100000;
2799 range->freq[k].e = 1;
2803 if (k >= IW_MAX_FREQUENCIES)
2806 range->num_frequency = k;
2807 range->sensitivity = 3;
2809 if (priv->has_wep) {
2810 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2811 range->encoding_size[0] = SMALL_KEY_SIZE;
2812 range->num_encoding_sizes = 1;
2814 if (priv->has_big_wep) {
2815 range->encoding_size[1] = LARGE_KEY_SIZE;
2816 range->num_encoding_sizes = 2;
2820 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2821 /* Quality stats meaningless in ad-hoc mode */
2823 range->max_qual.qual = 0x8b - 0x2f;
2824 range->max_qual.level = 0x2f - 0x95 - 1;
2825 range->max_qual.noise = 0x2f - 0x95 - 1;
2826 /* Need to get better values */
2827 range->avg_qual.qual = 0x24;
2828 range->avg_qual.level = 0xC2;
2829 range->avg_qual.noise = 0x9E;
2832 err = orinoco_hw_get_bitratelist(priv, &numrates,
2833 range->bitrate, IW_MAX_BITRATES);
2836 range->num_bitrates = numrates;
2838 /* Set an indication of the max TCP throughput in bit/s that we can
2839 * expect using this interface. May be use for QoS stuff...
2842 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2844 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2847 range->max_rts = 2347;
2848 range->min_frag = 256;
2849 range->max_frag = 2346;
2852 range->max_pmp = 65535000;
2854 range->max_pmt = 65535 * 1000; /* ??? */
2855 range->pmp_flags = IW_POWER_PERIOD;
2856 range->pmt_flags = IW_POWER_TIMEOUT;
2857 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2859 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2860 range->retry_flags = IW_RETRY_LIMIT;
2861 range->r_time_flags = IW_RETRY_LIFETIME;
2862 range->min_retry = 0;
2863 range->max_retry = 65535; /* ??? */
2864 range->min_r_time = 0;
2865 range->max_r_time = 65535 * 1000; /* ??? */
2867 /* Event capability (kernel) */
2868 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2869 /* Event capability (driver) */
2870 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2871 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2872 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2873 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2875 TRACE_EXIT(dev->name);
2880 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2881 struct iw_request_info *info,
2882 struct iw_point *erq,
2885 struct orinoco_private *priv = netdev_priv(dev);
2886 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2887 int setindex = priv->tx_key;
2888 int enable = priv->wep_on;
2889 int restricted = priv->wep_restrict;
2891 int err = -EINPROGRESS; /* Call commit handler */
2892 unsigned long flags;
2894 if (! priv->has_wep)
2898 /* We actually have a key to set - check its length */
2899 if (erq->length > LARGE_KEY_SIZE)
2902 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2906 if (orinoco_lock(priv, &flags) != 0)
2910 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2911 index = priv->tx_key;
2913 /* Adjust key length to a supported value */
2914 if (erq->length > SMALL_KEY_SIZE) {
2915 xlen = LARGE_KEY_SIZE;
2916 } else if (erq->length > 0) {
2917 xlen = SMALL_KEY_SIZE;
2921 /* Switch on WEP if off */
2922 if ((!enable) && (xlen > 0)) {
2927 /* Important note : if the user do "iwconfig eth0 enc off",
2928 * we will arrive there with an index of -1. This is valid
2929 * but need to be taken care off... Jean II */
2930 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2931 if((index != -1) || (erq->flags == 0)) {
2936 /* Set the index : Check that the key is valid */
2937 if(priv->keys[index].len == 0) {
2945 if (erq->flags & IW_ENCODE_DISABLED)
2947 if (erq->flags & IW_ENCODE_OPEN)
2949 if (erq->flags & IW_ENCODE_RESTRICTED)
2953 priv->keys[index].len = cpu_to_le16(xlen);
2954 memset(priv->keys[index].data, 0,
2955 sizeof(priv->keys[index].data));
2956 memcpy(priv->keys[index].data, keybuf, erq->length);
2958 priv->tx_key = setindex;
2960 /* Try fast key change if connected and only keys are changed */
2961 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2962 netif_carrier_ok(dev)) {
2963 err = __orinoco_hw_setup_wepkeys(priv);
2964 /* No need to commit if successful */
2968 priv->wep_on = enable;
2969 priv->wep_restrict = restricted;
2972 orinoco_unlock(priv, &flags);
2977 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2978 struct iw_request_info *info,
2979 struct iw_point *erq,
2982 struct orinoco_private *priv = netdev_priv(dev);
2983 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2985 unsigned long flags;
2987 if (! priv->has_wep)
2990 if (orinoco_lock(priv, &flags) != 0)
2993 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2994 index = priv->tx_key;
2998 erq->flags |= IW_ENCODE_DISABLED;
2999 erq->flags |= index + 1;
3001 if (priv->wep_restrict)
3002 erq->flags |= IW_ENCODE_RESTRICTED;
3004 erq->flags |= IW_ENCODE_OPEN;
3006 xlen = le16_to_cpu(priv->keys[index].len);
3010 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3012 orinoco_unlock(priv, &flags);
3016 static int orinoco_ioctl_setessid(struct net_device *dev,
3017 struct iw_request_info *info,
3018 struct iw_point *erq,
3021 struct orinoco_private *priv = netdev_priv(dev);
3022 unsigned long flags;
3024 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3025 * anyway... - Jean II */
3027 /* Hum... Should not use Wireless Extension constant (may change),
3028 * should use our own... - Jean II */
3029 if (erq->length > IW_ESSID_MAX_SIZE)
3032 if (orinoco_lock(priv, &flags) != 0)
3035 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3036 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3038 /* If not ANY, get the new ESSID */
3040 memcpy(priv->desired_essid, essidbuf, erq->length);
3043 orinoco_unlock(priv, &flags);
3045 return -EINPROGRESS; /* Call commit handler */
3048 static int orinoco_ioctl_getessid(struct net_device *dev,
3049 struct iw_request_info *info,
3050 struct iw_point *erq,
3053 struct orinoco_private *priv = netdev_priv(dev);
3056 unsigned long flags;
3058 TRACE_ENTER(dev->name);
3060 if (netif_running(dev)) {
3061 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3065 if (orinoco_lock(priv, &flags) != 0)
3067 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3068 orinoco_unlock(priv, &flags);
3072 erq->length = strlen(essidbuf) + 1;
3074 TRACE_EXIT(dev->name);
3079 static int orinoco_ioctl_setnick(struct net_device *dev,
3080 struct iw_request_info *info,
3081 struct iw_point *nrq,
3084 struct orinoco_private *priv = netdev_priv(dev);
3085 unsigned long flags;
3087 if (nrq->length > IW_ESSID_MAX_SIZE)
3090 if (orinoco_lock(priv, &flags) != 0)
3093 memset(priv->nick, 0, sizeof(priv->nick));
3094 memcpy(priv->nick, nickbuf, nrq->length);
3096 orinoco_unlock(priv, &flags);
3098 return -EINPROGRESS; /* Call commit handler */
3101 static int orinoco_ioctl_getnick(struct net_device *dev,
3102 struct iw_request_info *info,
3103 struct iw_point *nrq,
3106 struct orinoco_private *priv = netdev_priv(dev);
3107 unsigned long flags;
3109 if (orinoco_lock(priv, &flags) != 0)
3112 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3113 orinoco_unlock(priv, &flags);
3115 nrq->length = strlen(nickbuf)+1;
3120 static int orinoco_ioctl_setfreq(struct net_device *dev,
3121 struct iw_request_info *info,
3122 struct iw_freq *frq,
3125 struct orinoco_private *priv = netdev_priv(dev);
3127 unsigned long flags;
3128 int err = -EINPROGRESS; /* Call commit handler */
3130 /* In infrastructure mode the AP sets the channel */
3131 if (priv->iw_mode == IW_MODE_INFRA)
3134 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3135 /* Setting by channel number */
3138 /* Setting by frequency - search the table */
3142 for (i = 0; i < (6 - frq->e); i++)
3145 for (i = 0; i < NUM_CHANNELS; i++)
3146 if (frq->m == (channel_frequency[i] * mult))
3150 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3151 ! (priv->channel_mask & (1 << (chan-1)) ) )
3154 if (orinoco_lock(priv, &flags) != 0)
3157 priv->channel = chan;
3158 if (priv->iw_mode == IW_MODE_MONITOR) {
3159 /* Fast channel change - no commit if successful */
3160 hermes_t *hw = &priv->hw;
3161 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3162 HERMES_TEST_SET_CHANNEL,
3165 orinoco_unlock(priv, &flags);
3170 static int orinoco_ioctl_getfreq(struct net_device *dev,
3171 struct iw_request_info *info,
3172 struct iw_freq *frq,
3175 struct orinoco_private *priv = netdev_priv(dev);
3178 /* Locking done in there */
3179 tmp = orinoco_hw_get_freq(priv);
3190 static int orinoco_ioctl_getsens(struct net_device *dev,
3191 struct iw_request_info *info,
3192 struct iw_param *srq,
3195 struct orinoco_private *priv = netdev_priv(dev);
3196 hermes_t *hw = &priv->hw;
3199 unsigned long flags;
3201 if (!priv->has_sensitivity)
3204 if (orinoco_lock(priv, &flags) != 0)
3206 err = hermes_read_wordrec(hw, USER_BAP,
3207 HERMES_RID_CNFSYSTEMSCALE, &val);
3208 orinoco_unlock(priv, &flags);
3214 srq->fixed = 0; /* auto */
3219 static int orinoco_ioctl_setsens(struct net_device *dev,
3220 struct iw_request_info *info,
3221 struct iw_param *srq,
3224 struct orinoco_private *priv = netdev_priv(dev);
3225 int val = srq->value;
3226 unsigned long flags;
3228 if (!priv->has_sensitivity)
3231 if ((val < 1) || (val > 3))
3234 if (orinoco_lock(priv, &flags) != 0)
3236 priv->ap_density = val;
3237 orinoco_unlock(priv, &flags);
3239 return -EINPROGRESS; /* Call commit handler */
3242 static int orinoco_ioctl_setrts(struct net_device *dev,
3243 struct iw_request_info *info,
3244 struct iw_param *rrq,
3247 struct orinoco_private *priv = netdev_priv(dev);
3248 int val = rrq->value;
3249 unsigned long flags;
3254 if ( (val < 0) || (val > 2347) )
3257 if (orinoco_lock(priv, &flags) != 0)
3260 priv->rts_thresh = val;
3261 orinoco_unlock(priv, &flags);
3263 return -EINPROGRESS; /* Call commit handler */
3266 static int orinoco_ioctl_getrts(struct net_device *dev,
3267 struct iw_request_info *info,
3268 struct iw_param *rrq,
3271 struct orinoco_private *priv = netdev_priv(dev);
3273 rrq->value = priv->rts_thresh;
3274 rrq->disabled = (rrq->value == 2347);
3280 static int orinoco_ioctl_setfrag(struct net_device *dev,
3281 struct iw_request_info *info,
3282 struct iw_param *frq,
3285 struct orinoco_private *priv = netdev_priv(dev);
3286 int err = -EINPROGRESS; /* Call commit handler */
3287 unsigned long flags;
3289 if (orinoco_lock(priv, &flags) != 0)
3292 if (priv->has_mwo) {
3294 priv->mwo_robust = 0;
3297 printk(KERN_WARNING "%s: Fixed fragmentation is "
3298 "not supported on this firmware. "
3299 "Using MWO robust instead.\n", dev->name);
3300 priv->mwo_robust = 1;
3304 priv->frag_thresh = 2346;
3306 if ( (frq->value < 256) || (frq->value > 2346) )
3309 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3313 orinoco_unlock(priv, &flags);
3318 static int orinoco_ioctl_getfrag(struct net_device *dev,
3319 struct iw_request_info *info,
3320 struct iw_param *frq,
3323 struct orinoco_private *priv = netdev_priv(dev);
3324 hermes_t *hw = &priv->hw;
3327 unsigned long flags;
3329 if (orinoco_lock(priv, &flags) != 0)
3332 if (priv->has_mwo) {
3333 err = hermes_read_wordrec(hw, USER_BAP,
3334 HERMES_RID_CNFMWOROBUST_AGERE,
3339 frq->value = val ? 2347 : 0;
3340 frq->disabled = ! val;
3343 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3349 frq->disabled = (val >= 2346);
3353 orinoco_unlock(priv, &flags);
3358 static int orinoco_ioctl_setrate(struct net_device *dev,
3359 struct iw_request_info *info,
3360 struct iw_param *rrq,
3363 struct orinoco_private *priv = netdev_priv(dev);
3365 int bitrate; /* 100s of kilobits */
3367 unsigned long flags;
3369 /* As the user space doesn't know our highest rate, it uses -1
3370 * to ask us to set the highest rate. Test it using "iwconfig
3371 * ethX rate auto" - Jean II */
3372 if (rrq->value == -1)
3375 if (rrq->value % 100000)
3377 bitrate = rrq->value / 100000;
3380 if ( (bitrate != 10) && (bitrate != 20) &&
3381 (bitrate != 55) && (bitrate != 110) )
3384 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3385 if ( (bitrate_table[i].bitrate == bitrate) &&
3386 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3394 if (orinoco_lock(priv, &flags) != 0)
3396 priv->bitratemode = ratemode;
3397 orinoco_unlock(priv, &flags);
3399 return -EINPROGRESS;
3402 static int orinoco_ioctl_getrate(struct net_device *dev,
3403 struct iw_request_info *info,
3404 struct iw_param *rrq,
3407 struct orinoco_private *priv = netdev_priv(dev);
3408 hermes_t *hw = &priv->hw;
3413 unsigned long flags;
3415 if (orinoco_lock(priv, &flags) != 0)
3418 ratemode = priv->bitratemode;
3420 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3422 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3423 rrq->fixed = ! bitrate_table[ratemode].automatic;
3426 /* If the interface is running we try to find more about the
3428 if (netif_running(dev)) {
3429 err = hermes_read_wordrec(hw, USER_BAP,
3430 HERMES_RID_CURRENTTXRATE, &val);
3434 switch (priv->firmware_type) {
3435 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3436 /* Note : in Lucent firmware, the return value of
3437 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3438 * and therefore is totally different from the
3439 * encoding of HERMES_RID_CNFTXRATECONTROL.
3440 * Don't forget that 6Mb/s is really 5.5Mb/s */
3442 rrq->value = 5500000;
3444 rrq->value = val * 1000000;
3446 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3447 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3448 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3449 if (bitrate_table[i].intersil_txratectrl == val) {
3453 if (i >= BITRATE_TABLE_SIZE)
3454 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3457 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3465 orinoco_unlock(priv, &flags);
3470 static int orinoco_ioctl_setpower(struct net_device *dev,
3471 struct iw_request_info *info,
3472 struct iw_param *prq,
3475 struct orinoco_private *priv = netdev_priv(dev);
3476 int err = -EINPROGRESS; /* Call commit handler */
3477 unsigned long flags;
3479 if (orinoco_lock(priv, &flags) != 0)
3482 if (prq->disabled) {
3485 switch (prq->flags & IW_POWER_MODE) {
3486 case IW_POWER_UNICAST_R:
3490 case IW_POWER_ALL_R:
3495 /* No flags : but we may have a value - Jean II */
3503 if (prq->flags & IW_POWER_TIMEOUT) {
3505 priv->pm_timeout = prq->value / 1000;
3507 if (prq->flags & IW_POWER_PERIOD) {
3509 priv->pm_period = prq->value / 1000;
3511 /* It's valid to not have a value if we are just toggling
3512 * the flags... Jean II */
3520 orinoco_unlock(priv, &flags);
3525 static int orinoco_ioctl_getpower(struct net_device *dev,
3526 struct iw_request_info *info,
3527 struct iw_param *prq,
3530 struct orinoco_private *priv = netdev_priv(dev);
3531 hermes_t *hw = &priv->hw;
3533 u16 enable, period, timeout, mcast;
3534 unsigned long flags;
3536 if (orinoco_lock(priv, &flags) != 0)
3539 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3543 err = hermes_read_wordrec(hw, USER_BAP,
3544 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3548 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3552 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3556 prq->disabled = !enable;
3557 /* Note : by default, display the period */
3558 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3559 prq->flags = IW_POWER_TIMEOUT;
3560 prq->value = timeout * 1000;
3562 prq->flags = IW_POWER_PERIOD;
3563 prq->value = period * 1000;
3566 prq->flags |= IW_POWER_ALL_R;
3568 prq->flags |= IW_POWER_UNICAST_R;
3571 orinoco_unlock(priv, &flags);
3576 static int orinoco_ioctl_getretry(struct net_device *dev,
3577 struct iw_request_info *info,
3578 struct iw_param *rrq,
3581 struct orinoco_private *priv = netdev_priv(dev);
3582 hermes_t *hw = &priv->hw;
3584 u16 short_limit, long_limit, lifetime;
3585 unsigned long flags;
3587 if (orinoco_lock(priv, &flags) != 0)
3590 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3595 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3600 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3605 rrq->disabled = 0; /* Can't be disabled */
3607 /* Note : by default, display the retry number */
3608 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3609 rrq->flags = IW_RETRY_LIFETIME;
3610 rrq->value = lifetime * 1000; /* ??? */
3612 /* By default, display the min number */
3613 if ((rrq->flags & IW_RETRY_MAX)) {
3614 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3615 rrq->value = long_limit;
3617 rrq->flags = IW_RETRY_LIMIT;
3618 rrq->value = short_limit;
3619 if(short_limit != long_limit)
3620 rrq->flags |= IW_RETRY_MIN;
3625 orinoco_unlock(priv, &flags);
3630 static int orinoco_ioctl_reset(struct net_device *dev,
3631 struct iw_request_info *info,
3635 struct orinoco_private *priv = netdev_priv(dev);
3637 if (! capable(CAP_NET_ADMIN))
3640 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3641 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3643 /* Firmware reset */
3646 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3648 schedule_work(&priv->reset_work);
3654 static int orinoco_ioctl_setibssport(struct net_device *dev,
3655 struct iw_request_info *info,
3660 struct orinoco_private *priv = netdev_priv(dev);
3661 int val = *( (int *) extra );
3662 unsigned long flags;
3664 if (orinoco_lock(priv, &flags) != 0)
3667 priv->ibss_port = val ;
3669 /* Actually update the mode we are using */
3670 set_port_type(priv);
3672 orinoco_unlock(priv, &flags);
3673 return -EINPROGRESS; /* Call commit handler */
3676 static int orinoco_ioctl_getibssport(struct net_device *dev,
3677 struct iw_request_info *info,
3681 struct orinoco_private *priv = netdev_priv(dev);
3682 int *val = (int *) extra;
3684 *val = priv->ibss_port;
3688 static int orinoco_ioctl_setport3(struct net_device *dev,
3689 struct iw_request_info *info,
3693 struct orinoco_private *priv = netdev_priv(dev);
3694 int val = *( (int *) extra );
3696 unsigned long flags;
3698 if (orinoco_lock(priv, &flags) != 0)
3702 case 0: /* Try to do IEEE ad-hoc mode */
3703 if (! priv->has_ibss) {
3707 priv->prefer_port3 = 0;
3711 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3712 if (! priv->has_port3) {
3716 priv->prefer_port3 = 1;
3724 /* Actually update the mode we are using */
3725 set_port_type(priv);
3729 orinoco_unlock(priv, &flags);
3734 static int orinoco_ioctl_getport3(struct net_device *dev,
3735 struct iw_request_info *info,
3739 struct orinoco_private *priv = netdev_priv(dev);
3740 int *val = (int *) extra;
3742 *val = priv->prefer_port3;
3746 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3747 struct iw_request_info *info,
3751 struct orinoco_private *priv = netdev_priv(dev);
3752 unsigned long flags;
3755 if (! priv->has_preamble)
3758 /* 802.11b has recently defined some short preamble.
3759 * Basically, the Phy header has been reduced in size.
3760 * This increase performance, especially at high rates
3761 * (the preamble is transmitted at 1Mb/s), unfortunately
3762 * this give compatibility troubles... - Jean II */
3763 val = *( (int *) extra );
3765 if (orinoco_lock(priv, &flags) != 0)
3773 orinoco_unlock(priv, &flags);
3775 return -EINPROGRESS; /* Call commit handler */
3778 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3779 struct iw_request_info *info,
3783 struct orinoco_private *priv = netdev_priv(dev);
3784 int *val = (int *) extra;
3786 if (! priv->has_preamble)
3789 *val = priv->preamble;
3793 /* ioctl interface to hermes_read_ltv()
3794 * To use with iwpriv, pass the RID as the token argument, e.g.
3795 * iwpriv get_rid [0xfc00]
3796 * At least Wireless Tools 25 is required to use iwpriv.
3797 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3798 static int orinoco_ioctl_getrid(struct net_device *dev,
3799 struct iw_request_info *info,
3800 struct iw_point *data,
3803 struct orinoco_private *priv = netdev_priv(dev);
3804 hermes_t *hw = &priv->hw;
3805 int rid = data->flags;
3808 unsigned long flags;
3810 /* It's a "get" function, but we don't want users to access the
3811 * WEP key and other raw firmware data */
3812 if (! capable(CAP_NET_ADMIN))
3815 if (rid < 0xfc00 || rid > 0xffff)
3818 if (orinoco_lock(priv, &flags) != 0)
3821 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3826 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3830 orinoco_unlock(priv, &flags);
3834 /* Trigger a scan (look for other cells in the vicinity */
3835 static int orinoco_ioctl_setscan(struct net_device *dev,
3836 struct iw_request_info *info,
3837 struct iw_param *srq,
3840 struct orinoco_private *priv = netdev_priv(dev);
3841 hermes_t *hw = &priv->hw;
3843 unsigned long flags;
3845 /* Note : you may have realised that, as this is a SET operation,
3846 * this is priviledged and therefore a normal user can't
3848 * This is not an error, while the device perform scanning,
3849 * traffic doesn't flow, so it's a perfect DoS...
3852 if (orinoco_lock(priv, &flags) != 0)
3855 /* Scanning with port 0 disabled would fail */
3856 if (!netif_running(dev)) {
3861 /* In monitor mode, the scan results are always empty.
3862 * Probe responses are passed to the driver as received
3863 * frames and could be processed in software. */
3864 if (priv->iw_mode == IW_MODE_MONITOR) {
3869 /* Note : because we don't lock out the irq handler, the way
3870 * we access scan variables in priv is critical.
3871 * o scan_inprogress : not touched by irq handler
3872 * o scan_mode : not touched by irq handler
3873 * o scan_result : irq is strict producer, non-irq is strict
3875 * o scan_len : synchronised with scan_result
3876 * Before modifying anything on those variables, please think hard !
3879 /* If there is still some left-over scan results, get rid of it */
3880 if (priv->scan_result != NULL) {
3881 /* What's likely is that a client did crash or was killed
3882 * between triggering the scan request and reading the
3883 * results, so we need to reset everything.
3884 * Some clients that are too slow may suffer from that...
3886 kfree(priv->scan_result);
3887 priv->scan_result = NULL;
3891 priv->scan_mode = srq->flags;
3893 /* Always trigger scanning, even if it's in progress.
3894 * This way, if the info frame get lost, we will recover somewhat
3895 * gracefully - Jean II */
3897 if (priv->has_hostscan) {
3898 switch (priv->firmware_type) {
3899 case FIRMWARE_TYPE_SYMBOL:
3900 err = hermes_write_wordrec(hw, USER_BAP,
3901 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3902 HERMES_HOSTSCAN_SYMBOL_ONCE |
3903 HERMES_HOSTSCAN_SYMBOL_BCAST);
3905 case FIRMWARE_TYPE_INTERSIL: {
3908 req[0] = cpu_to_le16(0x3fff); /* All channels */
3909 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3910 req[2] = 0; /* Any ESSID */
3911 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3912 HERMES_RID_CNFHOSTSCAN, &req);
3915 case FIRMWARE_TYPE_AGERE:
3916 err = hermes_write_wordrec(hw, USER_BAP,
3917 HERMES_RID_CNFSCANSSID_AGERE,
3922 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3926 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3928 /* One more client */
3930 priv->scan_inprogress = 1;
3933 orinoco_unlock(priv, &flags);
3937 /* Translate scan data returned from the card to a card independant
3938 * format that the Wireless Tools will understand - Jean II
3939 * Return message length or -errno for fatal errors */
3940 static inline int orinoco_translate_scan(struct net_device *dev,
3945 struct orinoco_private *priv = netdev_priv(dev);
3946 int offset; /* In the scan data */
3947 union hermes_scan_info *atom;
3951 struct iw_event iwe; /* Temporary buffer */
3952 char * current_ev = buffer;
3953 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3955 switch (priv->firmware_type) {
3956 case FIRMWARE_TYPE_AGERE:
3957 atom_len = sizeof(struct agere_scan_apinfo);
3960 case FIRMWARE_TYPE_SYMBOL:
3961 /* Lack of documentation necessitates this hack.
3962 * Different firmwares have 68 or 76 byte long atoms.
3963 * We try modulo first. If the length divides by both,
3964 * we check what would be the channel in the second
3965 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3966 * Valid channel cannot be 0. */
3969 else if (scan_len % 68)
3971 else if (scan_len >= 1292 && scan[68] == 0)
3977 case FIRMWARE_TYPE_INTERSIL:
3979 if (priv->has_hostscan) {
3980 atom_len = le16_to_cpup((u16 *)scan);
3981 /* Sanity check for atom_len */
3982 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3983 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3984 dev->name, atom_len);
3988 atom_len = offsetof(struct prism2_scan_apinfo, atim);
3994 /* Check that we got an whole number of atoms */
3995 if ((scan_len - offset) % atom_len) {
3996 printk(KERN_ERR "%s: Unexpected scan data length %d, "
3997 "atom_len %d, offset %d\n", dev->name, scan_len,
4002 /* Read the entries one by one */
4003 for (; offset + atom_len <= scan_len; offset += atom_len) {
4005 atom = (union hermes_scan_info *) (scan + offset);
4007 /* First entry *MUST* be the AP MAC address */
4008 iwe.cmd = SIOCGIWAP;
4009 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4010 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4011 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4013 /* Other entries will be displayed in the order we give them */
4016 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4017 if (iwe.u.data.length > 32)
4018 iwe.u.data.length = 32;
4019 iwe.cmd = SIOCGIWESSID;
4020 iwe.u.data.flags = 1;
4021 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4024 iwe.cmd = SIOCGIWMODE;
4025 capabilities = le16_to_cpu(atom->a.capabilities);
4026 if (capabilities & 0x3) {
4027 if (capabilities & 0x1)
4028 iwe.u.mode = IW_MODE_MASTER;
4030 iwe.u.mode = IW_MODE_ADHOC;
4031 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4034 channel = atom->s.channel;
4035 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4037 iwe.cmd = SIOCGIWFREQ;
4038 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4040 current_ev = iwe_stream_add_event(current_ev, end_buf,
4041 &iwe, IW_EV_FREQ_LEN);
4044 /* Add quality statistics */
4046 iwe.u.qual.updated = 0x10; /* no link quality */
4047 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4048 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4049 /* Wireless tools prior to 27.pre22 will show link quality
4050 * anyway, so we provide a reasonable value. */
4051 if (iwe.u.qual.level > iwe.u.qual.noise)
4052 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4054 iwe.u.qual.qual = 0;
4055 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4057 /* Add encryption capability */
4058 iwe.cmd = SIOCGIWENCODE;
4059 if (capabilities & 0x10)
4060 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4062 iwe.u.data.flags = IW_ENCODE_DISABLED;
4063 iwe.u.data.length = 0;
4064 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4066 /* Bit rate is not available in Lucent/Agere firmwares */
4067 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4068 char * current_val = current_ev + IW_EV_LCP_LEN;
4072 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4077 iwe.cmd = SIOCGIWRATE;
4078 /* Those two flags are ignored... */
4079 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4081 for (i = 0; i < 10; i += step) {
4082 /* NULL terminated */
4083 if (atom->p.rates[i] == 0x0)
4085 /* Bit rate given in 500 kb/s units (+ 0x80) */
4086 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4087 current_val = iwe_stream_add_value(current_ev, current_val,
4091 /* Check if we added any event */
4092 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4093 current_ev = current_val;
4096 /* The other data in the scan result are not really
4097 * interesting, so for now drop it - Jean II */
4099 return current_ev - buffer;
4102 /* Return results of a scan */
4103 static int orinoco_ioctl_getscan(struct net_device *dev,
4104 struct iw_request_info *info,
4105 struct iw_point *srq,
4108 struct orinoco_private *priv = netdev_priv(dev);
4110 unsigned long flags;
4112 if (orinoco_lock(priv, &flags) != 0)
4115 /* If no results yet, ask to try again later */
4116 if (priv->scan_result == NULL) {
4117 if (priv->scan_inprogress)
4118 /* Important note : we don't want to block the caller
4119 * until results are ready for various reasons.
4120 * First, managing wait queues is complex and racy.
4121 * Second, we grab some rtnetlink lock before comming
4122 * here (in dev_ioctl()).
4123 * Third, we generate an Wireless Event, so the
4124 * caller can wait itself on that - Jean II */
4127 /* Client error, no scan results...
4128 * The caller need to restart the scan. */
4131 /* We have some results to push back to user space */
4133 /* Translate to WE format */
4134 int ret = orinoco_translate_scan(dev, extra,
4140 kfree(priv->scan_result);
4141 priv->scan_result = NULL;
4146 srq->flags = (__u16) priv->scan_mode;
4148 /* In any case, Scan results will be cleaned up in the
4149 * reset function and when exiting the driver.
4150 * The person triggering the scanning may never come to
4151 * pick the results, so we need to do it in those places.
4154 #ifdef SCAN_SINGLE_READ
4155 /* If you enable this option, only one client (the first
4156 * one) will be able to read the result (and only one
4157 * time). If there is multiple concurent clients that
4158 * want to read scan results, this behavior is not
4159 * advisable - Jean II */
4160 kfree(priv->scan_result);
4161 priv->scan_result = NULL;
4162 #endif /* SCAN_SINGLE_READ */
4163 /* Here, if too much time has elapsed since last scan,
4164 * we may want to clean up scan results... - Jean II */
4167 /* Scan is no longer in progress */
4168 priv->scan_inprogress = 0;
4171 orinoco_unlock(priv, &flags);
4175 /* Commit handler, called after set operations */
4176 static int orinoco_ioctl_commit(struct net_device *dev,
4177 struct iw_request_info *info,
4181 struct orinoco_private *priv = netdev_priv(dev);
4182 struct hermes *hw = &priv->hw;
4183 unsigned long flags;
4189 if (priv->broken_disableport) {
4194 if (orinoco_lock(priv, &flags) != 0)
4197 err = hermes_disable_port(hw, 0);
4199 printk(KERN_WARNING "%s: Unable to disable port "
4200 "while reconfiguring card\n", dev->name);
4201 priv->broken_disableport = 1;
4205 err = __orinoco_program_rids(dev);
4207 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4212 err = hermes_enable_port(hw, 0);
4214 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4221 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4222 schedule_work(&priv->reset_work);
4226 orinoco_unlock(priv, &flags);
4230 static const struct iw_priv_args orinoco_privtab[] = {
4231 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4232 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4233 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4235 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4237 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4238 0, "set_preamble" },
4239 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4241 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4242 0, "set_ibssport" },
4243 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4245 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4251 * Structures to export the Wireless Handlers
4254 static const iw_handler orinoco_handler[] = {
4255 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4256 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4257 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4258 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4259 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4260 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4261 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4262 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4263 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4264 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4265 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4266 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4267 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4268 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4269 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4270 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4271 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4272 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4273 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4274 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4275 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4276 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4277 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4278 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4279 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4280 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4281 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4282 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4283 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4284 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4285 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4286 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4291 Added typecasting since we no longer use iwreq_data -- Moustafa
4293 static const iw_handler orinoco_private_handler[] = {
4294 [0] = (iw_handler) orinoco_ioctl_reset,
4295 [1] = (iw_handler) orinoco_ioctl_reset,
4296 [2] = (iw_handler) orinoco_ioctl_setport3,
4297 [3] = (iw_handler) orinoco_ioctl_getport3,
4298 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4299 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4300 [6] = (iw_handler) orinoco_ioctl_setibssport,
4301 [7] = (iw_handler) orinoco_ioctl_getibssport,
4302 [9] = (iw_handler) orinoco_ioctl_getrid,
4305 static const struct iw_handler_def orinoco_handler_def = {
4306 .num_standard = ARRAY_SIZE(orinoco_handler),
4307 .num_private = ARRAY_SIZE(orinoco_private_handler),
4308 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4309 .standard = orinoco_handler,
4310 .private = orinoco_private_handler,
4311 .private_args = orinoco_privtab,
4312 .get_wireless_stats = orinoco_get_wireless_stats,
4315 static void orinoco_get_drvinfo(struct net_device *dev,
4316 struct ethtool_drvinfo *info)
4318 struct orinoco_private *priv = netdev_priv(dev);
4320 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4321 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4322 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4323 if (dev->class_dev.dev)
4324 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4325 sizeof(info->bus_info) - 1);
4327 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4328 "PCMCIA %p", priv->hw.iobase);
4331 static struct ethtool_ops orinoco_ethtool_ops = {
4332 .get_drvinfo = orinoco_get_drvinfo,
4333 .get_link = ethtool_op_get_link,
4336 /********************************************************************/
4338 /********************************************************************/
4341 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4343 printk(KERN_DEBUG "RX descriptor:\n");
4344 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4345 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4346 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4347 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4348 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4349 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4350 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4352 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4353 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4354 frame->p80211.frame_ctl);
4355 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4356 frame->p80211.duration_id);
4357 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4358 frame->p80211.addr1[0], frame->p80211.addr1[1],
4359 frame->p80211.addr1[2], frame->p80211.addr1[3],
4360 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4361 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4362 frame->p80211.addr2[0], frame->p80211.addr2[1],
4363 frame->p80211.addr2[2], frame->p80211.addr2[3],
4364 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4365 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4366 frame->p80211.addr3[0], frame->p80211.addr3[1],
4367 frame->p80211.addr3[2], frame->p80211.addr3[3],
4368 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4369 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4370 frame->p80211.seq_ctl);
4371 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4372 frame->p80211.addr4[0], frame->p80211.addr4[1],
4373 frame->p80211.addr4[2], frame->p80211.addr4[3],
4374 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4375 printk(KERN_DEBUG " data_len = 0x%04x\n",
4376 frame->p80211.data_len);
4378 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4379 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4380 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4381 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4382 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4383 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4384 frame->p8023.h_source[0], frame->p8023.h_source[1],
4385 frame->p8023.h_source[2], frame->p8023.h_source[3],
4386 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4387 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4389 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4390 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4391 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4392 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4393 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4394 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4395 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4399 /********************************************************************/
4400 /* Module initialization */
4401 /********************************************************************/
4403 EXPORT_SYMBOL(alloc_orinocodev);
4404 EXPORT_SYMBOL(free_orinocodev);
4406 EXPORT_SYMBOL(__orinoco_up);
4407 EXPORT_SYMBOL(__orinoco_down);
4408 EXPORT_SYMBOL(orinoco_reinit_firmware);
4410 EXPORT_SYMBOL(orinoco_interrupt);
4412 /* Can't be declared "const" or the whole __initdata section will
4414 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4415 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4416 "Pavel Roskin <proski@gnu.org>, et al)";
4418 static int __init init_orinoco(void)
4420 printk(KERN_DEBUG "%s\n", version);
4424 static void __exit exit_orinoco(void)
4428 module_init(init_orinoco);
4429 module_exit(exit_orinoco);