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/firmware.h>
87 #include <linux/suspend.h>
88 #include <linux/if_arp.h>
89 #include <linux/wireless.h>
90 #include <linux/ieee80211.h>
91 #include <net/iw_handler.h>
93 #include <linux/scatterlist.h>
94 #include <linux/crypto.h>
96 #include "hermes_rid.h"
97 #include "hermes_dld.h"
102 /********************************************************************/
103 /* Module information */
104 /********************************************************************/
106 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & "
107 "David Gibson <hermes@gibson.dropbear.id.au>");
108 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based "
109 "and similar wireless cards");
110 MODULE_LICENSE("Dual MPL/GPL");
112 /* Level of debugging. Used in the macros in orinoco.h */
114 int orinoco_debug = ORINOCO_DEBUG;
115 EXPORT_SYMBOL(orinoco_debug);
116 module_param(orinoco_debug, int, 0644);
117 MODULE_PARM_DESC(orinoco_debug, "Debug level");
120 static int suppress_linkstatus; /* = 0 */
121 module_param(suppress_linkstatus, bool, 0644);
122 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
124 static int ignore_disconnect; /* = 0 */
125 module_param(ignore_disconnect, int, 0644);
126 MODULE_PARM_DESC(ignore_disconnect,
127 "Don't report lost link to the network layer");
129 static int force_monitor; /* = 0 */
130 module_param(force_monitor, int, 0644);
131 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
133 /********************************************************************/
134 /* Compile time configuration and compatibility stuff */
135 /********************************************************************/
137 /* We do this this way to avoid ifdefs in the actual code */
139 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
141 #define SPY_NUMBER(priv) 0
142 #endif /* WIRELESS_SPY */
144 /********************************************************************/
145 /* Internal constants */
146 /********************************************************************/
148 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
149 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
150 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
152 #define ORINOCO_MIN_MTU 256
153 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
155 #define SYMBOL_MAX_VER_LEN (14)
158 #define MAX_IRQLOOPS_PER_IRQ 10
159 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
160 * how many events the
162 * legitimately generate */
163 #define SMALL_KEY_SIZE 5
164 #define LARGE_KEY_SIZE 13
165 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
167 #define DUMMY_FID 0xFFFF
169 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
170 HERMES_MAX_MULTICAST : 0)*/
171 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
173 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
174 | HERMES_EV_TX | HERMES_EV_TXEXC \
175 | HERMES_EV_WTERR | HERMES_EV_INFO \
178 #define MAX_RID_LEN 1024
180 static const struct iw_handler_def orinoco_handler_def;
181 static const struct ethtool_ops orinoco_ethtool_ops;
183 /********************************************************************/
185 /********************************************************************/
187 #define NUM_CHANNELS 14
189 /* This tables gives the actual meanings of the bitrate IDs returned
190 * by the firmware. */
192 int bitrate; /* in 100s of kilobits */
194 u16 agere_txratectrl;
195 u16 intersil_txratectrl;
196 } bitrate_table[] = {
197 {110, 1, 3, 15}, /* Entry 0 is the default */
206 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
208 /********************************************************************/
210 /********************************************************************/
212 /* Beginning of the Tx descriptor, used in TxExc handling */
213 struct hermes_txexc_data {
214 struct hermes_tx_descriptor desc;
218 } __attribute__ ((packed));
220 /* Rx frame header except compatibility 802.3 header */
221 struct hermes_rx_descriptor {
242 } __attribute__ ((packed));
244 struct orinoco_rx_data {
245 struct hermes_rx_descriptor *desc;
247 struct list_head list;
250 /********************************************************************/
251 /* Function prototypes */
252 /********************************************************************/
254 static int __orinoco_program_rids(struct net_device *dev);
255 static void __orinoco_set_multicast_list(struct net_device *dev);
257 /********************************************************************/
258 /* Michael MIC crypto setup */
259 /********************************************************************/
260 #define MICHAEL_MIC_LEN 8
261 static int orinoco_mic_init(struct orinoco_private *priv)
263 priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
264 if (IS_ERR(priv->tx_tfm_mic)) {
265 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
266 "crypto API michael_mic\n");
267 priv->tx_tfm_mic = NULL;
271 priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
272 if (IS_ERR(priv->rx_tfm_mic)) {
273 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
274 "crypto API michael_mic\n");
275 priv->rx_tfm_mic = NULL;
282 static void orinoco_mic_free(struct orinoco_private *priv)
284 if (priv->tx_tfm_mic)
285 crypto_free_hash(priv->tx_tfm_mic);
286 if (priv->rx_tfm_mic)
287 crypto_free_hash(priv->rx_tfm_mic);
290 static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
291 u8 *da, u8 *sa, u8 priority,
292 u8 *data, size_t data_len, u8 *mic)
294 struct hash_desc desc;
295 struct scatterlist sg[2];
296 u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
298 if (tfm_michael == NULL) {
299 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
303 /* Copy header into buffer. We need the padding on the end zeroed */
304 memcpy(&hdr[0], da, ETH_ALEN);
305 memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
306 hdr[ETH_ALEN*2] = priority;
307 hdr[ETH_ALEN*2+1] = 0;
308 hdr[ETH_ALEN*2+2] = 0;
309 hdr[ETH_ALEN*2+3] = 0;
311 /* Use scatter gather to MIC header and data in one go */
312 sg_init_table(sg, 2);
313 sg_set_buf(&sg[0], hdr, sizeof(hdr));
314 sg_set_buf(&sg[1], data, data_len);
316 if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
319 desc.tfm = tfm_michael;
321 return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
325 /********************************************************************/
326 /* Internal helper functions */
327 /********************************************************************/
329 static inline void set_port_type(struct orinoco_private *priv)
331 switch (priv->iw_mode) {
334 priv->createibss = 0;
337 if (priv->prefer_port3) {
339 priv->createibss = 0;
341 priv->port_type = priv->ibss_port;
342 priv->createibss = 1;
345 case IW_MODE_MONITOR:
347 priv->createibss = 0;
350 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
355 static inline u8 *orinoco_get_ie(u8 *data, size_t len,
356 enum ieee80211_eid eid)
359 while ((p + 2) < (data + len)) {
367 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
368 #define WPA_SELECTOR_LEN 4
369 static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
372 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
373 if ((p[0] == WLAN_EID_GENERIC) &&
374 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
382 /********************************************************************/
383 /* Download functionality */
384 /********************************************************************/
394 const static struct fw_info orinoco_fw[] = {
395 { NULL, "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
396 { NULL, "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
397 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", NULL, 0x00003100, 512 }
400 /* Structure used to access fields in FW
401 * Make sure LE decoding macros are used
403 struct orinoco_fw_header {
404 char hdr_vers[6]; /* ASCII string for header version */
405 __le16 headersize; /* Total length of header */
406 __le32 entry_point; /* NIC entry point */
407 __le32 blocks; /* Number of blocks to program */
408 __le32 block_offset; /* Offset of block data from eof header */
409 __le32 pdr_offset; /* Offset to PDR data from eof header */
410 __le32 pri_offset; /* Offset to primary plug data */
411 __le32 compat_offset; /* Offset to compatibility data*/
412 char signature[0]; /* FW signature length headersize-20 */
413 } __attribute__ ((packed));
415 /* Download either STA or AP firmware into the card. */
417 orinoco_dl_firmware(struct orinoco_private *priv,
418 const struct fw_info *fw,
421 /* Plug Data Area (PDA) */
424 hermes_t *hw = &priv->hw;
425 const struct firmware *fw_entry;
426 const struct orinoco_fw_header *hdr;
427 const unsigned char *first_block;
428 const unsigned char *end;
429 const char *firmware;
430 struct net_device *dev = priv->ndev;
433 pda = kzalloc(fw->pda_size, GFP_KERNEL);
438 firmware = fw->ap_fw;
440 firmware = fw->sta_fw;
442 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
443 dev->name, firmware);
445 /* Read current plug data */
446 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
447 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
451 if (!priv->cached_fw) {
452 err = request_firmware(&fw_entry, firmware, priv->dev);
455 printk(KERN_ERR "%s: Cannot find firmware %s\n",
456 dev->name, firmware);
461 fw_entry = priv->cached_fw;
463 hdr = (const struct orinoco_fw_header *) fw_entry->data;
465 /* Enable aux port to allow programming */
466 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
467 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
472 first_block = (fw_entry->data +
473 le16_to_cpu(hdr->headersize) +
474 le32_to_cpu(hdr->block_offset));
475 end = fw_entry->data + fw_entry->size;
477 err = hermes_program(hw, first_block, end);
478 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
482 /* Update production data */
483 first_block = (fw_entry->data +
484 le16_to_cpu(hdr->headersize) +
485 le32_to_cpu(hdr->pdr_offset));
487 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
488 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
492 /* Tell card we've finished */
493 err = hermesi_program_end(hw);
494 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
498 /* Check if we're running */
499 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
500 dev->name, hermes_present(hw));
503 /* If we requested the firmware, release it. */
504 if (!priv->cached_fw)
505 release_firmware(fw_entry);
513 #define TEXT_END 0x1A /* End of text header */
516 * Process a firmware image - stop the card, load the firmware, reset
517 * the card and make sure it responds. For the secondary firmware take
518 * care of the PDA - read it and then write it on top of the firmware.
521 symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
522 const unsigned char *image, const unsigned char *end,
525 hermes_t *hw = &priv->hw;
527 const unsigned char *ptr;
528 const unsigned char *first_block;
530 /* Plug Data Area (PDA) */
533 /* Binary block begins after the 0x1A marker */
535 while (*ptr++ != TEXT_END);
538 /* Read the PDA from EEPROM */
540 pda = kzalloc(fw->pda_size, GFP_KERNEL);
544 ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
549 /* Stop the firmware, so that it can be safely rewritten */
551 ret = priv->stop_fw(priv, 1);
556 /* Program the adapter with new firmware */
557 ret = hermes_program(hw, first_block, end);
561 /* Write the PDA to the adapter */
563 size_t len = hermes_blocks_length(first_block);
564 ptr = first_block + len;
565 ret = hermes_apply_pda(hw, ptr, pda);
571 /* Run the firmware */
573 ret = priv->stop_fw(priv, 0);
578 /* Reset hermes chip and make sure it responds */
579 ret = hermes_init(hw);
581 /* hermes_reset() should return 0 with the secondary firmware */
582 if (secondary && ret != 0)
585 /* And this should work with any firmware */
586 if (!hermes_present(hw))
598 * Download the firmware into the card, this also does a PCMCIA soft
599 * reset on the card, to make sure it's in a sane state.
602 symbol_dl_firmware(struct orinoco_private *priv,
603 const struct fw_info *fw)
605 struct net_device *dev = priv->ndev;
607 const struct firmware *fw_entry;
609 if (!priv->cached_pri_fw) {
610 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) {
611 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
612 dev->name, fw->pri_fw);
616 fw_entry = priv->cached_pri_fw;
618 /* Load primary firmware */
619 ret = symbol_dl_image(priv, fw, fw_entry->data,
620 fw_entry->data + fw_entry->size, 0);
622 if (!priv->cached_pri_fw)
623 release_firmware(fw_entry);
625 printk(KERN_ERR "%s: Primary firmware download failed\n",
630 if (!priv->cached_fw) {
631 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) {
632 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
633 dev->name, fw->sta_fw);
637 fw_entry = priv->cached_fw;
639 /* Load secondary firmware */
640 ret = symbol_dl_image(priv, fw, fw_entry->data,
641 fw_entry->data + fw_entry->size, 1);
642 if (!priv->cached_fw)
643 release_firmware(fw_entry);
645 printk(KERN_ERR "%s: Secondary firmware download failed\n",
652 static int orinoco_download(struct orinoco_private *priv)
655 /* Reload firmware */
656 switch (priv->firmware_type) {
657 case FIRMWARE_TYPE_AGERE:
658 /* case FIRMWARE_TYPE_INTERSIL: */
659 err = orinoco_dl_firmware(priv,
660 &orinoco_fw[priv->firmware_type], 0);
663 case FIRMWARE_TYPE_SYMBOL:
664 err = symbol_dl_firmware(priv,
665 &orinoco_fw[priv->firmware_type]);
667 case FIRMWARE_TYPE_INTERSIL:
670 /* TODO: if we fail we probably need to reinitialise
676 #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
677 static void orinoco_cache_fw(struct orinoco_private *priv, int ap)
679 const struct firmware *fw_entry = NULL;
683 pri_fw = orinoco_fw[priv->firmware_type].pri_fw;
685 fw = orinoco_fw[priv->firmware_type].ap_fw;
687 fw = orinoco_fw[priv->firmware_type].sta_fw;
690 if (request_firmware(&fw_entry, pri_fw, priv->dev) == 0)
691 priv->cached_pri_fw = fw_entry;
695 if (request_firmware(&fw_entry, fw, priv->dev) == 0)
696 priv->cached_fw = fw_entry;
700 static void orinoco_uncache_fw(struct orinoco_private *priv)
702 if (priv->cached_pri_fw)
703 release_firmware(priv->cached_pri_fw);
705 release_firmware(priv->cached_fw);
707 priv->cached_pri_fw = NULL;
708 priv->cached_fw = NULL;
711 #define orinoco_cache_fw(priv, ap)
712 #define orinoco_uncache_fw(priv)
715 /********************************************************************/
717 /********************************************************************/
719 static int orinoco_open(struct net_device *dev)
721 struct orinoco_private *priv = netdev_priv(dev);
725 if (orinoco_lock(priv, &flags) != 0)
728 err = __orinoco_up(dev);
733 orinoco_unlock(priv, &flags);
738 static int orinoco_stop(struct net_device *dev)
740 struct orinoco_private *priv = netdev_priv(dev);
743 /* We mustn't use orinoco_lock() here, because we need to be
744 able to close the interface even if hw_unavailable is set
745 (e.g. as we're released after a PC Card removal) */
746 spin_lock_irq(&priv->lock);
750 err = __orinoco_down(dev);
752 spin_unlock_irq(&priv->lock);
757 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
759 struct orinoco_private *priv = netdev_priv(dev);
764 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
766 struct orinoco_private *priv = netdev_priv(dev);
767 hermes_t *hw = &priv->hw;
768 struct iw_statistics *wstats = &priv->wstats;
772 if (!netif_device_present(dev)) {
773 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
775 return NULL; /* FIXME: Can we do better than this? */
778 /* If busy, return the old stats. Returning NULL may cause
779 * the interface to disappear from /proc/net/wireless */
780 if (orinoco_lock(priv, &flags) != 0)
783 /* We can't really wait for the tallies inquiry command to
784 * complete, so we just use the previous results and trigger
785 * a new tallies inquiry command for next time - Jean II */
786 /* FIXME: Really we should wait for the inquiry to come back -
787 * as it is the stats we give don't make a whole lot of sense.
788 * Unfortunately, it's not clear how to do that within the
789 * wireless extensions framework: I think we're in user
790 * context, but a lock seems to be held by the time we get in
791 * here so we're not safe to sleep here. */
792 hermes_inquire(hw, HERMES_INQ_TALLIES);
794 if (priv->iw_mode == IW_MODE_ADHOC) {
795 memset(&wstats->qual, 0, sizeof(wstats->qual));
796 /* If a spy address is defined, we report stats of the
797 * first spy address - Jean II */
798 if (SPY_NUMBER(priv)) {
799 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
800 wstats->qual.level = priv->spy_data.spy_stat[0].level;
801 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
802 wstats->qual.updated =
803 priv->spy_data.spy_stat[0].updated;
807 __le16 qual, signal, noise, unused;
808 } __attribute__ ((packed)) cq;
810 err = HERMES_READ_RECORD(hw, USER_BAP,
811 HERMES_RID_COMMSQUALITY, &cq);
814 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
815 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
816 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
817 wstats->qual.updated =
818 IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
822 orinoco_unlock(priv, &flags);
826 static void orinoco_set_multicast_list(struct net_device *dev)
828 struct orinoco_private *priv = netdev_priv(dev);
831 if (orinoco_lock(priv, &flags) != 0) {
832 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
833 "called when hw_unavailable\n", dev->name);
837 __orinoco_set_multicast_list(dev);
838 orinoco_unlock(priv, &flags);
841 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
843 struct orinoco_private *priv = netdev_priv(dev);
845 if ((new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU))
848 /* MTU + encapsulation + header length */
849 if ((new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
850 (priv->nicbuf_size - ETH_HLEN))
858 /********************************************************************/
860 /********************************************************************/
862 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
864 struct orinoco_private *priv = netdev_priv(dev);
865 struct net_device_stats *stats = &priv->stats;
866 hermes_t *hw = &priv->hw;
868 u16 txfid = priv->txfid;
873 if (!netif_running(dev)) {
874 printk(KERN_ERR "%s: Tx on stopped device!\n",
876 return NETDEV_TX_BUSY;
879 if (netif_queue_stopped(dev)) {
880 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
882 return NETDEV_TX_BUSY;
885 if (orinoco_lock(priv, &flags) != 0) {
886 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
888 return NETDEV_TX_BUSY;
891 if (!netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
892 /* Oops, the firmware hasn't established a connection,
893 silently drop the packet (this seems to be the
898 /* Check packet length */
899 if (skb->len < ETH_HLEN)
902 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
904 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
905 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
908 if (priv->has_alt_txcntl) {
909 /* WPA enabled firmwares have tx_cntl at the end of
910 * the 802.11 header. So write zeroed descriptor and
911 * 802.11 header at the same time
913 char desc[HERMES_802_3_OFFSET];
914 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
916 memset(&desc, 0, sizeof(desc));
918 *txcntl = cpu_to_le16(tx_control);
919 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
923 printk(KERN_ERR "%s: Error %d writing Tx "
924 "descriptor to BAP\n", dev->name, err);
928 struct hermes_tx_descriptor desc;
930 memset(&desc, 0, sizeof(desc));
932 desc.tx_control = cpu_to_le16(tx_control);
933 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
937 printk(KERN_ERR "%s: Error %d writing Tx "
938 "descriptor to BAP\n", dev->name, err);
942 /* Clear the 802.11 header and data length fields - some
943 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
944 * if this isn't done. */
945 hermes_clear_words(hw, HERMES_DATA0,
946 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
949 eh = (struct ethhdr *)skb->data;
951 /* Encapsulate Ethernet-II frames */
952 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
953 struct header_struct {
954 struct ethhdr eth; /* 802.3 header */
955 u8 encap[6]; /* 802.2 header */
956 } __attribute__ ((packed)) hdr;
958 /* Strip destination and source from the data */
959 skb_pull(skb, 2 * ETH_ALEN);
961 /* And move them to a separate header */
962 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
963 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
964 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
966 /* Insert the SNAP header */
967 if (skb_headroom(skb) < sizeof(hdr)) {
969 "%s: Not enough headroom for 802.2 headers %d\n",
970 dev->name, skb_headroom(skb));
973 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
974 memcpy(eh, &hdr, sizeof(hdr));
977 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
978 txfid, HERMES_802_3_OFFSET);
980 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
985 /* Calculate Michael MIC */
986 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
987 u8 mic_buf[MICHAEL_MIC_LEN + 1];
993 /* MIC start is on an odd boundary */
994 mic_buf[0] = skb->data[skb->len - 1];
996 offset = skb->len - 1;
997 len = MICHAEL_MIC_LEN + 1;
1001 len = MICHAEL_MIC_LEN;
1004 michael_mic(priv->tx_tfm_mic,
1005 priv->tkip_key[priv->tx_key].tx_mic,
1006 eh->h_dest, eh->h_source, 0 /* priority */,
1007 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
1010 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
1011 txfid, HERMES_802_3_OFFSET + offset);
1013 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
1019 /* Finally, we actually initiate the send */
1020 netif_stop_queue(dev);
1022 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
1025 netif_start_queue(dev);
1026 if (net_ratelimit())
1027 printk(KERN_ERR "%s: Error %d transmitting packet\n",
1032 dev->trans_start = jiffies;
1033 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
1038 stats->tx_dropped++;
1041 orinoco_unlock(priv, &flags);
1043 return NETDEV_TX_OK;
1047 schedule_work(&priv->reset_work);
1048 orinoco_unlock(priv, &flags);
1049 return NETDEV_TX_BUSY;
1052 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1054 struct orinoco_private *priv = netdev_priv(dev);
1055 u16 fid = hermes_read_regn(hw, ALLOCFID);
1057 if (fid != priv->txfid) {
1058 if (fid != DUMMY_FID)
1059 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1064 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1067 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1069 struct orinoco_private *priv = netdev_priv(dev);
1070 struct net_device_stats *stats = &priv->stats;
1072 stats->tx_packets++;
1074 netif_wake_queue(dev);
1076 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1079 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1081 struct orinoco_private *priv = netdev_priv(dev);
1082 struct net_device_stats *stats = &priv->stats;
1083 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
1085 struct hermes_txexc_data hdr;
1088 if (fid == DUMMY_FID)
1089 return; /* Nothing's really happened */
1091 /* Read part of the frame header - we need status and addr1 */
1092 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
1093 sizeof(struct hermes_txexc_data),
1096 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1100 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1101 "(FID=%04X error %d)\n",
1102 dev->name, fid, err);
1106 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1109 /* We produce a TXDROP event only for retry or lifetime
1110 * exceeded, because that's the only status that really mean
1111 * that this particular node went away.
1112 * Other errors means that *we* screwed up. - Jean II */
1113 status = le16_to_cpu(hdr.desc.status);
1114 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
1115 union iwreq_data wrqu;
1117 /* Copy 802.11 dest address.
1118 * We use the 802.11 header because the frame may
1119 * not be 802.3 or may be mangled...
1120 * In Ad-Hoc mode, it will be the node address.
1121 * In managed mode, it will be most likely the AP addr
1122 * User space will figure out how to convert it to
1123 * whatever it needs (IP address or else).
1125 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1126 wrqu.addr.sa_family = ARPHRD_ETHER;
1128 /* Send event to user space */
1129 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1132 netif_wake_queue(dev);
1135 static void orinoco_tx_timeout(struct net_device *dev)
1137 struct orinoco_private *priv = netdev_priv(dev);
1138 struct net_device_stats *stats = &priv->stats;
1139 struct hermes *hw = &priv->hw;
1141 printk(KERN_WARNING "%s: Tx timeout! "
1142 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1143 dev->name, hermes_read_regn(hw, ALLOCFID),
1144 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1148 schedule_work(&priv->reset_work);
1151 /********************************************************************/
1152 /* Rx path (data frames) */
1153 /********************************************************************/
1155 /* Does the frame have a SNAP header indicating it should be
1156 * de-encapsulated to Ethernet-II? */
1157 static inline int is_ethersnap(void *_hdr)
1161 /* We de-encapsulate all packets which, a) have SNAP headers
1162 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1163 * and where b) the OUI of the SNAP header is 00:00:00 or
1164 * 00:00:f8 - we need both because different APs appear to use
1165 * different OUIs for some reason */
1166 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1167 && ((hdr[5] == 0x00) || (hdr[5] == 0xf8));
1170 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1171 int level, int noise)
1173 struct iw_quality wstats;
1174 wstats.level = level - 0x95;
1175 wstats.noise = noise - 0x95;
1176 wstats.qual = (level > noise) ? (level - noise) : 0;
1177 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1178 /* Update spy records */
1179 wireless_spy_update(dev, mac, &wstats);
1182 static void orinoco_stat_gather(struct net_device *dev,
1183 struct sk_buff *skb,
1184 struct hermes_rx_descriptor *desc)
1186 struct orinoco_private *priv = netdev_priv(dev);
1188 /* Using spy support with lots of Rx packets, like in an
1189 * infrastructure (AP), will really slow down everything, because
1190 * the MAC address must be compared to each entry of the spy list.
1191 * If the user really asks for it (set some address in the
1192 * spy list), we do it, but he will pay the price.
1193 * Note that to get here, you need both WIRELESS_SPY
1194 * compiled in AND some addresses in the list !!!
1196 /* Note : gcc will optimise the whole section away if
1197 * WIRELESS_SPY is not defined... - Jean II */
1198 if (SPY_NUMBER(priv)) {
1199 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1200 desc->signal, desc->silence);
1205 * orinoco_rx_monitor - handle received monitor frames.
1208 * dev network device
1209 * rxfid received FID
1210 * desc rx descriptor of the frame
1212 * Call context: interrupt
1214 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1215 struct hermes_rx_descriptor *desc)
1217 u32 hdrlen = 30; /* return full header by default */
1222 struct sk_buff *skb;
1223 struct orinoco_private *priv = netdev_priv(dev);
1224 struct net_device_stats *stats = &priv->stats;
1225 hermes_t *hw = &priv->hw;
1227 len = le16_to_cpu(desc->data_len);
1229 /* Determine the size of the header and the data */
1230 fc = le16_to_cpu(desc->frame_ctl);
1231 switch (fc & IEEE80211_FCTL_FTYPE) {
1232 case IEEE80211_FTYPE_DATA:
1233 if ((fc & IEEE80211_FCTL_TODS)
1234 && (fc & IEEE80211_FCTL_FROMDS))
1240 case IEEE80211_FTYPE_MGMT:
1244 case IEEE80211_FTYPE_CTL:
1245 switch (fc & IEEE80211_FCTL_STYPE) {
1246 case IEEE80211_STYPE_PSPOLL:
1247 case IEEE80211_STYPE_RTS:
1248 case IEEE80211_STYPE_CFEND:
1249 case IEEE80211_STYPE_CFENDACK:
1252 case IEEE80211_STYPE_CTS:
1253 case IEEE80211_STYPE_ACK:
1259 /* Unknown frame type */
1263 /* sanity check the length */
1264 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
1265 printk(KERN_DEBUG "%s: oversized monitor frame, "
1266 "data length = %d\n", dev->name, datalen);
1267 stats->rx_length_errors++;
1271 skb = dev_alloc_skb(hdrlen + datalen);
1273 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1278 /* Copy the 802.11 header to the skb */
1279 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
1280 skb_reset_mac_header(skb);
1282 /* If any, copy the data from the card to the skb */
1284 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1285 ALIGN(datalen, 2), rxfid,
1286 HERMES_802_2_OFFSET);
1288 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1295 skb->ip_summed = CHECKSUM_NONE;
1296 skb->pkt_type = PACKET_OTHERHOST;
1297 skb->protocol = cpu_to_be16(ETH_P_802_2);
1299 stats->rx_packets++;
1300 stats->rx_bytes += skb->len;
1306 dev_kfree_skb_irq(skb);
1309 stats->rx_dropped++;
1312 /* Get tsc from the firmware */
1313 static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1316 hermes_t *hw = &priv->hw;
1318 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1320 if ((key < 0) || (key > 4))
1323 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1324 sizeof(tsc_arr), NULL, &tsc_arr);
1326 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1331 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1333 struct orinoco_private *priv = netdev_priv(dev);
1334 struct net_device_stats *stats = &priv->stats;
1335 struct iw_statistics *wstats = &priv->wstats;
1336 struct sk_buff *skb = NULL;
1339 struct hermes_rx_descriptor *desc;
1340 struct orinoco_rx_data *rx_data;
1343 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1346 "%s: Can't allocate space for RX descriptor\n",
1351 rxfid = hermes_read_regn(hw, RXFID);
1353 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
1356 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1357 "Frame dropped.\n", dev->name, err);
1361 status = le16_to_cpu(desc->status);
1363 if (status & HERMES_RXSTAT_BADCRC) {
1364 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1366 stats->rx_crc_errors++;
1370 /* Handle frames in monitor mode */
1371 if (priv->iw_mode == IW_MODE_MONITOR) {
1372 orinoco_rx_monitor(dev, rxfid, desc);
1376 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1377 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1379 wstats->discard.code++;
1383 length = le16_to_cpu(desc->data_len);
1386 if (length < 3) { /* No for even an 802.2 LLC header */
1387 /* At least on Symbol firmware with PCF we get quite a
1388 lot of these legitimately - Poll frames with no
1392 if (length > IEEE80211_MAX_DATA_LEN) {
1393 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1395 stats->rx_length_errors++;
1399 /* Payload size does not include Michael MIC. Increase payload
1400 * size to read it together with the data. */
1401 if (status & HERMES_RXSTAT_MIC)
1402 length += MICHAEL_MIC_LEN;
1404 /* We need space for the packet data itself, plus an ethernet
1405 header, plus 2 bytes so we can align the IP header on a
1406 32bit boundary, plus 1 byte so we can read in odd length
1407 packets from the card, which has an IO granularity of 16
1409 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1411 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1416 /* We'll prepend the header, so reserve space for it. The worst
1417 case is no decapsulation, when 802.3 header is prepended and
1418 nothing is removed. 2 is for aligning the IP header. */
1419 skb_reserve(skb, ETH_HLEN + 2);
1421 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1422 ALIGN(length, 2), rxfid,
1423 HERMES_802_2_OFFSET);
1425 printk(KERN_ERR "%s: error %d reading frame. "
1426 "Frame dropped.\n", dev->name, err);
1430 /* Add desc and skb to rx queue */
1431 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1433 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1437 rx_data->desc = desc;
1439 list_add_tail(&rx_data->list, &priv->rx_list);
1440 tasklet_schedule(&priv->rx_tasklet);
1445 dev_kfree_skb_irq(skb);
1448 stats->rx_dropped++;
1453 static void orinoco_rx(struct net_device *dev,
1454 struct hermes_rx_descriptor *desc,
1455 struct sk_buff *skb)
1457 struct orinoco_private *priv = netdev_priv(dev);
1458 struct net_device_stats *stats = &priv->stats;
1463 status = le16_to_cpu(desc->status);
1464 length = le16_to_cpu(desc->data_len);
1465 fc = le16_to_cpu(desc->frame_ctl);
1467 /* Calculate and check MIC */
1468 if (status & HERMES_RXSTAT_MIC) {
1469 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1470 HERMES_MIC_KEY_ID_SHIFT);
1471 u8 mic[MICHAEL_MIC_LEN];
1473 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1474 desc->addr3 : desc->addr2;
1476 /* Extract Michael MIC from payload */
1477 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1479 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1480 length -= MICHAEL_MIC_LEN;
1482 michael_mic(priv->rx_tfm_mic,
1483 priv->tkip_key[key_id].rx_mic,
1486 0, /* priority or QoS? */
1491 if (memcmp(mic, rxmic,
1493 union iwreq_data wrqu;
1494 struct iw_michaelmicfailure wxmic;
1496 printk(KERN_WARNING "%s: "
1497 "Invalid Michael MIC in data frame from %pM, "
1499 dev->name, src, key_id);
1501 /* TODO: update stats */
1503 /* Notify userspace */
1504 memset(&wxmic, 0, sizeof(wxmic));
1505 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1506 wxmic.flags |= (desc->addr1[0] & 1) ?
1507 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1508 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1509 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1511 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1514 memset(&wrqu, 0, sizeof(wrqu));
1515 wrqu.data.length = sizeof(wxmic);
1516 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1523 /* Handle decapsulation
1524 * In most cases, the firmware tell us about SNAP frames.
1525 * For some reason, the SNAP frames sent by LinkSys APs
1526 * are not properly recognised by most firmwares.
1527 * So, check ourselves */
1528 if (length >= ENCAPS_OVERHEAD &&
1529 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1530 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1531 is_ethersnap(skb->data))) {
1532 /* These indicate a SNAP within 802.2 LLC within
1533 802.11 frame which we'll need to de-encapsulate to
1534 the original EthernetII frame. */
1535 hdr = (struct ethhdr *)skb_push(skb,
1536 ETH_HLEN - ENCAPS_OVERHEAD);
1538 /* 802.3 frame - prepend 802.3 header as is */
1539 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1540 hdr->h_proto = htons(length);
1542 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
1543 if (fc & IEEE80211_FCTL_FROMDS)
1544 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
1546 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
1548 skb->protocol = eth_type_trans(skb, dev);
1549 skb->ip_summed = CHECKSUM_NONE;
1550 if (fc & IEEE80211_FCTL_TODS)
1551 skb->pkt_type = PACKET_OTHERHOST;
1553 /* Process the wireless stats if needed */
1554 orinoco_stat_gather(dev, skb, desc);
1556 /* Pass the packet to the networking stack */
1558 stats->rx_packets++;
1559 stats->rx_bytes += length;
1566 stats->rx_dropped++;
1569 static void orinoco_rx_isr_tasklet(unsigned long data)
1571 struct net_device *dev = (struct net_device *) data;
1572 struct orinoco_private *priv = netdev_priv(dev);
1573 struct orinoco_rx_data *rx_data, *temp;
1574 struct hermes_rx_descriptor *desc;
1575 struct sk_buff *skb;
1576 unsigned long flags;
1578 /* orinoco_rx requires the driver lock, and we also need to
1579 * protect priv->rx_list, so just hold the lock over the
1582 * If orinoco_lock fails, we've unplugged the card. In this
1583 * case just abort. */
1584 if (orinoco_lock(priv, &flags) != 0)
1587 /* extract desc and skb from queue */
1588 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1589 desc = rx_data->desc;
1591 list_del(&rx_data->list);
1594 orinoco_rx(dev, desc, skb);
1599 orinoco_unlock(priv, &flags);
1602 /********************************************************************/
1603 /* Rx path (info frames) */
1604 /********************************************************************/
1606 static void print_linkstatus(struct net_device *dev, u16 status)
1610 if (suppress_linkstatus)
1614 case HERMES_LINKSTATUS_NOT_CONNECTED:
1615 s = "Not Connected";
1617 case HERMES_LINKSTATUS_CONNECTED:
1620 case HERMES_LINKSTATUS_DISCONNECTED:
1623 case HERMES_LINKSTATUS_AP_CHANGE:
1626 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1627 s = "AP Out of Range";
1629 case HERMES_LINKSTATUS_AP_IN_RANGE:
1632 case HERMES_LINKSTATUS_ASSOC_FAILED:
1633 s = "Association Failed";
1639 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
1640 dev->name, s, status);
1643 /* Search scan results for requested BSSID, join it if found */
1644 static void orinoco_join_ap(struct work_struct *work)
1646 struct orinoco_private *priv =
1647 container_of(work, struct orinoco_private, join_work);
1648 struct net_device *dev = priv->ndev;
1649 struct hermes *hw = &priv->hw;
1651 unsigned long flags;
1655 } __attribute__ ((packed)) req;
1656 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1657 struct prism2_scan_apinfo *atom = NULL;
1663 /* Allocate buffer for scan results */
1664 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1668 if (orinoco_lock(priv, &flags) != 0)
1671 /* Sanity checks in case user changed something in the meantime */
1672 if (!priv->bssid_fixed)
1675 if (strlen(priv->desired_essid) == 0)
1678 /* Read scan results from the firmware */
1679 err = hermes_read_ltv(hw, USER_BAP,
1680 HERMES_RID_SCANRESULTSTABLE,
1681 MAX_SCAN_LEN, &len, buf);
1683 printk(KERN_ERR "%s: Cannot read scan results\n",
1688 len = HERMES_RECLEN_TO_BYTES(len);
1690 /* Go through the scan results looking for the channel of the AP
1691 * we were requested to join */
1692 for (; offset + atom_len <= len; offset += atom_len) {
1693 atom = (struct prism2_scan_apinfo *) (buf + offset);
1694 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1701 DEBUG(1, "%s: Requested AP not found in scan results\n",
1706 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1707 req.channel = atom->channel; /* both are little-endian */
1708 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1711 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1714 orinoco_unlock(priv, &flags);
1720 /* Send new BSSID to userspace */
1721 static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
1723 struct net_device *dev = priv->ndev;
1724 struct hermes *hw = &priv->hw;
1725 union iwreq_data wrqu;
1728 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1729 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1733 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1735 /* Send event to user space */
1736 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1739 static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1741 struct net_device *dev = priv->ndev;
1742 struct hermes *hw = &priv->hw;
1743 union iwreq_data wrqu;
1751 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1752 sizeof(buf), NULL, &buf);
1756 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1758 int rem = sizeof(buf) - (ie - &buf[0]);
1759 wrqu.data.length = ie[1] + 2;
1760 if (wrqu.data.length > rem)
1761 wrqu.data.length = rem;
1763 if (wrqu.data.length)
1764 /* Send event to user space */
1765 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1769 static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1771 struct net_device *dev = priv->ndev;
1772 struct hermes *hw = &priv->hw;
1773 union iwreq_data wrqu;
1775 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1781 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1782 sizeof(buf), NULL, &buf);
1786 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1788 int rem = sizeof(buf) - (ie - &buf[0]);
1789 wrqu.data.length = ie[1] + 2;
1790 if (wrqu.data.length > rem)
1791 wrqu.data.length = rem;
1793 if (wrqu.data.length)
1794 /* Send event to user space */
1795 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1799 static void orinoco_send_wevents(struct work_struct *work)
1801 struct orinoco_private *priv =
1802 container_of(work, struct orinoco_private, wevent_work);
1803 unsigned long flags;
1805 if (orinoco_lock(priv, &flags) != 0)
1808 orinoco_send_assocreqie_wevent(priv);
1809 orinoco_send_assocrespie_wevent(priv);
1810 orinoco_send_bssid_wevent(priv);
1812 orinoco_unlock(priv, &flags);
1815 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1817 struct orinoco_private *priv = netdev_priv(dev);
1822 } __attribute__ ((packed)) info;
1826 /* This is an answer to an INQUIRE command that we did earlier,
1827 * or an information "event" generated by the card
1828 * The controller return to us a pseudo frame containing
1829 * the information in question - Jean II */
1830 infofid = hermes_read_regn(hw, INFOFID);
1832 /* Read the info frame header - don't try too hard */
1833 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1836 printk(KERN_ERR "%s: error %d reading info frame. "
1837 "Frame dropped.\n", dev->name, err);
1841 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1842 type = le16_to_cpu(info.type);
1845 case HERMES_INQ_TALLIES: {
1846 struct hermes_tallies_frame tallies;
1847 struct iw_statistics *wstats = &priv->wstats;
1849 if (len > sizeof(tallies)) {
1850 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1852 len = sizeof(tallies);
1855 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1856 infofid, sizeof(info));
1860 /* Increment our various counters */
1861 /* wstats->discard.nwid - no wrong BSSID stuff */
1862 wstats->discard.code +=
1863 le16_to_cpu(tallies.RxWEPUndecryptable);
1864 if (len == sizeof(tallies))
1865 wstats->discard.code +=
1866 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1867 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1868 wstats->discard.misc +=
1869 le16_to_cpu(tallies.TxDiscardsWrongSA);
1870 wstats->discard.fragment +=
1871 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1872 wstats->discard.retries +=
1873 le16_to_cpu(tallies.TxRetryLimitExceeded);
1874 /* wstats->miss.beacon - no match */
1877 case HERMES_INQ_LINKSTATUS: {
1878 struct hermes_linkstatus linkstatus;
1882 if (priv->iw_mode == IW_MODE_MONITOR)
1885 if (len != sizeof(linkstatus)) {
1886 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1891 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1892 infofid, sizeof(info));
1895 newstatus = le16_to_cpu(linkstatus.linkstatus);
1897 /* Symbol firmware uses "out of range" to signal that
1898 * the hostscan frame can be requested. */
1899 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1900 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1901 priv->has_hostscan && priv->scan_inprogress) {
1902 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1906 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1907 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1908 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1911 netif_carrier_on(dev);
1912 else if (!ignore_disconnect)
1913 netif_carrier_off(dev);
1915 if (newstatus != priv->last_linkstatus) {
1916 priv->last_linkstatus = newstatus;
1917 print_linkstatus(dev, newstatus);
1918 /* The info frame contains only one word which is the
1919 * status (see hermes.h). The status is pretty boring
1920 * in itself, that's why we export the new BSSID...
1922 schedule_work(&priv->wevent_work);
1926 case HERMES_INQ_SCAN:
1927 if (!priv->scan_inprogress && priv->bssid_fixed &&
1928 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1929 schedule_work(&priv->join_work);
1933 case HERMES_INQ_HOSTSCAN:
1934 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1935 /* Result of a scanning. Contains information about
1936 * cells in the vicinity - Jean II */
1937 union iwreq_data wrqu;
1940 /* Scan is no longer in progress */
1941 priv->scan_inprogress = 0;
1945 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1950 /* Allocate buffer for results */
1951 buf = kmalloc(len, GFP_ATOMIC);
1953 /* No memory, so can't printk()... */
1956 /* Read scan data */
1957 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1958 infofid, sizeof(info));
1964 #ifdef ORINOCO_DEBUG
1967 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1968 for (i = 1; i < (len * 2); i++)
1969 printk(":%02X", buf[i]);
1972 #endif /* ORINOCO_DEBUG */
1974 if (orinoco_process_scan_results(priv, buf, len) == 0) {
1975 /* Send an empty event to user space.
1976 * We don't send the received data on the event because
1977 * it would require us to do complex transcoding, and
1978 * we want to minimise the work done in the irq handler
1979 * Use a request to extract the data - Jean II */
1980 wrqu.data.length = 0;
1981 wrqu.data.flags = 0;
1982 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1987 case HERMES_INQ_CHANNELINFO:
1989 struct agere_ext_scan_info *bss;
1991 if (!priv->scan_inprogress) {
1992 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1993 "len=%d\n", dev->name, len);
1997 /* An empty result indicates that the scan is complete */
1999 union iwreq_data wrqu;
2001 /* Scan is no longer in progress */
2002 priv->scan_inprogress = 0;
2004 wrqu.data.length = 0;
2005 wrqu.data.flags = 0;
2006 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2011 else if (len > sizeof(*bss)) {
2013 "%s: Ext scan results too large (%d bytes). "
2014 "Truncating results to %zd bytes.\n",
2015 dev->name, len, sizeof(*bss));
2017 } else if (len < (offsetof(struct agere_ext_scan_info,
2019 /* Drop this result now so we don't have to
2020 * keep checking later */
2022 "%s: Ext scan results too short (%d bytes)\n",
2027 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
2031 /* Read scan data */
2032 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
2033 infofid, sizeof(info));
2039 orinoco_add_ext_scan_result(priv, bss);
2044 case HERMES_INQ_SEC_STAT_AGERE:
2045 /* Security status (Agere specific) */
2046 /* Ignore this frame for now */
2047 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2051 printk(KERN_DEBUG "%s: Unknown information frame received: "
2052 "type 0x%04x, length %d\n", dev->name, type, len);
2053 /* We don't actually do anything about it */
2058 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
2060 if (net_ratelimit())
2061 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
2064 /********************************************************************/
2065 /* Internal hardware control routines */
2066 /********************************************************************/
2068 int __orinoco_up(struct net_device *dev)
2070 struct orinoco_private *priv = netdev_priv(dev);
2071 struct hermes *hw = &priv->hw;
2074 netif_carrier_off(dev); /* just to make sure */
2076 err = __orinoco_program_rids(dev);
2078 printk(KERN_ERR "%s: Error %d configuring card\n",
2083 /* Fire things up again */
2084 hermes_set_irqmask(hw, ORINOCO_INTEN);
2085 err = hermes_enable_port(hw, 0);
2087 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2092 netif_start_queue(dev);
2096 EXPORT_SYMBOL(__orinoco_up);
2098 int __orinoco_down(struct net_device *dev)
2100 struct orinoco_private *priv = netdev_priv(dev);
2101 struct hermes *hw = &priv->hw;
2104 netif_stop_queue(dev);
2106 if (!priv->hw_unavailable) {
2107 if (!priv->broken_disableport) {
2108 err = hermes_disable_port(hw, 0);
2110 /* Some firmwares (e.g. Intersil 1.3.x) seem
2111 * to have problems disabling the port, oh
2113 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2115 priv->broken_disableport = 1;
2118 hermes_set_irqmask(hw, 0);
2119 hermes_write_regn(hw, EVACK, 0xffff);
2122 /* firmware will have to reassociate */
2123 netif_carrier_off(dev);
2124 priv->last_linkstatus = 0xffff;
2128 EXPORT_SYMBOL(__orinoco_down);
2130 static int orinoco_allocate_fid(struct net_device *dev)
2132 struct orinoco_private *priv = netdev_priv(dev);
2133 struct hermes *hw = &priv->hw;
2136 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2137 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
2138 /* Try workaround for old Symbol firmware bug */
2139 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2140 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2142 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2143 "(old Symbol firmware?). Work around %s\n",
2144 dev->name, err ? "failed!" : "ok.");
2150 int orinoco_reinit_firmware(struct net_device *dev)
2152 struct orinoco_private *priv = netdev_priv(dev);
2153 struct hermes *hw = &priv->hw;
2156 err = hermes_init(hw);
2157 if (priv->do_fw_download && !err) {
2158 err = orinoco_download(priv);
2160 priv->do_fw_download = 0;
2163 err = orinoco_allocate_fid(dev);
2167 EXPORT_SYMBOL(orinoco_reinit_firmware);
2169 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2171 hermes_t *hw = &priv->hw;
2172 int ratemode = priv->bitratemode;
2175 if (ratemode >= BITRATE_TABLE_SIZE) {
2176 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
2177 priv->ndev->name, ratemode);
2181 switch (priv->firmware_type) {
2182 case FIRMWARE_TYPE_AGERE:
2183 err = hermes_write_wordrec(hw, USER_BAP,
2184 HERMES_RID_CNFTXRATECONTROL,
2185 bitrate_table[ratemode].agere_txratectrl);
2187 case FIRMWARE_TYPE_INTERSIL:
2188 case FIRMWARE_TYPE_SYMBOL:
2189 err = hermes_write_wordrec(hw, USER_BAP,
2190 HERMES_RID_CNFTXRATECONTROL,
2191 bitrate_table[ratemode].intersil_txratectrl);
2200 /* Set fixed AP address */
2201 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2205 hermes_t *hw = &priv->hw;
2207 switch (priv->firmware_type) {
2208 case FIRMWARE_TYPE_AGERE:
2211 case FIRMWARE_TYPE_INTERSIL:
2212 if (priv->bssid_fixed)
2217 err = hermes_write_wordrec(hw, USER_BAP,
2218 HERMES_RID_CNFROAMINGMODE,
2221 case FIRMWARE_TYPE_SYMBOL:
2222 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2223 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2224 &priv->desired_bssid);
2230 /* Change the WEP keys and/or the current keys. Can be called
2231 * either from __orinoco_hw_setup_enc() or directly from
2232 * orinoco_ioctl_setiwencode(). In the later case the association
2233 * with the AP is not broken (if the firmware can handle it),
2234 * which is needed for 802.1x implementations. */
2235 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2237 hermes_t *hw = &priv->hw;
2240 switch (priv->firmware_type) {
2241 case FIRMWARE_TYPE_AGERE:
2242 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2243 HERMES_RID_CNFWEPKEYS_AGERE,
2247 err = hermes_write_wordrec(hw, USER_BAP,
2248 HERMES_RID_CNFTXKEY_AGERE,
2253 case FIRMWARE_TYPE_INTERSIL:
2254 case FIRMWARE_TYPE_SYMBOL:
2259 /* Force uniform key length to work around
2261 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
2263 if (keylen > LARGE_KEY_SIZE) {
2264 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2265 priv->ndev->name, priv->tx_key, keylen);
2269 /* Write all 4 keys */
2270 for (i = 0; i < ORINOCO_MAX_KEYS; i++) {
2271 err = hermes_write_ltv(hw, USER_BAP,
2272 HERMES_RID_CNFDEFAULTKEY0 + i,
2273 HERMES_BYTES_TO_RECLEN(keylen),
2274 priv->keys[i].data);
2279 /* Write the index of the key used in transmission */
2280 err = hermes_write_wordrec(hw, USER_BAP,
2281 HERMES_RID_CNFWEPDEFAULTKEYID,
2292 static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
2294 hermes_t *hw = &priv->hw;
2296 int master_wep_flag;
2300 /* Setup WEP keys for WEP and WPA */
2301 if (priv->encode_alg)
2302 __orinoco_hw_setup_wepkeys(priv);
2304 if (priv->wep_restrict)
2305 auth_flag = HERMES_AUTH_SHARED_KEY;
2307 auth_flag = HERMES_AUTH_OPEN;
2309 if (priv->wpa_enabled)
2311 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
2316 switch (priv->firmware_type) {
2317 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
2318 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2319 /* Enable the shared-key authentication. */
2320 err = hermes_write_wordrec(hw, USER_BAP,
2321 HERMES_RID_CNFAUTHENTICATION_AGERE,
2324 err = hermes_write_wordrec(hw, USER_BAP,
2325 HERMES_RID_CNFWEPENABLED_AGERE,
2330 if (priv->has_wpa) {
2331 /* Set WPA key management */
2332 err = hermes_write_wordrec(hw, USER_BAP,
2333 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2341 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2342 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
2343 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2344 if (priv->wep_restrict ||
2345 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2346 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2347 HERMES_WEP_EXCL_UNENCRYPTED;
2349 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2351 err = hermes_write_wordrec(hw, USER_BAP,
2352 HERMES_RID_CNFAUTHENTICATION,
2357 master_wep_flag = 0;
2359 if (priv->iw_mode == IW_MODE_MONITOR)
2360 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2362 /* Master WEP setting : on/off */
2363 err = hermes_write_wordrec(hw, USER_BAP,
2364 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2375 /* key must be 32 bytes, including the tx and rx MIC keys.
2376 * rsc must be 8 bytes
2377 * tsc must be 8 bytes or NULL
2379 static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2380 u8 *key, u8 *rsc, u8 *tsc)
2384 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2385 u8 key[TKIP_KEYLEN];
2386 u8 tx_mic[MIC_KEYLEN];
2387 u8 rx_mic[MIC_KEYLEN];
2388 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2389 } __attribute__ ((packed)) buf;
2400 buf.idx = cpu_to_le16(key_idx);
2401 memcpy(buf.key, key,
2402 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2405 memset(buf.rsc, 0, sizeof(buf.rsc));
2407 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2410 memset(buf.tsc, 0, sizeof(buf.tsc));
2413 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2416 /* Wait upto 100ms for tx queue to empty */
2421 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2425 } while ((k > 0) && xmitting);
2430 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2431 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2434 return ret ? ret : err;
2437 static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2440 hermes_t *hw = &priv->hw;
2443 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2444 err = hermes_write_wordrec(hw, USER_BAP,
2445 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2448 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2449 priv->ndev->name, err, key_idx);
2453 static int __orinoco_program_rids(struct net_device *dev)
2455 struct orinoco_private *priv = netdev_priv(dev);
2456 hermes_t *hw = &priv->hw;
2458 struct hermes_idstring idbuf;
2460 /* Set the MAC address */
2461 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2462 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2464 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2469 /* Set up the link mode */
2470 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2473 printk(KERN_ERR "%s: Error %d setting port type\n",
2477 /* Set the channel/frequency */
2478 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2479 err = hermes_write_wordrec(hw, USER_BAP,
2480 HERMES_RID_CNFOWNCHANNEL,
2483 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2484 dev->name, err, priv->channel);
2489 if (priv->has_ibss) {
2492 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2493 printk(KERN_WARNING "%s: This firmware requires an "
2494 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2495 /* With wvlan_cs, in this case, we would crash.
2496 * hopefully, this driver will behave better...
2500 createibss = priv->createibss;
2503 err = hermes_write_wordrec(hw, USER_BAP,
2504 HERMES_RID_CNFCREATEIBSS,
2507 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2513 /* Set the desired BSSID */
2514 err = __orinoco_hw_set_wap(priv);
2516 printk(KERN_ERR "%s: Error %d setting AP address\n",
2520 /* Set the desired ESSID */
2521 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2522 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2523 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2524 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2525 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2528 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2532 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2533 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2536 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2541 /* Set the station name */
2542 idbuf.len = cpu_to_le16(strlen(priv->nick));
2543 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2544 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2545 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2548 printk(KERN_ERR "%s: Error %d setting nickname\n",
2553 /* Set AP density */
2554 if (priv->has_sensitivity) {
2555 err = hermes_write_wordrec(hw, USER_BAP,
2556 HERMES_RID_CNFSYSTEMSCALE,
2559 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2560 "Disabling sensitivity control\n",
2563 priv->has_sensitivity = 0;
2567 /* Set RTS threshold */
2568 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2571 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2576 /* Set fragmentation threshold or MWO robustness */
2578 err = hermes_write_wordrec(hw, USER_BAP,
2579 HERMES_RID_CNFMWOROBUST_AGERE,
2582 err = hermes_write_wordrec(hw, USER_BAP,
2583 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2586 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2592 err = __orinoco_hw_set_bitrate(priv);
2594 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2599 /* Set power management */
2601 err = hermes_write_wordrec(hw, USER_BAP,
2602 HERMES_RID_CNFPMENABLED,
2605 printk(KERN_ERR "%s: Error %d setting up PM\n",
2610 err = hermes_write_wordrec(hw, USER_BAP,
2611 HERMES_RID_CNFMULTICASTRECEIVE,
2614 printk(KERN_ERR "%s: Error %d setting up PM\n",
2618 err = hermes_write_wordrec(hw, USER_BAP,
2619 HERMES_RID_CNFMAXSLEEPDURATION,
2622 printk(KERN_ERR "%s: Error %d setting up PM\n",
2626 err = hermes_write_wordrec(hw, USER_BAP,
2627 HERMES_RID_CNFPMHOLDOVERDURATION,
2630 printk(KERN_ERR "%s: Error %d setting up PM\n",
2636 /* Set preamble - only for Symbol so far... */
2637 if (priv->has_preamble) {
2638 err = hermes_write_wordrec(hw, USER_BAP,
2639 HERMES_RID_CNFPREAMBLE_SYMBOL,
2642 printk(KERN_ERR "%s: Error %d setting preamble\n",
2648 /* Set up encryption */
2649 if (priv->has_wep || priv->has_wpa) {
2650 err = __orinoco_hw_setup_enc(priv);
2652 printk(KERN_ERR "%s: Error %d activating encryption\n",
2658 if (priv->iw_mode == IW_MODE_MONITOR) {
2659 /* Enable monitor mode */
2660 dev->type = ARPHRD_IEEE80211;
2661 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2662 HERMES_TEST_MONITOR, 0, NULL);
2664 /* Disable monitor mode */
2665 dev->type = ARPHRD_ETHER;
2666 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2667 HERMES_TEST_STOP, 0, NULL);
2672 /* Set promiscuity / multicast*/
2673 priv->promiscuous = 0;
2676 /* FIXME: what about netif_tx_lock */
2677 __orinoco_set_multicast_list(dev);
2682 /* FIXME: return int? */
2684 __orinoco_set_multicast_list(struct net_device *dev)
2686 struct orinoco_private *priv = netdev_priv(dev);
2687 hermes_t *hw = &priv->hw;
2689 int promisc, mc_count;
2691 /* The Hermes doesn't seem to have an allmulti mode, so we go
2692 * into promiscuous mode and let the upper levels deal. */
2693 if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2694 (dev->mc_count > MAX_MULTICAST(priv))) {
2699 mc_count = dev->mc_count;
2702 if (promisc != priv->promiscuous) {
2703 err = hermes_write_wordrec(hw, USER_BAP,
2704 HERMES_RID_CNFPROMISCUOUSMODE,
2707 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2710 priv->promiscuous = promisc;
2713 /* If we're not in promiscuous mode, then we need to set the
2714 * group address if either we want to multicast, or if we were
2715 * multicasting and want to stop */
2716 if (!promisc && (mc_count || priv->mc_count)) {
2717 struct dev_mc_list *p = dev->mc_list;
2718 struct hermes_multicast mclist;
2721 for (i = 0; i < mc_count; i++) {
2722 /* paranoia: is list shorter than mc_count? */
2724 /* paranoia: bad address size in list? */
2725 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2727 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2732 printk(KERN_WARNING "%s: Multicast list is "
2733 "longer than mc_count\n", dev->name);
2735 err = hermes_write_ltv(hw, USER_BAP,
2736 HERMES_RID_CNFGROUPADDRESSES,
2737 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2740 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2743 priv->mc_count = mc_count;
2747 /* This must be called from user context, without locks held - use
2748 * schedule_work() */
2749 static void orinoco_reset(struct work_struct *work)
2751 struct orinoco_private *priv =
2752 container_of(work, struct orinoco_private, reset_work);
2753 struct net_device *dev = priv->ndev;
2754 struct hermes *hw = &priv->hw;
2756 unsigned long flags;
2758 if (orinoco_lock(priv, &flags) != 0)
2759 /* When the hardware becomes available again, whatever
2760 * detects that is responsible for re-initializing
2761 * it. So no need for anything further */
2764 netif_stop_queue(dev);
2766 /* Shut off interrupts. Depending on what state the hardware
2767 * is in, this might not work, but we'll try anyway */
2768 hermes_set_irqmask(hw, 0);
2769 hermes_write_regn(hw, EVACK, 0xffff);
2771 priv->hw_unavailable++;
2772 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2773 netif_carrier_off(dev);
2775 orinoco_unlock(priv, &flags);
2777 /* Scanning support: Cleanup of driver struct */
2778 orinoco_clear_scan_results(priv, 0);
2779 priv->scan_inprogress = 0;
2781 if (priv->hard_reset) {
2782 err = (*priv->hard_reset)(priv);
2784 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2785 "performing hard reset\n", dev->name, err);
2790 err = orinoco_reinit_firmware(dev);
2792 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2797 /* This has to be called from user context */
2798 spin_lock_irq(&priv->lock);
2800 priv->hw_unavailable--;
2802 /* priv->open or priv->hw_unavailable might have changed while
2803 * we dropped the lock */
2804 if (priv->open && (!priv->hw_unavailable)) {
2805 err = __orinoco_up(dev);
2807 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2810 dev->trans_start = jiffies;
2813 spin_unlock_irq(&priv->lock);
2817 hermes_set_irqmask(hw, 0);
2818 netif_device_detach(dev);
2819 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2822 /********************************************************************/
2823 /* Interrupt handler */
2824 /********************************************************************/
2826 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2828 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2831 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2833 /* This seems to happen a fair bit under load, but ignoring it
2834 seems to work fine...*/
2835 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2839 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2841 struct net_device *dev = dev_id;
2842 struct orinoco_private *priv = netdev_priv(dev);
2843 hermes_t *hw = &priv->hw;
2844 int count = MAX_IRQLOOPS_PER_IRQ;
2846 /* These are used to detect a runaway interrupt situation.
2848 * If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2849 * we panic and shut down the hardware
2851 /* jiffies value the last time we were called */
2852 static int last_irq_jiffy; /* = 0 */
2853 static int loops_this_jiffy; /* = 0 */
2854 unsigned long flags;
2856 if (orinoco_lock(priv, &flags) != 0) {
2857 /* If hw is unavailable - we don't know if the irq was
2862 evstat = hermes_read_regn(hw, EVSTAT);
2863 events = evstat & hw->inten;
2865 orinoco_unlock(priv, &flags);
2869 if (jiffies != last_irq_jiffy)
2870 loops_this_jiffy = 0;
2871 last_irq_jiffy = jiffies;
2873 while (events && count--) {
2874 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2875 printk(KERN_WARNING "%s: IRQ handler is looping too "
2876 "much! Resetting.\n", dev->name);
2877 /* Disable interrupts for now */
2878 hermes_set_irqmask(hw, 0);
2879 schedule_work(&priv->reset_work);
2883 /* Check the card hasn't been removed */
2884 if (!hermes_present(hw)) {
2885 DEBUG(0, "orinoco_interrupt(): card removed\n");
2889 if (events & HERMES_EV_TICK)
2890 __orinoco_ev_tick(dev, hw);
2891 if (events & HERMES_EV_WTERR)
2892 __orinoco_ev_wterr(dev, hw);
2893 if (events & HERMES_EV_INFDROP)
2894 __orinoco_ev_infdrop(dev, hw);
2895 if (events & HERMES_EV_INFO)
2896 __orinoco_ev_info(dev, hw);
2897 if (events & HERMES_EV_RX)
2898 __orinoco_ev_rx(dev, hw);
2899 if (events & HERMES_EV_TXEXC)
2900 __orinoco_ev_txexc(dev, hw);
2901 if (events & HERMES_EV_TX)
2902 __orinoco_ev_tx(dev, hw);
2903 if (events & HERMES_EV_ALLOC)
2904 __orinoco_ev_alloc(dev, hw);
2906 hermes_write_regn(hw, EVACK, evstat);
2908 evstat = hermes_read_regn(hw, EVSTAT);
2909 events = evstat & hw->inten;
2912 orinoco_unlock(priv, &flags);
2915 EXPORT_SYMBOL(orinoco_interrupt);
2917 /********************************************************************/
2918 /* Power management */
2919 /********************************************************************/
2920 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
2921 static int orinoco_pm_notifier(struct notifier_block *notifier,
2922 unsigned long pm_event,
2925 struct orinoco_private *priv = container_of(notifier,
2926 struct orinoco_private,
2929 /* All we need to do is cache the firmware before suspend, and
2930 * release it when we come out.
2932 * Only need to do this if we're downloading firmware. */
2933 if (!priv->do_fw_download)
2937 case PM_HIBERNATION_PREPARE:
2938 case PM_SUSPEND_PREPARE:
2939 orinoco_cache_fw(priv, 0);
2942 case PM_POST_RESTORE:
2943 /* Restore from hibernation failed. We need to clean
2944 * up in exactly the same way, so fall through. */
2945 case PM_POST_HIBERNATION:
2946 case PM_POST_SUSPEND:
2947 orinoco_uncache_fw(priv);
2950 case PM_RESTORE_PREPARE:
2957 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
2958 #define orinoco_pm_notifier NULL
2961 /********************************************************************/
2962 /* Initialization */
2963 /********************************************************************/
2966 u16 id, variant, major, minor;
2967 } __attribute__ ((packed));
2969 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2971 if (nic_id->id < 0x8000)
2972 return FIRMWARE_TYPE_AGERE;
2973 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2974 return FIRMWARE_TYPE_SYMBOL;
2976 return FIRMWARE_TYPE_INTERSIL;
2979 /* Set priv->firmware type, determine firmware properties */
2980 static int determine_firmware(struct net_device *dev)
2982 struct orinoco_private *priv = netdev_priv(dev);
2983 hermes_t *hw = &priv->hw;
2985 struct comp_id nic_id, sta_id;
2986 unsigned int firmver;
2987 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2989 /* Get the hardware version */
2990 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2992 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2997 le16_to_cpus(&nic_id.id);
2998 le16_to_cpus(&nic_id.variant);
2999 le16_to_cpus(&nic_id.major);
3000 le16_to_cpus(&nic_id.minor);
3001 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
3002 dev->name, nic_id.id, nic_id.variant,
3003 nic_id.major, nic_id.minor);
3005 priv->firmware_type = determine_firmware_type(&nic_id);
3007 /* Get the firmware version */
3008 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
3010 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
3015 le16_to_cpus(&sta_id.id);
3016 le16_to_cpus(&sta_id.variant);
3017 le16_to_cpus(&sta_id.major);
3018 le16_to_cpus(&sta_id.minor);
3019 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
3020 dev->name, sta_id.id, sta_id.variant,
3021 sta_id.major, sta_id.minor);
3023 switch (sta_id.id) {
3025 printk(KERN_ERR "%s: Primary firmware is active\n",
3029 printk(KERN_ERR "%s: Tertiary firmware is active\n",
3032 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3033 case 0x21: /* Symbol Spectrum24 Trilogy */
3036 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
3041 /* Default capabilities */
3042 priv->has_sensitivity = 1;
3044 priv->has_preamble = 0;
3045 priv->has_port3 = 1;
3048 priv->has_big_wep = 0;
3049 priv->has_alt_txcntl = 0;
3050 priv->has_ext_scan = 0;
3052 priv->do_fw_download = 0;
3054 /* Determine capabilities from the firmware version */
3055 switch (priv->firmware_type) {
3056 case FIRMWARE_TYPE_AGERE:
3057 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3058 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3059 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3060 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
3062 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
3064 priv->has_ibss = (firmver >= 0x60006);
3065 priv->has_wep = (firmver >= 0x40020);
3066 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
3067 Gold cards from the others? */
3068 priv->has_mwo = (firmver >= 0x60000);
3069 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3070 priv->ibss_port = 1;
3071 priv->has_hostscan = (firmver >= 0x8000a);
3072 priv->do_fw_download = 1;
3073 priv->broken_monitor = (firmver >= 0x80000);
3074 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
3075 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
3076 priv->has_wpa = (firmver >= 0x9002a);
3077 /* Tested with Agere firmware :
3078 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3079 * Tested CableTron firmware : 4.32 => Anton */
3081 case FIRMWARE_TYPE_SYMBOL:
3082 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3083 /* Intel MAC : 00:02:B3:* */
3084 /* 3Com MAC : 00:50:DA:* */
3085 memset(tmp, 0, sizeof(tmp));
3086 /* Get the Symbol firmware version */
3087 err = hermes_read_ltv(hw, USER_BAP,
3088 HERMES_RID_SECONDARYVERSION_SYMBOL,
3089 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3092 "%s: Error %d reading Symbol firmware info. "
3093 "Wildly guessing capabilities...\n",
3098 /* The firmware revision is a string, the format is
3099 * something like : "V2.20-01".
3100 * Quick and dirty parsing... - Jean II
3102 firmver = ((tmp[1] - '0') << 16)
3103 | ((tmp[3] - '0') << 12)
3104 | ((tmp[4] - '0') << 8)
3105 | ((tmp[6] - '0') << 4)
3108 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3111 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3114 priv->has_ibss = (firmver >= 0x20000);
3115 priv->has_wep = (firmver >= 0x15012);
3116 priv->has_big_wep = (firmver >= 0x20000);
3117 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
3118 (firmver >= 0x29000 && firmver < 0x30000) ||
3120 priv->has_preamble = (firmver >= 0x20000);
3121 priv->ibss_port = 4;
3123 /* Symbol firmware is found on various cards, but
3124 * there has been no attempt to check firmware
3125 * download on non-spectrum_cs based cards.
3127 * Given that the Agere firmware download works
3128 * differently, we should avoid doing a firmware
3129 * download with the Symbol algorithm on non-spectrum
3132 * For now we can identify a spectrum_cs based card
3133 * because it has a firmware reset function.
3135 priv->do_fw_download = (priv->stop_fw != NULL);
3137 priv->broken_disableport = (firmver == 0x25013) ||
3138 (firmver >= 0x30000 && firmver <= 0x31000);
3139 priv->has_hostscan = (firmver >= 0x31001) ||
3140 (firmver >= 0x29057 && firmver < 0x30000);
3141 /* Tested with Intel firmware : 0x20015 => Jean II */
3142 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3144 case FIRMWARE_TYPE_INTERSIL:
3145 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3146 * Samsung, Compaq 100/200 and Proxim are slightly
3147 * different and less well tested */
3148 /* D-Link MAC : 00:40:05:* */
3149 /* Addtron MAC : 00:90:D1:* */
3150 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3151 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3154 firmver = ((unsigned long)sta_id.major << 16) |
3155 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3157 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3158 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3159 priv->has_pm = (firmver >= 0x000700);
3160 priv->has_hostscan = (firmver >= 0x010301);
3162 if (firmver >= 0x000800)
3163 priv->ibss_port = 0;
3165 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3166 "than v0.8.x - several features not supported\n",
3168 priv->ibss_port = 1;
3172 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3178 static int orinoco_init(struct net_device *dev)
3180 struct orinoco_private *priv = netdev_priv(dev);
3181 hermes_t *hw = &priv->hw;
3183 struct hermes_idstring nickbuf;
3187 /* No need to lock, the hw_unavailable flag is already set in
3188 * alloc_orinocodev() */
3189 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
3191 /* Initialize the firmware */
3192 err = hermes_init(hw);
3194 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3199 err = determine_firmware(dev);
3201 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3206 if (priv->do_fw_download) {
3207 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
3208 orinoco_cache_fw(priv, 0);
3211 err = orinoco_download(priv);
3213 priv->do_fw_download = 0;
3215 /* Check firmware version again */
3216 err = determine_firmware(dev);
3218 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3224 if (priv->has_port3)
3225 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n",
3228 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3230 if (priv->has_wep) {
3231 printk(KERN_DEBUG "%s: WEP supported, %s-bit key\n", dev->name,
3232 priv->has_big_wep ? "104" : "40");
3234 if (priv->has_wpa) {
3235 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
3236 if (orinoco_mic_init(priv)) {
3237 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3238 "algorithm. Disabling WPA support\n", dev->name);
3243 /* Now we have the firmware capabilities, allocate appropiate
3244 * sized scan buffers */
3245 if (orinoco_bss_data_allocate(priv))
3247 orinoco_bss_data_init(priv);
3249 /* Get the MAC address */
3250 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3251 ETH_ALEN, NULL, dev->dev_addr);
3253 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3258 printk(KERN_DEBUG "%s: MAC address %pM\n",
3259 dev->name, dev->dev_addr);
3261 /* Get the station name */
3262 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3263 sizeof(nickbuf), &reclen, &nickbuf);
3265 printk(KERN_ERR "%s: failed to read station name\n",
3270 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3272 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3273 memcpy(priv->nick, &nickbuf.val, len);
3274 priv->nick[len] = '\0';
3276 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3278 err = orinoco_allocate_fid(dev);
3280 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3285 /* Get allowed channels */
3286 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3287 &priv->channel_mask);
3289 printk(KERN_ERR "%s: failed to read channel list!\n",
3294 /* Get initial AP density */
3295 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3297 if (err || priv->ap_density < 1 || priv->ap_density > 3)
3298 priv->has_sensitivity = 0;
3300 /* Get initial RTS threshold */
3301 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3304 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3309 /* Get initial fragmentation settings */
3311 err = hermes_read_wordrec(hw, USER_BAP,
3312 HERMES_RID_CNFMWOROBUST_AGERE,
3315 err = hermes_read_wordrec(hw, USER_BAP,
3316 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3317 &priv->frag_thresh);
3319 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3324 /* Power management setup */
3328 err = hermes_read_wordrec(hw, USER_BAP,
3329 HERMES_RID_CNFMAXSLEEPDURATION,
3332 printk(KERN_ERR "%s: failed to read power management period!\n",
3336 err = hermes_read_wordrec(hw, USER_BAP,
3337 HERMES_RID_CNFPMHOLDOVERDURATION,
3340 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3346 /* Preamble setup */
3347 if (priv->has_preamble) {
3348 err = hermes_read_wordrec(hw, USER_BAP,
3349 HERMES_RID_CNFPREAMBLE_SYMBOL,
3355 /* Set up the default configuration */
3356 priv->iw_mode = IW_MODE_INFRA;
3357 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3358 priv->prefer_port3 = priv->has_port3 && (!priv->has_ibss);
3359 set_port_type(priv);
3360 priv->channel = 0; /* use firmware default */
3362 priv->promiscuous = 0;
3363 priv->encode_alg = IW_ENCODE_ALG_NONE;
3365 priv->wpa_enabled = 0;
3366 priv->tkip_cm_active = 0;
3368 priv->wpa_ie_len = 0;
3369 priv->wpa_ie = NULL;
3371 /* Make the hardware available, as long as it hasn't been
3372 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3373 spin_lock_irq(&priv->lock);
3374 priv->hw_unavailable--;
3375 spin_unlock_irq(&priv->lock);
3377 printk(KERN_DEBUG "%s: ready\n", dev->name);
3383 static const struct net_device_ops orinoco_netdev_ops = {
3384 .ndo_init = orinoco_init,
3385 .ndo_open = orinoco_open,
3386 .ndo_stop = orinoco_stop,
3387 .ndo_start_xmit = orinoco_xmit,
3388 .ndo_set_multicast_list = orinoco_set_multicast_list,
3389 .ndo_change_mtu = orinoco_change_mtu,
3390 .ndo_tx_timeout = orinoco_tx_timeout,
3391 .ndo_get_stats = orinoco_get_stats,
3395 *alloc_orinocodev(int sizeof_card,
3396 struct device *device,
3397 int (*hard_reset)(struct orinoco_private *),
3398 int (*stop_fw)(struct orinoco_private *, int))
3400 struct net_device *dev;
3401 struct orinoco_private *priv;
3403 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
3406 priv = netdev_priv(dev);
3409 priv->card = (void *)((unsigned long)priv
3410 + sizeof(struct orinoco_private));
3415 /* Setup / override net_device fields */
3416 dev->netdev_ops = &orinoco_netdev_ops;
3417 dev->watchdog_timeo = HZ; /* 1 second timeout */
3418 dev->ethtool_ops = &orinoco_ethtool_ops;
3419 dev->wireless_handlers = &orinoco_handler_def;
3421 priv->wireless_data.spy_data = &priv->spy_data;
3422 dev->wireless_data = &priv->wireless_data;
3424 /* we use the default eth_mac_addr for setting the MAC addr */
3426 /* Reserve space in skb for the SNAP header */
3427 dev->hard_header_len += ENCAPS_OVERHEAD;
3429 /* Set up default callbacks */
3430 priv->hard_reset = hard_reset;
3431 priv->stop_fw = stop_fw;
3433 spin_lock_init(&priv->lock);
3435 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3436 * before anything else touches the
3438 INIT_WORK(&priv->reset_work, orinoco_reset);
3439 INIT_WORK(&priv->join_work, orinoco_join_ap);
3440 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
3442 INIT_LIST_HEAD(&priv->rx_list);
3443 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3444 (unsigned long) dev);
3446 netif_carrier_off(dev);
3447 priv->last_linkstatus = 0xffff;
3449 priv->cached_pri_fw = NULL;
3450 priv->cached_fw = NULL;
3452 /* Register PM notifiers */
3453 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
3454 register_pm_notifier(&priv->pm_notifier);
3458 EXPORT_SYMBOL(alloc_orinocodev);
3460 void free_orinocodev(struct net_device *dev)
3462 struct orinoco_private *priv = netdev_priv(dev);
3463 struct orinoco_rx_data *rx_data, *temp;
3465 /* If the tasklet is scheduled when we call tasklet_kill it
3466 * will run one final time. However the tasklet will only
3467 * drain priv->rx_list if the hw is still available. */
3468 tasklet_kill(&priv->rx_tasklet);
3470 /* Explicitly drain priv->rx_list */
3471 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
3472 list_del(&rx_data->list);
3474 dev_kfree_skb(rx_data->skb);
3475 kfree(rx_data->desc);
3479 unregister_pm_notifier(&priv->pm_notifier);
3480 orinoco_uncache_fw(priv);
3482 priv->wpa_ie_len = 0;
3483 kfree(priv->wpa_ie);
3484 orinoco_mic_free(priv);
3485 orinoco_bss_data_free(priv);
3488 EXPORT_SYMBOL(free_orinocodev);
3490 /********************************************************************/
3491 /* Wireless extensions */
3492 /********************************************************************/
3494 /* Return : < 0 -> error code ; >= 0 -> length */
3495 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3496 char buf[IW_ESSID_MAX_SIZE+1])
3498 hermes_t *hw = &priv->hw;
3500 struct hermes_idstring essidbuf;
3501 char *p = (char *)(&essidbuf.val);
3503 unsigned long flags;
3505 if (orinoco_lock(priv, &flags) != 0)
3508 if (strlen(priv->desired_essid) > 0) {
3509 /* We read the desired SSID from the hardware rather
3510 than from priv->desired_essid, just in case the
3511 firmware is allowed to change it on us. I'm not
3513 /* My guess is that the OWNSSID should always be whatever
3514 * we set to the card, whereas CURRENT_SSID is the one that
3515 * may change... - Jean II */
3520 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3521 HERMES_RID_CNFDESIREDSSID;
3523 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3530 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3531 sizeof(essidbuf), NULL, &essidbuf);
3536 len = le16_to_cpu(essidbuf.len);
3537 BUG_ON(len > IW_ESSID_MAX_SIZE);
3539 memset(buf, 0, IW_ESSID_MAX_SIZE);
3540 memcpy(buf, p, len);
3544 orinoco_unlock(priv, &flags);
3549 static int orinoco_hw_get_freq(struct orinoco_private *priv)
3552 hermes_t *hw = &priv->hw;
3556 unsigned long flags;
3558 if (orinoco_lock(priv, &flags) != 0)
3561 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL,
3566 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3572 if ((channel < 1) || (channel > NUM_CHANNELS)) {
3573 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3574 priv->ndev->name, channel);
3579 freq = ieee80211_dsss_chan_to_freq(channel);
3582 orinoco_unlock(priv, &flags);
3586 return err ? err : freq;
3589 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3590 int *numrates, s32 *rates, int max)
3592 hermes_t *hw = &priv->hw;
3593 struct hermes_idstring list;
3594 unsigned char *p = (unsigned char *)&list.val;
3598 unsigned long flags;
3600 if (orinoco_lock(priv, &flags) != 0)
3603 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3604 sizeof(list), NULL, &list);
3605 orinoco_unlock(priv, &flags);
3610 num = le16_to_cpu(list.len);
3612 num = min(num, max);
3614 for (i = 0; i < num; i++)
3615 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3620 static int orinoco_ioctl_getname(struct net_device *dev,
3621 struct iw_request_info *info,
3625 struct orinoco_private *priv = netdev_priv(dev);
3629 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3631 if (!err && (numrates > 2))
3632 strcpy(name, "IEEE 802.11b");
3634 strcpy(name, "IEEE 802.11-DS");
3639 static int orinoco_ioctl_setwap(struct net_device *dev,
3640 struct iw_request_info *info,
3641 struct sockaddr *ap_addr,
3644 struct orinoco_private *priv = netdev_priv(dev);
3645 int err = -EINPROGRESS; /* Call commit handler */
3646 unsigned long flags;
3647 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3648 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3650 if (orinoco_lock(priv, &flags) != 0)
3653 /* Enable automatic roaming - no sanity checks are needed */
3654 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3655 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3656 priv->bssid_fixed = 0;
3657 memset(priv->desired_bssid, 0, ETH_ALEN);
3659 /* "off" means keep existing connection */
3660 if (ap_addr->sa_data[0] == 0) {
3661 __orinoco_hw_set_wap(priv);
3667 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3668 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3669 "support manual roaming\n",
3675 if (priv->iw_mode != IW_MODE_INFRA) {
3676 printk(KERN_WARNING "%s: Manual roaming supported only in "
3677 "managed mode\n", dev->name);
3682 /* Intersil firmware hangs without Desired ESSID */
3683 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3684 strlen(priv->desired_essid) == 0) {
3685 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3686 "manual roaming\n", dev->name);
3691 /* Finally, enable manual roaming */
3692 priv->bssid_fixed = 1;
3693 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3696 orinoco_unlock(priv, &flags);
3700 static int orinoco_ioctl_getwap(struct net_device *dev,
3701 struct iw_request_info *info,
3702 struct sockaddr *ap_addr,
3705 struct orinoco_private *priv = netdev_priv(dev);
3707 hermes_t *hw = &priv->hw;
3709 unsigned long flags;
3711 if (orinoco_lock(priv, &flags) != 0)
3714 ap_addr->sa_family = ARPHRD_ETHER;
3715 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3716 ETH_ALEN, NULL, ap_addr->sa_data);
3718 orinoco_unlock(priv, &flags);
3723 static int orinoco_ioctl_setmode(struct net_device *dev,
3724 struct iw_request_info *info,
3728 struct orinoco_private *priv = netdev_priv(dev);
3729 int err = -EINPROGRESS; /* Call commit handler */
3730 unsigned long flags;
3732 if (priv->iw_mode == *mode)
3735 if (orinoco_lock(priv, &flags) != 0)
3740 if (!priv->has_ibss && !priv->has_port3)
3747 case IW_MODE_MONITOR:
3748 if (priv->broken_monitor && !force_monitor) {
3749 printk(KERN_WARNING "%s: Monitor mode support is "
3750 "buggy in this firmware, not enabling\n",
3761 if (err == -EINPROGRESS) {
3762 priv->iw_mode = *mode;
3763 set_port_type(priv);
3766 orinoco_unlock(priv, &flags);
3771 static int orinoco_ioctl_getmode(struct net_device *dev,
3772 struct iw_request_info *info,
3776 struct orinoco_private *priv = netdev_priv(dev);
3778 *mode = priv->iw_mode;
3782 static int orinoco_ioctl_getiwrange(struct net_device *dev,
3783 struct iw_request_info *info,
3784 struct iw_point *rrq,
3787 struct orinoco_private *priv = netdev_priv(dev);
3789 struct iw_range *range = (struct iw_range *) extra;
3793 rrq->length = sizeof(struct iw_range);
3794 memset(range, 0, sizeof(struct iw_range));
3796 range->we_version_compiled = WIRELESS_EXT;
3797 range->we_version_source = 22;
3799 /* Set available channels/frequencies */
3800 range->num_channels = NUM_CHANNELS;
3802 for (i = 0; i < NUM_CHANNELS; i++) {
3803 if (priv->channel_mask & (1 << i)) {
3804 range->freq[k].i = i + 1;
3805 range->freq[k].m = (ieee80211_dsss_chan_to_freq(i + 1) *
3807 range->freq[k].e = 1;
3811 if (k >= IW_MAX_FREQUENCIES)
3814 range->num_frequency = k;
3815 range->sensitivity = 3;
3817 if (priv->has_wep) {
3818 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3819 range->encoding_size[0] = SMALL_KEY_SIZE;
3820 range->num_encoding_sizes = 1;
3822 if (priv->has_big_wep) {
3823 range->encoding_size[1] = LARGE_KEY_SIZE;
3824 range->num_encoding_sizes = 2;
3829 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
3831 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))) {
3832 /* Quality stats meaningless in ad-hoc mode */
3834 range->max_qual.qual = 0x8b - 0x2f;
3835 range->max_qual.level = 0x2f - 0x95 - 1;
3836 range->max_qual.noise = 0x2f - 0x95 - 1;
3837 /* Need to get better values */
3838 range->avg_qual.qual = 0x24;
3839 range->avg_qual.level = 0xC2;
3840 range->avg_qual.noise = 0x9E;
3843 err = orinoco_hw_get_bitratelist(priv, &numrates,
3844 range->bitrate, IW_MAX_BITRATES);
3847 range->num_bitrates = numrates;
3849 /* Set an indication of the max TCP throughput in bit/s that we can
3850 * expect using this interface. May be use for QoS stuff...
3853 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
3855 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3858 range->max_rts = 2347;
3859 range->min_frag = 256;
3860 range->max_frag = 2346;
3863 range->max_pmp = 65535000;
3865 range->max_pmt = 65535 * 1000; /* ??? */
3866 range->pmp_flags = IW_POWER_PERIOD;
3867 range->pmt_flags = IW_POWER_TIMEOUT;
3868 range->pm_capa = (IW_POWER_PERIOD | IW_POWER_TIMEOUT |
3869 IW_POWER_UNICAST_R);
3871 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3872 range->retry_flags = IW_RETRY_LIMIT;
3873 range->r_time_flags = IW_RETRY_LIFETIME;
3874 range->min_retry = 0;
3875 range->max_retry = 65535; /* ??? */
3876 range->min_r_time = 0;
3877 range->max_r_time = 65535 * 1000; /* ??? */
3879 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3880 range->scan_capa = IW_SCAN_CAPA_ESSID;
3882 range->scan_capa = IW_SCAN_CAPA_NONE;
3884 /* Event capability (kernel) */
3885 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3886 /* Event capability (driver) */
3887 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3888 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3889 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3890 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3895 static int orinoco_ioctl_setiwencode(struct net_device *dev,
3896 struct iw_request_info *info,
3897 struct iw_point *erq,
3900 struct orinoco_private *priv = netdev_priv(dev);
3901 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3902 int setindex = priv->tx_key;
3903 int encode_alg = priv->encode_alg;
3904 int restricted = priv->wep_restrict;
3906 int err = -EINPROGRESS; /* Call commit handler */
3907 unsigned long flags;
3913 /* We actually have a key to set - check its length */
3914 if (erq->length > LARGE_KEY_SIZE)
3917 if ((erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep)
3921 if (orinoco_lock(priv, &flags) != 0)
3924 /* Clear any TKIP key we have */
3925 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3926 (void) orinoco_clear_tkip_key(priv, setindex);
3928 if (erq->length > 0) {
3929 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3930 index = priv->tx_key;
3932 /* Adjust key length to a supported value */
3933 if (erq->length > SMALL_KEY_SIZE)
3934 xlen = LARGE_KEY_SIZE;
3935 else if (erq->length > 0)
3936 xlen = SMALL_KEY_SIZE;
3940 /* Switch on WEP if off */
3941 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
3943 encode_alg = IW_ENCODE_ALG_WEP;
3946 /* Important note : if the user do "iwconfig eth0 enc off",
3947 * we will arrive there with an index of -1. This is valid
3948 * but need to be taken care off... Jean II */
3949 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3950 if ((index != -1) || (erq->flags == 0)) {
3955 /* Set the index : Check that the key is valid */
3956 if (priv->keys[index].len == 0) {
3964 if (erq->flags & IW_ENCODE_DISABLED)
3965 encode_alg = IW_ENCODE_ALG_NONE;
3966 if (erq->flags & IW_ENCODE_OPEN)
3968 if (erq->flags & IW_ENCODE_RESTRICTED)
3971 if (erq->pointer && erq->length > 0) {
3972 priv->keys[index].len = cpu_to_le16(xlen);
3973 memset(priv->keys[index].data, 0,
3974 sizeof(priv->keys[index].data));
3975 memcpy(priv->keys[index].data, keybuf, erq->length);
3977 priv->tx_key = setindex;
3979 /* Try fast key change if connected and only keys are changed */
3980 if ((priv->encode_alg == encode_alg) &&
3981 (priv->wep_restrict == restricted) &&
3982 netif_carrier_ok(dev)) {
3983 err = __orinoco_hw_setup_wepkeys(priv);
3984 /* No need to commit if successful */
3988 priv->encode_alg = encode_alg;
3989 priv->wep_restrict = restricted;
3992 orinoco_unlock(priv, &flags);
3997 static int orinoco_ioctl_getiwencode(struct net_device *dev,
3998 struct iw_request_info *info,
3999 struct iw_point *erq,
4002 struct orinoco_private *priv = netdev_priv(dev);
4003 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4005 unsigned long flags;
4010 if (orinoco_lock(priv, &flags) != 0)
4013 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4014 index = priv->tx_key;
4017 if (!priv->encode_alg)
4018 erq->flags |= IW_ENCODE_DISABLED;
4019 erq->flags |= index + 1;
4021 if (priv->wep_restrict)
4022 erq->flags |= IW_ENCODE_RESTRICTED;
4024 erq->flags |= IW_ENCODE_OPEN;
4026 xlen = le16_to_cpu(priv->keys[index].len);
4030 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
4032 orinoco_unlock(priv, &flags);
4036 static int orinoco_ioctl_setessid(struct net_device *dev,
4037 struct iw_request_info *info,
4038 struct iw_point *erq,
4041 struct orinoco_private *priv = netdev_priv(dev);
4042 unsigned long flags;
4044 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4045 * anyway... - Jean II */
4047 /* Hum... Should not use Wireless Extension constant (may change),
4048 * should use our own... - Jean II */
4049 if (erq->length > IW_ESSID_MAX_SIZE)
4052 if (orinoco_lock(priv, &flags) != 0)
4055 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4056 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
4058 /* If not ANY, get the new ESSID */
4060 memcpy(priv->desired_essid, essidbuf, erq->length);
4062 orinoco_unlock(priv, &flags);
4064 return -EINPROGRESS; /* Call commit handler */
4067 static int orinoco_ioctl_getessid(struct net_device *dev,
4068 struct iw_request_info *info,
4069 struct iw_point *erq,
4072 struct orinoco_private *priv = netdev_priv(dev);
4075 unsigned long flags;
4077 if (netif_running(dev)) {
4078 err = orinoco_hw_get_essid(priv, &active, essidbuf);
4083 if (orinoco_lock(priv, &flags) != 0)
4085 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4086 erq->length = strlen(priv->desired_essid);
4087 orinoco_unlock(priv, &flags);
4095 static int orinoco_ioctl_setnick(struct net_device *dev,
4096 struct iw_request_info *info,
4097 struct iw_point *nrq,
4100 struct orinoco_private *priv = netdev_priv(dev);
4101 unsigned long flags;
4103 if (nrq->length > IW_ESSID_MAX_SIZE)
4106 if (orinoco_lock(priv, &flags) != 0)
4109 memset(priv->nick, 0, sizeof(priv->nick));
4110 memcpy(priv->nick, nickbuf, nrq->length);
4112 orinoco_unlock(priv, &flags);
4114 return -EINPROGRESS; /* Call commit handler */
4117 static int orinoco_ioctl_getnick(struct net_device *dev,
4118 struct iw_request_info *info,
4119 struct iw_point *nrq,
4122 struct orinoco_private *priv = netdev_priv(dev);
4123 unsigned long flags;
4125 if (orinoco_lock(priv, &flags) != 0)
4128 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
4129 orinoco_unlock(priv, &flags);
4131 nrq->length = strlen(priv->nick);
4136 static int orinoco_ioctl_setfreq(struct net_device *dev,
4137 struct iw_request_info *info,
4138 struct iw_freq *frq,
4141 struct orinoco_private *priv = netdev_priv(dev);
4143 unsigned long flags;
4144 int err = -EINPROGRESS; /* Call commit handler */
4146 /* In infrastructure mode the AP sets the channel */
4147 if (priv->iw_mode == IW_MODE_INFRA)
4150 if ((frq->e == 0) && (frq->m <= 1000)) {
4151 /* Setting by channel number */
4154 /* Setting by frequency */
4158 /* Calculate denominator to rescale to MHz */
4159 for (i = 0; i < (6 - frq->e); i++)
4162 chan = ieee80211_freq_to_dsss_chan(frq->m / denom);
4165 if ((chan < 1) || (chan > NUM_CHANNELS) ||
4166 !(priv->channel_mask & (1 << (chan-1))))
4169 if (orinoco_lock(priv, &flags) != 0)
4172 priv->channel = chan;
4173 if (priv->iw_mode == IW_MODE_MONITOR) {
4174 /* Fast channel change - no commit if successful */
4175 hermes_t *hw = &priv->hw;
4176 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4177 HERMES_TEST_SET_CHANNEL,
4180 orinoco_unlock(priv, &flags);
4185 static int orinoco_ioctl_getfreq(struct net_device *dev,
4186 struct iw_request_info *info,
4187 struct iw_freq *frq,
4190 struct orinoco_private *priv = netdev_priv(dev);
4193 /* Locking done in there */
4194 tmp = orinoco_hw_get_freq(priv);
4198 frq->m = tmp * 100000;
4204 static int orinoco_ioctl_getsens(struct net_device *dev,
4205 struct iw_request_info *info,
4206 struct iw_param *srq,
4209 struct orinoco_private *priv = netdev_priv(dev);
4210 hermes_t *hw = &priv->hw;
4213 unsigned long flags;
4215 if (!priv->has_sensitivity)
4218 if (orinoco_lock(priv, &flags) != 0)
4220 err = hermes_read_wordrec(hw, USER_BAP,
4221 HERMES_RID_CNFSYSTEMSCALE, &val);
4222 orinoco_unlock(priv, &flags);
4228 srq->fixed = 0; /* auto */
4233 static int orinoco_ioctl_setsens(struct net_device *dev,
4234 struct iw_request_info *info,
4235 struct iw_param *srq,
4238 struct orinoco_private *priv = netdev_priv(dev);
4239 int val = srq->value;
4240 unsigned long flags;
4242 if (!priv->has_sensitivity)
4245 if ((val < 1) || (val > 3))
4248 if (orinoco_lock(priv, &flags) != 0)
4250 priv->ap_density = val;
4251 orinoco_unlock(priv, &flags);
4253 return -EINPROGRESS; /* Call commit handler */
4256 static int orinoco_ioctl_setrts(struct net_device *dev,
4257 struct iw_request_info *info,
4258 struct iw_param *rrq,
4261 struct orinoco_private *priv = netdev_priv(dev);
4262 int val = rrq->value;
4263 unsigned long flags;
4268 if ((val < 0) || (val > 2347))
4271 if (orinoco_lock(priv, &flags) != 0)
4274 priv->rts_thresh = val;
4275 orinoco_unlock(priv, &flags);
4277 return -EINPROGRESS; /* Call commit handler */
4280 static int orinoco_ioctl_getrts(struct net_device *dev,
4281 struct iw_request_info *info,
4282 struct iw_param *rrq,
4285 struct orinoco_private *priv = netdev_priv(dev);
4287 rrq->value = priv->rts_thresh;
4288 rrq->disabled = (rrq->value == 2347);
4294 static int orinoco_ioctl_setfrag(struct net_device *dev,
4295 struct iw_request_info *info,
4296 struct iw_param *frq,
4299 struct orinoco_private *priv = netdev_priv(dev);
4300 int err = -EINPROGRESS; /* Call commit handler */
4301 unsigned long flags;
4303 if (orinoco_lock(priv, &flags) != 0)
4306 if (priv->has_mwo) {
4308 priv->mwo_robust = 0;
4311 printk(KERN_WARNING "%s: Fixed fragmentation "
4312 "is not supported on this firmware. "
4313 "Using MWO robust instead.\n",
4315 priv->mwo_robust = 1;
4319 priv->frag_thresh = 2346;
4321 if ((frq->value < 256) || (frq->value > 2346))
4325 priv->frag_thresh = frq->value & ~0x1;
4329 orinoco_unlock(priv, &flags);
4334 static int orinoco_ioctl_getfrag(struct net_device *dev,
4335 struct iw_request_info *info,
4336 struct iw_param *frq,
4339 struct orinoco_private *priv = netdev_priv(dev);
4340 hermes_t *hw = &priv->hw;
4343 unsigned long flags;
4345 if (orinoco_lock(priv, &flags) != 0)
4348 if (priv->has_mwo) {
4349 err = hermes_read_wordrec(hw, USER_BAP,
4350 HERMES_RID_CNFMWOROBUST_AGERE,
4355 frq->value = val ? 2347 : 0;
4356 frq->disabled = !val;
4359 err = hermes_read_wordrec(hw, USER_BAP,
4360 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
4366 frq->disabled = (val >= 2346);
4370 orinoco_unlock(priv, &flags);
4375 static int orinoco_ioctl_setrate(struct net_device *dev,
4376 struct iw_request_info *info,
4377 struct iw_param *rrq,
4380 struct orinoco_private *priv = netdev_priv(dev);
4382 int bitrate; /* 100s of kilobits */
4384 unsigned long flags;
4386 /* As the user space doesn't know our highest rate, it uses -1
4387 * to ask us to set the highest rate. Test it using "iwconfig
4388 * ethX rate auto" - Jean II */
4389 if (rrq->value == -1)
4392 if (rrq->value % 100000)
4394 bitrate = rrq->value / 100000;
4397 if ((bitrate != 10) && (bitrate != 20) &&
4398 (bitrate != 55) && (bitrate != 110))
4401 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4402 if ((bitrate_table[i].bitrate == bitrate) &&
4403 (bitrate_table[i].automatic == !rrq->fixed)) {
4411 if (orinoco_lock(priv, &flags) != 0)
4413 priv->bitratemode = ratemode;
4414 orinoco_unlock(priv, &flags);
4416 return -EINPROGRESS;
4419 static int orinoco_ioctl_getrate(struct net_device *dev,
4420 struct iw_request_info *info,
4421 struct iw_param *rrq,
4424 struct orinoco_private *priv = netdev_priv(dev);
4425 hermes_t *hw = &priv->hw;
4430 unsigned long flags;
4432 if (orinoco_lock(priv, &flags) != 0)
4435 ratemode = priv->bitratemode;
4437 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4439 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4440 rrq->fixed = !bitrate_table[ratemode].automatic;
4443 /* If the interface is running we try to find more about the
4445 if (netif_running(dev)) {
4446 err = hermes_read_wordrec(hw, USER_BAP,
4447 HERMES_RID_CURRENTTXRATE, &val);
4451 switch (priv->firmware_type) {
4452 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4453 /* Note : in Lucent firmware, the return value of
4454 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4455 * and therefore is totally different from the
4456 * encoding of HERMES_RID_CNFTXRATECONTROL.
4457 * Don't forget that 6Mb/s is really 5.5Mb/s */
4459 rrq->value = 5500000;
4461 rrq->value = val * 1000000;
4463 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4464 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4465 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4466 if (bitrate_table[i].intersil_txratectrl == val) {
4470 if (i >= BITRATE_TABLE_SIZE)
4471 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4474 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4482 orinoco_unlock(priv, &flags);
4487 static int orinoco_ioctl_setpower(struct net_device *dev,
4488 struct iw_request_info *info,
4489 struct iw_param *prq,
4492 struct orinoco_private *priv = netdev_priv(dev);
4493 int err = -EINPROGRESS; /* Call commit handler */
4494 unsigned long flags;
4496 if (orinoco_lock(priv, &flags) != 0)
4499 if (prq->disabled) {
4502 switch (prq->flags & IW_POWER_MODE) {
4503 case IW_POWER_UNICAST_R:
4507 case IW_POWER_ALL_R:
4512 /* No flags : but we may have a value - Jean II */
4519 if (prq->flags & IW_POWER_TIMEOUT) {
4521 priv->pm_timeout = prq->value / 1000;
4523 if (prq->flags & IW_POWER_PERIOD) {
4525 priv->pm_period = prq->value / 1000;
4527 /* It's valid to not have a value if we are just toggling
4528 * the flags... Jean II */
4536 orinoco_unlock(priv, &flags);
4541 static int orinoco_ioctl_getpower(struct net_device *dev,
4542 struct iw_request_info *info,
4543 struct iw_param *prq,
4546 struct orinoco_private *priv = netdev_priv(dev);
4547 hermes_t *hw = &priv->hw;
4549 u16 enable, period, timeout, mcast;
4550 unsigned long flags;
4552 if (orinoco_lock(priv, &flags) != 0)
4555 err = hermes_read_wordrec(hw, USER_BAP,
4556 HERMES_RID_CNFPMENABLED, &enable);
4560 err = hermes_read_wordrec(hw, USER_BAP,
4561 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4565 err = hermes_read_wordrec(hw, USER_BAP,
4566 HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4570 err = hermes_read_wordrec(hw, USER_BAP,
4571 HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4575 prq->disabled = !enable;
4576 /* Note : by default, display the period */
4577 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4578 prq->flags = IW_POWER_TIMEOUT;
4579 prq->value = timeout * 1000;
4581 prq->flags = IW_POWER_PERIOD;
4582 prq->value = period * 1000;
4585 prq->flags |= IW_POWER_ALL_R;
4587 prq->flags |= IW_POWER_UNICAST_R;
4590 orinoco_unlock(priv, &flags);
4595 static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4596 struct iw_request_info *info,
4597 union iwreq_data *wrqu,
4600 struct orinoco_private *priv = netdev_priv(dev);
4601 struct iw_point *encoding = &wrqu->encoding;
4602 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4603 int idx, alg = ext->alg, set_key = 1;
4604 unsigned long flags;
4608 if (orinoco_lock(priv, &flags) != 0)
4611 /* Determine and validate the key index */
4612 idx = encoding->flags & IW_ENCODE_INDEX;
4614 if ((idx < 1) || (idx > 4))
4620 if (encoding->flags & IW_ENCODE_DISABLED)
4621 alg = IW_ENCODE_ALG_NONE;
4623 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4624 /* Clear any TKIP TX key we had */
4625 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4628 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4630 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4631 (ext->key_len > 0)) ? 1 : 0;
4635 /* Set the requested key first */
4637 case IW_ENCODE_ALG_NONE:
4638 priv->encode_alg = alg;
4639 priv->keys[idx].len = 0;
4642 case IW_ENCODE_ALG_WEP:
4643 if (ext->key_len > SMALL_KEY_SIZE)
4644 key_len = LARGE_KEY_SIZE;
4645 else if (ext->key_len > 0)
4646 key_len = SMALL_KEY_SIZE;
4650 priv->encode_alg = alg;
4651 priv->keys[idx].len = cpu_to_le16(key_len);
4653 key_len = min(ext->key_len, key_len);
4655 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4656 memcpy(priv->keys[idx].data, ext->key, key_len);
4659 case IW_ENCODE_ALG_TKIP:
4661 hermes_t *hw = &priv->hw;
4664 if (!priv->has_wpa ||
4665 (ext->key_len > sizeof(priv->tkip_key[0])))
4668 priv->encode_alg = alg;
4669 memset(&priv->tkip_key[idx], 0,
4670 sizeof(priv->tkip_key[idx]));
4671 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4673 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4674 tkip_iv = &ext->rx_seq[0];
4676 err = __orinoco_hw_set_tkip_key(hw, idx,
4677 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4678 (u8 *) &priv->tkip_key[idx],
4681 printk(KERN_ERR "%s: Error %d setting TKIP key"
4682 "\n", dev->name, err);
4692 orinoco_unlock(priv, &flags);
4697 static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4698 struct iw_request_info *info,
4699 union iwreq_data *wrqu,
4702 struct orinoco_private *priv = netdev_priv(dev);
4703 struct iw_point *encoding = &wrqu->encoding;
4704 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4705 int idx, max_key_len;
4706 unsigned long flags;
4709 if (orinoco_lock(priv, &flags) != 0)
4713 max_key_len = encoding->length - sizeof(*ext);
4714 if (max_key_len < 0)
4717 idx = encoding->flags & IW_ENCODE_INDEX;
4719 if ((idx < 1) || (idx > 4))
4725 encoding->flags = idx + 1;
4726 memset(ext, 0, sizeof(*ext));
4728 ext->alg = priv->encode_alg;
4729 switch (priv->encode_alg) {
4730 case IW_ENCODE_ALG_NONE:
4732 encoding->flags |= IW_ENCODE_DISABLED;
4734 case IW_ENCODE_ALG_WEP:
4735 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
4737 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4738 encoding->flags |= IW_ENCODE_ENABLED;
4740 case IW_ENCODE_ALG_TKIP:
4741 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
4743 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4744 encoding->flags |= IW_ENCODE_ENABLED;
4750 orinoco_unlock(priv, &flags);
4755 static int orinoco_ioctl_set_auth(struct net_device *dev,
4756 struct iw_request_info *info,
4757 union iwreq_data *wrqu, char *extra)
4759 struct orinoco_private *priv = netdev_priv(dev);
4760 hermes_t *hw = &priv->hw;
4761 struct iw_param *param = &wrqu->param;
4762 unsigned long flags;
4763 int ret = -EINPROGRESS;
4765 if (orinoco_lock(priv, &flags) != 0)
4768 switch (param->flags & IW_AUTH_INDEX) {
4769 case IW_AUTH_WPA_VERSION:
4770 case IW_AUTH_CIPHER_PAIRWISE:
4771 case IW_AUTH_CIPHER_GROUP:
4772 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4773 case IW_AUTH_PRIVACY_INVOKED:
4774 case IW_AUTH_DROP_UNENCRYPTED:
4776 * orinoco does not use these parameters
4780 case IW_AUTH_KEY_MGMT:
4781 /* wl_lkm implies value 2 == PSK for Hermes I
4782 * which ties in with WEXT
4783 * no other hints tho :(
4785 priv->key_mgmt = param->value;
4788 case IW_AUTH_TKIP_COUNTERMEASURES:
4789 /* When countermeasures are enabled, shut down the
4790 * card; when disabled, re-enable the card. This must
4791 * take effect immediately.
4793 * TODO: Make sure that the EAPOL message is getting
4794 * out before card disabled
4797 priv->tkip_cm_active = 1;
4798 ret = hermes_enable_port(hw, 0);
4800 priv->tkip_cm_active = 0;
4801 ret = hermes_disable_port(hw, 0);
4805 case IW_AUTH_80211_AUTH_ALG:
4806 if (param->value & IW_AUTH_ALG_SHARED_KEY)
4807 priv->wep_restrict = 1;
4808 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
4809 priv->wep_restrict = 0;
4814 case IW_AUTH_WPA_ENABLED:
4815 if (priv->has_wpa) {
4816 priv->wpa_enabled = param->value ? 1 : 0;
4820 /* else silently accept disable of WPA */
4821 priv->wpa_enabled = 0;
4829 orinoco_unlock(priv, &flags);
4833 static int orinoco_ioctl_get_auth(struct net_device *dev,
4834 struct iw_request_info *info,
4835 union iwreq_data *wrqu, char *extra)
4837 struct orinoco_private *priv = netdev_priv(dev);
4838 struct iw_param *param = &wrqu->param;
4839 unsigned long flags;
4842 if (orinoco_lock(priv, &flags) != 0)
4845 switch (param->flags & IW_AUTH_INDEX) {
4846 case IW_AUTH_KEY_MGMT:
4847 param->value = priv->key_mgmt;
4850 case IW_AUTH_TKIP_COUNTERMEASURES:
4851 param->value = priv->tkip_cm_active;
4854 case IW_AUTH_80211_AUTH_ALG:
4855 if (priv->wep_restrict)
4856 param->value = IW_AUTH_ALG_SHARED_KEY;
4858 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
4861 case IW_AUTH_WPA_ENABLED:
4862 param->value = priv->wpa_enabled;
4869 orinoco_unlock(priv, &flags);
4873 static int orinoco_ioctl_set_genie(struct net_device *dev,
4874 struct iw_request_info *info,
4875 union iwreq_data *wrqu, char *extra)
4877 struct orinoco_private *priv = netdev_priv(dev);
4879 unsigned long flags;
4881 /* cut off at IEEE80211_MAX_DATA_LEN */
4882 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
4883 (wrqu->data.length && (extra == NULL)))
4886 if (wrqu->data.length) {
4887 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
4891 memcpy(buf, extra, wrqu->data.length);
4895 if (orinoco_lock(priv, &flags) != 0) {
4900 kfree(priv->wpa_ie);
4902 priv->wpa_ie_len = wrqu->data.length;
4905 /* Looks like wl_lkm wants to check the auth alg, and
4906 * somehow pass it to the firmware.
4907 * Instead it just calls the key mgmt rid
4908 * - we do this in set auth.
4912 orinoco_unlock(priv, &flags);
4916 static int orinoco_ioctl_get_genie(struct net_device *dev,
4917 struct iw_request_info *info,
4918 union iwreq_data *wrqu, char *extra)
4920 struct orinoco_private *priv = netdev_priv(dev);
4921 unsigned long flags;
4924 if (orinoco_lock(priv, &flags) != 0)
4927 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
4928 wrqu->data.length = 0;
4932 if (wrqu->data.length < priv->wpa_ie_len) {
4937 wrqu->data.length = priv->wpa_ie_len;
4938 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
4941 orinoco_unlock(priv, &flags);
4945 static int orinoco_ioctl_set_mlme(struct net_device *dev,
4946 struct iw_request_info *info,
4947 union iwreq_data *wrqu, char *extra)
4949 struct orinoco_private *priv = netdev_priv(dev);
4950 hermes_t *hw = &priv->hw;
4951 struct iw_mlme *mlme = (struct iw_mlme *)extra;
4952 unsigned long flags;
4955 if (orinoco_lock(priv, &flags) != 0)
4958 switch (mlme->cmd) {
4959 case IW_MLME_DEAUTH:
4960 /* silently ignore */
4963 case IW_MLME_DISASSOC:
4968 } __attribute__ ((packed)) buf;
4970 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
4971 buf.reason_code = cpu_to_le16(mlme->reason_code);
4972 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
4973 HERMES_RID_CNFDISASSOCIATE,
4981 orinoco_unlock(priv, &flags);
4985 static int orinoco_ioctl_getretry(struct net_device *dev,
4986 struct iw_request_info *info,
4987 struct iw_param *rrq,
4990 struct orinoco_private *priv = netdev_priv(dev);
4991 hermes_t *hw = &priv->hw;
4993 u16 short_limit, long_limit, lifetime;
4994 unsigned long flags;
4996 if (orinoco_lock(priv, &flags) != 0)
4999 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
5004 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
5009 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
5014 rrq->disabled = 0; /* Can't be disabled */
5016 /* Note : by default, display the retry number */
5017 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
5018 rrq->flags = IW_RETRY_LIFETIME;
5019 rrq->value = lifetime * 1000; /* ??? */
5021 /* By default, display the min number */
5022 if ((rrq->flags & IW_RETRY_LONG)) {
5023 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
5024 rrq->value = long_limit;
5026 rrq->flags = IW_RETRY_LIMIT;
5027 rrq->value = short_limit;
5028 if (short_limit != long_limit)
5029 rrq->flags |= IW_RETRY_SHORT;
5034 orinoco_unlock(priv, &flags);
5039 static int orinoco_ioctl_reset(struct net_device *dev,
5040 struct iw_request_info *info,
5044 struct orinoco_private *priv = netdev_priv(dev);
5046 if (!capable(CAP_NET_ADMIN))
5049 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
5050 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
5052 /* Firmware reset */
5053 orinoco_reset(&priv->reset_work);
5055 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
5057 schedule_work(&priv->reset_work);
5063 static int orinoco_ioctl_setibssport(struct net_device *dev,
5064 struct iw_request_info *info,
5069 struct orinoco_private *priv = netdev_priv(dev);
5070 int val = *((int *) extra);
5071 unsigned long flags;
5073 if (orinoco_lock(priv, &flags) != 0)
5076 priv->ibss_port = val ;
5078 /* Actually update the mode we are using */
5079 set_port_type(priv);
5081 orinoco_unlock(priv, &flags);
5082 return -EINPROGRESS; /* Call commit handler */
5085 static int orinoco_ioctl_getibssport(struct net_device *dev,
5086 struct iw_request_info *info,
5090 struct orinoco_private *priv = netdev_priv(dev);
5091 int *val = (int *) extra;
5093 *val = priv->ibss_port;
5097 static int orinoco_ioctl_setport3(struct net_device *dev,
5098 struct iw_request_info *info,
5102 struct orinoco_private *priv = netdev_priv(dev);
5103 int val = *((int *) extra);
5105 unsigned long flags;
5107 if (orinoco_lock(priv, &flags) != 0)
5111 case 0: /* Try to do IEEE ad-hoc mode */
5112 if (!priv->has_ibss) {
5116 priv->prefer_port3 = 0;
5120 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5121 if (!priv->has_port3) {
5125 priv->prefer_port3 = 1;
5133 /* Actually update the mode we are using */
5134 set_port_type(priv);
5138 orinoco_unlock(priv, &flags);
5143 static int orinoco_ioctl_getport3(struct net_device *dev,
5144 struct iw_request_info *info,
5148 struct orinoco_private *priv = netdev_priv(dev);
5149 int *val = (int *) extra;
5151 *val = priv->prefer_port3;
5155 static int orinoco_ioctl_setpreamble(struct net_device *dev,
5156 struct iw_request_info *info,
5160 struct orinoco_private *priv = netdev_priv(dev);
5161 unsigned long flags;
5164 if (!priv->has_preamble)
5167 /* 802.11b has recently defined some short preamble.
5168 * Basically, the Phy header has been reduced in size.
5169 * This increase performance, especially at high rates
5170 * (the preamble is transmitted at 1Mb/s), unfortunately
5171 * this give compatibility troubles... - Jean II */
5172 val = *((int *) extra);
5174 if (orinoco_lock(priv, &flags) != 0)
5182 orinoco_unlock(priv, &flags);
5184 return -EINPROGRESS; /* Call commit handler */
5187 static int orinoco_ioctl_getpreamble(struct net_device *dev,
5188 struct iw_request_info *info,
5192 struct orinoco_private *priv = netdev_priv(dev);
5193 int *val = (int *) extra;
5195 if (!priv->has_preamble)
5198 *val = priv->preamble;
5202 /* ioctl interface to hermes_read_ltv()
5203 * To use with iwpriv, pass the RID as the token argument, e.g.
5204 * iwpriv get_rid [0xfc00]
5205 * At least Wireless Tools 25 is required to use iwpriv.
5206 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5207 static int orinoco_ioctl_getrid(struct net_device *dev,
5208 struct iw_request_info *info,
5209 struct iw_point *data,
5212 struct orinoco_private *priv = netdev_priv(dev);
5213 hermes_t *hw = &priv->hw;
5214 int rid = data->flags;
5217 unsigned long flags;
5219 /* It's a "get" function, but we don't want users to access the
5220 * WEP key and other raw firmware data */
5221 if (!capable(CAP_NET_ADMIN))
5224 if (rid < 0xfc00 || rid > 0xffff)
5227 if (orinoco_lock(priv, &flags) != 0)
5230 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5235 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5239 orinoco_unlock(priv, &flags);
5243 /* Trigger a scan (look for other cells in the vicinity) */
5244 static int orinoco_ioctl_setscan(struct net_device *dev,
5245 struct iw_request_info *info,
5246 struct iw_point *srq,
5249 struct orinoco_private *priv = netdev_priv(dev);
5250 hermes_t *hw = &priv->hw;
5251 struct iw_scan_req *si = (struct iw_scan_req *) extra;
5253 unsigned long flags;
5255 /* Note : you may have realised that, as this is a SET operation,
5256 * this is privileged and therefore a normal user can't
5258 * This is not an error, while the device perform scanning,
5259 * traffic doesn't flow, so it's a perfect DoS...
5262 if (orinoco_lock(priv, &flags) != 0)
5265 /* Scanning with port 0 disabled would fail */
5266 if (!netif_running(dev)) {
5271 /* In monitor mode, the scan results are always empty.
5272 * Probe responses are passed to the driver as received
5273 * frames and could be processed in software. */
5274 if (priv->iw_mode == IW_MODE_MONITOR) {
5279 /* Note : because we don't lock out the irq handler, the way
5280 * we access scan variables in priv is critical.
5281 * o scan_inprogress : not touched by irq handler
5282 * o scan_mode : not touched by irq handler
5283 * Before modifying anything on those variables, please think hard !
5287 priv->scan_mode = srq->flags;
5289 /* Always trigger scanning, even if it's in progress.
5290 * This way, if the info frame get lost, we will recover somewhat
5291 * gracefully - Jean II */
5293 if (priv->has_hostscan) {
5294 switch (priv->firmware_type) {
5295 case FIRMWARE_TYPE_SYMBOL:
5296 err = hermes_write_wordrec(hw, USER_BAP,
5297 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5298 HERMES_HOSTSCAN_SYMBOL_ONCE |
5299 HERMES_HOSTSCAN_SYMBOL_BCAST);
5301 case FIRMWARE_TYPE_INTERSIL: {
5304 req[0] = cpu_to_le16(0x3fff); /* All channels */
5305 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5306 req[2] = 0; /* Any ESSID */
5307 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5308 HERMES_RID_CNFHOSTSCAN, &req);
5311 case FIRMWARE_TYPE_AGERE:
5312 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5313 struct hermes_idstring idbuf;
5314 size_t len = min(sizeof(idbuf.val),
5315 (size_t) si->essid_len);
5316 idbuf.len = cpu_to_le16(len);
5317 memcpy(idbuf.val, si->essid, len);
5319 err = hermes_write_ltv(hw, USER_BAP,
5320 HERMES_RID_CNFSCANSSID_AGERE,
5321 HERMES_BYTES_TO_RECLEN(len + 2),
5324 err = hermes_write_wordrec(hw, USER_BAP,
5325 HERMES_RID_CNFSCANSSID_AGERE,
5330 if (priv->has_ext_scan) {
5331 /* Clear scan results at the start of
5332 * an extended scan */
5333 orinoco_clear_scan_results(priv,
5334 msecs_to_jiffies(15000));
5336 /* TODO: Is this available on older firmware?
5337 * Can we use it to scan specific channels
5338 * for IW_SCAN_THIS_FREQ? */
5339 err = hermes_write_wordrec(hw, USER_BAP,
5340 HERMES_RID_CNFSCANCHANNELS2GHZ,
5345 err = hermes_inquire(hw,
5346 HERMES_INQ_CHANNELINFO);
5348 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5352 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5354 /* One more client */
5356 priv->scan_inprogress = 1;
5359 orinoco_unlock(priv, &flags);
5363 #define MAX_CUSTOM_LEN 64
5365 /* Translate scan data returned from the card to a card independant
5366 * format that the Wireless Tools will understand - Jean II */
5367 static inline char *orinoco_translate_scan(struct net_device *dev,
5368 struct iw_request_info *info,
5371 union hermes_scan_info *bss,
5372 unsigned long last_scanned)
5374 struct orinoco_private *priv = netdev_priv(dev);
5377 struct iw_event iwe; /* Temporary buffer */
5378 char custom[MAX_CUSTOM_LEN];
5380 memset(&iwe, 0, sizeof(iwe));
5382 /* First entry *MUST* be the AP MAC address */
5383 iwe.cmd = SIOCGIWAP;
5384 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5385 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
5386 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5387 &iwe, IW_EV_ADDR_LEN);
5389 /* Other entries will be displayed in the order we give them */
5392 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5393 if (iwe.u.data.length > 32)
5394 iwe.u.data.length = 32;
5395 iwe.cmd = SIOCGIWESSID;
5396 iwe.u.data.flags = 1;
5397 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5398 &iwe, bss->a.essid);
5401 iwe.cmd = SIOCGIWMODE;
5402 capabilities = le16_to_cpu(bss->a.capabilities);
5403 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5404 if (capabilities & WLAN_CAPABILITY_ESS)
5405 iwe.u.mode = IW_MODE_MASTER;
5407 iwe.u.mode = IW_MODE_ADHOC;
5408 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5409 &iwe, IW_EV_UINT_LEN);
5412 channel = bss->s.channel;
5413 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5414 /* Add channel and frequency */
5415 iwe.cmd = SIOCGIWFREQ;
5416 iwe.u.freq.m = channel;
5418 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5419 &iwe, IW_EV_FREQ_LEN);
5421 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
5423 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5424 &iwe, IW_EV_FREQ_LEN);
5427 /* Add quality statistics. level and noise in dB. No link quality */
5429 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5430 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5431 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5432 /* Wireless tools prior to 27.pre22 will show link quality
5433 * anyway, so we provide a reasonable value. */
5434 if (iwe.u.qual.level > iwe.u.qual.noise)
5435 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5437 iwe.u.qual.qual = 0;
5438 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5439 &iwe, IW_EV_QUAL_LEN);
5441 /* Add encryption capability */
5442 iwe.cmd = SIOCGIWENCODE;
5443 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5444 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5446 iwe.u.data.flags = IW_ENCODE_DISABLED;
5447 iwe.u.data.length = 0;
5448 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5451 /* Bit rate is not available in Lucent/Agere firmwares */
5452 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
5453 char *current_val = current_ev + iwe_stream_lcp_len(info);
5457 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5462 iwe.cmd = SIOCGIWRATE;
5463 /* Those two flags are ignored... */
5464 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5466 for (i = 0; i < 10; i += step) {
5467 /* NULL terminated */
5468 if (bss->p.rates[i] == 0x0)
5470 /* Bit rate given in 500 kb/s units (+ 0x80) */
5471 iwe.u.bitrate.value =
5472 ((bss->p.rates[i] & 0x7f) * 500000);
5473 current_val = iwe_stream_add_value(info, current_ev,
5478 /* Check if we added any event */
5479 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
5480 current_ev = current_val;
5483 /* Beacon interval */
5484 iwe.cmd = IWEVCUSTOM;
5485 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5487 le16_to_cpu(bss->a.beacon_interv));
5488 if (iwe.u.data.length)
5489 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5493 iwe.cmd = IWEVCUSTOM;
5494 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5497 if (iwe.u.data.length)
5498 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5501 /* Add EXTRA: Age to display seconds since last beacon/probe response
5502 * for given network. */
5503 iwe.cmd = IWEVCUSTOM;
5504 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5505 " Last beacon: %dms ago",
5506 jiffies_to_msecs(jiffies - last_scanned));
5507 if (iwe.u.data.length)
5508 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5514 static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5515 struct iw_request_info *info,
5518 struct agere_ext_scan_info *bss,
5519 unsigned long last_scanned)
5523 struct iw_event iwe; /* Temporary buffer */
5524 char custom[MAX_CUSTOM_LEN];
5527 memset(&iwe, 0, sizeof(iwe));
5529 /* First entry *MUST* be the AP MAC address */
5530 iwe.cmd = SIOCGIWAP;
5531 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5532 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5533 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5534 &iwe, IW_EV_ADDR_LEN);
5536 /* Other entries will be displayed in the order we give them */
5540 iwe.u.data.length = ie[1];
5541 if (iwe.u.data.length) {
5542 if (iwe.u.data.length > 32)
5543 iwe.u.data.length = 32;
5544 iwe.cmd = SIOCGIWESSID;
5545 iwe.u.data.flags = 1;
5546 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5551 capabilities = le16_to_cpu(bss->capabilities);
5552 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5553 iwe.cmd = SIOCGIWMODE;
5554 if (capabilities & WLAN_CAPABILITY_ESS)
5555 iwe.u.mode = IW_MODE_MASTER;
5557 iwe.u.mode = IW_MODE_ADHOC;
5558 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5559 &iwe, IW_EV_UINT_LEN);
5562 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
5563 channel = ie ? ie[2] : 0;
5564 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5565 /* Add channel and frequency */
5566 iwe.cmd = SIOCGIWFREQ;
5567 iwe.u.freq.m = channel;
5569 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5570 &iwe, IW_EV_FREQ_LEN);
5572 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(channel) * 100000;
5574 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5575 &iwe, IW_EV_FREQ_LEN);
5578 /* Add quality statistics. level and noise in dB. No link quality */
5580 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5581 iwe.u.qual.level = bss->level - 0x95;
5582 iwe.u.qual.noise = bss->noise - 0x95;
5583 /* Wireless tools prior to 27.pre22 will show link quality
5584 * anyway, so we provide a reasonable value. */
5585 if (iwe.u.qual.level > iwe.u.qual.noise)
5586 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5588 iwe.u.qual.qual = 0;
5589 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5590 &iwe, IW_EV_QUAL_LEN);
5592 /* Add encryption capability */
5593 iwe.cmd = SIOCGIWENCODE;
5594 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5595 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5597 iwe.u.data.flags = IW_ENCODE_DISABLED;
5598 iwe.u.data.length = 0;
5599 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5603 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5605 iwe.cmd = IWEVGENIE;
5606 iwe.u.data.length = ie[1] + 2;
5607 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5612 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
5614 iwe.cmd = IWEVGENIE;
5615 iwe.u.data.length = ie[1] + 2;
5616 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5620 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
5622 char *p = current_ev + iwe_stream_lcp_len(info);
5625 iwe.cmd = SIOCGIWRATE;
5626 /* Those two flags are ignored... */
5627 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5629 for (i = 2; i < (ie[1] + 2); i++) {
5630 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5631 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5632 &iwe, IW_EV_PARAM_LEN);
5634 /* Check if we added any event */
5635 if (p > (current_ev + iwe_stream_lcp_len(info)))
5640 iwe.cmd = IWEVCUSTOM;
5642 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
5643 (unsigned long long) le64_to_cpu(bss->timestamp));
5644 if (iwe.u.data.length)
5645 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5648 /* Beacon interval */
5649 iwe.cmd = IWEVCUSTOM;
5650 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5652 le16_to_cpu(bss->beacon_interval));
5653 if (iwe.u.data.length)
5654 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5658 iwe.cmd = IWEVCUSTOM;
5659 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5662 if (iwe.u.data.length)
5663 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5666 /* Add EXTRA: Age to display seconds since last beacon/probe response
5667 * for given network. */
5668 iwe.cmd = IWEVCUSTOM;
5669 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5670 " Last beacon: %dms ago",
5671 jiffies_to_msecs(jiffies - last_scanned));
5672 if (iwe.u.data.length)
5673 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5679 /* Return results of a scan */
5680 static int orinoco_ioctl_getscan(struct net_device *dev,
5681 struct iw_request_info *info,
5682 struct iw_point *srq,
5685 struct orinoco_private *priv = netdev_priv(dev);
5687 unsigned long flags;
5688 char *current_ev = extra;
5690 if (orinoco_lock(priv, &flags) != 0)
5693 if (priv->scan_inprogress) {
5694 /* Important note : we don't want to block the caller
5695 * until results are ready for various reasons.
5696 * First, managing wait queues is complex and racy.
5697 * Second, we grab some rtnetlink lock before comming
5698 * here (in dev_ioctl()).
5699 * Third, we generate an Wireless Event, so the
5700 * caller can wait itself on that - Jean II */
5705 if (priv->has_ext_scan) {
5706 struct xbss_element *bss;
5708 list_for_each_entry(bss, &priv->bss_list, list) {
5709 /* Translate this entry to WE format */
5711 orinoco_translate_ext_scan(dev, info,
5713 extra + srq->length,
5717 /* Check if there is space for one more entry */
5718 if ((extra + srq->length - current_ev)
5719 <= IW_EV_ADDR_LEN) {
5720 /* Ask user space to try again with a
5728 struct bss_element *bss;
5730 list_for_each_entry(bss, &priv->bss_list, list) {
5731 /* Translate this entry to WE format */
5732 current_ev = orinoco_translate_scan(dev, info,
5734 extra + srq->length,
5738 /* Check if there is space for one more entry */
5739 if ((extra + srq->length - current_ev)
5740 <= IW_EV_ADDR_LEN) {
5741 /* Ask user space to try again with a
5749 srq->length = (current_ev - extra);
5750 srq->flags = (__u16) priv->scan_mode;
5753 orinoco_unlock(priv, &flags);
5757 /* Commit handler, called after set operations */
5758 static int orinoco_ioctl_commit(struct net_device *dev,
5759 struct iw_request_info *info,
5763 struct orinoco_private *priv = netdev_priv(dev);
5764 struct hermes *hw = &priv->hw;
5765 unsigned long flags;
5771 if (priv->broken_disableport) {
5772 orinoco_reset(&priv->reset_work);
5776 if (orinoco_lock(priv, &flags) != 0)
5779 err = hermes_disable_port(hw, 0);
5781 printk(KERN_WARNING "%s: Unable to disable port "
5782 "while reconfiguring card\n", dev->name);
5783 priv->broken_disableport = 1;
5787 err = __orinoco_program_rids(dev);
5789 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5794 err = hermes_enable_port(hw, 0);
5796 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5803 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5804 schedule_work(&priv->reset_work);
5808 orinoco_unlock(priv, &flags);
5812 static const struct iw_priv_args orinoco_privtab[] = {
5813 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5814 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5815 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5817 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5819 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5820 0, "set_preamble" },
5821 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5823 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5824 0, "set_ibssport" },
5825 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5827 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5833 * Structures to export the Wireless Handlers
5836 #define STD_IW_HANDLER(id, func) \
5837 [IW_IOCTL_IDX(id)] = (iw_handler) func
5838 static const iw_handler orinoco_handler[] = {
5839 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
5840 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
5841 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
5842 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
5843 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
5844 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
5845 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
5846 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
5847 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
5848 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
5849 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
5850 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
5851 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
5852 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
5853 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
5854 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
5855 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
5856 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
5857 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
5858 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
5859 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
5860 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
5861 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
5862 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
5863 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
5864 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
5865 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
5866 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
5867 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
5868 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
5869 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
5870 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
5871 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
5872 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
5873 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
5874 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
5875 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
5876 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
5877 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
5882 Added typecasting since we no longer use iwreq_data -- Moustafa
5884 static const iw_handler orinoco_private_handler[] = {
5885 [0] = (iw_handler) orinoco_ioctl_reset,
5886 [1] = (iw_handler) orinoco_ioctl_reset,
5887 [2] = (iw_handler) orinoco_ioctl_setport3,
5888 [3] = (iw_handler) orinoco_ioctl_getport3,
5889 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5890 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5891 [6] = (iw_handler) orinoco_ioctl_setibssport,
5892 [7] = (iw_handler) orinoco_ioctl_getibssport,
5893 [9] = (iw_handler) orinoco_ioctl_getrid,
5896 static const struct iw_handler_def orinoco_handler_def = {
5897 .num_standard = ARRAY_SIZE(orinoco_handler),
5898 .num_private = ARRAY_SIZE(orinoco_private_handler),
5899 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5900 .standard = orinoco_handler,
5901 .private = orinoco_private_handler,
5902 .private_args = orinoco_privtab,
5903 .get_wireless_stats = orinoco_get_wireless_stats,
5906 static void orinoco_get_drvinfo(struct net_device *dev,
5907 struct ethtool_drvinfo *info)
5909 struct orinoco_private *priv = netdev_priv(dev);
5911 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5912 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5913 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
5914 if (dev->dev.parent)
5915 strncpy(info->bus_info, dev_name(dev->dev.parent),
5916 sizeof(info->bus_info) - 1);
5918 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5919 "PCMCIA %p", priv->hw.iobase);
5922 static const struct ethtool_ops orinoco_ethtool_ops = {
5923 .get_drvinfo = orinoco_get_drvinfo,
5924 .get_link = ethtool_op_get_link,
5927 /********************************************************************/
5928 /* Module initialization */
5929 /********************************************************************/
5931 /* Can't be declared "const" or the whole __initdata section will
5933 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
5934 " (David Gibson <hermes@gibson.dropbear.id.au>, "
5935 "Pavel Roskin <proski@gnu.org>, et al)";
5937 static int __init init_orinoco(void)
5939 printk(KERN_DEBUG "%s\n", version);
5943 static void __exit exit_orinoco(void)
5947 module_init(init_orinoco);
5948 module_exit(exit_orinoco);