1 /* main.c - (formerly known as dldwd_cs.c, orinoco_cs.c and orinoco.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/delay.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.h>
86 #include <linux/suspend.h>
87 #include <linux/if_arp.h>
88 #include <linux/wireless.h>
89 #include <linux/ieee80211.h>
90 #include <net/iw_handler.h>
92 #include "hermes_rid.h"
93 #include "hermes_dld.h"
101 /********************************************************************/
102 /* Module information */
103 /********************************************************************/
105 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
106 "David Gibson <hermes@gibson.dropbear.id.au>");
107 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
108 "and similar wireless cards");
109 MODULE_LICENSE("Dual MPL/GPL");
111 /* Level of debugging. Used in the macros in orinoco.h */
113 int orinoco_debug = ORINOCO_DEBUG;
114 EXPORT_SYMBOL(orinoco_debug);
115 module_param(orinoco_debug, int, 0644);
116 MODULE_PARM_DESC(orinoco_debug, "Debug level");
119 static int suppress_linkstatus; /* = 0 */
120 module_param(suppress_linkstatus, bool, 0644);
121 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
123 static int ignore_disconnect; /* = 0 */
124 module_param(ignore_disconnect, int, 0644);
125 MODULE_PARM_DESC(ignore_disconnect,
126 "Don't report lost link to the network layer");
128 static int force_monitor; /* = 0 */
129 module_param(force_monitor, int, 0644);
130 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
132 /********************************************************************/
133 /* Compile time configuration and compatibility stuff */
134 /********************************************************************/
136 /* We do this this way to avoid ifdefs in the actual code */
138 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
140 #define SPY_NUMBER(priv) 0
141 #endif /* WIRELESS_SPY */
143 /********************************************************************/
144 /* Internal constants */
145 /********************************************************************/
147 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
148 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
149 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
151 #define ORINOCO_MIN_MTU 256
152 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
154 #define SYMBOL_MAX_VER_LEN (14)
155 #define MAX_IRQLOOPS_PER_IRQ 10
156 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
157 * how many events the
159 * legitimately generate */
160 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
162 #define DUMMY_FID 0xFFFF
164 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
165 HERMES_MAX_MULTICAST : 0)*/
166 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
168 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
169 | HERMES_EV_TX | HERMES_EV_TXEXC \
170 | HERMES_EV_WTERR | HERMES_EV_INFO \
173 #define MAX_RID_LEN 1024
175 static const struct iw_handler_def orinoco_handler_def;
176 static const struct ethtool_ops orinoco_ethtool_ops;
178 /********************************************************************/
180 /********************************************************************/
182 /* Beginning of the Tx descriptor, used in TxExc handling */
183 struct hermes_txexc_data {
184 struct hermes_tx_descriptor desc;
188 } __attribute__ ((packed));
190 /* Rx frame header except compatibility 802.3 header */
191 struct hermes_rx_descriptor {
212 } __attribute__ ((packed));
214 struct orinoco_rx_data {
215 struct hermes_rx_descriptor *desc;
217 struct list_head list;
220 /********************************************************************/
221 /* Function prototypes */
222 /********************************************************************/
224 static int __orinoco_program_rids(struct net_device *dev);
225 static void __orinoco_set_multicast_list(struct net_device *dev);
227 /********************************************************************/
228 /* Internal helper functions */
229 /********************************************************************/
231 static inline void set_port_type(struct orinoco_private *priv)
233 switch (priv->iw_mode) {
236 priv->createibss = 0;
239 if (priv->prefer_port3) {
241 priv->createibss = 0;
243 priv->port_type = priv->ibss_port;
244 priv->createibss = 1;
247 case IW_MODE_MONITOR:
249 priv->createibss = 0;
252 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
257 static inline u8 *orinoco_get_ie(u8 *data, size_t len,
258 enum ieee80211_eid eid)
261 while ((p + 2) < (data + len)) {
269 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
270 #define WPA_SELECTOR_LEN 4
271 static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
274 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
275 if ((p[0] == WLAN_EID_GENERIC) &&
276 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
284 /********************************************************************/
286 /********************************************************************/
288 static int orinoco_open(struct net_device *dev)
290 struct orinoco_private *priv = netdev_priv(dev);
294 if (orinoco_lock(priv, &flags) != 0)
297 err = __orinoco_up(dev);
302 orinoco_unlock(priv, &flags);
307 static int orinoco_stop(struct net_device *dev)
309 struct orinoco_private *priv = netdev_priv(dev);
312 /* We mustn't use orinoco_lock() here, because we need to be
313 able to close the interface even if hw_unavailable is set
314 (e.g. as we're released after a PC Card removal) */
315 spin_lock_irq(&priv->lock);
319 err = __orinoco_down(dev);
321 spin_unlock_irq(&priv->lock);
326 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
328 struct orinoco_private *priv = netdev_priv(dev);
333 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
335 struct orinoco_private *priv = netdev_priv(dev);
336 hermes_t *hw = &priv->hw;
337 struct iw_statistics *wstats = &priv->wstats;
341 if (!netif_device_present(dev)) {
342 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
344 return NULL; /* FIXME: Can we do better than this? */
347 /* If busy, return the old stats. Returning NULL may cause
348 * the interface to disappear from /proc/net/wireless */
349 if (orinoco_lock(priv, &flags) != 0)
352 /* We can't really wait for the tallies inquiry command to
353 * complete, so we just use the previous results and trigger
354 * a new tallies inquiry command for next time - Jean II */
355 /* FIXME: Really we should wait for the inquiry to come back -
356 * as it is the stats we give don't make a whole lot of sense.
357 * Unfortunately, it's not clear how to do that within the
358 * wireless extensions framework: I think we're in user
359 * context, but a lock seems to be held by the time we get in
360 * here so we're not safe to sleep here. */
361 hermes_inquire(hw, HERMES_INQ_TALLIES);
363 if (priv->iw_mode == IW_MODE_ADHOC) {
364 memset(&wstats->qual, 0, sizeof(wstats->qual));
365 /* If a spy address is defined, we report stats of the
366 * first spy address - Jean II */
367 if (SPY_NUMBER(priv)) {
368 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
369 wstats->qual.level = priv->spy_data.spy_stat[0].level;
370 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
371 wstats->qual.updated =
372 priv->spy_data.spy_stat[0].updated;
376 __le16 qual, signal, noise, unused;
377 } __attribute__ ((packed)) cq;
379 err = HERMES_READ_RECORD(hw, USER_BAP,
380 HERMES_RID_COMMSQUALITY, &cq);
383 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
384 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
385 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
386 wstats->qual.updated =
387 IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
391 orinoco_unlock(priv, &flags);
395 static void orinoco_set_multicast_list(struct net_device *dev)
397 struct orinoco_private *priv = netdev_priv(dev);
400 if (orinoco_lock(priv, &flags) != 0) {
401 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
402 "called when hw_unavailable\n", dev->name);
406 __orinoco_set_multicast_list(dev);
407 orinoco_unlock(priv, &flags);
410 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
412 struct orinoco_private *priv = netdev_priv(dev);
414 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
417 /* MTU + encapsulation + header length */
418 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
419 (priv->nicbuf_size - ETH_HLEN))
427 /********************************************************************/
429 /********************************************************************/
431 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
433 struct orinoco_private *priv = netdev_priv(dev);
434 struct net_device_stats *stats = &priv->stats;
435 hermes_t *hw = &priv->hw;
437 u16 txfid = priv->txfid;
442 if (!netif_running(dev)) {
443 printk(KERN_ERR "%s: Tx on stopped device!\n",
445 return NETDEV_TX_BUSY;
448 if (netif_queue_stopped(dev)) {
449 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
451 return NETDEV_TX_BUSY;
454 if (orinoco_lock(priv, &flags) != 0) {
455 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
457 return NETDEV_TX_BUSY;
460 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
461 /* Oops, the firmware hasn't established a connection,
462 silently drop the packet (this seems to be the
467 /* Check packet length */
468 if (skb->len < ETH_HLEN)
471 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
473 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
474 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
477 if (priv->has_alt_txcntl) {
478 /* WPA enabled firmwares have tx_cntl at the end of
479 * the 802.11 header. So write zeroed descriptor and
480 * 802.11 header at the same time
482 char desc[HERMES_802_3_OFFSET];
483 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
485 memset(&desc, 0, sizeof(desc));
487 *txcntl = cpu_to_le16(tx_control);
488 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
492 printk(KERN_ERR "%s: Error %d writing Tx "
493 "descriptor to BAP\n", dev->name, err);
497 struct hermes_tx_descriptor desc;
499 memset(&desc, 0, sizeof(desc));
501 desc.tx_control = cpu_to_le16(tx_control);
502 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
506 printk(KERN_ERR "%s: Error %d writing Tx "
507 "descriptor to BAP\n", dev->name, err);
511 /* Clear the 802.11 header and data length fields - some
512 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
513 * if this isn't done. */
514 hermes_clear_words(hw, HERMES_DATA0,
515 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
518 eh = (struct ethhdr *)skb->data;
520 /* Encapsulate Ethernet-II frames */
521 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
522 struct header_struct {
523 struct ethhdr eth; /* 802.3 header */
524 u8 encap[6]; /* 802.2 header */
525 } __attribute__ ((packed)) hdr;
527 /* Strip destination and source from the data */
528 skb_pull(skb, 2 * ETH_ALEN);
530 /* And move them to a separate header */
531 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
532 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
533 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
535 /* Insert the SNAP header */
536 if (skb_headroom(skb) < sizeof(hdr)) {
538 "%s: Not enough headroom for 802.2 headers %d\n",
539 dev->name, skb_headroom(skb));
542 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
543 memcpy(eh, &hdr, sizeof(hdr));
546 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
547 txfid, HERMES_802_3_OFFSET);
549 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
554 /* Calculate Michael MIC */
555 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
556 u8 mic_buf[MICHAEL_MIC_LEN + 1];
562 /* MIC start is on an odd boundary */
563 mic_buf[0] = skb->data[skb->len - 1];
565 offset = skb->len - 1;
566 len = MICHAEL_MIC_LEN + 1;
570 len = MICHAEL_MIC_LEN;
573 orinoco_mic(priv->tx_tfm_mic,
574 priv->tkip_key[priv->tx_key].tx_mic,
575 eh->h_dest, eh->h_source, 0 /* priority */,
576 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
579 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
580 txfid, HERMES_802_3_OFFSET + offset);
582 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
588 /* Finally, we actually initiate the send */
589 netif_stop_queue(dev);
591 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
594 netif_start_queue(dev);
596 printk(KERN_ERR "%s: Error %d transmitting packet\n",
601 dev->trans_start = jiffies;
602 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
610 orinoco_unlock(priv, &flags);
616 schedule_work(&priv->reset_work);
617 orinoco_unlock(priv, &flags);
618 return NETDEV_TX_BUSY;
621 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
623 struct orinoco_private *priv = netdev_priv(dev);
624 u16 fid = hermes_read_regn(hw, ALLOCFID);
626 if (fid != priv->txfid) {
627 if (fid != DUMMY_FID)
628 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
633 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
636 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
638 struct orinoco_private *priv = netdev_priv(dev);
639 struct net_device_stats *stats = &priv->stats;
643 netif_wake_queue(dev);
645 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
648 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
650 struct orinoco_private *priv = netdev_priv(dev);
651 struct net_device_stats *stats = &priv->stats;
652 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
654 struct hermes_txexc_data hdr;
657 if (fid == DUMMY_FID)
658 return; /* Nothing's really happened */
660 /* Read part of the frame header - we need status and addr1 */
661 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
662 sizeof(struct hermes_txexc_data),
665 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
669 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
670 "(FID=%04X error %d)\n",
671 dev->name, fid, err);
675 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
678 /* We produce a TXDROP event only for retry or lifetime
679 * exceeded, because that's the only status that really mean
680 * that this particular node went away.
681 * Other errors means that *we* screwed up. - Jean II */
682 status = le16_to_cpu(hdr.desc.status);
683 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
684 union iwreq_data wrqu;
686 /* Copy 802.11 dest address.
687 * We use the 802.11 header because the frame may
688 * not be 802.3 or may be mangled...
689 * In Ad-Hoc mode, it will be the node address.
690 * In managed mode, it will be most likely the AP addr
691 * User space will figure out how to convert it to
692 * whatever it needs (IP address or else).
694 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
695 wrqu.addr.sa_family = ARPHRD_ETHER;
697 /* Send event to user space */
698 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
701 netif_wake_queue(dev);
704 static void orinoco_tx_timeout(struct net_device *dev)
706 struct orinoco_private *priv = netdev_priv(dev);
707 struct net_device_stats *stats = &priv->stats;
708 struct hermes *hw = &priv->hw;
710 printk(KERN_WARNING "%s: Tx timeout! "
711 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
712 dev->name, hermes_read_regn(hw, ALLOCFID),
713 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
717 schedule_work(&priv->reset_work);
720 /********************************************************************/
721 /* Rx path (data frames) */
722 /********************************************************************/
724 /* Does the frame have a SNAP header indicating it should be
725 * de-encapsulated to Ethernet-II? */
726 static inline int is_ethersnap(void *_hdr)
730 /* We de-encapsulate all packets which, a) have SNAP headers
731 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
732 * and where b) the OUI of the SNAP header is 00:00:00 or
733 * 00:00:f8 - we need both because different APs appear to use
734 * different OUIs for some reason */
735 return (memcmp(hdr, &encaps_hdr, 5) == 0)
736 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
739 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
740 int level, int noise)
742 struct iw_quality wstats;
743 wstats.level = level - 0x95;
744 wstats.noise = noise - 0x95;
745 wstats.qual = (level > noise) ? (level - noise) : 0;
746 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
747 /* Update spy records */
748 wireless_spy_update(dev, mac, &wstats);
751 static void orinoco_stat_gather(struct net_device *dev,
753 struct hermes_rx_descriptor *desc)
755 struct orinoco_private *priv = netdev_priv(dev);
757 /* Using spy support with lots of Rx packets, like in an
758 * infrastructure (AP), will really slow down everything, because
759 * the MAC address must be compared to each entry of the spy list.
760 * If the user really asks for it (set some address in the
761 * spy list), we do it, but he will pay the price.
762 * Note that to get here, you need both WIRELESS_SPY
763 * compiled in AND some addresses in the list !!!
765 /* Note : gcc will optimise the whole section away if
766 * WIRELESS_SPY is not defined... - Jean II */
767 if (SPY_NUMBER(priv)) {
768 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
769 desc->signal, desc->silence);
774 * orinoco_rx_monitor - handle received monitor frames.
779 * desc rx descriptor of the frame
781 * Call context: interrupt
783 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
784 struct hermes_rx_descriptor *desc)
786 u32 hdrlen = 30; /* return full header by default */
792 struct orinoco_private *priv = netdev_priv(dev);
793 struct net_device_stats *stats = &priv->stats;
794 hermes_t *hw = &priv->hw;
796 len = le16_to_cpu(desc->data_len);
798 /* Determine the size of the header and the data */
799 fc = le16_to_cpu(desc->frame_ctl);
800 switch (fc & IEEE80211_FCTL_FTYPE) {
801 case IEEE80211_FTYPE_DATA:
802 if ((fc & IEEE80211_FCTL_TODS)
803 && (fc & IEEE80211_FCTL_FROMDS))
809 case IEEE80211_FTYPE_MGMT:
813 case IEEE80211_FTYPE_CTL:
814 switch (fc & IEEE80211_FCTL_STYPE) {
815 case IEEE80211_STYPE_PSPOLL:
816 case IEEE80211_STYPE_RTS:
817 case IEEE80211_STYPE_CFEND:
818 case IEEE80211_STYPE_CFENDACK:
821 case IEEE80211_STYPE_CTS:
822 case IEEE80211_STYPE_ACK:
828 /* Unknown frame type */
832 /* sanity check the length */
833 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
834 printk(KERN_DEBUG "%s: oversized monitor frame, "
835 "data length = %d\n", dev->name, datalen);
836 stats->rx_length_errors++;
840 skb = dev_alloc_skb(hdrlen + datalen);
842 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
847 /* Copy the 802.11 header to the skb */
848 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
849 skb_reset_mac_header(skb);
851 /* If any, copy the data from the card to the skb */
853 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
854 ALIGN(datalen, 2), rxfid,
855 HERMES_802_2_OFFSET);
857 printk(KERN_ERR "%s: error %d reading monitor frame\n",
864 skb->ip_summed = CHECKSUM_NONE;
865 skb->pkt_type = PACKET_OTHERHOST;
866 skb->protocol = cpu_to_be16(ETH_P_802_2);
869 stats->rx_bytes += skb->len;
875 dev_kfree_skb_irq(skb);
881 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
883 struct orinoco_private *priv = netdev_priv(dev);
884 struct net_device_stats *stats = &priv->stats;
885 struct iw_statistics *wstats = &priv->wstats;
886 struct sk_buff *skb = NULL;
889 struct hermes_rx_descriptor *desc;
890 struct orinoco_rx_data *rx_data;
893 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
896 "%s: Can't allocate space for RX descriptor\n",
901 rxfid = hermes_read_regn(hw, RXFID);
903 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
906 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
907 "Frame dropped.\n", dev->name, err);
911 status = le16_to_cpu(desc->status);
913 if (status & HERMES_RXSTAT_BADCRC) {
914 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
916 stats->rx_crc_errors++;
920 /* Handle frames in monitor mode */
921 if (priv->iw_mode == IW_MODE_MONITOR) {
922 orinoco_rx_monitor(dev, rxfid, desc);
926 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
927 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
929 wstats->discard.code++;
933 length = le16_to_cpu(desc->data_len);
936 if (length < 3) { /* No for even an 802.2 LLC header */
937 /* At least on Symbol firmware with PCF we get quite a
938 lot of these legitimately - Poll frames with no
942 if (length > IEEE80211_MAX_DATA_LEN) {
943 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
945 stats->rx_length_errors++;
949 /* Payload size does not include Michael MIC. Increase payload
950 * size to read it together with the data. */
951 if (status & HERMES_RXSTAT_MIC)
952 length += MICHAEL_MIC_LEN;
954 /* We need space for the packet data itself, plus an ethernet
955 header, plus 2 bytes so we can align the IP header on a
956 32bit boundary, plus 1 byte so we can read in odd length
957 packets from the card, which has an IO granularity of 16
959 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
961 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
966 /* We'll prepend the header, so reserve space for it. The worst
967 case is no decapsulation, when 802.3 header is prepended and
968 nothing is removed. 2 is for aligning the IP header. */
969 skb_reserve(skb, ETH_HLEN + 2);
971 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
972 ALIGN(length, 2), rxfid,
973 HERMES_802_2_OFFSET);
975 printk(KERN_ERR "%s: error %d reading frame. "
976 "Frame dropped.\n", dev->name, err);
980 /* Add desc and skb to rx queue */
981 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
983 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
987 rx_data->desc = desc;
989 list_add_tail(&rx_data->list, &priv->rx_list);
990 tasklet_schedule(&priv->rx_tasklet);
995 dev_kfree_skb_irq(skb);
1003 static void orinoco_rx(struct net_device *dev,
1004 struct hermes_rx_descriptor *desc,
1005 struct sk_buff *skb)
1007 struct orinoco_private *priv = netdev_priv(dev);
1008 struct net_device_stats *stats = &priv->stats;
1013 status = le16_to_cpu(desc->status);
1014 length = le16_to_cpu(desc->data_len);
1015 fc = le16_to_cpu(desc->frame_ctl);
1017 /* Calculate and check MIC */
1018 if (status & HERMES_RXSTAT_MIC) {
1019 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1020 HERMES_MIC_KEY_ID_SHIFT);
1021 u8 mic[MICHAEL_MIC_LEN];
1023 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1024 desc->addr3 : desc->addr2;
1026 /* Extract Michael MIC from payload */
1027 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1029 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1030 length -= MICHAEL_MIC_LEN;
1032 orinoco_mic(priv->rx_tfm_mic,
1033 priv->tkip_key[key_id].rx_mic,
1036 0, /* priority or QoS? */
1041 if (memcmp(mic, rxmic,
1043 union iwreq_data wrqu;
1044 struct iw_michaelmicfailure wxmic;
1046 printk(KERN_WARNING "%s: "
1047 "Invalid Michael MIC in data frame from %pM, "
1049 dev->name, src, key_id);
1051 /* TODO: update stats */
1053 /* Notify userspace */
1054 memset(&wxmic, 0, sizeof(wxmic));
1055 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1056 wxmic.flags |= (desc->addr1[0] & 1) ?
1057 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1058 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1059 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1061 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1064 memset(&wrqu, 0, sizeof(wrqu));
1065 wrqu.data.length = sizeof(wxmic);
1066 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1073 /* Handle decapsulation
1074 * In most cases, the firmware tell us about SNAP frames.
1075 * For some reason, the SNAP frames sent by LinkSys APs
1076 * are not properly recognised by most firmwares.
1077 * So, check ourselves */
1078 if (length >= ENCAPS_OVERHEAD &&
1079 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1080 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1081 is_ethersnap(skb->data))) {
1082 /* These indicate a SNAP within 802.2 LLC within
1083 802.11 frame which we'll need to de-encapsulate to
1084 the original EthernetII frame. */
1085 hdr = (struct ethhdr *)skb_push(skb,
1086 ETH_HLEN - ENCAPS_OVERHEAD);
1088 /* 802.3 frame - prepend 802.3 header as is */
1089 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1090 hdr->h_proto = htons(length);
1092 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
1093 if (fc & IEEE80211_FCTL_FROMDS)
1094 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
1096 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
1098 skb->protocol = eth_type_trans(skb, dev);
1099 skb->ip_summed = CHECKSUM_NONE;
1100 if (fc & IEEE80211_FCTL_TODS)
1101 skb->pkt_type = PACKET_OTHERHOST;
1103 /* Process the wireless stats if needed */
1104 orinoco_stat_gather(dev, skb, desc);
1106 /* Pass the packet to the networking stack */
1108 stats->rx_packets++;
1109 stats->rx_bytes += length;
1116 stats->rx_dropped++;
1119 static void orinoco_rx_isr_tasklet(unsigned long data)
1121 struct net_device *dev = (struct net_device *) data;
1122 struct orinoco_private *priv = netdev_priv(dev);
1123 struct orinoco_rx_data *rx_data, *temp;
1124 struct hermes_rx_descriptor *desc;
1125 struct sk_buff *skb;
1126 unsigned long flags;
1128 /* orinoco_rx requires the driver lock, and we also need to
1129 * protect priv->rx_list, so just hold the lock over the
1132 * If orinoco_lock fails, we've unplugged the card. In this
1133 * case just abort. */
1134 if (orinoco_lock(priv, &flags) != 0)
1137 /* extract desc and skb from queue */
1138 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1139 desc = rx_data->desc;
1141 list_del(&rx_data->list);
1144 orinoco_rx(dev, desc, skb);
1149 orinoco_unlock(priv, &flags);
1152 /********************************************************************/
1153 /* Rx path (info frames) */
1154 /********************************************************************/
1156 static void print_linkstatus(struct net_device *dev, u16 status)
1160 if (suppress_linkstatus)
1164 case HERMES_LINKSTATUS_NOT_CONNECTED:
1165 s = "Not Connected";
1167 case HERMES_LINKSTATUS_CONNECTED:
1170 case HERMES_LINKSTATUS_DISCONNECTED:
1173 case HERMES_LINKSTATUS_AP_CHANGE:
1176 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1177 s = "AP Out of Range";
1179 case HERMES_LINKSTATUS_AP_IN_RANGE:
1182 case HERMES_LINKSTATUS_ASSOC_FAILED:
1183 s = "Association Failed";
1189 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
1190 dev->name, s, status);
1193 /* Search scan results for requested BSSID, join it if found */
1194 static void orinoco_join_ap(struct work_struct *work)
1196 struct orinoco_private *priv =
1197 container_of(work, struct orinoco_private, join_work);
1198 struct net_device *dev = priv->ndev;
1199 struct hermes *hw = &priv->hw;
1201 unsigned long flags;
1205 } __attribute__ ((packed)) req;
1206 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1207 struct prism2_scan_apinfo *atom = NULL;
1213 /* Allocate buffer for scan results */
1214 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1218 if (orinoco_lock(priv, &flags) != 0)
1221 /* Sanity checks in case user changed something in the meantime */
1222 if (!priv->bssid_fixed)
1225 if (strlen(priv->desired_essid) == 0)
1228 /* Read scan results from the firmware */
1229 err = hermes_read_ltv(hw, USER_BAP,
1230 HERMES_RID_SCANRESULTSTABLE,
1231 MAX_SCAN_LEN, &len, buf);
1233 printk(KERN_ERR "%s: Cannot read scan results\n",
1238 len = HERMES_RECLEN_TO_BYTES(len);
1240 /* Go through the scan results looking for the channel of the AP
1241 * we were requested to join */
1242 for (; offset + atom_len <= len; offset += atom_len) {
1243 atom = (struct prism2_scan_apinfo *) (buf + offset);
1244 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1251 DEBUG(1, "%s: Requested AP not found in scan results\n",
1256 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1257 req.channel = atom->channel; /* both are little-endian */
1258 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1261 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1264 orinoco_unlock(priv, &flags);
1270 /* Send new BSSID to userspace */
1271 static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
1273 struct net_device *dev = priv->ndev;
1274 struct hermes *hw = &priv->hw;
1275 union iwreq_data wrqu;
1278 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1279 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1283 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1285 /* Send event to user space */
1286 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1289 static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1291 struct net_device *dev = priv->ndev;
1292 struct hermes *hw = &priv->hw;
1293 union iwreq_data wrqu;
1301 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1302 sizeof(buf), NULL, &buf);
1306 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1308 int rem = sizeof(buf) - (ie - &buf[0]);
1309 wrqu.data.length = ie[1] + 2;
1310 if (wrqu.data.length > rem)
1311 wrqu.data.length = rem;
1313 if (wrqu.data.length)
1314 /* Send event to user space */
1315 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1319 static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1321 struct net_device *dev = priv->ndev;
1322 struct hermes *hw = &priv->hw;
1323 union iwreq_data wrqu;
1325 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1331 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1332 sizeof(buf), NULL, &buf);
1336 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1338 int rem = sizeof(buf) - (ie - &buf[0]);
1339 wrqu.data.length = ie[1] + 2;
1340 if (wrqu.data.length > rem)
1341 wrqu.data.length = rem;
1343 if (wrqu.data.length)
1344 /* Send event to user space */
1345 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1349 static void orinoco_send_wevents(struct work_struct *work)
1351 struct orinoco_private *priv =
1352 container_of(work, struct orinoco_private, wevent_work);
1353 unsigned long flags;
1355 if (orinoco_lock(priv, &flags) != 0)
1358 orinoco_send_assocreqie_wevent(priv);
1359 orinoco_send_assocrespie_wevent(priv);
1360 orinoco_send_bssid_wevent(priv);
1362 orinoco_unlock(priv, &flags);
1365 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1367 struct orinoco_private *priv = netdev_priv(dev);
1372 } __attribute__ ((packed)) info;
1376 /* This is an answer to an INQUIRE command that we did earlier,
1377 * or an information "event" generated by the card
1378 * The controller return to us a pseudo frame containing
1379 * the information in question - Jean II */
1380 infofid = hermes_read_regn(hw, INFOFID);
1382 /* Read the info frame header - don't try too hard */
1383 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1386 printk(KERN_ERR "%s: error %d reading info frame. "
1387 "Frame dropped.\n", dev->name, err);
1391 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1392 type = le16_to_cpu(info.type);
1395 case HERMES_INQ_TALLIES: {
1396 struct hermes_tallies_frame tallies;
1397 struct iw_statistics *wstats = &priv->wstats;
1399 if (len > sizeof(tallies)) {
1400 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1402 len = sizeof(tallies);
1405 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1406 infofid, sizeof(info));
1410 /* Increment our various counters */
1411 /* wstats->discard.nwid - no wrong BSSID stuff */
1412 wstats->discard.code +=
1413 le16_to_cpu(tallies.RxWEPUndecryptable);
1414 if (len == sizeof(tallies))
1415 wstats->discard.code +=
1416 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1417 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1418 wstats->discard.misc +=
1419 le16_to_cpu(tallies.TxDiscardsWrongSA);
1420 wstats->discard.fragment +=
1421 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1422 wstats->discard.retries +=
1423 le16_to_cpu(tallies.TxRetryLimitExceeded);
1424 /* wstats->miss.beacon - no match */
1427 case HERMES_INQ_LINKSTATUS: {
1428 struct hermes_linkstatus linkstatus;
1432 if (priv->iw_mode == IW_MODE_MONITOR)
1435 if (len != sizeof(linkstatus)) {
1436 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1441 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1442 infofid, sizeof(info));
1445 newstatus = le16_to_cpu(linkstatus.linkstatus);
1447 /* Symbol firmware uses "out of range" to signal that
1448 * the hostscan frame can be requested. */
1449 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1450 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1451 priv->has_hostscan && priv->scan_inprogress) {
1452 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1456 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1457 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1458 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1461 netif_carrier_on(dev);
1462 else if (!ignore_disconnect)
1463 netif_carrier_off(dev);
1465 if (newstatus != priv->last_linkstatus) {
1466 priv->last_linkstatus = newstatus;
1467 print_linkstatus(dev, newstatus);
1468 /* The info frame contains only one word which is the
1469 * status (see hermes.h). The status is pretty boring
1470 * in itself, that's why we export the new BSSID...
1472 schedule_work(&priv->wevent_work);
1476 case HERMES_INQ_SCAN:
1477 if (!priv->scan_inprogress && priv->bssid_fixed &&
1478 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1479 schedule_work(&priv->join_work);
1483 case HERMES_INQ_HOSTSCAN:
1484 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1485 /* Result of a scanning. Contains information about
1486 * cells in the vicinity - Jean II */
1487 union iwreq_data wrqu;
1490 /* Scan is no longer in progress */
1491 priv->scan_inprogress = 0;
1495 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1500 /* Allocate buffer for results */
1501 buf = kmalloc(len, GFP_ATOMIC);
1503 /* No memory, so can't printk()... */
1506 /* Read scan data */
1507 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1508 infofid, sizeof(info));
1514 #ifdef ORINOCO_DEBUG
1517 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1518 for (i = 1; i < (len * 2); i++)
1519 printk(":%02X", buf[i]);
1522 #endif /* ORINOCO_DEBUG */
1524 if (orinoco_process_scan_results(priv, buf, len) == 0) {
1525 /* Send an empty event to user space.
1526 * We don't send the received data on the event because
1527 * it would require us to do complex transcoding, and
1528 * we want to minimise the work done in the irq handler
1529 * Use a request to extract the data - Jean II */
1530 wrqu.data.length = 0;
1531 wrqu.data.flags = 0;
1532 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1537 case HERMES_INQ_CHANNELINFO:
1539 struct agere_ext_scan_info *bss;
1541 if (!priv->scan_inprogress) {
1542 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1543 "len=%d\n", dev->name, len);
1547 /* An empty result indicates that the scan is complete */
1549 union iwreq_data wrqu;
1551 /* Scan is no longer in progress */
1552 priv->scan_inprogress = 0;
1554 wrqu.data.length = 0;
1555 wrqu.data.flags = 0;
1556 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1561 else if (len > sizeof(*bss)) {
1563 "%s: Ext scan results too large (%d bytes). "
1564 "Truncating results to %zd bytes.\n",
1565 dev->name, len, sizeof(*bss));
1567 } else if (len < (offsetof(struct agere_ext_scan_info,
1569 /* Drop this result now so we don't have to
1570 * keep checking later */
1572 "%s: Ext scan results too short (%d bytes)\n",
1577 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1581 /* Read scan data */
1582 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1583 infofid, sizeof(info));
1589 orinoco_add_ext_scan_result(priv, bss);
1594 case HERMES_INQ_SEC_STAT_AGERE:
1595 /* Security status (Agere specific) */
1596 /* Ignore this frame for now */
1597 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1601 printk(KERN_DEBUG "%s: Unknown information frame received: "
1602 "type 0x%04x, length %d\n", dev->name, type, len);
1603 /* We don't actually do anything about it */
1608 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1610 if (net_ratelimit())
1611 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1614 /********************************************************************/
1615 /* Internal hardware control routines */
1616 /********************************************************************/
1618 int __orinoco_up(struct net_device *dev)
1620 struct orinoco_private *priv = netdev_priv(dev);
1621 struct hermes *hw = &priv->hw;
1624 netif_carrier_off(dev); /* just to make sure */
1626 err = __orinoco_program_rids(dev);
1628 printk(KERN_ERR "%s: Error %d configuring card\n",
1633 /* Fire things up again */
1634 hermes_set_irqmask(hw, ORINOCO_INTEN);
1635 err = hermes_enable_port(hw, 0);
1637 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1642 netif_start_queue(dev);
1646 EXPORT_SYMBOL(__orinoco_up);
1648 int __orinoco_down(struct net_device *dev)
1650 struct orinoco_private *priv = netdev_priv(dev);
1651 struct hermes *hw = &priv->hw;
1654 netif_stop_queue(dev);
1656 if (!priv->hw_unavailable) {
1657 if (!priv->broken_disableport) {
1658 err = hermes_disable_port(hw, 0);
1660 /* Some firmwares (e.g. Intersil 1.3.x) seem
1661 * to have problems disabling the port, oh
1663 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1665 priv->broken_disableport = 1;
1668 hermes_set_irqmask(hw, 0);
1669 hermes_write_regn(hw, EVACK, 0xffff);
1672 /* firmware will have to reassociate */
1673 netif_carrier_off(dev);
1674 priv->last_linkstatus = 0xffff;
1678 EXPORT_SYMBOL(__orinoco_down);
1680 static int orinoco_allocate_fid(struct net_device *dev)
1682 struct orinoco_private *priv = netdev_priv(dev);
1683 struct hermes *hw = &priv->hw;
1686 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1687 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1688 /* Try workaround for old Symbol firmware bug */
1689 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1690 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1692 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1693 "(old Symbol firmware?). Work around %s\n",
1694 dev->name, err ? "failed!" : "ok.");
1700 int orinoco_reinit_firmware(struct net_device *dev)
1702 struct orinoco_private *priv = netdev_priv(dev);
1703 struct hermes *hw = &priv->hw;
1706 err = hermes_init(hw);
1707 if (priv->do_fw_download && !err) {
1708 err = orinoco_download(priv);
1710 priv->do_fw_download = 0;
1713 err = orinoco_allocate_fid(dev);
1717 EXPORT_SYMBOL(orinoco_reinit_firmware);
1719 static int __orinoco_program_rids(struct net_device *dev)
1721 struct orinoco_private *priv = netdev_priv(dev);
1722 hermes_t *hw = &priv->hw;
1724 struct hermes_idstring idbuf;
1726 /* Set the MAC address */
1727 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
1728 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
1730 printk(KERN_ERR "%s: Error %d setting MAC address\n",
1735 /* Set up the link mode */
1736 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
1739 printk(KERN_ERR "%s: Error %d setting port type\n",
1743 /* Set the channel/frequency */
1744 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
1745 err = hermes_write_wordrec(hw, USER_BAP,
1746 HERMES_RID_CNFOWNCHANNEL,
1749 printk(KERN_ERR "%s: Error %d setting channel %d\n",
1750 dev->name, err, priv->channel);
1755 if (priv->has_ibss) {
1758 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
1759 printk(KERN_WARNING "%s: This firmware requires an "
1760 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
1761 /* With wvlan_cs, in this case, we would crash.
1762 * hopefully, this driver will behave better...
1766 createibss = priv->createibss;
1769 err = hermes_write_wordrec(hw, USER_BAP,
1770 HERMES_RID_CNFCREATEIBSS,
1773 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
1779 /* Set the desired BSSID */
1780 err = __orinoco_hw_set_wap(priv);
1782 printk(KERN_ERR "%s: Error %d setting AP address\n",
1786 /* Set the desired ESSID */
1787 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
1788 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
1789 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1790 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
1791 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1794 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
1798 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
1799 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
1802 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
1807 /* Set the station name */
1808 idbuf.len = cpu_to_le16(strlen(priv->nick));
1809 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
1810 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
1811 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
1814 printk(KERN_ERR "%s: Error %d setting nickname\n",
1819 /* Set AP density */
1820 if (priv->has_sensitivity) {
1821 err = hermes_write_wordrec(hw, USER_BAP,
1822 HERMES_RID_CNFSYSTEMSCALE,
1825 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
1826 "Disabling sensitivity control\n",
1829 priv->has_sensitivity = 0;
1833 /* Set RTS threshold */
1834 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
1837 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
1842 /* Set fragmentation threshold or MWO robustness */
1844 err = hermes_write_wordrec(hw, USER_BAP,
1845 HERMES_RID_CNFMWOROBUST_AGERE,
1848 err = hermes_write_wordrec(hw, USER_BAP,
1849 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
1852 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
1858 err = __orinoco_hw_set_bitrate(priv);
1860 printk(KERN_ERR "%s: Error %d setting bitrate\n",
1865 /* Set power management */
1867 err = hermes_write_wordrec(hw, USER_BAP,
1868 HERMES_RID_CNFPMENABLED,
1871 printk(KERN_ERR "%s: Error %d setting up PM\n",
1876 err = hermes_write_wordrec(hw, USER_BAP,
1877 HERMES_RID_CNFMULTICASTRECEIVE,
1880 printk(KERN_ERR "%s: Error %d setting up PM\n",
1884 err = hermes_write_wordrec(hw, USER_BAP,
1885 HERMES_RID_CNFMAXSLEEPDURATION,
1888 printk(KERN_ERR "%s: Error %d setting up PM\n",
1892 err = hermes_write_wordrec(hw, USER_BAP,
1893 HERMES_RID_CNFPMHOLDOVERDURATION,
1896 printk(KERN_ERR "%s: Error %d setting up PM\n",
1902 /* Set preamble - only for Symbol so far... */
1903 if (priv->has_preamble) {
1904 err = hermes_write_wordrec(hw, USER_BAP,
1905 HERMES_RID_CNFPREAMBLE_SYMBOL,
1908 printk(KERN_ERR "%s: Error %d setting preamble\n",
1914 /* Set up encryption */
1915 if (priv->has_wep || priv->has_wpa) {
1916 err = __orinoco_hw_setup_enc(priv);
1918 printk(KERN_ERR "%s: Error %d activating encryption\n",
1924 if (priv->iw_mode == IW_MODE_MONITOR) {
1925 /* Enable monitor mode */
1926 dev->type = ARPHRD_IEEE80211;
1927 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1928 HERMES_TEST_MONITOR, 0, NULL);
1930 /* Disable monitor mode */
1931 dev->type = ARPHRD_ETHER;
1932 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
1933 HERMES_TEST_STOP, 0, NULL);
1938 /* Set promiscuity / multicast*/
1939 priv->promiscuous = 0;
1942 /* FIXME: what about netif_tx_lock */
1943 __orinoco_set_multicast_list(dev);
1948 /* FIXME: return int? */
1950 __orinoco_set_multicast_list(struct net_device *dev)
1952 struct orinoco_private *priv = netdev_priv(dev);
1954 int promisc, mc_count;
1956 /* The Hermes doesn't seem to have an allmulti mode, so we go
1957 * into promiscuous mode and let the upper levels deal. */
1958 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
1959 (dev->mc_count > MAX_MULTICAST(priv))) {
1964 mc_count = dev->mc_count;
1967 err = __orinoco_hw_set_multicast_list(priv, dev->mc_list, mc_count,
1971 /* This must be called from user context, without locks held - use
1972 * schedule_work() */
1973 static void orinoco_reset(struct work_struct *work)
1975 struct orinoco_private *priv =
1976 container_of(work, struct orinoco_private, reset_work);
1977 struct net_device *dev = priv->ndev;
1978 struct hermes *hw = &priv->hw;
1980 unsigned long flags;
1982 if (orinoco_lock(priv, &flags) != 0)
1983 /* When the hardware becomes available again, whatever
1984 * detects that is responsible for re-initializing
1985 * it. So no need for anything further */
1988 netif_stop_queue(dev);
1990 /* Shut off interrupts. Depending on what state the hardware
1991 * is in, this might not work, but we'll try anyway */
1992 hermes_set_irqmask(hw, 0);
1993 hermes_write_regn(hw, EVACK, 0xffff);
1995 priv->hw_unavailable++;
1996 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
1997 netif_carrier_off(dev);
1999 orinoco_unlock(priv, &flags);
2001 /* Scanning support: Cleanup of driver struct */
2002 orinoco_clear_scan_results(priv, 0);
2003 priv->scan_inprogress = 0;
2005 if (priv->hard_reset) {
2006 err = (*priv->hard_reset)(priv);
2008 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2009 "performing hard reset\n", dev->name, err);
2014 err = orinoco_reinit_firmware(dev);
2016 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2021 /* This has to be called from user context */
2022 spin_lock_irq(&priv->lock);
2024 priv->hw_unavailable--;
2026 /* priv->open or priv->hw_unavailable might have changed while
2027 * we dropped the lock */
2028 if (priv->open && (!priv->hw_unavailable)) {
2029 err = __orinoco_up(dev);
2031 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2034 dev->trans_start = jiffies;
2037 spin_unlock_irq(&priv->lock);
2041 hermes_set_irqmask(hw, 0);
2042 netif_device_detach(dev);
2043 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2046 /********************************************************************/
2047 /* Interrupt handler */
2048 /********************************************************************/
2050 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2052 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2055 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2057 /* This seems to happen a fair bit under load, but ignoring it
2058 seems to work fine...*/
2059 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2063 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2065 struct net_device *dev = dev_id;
2066 struct orinoco_private *priv = netdev_priv(dev);
2067 hermes_t *hw = &priv->hw;
2068 int count = MAX_IRQLOOPS_PER_IRQ;
2070 /* These are used to detect a runaway interrupt situation.
2072 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2073 * we panic and shut down the hardware
2075 /* jiffies value the last time we were called */
2076 static int last_irq_jiffy; /* = 0 */
2077 static int loops_this_jiffy; /* = 0 */
2078 unsigned long flags;
2080 if (orinoco_lock(priv, &flags) != 0) {
2081 /* If hw is unavailable - we don't know if the irq was
2086 evstat = hermes_read_regn(hw, EVSTAT);
2087 events = evstat & hw->inten;
2089 orinoco_unlock(priv, &flags);
2093 if (jiffies != last_irq_jiffy)
2094 loops_this_jiffy = 0;
2095 last_irq_jiffy = jiffies;
2097 while (events && count--) {
2098 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2099 printk(KERN_WARNING "%s: IRQ handler is looping too "
2100 "much! Resetting.\n", dev->name);
2101 /* Disable interrupts for now */
2102 hermes_set_irqmask(hw, 0);
2103 schedule_work(&priv->reset_work);
2107 /* Check the card hasn't been removed */
2108 if (!hermes_present(hw)) {
2109 DEBUG(0, "orinoco_interrupt(): card removed\n");
2113 if (events & HERMES_EV_TICK)
2114 __orinoco_ev_tick(dev, hw);
2115 if (events & HERMES_EV_WTERR)
2116 __orinoco_ev_wterr(dev, hw);
2117 if (events & HERMES_EV_INFDROP)
2118 __orinoco_ev_infdrop(dev, hw);
2119 if (events & HERMES_EV_INFO)
2120 __orinoco_ev_info(dev, hw);
2121 if (events & HERMES_EV_RX)
2122 __orinoco_ev_rx(dev, hw);
2123 if (events & HERMES_EV_TXEXC)
2124 __orinoco_ev_txexc(dev, hw);
2125 if (events & HERMES_EV_TX)
2126 __orinoco_ev_tx(dev, hw);
2127 if (events & HERMES_EV_ALLOC)
2128 __orinoco_ev_alloc(dev, hw);
2130 hermes_write_regn(hw, EVACK, evstat);
2132 evstat = hermes_read_regn(hw, EVSTAT);
2133 events = evstat & hw->inten;
2136 orinoco_unlock(priv, &flags);
2139 EXPORT_SYMBOL(orinoco_interrupt);
2141 /********************************************************************/
2142 /* Power management */
2143 /********************************************************************/
2144 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2145 static int orinoco_pm_notifier(struct notifier_block *notifier,
2146 unsigned long pm_event,
2149 struct orinoco_private *priv = container_of(notifier,
2150 struct orinoco_private,
2153 /* All we need to do is cache the firmware before suspend, and
2154 * release it when we come out.
2156 * Only need to do this if we're downloading firmware. */
2157 if (!priv->do_fw_download)
2161 case PM_HIBERNATION_PREPARE:
2162 case PM_SUSPEND_PREPARE:
2163 orinoco_cache_fw(priv, 0);
2166 case PM_POST_RESTORE:
2167 /* Restore from hibernation failed. We need to clean
2168 * up in exactly the same way, so fall through. */
2169 case PM_POST_HIBERNATION:
2170 case PM_POST_SUSPEND:
2171 orinoco_uncache_fw(priv);
2174 case PM_RESTORE_PREPARE:
2181 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2182 #define orinoco_pm_notifier NULL
2185 /********************************************************************/
2186 /* Initialization */
2187 /********************************************************************/
2190 u16 id, variant, major, minor;
2191 } __attribute__ ((packed));
2193 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2195 if (nic_id->id < 0x8000)
2196 return FIRMWARE_TYPE_AGERE;
2197 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2198 return FIRMWARE_TYPE_SYMBOL;
2200 return FIRMWARE_TYPE_INTERSIL;
2203 /* Set priv->firmware type, determine firmware properties */
2204 static int determine_firmware(struct net_device *dev)
2206 struct orinoco_private *priv = netdev_priv(dev);
2207 hermes_t *hw = &priv->hw;
2209 struct comp_id nic_id, sta_id;
2210 unsigned int firmver;
2211 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2213 /* Get the hardware version */
2214 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2216 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2221 le16_to_cpus(&nic_id.id);
2222 le16_to_cpus(&nic_id.variant);
2223 le16_to_cpus(&nic_id.major);
2224 le16_to_cpus(&nic_id.minor);
2225 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2226 dev->name, nic_id.id, nic_id.variant,
2227 nic_id.major, nic_id.minor);
2229 priv->firmware_type = determine_firmware_type(&nic_id);
2231 /* Get the firmware version */
2232 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2234 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2239 le16_to_cpus(&sta_id.id);
2240 le16_to_cpus(&sta_id.variant);
2241 le16_to_cpus(&sta_id.major);
2242 le16_to_cpus(&sta_id.minor);
2243 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2244 dev->name, sta_id.id, sta_id.variant,
2245 sta_id.major, sta_id.minor);
2247 switch (sta_id.id) {
2249 printk(KERN_ERR "%s: Primary firmware is active\n",
2253 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2256 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2257 case 0x21: /* Symbol Spectrum24 Trilogy */
2260 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2265 /* Default capabilities */
2266 priv->has_sensitivity = 1;
2268 priv->has_preamble = 0;
2269 priv->has_port3 = 1;
2272 priv->has_big_wep = 0;
2273 priv->has_alt_txcntl = 0;
2274 priv->has_ext_scan = 0;
2276 priv->do_fw_download = 0;
2278 /* Determine capabilities from the firmware version */
2279 switch (priv->firmware_type) {
2280 case FIRMWARE_TYPE_AGERE:
2281 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2282 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2283 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2284 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2286 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2288 priv->has_ibss = (firmver >= 0x60006);
2289 priv->has_wep = (firmver >= 0x40020);
2290 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2291 Gold cards from the others? */
2292 priv->has_mwo = (firmver >= 0x60000);
2293 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2294 priv->ibss_port = 1;
2295 priv->has_hostscan = (firmver >= 0x8000a);
2296 priv->do_fw_download = 1;
2297 priv->broken_monitor = (firmver >= 0x80000);
2298 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
2299 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
2300 priv->has_wpa = (firmver >= 0x9002a);
2301 /* Tested with Agere firmware :
2302 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2303 * Tested CableTron firmware : 4.32 => Anton */
2305 case FIRMWARE_TYPE_SYMBOL:
2306 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2307 /* Intel MAC : 00:02:B3:* */
2308 /* 3Com MAC : 00:50:DA:* */
2309 memset(tmp, 0, sizeof(tmp));
2310 /* Get the Symbol firmware version */
2311 err = hermes_read_ltv(hw, USER_BAP,
2312 HERMES_RID_SECONDARYVERSION_SYMBOL,
2313 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2316 "%s: Error %d reading Symbol firmware info. "
2317 "Wildly guessing capabilities...\n",
2322 /* The firmware revision is a string, the format is
2323 * something like : "V2.20-01".
2324 * Quick and dirty parsing... - Jean II
2326 firmver = ((tmp[1] - '0') << 16)
2327 | ((tmp[3] - '0') << 12)
2328 | ((tmp[4] - '0') << 8)
2329 | ((tmp[6] - '0') << 4)
2332 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2335 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2338 priv->has_ibss = (firmver >= 0x20000);
2339 priv->has_wep = (firmver >= 0x15012);
2340 priv->has_big_wep = (firmver >= 0x20000);
2341 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2342 (firmver >= 0x29000 && firmver < 0x30000) ||
2344 priv->has_preamble = (firmver >= 0x20000);
2345 priv->ibss_port = 4;
2347 /* Symbol firmware is found on various cards, but
2348 * there has been no attempt to check firmware
2349 * download on non-spectrum_cs based cards.
2351 * Given that the Agere firmware download works
2352 * differently, we should avoid doing a firmware
2353 * download with the Symbol algorithm on non-spectrum
2356 * For now we can identify a spectrum_cs based card
2357 * because it has a firmware reset function.
2359 priv->do_fw_download = (priv->stop_fw != NULL);
2361 priv->broken_disableport = (firmver == 0x25013) ||
2362 (firmver >= 0x30000 && firmver <= 0x31000);
2363 priv->has_hostscan = (firmver >= 0x31001) ||
2364 (firmver >= 0x29057 && firmver < 0x30000);
2365 /* Tested with Intel firmware : 0x20015 => Jean II */
2366 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2368 case FIRMWARE_TYPE_INTERSIL:
2369 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2370 * Samsung, Compaq 100/200 and Proxim are slightly
2371 * different and less well tested */
2372 /* D-Link MAC : 00:40:05:* */
2373 /* Addtron MAC : 00:90:D1:* */
2374 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2375 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2378 firmver = ((unsigned long)sta_id.major << 16) |
2379 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2381 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2382 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2383 priv->has_pm = (firmver >= 0x000700);
2384 priv->has_hostscan = (firmver >= 0x010301);
2386 if (firmver >= 0x000800)
2387 priv->ibss_port = 0;
2389 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2390 "than v0.8.x - several features not supported\n",
2392 priv->ibss_port = 1;
2396 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2402 static int orinoco_init(struct net_device *dev)
2404 struct orinoco_private *priv = netdev_priv(dev);
2405 hermes_t *hw = &priv->hw;
2407 struct hermes_idstring nickbuf;
2411 /* No need to lock, the hw_unavailable flag is already set in
2412 * alloc_orinocodev() */
2413 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
2415 /* Initialize the firmware */
2416 err = hermes_init(hw);
2418 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2423 err = determine_firmware(dev);
2425 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2430 if (priv->do_fw_download) {
2431 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
2432 orinoco_cache_fw(priv, 0);
2435 err = orinoco_download(priv);
2437 priv->do_fw_download = 0;
2439 /* Check firmware version again */
2440 err = determine_firmware(dev);
2442 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2448 if (priv->has_port3)
2449 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
2452 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2454 if (priv->has_wep) {
2455 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
2456 priv->has_big_wep ? "104" : "40");
2458 if (priv->has_wpa) {
2459 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
2460 if (orinoco_mic_init(priv)) {
2461 printk(KERN_ERR "%s: Failed to setup MIC crypto "
2462 "algorithm. Disabling WPA support\n", dev->name);
2467 /* Now we have the firmware capabilities, allocate appropiate
2468 * sized scan buffers */
2469 if (orinoco_bss_data_allocate(priv))
2471 orinoco_bss_data_init(priv);
2473 /* Get the MAC address */
2474 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2475 ETH_ALEN, NULL, dev->dev_addr);
2477 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2482 printk(KERN_DEBUG "%s: MAC address %pM\n",
2483 dev->name, dev->dev_addr);
2485 /* Get the station name */
2486 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2487 sizeof(nickbuf), &reclen, &nickbuf);
2489 printk(KERN_ERR "%s: failed to read station name\n",
2494 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2496 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2497 memcpy(priv->nick, &nickbuf.val, len);
2498 priv->nick[len] = '\0';
2500 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2502 err = orinoco_allocate_fid(dev);
2504 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2509 /* Get allowed channels */
2510 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2511 &priv->channel_mask);
2513 printk(KERN_ERR "%s: failed to read channel list!\n",
2518 /* Get initial AP density */
2519 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2521 if (err || priv->ap_density < 1 || priv->ap_density > 3)
2522 priv->has_sensitivity = 0;
2524 /* Get initial RTS threshold */
2525 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2528 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2533 /* Get initial fragmentation settings */
2535 err = hermes_read_wordrec(hw, USER_BAP,
2536 HERMES_RID_CNFMWOROBUST_AGERE,
2539 err = hermes_read_wordrec(hw, USER_BAP,
2540 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2541 &priv->frag_thresh);
2543 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2548 /* Power management setup */
2552 err = hermes_read_wordrec(hw, USER_BAP,
2553 HERMES_RID_CNFMAXSLEEPDURATION,
2556 printk(KERN_ERR "%s: failed to read power management period!\n",
2560 err = hermes_read_wordrec(hw, USER_BAP,
2561 HERMES_RID_CNFPMHOLDOVERDURATION,
2564 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2570 /* Preamble setup */
2571 if (priv->has_preamble) {
2572 err = hermes_read_wordrec(hw, USER_BAP,
2573 HERMES_RID_CNFPREAMBLE_SYMBOL,
2579 /* Set up the default configuration */
2580 priv->iw_mode = IW_MODE_INFRA;
2581 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2582 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
2583 set_port_type(priv);
2584 priv->channel = 0; /* use firmware default */
2586 priv->promiscuous = 0;
2587 priv->encode_alg = IW_ENCODE_ALG_NONE;
2589 priv->wpa_enabled = 0;
2590 priv->tkip_cm_active = 0;
2592 priv->wpa_ie_len = 0;
2593 priv->wpa_ie = NULL;
2595 /* Make the hardware available, as long as it hasn't been
2596 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2597 spin_lock_irq(&priv->lock);
2598 priv->hw_unavailable--;
2599 spin_unlock_irq(&priv->lock);
2601 printk(KERN_DEBUG "%s: ready\n", dev->name);
2607 static const struct net_device_ops orinoco_netdev_ops = {
2608 .ndo_init = orinoco_init,
2609 .ndo_open = orinoco_open,
2610 .ndo_stop = orinoco_stop,
2611 .ndo_start_xmit = orinoco_xmit,
2612 .ndo_set_multicast_list = orinoco_set_multicast_list,
2613 .ndo_change_mtu = orinoco_change_mtu,
2614 .ndo_tx_timeout = orinoco_tx_timeout,
2615 .ndo_get_stats = orinoco_get_stats,
2619 *alloc_orinocodev(int sizeof_card,
2620 struct device *device,
2621 int (*hard_reset)(struct orinoco_private *),
2622 int (*stop_fw)(struct orinoco_private *, int))
2624 struct net_device *dev;
2625 struct orinoco_private *priv;
2627 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2630 priv = netdev_priv(dev);
2633 priv->card = (void *)((unsigned long)priv
2634 + sizeof(struct orinoco_private));
2639 /* Setup / override net_device fields */
2640 dev->netdev_ops = &orinoco_netdev_ops;
2641 dev->watchdog_timeo = HZ; /* 1 second timeout */
2642 dev->ethtool_ops = &orinoco_ethtool_ops;
2643 dev->wireless_handlers = &orinoco_handler_def;
2645 priv->wireless_data.spy_data = &priv->spy_data;
2646 dev->wireless_data = &priv->wireless_data;
2648 /* we use the default eth_mac_addr for setting the MAC addr */
2650 /* Reserve space in skb for the SNAP header */
2651 dev->hard_header_len += ENCAPS_OVERHEAD;
2653 /* Set up default callbacks */
2654 priv->hard_reset = hard_reset;
2655 priv->stop_fw = stop_fw;
2657 spin_lock_init(&priv->lock);
2659 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2660 * before anything else touches the
2662 INIT_WORK(&priv->reset_work, orinoco_reset);
2663 INIT_WORK(&priv->join_work, orinoco_join_ap);
2664 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2666 INIT_LIST_HEAD(&priv->rx_list);
2667 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
2668 (unsigned long) dev);
2670 netif_carrier_off(dev);
2671 priv->last_linkstatus = 0xffff;
2673 priv->cached_pri_fw = NULL;
2674 priv->cached_fw = NULL;
2676 /* Register PM notifiers */
2677 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
2678 register_pm_notifier(&priv->pm_notifier);
2682 EXPORT_SYMBOL(alloc_orinocodev);
2684 void free_orinocodev(struct net_device *dev)
2686 struct orinoco_private *priv = netdev_priv(dev);
2687 struct orinoco_rx_data *rx_data, *temp;
2689 /* If the tasklet is scheduled when we call tasklet_kill it
2690 * will run one final time. However the tasklet will only
2691 * drain priv->rx_list if the hw is still available. */
2692 tasklet_kill(&priv->rx_tasklet);
2694 /* Explicitly drain priv->rx_list */
2695 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
2696 list_del(&rx_data->list);
2698 dev_kfree_skb(rx_data->skb);
2699 kfree(rx_data->desc);
2703 unregister_pm_notifier(&priv->pm_notifier);
2704 orinoco_uncache_fw(priv);
2706 priv->wpa_ie_len = 0;
2707 kfree(priv->wpa_ie);
2708 orinoco_mic_free(priv);
2709 orinoco_bss_data_free(priv);
2712 EXPORT_SYMBOL(free_orinocodev);
2714 /********************************************************************/
2715 /* Wireless extensions */
2716 /********************************************************************/
2718 static int orinoco_ioctl_getname(struct net_device *dev,
2719 struct iw_request_info *info,
2723 struct orinoco_private *priv = netdev_priv(dev);
2727 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
2729 if (!err && (numrates > 2))
2730 strcpy(name, "IEEE 802.11b");
2732 strcpy(name, "IEEE 802.11-DS");
2737 static int orinoco_ioctl_setwap(struct net_device *dev,
2738 struct iw_request_info *info,
2739 struct sockaddr *ap_addr,
2742 struct orinoco_private *priv = netdev_priv(dev);
2743 int err = -EINPROGRESS; /* Call commit handler */
2744 unsigned long flags;
2745 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2746 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2748 if (orinoco_lock(priv, &flags) != 0)
2751 /* Enable automatic roaming - no sanity checks are needed */
2752 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
2753 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
2754 priv->bssid_fixed = 0;
2755 memset(priv->desired_bssid, 0, ETH_ALEN);
2757 /* "off" means keep existing connection */
2758 if (ap_addr->sa_data[0] == 0) {
2759 __orinoco_hw_set_wap(priv);
2765 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
2766 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
2767 "support manual roaming\n",
2773 if (priv->iw_mode != IW_MODE_INFRA) {
2774 printk(KERN_WARNING "%s: Manual roaming supported only in "
2775 "managed mode\n", dev->name);
2780 /* Intersil firmware hangs without Desired ESSID */
2781 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
2782 strlen(priv->desired_essid) == 0) {
2783 printk(KERN_WARNING "%s: Desired ESSID must be set for "
2784 "manual roaming\n", dev->name);
2789 /* Finally, enable manual roaming */
2790 priv->bssid_fixed = 1;
2791 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
2794 orinoco_unlock(priv, &flags);
2798 static int orinoco_ioctl_getwap(struct net_device *dev,
2799 struct iw_request_info *info,
2800 struct sockaddr *ap_addr,
2803 struct orinoco_private *priv = netdev_priv(dev);
2805 hermes_t *hw = &priv->hw;
2807 unsigned long flags;
2809 if (orinoco_lock(priv, &flags) != 0)
2812 ap_addr->sa_family = ARPHRD_ETHER;
2813 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
2814 ETH_ALEN, NULL, ap_addr->sa_data);
2816 orinoco_unlock(priv, &flags);
2821 static int orinoco_ioctl_setmode(struct net_device *dev,
2822 struct iw_request_info *info,
2826 struct orinoco_private *priv = netdev_priv(dev);
2827 int err = -EINPROGRESS; /* Call commit handler */
2828 unsigned long flags;
2830 if (priv->iw_mode == *mode)
2833 if (orinoco_lock(priv, &flags) != 0)
2838 if (!priv->has_ibss && !priv->has_port3)
2845 case IW_MODE_MONITOR:
2846 if (priv->broken_monitor && !force_monitor) {
2847 printk(KERN_WARNING "%s: Monitor mode support is "
2848 "buggy in this firmware, not enabling\n",
2859 if (err == -EINPROGRESS) {
2860 priv->iw_mode = *mode;
2861 set_port_type(priv);
2864 orinoco_unlock(priv, &flags);
2869 static int orinoco_ioctl_getmode(struct net_device *dev,
2870 struct iw_request_info *info,
2874 struct orinoco_private *priv = netdev_priv(dev);
2876 *mode = priv->iw_mode;
2880 static int orinoco_ioctl_getiwrange(struct net_device *dev,
2881 struct iw_request_info *info,
2882 struct iw_point *rrq,
2885 struct orinoco_private *priv = netdev_priv(dev);
2887 struct iw_range *range = (struct iw_range *) extra;
2891 rrq->length = sizeof(struct iw_range);
2892 memset(range, 0, sizeof(struct iw_range));
2894 range->we_version_compiled = WIRELESS_EXT;
2895 range->we_version_source = 22;
2897 /* Set available channels/frequencies */
2898 range->num_channels = NUM_CHANNELS;
2900 for (i = 0; i < NUM_CHANNELS; i++) {
2901 if (priv->channel_mask & (1 << i)) {
2902 range->freq[k].i = i + 1;
2903 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
2905 range->freq[k].e = 1;
2909 if (k >= IW_MAX_FREQUENCIES)
2912 range->num_frequency = k;
2913 range->sensitivity = 3;
2915 if (priv->has_wep) {
2916 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
2917 range->encoding_size[0] = SMALL_KEY_SIZE;
2918 range->num_encoding_sizes = 1;
2920 if (priv->has_big_wep) {
2921 range->encoding_size[1] = LARGE_KEY_SIZE;
2922 range->num_encoding_sizes = 2;
2927 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
2929 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
2930 /* Quality stats meaningless in ad-hoc mode */
2932 range->max_qual.qual = 0x8b - 0x2f;
2933 range->max_qual.level = 0x2f - 0x95 - 1;
2934 range->max_qual.noise = 0x2f - 0x95 - 1;
2935 /* Need to get better values */
2936 range->avg_qual.qual = 0x24;
2937 range->avg_qual.level = 0xC2;
2938 range->avg_qual.noise = 0x9E;
2941 err = orinoco_hw_get_bitratelist(priv, &numrates,
2942 range->bitrate, IW_MAX_BITRATES);
2945 range->num_bitrates = numrates;
2947 /* Set an indication of the max TCP throughput in bit/s that we can
2948 * expect using this interface. May be use for QoS stuff...
2951 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
2953 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2956 range->max_rts = 2347;
2957 range->min_frag = 256;
2958 range->max_frag = 2346;
2961 range->max_pmp = 65535000;
2963 range->max_pmt = 65535 * 1000; /* ??? */
2964 range->pmp_flags = IW_POWER_PERIOD;
2965 range->pmt_flags = IW_POWER_TIMEOUT;
2966 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
2967 IW_POWER_UNICAST_R);
2969 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
2970 range->retry_flags = IW_RETRY_LIMIT;
2971 range->r_time_flags = IW_RETRY_LIFETIME;
2972 range->min_retry = 0;
2973 range->max_retry = 65535; /* ??? */
2974 range->min_r_time = 0;
2975 range->max_r_time = 65535 * 1000; /* ??? */
2977 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2978 range->scan_capa = IW_SCAN_CAPA_ESSID;
2980 range->scan_capa = IW_SCAN_CAPA_NONE;
2982 /* Event capability (kernel) */
2983 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
2984 /* Event capability (driver) */
2985 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
2986 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
2987 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
2988 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
2993 static int orinoco_ioctl_setiwencode(struct net_device *dev,
2994 struct iw_request_info *info,
2995 struct iw_point *erq,
2998 struct orinoco_private *priv = netdev_priv(dev);
2999 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3000 int setindex = priv->tx_key;
3001 int encode_alg = priv->encode_alg;
3002 int restricted = priv->wep_restrict;
3004 int err = -EINPROGRESS; /* Call commit handler */
3005 unsigned long flags;
3011 /* We actually have a key to set - check its length */
3012 if (erq->length > LARGE_KEY_SIZE)
3015 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
3019 if (orinoco_lock(priv, &flags) != 0)
3022 /* Clear any TKIP key we have */
3023 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3024 (void) orinoco_clear_tkip_key(priv, setindex);
3026 if (erq->length > 0) {
3027 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3028 index = priv->tx_key;
3030 /* Adjust key length to a supported value */
3031 if (erq->length > SMALL_KEY_SIZE)
3032 xlen = LARGE_KEY_SIZE;
3033 else if (erq->length > 0)
3034 xlen = SMALL_KEY_SIZE;
3038 /* Switch on WEP if off */
3039 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
3041 encode_alg = IW_ENCODE_ALG_WEP;
3044 /* Important note : if the user do "iwconfig eth0 enc off",
3045 * we will arrive there with an index of -1. This is valid
3046 * but need to be taken care off... Jean II */
3047 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3048 if ((index != -1) || (erq->flags == 0)) {
3053 /* Set the index : Check that the key is valid */
3054 if (priv->keys[index].len == 0) {
3062 if (erq->flags & IW_ENCODE_DISABLED)
3063 encode_alg = IW_ENCODE_ALG_NONE;
3064 if (erq->flags & IW_ENCODE_OPEN)
3066 if (erq->flags & IW_ENCODE_RESTRICTED)
3069 if (erq->pointer && erq->length > 0) {
3070 priv->keys[index].len = cpu_to_le16(xlen);
3071 memset(priv->keys[index].data, 0,
3072 sizeof(priv->keys[index].data));
3073 memcpy(priv->keys[index].data, keybuf, erq->length);
3075 priv->tx_key = setindex;
3077 /* Try fast key change if connected and only keys are changed */
3078 if ((priv->encode_alg == encode_alg) &&
3079 (priv->wep_restrict == restricted) &&
3080 netif_carrier_ok(dev)) {
3081 err = __orinoco_hw_setup_wepkeys(priv);
3082 /* No need to commit if successful */
3086 priv->encode_alg = encode_alg;
3087 priv->wep_restrict = restricted;
3090 orinoco_unlock(priv, &flags);
3095 static int orinoco_ioctl_getiwencode(struct net_device *dev,
3096 struct iw_request_info *info,
3097 struct iw_point *erq,
3100 struct orinoco_private *priv = netdev_priv(dev);
3101 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3103 unsigned long flags;
3108 if (orinoco_lock(priv, &flags) != 0)
3111 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3112 index = priv->tx_key;
3115 if (!priv->encode_alg)
3116 erq->flags |= IW_ENCODE_DISABLED;
3117 erq->flags |= index + 1;
3119 if (priv->wep_restrict)
3120 erq->flags |= IW_ENCODE_RESTRICTED;
3122 erq->flags |= IW_ENCODE_OPEN;
3124 xlen = le16_to_cpu(priv->keys[index].len);
3128 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3130 orinoco_unlock(priv, &flags);
3134 static int orinoco_ioctl_setessid(struct net_device *dev,
3135 struct iw_request_info *info,
3136 struct iw_point *erq,
3139 struct orinoco_private *priv = netdev_priv(dev);
3140 unsigned long flags;
3142 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3143 * anyway... - Jean II */
3145 /* Hum... Should not use Wireless Extension constant (may change),
3146 * should use our own... - Jean II */
3147 if (erq->length > IW_ESSID_MAX_SIZE)
3150 if (orinoco_lock(priv, &flags) != 0)
3153 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3154 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3156 /* If not ANY, get the new ESSID */
3158 memcpy(priv->desired_essid, essidbuf, erq->length);
3160 orinoco_unlock(priv, &flags);
3162 return -EINPROGRESS; /* Call commit handler */
3165 static int orinoco_ioctl_getessid(struct net_device *dev,
3166 struct iw_request_info *info,
3167 struct iw_point *erq,
3170 struct orinoco_private *priv = netdev_priv(dev);
3173 unsigned long flags;
3175 if (netif_running(dev)) {
3176 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3181 if (orinoco_lock(priv, &flags) != 0)
3183 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3184 erq->length = strlen(priv->desired_essid);
3185 orinoco_unlock(priv, &flags);
3193 static int orinoco_ioctl_setnick(struct net_device *dev,
3194 struct iw_request_info *info,
3195 struct iw_point *nrq,
3198 struct orinoco_private *priv = netdev_priv(dev);
3199 unsigned long flags;
3201 if (nrq->length > IW_ESSID_MAX_SIZE)
3204 if (orinoco_lock(priv, &flags) != 0)
3207 memset(priv->nick, 0, sizeof(priv->nick));
3208 memcpy(priv->nick, nickbuf, nrq->length);
3210 orinoco_unlock(priv, &flags);
3212 return -EINPROGRESS; /* Call commit handler */
3215 static int orinoco_ioctl_getnick(struct net_device *dev,
3216 struct iw_request_info *info,
3217 struct iw_point *nrq,
3220 struct orinoco_private *priv = netdev_priv(dev);
3221 unsigned long flags;
3223 if (orinoco_lock(priv, &flags) != 0)
3226 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3227 orinoco_unlock(priv, &flags);
3229 nrq->length = strlen(priv->nick);
3234 static int orinoco_ioctl_setfreq(struct net_device *dev,
3235 struct iw_request_info *info,
3236 struct iw_freq *frq,
3239 struct orinoco_private *priv = netdev_priv(dev);
3241 unsigned long flags;
3242 int err = -EINPROGRESS; /* Call commit handler */
3244 /* In infrastructure mode the AP sets the channel */
3245 if (priv->iw_mode == IW_MODE_INFRA)
3248 if ((frq->e == 0) && (frq->m <= 1000)) {
3249 /* Setting by channel number */
3252 /* Setting by frequency */
3256 /* Calculate denominator to rescale to MHz */
3257 for (i = 0; i < (6 - frq->e); i++)
3260 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
3263 if ((chan < 1) || (chan > NUM_CHANNELS) ||
3264 !(priv->channel_mask & (1 << (chan-1))))
3267 if (orinoco_lock(priv, &flags) != 0)
3270 priv->channel = chan;
3271 if (priv->iw_mode == IW_MODE_MONITOR) {
3272 /* Fast channel change - no commit if successful */
3273 hermes_t *hw = &priv->hw;
3274 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3275 HERMES_TEST_SET_CHANNEL,
3278 orinoco_unlock(priv, &flags);
3283 static int orinoco_ioctl_getfreq(struct net_device *dev,
3284 struct iw_request_info *info,
3285 struct iw_freq *frq,
3288 struct orinoco_private *priv = netdev_priv(dev);
3291 /* Locking done in there */
3292 tmp = orinoco_hw_get_freq(priv);
3296 frq->m = tmp * 100000;
3302 static int orinoco_ioctl_getsens(struct net_device *dev,
3303 struct iw_request_info *info,
3304 struct iw_param *srq,
3307 struct orinoco_private *priv = netdev_priv(dev);
3308 hermes_t *hw = &priv->hw;
3311 unsigned long flags;
3313 if (!priv->has_sensitivity)
3316 if (orinoco_lock(priv, &flags) != 0)
3318 err = hermes_read_wordrec(hw, USER_BAP,
3319 HERMES_RID_CNFSYSTEMSCALE, &val);
3320 orinoco_unlock(priv, &flags);
3326 srq->fixed = 0; /* auto */
3331 static int orinoco_ioctl_setsens(struct net_device *dev,
3332 struct iw_request_info *info,
3333 struct iw_param *srq,
3336 struct orinoco_private *priv = netdev_priv(dev);
3337 int val = srq->value;
3338 unsigned long flags;
3340 if (!priv->has_sensitivity)
3343 if ((val < 1) || (val > 3))
3346 if (orinoco_lock(priv, &flags) != 0)
3348 priv->ap_density = val;
3349 orinoco_unlock(priv, &flags);
3351 return -EINPROGRESS; /* Call commit handler */
3354 static int orinoco_ioctl_setrts(struct net_device *dev,
3355 struct iw_request_info *info,
3356 struct iw_param *rrq,
3359 struct orinoco_private *priv = netdev_priv(dev);
3360 int val = rrq->value;
3361 unsigned long flags;
3366 if ((val < 0) || (val > 2347))
3369 if (orinoco_lock(priv, &flags) != 0)
3372 priv->rts_thresh = val;
3373 orinoco_unlock(priv, &flags);
3375 return -EINPROGRESS; /* Call commit handler */
3378 static int orinoco_ioctl_getrts(struct net_device *dev,
3379 struct iw_request_info *info,
3380 struct iw_param *rrq,
3383 struct orinoco_private *priv = netdev_priv(dev);
3385 rrq->value = priv->rts_thresh;
3386 rrq->disabled = (rrq->value == 2347);
3392 static int orinoco_ioctl_setfrag(struct net_device *dev,
3393 struct iw_request_info *info,
3394 struct iw_param *frq,
3397 struct orinoco_private *priv = netdev_priv(dev);
3398 int err = -EINPROGRESS; /* Call commit handler */
3399 unsigned long flags;
3401 if (orinoco_lock(priv, &flags) != 0)
3404 if (priv->has_mwo) {
3406 priv->mwo_robust = 0;
3409 printk(KERN_WARNING "%s: Fixed fragmentation "
3410 "is not supported on this firmware. "
3411 "Using MWO robust instead.\n",
3413 priv->mwo_robust = 1;
3417 priv->frag_thresh = 2346;
3419 if ((frq->value < 256) || (frq->value > 2346))
3423 priv->frag_thresh = frq->value & ~0x1;
3427 orinoco_unlock(priv, &flags);
3432 static int orinoco_ioctl_getfrag(struct net_device *dev,
3433 struct iw_request_info *info,
3434 struct iw_param *frq,
3437 struct orinoco_private *priv = netdev_priv(dev);
3438 hermes_t *hw = &priv->hw;
3441 unsigned long flags;
3443 if (orinoco_lock(priv, &flags) != 0)
3446 if (priv->has_mwo) {
3447 err = hermes_read_wordrec(hw, USER_BAP,
3448 HERMES_RID_CNFMWOROBUST_AGERE,
3453 frq->value = val ? 2347 : 0;
3454 frq->disabled = !val;
3457 err = hermes_read_wordrec(hw, USER_BAP,
3458 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3464 frq->disabled = (val >= 2346);
3468 orinoco_unlock(priv, &flags);
3473 static int orinoco_ioctl_setrate(struct net_device *dev,
3474 struct iw_request_info *info,
3475 struct iw_param *rrq,
3478 struct orinoco_private *priv = netdev_priv(dev);
3480 int bitrate; /* 100s of kilobits */
3481 unsigned long flags;
3483 /* As the user space doesn't know our highest rate, it uses -1
3484 * to ask us to set the highest rate. Test it using "iwconfig
3485 * ethX rate auto" - Jean II */
3486 if (rrq->value == -1)
3489 if (rrq->value % 100000)
3491 bitrate = rrq->value / 100000;
3494 ratemode = orinoco_get_bitratemode(bitrate, !rrq->fixed);
3499 if (orinoco_lock(priv, &flags) != 0)
3501 priv->bitratemode = ratemode;
3502 orinoco_unlock(priv, &flags);
3504 return -EINPROGRESS;
3507 static int orinoco_ioctl_getrate(struct net_device *dev,
3508 struct iw_request_info *info,
3509 struct iw_param *rrq,
3512 struct orinoco_private *priv = netdev_priv(dev);
3514 int bitrate, automatic;
3515 unsigned long flags;
3517 if (orinoco_lock(priv, &flags) != 0)
3520 orinoco_get_ratemode_cfg(priv->bitratemode, &bitrate, &automatic);
3522 /* If the interface is running we try to find more about the
3524 if (netif_running(dev))
3525 err = orinoco_hw_get_act_bitrate(priv, &bitrate);
3527 orinoco_unlock(priv, &flags);
3529 rrq->value = bitrate;
3530 rrq->fixed = !automatic;
3536 static int orinoco_ioctl_setpower(struct net_device *dev,
3537 struct iw_request_info *info,
3538 struct iw_param *prq,
3541 struct orinoco_private *priv = netdev_priv(dev);
3542 int err = -EINPROGRESS; /* Call commit handler */
3543 unsigned long flags;
3545 if (orinoco_lock(priv, &flags) != 0)
3548 if (prq->disabled) {
3551 switch (prq->flags & IW_POWER_MODE) {
3552 case IW_POWER_UNICAST_R:
3556 case IW_POWER_ALL_R:
3561 /* No flags : but we may have a value - Jean II */
3568 if (prq->flags & IW_POWER_TIMEOUT) {
3570 priv->pm_timeout = prq->value / 1000;
3572 if (prq->flags & IW_POWER_PERIOD) {
3574 priv->pm_period = prq->value / 1000;
3576 /* It's valid to not have a value if we are just toggling
3577 * the flags... Jean II */
3585 orinoco_unlock(priv, &flags);
3590 static int orinoco_ioctl_getpower(struct net_device *dev,
3591 struct iw_request_info *info,
3592 struct iw_param *prq,
3595 struct orinoco_private *priv = netdev_priv(dev);
3596 hermes_t *hw = &priv->hw;
3598 u16 enable, period, timeout, mcast;
3599 unsigned long flags;
3601 if (orinoco_lock(priv, &flags) != 0)
3604 err = hermes_read_wordrec(hw, USER_BAP,
3605 HERMES_RID_CNFPMENABLED, &enable);
3609 err = hermes_read_wordrec(hw, USER_BAP,
3610 HERMES_RID_CNFMAXSLEEPDURATION, &period);
3614 err = hermes_read_wordrec(hw, USER_BAP,
3615 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
3619 err = hermes_read_wordrec(hw, USER_BAP,
3620 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
3624 prq->disabled = !enable;
3625 /* Note : by default, display the period */
3626 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
3627 prq->flags = IW_POWER_TIMEOUT;
3628 prq->value = timeout * 1000;
3630 prq->flags = IW_POWER_PERIOD;
3631 prq->value = period * 1000;
3634 prq->flags |= IW_POWER_ALL_R;
3636 prq->flags |= IW_POWER_UNICAST_R;
3639 orinoco_unlock(priv, &flags);
3644 static int orinoco_ioctl_set_encodeext(struct net_device *dev,
3645 struct iw_request_info *info,
3646 union iwreq_data *wrqu,
3649 struct orinoco_private *priv = netdev_priv(dev);
3650 struct iw_point *encoding = &wrqu->encoding;
3651 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
3652 int idx, alg = ext->alg, set_key = 1;
3653 unsigned long flags;
3657 if (orinoco_lock(priv, &flags) != 0)
3660 /* Determine and validate the key index */
3661 idx = encoding->flags & IW_ENCODE_INDEX;
3663 if ((idx < 1) || (idx > 4))
3669 if (encoding->flags & IW_ENCODE_DISABLED)
3670 alg = IW_ENCODE_ALG_NONE;
3672 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
3673 /* Clear any TKIP TX key we had */
3674 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
3677 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3679 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
3680 (ext->key_len > 0)) ? 1 : 0;
3684 /* Set the requested key first */
3686 case IW_ENCODE_ALG_NONE:
3687 priv->encode_alg = alg;
3688 priv->keys[idx].len = 0;
3691 case IW_ENCODE_ALG_WEP:
3692 if (ext->key_len > SMALL_KEY_SIZE)
3693 key_len = LARGE_KEY_SIZE;
3694 else if (ext->key_len > 0)
3695 key_len = SMALL_KEY_SIZE;
3699 priv->encode_alg = alg;
3700 priv->keys[idx].len = cpu_to_le16(key_len);
3702 key_len = min(ext->key_len, key_len);
3704 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
3705 memcpy(priv->keys[idx].data, ext->key, key_len);
3708 case IW_ENCODE_ALG_TKIP:
3710 hermes_t *hw = &priv->hw;
3713 if (!priv->has_wpa ||
3714 (ext->key_len > sizeof(priv->tkip_key[0])))
3717 priv->encode_alg = alg;
3718 memset(&priv->tkip_key[idx], 0,
3719 sizeof(priv->tkip_key[idx]));
3720 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
3722 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
3723 tkip_iv = &ext->rx_seq[0];
3725 err = __orinoco_hw_set_tkip_key(hw, idx,
3726 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
3727 (u8 *) &priv->tkip_key[idx],
3730 printk(KERN_ERR "%s: Error %d setting TKIP key"
3731 "\n", dev->name, err);
3741 orinoco_unlock(priv, &flags);
3746 static int orinoco_ioctl_get_encodeext(struct net_device *dev,
3747 struct iw_request_info *info,
3748 union iwreq_data *wrqu,
3751 struct orinoco_private *priv = netdev_priv(dev);
3752 struct iw_point *encoding = &wrqu->encoding;
3753 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
3754 int idx, max_key_len;
3755 unsigned long flags;
3758 if (orinoco_lock(priv, &flags) != 0)
3762 max_key_len = encoding->length - sizeof(*ext);
3763 if (max_key_len < 0)
3766 idx = encoding->flags & IW_ENCODE_INDEX;
3768 if ((idx < 1) || (idx > 4))
3774 encoding->flags = idx + 1;
3775 memset(ext, 0, sizeof(*ext));
3777 ext->alg = priv->encode_alg;
3778 switch (priv->encode_alg) {
3779 case IW_ENCODE_ALG_NONE:
3781 encoding->flags |= IW_ENCODE_DISABLED;
3783 case IW_ENCODE_ALG_WEP:
3784 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
3786 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
3787 encoding->flags |= IW_ENCODE_ENABLED;
3789 case IW_ENCODE_ALG_TKIP:
3790 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
3792 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
3793 encoding->flags |= IW_ENCODE_ENABLED;
3799 orinoco_unlock(priv, &flags);
3804 static int orinoco_ioctl_set_auth(struct net_device *dev,
3805 struct iw_request_info *info,
3806 union iwreq_data *wrqu, char *extra)
3808 struct orinoco_private *priv = netdev_priv(dev);
3809 hermes_t *hw = &priv->hw;
3810 struct iw_param *param = &wrqu->param;
3811 unsigned long flags;
3812 int ret = -EINPROGRESS;
3814 if (orinoco_lock(priv, &flags) != 0)
3817 switch (param->flags & IW_AUTH_INDEX) {
3818 case IW_AUTH_WPA_VERSION:
3819 case IW_AUTH_CIPHER_PAIRWISE:
3820 case IW_AUTH_CIPHER_GROUP:
3821 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3822 case IW_AUTH_PRIVACY_INVOKED:
3823 case IW_AUTH_DROP_UNENCRYPTED:
3825 * orinoco does not use these parameters
3829 case IW_AUTH_KEY_MGMT:
3830 /* wl_lkm implies value 2 == PSK for Hermes I
3831 * which ties in with WEXT
3832 * no other hints tho :(
3834 priv->key_mgmt = param->value;
3837 case IW_AUTH_TKIP_COUNTERMEASURES:
3838 /* When countermeasures are enabled, shut down the
3839 * card; when disabled, re-enable the card. This must
3840 * take effect immediately.
3842 * TODO: Make sure that the EAPOL message is getting
3843 * out before card disabled
3846 priv->tkip_cm_active = 1;
3847 ret = hermes_enable_port(hw, 0);
3849 priv->tkip_cm_active = 0;
3850 ret = hermes_disable_port(hw, 0);
3854 case IW_AUTH_80211_AUTH_ALG:
3855 if (param->value & IW_AUTH_ALG_SHARED_KEY)
3856 priv->wep_restrict = 1;
3857 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
3858 priv->wep_restrict = 0;
3863 case IW_AUTH_WPA_ENABLED:
3864 if (priv->has_wpa) {
3865 priv->wpa_enabled = param->value ? 1 : 0;
3869 /* else silently accept disable of WPA */
3870 priv->wpa_enabled = 0;
3878 orinoco_unlock(priv, &flags);
3882 static int orinoco_ioctl_get_auth(struct net_device *dev,
3883 struct iw_request_info *info,
3884 union iwreq_data *wrqu, char *extra)
3886 struct orinoco_private *priv = netdev_priv(dev);
3887 struct iw_param *param = &wrqu->param;
3888 unsigned long flags;
3891 if (orinoco_lock(priv, &flags) != 0)
3894 switch (param->flags & IW_AUTH_INDEX) {
3895 case IW_AUTH_KEY_MGMT:
3896 param->value = priv->key_mgmt;
3899 case IW_AUTH_TKIP_COUNTERMEASURES:
3900 param->value = priv->tkip_cm_active;
3903 case IW_AUTH_80211_AUTH_ALG:
3904 if (priv->wep_restrict)
3905 param->value = IW_AUTH_ALG_SHARED_KEY;
3907 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
3910 case IW_AUTH_WPA_ENABLED:
3911 param->value = priv->wpa_enabled;
3918 orinoco_unlock(priv, &flags);
3922 static int orinoco_ioctl_set_genie(struct net_device *dev,
3923 struct iw_request_info *info,
3924 union iwreq_data *wrqu, char *extra)
3926 struct orinoco_private *priv = netdev_priv(dev);
3928 unsigned long flags;
3930 /* cut off at IEEE80211_MAX_DATA_LEN */
3931 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
3932 (wrqu->data.length && (extra == NULL)))
3935 if (wrqu->data.length) {
3936 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
3940 memcpy(buf, extra, wrqu->data.length);
3944 if (orinoco_lock(priv, &flags) != 0) {
3949 kfree(priv->wpa_ie);
3951 priv->wpa_ie_len = wrqu->data.length;
3954 /* Looks like wl_lkm wants to check the auth alg, and
3955 * somehow pass it to the firmware.
3956 * Instead it just calls the key mgmt rid
3957 * - we do this in set auth.
3961 orinoco_unlock(priv, &flags);
3965 static int orinoco_ioctl_get_genie(struct net_device *dev,
3966 struct iw_request_info *info,
3967 union iwreq_data *wrqu, char *extra)
3969 struct orinoco_private *priv = netdev_priv(dev);
3970 unsigned long flags;
3973 if (orinoco_lock(priv, &flags) != 0)
3976 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
3977 wrqu->data.length = 0;
3981 if (wrqu->data.length < priv->wpa_ie_len) {
3986 wrqu->data.length = priv->wpa_ie_len;
3987 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
3990 orinoco_unlock(priv, &flags);
3994 static int orinoco_ioctl_set_mlme(struct net_device *dev,
3995 struct iw_request_info *info,
3996 union iwreq_data *wrqu, char *extra)
3998 struct orinoco_private *priv = netdev_priv(dev);
3999 hermes_t *hw = &priv->hw;
4000 struct iw_mlme *mlme = (struct iw_mlme *)extra;
4001 unsigned long flags;
4004 if (orinoco_lock(priv, &flags) != 0)
4007 switch (mlme->cmd) {
4008 case IW_MLME_DEAUTH:
4009 /* silently ignore */
4012 case IW_MLME_DISASSOC:
4017 } __attribute__ ((packed)) buf;
4019 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
4020 buf.reason_code = cpu_to_le16(mlme->reason_code);
4021 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
4022 HERMES_RID_CNFDISASSOCIATE,
4030 orinoco_unlock(priv, &flags);
4034 static int orinoco_ioctl_getretry(struct net_device *dev,
4035 struct iw_request_info *info,
4036 struct iw_param *rrq,
4039 struct orinoco_private *priv = netdev_priv(dev);
4040 hermes_t *hw = &priv->hw;
4042 u16 short_limit, long_limit, lifetime;
4043 unsigned long flags;
4045 if (orinoco_lock(priv, &flags) != 0)
4048 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4053 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4058 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4063 rrq->disabled = 0; /* Can't be disabled */
4065 /* Note : by default, display the retry number */
4066 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4067 rrq->flags = IW_RETRY_LIFETIME;
4068 rrq->value = lifetime * 1000; /* ??? */
4070 /* By default, display the min number */
4071 if ((rrq->flags & IW_RETRY_LONG)) {
4072 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
4073 rrq->value = long_limit;
4075 rrq->flags = IW_RETRY_LIMIT;
4076 rrq->value = short_limit;
4077 if (short_limit != long_limit)
4078 rrq->flags |= IW_RETRY_SHORT;
4083 orinoco_unlock(priv, &flags);
4088 static int orinoco_ioctl_reset(struct net_device *dev,
4089 struct iw_request_info *info,
4093 struct orinoco_private *priv = netdev_priv(dev);
4095 if (!capable(CAP_NET_ADMIN))
4098 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4099 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4101 /* Firmware reset */
4102 orinoco_reset(&priv->reset_work);
4104 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4106 schedule_work(&priv->reset_work);
4112 static int orinoco_ioctl_setibssport(struct net_device *dev,
4113 struct iw_request_info *info,
4118 struct orinoco_private *priv = netdev_priv(dev);
4119 int val = *((int *) extra);
4120 unsigned long flags;
4122 if (orinoco_lock(priv, &flags) != 0)
4125 priv->ibss_port = val ;
4127 /* Actually update the mode we are using */
4128 set_port_type(priv);
4130 orinoco_unlock(priv, &flags);
4131 return -EINPROGRESS; /* Call commit handler */
4134 static int orinoco_ioctl_getibssport(struct net_device *dev,
4135 struct iw_request_info *info,
4139 struct orinoco_private *priv = netdev_priv(dev);
4140 int *val = (int *) extra;
4142 *val = priv->ibss_port;
4146 static int orinoco_ioctl_setport3(struct net_device *dev,
4147 struct iw_request_info *info,
4151 struct orinoco_private *priv = netdev_priv(dev);
4152 int val = *((int *) extra);
4154 unsigned long flags;
4156 if (orinoco_lock(priv, &flags) != 0)
4160 case 0: /* Try to do IEEE ad-hoc mode */
4161 if (!priv->has_ibss) {
4165 priv->prefer_port3 = 0;
4169 case 1: /* Try to do Lucent proprietary ad-hoc mode */
4170 if (!priv->has_port3) {
4174 priv->prefer_port3 = 1;
4182 /* Actually update the mode we are using */
4183 set_port_type(priv);
4187 orinoco_unlock(priv, &flags);
4192 static int orinoco_ioctl_getport3(struct net_device *dev,
4193 struct iw_request_info *info,
4197 struct orinoco_private *priv = netdev_priv(dev);
4198 int *val = (int *) extra;
4200 *val = priv->prefer_port3;
4204 static int orinoco_ioctl_setpreamble(struct net_device *dev,
4205 struct iw_request_info *info,
4209 struct orinoco_private *priv = netdev_priv(dev);
4210 unsigned long flags;
4213 if (!priv->has_preamble)
4216 /* 802.11b has recently defined some short preamble.
4217 * Basically, the Phy header has been reduced in size.
4218 * This increase performance, especially at high rates
4219 * (the preamble is transmitted at 1Mb/s), unfortunately
4220 * this give compatibility troubles... - Jean II */
4221 val = *((int *) extra);
4223 if (orinoco_lock(priv, &flags) != 0)
4231 orinoco_unlock(priv, &flags);
4233 return -EINPROGRESS; /* Call commit handler */
4236 static int orinoco_ioctl_getpreamble(struct net_device *dev,
4237 struct iw_request_info *info,
4241 struct orinoco_private *priv = netdev_priv(dev);
4242 int *val = (int *) extra;
4244 if (!priv->has_preamble)
4247 *val = priv->preamble;
4251 /* ioctl interface to hermes_read_ltv()
4252 * To use with iwpriv, pass the RID as the token argument, e.g.
4253 * iwpriv get_rid [0xfc00]
4254 * At least Wireless Tools 25 is required to use iwpriv.
4255 * For Wireless Tools 25 and 26 append "dummy" are the end. */
4256 static int orinoco_ioctl_getrid(struct net_device *dev,
4257 struct iw_request_info *info,
4258 struct iw_point *data,
4261 struct orinoco_private *priv = netdev_priv(dev);
4262 hermes_t *hw = &priv->hw;
4263 int rid = data->flags;
4266 unsigned long flags;
4268 /* It's a "get" function, but we don't want users to access the
4269 * WEP key and other raw firmware data */
4270 if (!capable(CAP_NET_ADMIN))
4273 if (rid < 0xfc00 || rid > 0xffff)
4276 if (orinoco_lock(priv, &flags) != 0)
4279 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
4284 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
4288 orinoco_unlock(priv, &flags);
4292 /* Trigger a scan (look for other cells in the vicinity) */
4293 static int orinoco_ioctl_setscan(struct net_device *dev,
4294 struct iw_request_info *info,
4295 struct iw_point *srq,
4298 struct orinoco_private *priv = netdev_priv(dev);
4299 hermes_t *hw = &priv->hw;
4300 struct iw_scan_req *si = (struct iw_scan_req *) extra;
4302 unsigned long flags;
4304 /* Note : you may have realised that, as this is a SET operation,
4305 * this is privileged and therefore a normal user can't
4307 * This is not an error, while the device perform scanning,
4308 * traffic doesn't flow, so it's a perfect DoS...
4311 if (orinoco_lock(priv, &flags) != 0)
4314 /* Scanning with port 0 disabled would fail */
4315 if (!netif_running(dev)) {
4320 /* In monitor mode, the scan results are always empty.
4321 * Probe responses are passed to the driver as received
4322 * frames and could be processed in software. */
4323 if (priv->iw_mode == IW_MODE_MONITOR) {
4328 /* Note : because we don't lock out the irq handler, the way
4329 * we access scan variables in priv is critical.
4330 * o scan_inprogress : not touched by irq handler
4331 * o scan_mode : not touched by irq handler
4332 * Before modifying anything on those variables, please think hard !
4336 priv->scan_mode = srq->flags;
4338 /* Always trigger scanning, even if it's in progress.
4339 * This way, if the info frame get lost, we will recover somewhat
4340 * gracefully - Jean II */
4342 if (priv->has_hostscan) {
4343 switch (priv->firmware_type) {
4344 case FIRMWARE_TYPE_SYMBOL:
4345 err = hermes_write_wordrec(hw, USER_BAP,
4346 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4347 HERMES_HOSTSCAN_SYMBOL_ONCE |
4348 HERMES_HOSTSCAN_SYMBOL_BCAST);
4350 case FIRMWARE_TYPE_INTERSIL: {
4353 req[0] = cpu_to_le16(0x3fff); /* All channels */
4354 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4355 req[2] = 0; /* Any ESSID */
4356 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4357 HERMES_RID_CNFHOSTSCAN, &req);
4360 case FIRMWARE_TYPE_AGERE:
4361 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4362 struct hermes_idstring idbuf;
4363 size_t len = min(sizeof(idbuf.val),
4364 (size_t) si->essid_len);
4365 idbuf.len = cpu_to_le16(len);
4366 memcpy(idbuf.val, si->essid, len);
4368 err = hermes_write_ltv(hw, USER_BAP,
4369 HERMES_RID_CNFSCANSSID_AGERE,
4370 HERMES_BYTES_TO_RECLEN(len + 2),
4373 err = hermes_write_wordrec(hw, USER_BAP,
4374 HERMES_RID_CNFSCANSSID_AGERE,
4379 if (priv->has_ext_scan) {
4380 /* Clear scan results at the start of
4381 * an extended scan */
4382 orinoco_clear_scan_results(priv,
4383 msecs_to_jiffies(15000));
4385 /* TODO: Is this available on older firmware?
4386 * Can we use it to scan specific channels
4387 * for IW_SCAN_THIS_FREQ? */
4388 err = hermes_write_wordrec(hw, USER_BAP,
4389 HERMES_RID_CNFSCANCHANNELS2GHZ,
4394 err = hermes_inquire(hw,
4395 HERMES_INQ_CHANNELINFO);
4397 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4401 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4403 /* One more client */
4405 priv->scan_inprogress = 1;
4408 orinoco_unlock(priv, &flags);
4412 #define MAX_CUSTOM_LEN 64
4414 /* Translate scan data returned from the card to a card independant
4415 * format that the Wireless Tools will understand - Jean II */
4416 static inline char *orinoco_translate_scan(struct net_device *dev,
4417 struct iw_request_info *info,
4420 union hermes_scan_info *bss,
4421 unsigned long last_scanned)
4423 struct orinoco_private *priv = netdev_priv(dev);
4426 struct iw_event iwe; /* Temporary buffer */
4427 char custom[MAX_CUSTOM_LEN];
4429 memset(&iwe, 0, sizeof(iwe));
4431 /* First entry *MUST* be the AP MAC address */
4432 iwe.cmd = SIOCGIWAP;
4433 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4434 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
4435 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4436 &iwe, IW_EV_ADDR_LEN);
4438 /* Other entries will be displayed in the order we give them */
4441 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4442 if (iwe.u.data.length > 32)
4443 iwe.u.data.length = 32;
4444 iwe.cmd = SIOCGIWESSID;
4445 iwe.u.data.flags = 1;
4446 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4447 &iwe, bss->a.essid);
4450 iwe.cmd = SIOCGIWMODE;
4451 capabilities = le16_to_cpu(bss->a.capabilities);
4452 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4453 if (capabilities & WLAN_CAPABILITY_ESS)
4454 iwe.u.mode = IW_MODE_MASTER;
4456 iwe.u.mode = IW_MODE_ADHOC;
4457 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4458 &iwe, IW_EV_UINT_LEN);
4461 channel = bss->s.channel;
4462 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4463 /* Add channel and frequency */
4464 iwe.cmd = SIOCGIWFREQ;
4465 iwe.u.freq.m = channel;
4467 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4468 &iwe, IW_EV_FREQ_LEN);
4470 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
4472 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4473 &iwe, IW_EV_FREQ_LEN);
4476 /* Add quality statistics. level and noise in dB. No link quality */
4478 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4479 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4480 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4481 /* Wireless tools prior to 27.pre22 will show link quality
4482 * anyway, so we provide a reasonable value. */
4483 if (iwe.u.qual.level > iwe.u.qual.noise)
4484 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4486 iwe.u.qual.qual = 0;
4487 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4488 &iwe, IW_EV_QUAL_LEN);
4490 /* Add encryption capability */
4491 iwe.cmd = SIOCGIWENCODE;
4492 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4493 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4495 iwe.u.data.flags = IW_ENCODE_DISABLED;
4496 iwe.u.data.length = 0;
4497 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4500 /* Bit rate is not available in Lucent/Agere firmwares */
4501 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4502 char *current_val = current_ev + iwe_stream_lcp_len(info);
4506 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4511 iwe.cmd = SIOCGIWRATE;
4512 /* Those two flags are ignored... */
4513 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4515 for (i = 0; i < 10; i += step) {
4516 /* NULL terminated */
4517 if (bss->p.rates[i] == 0x0)
4519 /* Bit rate given in 500 kb/s units (+ 0x80) */
4520 iwe.u.bitrate.value =
4521 ((bss->p.rates[i] & 0x7f) * 500000);
4522 current_val = iwe_stream_add_value(info, current_ev,
4527 /* Check if we added any event */
4528 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
4529 current_ev = current_val;
4532 /* Beacon interval */
4533 iwe.cmd = IWEVCUSTOM;
4534 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4536 le16_to_cpu(bss->a.beacon_interv));
4537 if (iwe.u.data.length)
4538 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4542 iwe.cmd = IWEVCUSTOM;
4543 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4546 if (iwe.u.data.length)
4547 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4550 /* Add EXTRA: Age to display seconds since last beacon/probe response
4551 * for given network. */
4552 iwe.cmd = IWEVCUSTOM;
4553 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4554 " Last beacon: %dms ago",
4555 jiffies_to_msecs(jiffies - last_scanned));
4556 if (iwe.u.data.length)
4557 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4563 static inline char *orinoco_translate_ext_scan(struct net_device *dev,
4564 struct iw_request_info *info,
4567 struct agere_ext_scan_info *bss,
4568 unsigned long last_scanned)
4572 struct iw_event iwe; /* Temporary buffer */
4573 char custom[MAX_CUSTOM_LEN];
4576 memset(&iwe, 0, sizeof(iwe));
4578 /* First entry *MUST* be the AP MAC address */
4579 iwe.cmd = SIOCGIWAP;
4580 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4581 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
4582 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4583 &iwe, IW_EV_ADDR_LEN);
4585 /* Other entries will be displayed in the order we give them */
4589 iwe.u.data.length = ie[1];
4590 if (iwe.u.data.length) {
4591 if (iwe.u.data.length > 32)
4592 iwe.u.data.length = 32;
4593 iwe.cmd = SIOCGIWESSID;
4594 iwe.u.data.flags = 1;
4595 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4600 capabilities = le16_to_cpu(bss->capabilities);
4601 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4602 iwe.cmd = SIOCGIWMODE;
4603 if (capabilities & WLAN_CAPABILITY_ESS)
4604 iwe.u.mode = IW_MODE_MASTER;
4606 iwe.u.mode = IW_MODE_ADHOC;
4607 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4608 &iwe, IW_EV_UINT_LEN);
4611 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
4612 channel = ie ? ie[2] : 0;
4613 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4614 /* Add channel and frequency */
4615 iwe.cmd = SIOCGIWFREQ;
4616 iwe.u.freq.m = channel;
4618 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4619 &iwe, IW_EV_FREQ_LEN);
4621 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
4623 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4624 &iwe, IW_EV_FREQ_LEN);
4627 /* Add quality statistics. level and noise in dB. No link quality */
4629 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4630 iwe.u.qual.level = bss->level - 0x95;
4631 iwe.u.qual.noise = bss->noise - 0x95;
4632 /* Wireless tools prior to 27.pre22 will show link quality
4633 * anyway, so we provide a reasonable value. */
4634 if (iwe.u.qual.level > iwe.u.qual.noise)
4635 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4637 iwe.u.qual.qual = 0;
4638 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4639 &iwe, IW_EV_QUAL_LEN);
4641 /* Add encryption capability */
4642 iwe.cmd = SIOCGIWENCODE;
4643 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4644 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4646 iwe.u.data.flags = IW_ENCODE_DISABLED;
4647 iwe.u.data.length = 0;
4648 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4652 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
4654 iwe.cmd = IWEVGENIE;
4655 iwe.u.data.length = ie[1] + 2;
4656 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4661 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
4663 iwe.cmd = IWEVGENIE;
4664 iwe.u.data.length = ie[1] + 2;
4665 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4669 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
4671 char *p = current_ev + iwe_stream_lcp_len(info);
4674 iwe.cmd = SIOCGIWRATE;
4675 /* Those two flags are ignored... */
4676 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4678 for (i = 2; i < (ie[1] + 2); i++) {
4679 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
4680 p = iwe_stream_add_value(info, current_ev, p, end_buf,
4681 &iwe, IW_EV_PARAM_LEN);
4683 /* Check if we added any event */
4684 if (p > (current_ev + iwe_stream_lcp_len(info)))
4689 iwe.cmd = IWEVCUSTOM;
4691 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
4692 (unsigned long long) le64_to_cpu(bss->timestamp));
4693 if (iwe.u.data.length)
4694 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4697 /* Beacon interval */
4698 iwe.cmd = IWEVCUSTOM;
4699 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4701 le16_to_cpu(bss->beacon_interval));
4702 if (iwe.u.data.length)
4703 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4707 iwe.cmd = IWEVCUSTOM;
4708 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4711 if (iwe.u.data.length)
4712 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4715 /* Add EXTRA: Age to display seconds since last beacon/probe response
4716 * for given network. */
4717 iwe.cmd = IWEVCUSTOM;
4718 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4719 " Last beacon: %dms ago",
4720 jiffies_to_msecs(jiffies - last_scanned));
4721 if (iwe.u.data.length)
4722 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4728 /* Return results of a scan */
4729 static int orinoco_ioctl_getscan(struct net_device *dev,
4730 struct iw_request_info *info,
4731 struct iw_point *srq,
4734 struct orinoco_private *priv = netdev_priv(dev);
4736 unsigned long flags;
4737 char *current_ev = extra;
4739 if (orinoco_lock(priv, &flags) != 0)
4742 if (priv->scan_inprogress) {
4743 /* Important note : we don't want to block the caller
4744 * until results are ready for various reasons.
4745 * First, managing wait queues is complex and racy.
4746 * Second, we grab some rtnetlink lock before comming
4747 * here (in dev_ioctl()).
4748 * Third, we generate an Wireless Event, so the
4749 * caller can wait itself on that - Jean II */
4754 if (priv->has_ext_scan) {
4755 struct xbss_element *bss;
4757 list_for_each_entry(bss, &priv->bss_list, list) {
4758 /* Translate this entry to WE format */
4760 orinoco_translate_ext_scan(dev, info,
4762 extra + srq->length,
4766 /* Check if there is space for one more entry */
4767 if ((extra + srq->length - current_ev)
4768 <= IW_EV_ADDR_LEN) {
4769 /* Ask user space to try again with a
4777 struct bss_element *bss;
4779 list_for_each_entry(bss, &priv->bss_list, list) {
4780 /* Translate this entry to WE format */
4781 current_ev = orinoco_translate_scan(dev, info,
4783 extra + srq->length,
4787 /* Check if there is space for one more entry */
4788 if ((extra + srq->length - current_ev)
4789 <= IW_EV_ADDR_LEN) {
4790 /* Ask user space to try again with a
4798 srq->length = (current_ev - extra);
4799 srq->flags = (__u16) priv->scan_mode;
4802 orinoco_unlock(priv, &flags);
4806 /* Commit handler, called after set operations */
4807 static int orinoco_ioctl_commit(struct net_device *dev,
4808 struct iw_request_info *info,
4812 struct orinoco_private *priv = netdev_priv(dev);
4813 struct hermes *hw = &priv->hw;
4814 unsigned long flags;
4820 if (priv->broken_disableport) {
4821 orinoco_reset(&priv->reset_work);
4825 if (orinoco_lock(priv, &flags) != 0)
4828 err = hermes_disable_port(hw, 0);
4830 printk(KERN_WARNING "%s: Unable to disable port "
4831 "while reconfiguring card\n", dev->name);
4832 priv->broken_disableport = 1;
4836 err = __orinoco_program_rids(dev);
4838 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4843 err = hermes_enable_port(hw, 0);
4845 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4852 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4853 schedule_work(&priv->reset_work);
4857 orinoco_unlock(priv, &flags);
4861 static const struct iw_priv_args orinoco_privtab[] = {
4862 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4863 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4864 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4866 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4868 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4869 0, "set_preamble" },
4870 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4872 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4873 0, "set_ibssport" },
4874 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4876 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4882 * Structures to export the Wireless Handlers
4885 #define STD_IW_HANDLER(id, func) \
4886 [IW_IOCTL_IDX(id)] = (iw_handler) func
4887 static const iw_handler orinoco_handler[] = {
4888 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
4889 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
4890 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
4891 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
4892 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
4893 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
4894 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
4895 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
4896 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
4897 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
4898 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
4899 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
4900 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
4901 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
4902 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
4903 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
4904 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
4905 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
4906 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
4907 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
4908 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
4909 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
4910 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
4911 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
4912 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
4913 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
4914 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
4915 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
4916 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
4917 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
4918 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
4919 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
4920 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
4921 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
4922 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
4923 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
4924 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
4925 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
4926 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
4931 Added typecasting since we no longer use iwreq_data -- Moustafa
4933 static const iw_handler orinoco_private_handler[] = {
4934 [0] = (iw_handler) orinoco_ioctl_reset,
4935 [1] = (iw_handler) orinoco_ioctl_reset,
4936 [2] = (iw_handler) orinoco_ioctl_setport3,
4937 [3] = (iw_handler) orinoco_ioctl_getport3,
4938 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4939 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4940 [6] = (iw_handler) orinoco_ioctl_setibssport,
4941 [7] = (iw_handler) orinoco_ioctl_getibssport,
4942 [9] = (iw_handler) orinoco_ioctl_getrid,
4945 static const struct iw_handler_def orinoco_handler_def = {
4946 .num_standard = ARRAY_SIZE(orinoco_handler),
4947 .num_private = ARRAY_SIZE(orinoco_private_handler),
4948 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4949 .standard = orinoco_handler,
4950 .private = orinoco_private_handler,
4951 .private_args = orinoco_privtab,
4952 .get_wireless_stats = orinoco_get_wireless_stats,
4955 static void orinoco_get_drvinfo(struct net_device *dev,
4956 struct ethtool_drvinfo *info)
4958 struct orinoco_private *priv = netdev_priv(dev);
4960 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4961 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4962 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4963 if (dev->dev.parent)
4964 strncpy(info->bus_info, dev_name(dev->dev.parent),
4965 sizeof(info->bus_info) - 1);
4967 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4968 "PCMCIA %p", priv->hw.iobase);
4971 static const struct ethtool_ops orinoco_ethtool_ops = {
4972 .get_drvinfo = orinoco_get_drvinfo,
4973 .get_link = ethtool_op_get_link,
4976 /********************************************************************/
4977 /* Module initialization */
4978 /********************************************************************/
4980 /* Can't be declared "const" or the whole __initdata section will
4982 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4983 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4984 "Pavel Roskin <proski@gnu.org>, et al)";
4986 static int __init init_orinoco(void)
4988 printk(KERN_DEBUG "%s\n", version);
4992 static void __exit exit_orinoco(void)
4996 module_init(init_orinoco);
4997 module_exit(exit_orinoco);