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 structures as they break on ARM -- Moustafa */
206 struct hermes_tx_descriptor_802_11 {
207 /* hermes_tx_descriptor */
228 u8 h_dest[ETH_ALEN]; /* destination eth addr */
229 u8 h_source[ETH_ALEN]; /* source ether addr */
230 __be16 h_proto; /* packet type ID field */
239 } __attribute__ ((packed));
241 /* Rx frame header except compatibility 802.3 header */
242 struct hermes_rx_descriptor {
263 } __attribute__ ((packed));
265 /********************************************************************/
266 /* Function prototypes */
267 /********************************************************************/
269 static int __orinoco_program_rids(struct net_device *dev);
270 static void __orinoco_set_multicast_list(struct net_device *dev);
272 /********************************************************************/
273 /* Internal helper functions */
274 /********************************************************************/
276 static inline void set_port_type(struct orinoco_private *priv)
278 switch (priv->iw_mode) {
281 priv->createibss = 0;
284 if (priv->prefer_port3) {
286 priv->createibss = 0;
288 priv->port_type = priv->ibss_port;
289 priv->createibss = 1;
292 case IW_MODE_MONITOR:
294 priv->createibss = 0;
297 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
302 /********************************************************************/
304 /********************************************************************/
306 static int orinoco_open(struct net_device *dev)
308 struct orinoco_private *priv = netdev_priv(dev);
312 if (orinoco_lock(priv, &flags) != 0)
315 err = __orinoco_up(dev);
320 orinoco_unlock(priv, &flags);
325 static int orinoco_stop(struct net_device *dev)
327 struct orinoco_private *priv = netdev_priv(dev);
330 /* We mustn't use orinoco_lock() here, because we need to be
331 able to close the interface even if hw_unavailable is set
332 (e.g. as we're released after a PC Card removal) */
333 spin_lock_irq(&priv->lock);
337 err = __orinoco_down(dev);
339 spin_unlock_irq(&priv->lock);
344 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
346 struct orinoco_private *priv = netdev_priv(dev);
351 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
353 struct orinoco_private *priv = netdev_priv(dev);
354 hermes_t *hw = &priv->hw;
355 struct iw_statistics *wstats = &priv->wstats;
359 if (! netif_device_present(dev)) {
360 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
362 return NULL; /* FIXME: Can we do better than this? */
365 /* If busy, return the old stats. Returning NULL may cause
366 * the interface to disappear from /proc/net/wireless */
367 if (orinoco_lock(priv, &flags) != 0)
370 /* We can't really wait for the tallies inquiry command to
371 * complete, so we just use the previous results and trigger
372 * a new tallies inquiry command for next time - Jean II */
373 /* FIXME: Really we should wait for the inquiry to come back -
374 * as it is the stats we give don't make a whole lot of sense.
375 * Unfortunately, it's not clear how to do that within the
376 * wireless extensions framework: I think we're in user
377 * context, but a lock seems to be held by the time we get in
378 * here so we're not safe to sleep here. */
379 hermes_inquire(hw, HERMES_INQ_TALLIES);
381 if (priv->iw_mode == IW_MODE_ADHOC) {
382 memset(&wstats->qual, 0, sizeof(wstats->qual));
383 /* If a spy address is defined, we report stats of the
384 * first spy address - Jean II */
385 if (SPY_NUMBER(priv)) {
386 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
387 wstats->qual.level = priv->spy_data.spy_stat[0].level;
388 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
389 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
393 __le16 qual, signal, noise;
394 } __attribute__ ((packed)) cq;
396 err = HERMES_READ_RECORD(hw, USER_BAP,
397 HERMES_RID_COMMSQUALITY, &cq);
400 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
401 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
402 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
403 wstats->qual.updated = 7;
407 orinoco_unlock(priv, &flags);
411 static void orinoco_set_multicast_list(struct net_device *dev)
413 struct orinoco_private *priv = netdev_priv(dev);
416 if (orinoco_lock(priv, &flags) != 0) {
417 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
418 "called when hw_unavailable\n", dev->name);
422 __orinoco_set_multicast_list(dev);
423 orinoco_unlock(priv, &flags);
426 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
428 struct orinoco_private *priv = netdev_priv(dev);
430 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
433 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
434 (priv->nicbuf_size - ETH_HLEN) )
442 /********************************************************************/
444 /********************************************************************/
446 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
448 struct orinoco_private *priv = netdev_priv(dev);
449 struct net_device_stats *stats = &priv->stats;
450 hermes_t *hw = &priv->hw;
452 u16 txfid = priv->txfid;
455 int len, data_len, data_off;
456 struct hermes_tx_descriptor desc;
459 TRACE_ENTER(dev->name);
461 if (! netif_running(dev)) {
462 printk(KERN_ERR "%s: Tx on stopped device!\n",
464 TRACE_EXIT(dev->name);
468 if (netif_queue_stopped(dev)) {
469 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
471 TRACE_EXIT(dev->name);
475 if (orinoco_lock(priv, &flags) != 0) {
476 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
478 TRACE_EXIT(dev->name);
482 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
483 /* Oops, the firmware hasn't established a connection,
484 silently drop the packet (this seems to be the
487 orinoco_unlock(priv, &flags);
489 TRACE_EXIT(dev->name);
493 /* Check packet length, pad short packets, round up odd length */
494 len = max_t(int, ALIGN(skb->len, 2), ETH_ZLEN);
495 if (skb->len < len) {
496 skb = skb_padto(skb, len);
502 eh = (struct ethhdr *)skb->data;
504 memset(&desc, 0, sizeof(desc));
505 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
506 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
509 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
510 "to BAP\n", dev->name, err);
515 /* Clear the 802.11 header and data length fields - some
516 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
517 * if this isn't done. */
518 hermes_clear_words(hw, HERMES_DATA0,
519 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
521 /* Encapsulate Ethernet-II frames */
522 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
523 struct header_struct hdr;
525 data_off = HERMES_802_3_OFFSET + sizeof(hdr);
526 p = skb->data + ETH_HLEN;
529 memcpy(hdr.dest, eh->h_dest, ETH_ALEN);
530 memcpy(hdr.src, eh->h_source, ETH_ALEN);
531 hdr.len = htons(data_len + ENCAPS_OVERHEAD);
534 memcpy(&hdr.dsap, &encaps_hdr, sizeof(encaps_hdr));
536 hdr.ethertype = eh->h_proto;
537 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
538 txfid, HERMES_802_3_OFFSET);
541 printk(KERN_ERR "%s: Error %d writing packet "
542 "header to BAP\n", dev->name, err);
546 } else { /* IEEE 802.3 frame */
547 data_len = len + ETH_HLEN;
548 data_off = HERMES_802_3_OFFSET;
552 err = hermes_bap_pwrite(hw, USER_BAP, p, data_len,
555 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
561 /* Finally, we actually initiate the send */
562 netif_stop_queue(dev);
564 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
567 netif_start_queue(dev);
568 printk(KERN_ERR "%s: Error %d transmitting packet\n",
574 dev->trans_start = jiffies;
575 stats->tx_bytes += data_off + data_len;
577 orinoco_unlock(priv, &flags);
581 TRACE_EXIT(dev->name);
585 TRACE_EXIT(dev->name);
587 orinoco_unlock(priv, &flags);
591 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
593 struct orinoco_private *priv = netdev_priv(dev);
594 u16 fid = hermes_read_regn(hw, ALLOCFID);
596 if (fid != priv->txfid) {
597 if (fid != DUMMY_FID)
598 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
603 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
606 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
608 struct orinoco_private *priv = netdev_priv(dev);
609 struct net_device_stats *stats = &priv->stats;
613 netif_wake_queue(dev);
615 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
618 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
620 struct orinoco_private *priv = netdev_priv(dev);
621 struct net_device_stats *stats = &priv->stats;
622 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
624 struct hermes_tx_descriptor_802_11 hdr;
627 if (fid == DUMMY_FID)
628 return; /* Nothing's really happened */
630 /* Read part of the frame header - we need status and addr1 */
631 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
632 offsetof(struct hermes_tx_descriptor_802_11,
636 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
640 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
641 "(FID=%04X error %d)\n",
642 dev->name, fid, err);
646 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
649 /* We produce a TXDROP event only for retry or lifetime
650 * exceeded, because that's the only status that really mean
651 * that this particular node went away.
652 * Other errors means that *we* screwed up. - Jean II */
653 status = le16_to_cpu(hdr.status);
654 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
655 union iwreq_data wrqu;
657 /* Copy 802.11 dest address.
658 * We use the 802.11 header because the frame may
659 * not be 802.3 or may be mangled...
660 * In Ad-Hoc mode, it will be the node address.
661 * In managed mode, it will be most likely the AP addr
662 * User space will figure out how to convert it to
663 * whatever it needs (IP address or else).
665 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
666 wrqu.addr.sa_family = ARPHRD_ETHER;
668 /* Send event to user space */
669 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
672 netif_wake_queue(dev);
675 static void orinoco_tx_timeout(struct net_device *dev)
677 struct orinoco_private *priv = netdev_priv(dev);
678 struct net_device_stats *stats = &priv->stats;
679 struct hermes *hw = &priv->hw;
681 printk(KERN_WARNING "%s: Tx timeout! "
682 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
683 dev->name, hermes_read_regn(hw, ALLOCFID),
684 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
688 schedule_work(&priv->reset_work);
691 /********************************************************************/
692 /* Rx path (data frames) */
693 /********************************************************************/
695 /* Does the frame have a SNAP header indicating it should be
696 * de-encapsulated to Ethernet-II? */
697 static inline int is_ethersnap(void *_hdr)
701 /* We de-encapsulate all packets which, a) have SNAP headers
702 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
703 * and where b) the OUI of the SNAP header is 00:00:00 or
704 * 00:00:f8 - we need both because different APs appear to use
705 * different OUIs for some reason */
706 return (memcmp(hdr, &encaps_hdr, 5) == 0)
707 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
710 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
711 int level, int noise)
713 struct iw_quality wstats;
714 wstats.level = level - 0x95;
715 wstats.noise = noise - 0x95;
716 wstats.qual = (level > noise) ? (level - noise) : 0;
718 /* Update spy records */
719 wireless_spy_update(dev, mac, &wstats);
722 static void orinoco_stat_gather(struct net_device *dev,
724 struct hermes_rx_descriptor *desc)
726 struct orinoco_private *priv = netdev_priv(dev);
728 /* Using spy support with lots of Rx packets, like in an
729 * infrastructure (AP), will really slow down everything, because
730 * the MAC address must be compared to each entry of the spy list.
731 * If the user really asks for it (set some address in the
732 * spy list), we do it, but he will pay the price.
733 * Note that to get here, you need both WIRELESS_SPY
734 * compiled in AND some addresses in the list !!!
736 /* Note : gcc will optimise the whole section away if
737 * WIRELESS_SPY is not defined... - Jean II */
738 if (SPY_NUMBER(priv)) {
739 orinoco_spy_gather(dev, skb->mac.raw + ETH_ALEN,
740 desc->signal, desc->silence);
745 * orinoco_rx_monitor - handle received monitor frames.
750 * desc rx descriptor of the frame
752 * Call context: interrupt
754 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
755 struct hermes_rx_descriptor *desc)
757 u32 hdrlen = 30; /* return full header by default */
763 struct orinoco_private *priv = netdev_priv(dev);
764 struct net_device_stats *stats = &priv->stats;
765 hermes_t *hw = &priv->hw;
767 len = le16_to_cpu(desc->data_len);
769 /* Determine the size of the header and the data */
770 fc = le16_to_cpu(desc->frame_ctl);
771 switch (fc & IEEE80211_FCTL_FTYPE) {
772 case IEEE80211_FTYPE_DATA:
773 if ((fc & IEEE80211_FCTL_TODS)
774 && (fc & IEEE80211_FCTL_FROMDS))
780 case IEEE80211_FTYPE_MGMT:
784 case IEEE80211_FTYPE_CTL:
785 switch (fc & IEEE80211_FCTL_STYPE) {
786 case IEEE80211_STYPE_PSPOLL:
787 case IEEE80211_STYPE_RTS:
788 case IEEE80211_STYPE_CFEND:
789 case IEEE80211_STYPE_CFENDACK:
792 case IEEE80211_STYPE_CTS:
793 case IEEE80211_STYPE_ACK:
799 /* Unknown frame type */
803 /* sanity check the length */
804 if (datalen > IEEE80211_DATA_LEN + 12) {
805 printk(KERN_DEBUG "%s: oversized monitor frame, "
806 "data length = %d\n", dev->name, datalen);
808 stats->rx_length_errors++;
812 skb = dev_alloc_skb(hdrlen + datalen);
814 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
820 /* Copy the 802.11 header to the skb */
821 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
822 skb->mac.raw = skb->data;
824 /* If any, copy the data from the card to the skb */
826 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
827 ALIGN(datalen, 2), rxfid,
828 HERMES_802_2_OFFSET);
830 printk(KERN_ERR "%s: error %d reading monitor frame\n",
837 skb->ip_summed = CHECKSUM_NONE;
838 skb->pkt_type = PACKET_OTHERHOST;
839 skb->protocol = __constant_htons(ETH_P_802_2);
841 dev->last_rx = jiffies;
843 stats->rx_bytes += skb->len;
849 dev_kfree_skb_irq(skb);
855 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
857 struct orinoco_private *priv = netdev_priv(dev);
858 struct net_device_stats *stats = &priv->stats;
859 struct iw_statistics *wstats = &priv->wstats;
860 struct sk_buff *skb = NULL;
861 u16 rxfid, status, fc;
863 struct hermes_rx_descriptor desc;
867 rxfid = hermes_read_regn(hw, RXFID);
869 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
872 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
873 "Frame dropped.\n", dev->name, err);
877 status = le16_to_cpu(desc.status);
879 if (status & HERMES_RXSTAT_BADCRC) {
880 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
882 stats->rx_crc_errors++;
886 /* Handle frames in monitor mode */
887 if (priv->iw_mode == IW_MODE_MONITOR) {
888 orinoco_rx_monitor(dev, rxfid, &desc);
892 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
893 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
895 wstats->discard.code++;
899 length = le16_to_cpu(desc.data_len);
900 fc = le16_to_cpu(desc.frame_ctl);
903 if (length < 3) { /* No for even an 802.2 LLC header */
904 /* At least on Symbol firmware with PCF we get quite a
905 lot of these legitimately - Poll frames with no
909 if (length > IEEE80211_DATA_LEN) {
910 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
912 stats->rx_length_errors++;
916 /* We need space for the packet data itself, plus an ethernet
917 header, plus 2 bytes so we can align the IP header on a
918 32bit boundary, plus 1 byte so we can read in odd length
919 packets from the card, which has an IO granularity of 16
921 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
923 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
928 /* We'll prepend the header, so reserve space for it. The worst
929 case is no decapsulation, when 802.3 header is prepended and
930 nothing is removed. 2 is for aligning the IP header. */
931 skb_reserve(skb, ETH_HLEN + 2);
933 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
934 ALIGN(length, 2), rxfid,
935 HERMES_802_2_OFFSET);
937 printk(KERN_ERR "%s: error %d reading frame. "
938 "Frame dropped.\n", dev->name, err);
942 /* Handle decapsulation
943 * In most cases, the firmware tell us about SNAP frames.
944 * For some reason, the SNAP frames sent by LinkSys APs
945 * are not properly recognised by most firmwares.
946 * So, check ourselves */
947 if (length >= ENCAPS_OVERHEAD &&
948 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
949 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
950 is_ethersnap(skb->data))) {
951 /* These indicate a SNAP within 802.2 LLC within
952 802.11 frame which we'll need to de-encapsulate to
953 the original EthernetII frame. */
954 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
956 /* 802.3 frame - prepend 802.3 header as is */
957 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
958 hdr->h_proto = htons(length);
960 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
961 if (fc & IEEE80211_FCTL_FROMDS)
962 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
964 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
966 dev->last_rx = jiffies;
968 skb->protocol = eth_type_trans(skb, dev);
969 skb->ip_summed = CHECKSUM_NONE;
970 if (fc & IEEE80211_FCTL_TODS)
971 skb->pkt_type = PACKET_OTHERHOST;
973 /* Process the wireless stats if needed */
974 orinoco_stat_gather(dev, skb, &desc);
976 /* Pass the packet to the networking stack */
979 stats->rx_bytes += length;
984 dev_kfree_skb_irq(skb);
990 /********************************************************************/
991 /* Rx path (info frames) */
992 /********************************************************************/
994 static void print_linkstatus(struct net_device *dev, u16 status)
998 if (suppress_linkstatus)
1002 case HERMES_LINKSTATUS_NOT_CONNECTED:
1003 s = "Not Connected";
1005 case HERMES_LINKSTATUS_CONNECTED:
1008 case HERMES_LINKSTATUS_DISCONNECTED:
1011 case HERMES_LINKSTATUS_AP_CHANGE:
1014 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1015 s = "AP Out of Range";
1017 case HERMES_LINKSTATUS_AP_IN_RANGE:
1020 case HERMES_LINKSTATUS_ASSOC_FAILED:
1021 s = "Association Failed";
1027 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1028 dev->name, s, status);
1031 /* Search scan results for requested BSSID, join it if found */
1032 static void orinoco_join_ap(struct net_device *dev)
1034 struct orinoco_private *priv = netdev_priv(dev);
1035 struct hermes *hw = &priv->hw;
1037 unsigned long flags;
1041 } __attribute__ ((packed)) req;
1042 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1043 struct prism2_scan_apinfo *atom = NULL;
1049 /* Allocate buffer for scan results */
1050 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1054 if (orinoco_lock(priv, &flags) != 0)
1057 /* Sanity checks in case user changed something in the meantime */
1058 if (! priv->bssid_fixed)
1061 if (strlen(priv->desired_essid) == 0)
1064 /* Read scan results from the firmware */
1065 err = hermes_read_ltv(hw, USER_BAP,
1066 HERMES_RID_SCANRESULTSTABLE,
1067 MAX_SCAN_LEN, &len, buf);
1069 printk(KERN_ERR "%s: Cannot read scan results\n",
1074 len = HERMES_RECLEN_TO_BYTES(len);
1076 /* Go through the scan results looking for the channel of the AP
1077 * we were requested to join */
1078 for (; offset + atom_len <= len; offset += atom_len) {
1079 atom = (struct prism2_scan_apinfo *) (buf + offset);
1080 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1087 DEBUG(1, "%s: Requested AP not found in scan results\n",
1092 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1093 req.channel = atom->channel; /* both are little-endian */
1094 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1097 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1100 orinoco_unlock(priv, &flags);
1106 /* Send new BSSID to userspace */
1107 static void orinoco_send_wevents(struct net_device *dev)
1109 struct orinoco_private *priv = netdev_priv(dev);
1110 struct hermes *hw = &priv->hw;
1111 union iwreq_data wrqu;
1113 unsigned long flags;
1115 if (orinoco_lock(priv, &flags) != 0)
1118 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1119 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1123 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1125 /* Send event to user space */
1126 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1129 orinoco_unlock(priv, &flags);
1132 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1134 struct orinoco_private *priv = netdev_priv(dev);
1139 } __attribute__ ((packed)) info;
1143 /* This is an answer to an INQUIRE command that we did earlier,
1144 * or an information "event" generated by the card
1145 * The controller return to us a pseudo frame containing
1146 * the information in question - Jean II */
1147 infofid = hermes_read_regn(hw, INFOFID);
1149 /* Read the info frame header - don't try too hard */
1150 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1153 printk(KERN_ERR "%s: error %d reading info frame. "
1154 "Frame dropped.\n", dev->name, err);
1158 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1159 type = le16_to_cpu(info.type);
1162 case HERMES_INQ_TALLIES: {
1163 struct hermes_tallies_frame tallies;
1164 struct iw_statistics *wstats = &priv->wstats;
1166 if (len > sizeof(tallies)) {
1167 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1169 len = sizeof(tallies);
1172 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1173 infofid, sizeof(info));
1177 /* Increment our various counters */
1178 /* wstats->discard.nwid - no wrong BSSID stuff */
1179 wstats->discard.code +=
1180 le16_to_cpu(tallies.RxWEPUndecryptable);
1181 if (len == sizeof(tallies))
1182 wstats->discard.code +=
1183 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1184 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1185 wstats->discard.misc +=
1186 le16_to_cpu(tallies.TxDiscardsWrongSA);
1187 wstats->discard.fragment +=
1188 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1189 wstats->discard.retries +=
1190 le16_to_cpu(tallies.TxRetryLimitExceeded);
1191 /* wstats->miss.beacon - no match */
1194 case HERMES_INQ_LINKSTATUS: {
1195 struct hermes_linkstatus linkstatus;
1199 if (priv->iw_mode == IW_MODE_MONITOR)
1202 if (len != sizeof(linkstatus)) {
1203 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1208 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1209 infofid, sizeof(info));
1212 newstatus = le16_to_cpu(linkstatus.linkstatus);
1214 /* Symbol firmware uses "out of range" to signal that
1215 * the hostscan frame can be requested. */
1216 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1217 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1218 priv->has_hostscan && priv->scan_inprogress) {
1219 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1223 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1224 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1225 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1228 netif_carrier_on(dev);
1229 else if (!ignore_disconnect)
1230 netif_carrier_off(dev);
1232 if (newstatus != priv->last_linkstatus) {
1233 priv->last_linkstatus = newstatus;
1234 print_linkstatus(dev, newstatus);
1235 /* The info frame contains only one word which is the
1236 * status (see hermes.h). The status is pretty boring
1237 * in itself, that's why we export the new BSSID...
1239 schedule_work(&priv->wevent_work);
1243 case HERMES_INQ_SCAN:
1244 if (!priv->scan_inprogress && priv->bssid_fixed &&
1245 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1246 schedule_work(&priv->join_work);
1250 case HERMES_INQ_HOSTSCAN:
1251 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1252 /* Result of a scanning. Contains information about
1253 * cells in the vicinity - Jean II */
1254 union iwreq_data wrqu;
1259 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1264 /* We are a strict producer. If the previous scan results
1265 * have not been consumed, we just have to drop this
1266 * frame. We can't remove the previous results ourselves,
1267 * that would be *very* racy... Jean II */
1268 if (priv->scan_result != NULL) {
1269 printk(KERN_WARNING "%s: Previous scan results not consumed, dropping info frame.\n", dev->name);
1273 /* Allocate buffer for results */
1274 buf = kmalloc(len, GFP_ATOMIC);
1276 /* No memory, so can't printk()... */
1279 /* Read scan data */
1280 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1281 infofid, sizeof(info));
1287 #ifdef ORINOCO_DEBUG
1290 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1291 for(i = 1; i < (len * 2); i++)
1292 printk(":%02X", buf[i]);
1295 #endif /* ORINOCO_DEBUG */
1297 /* Allow the clients to access the results */
1298 priv->scan_len = len;
1299 priv->scan_result = buf;
1301 /* Send an empty event to user space.
1302 * We don't send the received data on the event because
1303 * it would require us to do complex transcoding, and
1304 * we want to minimise the work done in the irq handler
1305 * Use a request to extract the data - Jean II */
1306 wrqu.data.length = 0;
1307 wrqu.data.flags = 0;
1308 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1311 case HERMES_INQ_SEC_STAT_AGERE:
1312 /* Security status (Agere specific) */
1313 /* Ignore this frame for now */
1314 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1318 printk(KERN_DEBUG "%s: Unknown information frame received: "
1319 "type 0x%04x, length %d\n", dev->name, type, len);
1320 /* We don't actually do anything about it */
1325 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1327 if (net_ratelimit())
1328 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1331 /********************************************************************/
1332 /* Internal hardware control routines */
1333 /********************************************************************/
1335 int __orinoco_up(struct net_device *dev)
1337 struct orinoco_private *priv = netdev_priv(dev);
1338 struct hermes *hw = &priv->hw;
1341 netif_carrier_off(dev); /* just to make sure */
1343 err = __orinoco_program_rids(dev);
1345 printk(KERN_ERR "%s: Error %d configuring card\n",
1350 /* Fire things up again */
1351 hermes_set_irqmask(hw, ORINOCO_INTEN);
1352 err = hermes_enable_port(hw, 0);
1354 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1359 netif_start_queue(dev);
1364 int __orinoco_down(struct net_device *dev)
1366 struct orinoco_private *priv = netdev_priv(dev);
1367 struct hermes *hw = &priv->hw;
1370 netif_stop_queue(dev);
1372 if (! priv->hw_unavailable) {
1373 if (! priv->broken_disableport) {
1374 err = hermes_disable_port(hw, 0);
1376 /* Some firmwares (e.g. Intersil 1.3.x) seem
1377 * to have problems disabling the port, oh
1379 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1381 priv->broken_disableport = 1;
1384 hermes_set_irqmask(hw, 0);
1385 hermes_write_regn(hw, EVACK, 0xffff);
1388 /* firmware will have to reassociate */
1389 netif_carrier_off(dev);
1390 priv->last_linkstatus = 0xffff;
1395 int orinoco_reinit_firmware(struct net_device *dev)
1397 struct orinoco_private *priv = netdev_priv(dev);
1398 struct hermes *hw = &priv->hw;
1401 err = hermes_init(hw);
1405 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1406 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1407 /* Try workaround for old Symbol firmware bug */
1408 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1409 "(old Symbol firmware?). Trying to work around... ",
1412 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1413 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1415 printk("failed!\n");
1423 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1425 hermes_t *hw = &priv->hw;
1428 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1429 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1430 priv->ndev->name, priv->bitratemode);
1434 switch (priv->firmware_type) {
1435 case FIRMWARE_TYPE_AGERE:
1436 err = hermes_write_wordrec(hw, USER_BAP,
1437 HERMES_RID_CNFTXRATECONTROL,
1438 bitrate_table[priv->bitratemode].agere_txratectrl);
1440 case FIRMWARE_TYPE_INTERSIL:
1441 case FIRMWARE_TYPE_SYMBOL:
1442 err = hermes_write_wordrec(hw, USER_BAP,
1443 HERMES_RID_CNFTXRATECONTROL,
1444 bitrate_table[priv->bitratemode].intersil_txratectrl);
1453 /* Set fixed AP address */
1454 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1458 hermes_t *hw = &priv->hw;
1460 switch (priv->firmware_type) {
1461 case FIRMWARE_TYPE_AGERE:
1464 case FIRMWARE_TYPE_INTERSIL:
1465 if (priv->bssid_fixed)
1470 err = hermes_write_wordrec(hw, USER_BAP,
1471 HERMES_RID_CNFROAMINGMODE,
1474 case FIRMWARE_TYPE_SYMBOL:
1475 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1476 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1477 &priv->desired_bssid);
1483 /* Change the WEP keys and/or the current keys. Can be called
1484 * either from __orinoco_hw_setup_wep() or directly from
1485 * orinoco_ioctl_setiwencode(). In the later case the association
1486 * with the AP is not broken (if the firmware can handle it),
1487 * which is needed for 802.1x implementations. */
1488 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1490 hermes_t *hw = &priv->hw;
1493 switch (priv->firmware_type) {
1494 case FIRMWARE_TYPE_AGERE:
1495 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1496 HERMES_RID_CNFWEPKEYS_AGERE,
1500 err = hermes_write_wordrec(hw, USER_BAP,
1501 HERMES_RID_CNFTXKEY_AGERE,
1506 case FIRMWARE_TYPE_INTERSIL:
1507 case FIRMWARE_TYPE_SYMBOL:
1512 /* Force uniform key length to work around firmware bugs */
1513 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1515 if (keylen > LARGE_KEY_SIZE) {
1516 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1517 priv->ndev->name, priv->tx_key, keylen);
1521 /* Write all 4 keys */
1522 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1523 err = hermes_write_ltv(hw, USER_BAP,
1524 HERMES_RID_CNFDEFAULTKEY0 + i,
1525 HERMES_BYTES_TO_RECLEN(keylen),
1526 priv->keys[i].data);
1531 /* Write the index of the key used in transmission */
1532 err = hermes_write_wordrec(hw, USER_BAP,
1533 HERMES_RID_CNFWEPDEFAULTKEYID,
1544 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1546 hermes_t *hw = &priv->hw;
1548 int master_wep_flag;
1552 __orinoco_hw_setup_wepkeys(priv);
1554 if (priv->wep_restrict)
1555 auth_flag = HERMES_AUTH_SHARED_KEY;
1557 auth_flag = HERMES_AUTH_OPEN;
1559 switch (priv->firmware_type) {
1560 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1562 /* Enable the shared-key authentication. */
1563 err = hermes_write_wordrec(hw, USER_BAP,
1564 HERMES_RID_CNFAUTHENTICATION_AGERE,
1567 err = hermes_write_wordrec(hw, USER_BAP,
1568 HERMES_RID_CNFWEPENABLED_AGERE,
1574 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1575 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1577 if (priv->wep_restrict ||
1578 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1579 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1580 HERMES_WEP_EXCL_UNENCRYPTED;
1582 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1584 err = hermes_write_wordrec(hw, USER_BAP,
1585 HERMES_RID_CNFAUTHENTICATION,
1590 master_wep_flag = 0;
1592 if (priv->iw_mode == IW_MODE_MONITOR)
1593 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1595 /* Master WEP setting : on/off */
1596 err = hermes_write_wordrec(hw, USER_BAP,
1597 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1608 static int __orinoco_program_rids(struct net_device *dev)
1610 struct orinoco_private *priv = netdev_priv(dev);
1611 hermes_t *hw = &priv->hw;
1613 struct hermes_idstring idbuf;
1615 /* Set the MAC address */
1616 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1617 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1619 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1624 /* Set up the link mode */
1625 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1628 printk(KERN_ERR "%s: Error %d setting port type\n",
1632 /* Set the channel/frequency */
1633 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1634 err = hermes_write_wordrec(hw, USER_BAP,
1635 HERMES_RID_CNFOWNCHANNEL,
1638 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1639 dev->name, err, priv->channel);
1644 if (priv->has_ibss) {
1647 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1648 printk(KERN_WARNING "%s: This firmware requires an "
1649 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1650 /* With wvlan_cs, in this case, we would crash.
1651 * hopefully, this driver will behave better...
1655 createibss = priv->createibss;
1658 err = hermes_write_wordrec(hw, USER_BAP,
1659 HERMES_RID_CNFCREATEIBSS,
1662 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1668 /* Set the desired BSSID */
1669 err = __orinoco_hw_set_wap(priv);
1671 printk(KERN_ERR "%s: Error %d setting AP address\n",
1675 /* Set the desired ESSID */
1676 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1677 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1678 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1679 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1680 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1683 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1687 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1688 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1691 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1696 /* Set the station name */
1697 idbuf.len = cpu_to_le16(strlen(priv->nick));
1698 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1699 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1700 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1703 printk(KERN_ERR "%s: Error %d setting nickname\n",
1708 /* Set AP density */
1709 if (priv->has_sensitivity) {
1710 err = hermes_write_wordrec(hw, USER_BAP,
1711 HERMES_RID_CNFSYSTEMSCALE,
1714 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1715 "Disabling sensitivity control\n",
1718 priv->has_sensitivity = 0;
1722 /* Set RTS threshold */
1723 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1726 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1731 /* Set fragmentation threshold or MWO robustness */
1733 err = hermes_write_wordrec(hw, USER_BAP,
1734 HERMES_RID_CNFMWOROBUST_AGERE,
1737 err = hermes_write_wordrec(hw, USER_BAP,
1738 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1741 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1747 err = __orinoco_hw_set_bitrate(priv);
1749 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1754 /* Set power management */
1756 err = hermes_write_wordrec(hw, USER_BAP,
1757 HERMES_RID_CNFPMENABLED,
1760 printk(KERN_ERR "%s: Error %d setting up PM\n",
1765 err = hermes_write_wordrec(hw, USER_BAP,
1766 HERMES_RID_CNFMULTICASTRECEIVE,
1769 printk(KERN_ERR "%s: Error %d setting up PM\n",
1773 err = hermes_write_wordrec(hw, USER_BAP,
1774 HERMES_RID_CNFMAXSLEEPDURATION,
1777 printk(KERN_ERR "%s: Error %d setting up PM\n",
1781 err = hermes_write_wordrec(hw, USER_BAP,
1782 HERMES_RID_CNFPMHOLDOVERDURATION,
1785 printk(KERN_ERR "%s: Error %d setting up PM\n",
1791 /* Set preamble - only for Symbol so far... */
1792 if (priv->has_preamble) {
1793 err = hermes_write_wordrec(hw, USER_BAP,
1794 HERMES_RID_CNFPREAMBLE_SYMBOL,
1797 printk(KERN_ERR "%s: Error %d setting preamble\n",
1803 /* Set up encryption */
1804 if (priv->has_wep) {
1805 err = __orinoco_hw_setup_wep(priv);
1807 printk(KERN_ERR "%s: Error %d activating WEP\n",
1813 if (priv->iw_mode == IW_MODE_MONITOR) {
1814 /* Enable monitor mode */
1815 dev->type = ARPHRD_IEEE80211;
1816 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1817 HERMES_TEST_MONITOR, 0, NULL);
1819 /* Disable monitor mode */
1820 dev->type = ARPHRD_ETHER;
1821 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1822 HERMES_TEST_STOP, 0, NULL);
1827 /* Set promiscuity / multicast*/
1828 priv->promiscuous = 0;
1830 __orinoco_set_multicast_list(dev); /* FIXME: what about the xmit_lock */
1835 /* FIXME: return int? */
1837 __orinoco_set_multicast_list(struct net_device *dev)
1839 struct orinoco_private *priv = netdev_priv(dev);
1840 hermes_t *hw = &priv->hw;
1842 int promisc, mc_count;
1844 /* The Hermes doesn't seem to have an allmulti mode, so we go
1845 * into promiscuous mode and let the upper levels deal. */
1846 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1847 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1852 mc_count = dev->mc_count;
1855 if (promisc != priv->promiscuous) {
1856 err = hermes_write_wordrec(hw, USER_BAP,
1857 HERMES_RID_CNFPROMISCUOUSMODE,
1860 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1863 priv->promiscuous = promisc;
1866 if (! promisc && (mc_count || priv->mc_count) ) {
1867 struct dev_mc_list *p = dev->mc_list;
1868 struct hermes_multicast mclist;
1871 for (i = 0; i < mc_count; i++) {
1872 /* paranoia: is list shorter than mc_count? */
1874 /* paranoia: bad address size in list? */
1875 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1877 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1882 printk(KERN_WARNING "%s: Multicast list is "
1883 "longer than mc_count\n", dev->name);
1885 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
1886 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
1889 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
1892 priv->mc_count = mc_count;
1895 /* Since we can set the promiscuous flag when it wasn't asked
1896 for, make sure the net_device knows about it. */
1897 if (priv->promiscuous)
1898 dev->flags |= IFF_PROMISC;
1900 dev->flags &= ~IFF_PROMISC;
1903 /* This must be called from user context, without locks held - use
1904 * schedule_work() */
1905 static void orinoco_reset(struct net_device *dev)
1907 struct orinoco_private *priv = netdev_priv(dev);
1908 struct hermes *hw = &priv->hw;
1910 unsigned long flags;
1912 if (orinoco_lock(priv, &flags) != 0)
1913 /* When the hardware becomes available again, whatever
1914 * detects that is responsible for re-initializing
1915 * it. So no need for anything further */
1918 netif_stop_queue(dev);
1920 /* Shut off interrupts. Depending on what state the hardware
1921 * is in, this might not work, but we'll try anyway */
1922 hermes_set_irqmask(hw, 0);
1923 hermes_write_regn(hw, EVACK, 0xffff);
1925 priv->hw_unavailable++;
1926 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1927 netif_carrier_off(dev);
1929 orinoco_unlock(priv, &flags);
1931 /* Scanning support: Cleanup of driver struct */
1932 kfree(priv->scan_result);
1933 priv->scan_result = NULL;
1934 priv->scan_inprogress = 0;
1936 if (priv->hard_reset) {
1937 err = (*priv->hard_reset)(priv);
1939 printk(KERN_ERR "%s: orinoco_reset: Error %d "
1940 "performing hard reset\n", dev->name, err);
1945 err = orinoco_reinit_firmware(dev);
1947 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
1952 spin_lock_irq(&priv->lock); /* This has to be called from user context */
1954 priv->hw_unavailable--;
1956 /* priv->open or priv->hw_unavailable might have changed while
1957 * we dropped the lock */
1958 if (priv->open && (! priv->hw_unavailable)) {
1959 err = __orinoco_up(dev);
1961 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
1964 dev->trans_start = jiffies;
1967 spin_unlock_irq(&priv->lock);
1971 hermes_set_irqmask(hw, 0);
1972 netif_device_detach(dev);
1973 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
1976 /********************************************************************/
1977 /* Interrupt handler */
1978 /********************************************************************/
1980 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
1982 printk(KERN_DEBUG "%s: TICK\n", dev->name);
1985 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
1987 /* This seems to happen a fair bit under load, but ignoring it
1988 seems to work fine...*/
1989 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
1993 irqreturn_t orinoco_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1995 struct net_device *dev = (struct net_device *)dev_id;
1996 struct orinoco_private *priv = netdev_priv(dev);
1997 hermes_t *hw = &priv->hw;
1998 int count = MAX_IRQLOOPS_PER_IRQ;
2000 /* These are used to detect a runaway interrupt situation */
2001 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2002 * we panic and shut down the hardware */
2003 static int last_irq_jiffy = 0; /* jiffies value the last time
2005 static int loops_this_jiffy = 0;
2006 unsigned long flags;
2008 if (orinoco_lock(priv, &flags) != 0) {
2009 /* If hw is unavailable - we don't know if the irq was
2014 evstat = hermes_read_regn(hw, EVSTAT);
2015 events = evstat & hw->inten;
2017 orinoco_unlock(priv, &flags);
2021 if (jiffies != last_irq_jiffy)
2022 loops_this_jiffy = 0;
2023 last_irq_jiffy = jiffies;
2025 while (events && count--) {
2026 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2027 printk(KERN_WARNING "%s: IRQ handler is looping too "
2028 "much! Resetting.\n", dev->name);
2029 /* Disable interrupts for now */
2030 hermes_set_irqmask(hw, 0);
2031 schedule_work(&priv->reset_work);
2035 /* Check the card hasn't been removed */
2036 if (! hermes_present(hw)) {
2037 DEBUG(0, "orinoco_interrupt(): card removed\n");
2041 if (events & HERMES_EV_TICK)
2042 __orinoco_ev_tick(dev, hw);
2043 if (events & HERMES_EV_WTERR)
2044 __orinoco_ev_wterr(dev, hw);
2045 if (events & HERMES_EV_INFDROP)
2046 __orinoco_ev_infdrop(dev, hw);
2047 if (events & HERMES_EV_INFO)
2048 __orinoco_ev_info(dev, hw);
2049 if (events & HERMES_EV_RX)
2050 __orinoco_ev_rx(dev, hw);
2051 if (events & HERMES_EV_TXEXC)
2052 __orinoco_ev_txexc(dev, hw);
2053 if (events & HERMES_EV_TX)
2054 __orinoco_ev_tx(dev, hw);
2055 if (events & HERMES_EV_ALLOC)
2056 __orinoco_ev_alloc(dev, hw);
2058 hermes_write_regn(hw, EVACK, evstat);
2060 evstat = hermes_read_regn(hw, EVSTAT);
2061 events = evstat & hw->inten;
2064 orinoco_unlock(priv, &flags);
2068 /********************************************************************/
2069 /* Initialization */
2070 /********************************************************************/
2073 u16 id, variant, major, minor;
2074 } __attribute__ ((packed));
2076 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2078 if (nic_id->id < 0x8000)
2079 return FIRMWARE_TYPE_AGERE;
2080 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2081 return FIRMWARE_TYPE_SYMBOL;
2083 return FIRMWARE_TYPE_INTERSIL;
2086 /* Set priv->firmware type, determine firmware properties */
2087 static int determine_firmware(struct net_device *dev)
2089 struct orinoco_private *priv = netdev_priv(dev);
2090 hermes_t *hw = &priv->hw;
2092 struct comp_id nic_id, sta_id;
2093 unsigned int firmver;
2094 char tmp[SYMBOL_MAX_VER_LEN+1];
2096 /* Get the hardware version */
2097 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2099 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2104 le16_to_cpus(&nic_id.id);
2105 le16_to_cpus(&nic_id.variant);
2106 le16_to_cpus(&nic_id.major);
2107 le16_to_cpus(&nic_id.minor);
2108 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2109 dev->name, nic_id.id, nic_id.variant,
2110 nic_id.major, nic_id.minor);
2112 priv->firmware_type = determine_firmware_type(&nic_id);
2114 /* Get the firmware version */
2115 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2117 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2122 le16_to_cpus(&sta_id.id);
2123 le16_to_cpus(&sta_id.variant);
2124 le16_to_cpus(&sta_id.major);
2125 le16_to_cpus(&sta_id.minor);
2126 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2127 dev->name, sta_id.id, sta_id.variant,
2128 sta_id.major, sta_id.minor);
2130 switch (sta_id.id) {
2132 printk(KERN_ERR "%s: Primary firmware is active\n",
2136 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2139 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2140 case 0x21: /* Symbol Spectrum24 Trilogy */
2143 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2148 /* Default capabilities */
2149 priv->has_sensitivity = 1;
2151 priv->has_preamble = 0;
2152 priv->has_port3 = 1;
2155 priv->has_big_wep = 0;
2157 /* Determine capabilities from the firmware version */
2158 switch (priv->firmware_type) {
2159 case FIRMWARE_TYPE_AGERE:
2160 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2161 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2162 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2163 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2165 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2167 priv->has_ibss = (firmver >= 0x60006);
2168 priv->has_wep = (firmver >= 0x40020);
2169 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2170 Gold cards from the others? */
2171 priv->has_mwo = (firmver >= 0x60000);
2172 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2173 priv->ibss_port = 1;
2174 priv->has_hostscan = (firmver >= 0x8000a);
2175 priv->broken_monitor = (firmver >= 0x80000);
2177 /* Tested with Agere firmware :
2178 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2179 * Tested CableTron firmware : 4.32 => Anton */
2181 case FIRMWARE_TYPE_SYMBOL:
2182 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2183 /* Intel MAC : 00:02:B3:* */
2184 /* 3Com MAC : 00:50:DA:* */
2185 memset(tmp, 0, sizeof(tmp));
2186 /* Get the Symbol firmware version */
2187 err = hermes_read_ltv(hw, USER_BAP,
2188 HERMES_RID_SECONDARYVERSION_SYMBOL,
2189 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2192 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2197 /* The firmware revision is a string, the format is
2198 * something like : "V2.20-01".
2199 * Quick and dirty parsing... - Jean II
2201 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2202 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2205 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2208 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2211 priv->has_ibss = (firmver >= 0x20000);
2212 priv->has_wep = (firmver >= 0x15012);
2213 priv->has_big_wep = (firmver >= 0x20000);
2214 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2215 (firmver >= 0x29000 && firmver < 0x30000) ||
2217 priv->has_preamble = (firmver >= 0x20000);
2218 priv->ibss_port = 4;
2219 priv->broken_disableport = (firmver == 0x25013) ||
2220 (firmver >= 0x30000 && firmver <= 0x31000);
2221 priv->has_hostscan = (firmver >= 0x31001) ||
2222 (firmver >= 0x29057 && firmver < 0x30000);
2223 /* Tested with Intel firmware : 0x20015 => Jean II */
2224 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2226 case FIRMWARE_TYPE_INTERSIL:
2227 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2228 * Samsung, Compaq 100/200 and Proxim are slightly
2229 * different and less well tested */
2230 /* D-Link MAC : 00:40:05:* */
2231 /* Addtron MAC : 00:90:D1:* */
2232 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2233 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2236 firmver = ((unsigned long)sta_id.major << 16) |
2237 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2239 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2240 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2241 priv->has_pm = (firmver >= 0x000700);
2242 priv->has_hostscan = (firmver >= 0x010301);
2244 if (firmver >= 0x000800)
2245 priv->ibss_port = 0;
2247 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2248 "than v0.8.x - several features not supported\n",
2250 priv->ibss_port = 1;
2254 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2260 static int orinoco_init(struct net_device *dev)
2262 struct orinoco_private *priv = netdev_priv(dev);
2263 hermes_t *hw = &priv->hw;
2265 struct hermes_idstring nickbuf;
2269 TRACE_ENTER(dev->name);
2271 /* No need to lock, the hw_unavailable flag is already set in
2272 * alloc_orinocodev() */
2273 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2275 /* Initialize the firmware */
2276 err = orinoco_reinit_firmware(dev);
2278 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2283 err = determine_firmware(dev);
2285 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2290 if (priv->has_port3)
2291 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2293 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2295 if (priv->has_wep) {
2296 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2297 if (priv->has_big_wep)
2298 printk("104-bit key\n");
2300 printk("40-bit key\n");
2303 /* Get the MAC address */
2304 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2305 ETH_ALEN, NULL, dev->dev_addr);
2307 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2312 printk(KERN_DEBUG "%s: MAC address %02X:%02X:%02X:%02X:%02X:%02X\n",
2313 dev->name, dev->dev_addr[0], dev->dev_addr[1],
2314 dev->dev_addr[2], dev->dev_addr[3], dev->dev_addr[4],
2317 /* Get the station name */
2318 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2319 sizeof(nickbuf), &reclen, &nickbuf);
2321 printk(KERN_ERR "%s: failed to read station name\n",
2326 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2328 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2329 memcpy(priv->nick, &nickbuf.val, len);
2330 priv->nick[len] = '\0';
2332 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2334 /* Get allowed channels */
2335 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2336 &priv->channel_mask);
2338 printk(KERN_ERR "%s: failed to read channel list!\n",
2343 /* Get initial AP density */
2344 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2346 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2347 priv->has_sensitivity = 0;
2350 /* Get initial RTS threshold */
2351 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2354 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2359 /* Get initial fragmentation settings */
2361 err = hermes_read_wordrec(hw, USER_BAP,
2362 HERMES_RID_CNFMWOROBUST_AGERE,
2365 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2366 &priv->frag_thresh);
2368 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2373 /* Power management setup */
2377 err = hermes_read_wordrec(hw, USER_BAP,
2378 HERMES_RID_CNFMAXSLEEPDURATION,
2381 printk(KERN_ERR "%s: failed to read power management period!\n",
2385 err = hermes_read_wordrec(hw, USER_BAP,
2386 HERMES_RID_CNFPMHOLDOVERDURATION,
2389 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2395 /* Preamble setup */
2396 if (priv->has_preamble) {
2397 err = hermes_read_wordrec(hw, USER_BAP,
2398 HERMES_RID_CNFPREAMBLE_SYMBOL,
2404 /* Set up the default configuration */
2405 priv->iw_mode = IW_MODE_INFRA;
2406 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2407 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2408 set_port_type(priv);
2409 priv->channel = 0; /* use firmware default */
2411 priv->promiscuous = 0;
2415 /* Make the hardware available, as long as it hasn't been
2416 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2417 spin_lock_irq(&priv->lock);
2418 priv->hw_unavailable--;
2419 spin_unlock_irq(&priv->lock);
2421 printk(KERN_DEBUG "%s: ready\n", dev->name);
2424 TRACE_EXIT(dev->name);
2428 struct net_device *alloc_orinocodev(int sizeof_card,
2429 int (*hard_reset)(struct orinoco_private *))
2431 struct net_device *dev;
2432 struct orinoco_private *priv;
2434 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2437 priv = netdev_priv(dev);
2440 priv->card = (void *)((unsigned long)priv
2441 + sizeof(struct orinoco_private));
2445 /* Setup / override net_device fields */
2446 dev->init = orinoco_init;
2447 dev->hard_start_xmit = orinoco_xmit;
2448 dev->tx_timeout = orinoco_tx_timeout;
2449 dev->watchdog_timeo = HZ; /* 1 second timeout */
2450 dev->get_stats = orinoco_get_stats;
2451 dev->ethtool_ops = &orinoco_ethtool_ops;
2452 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2454 priv->wireless_data.spy_data = &priv->spy_data;
2455 dev->wireless_data = &priv->wireless_data;
2457 dev->change_mtu = orinoco_change_mtu;
2458 dev->set_multicast_list = orinoco_set_multicast_list;
2459 /* we use the default eth_mac_addr for setting the MAC addr */
2461 /* Set up default callbacks */
2462 dev->open = orinoco_open;
2463 dev->stop = orinoco_stop;
2464 priv->hard_reset = hard_reset;
2466 spin_lock_init(&priv->lock);
2468 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2469 * before anything else touches the
2471 INIT_WORK(&priv->reset_work, (void (*)(void *))orinoco_reset, dev);
2472 INIT_WORK(&priv->join_work, (void (*)(void *))orinoco_join_ap, dev);
2473 INIT_WORK(&priv->wevent_work, (void (*)(void *))orinoco_send_wevents, dev);
2475 netif_carrier_off(dev);
2476 priv->last_linkstatus = 0xffff;
2482 void free_orinocodev(struct net_device *dev)
2484 struct orinoco_private *priv = netdev_priv(dev);
2486 kfree(priv->scan_result);
2490 /********************************************************************/
2491 /* Wireless extensions */
2492 /********************************************************************/
2494 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2495 char buf[IW_ESSID_MAX_SIZE+1])
2497 hermes_t *hw = &priv->hw;
2499 struct hermes_idstring essidbuf;
2500 char *p = (char *)(&essidbuf.val);
2502 unsigned long flags;
2504 if (orinoco_lock(priv, &flags) != 0)
2507 if (strlen(priv->desired_essid) > 0) {
2508 /* We read the desired SSID from the hardware rather
2509 than from priv->desired_essid, just in case the
2510 firmware is allowed to change it on us. I'm not
2512 /* My guess is that the OWNSSID should always be whatever
2513 * we set to the card, whereas CURRENT_SSID is the one that
2514 * may change... - Jean II */
2519 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2520 HERMES_RID_CNFDESIREDSSID;
2522 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2529 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2530 sizeof(essidbuf), NULL, &essidbuf);
2535 len = le16_to_cpu(essidbuf.len);
2536 BUG_ON(len > IW_ESSID_MAX_SIZE);
2538 memset(buf, 0, IW_ESSID_MAX_SIZE+1);
2539 memcpy(buf, p, len);
2543 orinoco_unlock(priv, &flags);
2548 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2551 hermes_t *hw = &priv->hw;
2555 unsigned long flags;
2557 if (orinoco_lock(priv, &flags) != 0)
2560 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2564 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2570 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2571 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2572 priv->ndev->name, channel);
2577 freq = channel_frequency[channel-1] * 100000;
2580 orinoco_unlock(priv, &flags);
2584 return err ? err : freq;
2587 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2588 int *numrates, s32 *rates, int max)
2590 hermes_t *hw = &priv->hw;
2591 struct hermes_idstring list;
2592 unsigned char *p = (unsigned char *)&list.val;
2596 unsigned long flags;
2598 if (orinoco_lock(priv, &flags) != 0)
2601 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2602 sizeof(list), NULL, &list);
2603 orinoco_unlock(priv, &flags);
2608 num = le16_to_cpu(list.len);
2610 num = min(num, max);
2612 for (i = 0; i < num; i++) {
2613 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2619 static int orinoco_ioctl_getname(struct net_device *dev,
2620 struct iw_request_info *info,
2624 struct orinoco_private *priv = netdev_priv(dev);
2628 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2630 if (!err && (numrates > 2))
2631 strcpy(name, "IEEE 802.11b");
2633 strcpy(name, "IEEE 802.11-DS");
2638 static int orinoco_ioctl_setwap(struct net_device *dev,
2639 struct iw_request_info *info,
2640 struct sockaddr *ap_addr,
2643 struct orinoco_private *priv = netdev_priv(dev);
2644 int err = -EINPROGRESS; /* Call commit handler */
2645 unsigned long flags;
2646 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2647 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2649 if (orinoco_lock(priv, &flags) != 0)
2652 /* Enable automatic roaming - no sanity checks are needed */
2653 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2654 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2655 priv->bssid_fixed = 0;
2656 memset(priv->desired_bssid, 0, ETH_ALEN);
2658 /* "off" means keep existing connection */
2659 if (ap_addr->sa_data[0] == 0) {
2660 __orinoco_hw_set_wap(priv);
2666 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2667 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2668 "support manual roaming\n",
2674 if (priv->iw_mode != IW_MODE_INFRA) {
2675 printk(KERN_WARNING "%s: Manual roaming supported only in "
2676 "managed mode\n", dev->name);
2681 /* Intersil firmware hangs without Desired ESSID */
2682 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2683 strlen(priv->desired_essid) == 0) {
2684 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2685 "manual roaming\n", dev->name);
2690 /* Finally, enable manual roaming */
2691 priv->bssid_fixed = 1;
2692 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2695 orinoco_unlock(priv, &flags);
2699 static int orinoco_ioctl_getwap(struct net_device *dev,
2700 struct iw_request_info *info,
2701 struct sockaddr *ap_addr,
2704 struct orinoco_private *priv = netdev_priv(dev);
2706 hermes_t *hw = &priv->hw;
2708 unsigned long flags;
2710 if (orinoco_lock(priv, &flags) != 0)
2713 ap_addr->sa_family = ARPHRD_ETHER;
2714 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2715 ETH_ALEN, NULL, ap_addr->sa_data);
2717 orinoco_unlock(priv, &flags);
2722 static int orinoco_ioctl_setmode(struct net_device *dev,
2723 struct iw_request_info *info,
2727 struct orinoco_private *priv = netdev_priv(dev);
2728 int err = -EINPROGRESS; /* Call commit handler */
2729 unsigned long flags;
2731 if (priv->iw_mode == *mode)
2734 if (orinoco_lock(priv, &flags) != 0)
2739 if (!priv->has_ibss && !priv->has_port3)
2746 case IW_MODE_MONITOR:
2747 if (priv->broken_monitor && !force_monitor) {
2748 printk(KERN_WARNING "%s: Monitor mode support is "
2749 "buggy in this firmware, not enabling\n",
2760 if (err == -EINPROGRESS) {
2761 priv->iw_mode = *mode;
2762 set_port_type(priv);
2765 orinoco_unlock(priv, &flags);
2770 static int orinoco_ioctl_getmode(struct net_device *dev,
2771 struct iw_request_info *info,
2775 struct orinoco_private *priv = netdev_priv(dev);
2777 *mode = priv->iw_mode;
2781 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2782 struct iw_request_info *info,
2783 struct iw_point *rrq,
2786 struct orinoco_private *priv = netdev_priv(dev);
2788 struct iw_range *range = (struct iw_range *) extra;
2792 TRACE_ENTER(dev->name);
2794 rrq->length = sizeof(struct iw_range);
2795 memset(range, 0, sizeof(struct iw_range));
2797 range->we_version_compiled = WIRELESS_EXT;
2798 range->we_version_source = 14;
2800 /* Set available channels/frequencies */
2801 range->num_channels = NUM_CHANNELS;
2803 for (i = 0; i < NUM_CHANNELS; i++) {
2804 if (priv->channel_mask & (1 << i)) {
2805 range->freq[k].i = i + 1;
2806 range->freq[k].m = channel_frequency[i] * 100000;
2807 range->freq[k].e = 1;
2811 if (k >= IW_MAX_FREQUENCIES)
2814 range->num_frequency = k;
2815 range->sensitivity = 3;
2817 if (priv->has_wep) {
2818 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2819 range->encoding_size[0] = SMALL_KEY_SIZE;
2820 range->num_encoding_sizes = 1;
2822 if (priv->has_big_wep) {
2823 range->encoding_size[1] = LARGE_KEY_SIZE;
2824 range->num_encoding_sizes = 2;
2828 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2829 /* Quality stats meaningless in ad-hoc mode */
2831 range->max_qual.qual = 0x8b - 0x2f;
2832 range->max_qual.level = 0x2f - 0x95 - 1;
2833 range->max_qual.noise = 0x2f - 0x95 - 1;
2834 /* Need to get better values */
2835 range->avg_qual.qual = 0x24;
2836 range->avg_qual.level = 0xC2;
2837 range->avg_qual.noise = 0x9E;
2840 err = orinoco_hw_get_bitratelist(priv, &numrates,
2841 range->bitrate, IW_MAX_BITRATES);
2844 range->num_bitrates = numrates;
2846 /* Set an indication of the max TCP throughput in bit/s that we can
2847 * expect using this interface. May be use for QoS stuff...
2850 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2852 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2855 range->max_rts = 2347;
2856 range->min_frag = 256;
2857 range->max_frag = 2346;
2860 range->max_pmp = 65535000;
2862 range->max_pmt = 65535 * 1000; /* ??? */
2863 range->pmp_flags = IW_POWER_PERIOD;
2864 range->pmt_flags = IW_POWER_TIMEOUT;
2865 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2867 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2868 range->retry_flags = IW_RETRY_LIMIT;
2869 range->r_time_flags = IW_RETRY_LIFETIME;
2870 range->min_retry = 0;
2871 range->max_retry = 65535; /* ??? */
2872 range->min_r_time = 0;
2873 range->max_r_time = 65535 * 1000; /* ??? */
2875 /* Event capability (kernel) */
2876 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2877 /* Event capability (driver) */
2878 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2879 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2880 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2881 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2883 TRACE_EXIT(dev->name);
2888 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2889 struct iw_request_info *info,
2890 struct iw_point *erq,
2893 struct orinoco_private *priv = netdev_priv(dev);
2894 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2895 int setindex = priv->tx_key;
2896 int enable = priv->wep_on;
2897 int restricted = priv->wep_restrict;
2899 int err = -EINPROGRESS; /* Call commit handler */
2900 unsigned long flags;
2902 if (! priv->has_wep)
2906 /* We actually have a key to set - check its length */
2907 if (erq->length > LARGE_KEY_SIZE)
2910 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
2914 if (orinoco_lock(priv, &flags) != 0)
2918 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
2919 index = priv->tx_key;
2921 /* Adjust key length to a supported value */
2922 if (erq->length > SMALL_KEY_SIZE) {
2923 xlen = LARGE_KEY_SIZE;
2924 } else if (erq->length > 0) {
2925 xlen = SMALL_KEY_SIZE;
2929 /* Switch on WEP if off */
2930 if ((!enable) && (xlen > 0)) {
2935 /* Important note : if the user do "iwconfig eth0 enc off",
2936 * we will arrive there with an index of -1. This is valid
2937 * but need to be taken care off... Jean II */
2938 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
2939 if((index != -1) || (erq->flags == 0)) {
2944 /* Set the index : Check that the key is valid */
2945 if(priv->keys[index].len == 0) {
2953 if (erq->flags & IW_ENCODE_DISABLED)
2955 if (erq->flags & IW_ENCODE_OPEN)
2957 if (erq->flags & IW_ENCODE_RESTRICTED)
2961 priv->keys[index].len = cpu_to_le16(xlen);
2962 memset(priv->keys[index].data, 0,
2963 sizeof(priv->keys[index].data));
2964 memcpy(priv->keys[index].data, keybuf, erq->length);
2966 priv->tx_key = setindex;
2968 /* Try fast key change if connected and only keys are changed */
2969 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
2970 netif_carrier_ok(dev)) {
2971 err = __orinoco_hw_setup_wepkeys(priv);
2972 /* No need to commit if successful */
2976 priv->wep_on = enable;
2977 priv->wep_restrict = restricted;
2980 orinoco_unlock(priv, &flags);
2985 static int orinoco_ioctl_getiwencode(struct net_device *dev,
2986 struct iw_request_info *info,
2987 struct iw_point *erq,
2990 struct orinoco_private *priv = netdev_priv(dev);
2991 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
2993 unsigned long flags;
2995 if (! priv->has_wep)
2998 if (orinoco_lock(priv, &flags) != 0)
3001 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3002 index = priv->tx_key;
3006 erq->flags |= IW_ENCODE_DISABLED;
3007 erq->flags |= index + 1;
3009 if (priv->wep_restrict)
3010 erq->flags |= IW_ENCODE_RESTRICTED;
3012 erq->flags |= IW_ENCODE_OPEN;
3014 xlen = le16_to_cpu(priv->keys[index].len);
3018 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3020 orinoco_unlock(priv, &flags);
3024 static int orinoco_ioctl_setessid(struct net_device *dev,
3025 struct iw_request_info *info,
3026 struct iw_point *erq,
3029 struct orinoco_private *priv = netdev_priv(dev);
3030 unsigned long flags;
3032 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3033 * anyway... - Jean II */
3035 /* Hum... Should not use Wireless Extension constant (may change),
3036 * should use our own... - Jean II */
3037 if (erq->length > IW_ESSID_MAX_SIZE)
3040 if (orinoco_lock(priv, &flags) != 0)
3043 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3044 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3046 /* If not ANY, get the new ESSID */
3048 memcpy(priv->desired_essid, essidbuf, erq->length);
3051 orinoco_unlock(priv, &flags);
3053 return -EINPROGRESS; /* Call commit handler */
3056 static int orinoco_ioctl_getessid(struct net_device *dev,
3057 struct iw_request_info *info,
3058 struct iw_point *erq,
3061 struct orinoco_private *priv = netdev_priv(dev);
3064 unsigned long flags;
3066 TRACE_ENTER(dev->name);
3068 if (netif_running(dev)) {
3069 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3073 if (orinoco_lock(priv, &flags) != 0)
3075 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE + 1);
3076 orinoco_unlock(priv, &flags);
3080 erq->length = strlen(essidbuf) + 1;
3082 TRACE_EXIT(dev->name);
3087 static int orinoco_ioctl_setnick(struct net_device *dev,
3088 struct iw_request_info *info,
3089 struct iw_point *nrq,
3092 struct orinoco_private *priv = netdev_priv(dev);
3093 unsigned long flags;
3095 if (nrq->length > IW_ESSID_MAX_SIZE)
3098 if (orinoco_lock(priv, &flags) != 0)
3101 memset(priv->nick, 0, sizeof(priv->nick));
3102 memcpy(priv->nick, nickbuf, nrq->length);
3104 orinoco_unlock(priv, &flags);
3106 return -EINPROGRESS; /* Call commit handler */
3109 static int orinoco_ioctl_getnick(struct net_device *dev,
3110 struct iw_request_info *info,
3111 struct iw_point *nrq,
3114 struct orinoco_private *priv = netdev_priv(dev);
3115 unsigned long flags;
3117 if (orinoco_lock(priv, &flags) != 0)
3120 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE+1);
3121 orinoco_unlock(priv, &flags);
3123 nrq->length = strlen(nickbuf)+1;
3128 static int orinoco_ioctl_setfreq(struct net_device *dev,
3129 struct iw_request_info *info,
3130 struct iw_freq *frq,
3133 struct orinoco_private *priv = netdev_priv(dev);
3135 unsigned long flags;
3136 int err = -EINPROGRESS; /* Call commit handler */
3138 /* In infrastructure mode the AP sets the channel */
3139 if (priv->iw_mode == IW_MODE_INFRA)
3142 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3143 /* Setting by channel number */
3146 /* Setting by frequency - search the table */
3150 for (i = 0; i < (6 - frq->e); i++)
3153 for (i = 0; i < NUM_CHANNELS; i++)
3154 if (frq->m == (channel_frequency[i] * mult))
3158 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3159 ! (priv->channel_mask & (1 << (chan-1)) ) )
3162 if (orinoco_lock(priv, &flags) != 0)
3165 priv->channel = chan;
3166 if (priv->iw_mode == IW_MODE_MONITOR) {
3167 /* Fast channel change - no commit if successful */
3168 hermes_t *hw = &priv->hw;
3169 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3170 HERMES_TEST_SET_CHANNEL,
3173 orinoco_unlock(priv, &flags);
3178 static int orinoco_ioctl_getfreq(struct net_device *dev,
3179 struct iw_request_info *info,
3180 struct iw_freq *frq,
3183 struct orinoco_private *priv = netdev_priv(dev);
3186 /* Locking done in there */
3187 tmp = orinoco_hw_get_freq(priv);
3198 static int orinoco_ioctl_getsens(struct net_device *dev,
3199 struct iw_request_info *info,
3200 struct iw_param *srq,
3203 struct orinoco_private *priv = netdev_priv(dev);
3204 hermes_t *hw = &priv->hw;
3207 unsigned long flags;
3209 if (!priv->has_sensitivity)
3212 if (orinoco_lock(priv, &flags) != 0)
3214 err = hermes_read_wordrec(hw, USER_BAP,
3215 HERMES_RID_CNFSYSTEMSCALE, &val);
3216 orinoco_unlock(priv, &flags);
3222 srq->fixed = 0; /* auto */
3227 static int orinoco_ioctl_setsens(struct net_device *dev,
3228 struct iw_request_info *info,
3229 struct iw_param *srq,
3232 struct orinoco_private *priv = netdev_priv(dev);
3233 int val = srq->value;
3234 unsigned long flags;
3236 if (!priv->has_sensitivity)
3239 if ((val < 1) || (val > 3))
3242 if (orinoco_lock(priv, &flags) != 0)
3244 priv->ap_density = val;
3245 orinoco_unlock(priv, &flags);
3247 return -EINPROGRESS; /* Call commit handler */
3250 static int orinoco_ioctl_setrts(struct net_device *dev,
3251 struct iw_request_info *info,
3252 struct iw_param *rrq,
3255 struct orinoco_private *priv = netdev_priv(dev);
3256 int val = rrq->value;
3257 unsigned long flags;
3262 if ( (val < 0) || (val > 2347) )
3265 if (orinoco_lock(priv, &flags) != 0)
3268 priv->rts_thresh = val;
3269 orinoco_unlock(priv, &flags);
3271 return -EINPROGRESS; /* Call commit handler */
3274 static int orinoco_ioctl_getrts(struct net_device *dev,
3275 struct iw_request_info *info,
3276 struct iw_param *rrq,
3279 struct orinoco_private *priv = netdev_priv(dev);
3281 rrq->value = priv->rts_thresh;
3282 rrq->disabled = (rrq->value == 2347);
3288 static int orinoco_ioctl_setfrag(struct net_device *dev,
3289 struct iw_request_info *info,
3290 struct iw_param *frq,
3293 struct orinoco_private *priv = netdev_priv(dev);
3294 int err = -EINPROGRESS; /* Call commit handler */
3295 unsigned long flags;
3297 if (orinoco_lock(priv, &flags) != 0)
3300 if (priv->has_mwo) {
3302 priv->mwo_robust = 0;
3305 printk(KERN_WARNING "%s: Fixed fragmentation is "
3306 "not supported on this firmware. "
3307 "Using MWO robust instead.\n", dev->name);
3308 priv->mwo_robust = 1;
3312 priv->frag_thresh = 2346;
3314 if ( (frq->value < 256) || (frq->value > 2346) )
3317 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3321 orinoco_unlock(priv, &flags);
3326 static int orinoco_ioctl_getfrag(struct net_device *dev,
3327 struct iw_request_info *info,
3328 struct iw_param *frq,
3331 struct orinoco_private *priv = netdev_priv(dev);
3332 hermes_t *hw = &priv->hw;
3335 unsigned long flags;
3337 if (orinoco_lock(priv, &flags) != 0)
3340 if (priv->has_mwo) {
3341 err = hermes_read_wordrec(hw, USER_BAP,
3342 HERMES_RID_CNFMWOROBUST_AGERE,
3347 frq->value = val ? 2347 : 0;
3348 frq->disabled = ! val;
3351 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3357 frq->disabled = (val >= 2346);
3361 orinoco_unlock(priv, &flags);
3366 static int orinoco_ioctl_setrate(struct net_device *dev,
3367 struct iw_request_info *info,
3368 struct iw_param *rrq,
3371 struct orinoco_private *priv = netdev_priv(dev);
3373 int bitrate; /* 100s of kilobits */
3375 unsigned long flags;
3377 /* As the user space doesn't know our highest rate, it uses -1
3378 * to ask us to set the highest rate. Test it using "iwconfig
3379 * ethX rate auto" - Jean II */
3380 if (rrq->value == -1)
3383 if (rrq->value % 100000)
3385 bitrate = rrq->value / 100000;
3388 if ( (bitrate != 10) && (bitrate != 20) &&
3389 (bitrate != 55) && (bitrate != 110) )
3392 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3393 if ( (bitrate_table[i].bitrate == bitrate) &&
3394 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3402 if (orinoco_lock(priv, &flags) != 0)
3404 priv->bitratemode = ratemode;
3405 orinoco_unlock(priv, &flags);
3407 return -EINPROGRESS;
3410 static int orinoco_ioctl_getrate(struct net_device *dev,
3411 struct iw_request_info *info,
3412 struct iw_param *rrq,
3415 struct orinoco_private *priv = netdev_priv(dev);
3416 hermes_t *hw = &priv->hw;
3421 unsigned long flags;
3423 if (orinoco_lock(priv, &flags) != 0)
3426 ratemode = priv->bitratemode;
3428 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3430 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3431 rrq->fixed = ! bitrate_table[ratemode].automatic;
3434 /* If the interface is running we try to find more about the
3436 if (netif_running(dev)) {
3437 err = hermes_read_wordrec(hw, USER_BAP,
3438 HERMES_RID_CURRENTTXRATE, &val);
3442 switch (priv->firmware_type) {
3443 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3444 /* Note : in Lucent firmware, the return value of
3445 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3446 * and therefore is totally different from the
3447 * encoding of HERMES_RID_CNFTXRATECONTROL.
3448 * Don't forget that 6Mb/s is really 5.5Mb/s */
3450 rrq->value = 5500000;
3452 rrq->value = val * 1000000;
3454 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3455 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3456 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3457 if (bitrate_table[i].intersil_txratectrl == val) {
3461 if (i >= BITRATE_TABLE_SIZE)
3462 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3465 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3473 orinoco_unlock(priv, &flags);
3478 static int orinoco_ioctl_setpower(struct net_device *dev,
3479 struct iw_request_info *info,
3480 struct iw_param *prq,
3483 struct orinoco_private *priv = netdev_priv(dev);
3484 int err = -EINPROGRESS; /* Call commit handler */
3485 unsigned long flags;
3487 if (orinoco_lock(priv, &flags) != 0)
3490 if (prq->disabled) {
3493 switch (prq->flags & IW_POWER_MODE) {
3494 case IW_POWER_UNICAST_R:
3498 case IW_POWER_ALL_R:
3503 /* No flags : but we may have a value - Jean II */
3511 if (prq->flags & IW_POWER_TIMEOUT) {
3513 priv->pm_timeout = prq->value / 1000;
3515 if (prq->flags & IW_POWER_PERIOD) {
3517 priv->pm_period = prq->value / 1000;
3519 /* It's valid to not have a value if we are just toggling
3520 * the flags... Jean II */
3528 orinoco_unlock(priv, &flags);
3533 static int orinoco_ioctl_getpower(struct net_device *dev,
3534 struct iw_request_info *info,
3535 struct iw_param *prq,
3538 struct orinoco_private *priv = netdev_priv(dev);
3539 hermes_t *hw = &priv->hw;
3541 u16 enable, period, timeout, mcast;
3542 unsigned long flags;
3544 if (orinoco_lock(priv, &flags) != 0)
3547 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3551 err = hermes_read_wordrec(hw, USER_BAP,
3552 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3556 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3560 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3564 prq->disabled = !enable;
3565 /* Note : by default, display the period */
3566 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3567 prq->flags = IW_POWER_TIMEOUT;
3568 prq->value = timeout * 1000;
3570 prq->flags = IW_POWER_PERIOD;
3571 prq->value = period * 1000;
3574 prq->flags |= IW_POWER_ALL_R;
3576 prq->flags |= IW_POWER_UNICAST_R;
3579 orinoco_unlock(priv, &flags);
3584 static int orinoco_ioctl_getretry(struct net_device *dev,
3585 struct iw_request_info *info,
3586 struct iw_param *rrq,
3589 struct orinoco_private *priv = netdev_priv(dev);
3590 hermes_t *hw = &priv->hw;
3592 u16 short_limit, long_limit, lifetime;
3593 unsigned long flags;
3595 if (orinoco_lock(priv, &flags) != 0)
3598 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3603 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3608 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3613 rrq->disabled = 0; /* Can't be disabled */
3615 /* Note : by default, display the retry number */
3616 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3617 rrq->flags = IW_RETRY_LIFETIME;
3618 rrq->value = lifetime * 1000; /* ??? */
3620 /* By default, display the min number */
3621 if ((rrq->flags & IW_RETRY_MAX)) {
3622 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
3623 rrq->value = long_limit;
3625 rrq->flags = IW_RETRY_LIMIT;
3626 rrq->value = short_limit;
3627 if(short_limit != long_limit)
3628 rrq->flags |= IW_RETRY_MIN;
3633 orinoco_unlock(priv, &flags);
3638 static int orinoco_ioctl_reset(struct net_device *dev,
3639 struct iw_request_info *info,
3643 struct orinoco_private *priv = netdev_priv(dev);
3645 if (! capable(CAP_NET_ADMIN))
3648 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3649 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3651 /* Firmware reset */
3654 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3656 schedule_work(&priv->reset_work);
3662 static int orinoco_ioctl_setibssport(struct net_device *dev,
3663 struct iw_request_info *info,
3668 struct orinoco_private *priv = netdev_priv(dev);
3669 int val = *( (int *) extra );
3670 unsigned long flags;
3672 if (orinoco_lock(priv, &flags) != 0)
3675 priv->ibss_port = val ;
3677 /* Actually update the mode we are using */
3678 set_port_type(priv);
3680 orinoco_unlock(priv, &flags);
3681 return -EINPROGRESS; /* Call commit handler */
3684 static int orinoco_ioctl_getibssport(struct net_device *dev,
3685 struct iw_request_info *info,
3689 struct orinoco_private *priv = netdev_priv(dev);
3690 int *val = (int *) extra;
3692 *val = priv->ibss_port;
3696 static int orinoco_ioctl_setport3(struct net_device *dev,
3697 struct iw_request_info *info,
3701 struct orinoco_private *priv = netdev_priv(dev);
3702 int val = *( (int *) extra );
3704 unsigned long flags;
3706 if (orinoco_lock(priv, &flags) != 0)
3710 case 0: /* Try to do IEEE ad-hoc mode */
3711 if (! priv->has_ibss) {
3715 priv->prefer_port3 = 0;
3719 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3720 if (! priv->has_port3) {
3724 priv->prefer_port3 = 1;
3732 /* Actually update the mode we are using */
3733 set_port_type(priv);
3737 orinoco_unlock(priv, &flags);
3742 static int orinoco_ioctl_getport3(struct net_device *dev,
3743 struct iw_request_info *info,
3747 struct orinoco_private *priv = netdev_priv(dev);
3748 int *val = (int *) extra;
3750 *val = priv->prefer_port3;
3754 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3755 struct iw_request_info *info,
3759 struct orinoco_private *priv = netdev_priv(dev);
3760 unsigned long flags;
3763 if (! priv->has_preamble)
3766 /* 802.11b has recently defined some short preamble.
3767 * Basically, the Phy header has been reduced in size.
3768 * This increase performance, especially at high rates
3769 * (the preamble is transmitted at 1Mb/s), unfortunately
3770 * this give compatibility troubles... - Jean II */
3771 val = *( (int *) extra );
3773 if (orinoco_lock(priv, &flags) != 0)
3781 orinoco_unlock(priv, &flags);
3783 return -EINPROGRESS; /* Call commit handler */
3786 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3787 struct iw_request_info *info,
3791 struct orinoco_private *priv = netdev_priv(dev);
3792 int *val = (int *) extra;
3794 if (! priv->has_preamble)
3797 *val = priv->preamble;
3801 /* ioctl interface to hermes_read_ltv()
3802 * To use with iwpriv, pass the RID as the token argument, e.g.
3803 * iwpriv get_rid [0xfc00]
3804 * At least Wireless Tools 25 is required to use iwpriv.
3805 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3806 static int orinoco_ioctl_getrid(struct net_device *dev,
3807 struct iw_request_info *info,
3808 struct iw_point *data,
3811 struct orinoco_private *priv = netdev_priv(dev);
3812 hermes_t *hw = &priv->hw;
3813 int rid = data->flags;
3816 unsigned long flags;
3818 /* It's a "get" function, but we don't want users to access the
3819 * WEP key and other raw firmware data */
3820 if (! capable(CAP_NET_ADMIN))
3823 if (rid < 0xfc00 || rid > 0xffff)
3826 if (orinoco_lock(priv, &flags) != 0)
3829 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3834 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3838 orinoco_unlock(priv, &flags);
3842 /* Trigger a scan (look for other cells in the vicinity */
3843 static int orinoco_ioctl_setscan(struct net_device *dev,
3844 struct iw_request_info *info,
3845 struct iw_param *srq,
3848 struct orinoco_private *priv = netdev_priv(dev);
3849 hermes_t *hw = &priv->hw;
3851 unsigned long flags;
3853 /* Note : you may have realised that, as this is a SET operation,
3854 * this is priviledged and therefore a normal user can't
3856 * This is not an error, while the device perform scanning,
3857 * traffic doesn't flow, so it's a perfect DoS...
3860 if (orinoco_lock(priv, &flags) != 0)
3863 /* Scanning with port 0 disabled would fail */
3864 if (!netif_running(dev)) {
3869 /* In monitor mode, the scan results are always empty.
3870 * Probe responses are passed to the driver as received
3871 * frames and could be processed in software. */
3872 if (priv->iw_mode == IW_MODE_MONITOR) {
3877 /* Note : because we don't lock out the irq handler, the way
3878 * we access scan variables in priv is critical.
3879 * o scan_inprogress : not touched by irq handler
3880 * o scan_mode : not touched by irq handler
3881 * o scan_result : irq is strict producer, non-irq is strict
3883 * o scan_len : synchronised with scan_result
3884 * Before modifying anything on those variables, please think hard !
3887 /* If there is still some left-over scan results, get rid of it */
3888 if (priv->scan_result != NULL) {
3889 /* What's likely is that a client did crash or was killed
3890 * between triggering the scan request and reading the
3891 * results, so we need to reset everything.
3892 * Some clients that are too slow may suffer from that...
3894 kfree(priv->scan_result);
3895 priv->scan_result = NULL;
3899 priv->scan_mode = srq->flags;
3901 /* Always trigger scanning, even if it's in progress.
3902 * This way, if the info frame get lost, we will recover somewhat
3903 * gracefully - Jean II */
3905 if (priv->has_hostscan) {
3906 switch (priv->firmware_type) {
3907 case FIRMWARE_TYPE_SYMBOL:
3908 err = hermes_write_wordrec(hw, USER_BAP,
3909 HERMES_RID_CNFHOSTSCAN_SYMBOL,
3910 HERMES_HOSTSCAN_SYMBOL_ONCE |
3911 HERMES_HOSTSCAN_SYMBOL_BCAST);
3913 case FIRMWARE_TYPE_INTERSIL: {
3916 req[0] = cpu_to_le16(0x3fff); /* All channels */
3917 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3918 req[2] = 0; /* Any ESSID */
3919 err = HERMES_WRITE_RECORD(hw, USER_BAP,
3920 HERMES_RID_CNFHOSTSCAN, &req);
3923 case FIRMWARE_TYPE_AGERE:
3924 err = hermes_write_wordrec(hw, USER_BAP,
3925 HERMES_RID_CNFSCANSSID_AGERE,
3930 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3934 err = hermes_inquire(hw, HERMES_INQ_SCAN);
3936 /* One more client */
3938 priv->scan_inprogress = 1;
3941 orinoco_unlock(priv, &flags);
3945 /* Translate scan data returned from the card to a card independant
3946 * format that the Wireless Tools will understand - Jean II
3947 * Return message length or -errno for fatal errors */
3948 static inline int orinoco_translate_scan(struct net_device *dev,
3953 struct orinoco_private *priv = netdev_priv(dev);
3954 int offset; /* In the scan data */
3955 union hermes_scan_info *atom;
3959 struct iw_event iwe; /* Temporary buffer */
3960 char * current_ev = buffer;
3961 char * end_buf = buffer + IW_SCAN_MAX_DATA;
3963 switch (priv->firmware_type) {
3964 case FIRMWARE_TYPE_AGERE:
3965 atom_len = sizeof(struct agere_scan_apinfo);
3968 case FIRMWARE_TYPE_SYMBOL:
3969 /* Lack of documentation necessitates this hack.
3970 * Different firmwares have 68 or 76 byte long atoms.
3971 * We try modulo first. If the length divides by both,
3972 * we check what would be the channel in the second
3973 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3974 * Valid channel cannot be 0. */
3977 else if (scan_len % 68)
3979 else if (scan_len >= 1292 && scan[68] == 0)
3985 case FIRMWARE_TYPE_INTERSIL:
3987 if (priv->has_hostscan) {
3988 atom_len = le16_to_cpup((__le16 *)scan);
3989 /* Sanity check for atom_len */
3990 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
3991 printk(KERN_ERR "%s: Invalid atom_len in scan data: %d\n",
3992 dev->name, atom_len);
3996 atom_len = offsetof(struct prism2_scan_apinfo, atim);
4002 /* Check that we got an whole number of atoms */
4003 if ((scan_len - offset) % atom_len) {
4004 printk(KERN_ERR "%s: Unexpected scan data length %d, "
4005 "atom_len %d, offset %d\n", dev->name, scan_len,
4010 /* Read the entries one by one */
4011 for (; offset + atom_len <= scan_len; offset += atom_len) {
4013 atom = (union hermes_scan_info *) (scan + offset);
4015 /* First entry *MUST* be the AP MAC address */
4016 iwe.cmd = SIOCGIWAP;
4017 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4018 memcpy(iwe.u.ap_addr.sa_data, atom->a.bssid, ETH_ALEN);
4019 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
4021 /* Other entries will be displayed in the order we give them */
4024 iwe.u.data.length = le16_to_cpu(atom->a.essid_len);
4025 if (iwe.u.data.length > 32)
4026 iwe.u.data.length = 32;
4027 iwe.cmd = SIOCGIWESSID;
4028 iwe.u.data.flags = 1;
4029 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4032 iwe.cmd = SIOCGIWMODE;
4033 capabilities = le16_to_cpu(atom->a.capabilities);
4034 if (capabilities & 0x3) {
4035 if (capabilities & 0x1)
4036 iwe.u.mode = IW_MODE_MASTER;
4038 iwe.u.mode = IW_MODE_ADHOC;
4039 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
4042 channel = atom->s.channel;
4043 if ( (channel >= 1) && (channel <= NUM_CHANNELS) ) {
4045 iwe.cmd = SIOCGIWFREQ;
4046 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4048 current_ev = iwe_stream_add_event(current_ev, end_buf,
4049 &iwe, IW_EV_FREQ_LEN);
4052 /* Add quality statistics */
4054 iwe.u.qual.updated = 0x10; /* no link quality */
4055 iwe.u.qual.level = (__u8) le16_to_cpu(atom->a.level) - 0x95;
4056 iwe.u.qual.noise = (__u8) le16_to_cpu(atom->a.noise) - 0x95;
4057 /* Wireless tools prior to 27.pre22 will show link quality
4058 * anyway, so we provide a reasonable value. */
4059 if (iwe.u.qual.level > iwe.u.qual.noise)
4060 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4062 iwe.u.qual.qual = 0;
4063 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
4065 /* Add encryption capability */
4066 iwe.cmd = SIOCGIWENCODE;
4067 if (capabilities & 0x10)
4068 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4070 iwe.u.data.flags = IW_ENCODE_DISABLED;
4071 iwe.u.data.length = 0;
4072 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, atom->a.essid);
4074 /* Bit rate is not available in Lucent/Agere firmwares */
4075 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4076 char * current_val = current_ev + IW_EV_LCP_LEN;
4080 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4085 iwe.cmd = SIOCGIWRATE;
4086 /* Those two flags are ignored... */
4087 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4089 for (i = 0; i < 10; i += step) {
4090 /* NULL terminated */
4091 if (atom->p.rates[i] == 0x0)
4093 /* Bit rate given in 500 kb/s units (+ 0x80) */
4094 iwe.u.bitrate.value = ((atom->p.rates[i] & 0x7f) * 500000);
4095 current_val = iwe_stream_add_value(current_ev, current_val,
4099 /* Check if we added any event */
4100 if ((current_val - current_ev) > IW_EV_LCP_LEN)
4101 current_ev = current_val;
4104 /* The other data in the scan result are not really
4105 * interesting, so for now drop it - Jean II */
4107 return current_ev - buffer;
4110 /* Return results of a scan */
4111 static int orinoco_ioctl_getscan(struct net_device *dev,
4112 struct iw_request_info *info,
4113 struct iw_point *srq,
4116 struct orinoco_private *priv = netdev_priv(dev);
4118 unsigned long flags;
4120 if (orinoco_lock(priv, &flags) != 0)
4123 /* If no results yet, ask to try again later */
4124 if (priv->scan_result == NULL) {
4125 if (priv->scan_inprogress)
4126 /* Important note : we don't want to block the caller
4127 * until results are ready for various reasons.
4128 * First, managing wait queues is complex and racy.
4129 * Second, we grab some rtnetlink lock before comming
4130 * here (in dev_ioctl()).
4131 * Third, we generate an Wireless Event, so the
4132 * caller can wait itself on that - Jean II */
4135 /* Client error, no scan results...
4136 * The caller need to restart the scan. */
4139 /* We have some results to push back to user space */
4141 /* Translate to WE format */
4142 int ret = orinoco_translate_scan(dev, extra,
4148 kfree(priv->scan_result);
4149 priv->scan_result = NULL;
4154 srq->flags = (__u16) priv->scan_mode;
4156 /* In any case, Scan results will be cleaned up in the
4157 * reset function and when exiting the driver.
4158 * The person triggering the scanning may never come to
4159 * pick the results, so we need to do it in those places.
4162 #ifdef SCAN_SINGLE_READ
4163 /* If you enable this option, only one client (the first
4164 * one) will be able to read the result (and only one
4165 * time). If there is multiple concurent clients that
4166 * want to read scan results, this behavior is not
4167 * advisable - Jean II */
4168 kfree(priv->scan_result);
4169 priv->scan_result = NULL;
4170 #endif /* SCAN_SINGLE_READ */
4171 /* Here, if too much time has elapsed since last scan,
4172 * we may want to clean up scan results... - Jean II */
4175 /* Scan is no longer in progress */
4176 priv->scan_inprogress = 0;
4179 orinoco_unlock(priv, &flags);
4183 /* Commit handler, called after set operations */
4184 static int orinoco_ioctl_commit(struct net_device *dev,
4185 struct iw_request_info *info,
4189 struct orinoco_private *priv = netdev_priv(dev);
4190 struct hermes *hw = &priv->hw;
4191 unsigned long flags;
4197 if (priv->broken_disableport) {
4202 if (orinoco_lock(priv, &flags) != 0)
4205 err = hermes_disable_port(hw, 0);
4207 printk(KERN_WARNING "%s: Unable to disable port "
4208 "while reconfiguring card\n", dev->name);
4209 priv->broken_disableport = 1;
4213 err = __orinoco_program_rids(dev);
4215 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4220 err = hermes_enable_port(hw, 0);
4222 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4229 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4230 schedule_work(&priv->reset_work);
4234 orinoco_unlock(priv, &flags);
4238 static const struct iw_priv_args orinoco_privtab[] = {
4239 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4240 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4241 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4243 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4245 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4246 0, "set_preamble" },
4247 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4249 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4250 0, "set_ibssport" },
4251 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4253 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4259 * Structures to export the Wireless Handlers
4262 static const iw_handler orinoco_handler[] = {
4263 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4264 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4265 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4266 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4267 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4268 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4269 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4270 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4271 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4272 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4273 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4274 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4275 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4276 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4277 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4278 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4279 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4280 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4281 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4282 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4283 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4284 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4285 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4286 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4287 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4288 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4289 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4290 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4291 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4292 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4293 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4294 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4299 Added typecasting since we no longer use iwreq_data -- Moustafa
4301 static const iw_handler orinoco_private_handler[] = {
4302 [0] = (iw_handler) orinoco_ioctl_reset,
4303 [1] = (iw_handler) orinoco_ioctl_reset,
4304 [2] = (iw_handler) orinoco_ioctl_setport3,
4305 [3] = (iw_handler) orinoco_ioctl_getport3,
4306 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4307 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4308 [6] = (iw_handler) orinoco_ioctl_setibssport,
4309 [7] = (iw_handler) orinoco_ioctl_getibssport,
4310 [9] = (iw_handler) orinoco_ioctl_getrid,
4313 static const struct iw_handler_def orinoco_handler_def = {
4314 .num_standard = ARRAY_SIZE(orinoco_handler),
4315 .num_private = ARRAY_SIZE(orinoco_private_handler),
4316 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4317 .standard = orinoco_handler,
4318 .private = orinoco_private_handler,
4319 .private_args = orinoco_privtab,
4320 .get_wireless_stats = orinoco_get_wireless_stats,
4323 static void orinoco_get_drvinfo(struct net_device *dev,
4324 struct ethtool_drvinfo *info)
4326 struct orinoco_private *priv = netdev_priv(dev);
4328 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4329 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4330 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4331 if (dev->class_dev.dev)
4332 strncpy(info->bus_info, dev->class_dev.dev->bus_id,
4333 sizeof(info->bus_info) - 1);
4335 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4336 "PCMCIA %p", priv->hw.iobase);
4339 static struct ethtool_ops orinoco_ethtool_ops = {
4340 .get_drvinfo = orinoco_get_drvinfo,
4341 .get_link = ethtool_op_get_link,
4344 /********************************************************************/
4346 /********************************************************************/
4349 static void show_rx_frame(struct orinoco_rxframe_hdr *frame)
4351 printk(KERN_DEBUG "RX descriptor:\n");
4352 printk(KERN_DEBUG " status = 0x%04x\n", frame->desc.status);
4353 printk(KERN_DEBUG " time = 0x%08x\n", frame->desc.time);
4354 printk(KERN_DEBUG " silence = 0x%02x\n", frame->desc.silence);
4355 printk(KERN_DEBUG " signal = 0x%02x\n", frame->desc.signal);
4356 printk(KERN_DEBUG " rate = 0x%02x\n", frame->desc.rate);
4357 printk(KERN_DEBUG " rxflow = 0x%02x\n", frame->desc.rxflow);
4358 printk(KERN_DEBUG " reserved = 0x%08x\n", frame->desc.reserved);
4360 printk(KERN_DEBUG "IEEE 802.11 header:\n");
4361 printk(KERN_DEBUG " frame_ctl = 0x%04x\n",
4362 frame->p80211.frame_ctl);
4363 printk(KERN_DEBUG " duration_id = 0x%04x\n",
4364 frame->p80211.duration_id);
4365 printk(KERN_DEBUG " addr1 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4366 frame->p80211.addr1[0], frame->p80211.addr1[1],
4367 frame->p80211.addr1[2], frame->p80211.addr1[3],
4368 frame->p80211.addr1[4], frame->p80211.addr1[5]);
4369 printk(KERN_DEBUG " addr2 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4370 frame->p80211.addr2[0], frame->p80211.addr2[1],
4371 frame->p80211.addr2[2], frame->p80211.addr2[3],
4372 frame->p80211.addr2[4], frame->p80211.addr2[5]);
4373 printk(KERN_DEBUG " addr3 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4374 frame->p80211.addr3[0], frame->p80211.addr3[1],
4375 frame->p80211.addr3[2], frame->p80211.addr3[3],
4376 frame->p80211.addr3[4], frame->p80211.addr3[5]);
4377 printk(KERN_DEBUG " seq_ctl = 0x%04x\n",
4378 frame->p80211.seq_ctl);
4379 printk(KERN_DEBUG " addr4 = %02x:%02x:%02x:%02x:%02x:%02x\n",
4380 frame->p80211.addr4[0], frame->p80211.addr4[1],
4381 frame->p80211.addr4[2], frame->p80211.addr4[3],
4382 frame->p80211.addr4[4], frame->p80211.addr4[5]);
4383 printk(KERN_DEBUG " data_len = 0x%04x\n",
4384 frame->p80211.data_len);
4386 printk(KERN_DEBUG "IEEE 802.3 header:\n");
4387 printk(KERN_DEBUG " dest = %02x:%02x:%02x:%02x:%02x:%02x\n",
4388 frame->p8023.h_dest[0], frame->p8023.h_dest[1],
4389 frame->p8023.h_dest[2], frame->p8023.h_dest[3],
4390 frame->p8023.h_dest[4], frame->p8023.h_dest[5]);
4391 printk(KERN_DEBUG " src = %02x:%02x:%02x:%02x:%02x:%02x\n",
4392 frame->p8023.h_source[0], frame->p8023.h_source[1],
4393 frame->p8023.h_source[2], frame->p8023.h_source[3],
4394 frame->p8023.h_source[4], frame->p8023.h_source[5]);
4395 printk(KERN_DEBUG " len = 0x%04x\n", frame->p8023.h_proto);
4397 printk(KERN_DEBUG "IEEE 802.2 LLC/SNAP header:\n");
4398 printk(KERN_DEBUG " DSAP = 0x%02x\n", frame->p8022.dsap);
4399 printk(KERN_DEBUG " SSAP = 0x%02x\n", frame->p8022.ssap);
4400 printk(KERN_DEBUG " ctrl = 0x%02x\n", frame->p8022.ctrl);
4401 printk(KERN_DEBUG " OUI = %02x:%02x:%02x\n",
4402 frame->p8022.oui[0], frame->p8022.oui[1], frame->p8022.oui[2]);
4403 printk(KERN_DEBUG " ethertype = 0x%04x\n", frame->ethertype);
4407 /********************************************************************/
4408 /* Module initialization */
4409 /********************************************************************/
4411 EXPORT_SYMBOL(alloc_orinocodev);
4412 EXPORT_SYMBOL(free_orinocodev);
4414 EXPORT_SYMBOL(__orinoco_up);
4415 EXPORT_SYMBOL(__orinoco_down);
4416 EXPORT_SYMBOL(orinoco_reinit_firmware);
4418 EXPORT_SYMBOL(orinoco_interrupt);
4420 /* Can't be declared "const" or the whole __initdata section will
4422 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4423 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4424 "Pavel Roskin <proski@gnu.org>, et al)";
4426 static int __init init_orinoco(void)
4428 printk(KERN_DEBUG "%s\n", version);
4432 static void __exit exit_orinoco(void)
4436 module_init(init_orinoco);
4437 module_exit(exit_orinoco);