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/module.h>
80 #include <linux/kernel.h>
81 #include <linux/init.h>
82 #include <linux/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/ethtool.h>
85 #include <linux/if_arp.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 const 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 /* Beginning of the Tx descriptor, used in TxExc handling */
205 struct hermes_txexc_data {
206 struct hermes_tx_descriptor desc;
210 } __attribute__ ((packed));
212 /* Rx frame header except compatibility 802.3 header */
213 struct hermes_rx_descriptor {
234 } __attribute__ ((packed));
236 /********************************************************************/
237 /* Function prototypes */
238 /********************************************************************/
240 static int __orinoco_program_rids(struct net_device *dev);
241 static void __orinoco_set_multicast_list(struct net_device *dev);
243 /********************************************************************/
244 /* Internal helper functions */
245 /********************************************************************/
247 static inline void set_port_type(struct orinoco_private *priv)
249 switch (priv->iw_mode) {
252 priv->createibss = 0;
255 if (priv->prefer_port3) {
257 priv->createibss = 0;
259 priv->port_type = priv->ibss_port;
260 priv->createibss = 1;
263 case IW_MODE_MONITOR:
265 priv->createibss = 0;
268 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
273 #define ORINOCO_MAX_BSS_COUNT 64
274 static int orinoco_bss_data_allocate(struct orinoco_private *priv)
280 kzalloc(ORINOCO_MAX_BSS_COUNT * sizeof(bss_element), GFP_KERNEL);
281 if (!priv->bss_data) {
282 printk(KERN_WARNING "Out of memory allocating beacons");
288 static void orinoco_bss_data_free(struct orinoco_private *priv)
290 kfree(priv->bss_data);
291 priv->bss_data = NULL;
294 static void orinoco_bss_data_init(struct orinoco_private *priv)
298 INIT_LIST_HEAD(&priv->bss_free_list);
299 INIT_LIST_HEAD(&priv->bss_list);
300 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
301 list_add_tail(&priv->bss_data[i].list, &priv->bss_free_list);
304 /********************************************************************/
306 /********************************************************************/
308 static int orinoco_open(struct net_device *dev)
310 struct orinoco_private *priv = netdev_priv(dev);
314 if (orinoco_lock(priv, &flags) != 0)
317 err = __orinoco_up(dev);
322 orinoco_unlock(priv, &flags);
327 static int orinoco_stop(struct net_device *dev)
329 struct orinoco_private *priv = netdev_priv(dev);
332 /* We mustn't use orinoco_lock() here, because we need to be
333 able to close the interface even if hw_unavailable is set
334 (e.g. as we're released after a PC Card removal) */
335 spin_lock_irq(&priv->lock);
339 err = __orinoco_down(dev);
341 spin_unlock_irq(&priv->lock);
346 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
348 struct orinoco_private *priv = netdev_priv(dev);
353 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
355 struct orinoco_private *priv = netdev_priv(dev);
356 hermes_t *hw = &priv->hw;
357 struct iw_statistics *wstats = &priv->wstats;
361 if (! netif_device_present(dev)) {
362 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
364 return NULL; /* FIXME: Can we do better than this? */
367 /* If busy, return the old stats. Returning NULL may cause
368 * the interface to disappear from /proc/net/wireless */
369 if (orinoco_lock(priv, &flags) != 0)
372 /* We can't really wait for the tallies inquiry command to
373 * complete, so we just use the previous results and trigger
374 * a new tallies inquiry command for next time - Jean II */
375 /* FIXME: Really we should wait for the inquiry to come back -
376 * as it is the stats we give don't make a whole lot of sense.
377 * Unfortunately, it's not clear how to do that within the
378 * wireless extensions framework: I think we're in user
379 * context, but a lock seems to be held by the time we get in
380 * here so we're not safe to sleep here. */
381 hermes_inquire(hw, HERMES_INQ_TALLIES);
383 if (priv->iw_mode == IW_MODE_ADHOC) {
384 memset(&wstats->qual, 0, sizeof(wstats->qual));
385 /* If a spy address is defined, we report stats of the
386 * first spy address - Jean II */
387 if (SPY_NUMBER(priv)) {
388 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
389 wstats->qual.level = priv->spy_data.spy_stat[0].level;
390 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
391 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
395 __le16 qual, signal, noise, unused;
396 } __attribute__ ((packed)) cq;
398 err = HERMES_READ_RECORD(hw, USER_BAP,
399 HERMES_RID_COMMSQUALITY, &cq);
402 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
403 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
404 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
405 wstats->qual.updated = 7;
409 orinoco_unlock(priv, &flags);
413 static void orinoco_set_multicast_list(struct net_device *dev)
415 struct orinoco_private *priv = netdev_priv(dev);
418 if (orinoco_lock(priv, &flags) != 0) {
419 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
420 "called when hw_unavailable\n", dev->name);
424 __orinoco_set_multicast_list(dev);
425 orinoco_unlock(priv, &flags);
428 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
430 struct orinoco_private *priv = netdev_priv(dev);
432 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
435 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
436 (priv->nicbuf_size - ETH_HLEN) )
444 /********************************************************************/
446 /********************************************************************/
448 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
450 struct orinoco_private *priv = netdev_priv(dev);
451 struct net_device_stats *stats = &priv->stats;
452 hermes_t *hw = &priv->hw;
454 u16 txfid = priv->txfid;
457 struct hermes_tx_descriptor desc;
460 if (! netif_running(dev)) {
461 printk(KERN_ERR "%s: Tx on stopped device!\n",
463 return NETDEV_TX_BUSY;
466 if (netif_queue_stopped(dev)) {
467 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
469 return NETDEV_TX_BUSY;
472 if (orinoco_lock(priv, &flags) != 0) {
473 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
475 return NETDEV_TX_BUSY;
478 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
479 /* Oops, the firmware hasn't established a connection,
480 silently drop the packet (this seems to be the
485 /* Check packet length */
486 if (skb->len < ETH_HLEN)
489 eh = (struct ethhdr *)skb->data;
491 memset(&desc, 0, sizeof(desc));
492 desc.tx_control = cpu_to_le16(HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX);
493 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc), txfid, 0);
496 printk(KERN_ERR "%s: Error %d writing Tx descriptor "
497 "to BAP\n", dev->name, err);
501 /* Clear the 802.11 header and data length fields - some
502 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
503 * if this isn't done. */
504 hermes_clear_words(hw, HERMES_DATA0,
505 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
507 /* Encapsulate Ethernet-II frames */
508 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
509 struct header_struct {
510 struct ethhdr eth; /* 802.3 header */
511 u8 encap[6]; /* 802.2 header */
512 } __attribute__ ((packed)) hdr;
514 /* Strip destination and source from the data */
515 skb_pull(skb, 2 * ETH_ALEN);
516 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
518 /* And move them to a separate header */
519 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
520 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
521 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
523 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
524 txfid, HERMES_802_3_OFFSET);
527 printk(KERN_ERR "%s: Error %d writing packet "
528 "header to BAP\n", dev->name, err);
531 } else { /* IEEE 802.3 frame */
532 data_off = HERMES_802_3_OFFSET;
535 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
538 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
543 /* Finally, we actually initiate the send */
544 netif_stop_queue(dev);
546 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
549 netif_start_queue(dev);
551 printk(KERN_ERR "%s: Error %d transmitting packet\n",
556 dev->trans_start = jiffies;
557 stats->tx_bytes += data_off + skb->len;
565 orinoco_unlock(priv, &flags);
571 schedule_work(&priv->reset_work);
572 orinoco_unlock(priv, &flags);
573 return NETDEV_TX_BUSY;
576 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
578 struct orinoco_private *priv = netdev_priv(dev);
579 u16 fid = hermes_read_regn(hw, ALLOCFID);
581 if (fid != priv->txfid) {
582 if (fid != DUMMY_FID)
583 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
588 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
591 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
593 struct orinoco_private *priv = netdev_priv(dev);
594 struct net_device_stats *stats = &priv->stats;
598 netif_wake_queue(dev);
600 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
603 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
605 struct orinoco_private *priv = netdev_priv(dev);
606 struct net_device_stats *stats = &priv->stats;
607 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
609 struct hermes_txexc_data hdr;
612 if (fid == DUMMY_FID)
613 return; /* Nothing's really happened */
615 /* Read part of the frame header - we need status and addr1 */
616 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
617 sizeof(struct hermes_txexc_data),
620 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
624 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
625 "(FID=%04X error %d)\n",
626 dev->name, fid, err);
630 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
633 /* We produce a TXDROP event only for retry or lifetime
634 * exceeded, because that's the only status that really mean
635 * that this particular node went away.
636 * Other errors means that *we* screwed up. - Jean II */
637 status = le16_to_cpu(hdr.desc.status);
638 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
639 union iwreq_data wrqu;
641 /* Copy 802.11 dest address.
642 * We use the 802.11 header because the frame may
643 * not be 802.3 or may be mangled...
644 * In Ad-Hoc mode, it will be the node address.
645 * In managed mode, it will be most likely the AP addr
646 * User space will figure out how to convert it to
647 * whatever it needs (IP address or else).
649 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
650 wrqu.addr.sa_family = ARPHRD_ETHER;
652 /* Send event to user space */
653 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
656 netif_wake_queue(dev);
659 static void orinoco_tx_timeout(struct net_device *dev)
661 struct orinoco_private *priv = netdev_priv(dev);
662 struct net_device_stats *stats = &priv->stats;
663 struct hermes *hw = &priv->hw;
665 printk(KERN_WARNING "%s: Tx timeout! "
666 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
667 dev->name, hermes_read_regn(hw, ALLOCFID),
668 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
672 schedule_work(&priv->reset_work);
675 /********************************************************************/
676 /* Rx path (data frames) */
677 /********************************************************************/
679 /* Does the frame have a SNAP header indicating it should be
680 * de-encapsulated to Ethernet-II? */
681 static inline int is_ethersnap(void *_hdr)
685 /* We de-encapsulate all packets which, a) have SNAP headers
686 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
687 * and where b) the OUI of the SNAP header is 00:00:00 or
688 * 00:00:f8 - we need both because different APs appear to use
689 * different OUIs for some reason */
690 return (memcmp(hdr, &encaps_hdr, 5) == 0)
691 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
694 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
695 int level, int noise)
697 struct iw_quality wstats;
698 wstats.level = level - 0x95;
699 wstats.noise = noise - 0x95;
700 wstats.qual = (level > noise) ? (level - noise) : 0;
702 /* Update spy records */
703 wireless_spy_update(dev, mac, &wstats);
706 static void orinoco_stat_gather(struct net_device *dev,
708 struct hermes_rx_descriptor *desc)
710 struct orinoco_private *priv = netdev_priv(dev);
712 /* Using spy support with lots of Rx packets, like in an
713 * infrastructure (AP), will really slow down everything, because
714 * the MAC address must be compared to each entry of the spy list.
715 * If the user really asks for it (set some address in the
716 * spy list), we do it, but he will pay the price.
717 * Note that to get here, you need both WIRELESS_SPY
718 * compiled in AND some addresses in the list !!!
720 /* Note : gcc will optimise the whole section away if
721 * WIRELESS_SPY is not defined... - Jean II */
722 if (SPY_NUMBER(priv)) {
723 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
724 desc->signal, desc->silence);
729 * orinoco_rx_monitor - handle received monitor frames.
734 * desc rx descriptor of the frame
736 * Call context: interrupt
738 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
739 struct hermes_rx_descriptor *desc)
741 u32 hdrlen = 30; /* return full header by default */
747 struct orinoco_private *priv = netdev_priv(dev);
748 struct net_device_stats *stats = &priv->stats;
749 hermes_t *hw = &priv->hw;
751 len = le16_to_cpu(desc->data_len);
753 /* Determine the size of the header and the data */
754 fc = le16_to_cpu(desc->frame_ctl);
755 switch (fc & IEEE80211_FCTL_FTYPE) {
756 case IEEE80211_FTYPE_DATA:
757 if ((fc & IEEE80211_FCTL_TODS)
758 && (fc & IEEE80211_FCTL_FROMDS))
764 case IEEE80211_FTYPE_MGMT:
768 case IEEE80211_FTYPE_CTL:
769 switch (fc & IEEE80211_FCTL_STYPE) {
770 case IEEE80211_STYPE_PSPOLL:
771 case IEEE80211_STYPE_RTS:
772 case IEEE80211_STYPE_CFEND:
773 case IEEE80211_STYPE_CFENDACK:
776 case IEEE80211_STYPE_CTS:
777 case IEEE80211_STYPE_ACK:
783 /* Unknown frame type */
787 /* sanity check the length */
788 if (datalen > IEEE80211_DATA_LEN + 12) {
789 printk(KERN_DEBUG "%s: oversized monitor frame, "
790 "data length = %d\n", dev->name, datalen);
791 stats->rx_length_errors++;
795 skb = dev_alloc_skb(hdrlen + datalen);
797 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
802 /* Copy the 802.11 header to the skb */
803 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
804 skb_reset_mac_header(skb);
806 /* If any, copy the data from the card to the skb */
808 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
809 ALIGN(datalen, 2), rxfid,
810 HERMES_802_2_OFFSET);
812 printk(KERN_ERR "%s: error %d reading monitor frame\n",
819 skb->ip_summed = CHECKSUM_NONE;
820 skb->pkt_type = PACKET_OTHERHOST;
821 skb->protocol = __constant_htons(ETH_P_802_2);
823 dev->last_rx = jiffies;
825 stats->rx_bytes += skb->len;
831 dev_kfree_skb_irq(skb);
837 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
839 struct orinoco_private *priv = netdev_priv(dev);
840 struct net_device_stats *stats = &priv->stats;
841 struct iw_statistics *wstats = &priv->wstats;
842 struct sk_buff *skb = NULL;
843 u16 rxfid, status, fc;
845 struct hermes_rx_descriptor desc;
849 rxfid = hermes_read_regn(hw, RXFID);
851 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
854 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
855 "Frame dropped.\n", dev->name, err);
859 status = le16_to_cpu(desc.status);
861 if (status & HERMES_RXSTAT_BADCRC) {
862 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
864 stats->rx_crc_errors++;
868 /* Handle frames in monitor mode */
869 if (priv->iw_mode == IW_MODE_MONITOR) {
870 orinoco_rx_monitor(dev, rxfid, &desc);
874 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
875 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
877 wstats->discard.code++;
881 length = le16_to_cpu(desc.data_len);
882 fc = le16_to_cpu(desc.frame_ctl);
885 if (length < 3) { /* No for even an 802.2 LLC header */
886 /* At least on Symbol firmware with PCF we get quite a
887 lot of these legitimately - Poll frames with no
891 if (length > IEEE80211_DATA_LEN) {
892 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
894 stats->rx_length_errors++;
898 /* We need space for the packet data itself, plus an ethernet
899 header, plus 2 bytes so we can align the IP header on a
900 32bit boundary, plus 1 byte so we can read in odd length
901 packets from the card, which has an IO granularity of 16
903 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
905 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
910 /* We'll prepend the header, so reserve space for it. The worst
911 case is no decapsulation, when 802.3 header is prepended and
912 nothing is removed. 2 is for aligning the IP header. */
913 skb_reserve(skb, ETH_HLEN + 2);
915 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
916 ALIGN(length, 2), rxfid,
917 HERMES_802_2_OFFSET);
919 printk(KERN_ERR "%s: error %d reading frame. "
920 "Frame dropped.\n", dev->name, err);
924 /* Handle decapsulation
925 * In most cases, the firmware tell us about SNAP frames.
926 * For some reason, the SNAP frames sent by LinkSys APs
927 * are not properly recognised by most firmwares.
928 * So, check ourselves */
929 if (length >= ENCAPS_OVERHEAD &&
930 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
931 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
932 is_ethersnap(skb->data))) {
933 /* These indicate a SNAP within 802.2 LLC within
934 802.11 frame which we'll need to de-encapsulate to
935 the original EthernetII frame. */
936 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
938 /* 802.3 frame - prepend 802.3 header as is */
939 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
940 hdr->h_proto = htons(length);
942 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
943 if (fc & IEEE80211_FCTL_FROMDS)
944 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
946 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
948 dev->last_rx = jiffies;
949 skb->protocol = eth_type_trans(skb, dev);
950 skb->ip_summed = CHECKSUM_NONE;
951 if (fc & IEEE80211_FCTL_TODS)
952 skb->pkt_type = PACKET_OTHERHOST;
954 /* Process the wireless stats if needed */
955 orinoco_stat_gather(dev, skb, &desc);
957 /* Pass the packet to the networking stack */
960 stats->rx_bytes += length;
965 dev_kfree_skb_irq(skb);
971 /********************************************************************/
972 /* Rx path (info frames) */
973 /********************************************************************/
975 static void print_linkstatus(struct net_device *dev, u16 status)
979 if (suppress_linkstatus)
983 case HERMES_LINKSTATUS_NOT_CONNECTED:
986 case HERMES_LINKSTATUS_CONNECTED:
989 case HERMES_LINKSTATUS_DISCONNECTED:
992 case HERMES_LINKSTATUS_AP_CHANGE:
995 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
996 s = "AP Out of Range";
998 case HERMES_LINKSTATUS_AP_IN_RANGE:
1001 case HERMES_LINKSTATUS_ASSOC_FAILED:
1002 s = "Association Failed";
1008 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1009 dev->name, s, status);
1012 /* Search scan results for requested BSSID, join it if found */
1013 static void orinoco_join_ap(struct work_struct *work)
1015 struct orinoco_private *priv =
1016 container_of(work, struct orinoco_private, join_work);
1017 struct net_device *dev = priv->ndev;
1018 struct hermes *hw = &priv->hw;
1020 unsigned long flags;
1024 } __attribute__ ((packed)) req;
1025 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1026 struct prism2_scan_apinfo *atom = NULL;
1032 /* Allocate buffer for scan results */
1033 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1037 if (orinoco_lock(priv, &flags) != 0)
1040 /* Sanity checks in case user changed something in the meantime */
1041 if (! priv->bssid_fixed)
1044 if (strlen(priv->desired_essid) == 0)
1047 /* Read scan results from the firmware */
1048 err = hermes_read_ltv(hw, USER_BAP,
1049 HERMES_RID_SCANRESULTSTABLE,
1050 MAX_SCAN_LEN, &len, buf);
1052 printk(KERN_ERR "%s: Cannot read scan results\n",
1057 len = HERMES_RECLEN_TO_BYTES(len);
1059 /* Go through the scan results looking for the channel of the AP
1060 * we were requested to join */
1061 for (; offset + atom_len <= len; offset += atom_len) {
1062 atom = (struct prism2_scan_apinfo *) (buf + offset);
1063 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1070 DEBUG(1, "%s: Requested AP not found in scan results\n",
1075 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1076 req.channel = atom->channel; /* both are little-endian */
1077 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1080 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1083 orinoco_unlock(priv, &flags);
1089 /* Send new BSSID to userspace */
1090 static void orinoco_send_wevents(struct work_struct *work)
1092 struct orinoco_private *priv =
1093 container_of(work, struct orinoco_private, wevent_work);
1094 struct net_device *dev = priv->ndev;
1095 struct hermes *hw = &priv->hw;
1096 union iwreq_data wrqu;
1098 unsigned long flags;
1100 if (orinoco_lock(priv, &flags) != 0)
1103 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1104 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1108 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1110 /* Send event to user space */
1111 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1114 orinoco_unlock(priv, &flags);
1118 static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1119 unsigned long scan_age)
1122 bss_element *tmp_bss;
1124 /* Blow away current list of scan results */
1125 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1127 time_after(jiffies, bss->last_scanned + scan_age)) {
1128 list_move_tail(&bss->list, &priv->bss_free_list);
1129 /* Don't blow away ->list, just BSS data */
1130 memset(bss, 0, sizeof(bss->bss));
1131 bss->last_scanned = 0;
1136 static int orinoco_process_scan_results(struct net_device *dev,
1140 struct orinoco_private *priv = netdev_priv(dev);
1141 int offset; /* In the scan data */
1142 union hermes_scan_info *atom;
1145 switch (priv->firmware_type) {
1146 case FIRMWARE_TYPE_AGERE:
1147 atom_len = sizeof(struct agere_scan_apinfo);
1150 case FIRMWARE_TYPE_SYMBOL:
1151 /* Lack of documentation necessitates this hack.
1152 * Different firmwares have 68 or 76 byte long atoms.
1153 * We try modulo first. If the length divides by both,
1154 * we check what would be the channel in the second
1155 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1156 * Valid channel cannot be 0. */
1161 else if (len >= 1292 && buf[68] == 0)
1167 case FIRMWARE_TYPE_INTERSIL:
1169 if (priv->has_hostscan) {
1170 atom_len = le16_to_cpup((__le16 *)buf);
1171 /* Sanity check for atom_len */
1172 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1173 printk(KERN_ERR "%s: Invalid atom_len in scan "
1174 "data: %d\n", dev->name, atom_len);
1178 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1184 /* Check that we got an whole number of atoms */
1185 if ((len - offset) % atom_len) {
1186 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1187 "atom_len %d, offset %d\n", dev->name, len,
1192 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1194 /* Read the entries one by one */
1195 for (; offset + atom_len <= len; offset += atom_len) {
1197 bss_element *bss = NULL;
1200 atom = (union hermes_scan_info *) (buf + offset);
1202 /* Try to update an existing bss first */
1203 list_for_each_entry(bss, &priv->bss_list, list) {
1204 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1206 if (le16_to_cpu(bss->bss.a.essid_len) !=
1207 le16_to_cpu(atom->a.essid_len))
1209 if (memcmp(bss->bss.a.essid, atom->a.essid,
1210 le16_to_cpu(atom->a.essid_len)))
1216 /* Grab a bss off the free list */
1217 if (!found && !list_empty(&priv->bss_free_list)) {
1218 bss = list_entry(priv->bss_free_list.next,
1220 list_del(priv->bss_free_list.next);
1222 list_add_tail(&bss->list, &priv->bss_list);
1226 /* Always update the BSS to get latest beacon info */
1227 memcpy(&bss->bss, atom, sizeof(bss->bss));
1228 bss->last_scanned = jiffies;
1235 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1237 struct orinoco_private *priv = netdev_priv(dev);
1242 } __attribute__ ((packed)) info;
1246 /* This is an answer to an INQUIRE command that we did earlier,
1247 * or an information "event" generated by the card
1248 * The controller return to us a pseudo frame containing
1249 * the information in question - Jean II */
1250 infofid = hermes_read_regn(hw, INFOFID);
1252 /* Read the info frame header - don't try too hard */
1253 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1256 printk(KERN_ERR "%s: error %d reading info frame. "
1257 "Frame dropped.\n", dev->name, err);
1261 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1262 type = le16_to_cpu(info.type);
1265 case HERMES_INQ_TALLIES: {
1266 struct hermes_tallies_frame tallies;
1267 struct iw_statistics *wstats = &priv->wstats;
1269 if (len > sizeof(tallies)) {
1270 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1272 len = sizeof(tallies);
1275 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1276 infofid, sizeof(info));
1280 /* Increment our various counters */
1281 /* wstats->discard.nwid - no wrong BSSID stuff */
1282 wstats->discard.code +=
1283 le16_to_cpu(tallies.RxWEPUndecryptable);
1284 if (len == sizeof(tallies))
1285 wstats->discard.code +=
1286 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1287 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1288 wstats->discard.misc +=
1289 le16_to_cpu(tallies.TxDiscardsWrongSA);
1290 wstats->discard.fragment +=
1291 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1292 wstats->discard.retries +=
1293 le16_to_cpu(tallies.TxRetryLimitExceeded);
1294 /* wstats->miss.beacon - no match */
1297 case HERMES_INQ_LINKSTATUS: {
1298 struct hermes_linkstatus linkstatus;
1302 if (priv->iw_mode == IW_MODE_MONITOR)
1305 if (len != sizeof(linkstatus)) {
1306 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1311 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1312 infofid, sizeof(info));
1315 newstatus = le16_to_cpu(linkstatus.linkstatus);
1317 /* Symbol firmware uses "out of range" to signal that
1318 * the hostscan frame can be requested. */
1319 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1320 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1321 priv->has_hostscan && priv->scan_inprogress) {
1322 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1326 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1327 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1328 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1331 netif_carrier_on(dev);
1332 else if (!ignore_disconnect)
1333 netif_carrier_off(dev);
1335 if (newstatus != priv->last_linkstatus) {
1336 priv->last_linkstatus = newstatus;
1337 print_linkstatus(dev, newstatus);
1338 /* The info frame contains only one word which is the
1339 * status (see hermes.h). The status is pretty boring
1340 * in itself, that's why we export the new BSSID...
1342 schedule_work(&priv->wevent_work);
1346 case HERMES_INQ_SCAN:
1347 if (!priv->scan_inprogress && priv->bssid_fixed &&
1348 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1349 schedule_work(&priv->join_work);
1353 case HERMES_INQ_HOSTSCAN:
1354 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1355 /* Result of a scanning. Contains information about
1356 * cells in the vicinity - Jean II */
1357 union iwreq_data wrqu;
1360 /* Scan is no longer in progress */
1361 priv->scan_inprogress = 0;
1365 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1370 /* Allocate buffer for results */
1371 buf = kmalloc(len, GFP_ATOMIC);
1373 /* No memory, so can't printk()... */
1376 /* Read scan data */
1377 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1378 infofid, sizeof(info));
1384 #ifdef ORINOCO_DEBUG
1387 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1388 for(i = 1; i < (len * 2); i++)
1389 printk(":%02X", buf[i]);
1392 #endif /* ORINOCO_DEBUG */
1394 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1395 /* Send an empty event to user space.
1396 * We don't send the received data on the event because
1397 * it would require us to do complex transcoding, and
1398 * we want to minimise the work done in the irq handler
1399 * Use a request to extract the data - Jean II */
1400 wrqu.data.length = 0;
1401 wrqu.data.flags = 0;
1402 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1407 case HERMES_INQ_SEC_STAT_AGERE:
1408 /* Security status (Agere specific) */
1409 /* Ignore this frame for now */
1410 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1414 printk(KERN_DEBUG "%s: Unknown information frame received: "
1415 "type 0x%04x, length %d\n", dev->name, type, len);
1416 /* We don't actually do anything about it */
1421 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1423 if (net_ratelimit())
1424 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1427 /********************************************************************/
1428 /* Internal hardware control routines */
1429 /********************************************************************/
1431 int __orinoco_up(struct net_device *dev)
1433 struct orinoco_private *priv = netdev_priv(dev);
1434 struct hermes *hw = &priv->hw;
1437 netif_carrier_off(dev); /* just to make sure */
1439 err = __orinoco_program_rids(dev);
1441 printk(KERN_ERR "%s: Error %d configuring card\n",
1446 /* Fire things up again */
1447 hermes_set_irqmask(hw, ORINOCO_INTEN);
1448 err = hermes_enable_port(hw, 0);
1450 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1455 netif_start_queue(dev);
1460 int __orinoco_down(struct net_device *dev)
1462 struct orinoco_private *priv = netdev_priv(dev);
1463 struct hermes *hw = &priv->hw;
1466 netif_stop_queue(dev);
1468 if (! priv->hw_unavailable) {
1469 if (! priv->broken_disableport) {
1470 err = hermes_disable_port(hw, 0);
1472 /* Some firmwares (e.g. Intersil 1.3.x) seem
1473 * to have problems disabling the port, oh
1475 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1477 priv->broken_disableport = 1;
1480 hermes_set_irqmask(hw, 0);
1481 hermes_write_regn(hw, EVACK, 0xffff);
1484 /* firmware will have to reassociate */
1485 netif_carrier_off(dev);
1486 priv->last_linkstatus = 0xffff;
1491 static int orinoco_allocate_fid(struct net_device *dev)
1493 struct orinoco_private *priv = netdev_priv(dev);
1494 struct hermes *hw = &priv->hw;
1497 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1498 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1499 /* Try workaround for old Symbol firmware bug */
1500 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1501 "(old Symbol firmware?). Trying to work around... ",
1504 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1505 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1507 printk("failed!\n");
1515 int orinoco_reinit_firmware(struct net_device *dev)
1517 struct orinoco_private *priv = netdev_priv(dev);
1518 struct hermes *hw = &priv->hw;
1521 err = hermes_init(hw);
1523 err = orinoco_allocate_fid(dev);
1528 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1530 hermes_t *hw = &priv->hw;
1533 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1534 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1535 priv->ndev->name, priv->bitratemode);
1539 switch (priv->firmware_type) {
1540 case FIRMWARE_TYPE_AGERE:
1541 err = hermes_write_wordrec(hw, USER_BAP,
1542 HERMES_RID_CNFTXRATECONTROL,
1543 bitrate_table[priv->bitratemode].agere_txratectrl);
1545 case FIRMWARE_TYPE_INTERSIL:
1546 case FIRMWARE_TYPE_SYMBOL:
1547 err = hermes_write_wordrec(hw, USER_BAP,
1548 HERMES_RID_CNFTXRATECONTROL,
1549 bitrate_table[priv->bitratemode].intersil_txratectrl);
1558 /* Set fixed AP address */
1559 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1563 hermes_t *hw = &priv->hw;
1565 switch (priv->firmware_type) {
1566 case FIRMWARE_TYPE_AGERE:
1569 case FIRMWARE_TYPE_INTERSIL:
1570 if (priv->bssid_fixed)
1575 err = hermes_write_wordrec(hw, USER_BAP,
1576 HERMES_RID_CNFROAMINGMODE,
1579 case FIRMWARE_TYPE_SYMBOL:
1580 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1581 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1582 &priv->desired_bssid);
1588 /* Change the WEP keys and/or the current keys. Can be called
1589 * either from __orinoco_hw_setup_wep() or directly from
1590 * orinoco_ioctl_setiwencode(). In the later case the association
1591 * with the AP is not broken (if the firmware can handle it),
1592 * which is needed for 802.1x implementations. */
1593 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1595 hermes_t *hw = &priv->hw;
1598 switch (priv->firmware_type) {
1599 case FIRMWARE_TYPE_AGERE:
1600 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1601 HERMES_RID_CNFWEPKEYS_AGERE,
1605 err = hermes_write_wordrec(hw, USER_BAP,
1606 HERMES_RID_CNFTXKEY_AGERE,
1611 case FIRMWARE_TYPE_INTERSIL:
1612 case FIRMWARE_TYPE_SYMBOL:
1617 /* Force uniform key length to work around firmware bugs */
1618 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1620 if (keylen > LARGE_KEY_SIZE) {
1621 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1622 priv->ndev->name, priv->tx_key, keylen);
1626 /* Write all 4 keys */
1627 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1628 err = hermes_write_ltv(hw, USER_BAP,
1629 HERMES_RID_CNFDEFAULTKEY0 + i,
1630 HERMES_BYTES_TO_RECLEN(keylen),
1631 priv->keys[i].data);
1636 /* Write the index of the key used in transmission */
1637 err = hermes_write_wordrec(hw, USER_BAP,
1638 HERMES_RID_CNFWEPDEFAULTKEYID,
1649 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1651 hermes_t *hw = &priv->hw;
1653 int master_wep_flag;
1657 __orinoco_hw_setup_wepkeys(priv);
1659 if (priv->wep_restrict)
1660 auth_flag = HERMES_AUTH_SHARED_KEY;
1662 auth_flag = HERMES_AUTH_OPEN;
1664 switch (priv->firmware_type) {
1665 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1667 /* Enable the shared-key authentication. */
1668 err = hermes_write_wordrec(hw, USER_BAP,
1669 HERMES_RID_CNFAUTHENTICATION_AGERE,
1672 err = hermes_write_wordrec(hw, USER_BAP,
1673 HERMES_RID_CNFWEPENABLED_AGERE,
1679 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1680 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1682 if (priv->wep_restrict ||
1683 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1684 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1685 HERMES_WEP_EXCL_UNENCRYPTED;
1687 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1689 err = hermes_write_wordrec(hw, USER_BAP,
1690 HERMES_RID_CNFAUTHENTICATION,
1695 master_wep_flag = 0;
1697 if (priv->iw_mode == IW_MODE_MONITOR)
1698 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1700 /* Master WEP setting : on/off */
1701 err = hermes_write_wordrec(hw, USER_BAP,
1702 HERMES_RID_CNFWEPFLAGS_INTERSIL,
1713 static int __orinoco_program_rids(struct net_device *dev)
1715 struct orinoco_private *priv = netdev_priv(dev);
1716 hermes_t *hw = &priv->hw;
1718 struct hermes_idstring idbuf;
1720 /* Set the MAC address */
1721 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1722 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1724 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1729 /* Set up the link mode */
1730 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1733 printk(KERN_ERR "%s: Error %d setting port type\n",
1737 /* Set the channel/frequency */
1738 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1739 err = hermes_write_wordrec(hw, USER_BAP,
1740 HERMES_RID_CNFOWNCHANNEL,
1743 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1744 dev->name, err, priv->channel);
1749 if (priv->has_ibss) {
1752 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1753 printk(KERN_WARNING "%s: This firmware requires an "
1754 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1755 /* With wvlan_cs, in this case, we would crash.
1756 * hopefully, this driver will behave better...
1760 createibss = priv->createibss;
1763 err = hermes_write_wordrec(hw, USER_BAP,
1764 HERMES_RID_CNFCREATEIBSS,
1767 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1773 /* Set the desired BSSID */
1774 err = __orinoco_hw_set_wap(priv);
1776 printk(KERN_ERR "%s: Error %d setting AP address\n",
1780 /* Set the desired ESSID */
1781 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1782 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1783 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1784 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1785 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1788 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1792 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1793 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1796 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1801 /* Set the station name */
1802 idbuf.len = cpu_to_le16(strlen(priv->nick));
1803 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1804 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1805 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1808 printk(KERN_ERR "%s: Error %d setting nickname\n",
1813 /* Set AP density */
1814 if (priv->has_sensitivity) {
1815 err = hermes_write_wordrec(hw, USER_BAP,
1816 HERMES_RID_CNFSYSTEMSCALE,
1819 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1820 "Disabling sensitivity control\n",
1823 priv->has_sensitivity = 0;
1827 /* Set RTS threshold */
1828 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1831 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1836 /* Set fragmentation threshold or MWO robustness */
1838 err = hermes_write_wordrec(hw, USER_BAP,
1839 HERMES_RID_CNFMWOROBUST_AGERE,
1842 err = hermes_write_wordrec(hw, USER_BAP,
1843 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1846 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1852 err = __orinoco_hw_set_bitrate(priv);
1854 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1859 /* Set power management */
1861 err = hermes_write_wordrec(hw, USER_BAP,
1862 HERMES_RID_CNFPMENABLED,
1865 printk(KERN_ERR "%s: Error %d setting up PM\n",
1870 err = hermes_write_wordrec(hw, USER_BAP,
1871 HERMES_RID_CNFMULTICASTRECEIVE,
1874 printk(KERN_ERR "%s: Error %d setting up PM\n",
1878 err = hermes_write_wordrec(hw, USER_BAP,
1879 HERMES_RID_CNFMAXSLEEPDURATION,
1882 printk(KERN_ERR "%s: Error %d setting up PM\n",
1886 err = hermes_write_wordrec(hw, USER_BAP,
1887 HERMES_RID_CNFPMHOLDOVERDURATION,
1890 printk(KERN_ERR "%s: Error %d setting up PM\n",
1896 /* Set preamble - only for Symbol so far... */
1897 if (priv->has_preamble) {
1898 err = hermes_write_wordrec(hw, USER_BAP,
1899 HERMES_RID_CNFPREAMBLE_SYMBOL,
1902 printk(KERN_ERR "%s: Error %d setting preamble\n",
1908 /* Set up encryption */
1909 if (priv->has_wep) {
1910 err = __orinoco_hw_setup_wep(priv);
1912 printk(KERN_ERR "%s: Error %d activating WEP\n",
1918 if (priv->iw_mode == IW_MODE_MONITOR) {
1919 /* Enable monitor mode */
1920 dev->type = ARPHRD_IEEE80211;
1921 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1922 HERMES_TEST_MONITOR, 0, NULL);
1924 /* Disable monitor mode */
1925 dev->type = ARPHRD_ETHER;
1926 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1927 HERMES_TEST_STOP, 0, NULL);
1932 /* Set promiscuity / multicast*/
1933 priv->promiscuous = 0;
1936 /* FIXME: what about netif_tx_lock */
1937 __orinoco_set_multicast_list(dev);
1942 /* FIXME: return int? */
1944 __orinoco_set_multicast_list(struct net_device *dev)
1946 struct orinoco_private *priv = netdev_priv(dev);
1947 hermes_t *hw = &priv->hw;
1949 int promisc, mc_count;
1951 /* The Hermes doesn't seem to have an allmulti mode, so we go
1952 * into promiscuous mode and let the upper levels deal. */
1953 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1954 (dev->mc_count > MAX_MULTICAST(priv)) ) {
1959 mc_count = dev->mc_count;
1962 if (promisc != priv->promiscuous) {
1963 err = hermes_write_wordrec(hw, USER_BAP,
1964 HERMES_RID_CNFPROMISCUOUSMODE,
1967 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1970 priv->promiscuous = promisc;
1973 /* If we're not in promiscuous mode, then we need to set the
1974 * group address if either we want to multicast, or if we were
1975 * multicasting and want to stop */
1976 if (! promisc && (mc_count || priv->mc_count) ) {
1977 struct dev_mc_list *p = dev->mc_list;
1978 struct hermes_multicast mclist;
1981 for (i = 0; i < mc_count; i++) {
1982 /* paranoia: is list shorter than mc_count? */
1984 /* paranoia: bad address size in list? */
1985 BUG_ON(p->dmi_addrlen != ETH_ALEN);
1987 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
1992 printk(KERN_WARNING "%s: Multicast list is "
1993 "longer than mc_count\n", dev->name);
1995 err = hermes_write_ltv(hw, USER_BAP,
1996 HERMES_RID_CNFGROUPADDRESSES,
1997 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2000 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2003 priv->mc_count = mc_count;
2007 /* This must be called from user context, without locks held - use
2008 * schedule_work() */
2009 static void orinoco_reset(struct work_struct *work)
2011 struct orinoco_private *priv =
2012 container_of(work, struct orinoco_private, reset_work);
2013 struct net_device *dev = priv->ndev;
2014 struct hermes *hw = &priv->hw;
2016 unsigned long flags;
2018 if (orinoco_lock(priv, &flags) != 0)
2019 /* When the hardware becomes available again, whatever
2020 * detects that is responsible for re-initializing
2021 * it. So no need for anything further */
2024 netif_stop_queue(dev);
2026 /* Shut off interrupts. Depending on what state the hardware
2027 * is in, this might not work, but we'll try anyway */
2028 hermes_set_irqmask(hw, 0);
2029 hermes_write_regn(hw, EVACK, 0xffff);
2031 priv->hw_unavailable++;
2032 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2033 netif_carrier_off(dev);
2035 orinoco_unlock(priv, &flags);
2037 /* Scanning support: Cleanup of driver struct */
2038 orinoco_clear_scan_results(priv, 0);
2039 priv->scan_inprogress = 0;
2041 if (priv->hard_reset) {
2042 err = (*priv->hard_reset)(priv);
2044 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2045 "performing hard reset\n", dev->name, err);
2050 err = orinoco_reinit_firmware(dev);
2052 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2057 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2059 priv->hw_unavailable--;
2061 /* priv->open or priv->hw_unavailable might have changed while
2062 * we dropped the lock */
2063 if (priv->open && (! priv->hw_unavailable)) {
2064 err = __orinoco_up(dev);
2066 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2069 dev->trans_start = jiffies;
2072 spin_unlock_irq(&priv->lock);
2076 hermes_set_irqmask(hw, 0);
2077 netif_device_detach(dev);
2078 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2081 /********************************************************************/
2082 /* Interrupt handler */
2083 /********************************************************************/
2085 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2087 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2090 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2092 /* This seems to happen a fair bit under load, but ignoring it
2093 seems to work fine...*/
2094 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2098 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2100 struct net_device *dev = dev_id;
2101 struct orinoco_private *priv = netdev_priv(dev);
2102 hermes_t *hw = &priv->hw;
2103 int count = MAX_IRQLOOPS_PER_IRQ;
2105 /* These are used to detect a runaway interrupt situation */
2106 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2107 * we panic and shut down the hardware */
2108 static int last_irq_jiffy = 0; /* jiffies value the last time
2110 static int loops_this_jiffy = 0;
2111 unsigned long flags;
2113 if (orinoco_lock(priv, &flags) != 0) {
2114 /* If hw is unavailable - we don't know if the irq was
2119 evstat = hermes_read_regn(hw, EVSTAT);
2120 events = evstat & hw->inten;
2122 orinoco_unlock(priv, &flags);
2126 if (jiffies != last_irq_jiffy)
2127 loops_this_jiffy = 0;
2128 last_irq_jiffy = jiffies;
2130 while (events && count--) {
2131 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2132 printk(KERN_WARNING "%s: IRQ handler is looping too "
2133 "much! Resetting.\n", dev->name);
2134 /* Disable interrupts for now */
2135 hermes_set_irqmask(hw, 0);
2136 schedule_work(&priv->reset_work);
2140 /* Check the card hasn't been removed */
2141 if (! hermes_present(hw)) {
2142 DEBUG(0, "orinoco_interrupt(): card removed\n");
2146 if (events & HERMES_EV_TICK)
2147 __orinoco_ev_tick(dev, hw);
2148 if (events & HERMES_EV_WTERR)
2149 __orinoco_ev_wterr(dev, hw);
2150 if (events & HERMES_EV_INFDROP)
2151 __orinoco_ev_infdrop(dev, hw);
2152 if (events & HERMES_EV_INFO)
2153 __orinoco_ev_info(dev, hw);
2154 if (events & HERMES_EV_RX)
2155 __orinoco_ev_rx(dev, hw);
2156 if (events & HERMES_EV_TXEXC)
2157 __orinoco_ev_txexc(dev, hw);
2158 if (events & HERMES_EV_TX)
2159 __orinoco_ev_tx(dev, hw);
2160 if (events & HERMES_EV_ALLOC)
2161 __orinoco_ev_alloc(dev, hw);
2163 hermes_write_regn(hw, EVACK, evstat);
2165 evstat = hermes_read_regn(hw, EVSTAT);
2166 events = evstat & hw->inten;
2169 orinoco_unlock(priv, &flags);
2173 /********************************************************************/
2174 /* Initialization */
2175 /********************************************************************/
2178 u16 id, variant, major, minor;
2179 } __attribute__ ((packed));
2181 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2183 if (nic_id->id < 0x8000)
2184 return FIRMWARE_TYPE_AGERE;
2185 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2186 return FIRMWARE_TYPE_SYMBOL;
2188 return FIRMWARE_TYPE_INTERSIL;
2191 /* Set priv->firmware type, determine firmware properties */
2192 static int determine_firmware(struct net_device *dev)
2194 struct orinoco_private *priv = netdev_priv(dev);
2195 hermes_t *hw = &priv->hw;
2197 struct comp_id nic_id, sta_id;
2198 unsigned int firmver;
2199 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2201 /* Get the hardware version */
2202 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2204 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2209 le16_to_cpus(&nic_id.id);
2210 le16_to_cpus(&nic_id.variant);
2211 le16_to_cpus(&nic_id.major);
2212 le16_to_cpus(&nic_id.minor);
2213 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2214 dev->name, nic_id.id, nic_id.variant,
2215 nic_id.major, nic_id.minor);
2217 priv->firmware_type = determine_firmware_type(&nic_id);
2219 /* Get the firmware version */
2220 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2222 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2227 le16_to_cpus(&sta_id.id);
2228 le16_to_cpus(&sta_id.variant);
2229 le16_to_cpus(&sta_id.major);
2230 le16_to_cpus(&sta_id.minor);
2231 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2232 dev->name, sta_id.id, sta_id.variant,
2233 sta_id.major, sta_id.minor);
2235 switch (sta_id.id) {
2237 printk(KERN_ERR "%s: Primary firmware is active\n",
2241 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2244 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2245 case 0x21: /* Symbol Spectrum24 Trilogy */
2248 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2253 /* Default capabilities */
2254 priv->has_sensitivity = 1;
2256 priv->has_preamble = 0;
2257 priv->has_port3 = 1;
2260 priv->has_big_wep = 0;
2262 /* Determine capabilities from the firmware version */
2263 switch (priv->firmware_type) {
2264 case FIRMWARE_TYPE_AGERE:
2265 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2266 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2267 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2268 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2270 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2272 priv->has_ibss = (firmver >= 0x60006);
2273 priv->has_wep = (firmver >= 0x40020);
2274 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2275 Gold cards from the others? */
2276 priv->has_mwo = (firmver >= 0x60000);
2277 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2278 priv->ibss_port = 1;
2279 priv->has_hostscan = (firmver >= 0x8000a);
2280 priv->broken_monitor = (firmver >= 0x80000);
2282 /* Tested with Agere firmware :
2283 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2284 * Tested CableTron firmware : 4.32 => Anton */
2286 case FIRMWARE_TYPE_SYMBOL:
2287 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2288 /* Intel MAC : 00:02:B3:* */
2289 /* 3Com MAC : 00:50:DA:* */
2290 memset(tmp, 0, sizeof(tmp));
2291 /* Get the Symbol firmware version */
2292 err = hermes_read_ltv(hw, USER_BAP,
2293 HERMES_RID_SECONDARYVERSION_SYMBOL,
2294 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2297 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2302 /* The firmware revision is a string, the format is
2303 * something like : "V2.20-01".
2304 * Quick and dirty parsing... - Jean II
2306 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2307 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2310 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2313 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2316 priv->has_ibss = (firmver >= 0x20000);
2317 priv->has_wep = (firmver >= 0x15012);
2318 priv->has_big_wep = (firmver >= 0x20000);
2319 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2320 (firmver >= 0x29000 && firmver < 0x30000) ||
2322 priv->has_preamble = (firmver >= 0x20000);
2323 priv->ibss_port = 4;
2324 priv->broken_disableport = (firmver == 0x25013) ||
2325 (firmver >= 0x30000 && firmver <= 0x31000);
2326 priv->has_hostscan = (firmver >= 0x31001) ||
2327 (firmver >= 0x29057 && firmver < 0x30000);
2328 /* Tested with Intel firmware : 0x20015 => Jean II */
2329 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2331 case FIRMWARE_TYPE_INTERSIL:
2332 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2333 * Samsung, Compaq 100/200 and Proxim are slightly
2334 * different and less well tested */
2335 /* D-Link MAC : 00:40:05:* */
2336 /* Addtron MAC : 00:90:D1:* */
2337 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2338 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2341 firmver = ((unsigned long)sta_id.major << 16) |
2342 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2344 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2345 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2346 priv->has_pm = (firmver >= 0x000700);
2347 priv->has_hostscan = (firmver >= 0x010301);
2349 if (firmver >= 0x000800)
2350 priv->ibss_port = 0;
2352 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2353 "than v0.8.x - several features not supported\n",
2355 priv->ibss_port = 1;
2359 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2365 static int orinoco_init(struct net_device *dev)
2367 struct orinoco_private *priv = netdev_priv(dev);
2368 hermes_t *hw = &priv->hw;
2370 struct hermes_idstring nickbuf;
2373 DECLARE_MAC_BUF(mac);
2375 /* No need to lock, the hw_unavailable flag is already set in
2376 * alloc_orinocodev() */
2377 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2379 /* Initialize the firmware */
2380 err = hermes_init(hw);
2382 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2387 err = determine_firmware(dev);
2389 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2394 if (priv->has_port3)
2395 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2397 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2399 if (priv->has_wep) {
2400 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2401 if (priv->has_big_wep)
2402 printk("104-bit key\n");
2404 printk("40-bit key\n");
2407 /* Get the MAC address */
2408 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2409 ETH_ALEN, NULL, dev->dev_addr);
2411 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2416 printk(KERN_DEBUG "%s: MAC address %s\n",
2417 dev->name, print_mac(mac, dev->dev_addr));
2419 /* Get the station name */
2420 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2421 sizeof(nickbuf), &reclen, &nickbuf);
2423 printk(KERN_ERR "%s: failed to read station name\n",
2428 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2430 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2431 memcpy(priv->nick, &nickbuf.val, len);
2432 priv->nick[len] = '\0';
2434 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2436 err = orinoco_allocate_fid(dev);
2438 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2443 /* Get allowed channels */
2444 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2445 &priv->channel_mask);
2447 printk(KERN_ERR "%s: failed to read channel list!\n",
2452 /* Get initial AP density */
2453 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2455 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2456 priv->has_sensitivity = 0;
2459 /* Get initial RTS threshold */
2460 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2463 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2468 /* Get initial fragmentation settings */
2470 err = hermes_read_wordrec(hw, USER_BAP,
2471 HERMES_RID_CNFMWOROBUST_AGERE,
2474 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2475 &priv->frag_thresh);
2477 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2482 /* Power management setup */
2486 err = hermes_read_wordrec(hw, USER_BAP,
2487 HERMES_RID_CNFMAXSLEEPDURATION,
2490 printk(KERN_ERR "%s: failed to read power management period!\n",
2494 err = hermes_read_wordrec(hw, USER_BAP,
2495 HERMES_RID_CNFPMHOLDOVERDURATION,
2498 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2504 /* Preamble setup */
2505 if (priv->has_preamble) {
2506 err = hermes_read_wordrec(hw, USER_BAP,
2507 HERMES_RID_CNFPREAMBLE_SYMBOL,
2513 /* Set up the default configuration */
2514 priv->iw_mode = IW_MODE_INFRA;
2515 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2516 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2517 set_port_type(priv);
2518 priv->channel = 0; /* use firmware default */
2520 priv->promiscuous = 0;
2524 /* Make the hardware available, as long as it hasn't been
2525 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2526 spin_lock_irq(&priv->lock);
2527 priv->hw_unavailable--;
2528 spin_unlock_irq(&priv->lock);
2530 printk(KERN_DEBUG "%s: ready\n", dev->name);
2536 struct net_device *alloc_orinocodev(int sizeof_card,
2537 int (*hard_reset)(struct orinoco_private *))
2539 struct net_device *dev;
2540 struct orinoco_private *priv;
2542 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2545 priv = netdev_priv(dev);
2548 priv->card = (void *)((unsigned long)priv
2549 + sizeof(struct orinoco_private));
2553 if (orinoco_bss_data_allocate(priv))
2555 orinoco_bss_data_init(priv);
2557 /* Setup / override net_device fields */
2558 dev->init = orinoco_init;
2559 dev->hard_start_xmit = orinoco_xmit;
2560 dev->tx_timeout = orinoco_tx_timeout;
2561 dev->watchdog_timeo = HZ; /* 1 second timeout */
2562 dev->get_stats = orinoco_get_stats;
2563 dev->ethtool_ops = &orinoco_ethtool_ops;
2564 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2566 priv->wireless_data.spy_data = &priv->spy_data;
2567 dev->wireless_data = &priv->wireless_data;
2569 dev->change_mtu = orinoco_change_mtu;
2570 dev->set_multicast_list = orinoco_set_multicast_list;
2571 /* we use the default eth_mac_addr for setting the MAC addr */
2573 /* Set up default callbacks */
2574 dev->open = orinoco_open;
2575 dev->stop = orinoco_stop;
2576 priv->hard_reset = hard_reset;
2578 spin_lock_init(&priv->lock);
2580 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2581 * before anything else touches the
2583 INIT_WORK(&priv->reset_work, orinoco_reset);
2584 INIT_WORK(&priv->join_work, orinoco_join_ap);
2585 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2587 netif_carrier_off(dev);
2588 priv->last_linkstatus = 0xffff;
2597 void free_orinocodev(struct net_device *dev)
2599 struct orinoco_private *priv = netdev_priv(dev);
2601 orinoco_bss_data_free(priv);
2605 /********************************************************************/
2606 /* Wireless extensions */
2607 /********************************************************************/
2609 /* Return : < 0 -> error code ; >= 0 -> length */
2610 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2611 char buf[IW_ESSID_MAX_SIZE+1])
2613 hermes_t *hw = &priv->hw;
2615 struct hermes_idstring essidbuf;
2616 char *p = (char *)(&essidbuf.val);
2618 unsigned long flags;
2620 if (orinoco_lock(priv, &flags) != 0)
2623 if (strlen(priv->desired_essid) > 0) {
2624 /* We read the desired SSID from the hardware rather
2625 than from priv->desired_essid, just in case the
2626 firmware is allowed to change it on us. I'm not
2628 /* My guess is that the OWNSSID should always be whatever
2629 * we set to the card, whereas CURRENT_SSID is the one that
2630 * may change... - Jean II */
2635 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2636 HERMES_RID_CNFDESIREDSSID;
2638 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2645 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2646 sizeof(essidbuf), NULL, &essidbuf);
2651 len = le16_to_cpu(essidbuf.len);
2652 BUG_ON(len > IW_ESSID_MAX_SIZE);
2654 memset(buf, 0, IW_ESSID_MAX_SIZE);
2655 memcpy(buf, p, len);
2659 orinoco_unlock(priv, &flags);
2664 static long orinoco_hw_get_freq(struct orinoco_private *priv)
2667 hermes_t *hw = &priv->hw;
2671 unsigned long flags;
2673 if (orinoco_lock(priv, &flags) != 0)
2676 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
2680 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2686 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
2687 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
2688 priv->ndev->name, channel);
2693 freq = channel_frequency[channel-1] * 100000;
2696 orinoco_unlock(priv, &flags);
2700 return err ? err : freq;
2703 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
2704 int *numrates, s32 *rates, int max)
2706 hermes_t *hw = &priv->hw;
2707 struct hermes_idstring list;
2708 unsigned char *p = (unsigned char *)&list.val;
2712 unsigned long flags;
2714 if (orinoco_lock(priv, &flags) != 0)
2717 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
2718 sizeof(list), NULL, &list);
2719 orinoco_unlock(priv, &flags);
2724 num = le16_to_cpu(list.len);
2726 num = min(num, max);
2728 for (i = 0; i < num; i++) {
2729 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
2735 static int orinoco_ioctl_getname(struct net_device *dev,
2736 struct iw_request_info *info,
2740 struct orinoco_private *priv = netdev_priv(dev);
2744 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2746 if (!err && (numrates > 2))
2747 strcpy(name, "IEEE 802.11b");
2749 strcpy(name, "IEEE 802.11-DS");
2754 static int orinoco_ioctl_setwap(struct net_device *dev,
2755 struct iw_request_info *info,
2756 struct sockaddr *ap_addr,
2759 struct orinoco_private *priv = netdev_priv(dev);
2760 int err = -EINPROGRESS; /* Call commit handler */
2761 unsigned long flags;
2762 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2763 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2765 if (orinoco_lock(priv, &flags) != 0)
2768 /* Enable automatic roaming - no sanity checks are needed */
2769 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2770 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2771 priv->bssid_fixed = 0;
2772 memset(priv->desired_bssid, 0, ETH_ALEN);
2774 /* "off" means keep existing connection */
2775 if (ap_addr->sa_data[0] == 0) {
2776 __orinoco_hw_set_wap(priv);
2782 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2783 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2784 "support manual roaming\n",
2790 if (priv->iw_mode != IW_MODE_INFRA) {
2791 printk(KERN_WARNING "%s: Manual roaming supported only in "
2792 "managed mode\n", dev->name);
2797 /* Intersil firmware hangs without Desired ESSID */
2798 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2799 strlen(priv->desired_essid) == 0) {
2800 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2801 "manual roaming\n", dev->name);
2806 /* Finally, enable manual roaming */
2807 priv->bssid_fixed = 1;
2808 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2811 orinoco_unlock(priv, &flags);
2815 static int orinoco_ioctl_getwap(struct net_device *dev,
2816 struct iw_request_info *info,
2817 struct sockaddr *ap_addr,
2820 struct orinoco_private *priv = netdev_priv(dev);
2822 hermes_t *hw = &priv->hw;
2824 unsigned long flags;
2826 if (orinoco_lock(priv, &flags) != 0)
2829 ap_addr->sa_family = ARPHRD_ETHER;
2830 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2831 ETH_ALEN, NULL, ap_addr->sa_data);
2833 orinoco_unlock(priv, &flags);
2838 static int orinoco_ioctl_setmode(struct net_device *dev,
2839 struct iw_request_info *info,
2843 struct orinoco_private *priv = netdev_priv(dev);
2844 int err = -EINPROGRESS; /* Call commit handler */
2845 unsigned long flags;
2847 if (priv->iw_mode == *mode)
2850 if (orinoco_lock(priv, &flags) != 0)
2855 if (!priv->has_ibss && !priv->has_port3)
2862 case IW_MODE_MONITOR:
2863 if (priv->broken_monitor && !force_monitor) {
2864 printk(KERN_WARNING "%s: Monitor mode support is "
2865 "buggy in this firmware, not enabling\n",
2876 if (err == -EINPROGRESS) {
2877 priv->iw_mode = *mode;
2878 set_port_type(priv);
2881 orinoco_unlock(priv, &flags);
2886 static int orinoco_ioctl_getmode(struct net_device *dev,
2887 struct iw_request_info *info,
2891 struct orinoco_private *priv = netdev_priv(dev);
2893 *mode = priv->iw_mode;
2897 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2898 struct iw_request_info *info,
2899 struct iw_point *rrq,
2902 struct orinoco_private *priv = netdev_priv(dev);
2904 struct iw_range *range = (struct iw_range *) extra;
2908 rrq->length = sizeof(struct iw_range);
2909 memset(range, 0, sizeof(struct iw_range));
2911 range->we_version_compiled = WIRELESS_EXT;
2912 range->we_version_source = 14;
2914 /* Set available channels/frequencies */
2915 range->num_channels = NUM_CHANNELS;
2917 for (i = 0; i < NUM_CHANNELS; i++) {
2918 if (priv->channel_mask & (1 << i)) {
2919 range->freq[k].i = i + 1;
2920 range->freq[k].m = channel_frequency[i] * 100000;
2921 range->freq[k].e = 1;
2925 if (k >= IW_MAX_FREQUENCIES)
2928 range->num_frequency = k;
2929 range->sensitivity = 3;
2931 if (priv->has_wep) {
2932 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2933 range->encoding_size[0] = SMALL_KEY_SIZE;
2934 range->num_encoding_sizes = 1;
2936 if (priv->has_big_wep) {
2937 range->encoding_size[1] = LARGE_KEY_SIZE;
2938 range->num_encoding_sizes = 2;
2942 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
2943 /* Quality stats meaningless in ad-hoc mode */
2945 range->max_qual.qual = 0x8b - 0x2f;
2946 range->max_qual.level = 0x2f - 0x95 - 1;
2947 range->max_qual.noise = 0x2f - 0x95 - 1;
2948 /* Need to get better values */
2949 range->avg_qual.qual = 0x24;
2950 range->avg_qual.level = 0xC2;
2951 range->avg_qual.noise = 0x9E;
2954 err = orinoco_hw_get_bitratelist(priv, &numrates,
2955 range->bitrate, IW_MAX_BITRATES);
2958 range->num_bitrates = numrates;
2960 /* Set an indication of the max TCP throughput in bit/s that we can
2961 * expect using this interface. May be use for QoS stuff...
2964 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2966 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2969 range->max_rts = 2347;
2970 range->min_frag = 256;
2971 range->max_frag = 2346;
2974 range->max_pmp = 65535000;
2976 range->max_pmt = 65535 * 1000; /* ??? */
2977 range->pmp_flags = IW_POWER_PERIOD;
2978 range->pmt_flags = IW_POWER_TIMEOUT;
2979 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
2981 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2982 range->retry_flags = IW_RETRY_LIMIT;
2983 range->r_time_flags = IW_RETRY_LIFETIME;
2984 range->min_retry = 0;
2985 range->max_retry = 65535; /* ??? */
2986 range->min_r_time = 0;
2987 range->max_r_time = 65535 * 1000; /* ??? */
2989 /* Event capability (kernel) */
2990 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2991 /* Event capability (driver) */
2992 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2993 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2994 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2995 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3000 static int orinoco_ioctl_setiwencode(struct net_device *dev,
3001 struct iw_request_info *info,
3002 struct iw_point *erq,
3005 struct orinoco_private *priv = netdev_priv(dev);
3006 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3007 int setindex = priv->tx_key;
3008 int enable = priv->wep_on;
3009 int restricted = priv->wep_restrict;
3011 int err = -EINPROGRESS; /* Call commit handler */
3012 unsigned long flags;
3014 if (! priv->has_wep)
3018 /* We actually have a key to set - check its length */
3019 if (erq->length > LARGE_KEY_SIZE)
3022 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3026 if (orinoco_lock(priv, &flags) != 0)
3029 if (erq->length > 0) {
3030 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3031 index = priv->tx_key;
3033 /* Adjust key length to a supported value */
3034 if (erq->length > SMALL_KEY_SIZE) {
3035 xlen = LARGE_KEY_SIZE;
3036 } else if (erq->length > 0) {
3037 xlen = SMALL_KEY_SIZE;
3041 /* Switch on WEP if off */
3042 if ((!enable) && (xlen > 0)) {
3047 /* Important note : if the user do "iwconfig eth0 enc off",
3048 * we will arrive there with an index of -1. This is valid
3049 * but need to be taken care off... Jean II */
3050 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3051 if((index != -1) || (erq->flags == 0)) {
3056 /* Set the index : Check that the key is valid */
3057 if(priv->keys[index].len == 0) {
3065 if (erq->flags & IW_ENCODE_DISABLED)
3067 if (erq->flags & IW_ENCODE_OPEN)
3069 if (erq->flags & IW_ENCODE_RESTRICTED)
3072 if (erq->pointer && erq->length > 0) {
3073 priv->keys[index].len = cpu_to_le16(xlen);
3074 memset(priv->keys[index].data, 0,
3075 sizeof(priv->keys[index].data));
3076 memcpy(priv->keys[index].data, keybuf, erq->length);
3078 priv->tx_key = setindex;
3080 /* Try fast key change if connected and only keys are changed */
3081 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
3082 netif_carrier_ok(dev)) {
3083 err = __orinoco_hw_setup_wepkeys(priv);
3084 /* No need to commit if successful */
3088 priv->wep_on = enable;
3089 priv->wep_restrict = restricted;
3092 orinoco_unlock(priv, &flags);
3097 static int orinoco_ioctl_getiwencode(struct net_device *dev,
3098 struct iw_request_info *info,
3099 struct iw_point *erq,
3102 struct orinoco_private *priv = netdev_priv(dev);
3103 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3105 unsigned long flags;
3107 if (! priv->has_wep)
3110 if (orinoco_lock(priv, &flags) != 0)
3113 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3114 index = priv->tx_key;
3118 erq->flags |= IW_ENCODE_DISABLED;
3119 erq->flags |= index + 1;
3121 if (priv->wep_restrict)
3122 erq->flags |= IW_ENCODE_RESTRICTED;
3124 erq->flags |= IW_ENCODE_OPEN;
3126 xlen = le16_to_cpu(priv->keys[index].len);
3130 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3132 orinoco_unlock(priv, &flags);
3136 static int orinoco_ioctl_setessid(struct net_device *dev,
3137 struct iw_request_info *info,
3138 struct iw_point *erq,
3141 struct orinoco_private *priv = netdev_priv(dev);
3142 unsigned long flags;
3144 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3145 * anyway... - Jean II */
3147 /* Hum... Should not use Wireless Extension constant (may change),
3148 * should use our own... - Jean II */
3149 if (erq->length > IW_ESSID_MAX_SIZE)
3152 if (orinoco_lock(priv, &flags) != 0)
3155 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3156 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3158 /* If not ANY, get the new ESSID */
3160 memcpy(priv->desired_essid, essidbuf, erq->length);
3163 orinoco_unlock(priv, &flags);
3165 return -EINPROGRESS; /* Call commit handler */
3168 static int orinoco_ioctl_getessid(struct net_device *dev,
3169 struct iw_request_info *info,
3170 struct iw_point *erq,
3173 struct orinoco_private *priv = netdev_priv(dev);
3176 unsigned long flags;
3178 if (netif_running(dev)) {
3179 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3184 if (orinoco_lock(priv, &flags) != 0)
3186 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3187 erq->length = strlen(priv->desired_essid);
3188 orinoco_unlock(priv, &flags);
3196 static int orinoco_ioctl_setnick(struct net_device *dev,
3197 struct iw_request_info *info,
3198 struct iw_point *nrq,
3201 struct orinoco_private *priv = netdev_priv(dev);
3202 unsigned long flags;
3204 if (nrq->length > IW_ESSID_MAX_SIZE)
3207 if (orinoco_lock(priv, &flags) != 0)
3210 memset(priv->nick, 0, sizeof(priv->nick));
3211 memcpy(priv->nick, nickbuf, nrq->length);
3213 orinoco_unlock(priv, &flags);
3215 return -EINPROGRESS; /* Call commit handler */
3218 static int orinoco_ioctl_getnick(struct net_device *dev,
3219 struct iw_request_info *info,
3220 struct iw_point *nrq,
3223 struct orinoco_private *priv = netdev_priv(dev);
3224 unsigned long flags;
3226 if (orinoco_lock(priv, &flags) != 0)
3229 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3230 orinoco_unlock(priv, &flags);
3232 nrq->length = strlen(priv->nick);
3237 static int orinoco_ioctl_setfreq(struct net_device *dev,
3238 struct iw_request_info *info,
3239 struct iw_freq *frq,
3242 struct orinoco_private *priv = netdev_priv(dev);
3244 unsigned long flags;
3245 int err = -EINPROGRESS; /* Call commit handler */
3247 /* In infrastructure mode the AP sets the channel */
3248 if (priv->iw_mode == IW_MODE_INFRA)
3251 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3252 /* Setting by channel number */
3255 /* Setting by frequency - search the table */
3259 for (i = 0; i < (6 - frq->e); i++)
3262 for (i = 0; i < NUM_CHANNELS; i++)
3263 if (frq->m == (channel_frequency[i] * mult))
3267 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3268 ! (priv->channel_mask & (1 << (chan-1)) ) )
3271 if (orinoco_lock(priv, &flags) != 0)
3274 priv->channel = chan;
3275 if (priv->iw_mode == IW_MODE_MONITOR) {
3276 /* Fast channel change - no commit if successful */
3277 hermes_t *hw = &priv->hw;
3278 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3279 HERMES_TEST_SET_CHANNEL,
3282 orinoco_unlock(priv, &flags);
3287 static int orinoco_ioctl_getfreq(struct net_device *dev,
3288 struct iw_request_info *info,
3289 struct iw_freq *frq,
3292 struct orinoco_private *priv = netdev_priv(dev);
3295 /* Locking done in there */
3296 tmp = orinoco_hw_get_freq(priv);
3307 static int orinoco_ioctl_getsens(struct net_device *dev,
3308 struct iw_request_info *info,
3309 struct iw_param *srq,
3312 struct orinoco_private *priv = netdev_priv(dev);
3313 hermes_t *hw = &priv->hw;
3316 unsigned long flags;
3318 if (!priv->has_sensitivity)
3321 if (orinoco_lock(priv, &flags) != 0)
3323 err = hermes_read_wordrec(hw, USER_BAP,
3324 HERMES_RID_CNFSYSTEMSCALE, &val);
3325 orinoco_unlock(priv, &flags);
3331 srq->fixed = 0; /* auto */
3336 static int orinoco_ioctl_setsens(struct net_device *dev,
3337 struct iw_request_info *info,
3338 struct iw_param *srq,
3341 struct orinoco_private *priv = netdev_priv(dev);
3342 int val = srq->value;
3343 unsigned long flags;
3345 if (!priv->has_sensitivity)
3348 if ((val < 1) || (val > 3))
3351 if (orinoco_lock(priv, &flags) != 0)
3353 priv->ap_density = val;
3354 orinoco_unlock(priv, &flags);
3356 return -EINPROGRESS; /* Call commit handler */
3359 static int orinoco_ioctl_setrts(struct net_device *dev,
3360 struct iw_request_info *info,
3361 struct iw_param *rrq,
3364 struct orinoco_private *priv = netdev_priv(dev);
3365 int val = rrq->value;
3366 unsigned long flags;
3371 if ( (val < 0) || (val > 2347) )
3374 if (orinoco_lock(priv, &flags) != 0)
3377 priv->rts_thresh = val;
3378 orinoco_unlock(priv, &flags);
3380 return -EINPROGRESS; /* Call commit handler */
3383 static int orinoco_ioctl_getrts(struct net_device *dev,
3384 struct iw_request_info *info,
3385 struct iw_param *rrq,
3388 struct orinoco_private *priv = netdev_priv(dev);
3390 rrq->value = priv->rts_thresh;
3391 rrq->disabled = (rrq->value == 2347);
3397 static int orinoco_ioctl_setfrag(struct net_device *dev,
3398 struct iw_request_info *info,
3399 struct iw_param *frq,
3402 struct orinoco_private *priv = netdev_priv(dev);
3403 int err = -EINPROGRESS; /* Call commit handler */
3404 unsigned long flags;
3406 if (orinoco_lock(priv, &flags) != 0)
3409 if (priv->has_mwo) {
3411 priv->mwo_robust = 0;
3414 printk(KERN_WARNING "%s: Fixed fragmentation is "
3415 "not supported on this firmware. "
3416 "Using MWO robust instead.\n", dev->name);
3417 priv->mwo_robust = 1;
3421 priv->frag_thresh = 2346;
3423 if ( (frq->value < 256) || (frq->value > 2346) )
3426 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3430 orinoco_unlock(priv, &flags);
3435 static int orinoco_ioctl_getfrag(struct net_device *dev,
3436 struct iw_request_info *info,
3437 struct iw_param *frq,
3440 struct orinoco_private *priv = netdev_priv(dev);
3441 hermes_t *hw = &priv->hw;
3444 unsigned long flags;
3446 if (orinoco_lock(priv, &flags) != 0)
3449 if (priv->has_mwo) {
3450 err = hermes_read_wordrec(hw, USER_BAP,
3451 HERMES_RID_CNFMWOROBUST_AGERE,
3456 frq->value = val ? 2347 : 0;
3457 frq->disabled = ! val;
3460 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3466 frq->disabled = (val >= 2346);
3470 orinoco_unlock(priv, &flags);
3475 static int orinoco_ioctl_setrate(struct net_device *dev,
3476 struct iw_request_info *info,
3477 struct iw_param *rrq,
3480 struct orinoco_private *priv = netdev_priv(dev);
3482 int bitrate; /* 100s of kilobits */
3484 unsigned long flags;
3486 /* As the user space doesn't know our highest rate, it uses -1
3487 * to ask us to set the highest rate. Test it using "iwconfig
3488 * ethX rate auto" - Jean II */
3489 if (rrq->value == -1)
3492 if (rrq->value % 100000)
3494 bitrate = rrq->value / 100000;
3497 if ( (bitrate != 10) && (bitrate != 20) &&
3498 (bitrate != 55) && (bitrate != 110) )
3501 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3502 if ( (bitrate_table[i].bitrate == bitrate) &&
3503 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3511 if (orinoco_lock(priv, &flags) != 0)
3513 priv->bitratemode = ratemode;
3514 orinoco_unlock(priv, &flags);
3516 return -EINPROGRESS;
3519 static int orinoco_ioctl_getrate(struct net_device *dev,
3520 struct iw_request_info *info,
3521 struct iw_param *rrq,
3524 struct orinoco_private *priv = netdev_priv(dev);
3525 hermes_t *hw = &priv->hw;
3530 unsigned long flags;
3532 if (orinoco_lock(priv, &flags) != 0)
3535 ratemode = priv->bitratemode;
3537 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3539 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3540 rrq->fixed = ! bitrate_table[ratemode].automatic;
3543 /* If the interface is running we try to find more about the
3545 if (netif_running(dev)) {
3546 err = hermes_read_wordrec(hw, USER_BAP,
3547 HERMES_RID_CURRENTTXRATE, &val);
3551 switch (priv->firmware_type) {
3552 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3553 /* Note : in Lucent firmware, the return value of
3554 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3555 * and therefore is totally different from the
3556 * encoding of HERMES_RID_CNFTXRATECONTROL.
3557 * Don't forget that 6Mb/s is really 5.5Mb/s */
3559 rrq->value = 5500000;
3561 rrq->value = val * 1000000;
3563 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3564 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3565 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3566 if (bitrate_table[i].intersil_txratectrl == val) {
3570 if (i >= BITRATE_TABLE_SIZE)
3571 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3574 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3582 orinoco_unlock(priv, &flags);
3587 static int orinoco_ioctl_setpower(struct net_device *dev,
3588 struct iw_request_info *info,
3589 struct iw_param *prq,
3592 struct orinoco_private *priv = netdev_priv(dev);
3593 int err = -EINPROGRESS; /* Call commit handler */
3594 unsigned long flags;
3596 if (orinoco_lock(priv, &flags) != 0)
3599 if (prq->disabled) {
3602 switch (prq->flags & IW_POWER_MODE) {
3603 case IW_POWER_UNICAST_R:
3607 case IW_POWER_ALL_R:
3612 /* No flags : but we may have a value - Jean II */
3619 if (prq->flags & IW_POWER_TIMEOUT) {
3621 priv->pm_timeout = prq->value / 1000;
3623 if (prq->flags & IW_POWER_PERIOD) {
3625 priv->pm_period = prq->value / 1000;
3627 /* It's valid to not have a value if we are just toggling
3628 * the flags... Jean II */
3636 orinoco_unlock(priv, &flags);
3641 static int orinoco_ioctl_getpower(struct net_device *dev,
3642 struct iw_request_info *info,
3643 struct iw_param *prq,
3646 struct orinoco_private *priv = netdev_priv(dev);
3647 hermes_t *hw = &priv->hw;
3649 u16 enable, period, timeout, mcast;
3650 unsigned long flags;
3652 if (orinoco_lock(priv, &flags) != 0)
3655 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
3659 err = hermes_read_wordrec(hw, USER_BAP,
3660 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3664 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3668 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3672 prq->disabled = !enable;
3673 /* Note : by default, display the period */
3674 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3675 prq->flags = IW_POWER_TIMEOUT;
3676 prq->value = timeout * 1000;
3678 prq->flags = IW_POWER_PERIOD;
3679 prq->value = period * 1000;
3682 prq->flags |= IW_POWER_ALL_R;
3684 prq->flags |= IW_POWER_UNICAST_R;
3687 orinoco_unlock(priv, &flags);
3692 static int orinoco_ioctl_getretry(struct net_device *dev,
3693 struct iw_request_info *info,
3694 struct iw_param *rrq,
3697 struct orinoco_private *priv = netdev_priv(dev);
3698 hermes_t *hw = &priv->hw;
3700 u16 short_limit, long_limit, lifetime;
3701 unsigned long flags;
3703 if (orinoco_lock(priv, &flags) != 0)
3706 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
3711 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
3716 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
3721 rrq->disabled = 0; /* Can't be disabled */
3723 /* Note : by default, display the retry number */
3724 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
3725 rrq->flags = IW_RETRY_LIFETIME;
3726 rrq->value = lifetime * 1000; /* ??? */
3728 /* By default, display the min number */
3729 if ((rrq->flags & IW_RETRY_LONG)) {
3730 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
3731 rrq->value = long_limit;
3733 rrq->flags = IW_RETRY_LIMIT;
3734 rrq->value = short_limit;
3735 if(short_limit != long_limit)
3736 rrq->flags |= IW_RETRY_SHORT;
3741 orinoco_unlock(priv, &flags);
3746 static int orinoco_ioctl_reset(struct net_device *dev,
3747 struct iw_request_info *info,
3751 struct orinoco_private *priv = netdev_priv(dev);
3753 if (! capable(CAP_NET_ADMIN))
3756 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
3757 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
3759 /* Firmware reset */
3760 orinoco_reset(&priv->reset_work);
3762 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
3764 schedule_work(&priv->reset_work);
3770 static int orinoco_ioctl_setibssport(struct net_device *dev,
3771 struct iw_request_info *info,
3776 struct orinoco_private *priv = netdev_priv(dev);
3777 int val = *( (int *) extra );
3778 unsigned long flags;
3780 if (orinoco_lock(priv, &flags) != 0)
3783 priv->ibss_port = val ;
3785 /* Actually update the mode we are using */
3786 set_port_type(priv);
3788 orinoco_unlock(priv, &flags);
3789 return -EINPROGRESS; /* Call commit handler */
3792 static int orinoco_ioctl_getibssport(struct net_device *dev,
3793 struct iw_request_info *info,
3797 struct orinoco_private *priv = netdev_priv(dev);
3798 int *val = (int *) extra;
3800 *val = priv->ibss_port;
3804 static int orinoco_ioctl_setport3(struct net_device *dev,
3805 struct iw_request_info *info,
3809 struct orinoco_private *priv = netdev_priv(dev);
3810 int val = *( (int *) extra );
3812 unsigned long flags;
3814 if (orinoco_lock(priv, &flags) != 0)
3818 case 0: /* Try to do IEEE ad-hoc mode */
3819 if (! priv->has_ibss) {
3823 priv->prefer_port3 = 0;
3827 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3828 if (! priv->has_port3) {
3832 priv->prefer_port3 = 1;
3840 /* Actually update the mode we are using */
3841 set_port_type(priv);
3845 orinoco_unlock(priv, &flags);
3850 static int orinoco_ioctl_getport3(struct net_device *dev,
3851 struct iw_request_info *info,
3855 struct orinoco_private *priv = netdev_priv(dev);
3856 int *val = (int *) extra;
3858 *val = priv->prefer_port3;
3862 static int orinoco_ioctl_setpreamble(struct net_device *dev,
3863 struct iw_request_info *info,
3867 struct orinoco_private *priv = netdev_priv(dev);
3868 unsigned long flags;
3871 if (! priv->has_preamble)
3874 /* 802.11b has recently defined some short preamble.
3875 * Basically, the Phy header has been reduced in size.
3876 * This increase performance, especially at high rates
3877 * (the preamble is transmitted at 1Mb/s), unfortunately
3878 * this give compatibility troubles... - Jean II */
3879 val = *( (int *) extra );
3881 if (orinoco_lock(priv, &flags) != 0)
3889 orinoco_unlock(priv, &flags);
3891 return -EINPROGRESS; /* Call commit handler */
3894 static int orinoco_ioctl_getpreamble(struct net_device *dev,
3895 struct iw_request_info *info,
3899 struct orinoco_private *priv = netdev_priv(dev);
3900 int *val = (int *) extra;
3902 if (! priv->has_preamble)
3905 *val = priv->preamble;
3909 /* ioctl interface to hermes_read_ltv()
3910 * To use with iwpriv, pass the RID as the token argument, e.g.
3911 * iwpriv get_rid [0xfc00]
3912 * At least Wireless Tools 25 is required to use iwpriv.
3913 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3914 static int orinoco_ioctl_getrid(struct net_device *dev,
3915 struct iw_request_info *info,
3916 struct iw_point *data,
3919 struct orinoco_private *priv = netdev_priv(dev);
3920 hermes_t *hw = &priv->hw;
3921 int rid = data->flags;
3924 unsigned long flags;
3926 /* It's a "get" function, but we don't want users to access the
3927 * WEP key and other raw firmware data */
3928 if (! capable(CAP_NET_ADMIN))
3931 if (rid < 0xfc00 || rid > 0xffff)
3934 if (orinoco_lock(priv, &flags) != 0)
3937 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
3942 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
3946 orinoco_unlock(priv, &flags);
3950 /* Trigger a scan (look for other cells in the vicinity */
3951 static int orinoco_ioctl_setscan(struct net_device *dev,
3952 struct iw_request_info *info,
3953 struct iw_param *srq,
3956 struct orinoco_private *priv = netdev_priv(dev);
3957 hermes_t *hw = &priv->hw;
3959 unsigned long flags;
3961 /* Note : you may have realised that, as this is a SET operation,
3962 * this is privileged and therefore a normal user can't
3964 * This is not an error, while the device perform scanning,
3965 * traffic doesn't flow, so it's a perfect DoS...
3968 if (orinoco_lock(priv, &flags) != 0)
3971 /* Scanning with port 0 disabled would fail */
3972 if (!netif_running(dev)) {
3977 /* In monitor mode, the scan results are always empty.
3978 * Probe responses are passed to the driver as received
3979 * frames and could be processed in software. */
3980 if (priv->iw_mode == IW_MODE_MONITOR) {
3985 /* Note : because we don't lock out the irq handler, the way
3986 * we access scan variables in priv is critical.
3987 * o scan_inprogress : not touched by irq handler
3988 * o scan_mode : not touched by irq handler
3989 * o scan_len : synchronised with scan_result
3990 * Before modifying anything on those variables, please think hard !
3994 priv->scan_mode = srq->flags;
3996 /* Always trigger scanning, even if it's in progress.
3997 * This way, if the info frame get lost, we will recover somewhat
3998 * gracefully - Jean II */
4000 if (priv->has_hostscan) {
4001 switch (priv->firmware_type) {
4002 case FIRMWARE_TYPE_SYMBOL:
4003 err = hermes_write_wordrec(hw, USER_BAP,
4004 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4005 HERMES_HOSTSCAN_SYMBOL_ONCE |
4006 HERMES_HOSTSCAN_SYMBOL_BCAST);
4008 case FIRMWARE_TYPE_INTERSIL: {
4011 req[0] = cpu_to_le16(0x3fff); /* All channels */
4012 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4013 req[2] = 0; /* Any ESSID */
4014 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4015 HERMES_RID_CNFHOSTSCAN, &req);
4018 case FIRMWARE_TYPE_AGERE:
4019 err = hermes_write_wordrec(hw, USER_BAP,
4020 HERMES_RID_CNFSCANSSID_AGERE,
4025 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4029 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4031 /* One more client */
4033 priv->scan_inprogress = 1;
4036 orinoco_unlock(priv, &flags);
4040 #define MAX_CUSTOM_LEN 64
4042 /* Translate scan data returned from the card to a card independant
4043 * format that the Wireless Tools will understand - Jean II
4044 * Return message length or -errno for fatal errors */
4045 static inline char *orinoco_translate_scan(struct net_device *dev,
4046 struct iw_request_info *info,
4049 union hermes_scan_info *bss,
4050 unsigned int last_scanned)
4052 struct orinoco_private *priv = netdev_priv(dev);
4055 struct iw_event iwe; /* Temporary buffer */
4057 char custom[MAX_CUSTOM_LEN];
4059 /* First entry *MUST* be the AP MAC address */
4060 iwe.cmd = SIOCGIWAP;
4061 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4062 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
4063 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4064 &iwe, IW_EV_ADDR_LEN);
4066 /* Other entries will be displayed in the order we give them */
4069 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4070 if (iwe.u.data.length > 32)
4071 iwe.u.data.length = 32;
4072 iwe.cmd = SIOCGIWESSID;
4073 iwe.u.data.flags = 1;
4074 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4075 &iwe, bss->a.essid);
4078 iwe.cmd = SIOCGIWMODE;
4079 capabilities = le16_to_cpu(bss->a.capabilities);
4080 if (capabilities & 0x3) {
4081 if (capabilities & 0x1)
4082 iwe.u.mode = IW_MODE_MASTER;
4084 iwe.u.mode = IW_MODE_ADHOC;
4085 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4086 &iwe, IW_EV_UINT_LEN);
4089 channel = bss->s.channel;
4090 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4092 iwe.cmd = SIOCGIWFREQ;
4093 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4095 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4096 &iwe, IW_EV_FREQ_LEN);
4099 /* Add quality statistics */
4101 iwe.u.qual.updated = 0x10; /* no link quality */
4102 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4103 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4104 /* Wireless tools prior to 27.pre22 will show link quality
4105 * anyway, so we provide a reasonable value. */
4106 if (iwe.u.qual.level > iwe.u.qual.noise)
4107 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4109 iwe.u.qual.qual = 0;
4110 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4111 &iwe, IW_EV_QUAL_LEN);
4113 /* Add encryption capability */
4114 iwe.cmd = SIOCGIWENCODE;
4115 if (capabilities & 0x10)
4116 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4118 iwe.u.data.flags = IW_ENCODE_DISABLED;
4119 iwe.u.data.length = 0;
4120 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4121 &iwe, bss->a.essid);
4123 /* Add EXTRA: Age to display seconds since last beacon/probe response
4124 * for given network. */
4125 iwe.cmd = IWEVCUSTOM;
4127 p += snprintf(p, MAX_CUSTOM_LEN - (p - custom),
4128 " Last beacon: %dms ago",
4129 jiffies_to_msecs(jiffies - last_scanned));
4130 iwe.u.data.length = p - custom;
4131 if (iwe.u.data.length)
4132 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4135 /* Bit rate is not available in Lucent/Agere firmwares */
4136 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4137 char *current_val = current_ev + iwe_stream_lcp_len(info);
4141 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4146 iwe.cmd = SIOCGIWRATE;
4147 /* Those two flags are ignored... */
4148 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4150 for (i = 0; i < 10; i += step) {
4151 /* NULL terminated */
4152 if (bss->p.rates[i] == 0x0)
4154 /* Bit rate given in 500 kb/s units (+ 0x80) */
4155 iwe.u.bitrate.value = ((bss->p.rates[i] & 0x7f) * 500000);
4156 current_val = iwe_stream_add_value(info, current_ev,
4161 /* Check if we added any event */
4162 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
4163 current_ev = current_val;
4169 /* Return results of a scan */
4170 static int orinoco_ioctl_getscan(struct net_device *dev,
4171 struct iw_request_info *info,
4172 struct iw_point *srq,
4175 struct orinoco_private *priv = netdev_priv(dev);
4178 unsigned long flags;
4179 char *current_ev = extra;
4181 if (orinoco_lock(priv, &flags) != 0)
4184 if (priv->scan_inprogress) {
4185 /* Important note : we don't want to block the caller
4186 * until results are ready for various reasons.
4187 * First, managing wait queues is complex and racy.
4188 * Second, we grab some rtnetlink lock before comming
4189 * here (in dev_ioctl()).
4190 * Third, we generate an Wireless Event, so the
4191 * caller can wait itself on that - Jean II */
4196 list_for_each_entry(bss, &priv->bss_list, list) {
4197 /* Translate to WE format this entry */
4198 current_ev = orinoco_translate_scan(dev, info, current_ev,
4199 extra + srq->length,
4203 /* Check if there is space for one more entry */
4204 if ((extra + srq->length - current_ev) <= IW_EV_ADDR_LEN) {
4205 /* Ask user space to try again with a bigger buffer */
4211 srq->length = (current_ev - extra);
4212 srq->flags = (__u16) priv->scan_mode;
4215 orinoco_unlock(priv, &flags);
4219 /* Commit handler, called after set operations */
4220 static int orinoco_ioctl_commit(struct net_device *dev,
4221 struct iw_request_info *info,
4225 struct orinoco_private *priv = netdev_priv(dev);
4226 struct hermes *hw = &priv->hw;
4227 unsigned long flags;
4233 if (priv->broken_disableport) {
4234 orinoco_reset(&priv->reset_work);
4238 if (orinoco_lock(priv, &flags) != 0)
4241 err = hermes_disable_port(hw, 0);
4243 printk(KERN_WARNING "%s: Unable to disable port "
4244 "while reconfiguring card\n", dev->name);
4245 priv->broken_disableport = 1;
4249 err = __orinoco_program_rids(dev);
4251 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4256 err = hermes_enable_port(hw, 0);
4258 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4265 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4266 schedule_work(&priv->reset_work);
4270 orinoco_unlock(priv, &flags);
4274 static const struct iw_priv_args orinoco_privtab[] = {
4275 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4276 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4277 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4279 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4281 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4282 0, "set_preamble" },
4283 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4285 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4286 0, "set_ibssport" },
4287 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4289 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4295 * Structures to export the Wireless Handlers
4298 static const iw_handler orinoco_handler[] = {
4299 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4300 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4301 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4302 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4303 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4304 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4305 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4306 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4307 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4308 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4309 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4310 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4311 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4312 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4313 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4314 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4315 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4316 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4317 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4318 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4319 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4320 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4321 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4322 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4323 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4324 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4325 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4326 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4327 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4328 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4329 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4330 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4335 Added typecasting since we no longer use iwreq_data -- Moustafa
4337 static const iw_handler orinoco_private_handler[] = {
4338 [0] = (iw_handler) orinoco_ioctl_reset,
4339 [1] = (iw_handler) orinoco_ioctl_reset,
4340 [2] = (iw_handler) orinoco_ioctl_setport3,
4341 [3] = (iw_handler) orinoco_ioctl_getport3,
4342 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4343 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4344 [6] = (iw_handler) orinoco_ioctl_setibssport,
4345 [7] = (iw_handler) orinoco_ioctl_getibssport,
4346 [9] = (iw_handler) orinoco_ioctl_getrid,
4349 static const struct iw_handler_def orinoco_handler_def = {
4350 .num_standard = ARRAY_SIZE(orinoco_handler),
4351 .num_private = ARRAY_SIZE(orinoco_private_handler),
4352 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4353 .standard = orinoco_handler,
4354 .private = orinoco_private_handler,
4355 .private_args = orinoco_privtab,
4356 .get_wireless_stats = orinoco_get_wireless_stats,
4359 static void orinoco_get_drvinfo(struct net_device *dev,
4360 struct ethtool_drvinfo *info)
4362 struct orinoco_private *priv = netdev_priv(dev);
4364 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4365 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4366 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4367 if (dev->dev.parent)
4368 strncpy(info->bus_info, dev->dev.parent->bus_id,
4369 sizeof(info->bus_info) - 1);
4371 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4372 "PCMCIA %p", priv->hw.iobase);
4375 static const struct ethtool_ops orinoco_ethtool_ops = {
4376 .get_drvinfo = orinoco_get_drvinfo,
4377 .get_link = ethtool_op_get_link,
4380 /********************************************************************/
4381 /* Module initialization */
4382 /********************************************************************/
4384 EXPORT_SYMBOL(alloc_orinocodev);
4385 EXPORT_SYMBOL(free_orinocodev);
4387 EXPORT_SYMBOL(__orinoco_up);
4388 EXPORT_SYMBOL(__orinoco_down);
4389 EXPORT_SYMBOL(orinoco_reinit_firmware);
4391 EXPORT_SYMBOL(orinoco_interrupt);
4393 /* Can't be declared "const" or the whole __initdata section will
4395 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4396 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4397 "Pavel Roskin <proski@gnu.org>, et al)";
4399 static int __init init_orinoco(void)
4401 printk(KERN_DEBUG "%s\n", version);
4405 static void __exit exit_orinoco(void)
4409 module_init(init_orinoco);
4410 module_exit(exit_orinoco);