1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/module.h>
80 #include <linux/kernel.h>
81 #include <linux/init.h>
82 #include <linux/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"
100 /********************************************************************/
101 /* Module information */
102 /********************************************************************/
104 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
105 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
106 MODULE_LICENSE("Dual MPL/GPL");
108 /* Level of debugging. Used in the macros in orinoco.h */
110 int orinoco_debug = ORINOCO_DEBUG;
111 module_param(orinoco_debug, int, 0644);
112 MODULE_PARM_DESC(orinoco_debug, "Debug level");
113 EXPORT_SYMBOL(orinoco_debug);
116 static int suppress_linkstatus; /* = 0 */
117 module_param(suppress_linkstatus, bool, 0644);
118 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
119 static int ignore_disconnect; /* = 0 */
120 module_param(ignore_disconnect, int, 0644);
121 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
123 static int force_monitor; /* = 0 */
124 module_param(force_monitor, int, 0644);
125 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
127 /********************************************************************/
128 /* Compile time configuration and compatibility stuff */
129 /********************************************************************/
131 /* We do this this way to avoid ifdefs in the actual code */
133 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
135 #define SPY_NUMBER(priv) 0
136 #endif /* WIRELESS_SPY */
138 /********************************************************************/
139 /* Internal constants */
140 /********************************************************************/
142 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
143 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
144 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
146 #define ORINOCO_MIN_MTU 256
147 #define ORINOCO_MAX_MTU (IEEE80211_MAX_DATA_LEN - ENCAPS_OVERHEAD)
149 #define SYMBOL_MAX_VER_LEN (14)
152 #define MAX_IRQLOOPS_PER_IRQ 10
153 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
154 * how many events the
156 * legitimately generate */
157 #define SMALL_KEY_SIZE 5
158 #define LARGE_KEY_SIZE 13
159 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
161 #define DUMMY_FID 0xFFFF
163 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
164 HERMES_MAX_MULTICAST : 0)*/
165 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
167 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
168 | HERMES_EV_TX | HERMES_EV_TXEXC \
169 | HERMES_EV_WTERR | HERMES_EV_INFO \
170 | HERMES_EV_INFDROP )
172 #define MAX_RID_LEN 1024
174 static const struct iw_handler_def orinoco_handler_def;
175 static const struct ethtool_ops orinoco_ethtool_ops;
177 /********************************************************************/
179 /********************************************************************/
181 /* The frequency of each channel in MHz */
182 static const long channel_frequency[] = {
183 2412, 2417, 2422, 2427, 2432, 2437, 2442,
184 2447, 2452, 2457, 2462, 2467, 2472, 2484
186 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
188 /* This tables gives the actual meanings of the bitrate IDs returned
189 * by the firmware. */
191 int bitrate; /* in 100s of kilobits */
193 u16 agere_txratectrl;
194 u16 intersil_txratectrl;
195 } bitrate_table[] = {
196 {110, 1, 3, 15}, /* Entry 0 is the default */
205 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
207 /********************************************************************/
209 /********************************************************************/
211 /* Beginning of the Tx descriptor, used in TxExc handling */
212 struct hermes_txexc_data {
213 struct hermes_tx_descriptor desc;
217 } __attribute__ ((packed));
219 /* Rx frame header except compatibility 802.3 header */
220 struct hermes_rx_descriptor {
241 } __attribute__ ((packed));
243 /********************************************************************/
244 /* Function prototypes */
245 /********************************************************************/
247 static int __orinoco_program_rids(struct net_device *dev);
248 static void __orinoco_set_multicast_list(struct net_device *dev);
250 /********************************************************************/
251 /* Michael MIC crypto setup */
252 /********************************************************************/
253 #define MICHAEL_MIC_LEN 8
254 static int orinoco_mic_init(struct orinoco_private *priv)
256 priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
257 if (IS_ERR(priv->tx_tfm_mic)) {
258 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
259 "crypto API michael_mic\n");
260 priv->tx_tfm_mic = NULL;
264 priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
265 if (IS_ERR(priv->rx_tfm_mic)) {
266 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
267 "crypto API michael_mic\n");
268 priv->rx_tfm_mic = NULL;
275 static void orinoco_mic_free(struct orinoco_private *priv)
277 if (priv->tx_tfm_mic)
278 crypto_free_hash(priv->tx_tfm_mic);
279 if (priv->rx_tfm_mic)
280 crypto_free_hash(priv->rx_tfm_mic);
283 static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
284 u8 *da, u8 *sa, u8 priority,
285 u8 *data, size_t data_len, u8 *mic)
287 struct hash_desc desc;
288 struct scatterlist sg[2];
289 u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
291 if (tfm_michael == NULL) {
292 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
296 /* Copy header into buffer. We need the padding on the end zeroed */
297 memcpy(&hdr[0], da, ETH_ALEN);
298 memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
299 hdr[ETH_ALEN*2] = priority;
300 hdr[ETH_ALEN*2+1] = 0;
301 hdr[ETH_ALEN*2+2] = 0;
302 hdr[ETH_ALEN*2+3] = 0;
304 /* Use scatter gather to MIC header and data in one go */
305 sg_init_table(sg, 2);
306 sg_set_buf(&sg[0], hdr, sizeof(hdr));
307 sg_set_buf(&sg[1], data, data_len);
309 if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
312 desc.tfm = tfm_michael;
314 return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
318 /********************************************************************/
319 /* Internal helper functions */
320 /********************************************************************/
322 static inline void set_port_type(struct orinoco_private *priv)
324 switch (priv->iw_mode) {
327 priv->createibss = 0;
330 if (priv->prefer_port3) {
332 priv->createibss = 0;
334 priv->port_type = priv->ibss_port;
335 priv->createibss = 1;
338 case IW_MODE_MONITOR:
340 priv->createibss = 0;
343 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
348 #define ORINOCO_MAX_BSS_COUNT 64
349 static int orinoco_bss_data_allocate(struct orinoco_private *priv)
351 if (priv->bss_xbss_data)
354 if (priv->has_ext_scan)
355 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
356 sizeof(struct xbss_element),
359 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
360 sizeof(struct bss_element),
363 if (!priv->bss_xbss_data) {
364 printk(KERN_WARNING "Out of memory allocating beacons");
370 static void orinoco_bss_data_free(struct orinoco_private *priv)
372 kfree(priv->bss_xbss_data);
373 priv->bss_xbss_data = NULL;
376 #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
377 #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
378 static void orinoco_bss_data_init(struct orinoco_private *priv)
382 INIT_LIST_HEAD(&priv->bss_free_list);
383 INIT_LIST_HEAD(&priv->bss_list);
384 if (priv->has_ext_scan)
385 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
386 list_add_tail(&(PRIV_XBSS[i].list),
387 &priv->bss_free_list);
389 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
390 list_add_tail(&(PRIV_BSS[i].list),
391 &priv->bss_free_list);
395 static inline u8 *orinoco_get_ie(u8 *data, size_t len,
396 enum ieee80211_eid eid)
399 while ((p + 2) < (data + len)) {
407 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
408 #define WPA_SELECTOR_LEN 4
409 static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
412 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
413 if ((p[0] == WLAN_EID_GENERIC) &&
414 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
422 /********************************************************************/
423 /* Download functionality */
424 /********************************************************************/
434 const static struct fw_info orinoco_fw[] = {
435 { NULL, "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
436 { NULL, "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
437 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", NULL, 0x00003100, 512 }
440 /* Structure used to access fields in FW
441 * Make sure LE decoding macros are used
443 struct orinoco_fw_header {
444 char hdr_vers[6]; /* ASCII string for header version */
445 __le16 headersize; /* Total length of header */
446 __le32 entry_point; /* NIC entry point */
447 __le32 blocks; /* Number of blocks to program */
448 __le32 block_offset; /* Offset of block data from eof header */
449 __le32 pdr_offset; /* Offset to PDR data from eof header */
450 __le32 pri_offset; /* Offset to primary plug data */
451 __le32 compat_offset; /* Offset to compatibility data*/
452 char signature[0]; /* FW signature length headersize-20 */
453 } __attribute__ ((packed));
455 /* Download either STA or AP firmware into the card. */
457 orinoco_dl_firmware(struct orinoco_private *priv,
458 const struct fw_info *fw,
461 /* Plug Data Area (PDA) */
464 hermes_t *hw = &priv->hw;
465 const struct firmware *fw_entry;
466 const struct orinoco_fw_header *hdr;
467 const unsigned char *first_block;
468 const unsigned char *end;
469 const char *firmware;
470 struct net_device *dev = priv->ndev;
473 pda = kzalloc(fw->pda_size, GFP_KERNEL);
478 firmware = fw->ap_fw;
480 firmware = fw->sta_fw;
482 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
483 dev->name, firmware);
485 /* Read current plug data */
486 err = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 0);
487 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
491 if (!priv->cached_fw) {
492 err = request_firmware(&fw_entry, firmware, priv->dev);
495 printk(KERN_ERR "%s: Cannot find firmware %s\n",
496 dev->name, firmware);
501 fw_entry = priv->cached_fw;
503 hdr = (const struct orinoco_fw_header *) fw_entry->data;
505 /* Enable aux port to allow programming */
506 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
507 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
512 first_block = (fw_entry->data +
513 le16_to_cpu(hdr->headersize) +
514 le32_to_cpu(hdr->block_offset));
515 end = fw_entry->data + fw_entry->size;
517 err = hermes_program(hw, first_block, end);
518 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
522 /* Update production data */
523 first_block = (fw_entry->data +
524 le16_to_cpu(hdr->headersize) +
525 le32_to_cpu(hdr->pdr_offset));
527 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
528 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
532 /* Tell card we've finished */
533 err = hermesi_program_end(hw);
534 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
538 /* Check if we're running */
539 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
540 dev->name, hermes_present(hw));
543 /* If we requested the firmware, release it. */
544 if (!priv->cached_fw)
545 release_firmware(fw_entry);
553 #define TEXT_END 0x1A /* End of text header */
556 * Process a firmware image - stop the card, load the firmware, reset
557 * the card and make sure it responds. For the secondary firmware take
558 * care of the PDA - read it and then write it on top of the firmware.
561 symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
562 const unsigned char *image, const unsigned char *end,
565 hermes_t *hw = &priv->hw;
567 const unsigned char *ptr;
568 const unsigned char *first_block;
570 /* Plug Data Area (PDA) */
573 /* Binary block begins after the 0x1A marker */
575 while (*ptr++ != TEXT_END);
578 /* Read the PDA from EEPROM */
580 pda = kzalloc(fw->pda_size, GFP_KERNEL);
584 ret = hermes_read_pda(hw, pda, fw->pda_addr, fw->pda_size, 1);
589 /* Stop the firmware, so that it can be safely rewritten */
591 ret = priv->stop_fw(priv, 1);
596 /* Program the adapter with new firmware */
597 ret = hermes_program(hw, first_block, end);
601 /* Write the PDA to the adapter */
603 size_t len = hermes_blocks_length(first_block);
604 ptr = first_block + len;
605 ret = hermes_apply_pda(hw, ptr, pda);
611 /* Run the firmware */
613 ret = priv->stop_fw(priv, 0);
618 /* Reset hermes chip and make sure it responds */
619 ret = hermes_init(hw);
621 /* hermes_reset() should return 0 with the secondary firmware */
622 if (secondary && ret != 0)
625 /* And this should work with any firmware */
626 if (!hermes_present(hw))
638 * Download the firmware into the card, this also does a PCMCIA soft
639 * reset on the card, to make sure it's in a sane state.
642 symbol_dl_firmware(struct orinoco_private *priv,
643 const struct fw_info *fw)
645 struct net_device *dev = priv->ndev;
647 const struct firmware *fw_entry;
649 if (!priv->cached_pri_fw) {
650 if (request_firmware(&fw_entry, fw->pri_fw, priv->dev) != 0) {
651 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
652 dev->name, fw->pri_fw);
656 fw_entry = priv->cached_pri_fw;
658 /* Load primary firmware */
659 ret = symbol_dl_image(priv, fw, fw_entry->data,
660 fw_entry->data + fw_entry->size, 0);
662 if (!priv->cached_pri_fw)
663 release_firmware(fw_entry);
665 printk(KERN_ERR "%s: Primary firmware download failed\n",
670 if (!priv->cached_fw) {
671 if (request_firmware(&fw_entry, fw->sta_fw, priv->dev) != 0) {
672 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
673 dev->name, fw->sta_fw);
677 fw_entry = priv->cached_fw;
679 /* Load secondary firmware */
680 ret = symbol_dl_image(priv, fw, fw_entry->data,
681 fw_entry->data + fw_entry->size, 1);
682 if (!priv->cached_fw)
683 release_firmware(fw_entry);
685 printk(KERN_ERR "%s: Secondary firmware download failed\n",
692 static int orinoco_download(struct orinoco_private *priv)
695 /* Reload firmware */
696 switch (priv->firmware_type) {
697 case FIRMWARE_TYPE_AGERE:
698 /* case FIRMWARE_TYPE_INTERSIL: */
699 err = orinoco_dl_firmware(priv,
700 &orinoco_fw[priv->firmware_type], 0);
703 case FIRMWARE_TYPE_SYMBOL:
704 err = symbol_dl_firmware(priv,
705 &orinoco_fw[priv->firmware_type]);
707 case FIRMWARE_TYPE_INTERSIL:
710 /* TODO: if we fail we probably need to reinitialise
716 #if defined(CONFIG_HERMES_CACHE_FW_ON_INIT) || defined(CONFIG_PM_SLEEP)
717 static void orinoco_cache_fw(struct orinoco_private *priv, int ap)
719 const struct firmware *fw_entry = NULL;
723 pri_fw = orinoco_fw[priv->firmware_type].pri_fw;
725 fw = orinoco_fw[priv->firmware_type].ap_fw;
727 fw = orinoco_fw[priv->firmware_type].sta_fw;
730 if (request_firmware(&fw_entry, pri_fw, priv->dev) == 0)
731 priv->cached_pri_fw = fw_entry;
735 if (request_firmware(&fw_entry, fw, priv->dev) == 0)
736 priv->cached_fw = fw_entry;
740 static void orinoco_uncache_fw(struct orinoco_private *priv)
742 if (priv->cached_pri_fw)
743 release_firmware(priv->cached_pri_fw);
745 release_firmware(priv->cached_fw);
747 priv->cached_pri_fw = NULL;
748 priv->cached_fw = NULL;
751 #define orinoco_cache_fw(priv, ap)
752 #define orinoco_uncache_fw(priv)
755 /********************************************************************/
757 /********************************************************************/
759 static int orinoco_open(struct net_device *dev)
761 struct orinoco_private *priv = netdev_priv(dev);
765 if (orinoco_lock(priv, &flags) != 0)
768 err = __orinoco_up(dev);
773 orinoco_unlock(priv, &flags);
778 static int orinoco_stop(struct net_device *dev)
780 struct orinoco_private *priv = netdev_priv(dev);
783 /* We mustn't use orinoco_lock() here, because we need to be
784 able to close the interface even if hw_unavailable is set
785 (e.g. as we're released after a PC Card removal) */
786 spin_lock_irq(&priv->lock);
790 err = __orinoco_down(dev);
792 spin_unlock_irq(&priv->lock);
797 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
799 struct orinoco_private *priv = netdev_priv(dev);
804 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
806 struct orinoco_private *priv = netdev_priv(dev);
807 hermes_t *hw = &priv->hw;
808 struct iw_statistics *wstats = &priv->wstats;
812 if (! netif_device_present(dev)) {
813 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
815 return NULL; /* FIXME: Can we do better than this? */
818 /* If busy, return the old stats. Returning NULL may cause
819 * the interface to disappear from /proc/net/wireless */
820 if (orinoco_lock(priv, &flags) != 0)
823 /* We can't really wait for the tallies inquiry command to
824 * complete, so we just use the previous results and trigger
825 * a new tallies inquiry command for next time - Jean II */
826 /* FIXME: Really we should wait for the inquiry to come back -
827 * as it is the stats we give don't make a whole lot of sense.
828 * Unfortunately, it's not clear how to do that within the
829 * wireless extensions framework: I think we're in user
830 * context, but a lock seems to be held by the time we get in
831 * here so we're not safe to sleep here. */
832 hermes_inquire(hw, HERMES_INQ_TALLIES);
834 if (priv->iw_mode == IW_MODE_ADHOC) {
835 memset(&wstats->qual, 0, sizeof(wstats->qual));
836 /* If a spy address is defined, we report stats of the
837 * first spy address - Jean II */
838 if (SPY_NUMBER(priv)) {
839 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
840 wstats->qual.level = priv->spy_data.spy_stat[0].level;
841 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
842 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
846 __le16 qual, signal, noise, unused;
847 } __attribute__ ((packed)) cq;
849 err = HERMES_READ_RECORD(hw, USER_BAP,
850 HERMES_RID_COMMSQUALITY, &cq);
853 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
854 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
855 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
856 wstats->qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
860 orinoco_unlock(priv, &flags);
864 static void orinoco_set_multicast_list(struct net_device *dev)
866 struct orinoco_private *priv = netdev_priv(dev);
869 if (orinoco_lock(priv, &flags) != 0) {
870 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
871 "called when hw_unavailable\n", dev->name);
875 __orinoco_set_multicast_list(dev);
876 orinoco_unlock(priv, &flags);
879 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
881 struct orinoco_private *priv = netdev_priv(dev);
883 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
886 /* MTU + encapsulation + header length */
887 if ( (new_mtu + ENCAPS_OVERHEAD + sizeof(struct ieee80211_hdr)) >
888 (priv->nicbuf_size - ETH_HLEN) )
896 /********************************************************************/
898 /********************************************************************/
900 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
902 struct orinoco_private *priv = netdev_priv(dev);
903 struct net_device_stats *stats = &priv->stats;
904 hermes_t *hw = &priv->hw;
906 u16 txfid = priv->txfid;
911 if (! netif_running(dev)) {
912 printk(KERN_ERR "%s: Tx on stopped device!\n",
914 return NETDEV_TX_BUSY;
917 if (netif_queue_stopped(dev)) {
918 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
920 return NETDEV_TX_BUSY;
923 if (orinoco_lock(priv, &flags) != 0) {
924 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
926 return NETDEV_TX_BUSY;
929 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
930 /* Oops, the firmware hasn't established a connection,
931 silently drop the packet (this seems to be the
936 /* Check packet length */
937 if (skb->len < ETH_HLEN)
940 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
942 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
943 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
946 if (priv->has_alt_txcntl) {
947 /* WPA enabled firmwares have tx_cntl at the end of
948 * the 802.11 header. So write zeroed descriptor and
949 * 802.11 header at the same time
951 char desc[HERMES_802_3_OFFSET];
952 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
954 memset(&desc, 0, sizeof(desc));
956 *txcntl = cpu_to_le16(tx_control);
957 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
961 printk(KERN_ERR "%s: Error %d writing Tx "
962 "descriptor to BAP\n", dev->name, err);
966 struct hermes_tx_descriptor desc;
968 memset(&desc, 0, sizeof(desc));
970 desc.tx_control = cpu_to_le16(tx_control);
971 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
975 printk(KERN_ERR "%s: Error %d writing Tx "
976 "descriptor to BAP\n", dev->name, err);
980 /* Clear the 802.11 header and data length fields - some
981 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
982 * if this isn't done. */
983 hermes_clear_words(hw, HERMES_DATA0,
984 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
987 eh = (struct ethhdr *)skb->data;
989 /* Encapsulate Ethernet-II frames */
990 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
991 struct header_struct {
992 struct ethhdr eth; /* 802.3 header */
993 u8 encap[6]; /* 802.2 header */
994 } __attribute__ ((packed)) hdr;
996 /* Strip destination and source from the data */
997 skb_pull(skb, 2 * ETH_ALEN);
999 /* And move them to a separate header */
1000 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
1001 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
1002 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
1004 /* Insert the SNAP header */
1005 if (skb_headroom(skb) < sizeof(hdr)) {
1007 "%s: Not enough headroom for 802.2 headers %d\n",
1008 dev->name, skb_headroom(skb));
1011 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
1012 memcpy(eh, &hdr, sizeof(hdr));
1015 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
1016 txfid, HERMES_802_3_OFFSET);
1018 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
1023 /* Calculate Michael MIC */
1024 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
1025 u8 mic_buf[MICHAEL_MIC_LEN + 1];
1031 /* MIC start is on an odd boundary */
1032 mic_buf[0] = skb->data[skb->len - 1];
1034 offset = skb->len - 1;
1035 len = MICHAEL_MIC_LEN + 1;
1039 len = MICHAEL_MIC_LEN;
1042 michael_mic(priv->tx_tfm_mic,
1043 priv->tkip_key[priv->tx_key].tx_mic,
1044 eh->h_dest, eh->h_source, 0 /* priority */,
1045 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
1048 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
1049 txfid, HERMES_802_3_OFFSET + offset);
1051 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
1057 /* Finally, we actually initiate the send */
1058 netif_stop_queue(dev);
1060 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
1063 netif_start_queue(dev);
1064 if (net_ratelimit())
1065 printk(KERN_ERR "%s: Error %d transmitting packet\n",
1070 dev->trans_start = jiffies;
1071 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
1076 stats->tx_dropped++;
1079 orinoco_unlock(priv, &flags);
1081 return NETDEV_TX_OK;
1085 schedule_work(&priv->reset_work);
1086 orinoco_unlock(priv, &flags);
1087 return NETDEV_TX_BUSY;
1090 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1092 struct orinoco_private *priv = netdev_priv(dev);
1093 u16 fid = hermes_read_regn(hw, ALLOCFID);
1095 if (fid != priv->txfid) {
1096 if (fid != DUMMY_FID)
1097 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1102 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1105 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1107 struct orinoco_private *priv = netdev_priv(dev);
1108 struct net_device_stats *stats = &priv->stats;
1110 stats->tx_packets++;
1112 netif_wake_queue(dev);
1114 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1117 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1119 struct orinoco_private *priv = netdev_priv(dev);
1120 struct net_device_stats *stats = &priv->stats;
1121 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
1123 struct hermes_txexc_data hdr;
1126 if (fid == DUMMY_FID)
1127 return; /* Nothing's really happened */
1129 /* Read part of the frame header - we need status and addr1 */
1130 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
1131 sizeof(struct hermes_txexc_data),
1134 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1138 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1139 "(FID=%04X error %d)\n",
1140 dev->name, fid, err);
1144 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1147 /* We produce a TXDROP event only for retry or lifetime
1148 * exceeded, because that's the only status that really mean
1149 * that this particular node went away.
1150 * Other errors means that *we* screwed up. - Jean II */
1151 status = le16_to_cpu(hdr.desc.status);
1152 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
1153 union iwreq_data wrqu;
1155 /* Copy 802.11 dest address.
1156 * We use the 802.11 header because the frame may
1157 * not be 802.3 or may be mangled...
1158 * In Ad-Hoc mode, it will be the node address.
1159 * In managed mode, it will be most likely the AP addr
1160 * User space will figure out how to convert it to
1161 * whatever it needs (IP address or else).
1163 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1164 wrqu.addr.sa_family = ARPHRD_ETHER;
1166 /* Send event to user space */
1167 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1170 netif_wake_queue(dev);
1173 static void orinoco_tx_timeout(struct net_device *dev)
1175 struct orinoco_private *priv = netdev_priv(dev);
1176 struct net_device_stats *stats = &priv->stats;
1177 struct hermes *hw = &priv->hw;
1179 printk(KERN_WARNING "%s: Tx timeout! "
1180 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1181 dev->name, hermes_read_regn(hw, ALLOCFID),
1182 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1186 schedule_work(&priv->reset_work);
1189 /********************************************************************/
1190 /* Rx path (data frames) */
1191 /********************************************************************/
1193 /* Does the frame have a SNAP header indicating it should be
1194 * de-encapsulated to Ethernet-II? */
1195 static inline int is_ethersnap(void *_hdr)
1199 /* We de-encapsulate all packets which, a) have SNAP headers
1200 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1201 * and where b) the OUI of the SNAP header is 00:00:00 or
1202 * 00:00:f8 - we need both because different APs appear to use
1203 * different OUIs for some reason */
1204 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1205 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1208 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1209 int level, int noise)
1211 struct iw_quality wstats;
1212 wstats.level = level - 0x95;
1213 wstats.noise = noise - 0x95;
1214 wstats.qual = (level > noise) ? (level - noise) : 0;
1215 wstats.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1216 /* Update spy records */
1217 wireless_spy_update(dev, mac, &wstats);
1220 static void orinoco_stat_gather(struct net_device *dev,
1221 struct sk_buff *skb,
1222 struct hermes_rx_descriptor *desc)
1224 struct orinoco_private *priv = netdev_priv(dev);
1226 /* Using spy support with lots of Rx packets, like in an
1227 * infrastructure (AP), will really slow down everything, because
1228 * the MAC address must be compared to each entry of the spy list.
1229 * If the user really asks for it (set some address in the
1230 * spy list), we do it, but he will pay the price.
1231 * Note that to get here, you need both WIRELESS_SPY
1232 * compiled in AND some addresses in the list !!!
1234 /* Note : gcc will optimise the whole section away if
1235 * WIRELESS_SPY is not defined... - Jean II */
1236 if (SPY_NUMBER(priv)) {
1237 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1238 desc->signal, desc->silence);
1243 * orinoco_rx_monitor - handle received monitor frames.
1246 * dev network device
1247 * rxfid received FID
1248 * desc rx descriptor of the frame
1250 * Call context: interrupt
1252 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1253 struct hermes_rx_descriptor *desc)
1255 u32 hdrlen = 30; /* return full header by default */
1260 struct sk_buff *skb;
1261 struct orinoco_private *priv = netdev_priv(dev);
1262 struct net_device_stats *stats = &priv->stats;
1263 hermes_t *hw = &priv->hw;
1265 len = le16_to_cpu(desc->data_len);
1267 /* Determine the size of the header and the data */
1268 fc = le16_to_cpu(desc->frame_ctl);
1269 switch (fc & IEEE80211_FCTL_FTYPE) {
1270 case IEEE80211_FTYPE_DATA:
1271 if ((fc & IEEE80211_FCTL_TODS)
1272 && (fc & IEEE80211_FCTL_FROMDS))
1278 case IEEE80211_FTYPE_MGMT:
1282 case IEEE80211_FTYPE_CTL:
1283 switch (fc & IEEE80211_FCTL_STYPE) {
1284 case IEEE80211_STYPE_PSPOLL:
1285 case IEEE80211_STYPE_RTS:
1286 case IEEE80211_STYPE_CFEND:
1287 case IEEE80211_STYPE_CFENDACK:
1290 case IEEE80211_STYPE_CTS:
1291 case IEEE80211_STYPE_ACK:
1297 /* Unknown frame type */
1301 /* sanity check the length */
1302 if (datalen > IEEE80211_MAX_DATA_LEN + 12) {
1303 printk(KERN_DEBUG "%s: oversized monitor frame, "
1304 "data length = %d\n", dev->name, datalen);
1305 stats->rx_length_errors++;
1309 skb = dev_alloc_skb(hdrlen + datalen);
1311 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1316 /* Copy the 802.11 header to the skb */
1317 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
1318 skb_reset_mac_header(skb);
1320 /* If any, copy the data from the card to the skb */
1322 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1323 ALIGN(datalen, 2), rxfid,
1324 HERMES_802_2_OFFSET);
1326 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1333 skb->ip_summed = CHECKSUM_NONE;
1334 skb->pkt_type = PACKET_OTHERHOST;
1335 skb->protocol = __constant_htons(ETH_P_802_2);
1337 stats->rx_packets++;
1338 stats->rx_bytes += skb->len;
1344 dev_kfree_skb_irq(skb);
1347 stats->rx_dropped++;
1350 /* Get tsc from the firmware */
1351 static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1354 hermes_t *hw = &priv->hw;
1356 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1358 if ((key < 0) || (key > 4))
1361 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1362 sizeof(tsc_arr), NULL, &tsc_arr);
1364 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1369 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1371 struct orinoco_private *priv = netdev_priv(dev);
1372 struct net_device_stats *stats = &priv->stats;
1373 struct iw_statistics *wstats = &priv->wstats;
1374 struct sk_buff *skb = NULL;
1377 struct hermes_rx_descriptor *desc;
1378 struct orinoco_rx_data *rx_data;
1381 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1384 "%s: Can't allocate space for RX descriptor\n",
1389 rxfid = hermes_read_regn(hw, RXFID);
1391 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
1394 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1395 "Frame dropped.\n", dev->name, err);
1399 status = le16_to_cpu(desc->status);
1401 if (status & HERMES_RXSTAT_BADCRC) {
1402 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1404 stats->rx_crc_errors++;
1408 /* Handle frames in monitor mode */
1409 if (priv->iw_mode == IW_MODE_MONITOR) {
1410 orinoco_rx_monitor(dev, rxfid, desc);
1414 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1415 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1417 wstats->discard.code++;
1421 length = le16_to_cpu(desc->data_len);
1424 if (length < 3) { /* No for even an 802.2 LLC header */
1425 /* At least on Symbol firmware with PCF we get quite a
1426 lot of these legitimately - Poll frames with no
1430 if (length > IEEE80211_MAX_DATA_LEN) {
1431 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1433 stats->rx_length_errors++;
1437 /* Payload size does not include Michael MIC. Increase payload
1438 * size to read it together with the data. */
1439 if (status & HERMES_RXSTAT_MIC)
1440 length += MICHAEL_MIC_LEN;
1442 /* We need space for the packet data itself, plus an ethernet
1443 header, plus 2 bytes so we can align the IP header on a
1444 32bit boundary, plus 1 byte so we can read in odd length
1445 packets from the card, which has an IO granularity of 16
1447 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1449 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1454 /* We'll prepend the header, so reserve space for it. The worst
1455 case is no decapsulation, when 802.3 header is prepended and
1456 nothing is removed. 2 is for aligning the IP header. */
1457 skb_reserve(skb, ETH_HLEN + 2);
1459 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1460 ALIGN(length, 2), rxfid,
1461 HERMES_802_2_OFFSET);
1463 printk(KERN_ERR "%s: error %d reading frame. "
1464 "Frame dropped.\n", dev->name, err);
1468 /* Add desc and skb to rx queue */
1469 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1471 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1475 rx_data->desc = desc;
1477 list_add_tail(&rx_data->list, &priv->rx_list);
1478 tasklet_schedule(&priv->rx_tasklet);
1483 dev_kfree_skb_irq(skb);
1486 stats->rx_dropped++;
1491 static void orinoco_rx(struct net_device *dev,
1492 struct hermes_rx_descriptor *desc,
1493 struct sk_buff *skb)
1495 struct orinoco_private *priv = netdev_priv(dev);
1496 struct net_device_stats *stats = &priv->stats;
1501 status = le16_to_cpu(desc->status);
1502 length = le16_to_cpu(desc->data_len);
1503 fc = le16_to_cpu(desc->frame_ctl);
1505 /* Calculate and check MIC */
1506 if (status & HERMES_RXSTAT_MIC) {
1507 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1508 HERMES_MIC_KEY_ID_SHIFT);
1509 u8 mic[MICHAEL_MIC_LEN];
1511 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1512 desc->addr3 : desc->addr2;
1514 /* Extract Michael MIC from payload */
1515 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1517 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1518 length -= MICHAEL_MIC_LEN;
1520 michael_mic(priv->rx_tfm_mic,
1521 priv->tkip_key[key_id].rx_mic,
1524 0, /* priority or QoS? */
1529 if (memcmp(mic, rxmic,
1531 union iwreq_data wrqu;
1532 struct iw_michaelmicfailure wxmic;
1534 printk(KERN_WARNING "%s: "
1535 "Invalid Michael MIC in data frame from %pM, "
1537 dev->name, src, key_id);
1539 /* TODO: update stats */
1541 /* Notify userspace */
1542 memset(&wxmic, 0, sizeof(wxmic));
1543 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1544 wxmic.flags |= (desc->addr1[0] & 1) ?
1545 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1546 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1547 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1549 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1552 memset(&wrqu, 0, sizeof(wrqu));
1553 wrqu.data.length = sizeof(wxmic);
1554 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1561 /* Handle decapsulation
1562 * In most cases, the firmware tell us about SNAP frames.
1563 * For some reason, the SNAP frames sent by LinkSys APs
1564 * are not properly recognised by most firmwares.
1565 * So, check ourselves */
1566 if (length >= ENCAPS_OVERHEAD &&
1567 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1568 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1569 is_ethersnap(skb->data))) {
1570 /* These indicate a SNAP within 802.2 LLC within
1571 802.11 frame which we'll need to de-encapsulate to
1572 the original EthernetII frame. */
1573 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1575 /* 802.3 frame - prepend 802.3 header as is */
1576 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1577 hdr->h_proto = htons(length);
1579 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
1580 if (fc & IEEE80211_FCTL_FROMDS)
1581 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
1583 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
1585 skb->protocol = eth_type_trans(skb, dev);
1586 skb->ip_summed = CHECKSUM_NONE;
1587 if (fc & IEEE80211_FCTL_TODS)
1588 skb->pkt_type = PACKET_OTHERHOST;
1590 /* Process the wireless stats if needed */
1591 orinoco_stat_gather(dev, skb, desc);
1593 /* Pass the packet to the networking stack */
1595 stats->rx_packets++;
1596 stats->rx_bytes += length;
1603 stats->rx_dropped++;
1606 static void orinoco_rx_isr_tasklet(unsigned long data)
1608 struct net_device *dev = (struct net_device *) data;
1609 struct orinoco_private *priv = netdev_priv(dev);
1610 struct orinoco_rx_data *rx_data, *temp;
1611 struct hermes_rx_descriptor *desc;
1612 struct sk_buff *skb;
1613 unsigned long flags;
1615 /* orinoco_rx requires the driver lock, and we also need to
1616 * protect priv->rx_list, so just hold the lock over the
1619 * If orinoco_lock fails, we've unplugged the card. In this
1620 * case just abort. */
1621 if (orinoco_lock(priv, &flags) != 0)
1624 /* extract desc and skb from queue */
1625 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1626 desc = rx_data->desc;
1628 list_del(&rx_data->list);
1631 orinoco_rx(dev, desc, skb);
1636 orinoco_unlock(priv, &flags);
1639 /********************************************************************/
1640 /* Rx path (info frames) */
1641 /********************************************************************/
1643 static void print_linkstatus(struct net_device *dev, u16 status)
1647 if (suppress_linkstatus)
1651 case HERMES_LINKSTATUS_NOT_CONNECTED:
1652 s = "Not Connected";
1654 case HERMES_LINKSTATUS_CONNECTED:
1657 case HERMES_LINKSTATUS_DISCONNECTED:
1660 case HERMES_LINKSTATUS_AP_CHANGE:
1663 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1664 s = "AP Out of Range";
1666 case HERMES_LINKSTATUS_AP_IN_RANGE:
1669 case HERMES_LINKSTATUS_ASSOC_FAILED:
1670 s = "Association Failed";
1676 printk(KERN_DEBUG "%s: New link status: %s (%04x)\n",
1677 dev->name, s, status);
1680 /* Search scan results for requested BSSID, join it if found */
1681 static void orinoco_join_ap(struct work_struct *work)
1683 struct orinoco_private *priv =
1684 container_of(work, struct orinoco_private, join_work);
1685 struct net_device *dev = priv->ndev;
1686 struct hermes *hw = &priv->hw;
1688 unsigned long flags;
1692 } __attribute__ ((packed)) req;
1693 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1694 struct prism2_scan_apinfo *atom = NULL;
1700 /* Allocate buffer for scan results */
1701 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1705 if (orinoco_lock(priv, &flags) != 0)
1708 /* Sanity checks in case user changed something in the meantime */
1709 if (! priv->bssid_fixed)
1712 if (strlen(priv->desired_essid) == 0)
1715 /* Read scan results from the firmware */
1716 err = hermes_read_ltv(hw, USER_BAP,
1717 HERMES_RID_SCANRESULTSTABLE,
1718 MAX_SCAN_LEN, &len, buf);
1720 printk(KERN_ERR "%s: Cannot read scan results\n",
1725 len = HERMES_RECLEN_TO_BYTES(len);
1727 /* Go through the scan results looking for the channel of the AP
1728 * we were requested to join */
1729 for (; offset + atom_len <= len; offset += atom_len) {
1730 atom = (struct prism2_scan_apinfo *) (buf + offset);
1731 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1738 DEBUG(1, "%s: Requested AP not found in scan results\n",
1743 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1744 req.channel = atom->channel; /* both are little-endian */
1745 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1748 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1751 orinoco_unlock(priv, &flags);
1757 /* Send new BSSID to userspace */
1758 static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
1760 struct net_device *dev = priv->ndev;
1761 struct hermes *hw = &priv->hw;
1762 union iwreq_data wrqu;
1765 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
1766 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1770 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1772 /* Send event to user space */
1773 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1776 static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1778 struct net_device *dev = priv->ndev;
1779 struct hermes *hw = &priv->hw;
1780 union iwreq_data wrqu;
1788 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1789 sizeof(buf), NULL, &buf);
1793 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1795 int rem = sizeof(buf) - (ie - &buf[0]);
1796 wrqu.data.length = ie[1] + 2;
1797 if (wrqu.data.length > rem)
1798 wrqu.data.length = rem;
1800 if (wrqu.data.length)
1801 /* Send event to user space */
1802 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1806 static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1808 struct net_device *dev = priv->ndev;
1809 struct hermes *hw = &priv->hw;
1810 union iwreq_data wrqu;
1812 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1818 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1819 sizeof(buf), NULL, &buf);
1823 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1825 int rem = sizeof(buf) - (ie - &buf[0]);
1826 wrqu.data.length = ie[1] + 2;
1827 if (wrqu.data.length > rem)
1828 wrqu.data.length = rem;
1830 if (wrqu.data.length)
1831 /* Send event to user space */
1832 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1836 static void orinoco_send_wevents(struct work_struct *work)
1838 struct orinoco_private *priv =
1839 container_of(work, struct orinoco_private, wevent_work);
1840 unsigned long flags;
1842 if (orinoco_lock(priv, &flags) != 0)
1845 orinoco_send_assocreqie_wevent(priv);
1846 orinoco_send_assocrespie_wevent(priv);
1847 orinoco_send_bssid_wevent(priv);
1849 orinoco_unlock(priv, &flags);
1852 static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1853 unsigned long scan_age)
1855 if (priv->has_ext_scan) {
1856 struct xbss_element *bss;
1857 struct xbss_element *tmp_bss;
1859 /* Blow away current list of scan results */
1860 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1862 time_after(jiffies, bss->last_scanned + scan_age)) {
1863 list_move_tail(&bss->list,
1864 &priv->bss_free_list);
1865 /* Don't blow away ->list, just BSS data */
1866 memset(&bss->bss, 0, sizeof(bss->bss));
1867 bss->last_scanned = 0;
1871 struct bss_element *bss;
1872 struct bss_element *tmp_bss;
1874 /* Blow away current list of scan results */
1875 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1877 time_after(jiffies, bss->last_scanned + scan_age)) {
1878 list_move_tail(&bss->list,
1879 &priv->bss_free_list);
1880 /* Don't blow away ->list, just BSS data */
1881 memset(&bss->bss, 0, sizeof(bss->bss));
1882 bss->last_scanned = 0;
1888 static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
1889 struct agere_ext_scan_info *atom)
1891 struct xbss_element *bss = NULL;
1894 /* Try to update an existing bss first */
1895 list_for_each_entry(bss, &priv->bss_list, list) {
1896 if (compare_ether_addr(bss->bss.bssid, atom->bssid))
1899 if (bss->bss.data[1] != atom->data[1])
1901 if (memcmp(&bss->bss.data[2], &atom->data[2],
1908 /* Grab a bss off the free list */
1909 if (!found && !list_empty(&priv->bss_free_list)) {
1910 bss = list_entry(priv->bss_free_list.next,
1911 struct xbss_element, list);
1912 list_del(priv->bss_free_list.next);
1914 list_add_tail(&bss->list, &priv->bss_list);
1918 /* Always update the BSS to get latest beacon info */
1919 memcpy(&bss->bss, atom, sizeof(bss->bss));
1920 bss->last_scanned = jiffies;
1924 static int orinoco_process_scan_results(struct net_device *dev,
1928 struct orinoco_private *priv = netdev_priv(dev);
1929 int offset; /* In the scan data */
1930 union hermes_scan_info *atom;
1933 switch (priv->firmware_type) {
1934 case FIRMWARE_TYPE_AGERE:
1935 atom_len = sizeof(struct agere_scan_apinfo);
1938 case FIRMWARE_TYPE_SYMBOL:
1939 /* Lack of documentation necessitates this hack.
1940 * Different firmwares have 68 or 76 byte long atoms.
1941 * We try modulo first. If the length divides by both,
1942 * we check what would be the channel in the second
1943 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1944 * Valid channel cannot be 0. */
1949 else if (len >= 1292 && buf[68] == 0)
1955 case FIRMWARE_TYPE_INTERSIL:
1957 if (priv->has_hostscan) {
1958 atom_len = le16_to_cpup((__le16 *)buf);
1959 /* Sanity check for atom_len */
1960 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1961 printk(KERN_ERR "%s: Invalid atom_len in scan "
1962 "data: %d\n", dev->name, atom_len);
1966 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1972 /* Check that we got an whole number of atoms */
1973 if ((len - offset) % atom_len) {
1974 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1975 "atom_len %d, offset %d\n", dev->name, len,
1980 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1982 /* Read the entries one by one */
1983 for (; offset + atom_len <= len; offset += atom_len) {
1985 struct bss_element *bss = NULL;
1988 atom = (union hermes_scan_info *) (buf + offset);
1990 /* Try to update an existing bss first */
1991 list_for_each_entry(bss, &priv->bss_list, list) {
1992 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1994 if (le16_to_cpu(bss->bss.a.essid_len) !=
1995 le16_to_cpu(atom->a.essid_len))
1997 if (memcmp(bss->bss.a.essid, atom->a.essid,
1998 le16_to_cpu(atom->a.essid_len)))
2004 /* Grab a bss off the free list */
2005 if (!found && !list_empty(&priv->bss_free_list)) {
2006 bss = list_entry(priv->bss_free_list.next,
2007 struct bss_element, list);
2008 list_del(priv->bss_free_list.next);
2010 list_add_tail(&bss->list, &priv->bss_list);
2014 /* Always update the BSS to get latest beacon info */
2015 memcpy(&bss->bss, atom, sizeof(bss->bss));
2016 bss->last_scanned = jiffies;
2023 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
2025 struct orinoco_private *priv = netdev_priv(dev);
2030 } __attribute__ ((packed)) info;
2034 /* This is an answer to an INQUIRE command that we did earlier,
2035 * or an information "event" generated by the card
2036 * The controller return to us a pseudo frame containing
2037 * the information in question - Jean II */
2038 infofid = hermes_read_regn(hw, INFOFID);
2040 /* Read the info frame header - don't try too hard */
2041 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
2044 printk(KERN_ERR "%s: error %d reading info frame. "
2045 "Frame dropped.\n", dev->name, err);
2049 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
2050 type = le16_to_cpu(info.type);
2053 case HERMES_INQ_TALLIES: {
2054 struct hermes_tallies_frame tallies;
2055 struct iw_statistics *wstats = &priv->wstats;
2057 if (len > sizeof(tallies)) {
2058 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
2060 len = sizeof(tallies);
2063 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
2064 infofid, sizeof(info));
2068 /* Increment our various counters */
2069 /* wstats->discard.nwid - no wrong BSSID stuff */
2070 wstats->discard.code +=
2071 le16_to_cpu(tallies.RxWEPUndecryptable);
2072 if (len == sizeof(tallies))
2073 wstats->discard.code +=
2074 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
2075 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
2076 wstats->discard.misc +=
2077 le16_to_cpu(tallies.TxDiscardsWrongSA);
2078 wstats->discard.fragment +=
2079 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
2080 wstats->discard.retries +=
2081 le16_to_cpu(tallies.TxRetryLimitExceeded);
2082 /* wstats->miss.beacon - no match */
2085 case HERMES_INQ_LINKSTATUS: {
2086 struct hermes_linkstatus linkstatus;
2090 if (priv->iw_mode == IW_MODE_MONITOR)
2093 if (len != sizeof(linkstatus)) {
2094 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
2099 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
2100 infofid, sizeof(info));
2103 newstatus = le16_to_cpu(linkstatus.linkstatus);
2105 /* Symbol firmware uses "out of range" to signal that
2106 * the hostscan frame can be requested. */
2107 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
2108 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
2109 priv->has_hostscan && priv->scan_inprogress) {
2110 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
2114 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
2115 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
2116 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
2119 netif_carrier_on(dev);
2120 else if (!ignore_disconnect)
2121 netif_carrier_off(dev);
2123 if (newstatus != priv->last_linkstatus) {
2124 priv->last_linkstatus = newstatus;
2125 print_linkstatus(dev, newstatus);
2126 /* The info frame contains only one word which is the
2127 * status (see hermes.h). The status is pretty boring
2128 * in itself, that's why we export the new BSSID...
2130 schedule_work(&priv->wevent_work);
2134 case HERMES_INQ_SCAN:
2135 if (!priv->scan_inprogress && priv->bssid_fixed &&
2136 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
2137 schedule_work(&priv->join_work);
2141 case HERMES_INQ_HOSTSCAN:
2142 case HERMES_INQ_HOSTSCAN_SYMBOL: {
2143 /* Result of a scanning. Contains information about
2144 * cells in the vicinity - Jean II */
2145 union iwreq_data wrqu;
2148 /* Scan is no longer in progress */
2149 priv->scan_inprogress = 0;
2153 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
2158 /* Allocate buffer for results */
2159 buf = kmalloc(len, GFP_ATOMIC);
2161 /* No memory, so can't printk()... */
2164 /* Read scan data */
2165 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
2166 infofid, sizeof(info));
2172 #ifdef ORINOCO_DEBUG
2175 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
2176 for(i = 1; i < (len * 2); i++)
2177 printk(":%02X", buf[i]);
2180 #endif /* ORINOCO_DEBUG */
2182 if (orinoco_process_scan_results(dev, buf, len) == 0) {
2183 /* Send an empty event to user space.
2184 * We don't send the received data on the event because
2185 * it would require us to do complex transcoding, and
2186 * we want to minimise the work done in the irq handler
2187 * Use a request to extract the data - Jean II */
2188 wrqu.data.length = 0;
2189 wrqu.data.flags = 0;
2190 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2195 case HERMES_INQ_CHANNELINFO:
2197 struct agere_ext_scan_info *bss;
2199 if (!priv->scan_inprogress) {
2200 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
2201 "len=%d\n", dev->name, len);
2205 /* An empty result indicates that the scan is complete */
2207 union iwreq_data wrqu;
2209 /* Scan is no longer in progress */
2210 priv->scan_inprogress = 0;
2212 wrqu.data.length = 0;
2213 wrqu.data.flags = 0;
2214 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2219 else if (len > sizeof(*bss)) {
2221 "%s: Ext scan results too large (%d bytes). "
2222 "Truncating results to %zd bytes.\n",
2223 dev->name, len, sizeof(*bss));
2225 } else if (len < (offsetof(struct agere_ext_scan_info,
2227 /* Drop this result now so we don't have to
2228 * keep checking later */
2230 "%s: Ext scan results too short (%d bytes)\n",
2235 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
2239 /* Read scan data */
2240 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
2241 infofid, sizeof(info));
2247 orinoco_add_ext_scan_result(priv, bss);
2252 case HERMES_INQ_SEC_STAT_AGERE:
2253 /* Security status (Agere specific) */
2254 /* Ignore this frame for now */
2255 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2259 printk(KERN_DEBUG "%s: Unknown information frame received: "
2260 "type 0x%04x, length %d\n", dev->name, type, len);
2261 /* We don't actually do anything about it */
2266 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
2268 if (net_ratelimit())
2269 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
2272 /********************************************************************/
2273 /* Internal hardware control routines */
2274 /********************************************************************/
2276 int __orinoco_up(struct net_device *dev)
2278 struct orinoco_private *priv = netdev_priv(dev);
2279 struct hermes *hw = &priv->hw;
2282 netif_carrier_off(dev); /* just to make sure */
2284 err = __orinoco_program_rids(dev);
2286 printk(KERN_ERR "%s: Error %d configuring card\n",
2291 /* Fire things up again */
2292 hermes_set_irqmask(hw, ORINOCO_INTEN);
2293 err = hermes_enable_port(hw, 0);
2295 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2300 netif_start_queue(dev);
2305 int __orinoco_down(struct net_device *dev)
2307 struct orinoco_private *priv = netdev_priv(dev);
2308 struct hermes *hw = &priv->hw;
2311 netif_stop_queue(dev);
2313 if (! priv->hw_unavailable) {
2314 if (! priv->broken_disableport) {
2315 err = hermes_disable_port(hw, 0);
2317 /* Some firmwares (e.g. Intersil 1.3.x) seem
2318 * to have problems disabling the port, oh
2320 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2322 priv->broken_disableport = 1;
2325 hermes_set_irqmask(hw, 0);
2326 hermes_write_regn(hw, EVACK, 0xffff);
2329 /* firmware will have to reassociate */
2330 netif_carrier_off(dev);
2331 priv->last_linkstatus = 0xffff;
2336 static int orinoco_allocate_fid(struct net_device *dev)
2338 struct orinoco_private *priv = netdev_priv(dev);
2339 struct hermes *hw = &priv->hw;
2342 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2343 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
2344 /* Try workaround for old Symbol firmware bug */
2345 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2346 "(old Symbol firmware?). Trying to work around... ",
2349 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2350 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2352 printk("failed!\n");
2360 int orinoco_reinit_firmware(struct net_device *dev)
2362 struct orinoco_private *priv = netdev_priv(dev);
2363 struct hermes *hw = &priv->hw;
2366 err = hermes_init(hw);
2367 if (priv->do_fw_download && !err) {
2368 err = orinoco_download(priv);
2370 priv->do_fw_download = 0;
2373 err = orinoco_allocate_fid(dev);
2378 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2380 hermes_t *hw = &priv->hw;
2383 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
2384 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
2385 priv->ndev->name, priv->bitratemode);
2389 switch (priv->firmware_type) {
2390 case FIRMWARE_TYPE_AGERE:
2391 err = hermes_write_wordrec(hw, USER_BAP,
2392 HERMES_RID_CNFTXRATECONTROL,
2393 bitrate_table[priv->bitratemode].agere_txratectrl);
2395 case FIRMWARE_TYPE_INTERSIL:
2396 case FIRMWARE_TYPE_SYMBOL:
2397 err = hermes_write_wordrec(hw, USER_BAP,
2398 HERMES_RID_CNFTXRATECONTROL,
2399 bitrate_table[priv->bitratemode].intersil_txratectrl);
2408 /* Set fixed AP address */
2409 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2413 hermes_t *hw = &priv->hw;
2415 switch (priv->firmware_type) {
2416 case FIRMWARE_TYPE_AGERE:
2419 case FIRMWARE_TYPE_INTERSIL:
2420 if (priv->bssid_fixed)
2425 err = hermes_write_wordrec(hw, USER_BAP,
2426 HERMES_RID_CNFROAMINGMODE,
2429 case FIRMWARE_TYPE_SYMBOL:
2430 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2431 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2432 &priv->desired_bssid);
2438 /* Change the WEP keys and/or the current keys. Can be called
2439 * either from __orinoco_hw_setup_enc() or directly from
2440 * orinoco_ioctl_setiwencode(). In the later case the association
2441 * with the AP is not broken (if the firmware can handle it),
2442 * which is needed for 802.1x implementations. */
2443 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2445 hermes_t *hw = &priv->hw;
2448 switch (priv->firmware_type) {
2449 case FIRMWARE_TYPE_AGERE:
2450 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2451 HERMES_RID_CNFWEPKEYS_AGERE,
2455 err = hermes_write_wordrec(hw, USER_BAP,
2456 HERMES_RID_CNFTXKEY_AGERE,
2461 case FIRMWARE_TYPE_INTERSIL:
2462 case FIRMWARE_TYPE_SYMBOL:
2467 /* Force uniform key length to work around firmware bugs */
2468 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
2470 if (keylen > LARGE_KEY_SIZE) {
2471 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2472 priv->ndev->name, priv->tx_key, keylen);
2476 /* Write all 4 keys */
2477 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
2478 err = hermes_write_ltv(hw, USER_BAP,
2479 HERMES_RID_CNFDEFAULTKEY0 + i,
2480 HERMES_BYTES_TO_RECLEN(keylen),
2481 priv->keys[i].data);
2486 /* Write the index of the key used in transmission */
2487 err = hermes_write_wordrec(hw, USER_BAP,
2488 HERMES_RID_CNFWEPDEFAULTKEYID,
2499 static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
2501 hermes_t *hw = &priv->hw;
2503 int master_wep_flag;
2507 /* Setup WEP keys for WEP and WPA */
2508 if (priv->encode_alg)
2509 __orinoco_hw_setup_wepkeys(priv);
2511 if (priv->wep_restrict)
2512 auth_flag = HERMES_AUTH_SHARED_KEY;
2514 auth_flag = HERMES_AUTH_OPEN;
2516 if (priv->wpa_enabled)
2518 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
2523 switch (priv->firmware_type) {
2524 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
2525 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2526 /* Enable the shared-key authentication. */
2527 err = hermes_write_wordrec(hw, USER_BAP,
2528 HERMES_RID_CNFAUTHENTICATION_AGERE,
2531 err = hermes_write_wordrec(hw, USER_BAP,
2532 HERMES_RID_CNFWEPENABLED_AGERE,
2537 if (priv->has_wpa) {
2538 /* Set WPA key management */
2539 err = hermes_write_wordrec(hw, USER_BAP,
2540 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2548 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2549 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
2550 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2551 if (priv->wep_restrict ||
2552 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2553 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2554 HERMES_WEP_EXCL_UNENCRYPTED;
2556 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2558 err = hermes_write_wordrec(hw, USER_BAP,
2559 HERMES_RID_CNFAUTHENTICATION,
2564 master_wep_flag = 0;
2566 if (priv->iw_mode == IW_MODE_MONITOR)
2567 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2569 /* Master WEP setting : on/off */
2570 err = hermes_write_wordrec(hw, USER_BAP,
2571 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2582 /* key must be 32 bytes, including the tx and rx MIC keys.
2583 * rsc must be 8 bytes
2584 * tsc must be 8 bytes or NULL
2586 static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2587 u8 *key, u8 *rsc, u8 *tsc)
2591 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2592 u8 key[TKIP_KEYLEN];
2593 u8 tx_mic[MIC_KEYLEN];
2594 u8 rx_mic[MIC_KEYLEN];
2595 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2596 } __attribute__ ((packed)) buf;
2607 buf.idx = cpu_to_le16(key_idx);
2608 memcpy(buf.key, key,
2609 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2612 memset(buf.rsc, 0, sizeof(buf.rsc));
2614 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2617 memset(buf.tsc, 0, sizeof(buf.tsc));
2620 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2623 /* Wait upto 100ms for tx queue to empty */
2628 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2632 } while ((k > 0) && xmitting);
2637 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2638 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2641 return ret ? ret : err;
2644 static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2647 hermes_t *hw = &priv->hw;
2650 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2651 err = hermes_write_wordrec(hw, USER_BAP,
2652 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2655 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2656 priv->ndev->name, err, key_idx);
2660 static int __orinoco_program_rids(struct net_device *dev)
2662 struct orinoco_private *priv = netdev_priv(dev);
2663 hermes_t *hw = &priv->hw;
2665 struct hermes_idstring idbuf;
2667 /* Set the MAC address */
2668 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2669 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2671 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2676 /* Set up the link mode */
2677 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2680 printk(KERN_ERR "%s: Error %d setting port type\n",
2684 /* Set the channel/frequency */
2685 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2686 err = hermes_write_wordrec(hw, USER_BAP,
2687 HERMES_RID_CNFOWNCHANNEL,
2690 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2691 dev->name, err, priv->channel);
2696 if (priv->has_ibss) {
2699 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2700 printk(KERN_WARNING "%s: This firmware requires an "
2701 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2702 /* With wvlan_cs, in this case, we would crash.
2703 * hopefully, this driver will behave better...
2707 createibss = priv->createibss;
2710 err = hermes_write_wordrec(hw, USER_BAP,
2711 HERMES_RID_CNFCREATEIBSS,
2714 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2720 /* Set the desired BSSID */
2721 err = __orinoco_hw_set_wap(priv);
2723 printk(KERN_ERR "%s: Error %d setting AP address\n",
2727 /* Set the desired ESSID */
2728 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2729 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2730 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2731 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2732 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2735 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2739 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2740 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2743 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2748 /* Set the station name */
2749 idbuf.len = cpu_to_le16(strlen(priv->nick));
2750 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2751 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2752 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2755 printk(KERN_ERR "%s: Error %d setting nickname\n",
2760 /* Set AP density */
2761 if (priv->has_sensitivity) {
2762 err = hermes_write_wordrec(hw, USER_BAP,
2763 HERMES_RID_CNFSYSTEMSCALE,
2766 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2767 "Disabling sensitivity control\n",
2770 priv->has_sensitivity = 0;
2774 /* Set RTS threshold */
2775 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2778 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2783 /* Set fragmentation threshold or MWO robustness */
2785 err = hermes_write_wordrec(hw, USER_BAP,
2786 HERMES_RID_CNFMWOROBUST_AGERE,
2789 err = hermes_write_wordrec(hw, USER_BAP,
2790 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2793 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2799 err = __orinoco_hw_set_bitrate(priv);
2801 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2806 /* Set power management */
2808 err = hermes_write_wordrec(hw, USER_BAP,
2809 HERMES_RID_CNFPMENABLED,
2812 printk(KERN_ERR "%s: Error %d setting up PM\n",
2817 err = hermes_write_wordrec(hw, USER_BAP,
2818 HERMES_RID_CNFMULTICASTRECEIVE,
2821 printk(KERN_ERR "%s: Error %d setting up PM\n",
2825 err = hermes_write_wordrec(hw, USER_BAP,
2826 HERMES_RID_CNFMAXSLEEPDURATION,
2829 printk(KERN_ERR "%s: Error %d setting up PM\n",
2833 err = hermes_write_wordrec(hw, USER_BAP,
2834 HERMES_RID_CNFPMHOLDOVERDURATION,
2837 printk(KERN_ERR "%s: Error %d setting up PM\n",
2843 /* Set preamble - only for Symbol so far... */
2844 if (priv->has_preamble) {
2845 err = hermes_write_wordrec(hw, USER_BAP,
2846 HERMES_RID_CNFPREAMBLE_SYMBOL,
2849 printk(KERN_ERR "%s: Error %d setting preamble\n",
2855 /* Set up encryption */
2856 if (priv->has_wep || priv->has_wpa) {
2857 err = __orinoco_hw_setup_enc(priv);
2859 printk(KERN_ERR "%s: Error %d activating encryption\n",
2865 if (priv->iw_mode == IW_MODE_MONITOR) {
2866 /* Enable monitor mode */
2867 dev->type = ARPHRD_IEEE80211;
2868 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2869 HERMES_TEST_MONITOR, 0, NULL);
2871 /* Disable monitor mode */
2872 dev->type = ARPHRD_ETHER;
2873 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2874 HERMES_TEST_STOP, 0, NULL);
2879 /* Set promiscuity / multicast*/
2880 priv->promiscuous = 0;
2883 /* FIXME: what about netif_tx_lock */
2884 __orinoco_set_multicast_list(dev);
2889 /* FIXME: return int? */
2891 __orinoco_set_multicast_list(struct net_device *dev)
2893 struct orinoco_private *priv = netdev_priv(dev);
2894 hermes_t *hw = &priv->hw;
2896 int promisc, mc_count;
2898 /* The Hermes doesn't seem to have an allmulti mode, so we go
2899 * into promiscuous mode and let the upper levels deal. */
2900 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2901 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2906 mc_count = dev->mc_count;
2909 if (promisc != priv->promiscuous) {
2910 err = hermes_write_wordrec(hw, USER_BAP,
2911 HERMES_RID_CNFPROMISCUOUSMODE,
2914 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2917 priv->promiscuous = promisc;
2920 /* If we're not in promiscuous mode, then we need to set the
2921 * group address if either we want to multicast, or if we were
2922 * multicasting and want to stop */
2923 if (! promisc && (mc_count || priv->mc_count) ) {
2924 struct dev_mc_list *p = dev->mc_list;
2925 struct hermes_multicast mclist;
2928 for (i = 0; i < mc_count; i++) {
2929 /* paranoia: is list shorter than mc_count? */
2931 /* paranoia: bad address size in list? */
2932 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2934 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2939 printk(KERN_WARNING "%s: Multicast list is "
2940 "longer than mc_count\n", dev->name);
2942 err = hermes_write_ltv(hw, USER_BAP,
2943 HERMES_RID_CNFGROUPADDRESSES,
2944 HERMES_BYTES_TO_RECLEN(mc_count * ETH_ALEN),
2947 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2950 priv->mc_count = mc_count;
2954 /* This must be called from user context, without locks held - use
2955 * schedule_work() */
2956 static void orinoco_reset(struct work_struct *work)
2958 struct orinoco_private *priv =
2959 container_of(work, struct orinoco_private, reset_work);
2960 struct net_device *dev = priv->ndev;
2961 struct hermes *hw = &priv->hw;
2963 unsigned long flags;
2965 if (orinoco_lock(priv, &flags) != 0)
2966 /* When the hardware becomes available again, whatever
2967 * detects that is responsible for re-initializing
2968 * it. So no need for anything further */
2971 netif_stop_queue(dev);
2973 /* Shut off interrupts. Depending on what state the hardware
2974 * is in, this might not work, but we'll try anyway */
2975 hermes_set_irqmask(hw, 0);
2976 hermes_write_regn(hw, EVACK, 0xffff);
2978 priv->hw_unavailable++;
2979 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2980 netif_carrier_off(dev);
2982 orinoco_unlock(priv, &flags);
2984 /* Scanning support: Cleanup of driver struct */
2985 orinoco_clear_scan_results(priv, 0);
2986 priv->scan_inprogress = 0;
2988 if (priv->hard_reset) {
2989 err = (*priv->hard_reset)(priv);
2991 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2992 "performing hard reset\n", dev->name, err);
2997 err = orinoco_reinit_firmware(dev);
2999 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
3004 spin_lock_irq(&priv->lock); /* This has to be called from user context */
3006 priv->hw_unavailable--;
3008 /* priv->open or priv->hw_unavailable might have changed while
3009 * we dropped the lock */
3010 if (priv->open && (! priv->hw_unavailable)) {
3011 err = __orinoco_up(dev);
3013 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
3016 dev->trans_start = jiffies;
3019 spin_unlock_irq(&priv->lock);
3023 hermes_set_irqmask(hw, 0);
3024 netif_device_detach(dev);
3025 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
3028 /********************************************************************/
3029 /* Interrupt handler */
3030 /********************************************************************/
3032 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
3034 printk(KERN_DEBUG "%s: TICK\n", dev->name);
3037 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
3039 /* This seems to happen a fair bit under load, but ignoring it
3040 seems to work fine...*/
3041 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
3045 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
3047 struct net_device *dev = dev_id;
3048 struct orinoco_private *priv = netdev_priv(dev);
3049 hermes_t *hw = &priv->hw;
3050 int count = MAX_IRQLOOPS_PER_IRQ;
3052 /* These are used to detect a runaway interrupt situation */
3053 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
3054 * we panic and shut down the hardware */
3055 static int last_irq_jiffy = 0; /* jiffies value the last time
3057 static int loops_this_jiffy = 0;
3058 unsigned long flags;
3060 if (orinoco_lock(priv, &flags) != 0) {
3061 /* If hw is unavailable - we don't know if the irq was
3066 evstat = hermes_read_regn(hw, EVSTAT);
3067 events = evstat & hw->inten;
3069 orinoco_unlock(priv, &flags);
3073 if (jiffies != last_irq_jiffy)
3074 loops_this_jiffy = 0;
3075 last_irq_jiffy = jiffies;
3077 while (events && count--) {
3078 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
3079 printk(KERN_WARNING "%s: IRQ handler is looping too "
3080 "much! Resetting.\n", dev->name);
3081 /* Disable interrupts for now */
3082 hermes_set_irqmask(hw, 0);
3083 schedule_work(&priv->reset_work);
3087 /* Check the card hasn't been removed */
3088 if (! hermes_present(hw)) {
3089 DEBUG(0, "orinoco_interrupt(): card removed\n");
3093 if (events & HERMES_EV_TICK)
3094 __orinoco_ev_tick(dev, hw);
3095 if (events & HERMES_EV_WTERR)
3096 __orinoco_ev_wterr(dev, hw);
3097 if (events & HERMES_EV_INFDROP)
3098 __orinoco_ev_infdrop(dev, hw);
3099 if (events & HERMES_EV_INFO)
3100 __orinoco_ev_info(dev, hw);
3101 if (events & HERMES_EV_RX)
3102 __orinoco_ev_rx(dev, hw);
3103 if (events & HERMES_EV_TXEXC)
3104 __orinoco_ev_txexc(dev, hw);
3105 if (events & HERMES_EV_TX)
3106 __orinoco_ev_tx(dev, hw);
3107 if (events & HERMES_EV_ALLOC)
3108 __orinoco_ev_alloc(dev, hw);
3110 hermes_write_regn(hw, EVACK, evstat);
3112 evstat = hermes_read_regn(hw, EVSTAT);
3113 events = evstat & hw->inten;
3116 orinoco_unlock(priv, &flags);
3120 /********************************************************************/
3121 /* Power management */
3122 /********************************************************************/
3123 #if defined(CONFIG_PM_SLEEP) && !defined(CONFIG_HERMES_CACHE_FW_ON_INIT)
3124 static int orinoco_pm_notifier(struct notifier_block *notifier,
3125 unsigned long pm_event,
3128 struct orinoco_private *priv = container_of(notifier,
3129 struct orinoco_private,
3132 /* All we need to do is cache the firmware before suspend, and
3133 * release it when we come out.
3135 * Only need to do this if we're downloading firmware. */
3136 if (!priv->do_fw_download)
3140 case PM_HIBERNATION_PREPARE:
3141 case PM_SUSPEND_PREPARE:
3142 orinoco_cache_fw(priv, 0);
3145 case PM_POST_RESTORE:
3146 /* Restore from hibernation failed. We need to clean
3147 * up in exactly the same way, so fall through. */
3148 case PM_POST_HIBERNATION:
3149 case PM_POST_SUSPEND:
3150 orinoco_uncache_fw(priv);
3153 case PM_RESTORE_PREPARE:
3161 static void orinoco_register_pm_notifier(struct orinoco_private *priv)
3163 priv->pm_notifier.notifier_call = orinoco_pm_notifier;
3164 register_pm_notifier(&priv->pm_notifier);
3167 static void orinoco_unregister_pm_notifier(struct orinoco_private *priv)
3169 unregister_pm_notifier(&priv->pm_notifier);
3171 #else /* !PM_SLEEP || HERMES_CACHE_FW_ON_INIT */
3172 #define orinoco_register_pm_notifier(priv) do { } while(0)
3173 #define orinoco_unregister_pm_notifier(priv) do { } while(0)
3176 /********************************************************************/
3177 /* Initialization */
3178 /********************************************************************/
3181 u16 id, variant, major, minor;
3182 } __attribute__ ((packed));
3184 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
3186 if (nic_id->id < 0x8000)
3187 return FIRMWARE_TYPE_AGERE;
3188 else if (nic_id->id == 0x8000 && nic_id->major == 0)
3189 return FIRMWARE_TYPE_SYMBOL;
3191 return FIRMWARE_TYPE_INTERSIL;
3194 /* Set priv->firmware type, determine firmware properties */
3195 static int determine_firmware(struct net_device *dev)
3197 struct orinoco_private *priv = netdev_priv(dev);
3198 hermes_t *hw = &priv->hw;
3200 struct comp_id nic_id, sta_id;
3201 unsigned int firmver;
3202 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
3204 /* Get the hardware version */
3205 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
3207 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
3212 le16_to_cpus(&nic_id.id);
3213 le16_to_cpus(&nic_id.variant);
3214 le16_to_cpus(&nic_id.major);
3215 le16_to_cpus(&nic_id.minor);
3216 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
3217 dev->name, nic_id.id, nic_id.variant,
3218 nic_id.major, nic_id.minor);
3220 priv->firmware_type = determine_firmware_type(&nic_id);
3222 /* Get the firmware version */
3223 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
3225 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
3230 le16_to_cpus(&sta_id.id);
3231 le16_to_cpus(&sta_id.variant);
3232 le16_to_cpus(&sta_id.major);
3233 le16_to_cpus(&sta_id.minor);
3234 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
3235 dev->name, sta_id.id, sta_id.variant,
3236 sta_id.major, sta_id.minor);
3238 switch (sta_id.id) {
3240 printk(KERN_ERR "%s: Primary firmware is active\n",
3244 printk(KERN_ERR "%s: Tertiary firmware is active\n",
3247 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3248 case 0x21: /* Symbol Spectrum24 Trilogy */
3251 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
3256 /* Default capabilities */
3257 priv->has_sensitivity = 1;
3259 priv->has_preamble = 0;
3260 priv->has_port3 = 1;
3263 priv->has_big_wep = 0;
3264 priv->has_alt_txcntl = 0;
3265 priv->has_ext_scan = 0;
3267 priv->do_fw_download = 0;
3269 /* Determine capabilities from the firmware version */
3270 switch (priv->firmware_type) {
3271 case FIRMWARE_TYPE_AGERE:
3272 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3273 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3274 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3275 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
3277 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
3279 priv->has_ibss = (firmver >= 0x60006);
3280 priv->has_wep = (firmver >= 0x40020);
3281 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
3282 Gold cards from the others? */
3283 priv->has_mwo = (firmver >= 0x60000);
3284 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3285 priv->ibss_port = 1;
3286 priv->has_hostscan = (firmver >= 0x8000a);
3287 priv->do_fw_download = 1;
3288 priv->broken_monitor = (firmver >= 0x80000);
3289 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
3290 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
3291 priv->has_wpa = (firmver >= 0x9002a);
3292 /* Tested with Agere firmware :
3293 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3294 * Tested CableTron firmware : 4.32 => Anton */
3296 case FIRMWARE_TYPE_SYMBOL:
3297 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3298 /* Intel MAC : 00:02:B3:* */
3299 /* 3Com MAC : 00:50:DA:* */
3300 memset(tmp, 0, sizeof(tmp));
3301 /* Get the Symbol firmware version */
3302 err = hermes_read_ltv(hw, USER_BAP,
3303 HERMES_RID_SECONDARYVERSION_SYMBOL,
3304 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3307 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3312 /* The firmware revision is a string, the format is
3313 * something like : "V2.20-01".
3314 * Quick and dirty parsing... - Jean II
3316 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
3317 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
3320 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3323 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3326 priv->has_ibss = (firmver >= 0x20000);
3327 priv->has_wep = (firmver >= 0x15012);
3328 priv->has_big_wep = (firmver >= 0x20000);
3329 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
3330 (firmver >= 0x29000 && firmver < 0x30000) ||
3332 priv->has_preamble = (firmver >= 0x20000);
3333 priv->ibss_port = 4;
3335 /* Symbol firmware is found on various cards, but
3336 * there has been no attempt to check firmware
3337 * download on non-spectrum_cs based cards.
3339 * Given that the Agere firmware download works
3340 * differently, we should avoid doing a firmware
3341 * download with the Symbol algorithm on non-spectrum
3344 * For now we can identify a spectrum_cs based card
3345 * because it has a firmware reset function.
3347 priv->do_fw_download = (priv->stop_fw != NULL);
3349 priv->broken_disableport = (firmver == 0x25013) ||
3350 (firmver >= 0x30000 && firmver <= 0x31000);
3351 priv->has_hostscan = (firmver >= 0x31001) ||
3352 (firmver >= 0x29057 && firmver < 0x30000);
3353 /* Tested with Intel firmware : 0x20015 => Jean II */
3354 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3356 case FIRMWARE_TYPE_INTERSIL:
3357 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3358 * Samsung, Compaq 100/200 and Proxim are slightly
3359 * different and less well tested */
3360 /* D-Link MAC : 00:40:05:* */
3361 /* Addtron MAC : 00:90:D1:* */
3362 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3363 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3366 firmver = ((unsigned long)sta_id.major << 16) |
3367 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3369 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3370 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3371 priv->has_pm = (firmver >= 0x000700);
3372 priv->has_hostscan = (firmver >= 0x010301);
3374 if (firmver >= 0x000800)
3375 priv->ibss_port = 0;
3377 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3378 "than v0.8.x - several features not supported\n",
3380 priv->ibss_port = 1;
3384 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3390 static int orinoco_init(struct net_device *dev)
3392 struct orinoco_private *priv = netdev_priv(dev);
3393 hermes_t *hw = &priv->hw;
3395 struct hermes_idstring nickbuf;
3399 /* No need to lock, the hw_unavailable flag is already set in
3400 * alloc_orinocodev() */
3401 priv->nicbuf_size = IEEE80211_MAX_FRAME_LEN + ETH_HLEN;
3403 /* Initialize the firmware */
3404 err = hermes_init(hw);
3406 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3411 err = determine_firmware(dev);
3413 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3418 if (priv->do_fw_download) {
3419 #ifdef CONFIG_HERMES_CACHE_FW_ON_INIT
3420 orinoco_cache_fw(priv, 0);
3423 err = orinoco_download(priv);
3425 priv->do_fw_download = 0;
3427 /* Check firmware version again */
3428 err = determine_firmware(dev);
3430 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3436 if (priv->has_port3)
3437 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
3439 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3441 if (priv->has_wep) {
3442 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
3443 if (priv->has_big_wep)
3444 printk("104-bit key\n");
3446 printk("40-bit key\n");
3448 if (priv->has_wpa) {
3449 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
3450 if (orinoco_mic_init(priv)) {
3451 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3452 "algorithm. Disabling WPA support\n", dev->name);
3457 /* Now we have the firmware capabilities, allocate appropiate
3458 * sized scan buffers */
3459 if (orinoco_bss_data_allocate(priv))
3461 orinoco_bss_data_init(priv);
3463 /* Get the MAC address */
3464 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3465 ETH_ALEN, NULL, dev->dev_addr);
3467 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3472 printk(KERN_DEBUG "%s: MAC address %pM\n",
3473 dev->name, dev->dev_addr);
3475 /* Get the station name */
3476 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3477 sizeof(nickbuf), &reclen, &nickbuf);
3479 printk(KERN_ERR "%s: failed to read station name\n",
3484 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3486 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3487 memcpy(priv->nick, &nickbuf.val, len);
3488 priv->nick[len] = '\0';
3490 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3492 err = orinoco_allocate_fid(dev);
3494 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3499 /* Get allowed channels */
3500 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3501 &priv->channel_mask);
3503 printk(KERN_ERR "%s: failed to read channel list!\n",
3508 /* Get initial AP density */
3509 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3511 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
3512 priv->has_sensitivity = 0;
3515 /* Get initial RTS threshold */
3516 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3519 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3524 /* Get initial fragmentation settings */
3526 err = hermes_read_wordrec(hw, USER_BAP,
3527 HERMES_RID_CNFMWOROBUST_AGERE,
3530 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3531 &priv->frag_thresh);
3533 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3538 /* Power management setup */
3542 err = hermes_read_wordrec(hw, USER_BAP,
3543 HERMES_RID_CNFMAXSLEEPDURATION,
3546 printk(KERN_ERR "%s: failed to read power management period!\n",
3550 err = hermes_read_wordrec(hw, USER_BAP,
3551 HERMES_RID_CNFPMHOLDOVERDURATION,
3554 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3560 /* Preamble setup */
3561 if (priv->has_preamble) {
3562 err = hermes_read_wordrec(hw, USER_BAP,
3563 HERMES_RID_CNFPREAMBLE_SYMBOL,
3569 /* Set up the default configuration */
3570 priv->iw_mode = IW_MODE_INFRA;
3571 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3572 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
3573 set_port_type(priv);
3574 priv->channel = 0; /* use firmware default */
3576 priv->promiscuous = 0;
3577 priv->encode_alg = IW_ENCODE_ALG_NONE;
3579 priv->wpa_enabled = 0;
3580 priv->tkip_cm_active = 0;
3582 priv->wpa_ie_len = 0;
3583 priv->wpa_ie = NULL;
3585 /* Make the hardware available, as long as it hasn't been
3586 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3587 spin_lock_irq(&priv->lock);
3588 priv->hw_unavailable--;
3589 spin_unlock_irq(&priv->lock);
3591 printk(KERN_DEBUG "%s: ready\n", dev->name);
3598 *alloc_orinocodev(int sizeof_card,
3599 struct device *device,
3600 int (*hard_reset)(struct orinoco_private *),
3601 int (*stop_fw)(struct orinoco_private *, int))
3603 struct net_device *dev;
3604 struct orinoco_private *priv;
3606 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
3609 priv = netdev_priv(dev);
3612 priv->card = (void *)((unsigned long)priv
3613 + sizeof(struct orinoco_private));
3618 /* Setup / override net_device fields */
3619 dev->init = orinoco_init;
3620 dev->hard_start_xmit = orinoco_xmit;
3621 dev->tx_timeout = orinoco_tx_timeout;
3622 dev->watchdog_timeo = HZ; /* 1 second timeout */
3623 dev->get_stats = orinoco_get_stats;
3624 dev->ethtool_ops = &orinoco_ethtool_ops;
3625 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
3627 priv->wireless_data.spy_data = &priv->spy_data;
3628 dev->wireless_data = &priv->wireless_data;
3630 dev->change_mtu = orinoco_change_mtu;
3631 dev->set_multicast_list = orinoco_set_multicast_list;
3632 /* we use the default eth_mac_addr for setting the MAC addr */
3634 /* Reserve space in skb for the SNAP header */
3635 dev->hard_header_len += ENCAPS_OVERHEAD;
3637 /* Set up default callbacks */
3638 dev->open = orinoco_open;
3639 dev->stop = orinoco_stop;
3640 priv->hard_reset = hard_reset;
3641 priv->stop_fw = stop_fw;
3643 spin_lock_init(&priv->lock);
3645 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3646 * before anything else touches the
3648 INIT_WORK(&priv->reset_work, orinoco_reset);
3649 INIT_WORK(&priv->join_work, orinoco_join_ap);
3650 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
3652 INIT_LIST_HEAD(&priv->rx_list);
3653 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3654 (unsigned long) dev);
3656 netif_carrier_off(dev);
3657 priv->last_linkstatus = 0xffff;
3659 priv->cached_pri_fw = NULL;
3660 priv->cached_fw = NULL;
3662 /* Register PM notifiers */
3663 orinoco_register_pm_notifier(priv);
3668 void free_orinocodev(struct net_device *dev)
3670 struct orinoco_private *priv = netdev_priv(dev);
3671 struct orinoco_rx_data *rx_data, *temp;
3673 /* If the tasklet is scheduled when we call tasklet_kill it
3674 * will run one final time. However the tasklet will only
3675 * drain priv->rx_list if the hw is still available. */
3676 tasklet_kill(&priv->rx_tasklet);
3678 /* Explicitly drain priv->rx_list */
3679 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
3680 list_del(&rx_data->list);
3682 dev_kfree_skb(rx_data->skb);
3683 kfree(rx_data->desc);
3687 orinoco_unregister_pm_notifier(priv);
3688 orinoco_uncache_fw(priv);
3690 priv->wpa_ie_len = 0;
3691 kfree(priv->wpa_ie);
3692 orinoco_mic_free(priv);
3693 orinoco_bss_data_free(priv);
3697 /********************************************************************/
3698 /* Wireless extensions */
3699 /********************************************************************/
3701 /* Return : < 0 -> error code ; >= 0 -> length */
3702 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3703 char buf[IW_ESSID_MAX_SIZE+1])
3705 hermes_t *hw = &priv->hw;
3707 struct hermes_idstring essidbuf;
3708 char *p = (char *)(&essidbuf.val);
3710 unsigned long flags;
3712 if (orinoco_lock(priv, &flags) != 0)
3715 if (strlen(priv->desired_essid) > 0) {
3716 /* We read the desired SSID from the hardware rather
3717 than from priv->desired_essid, just in case the
3718 firmware is allowed to change it on us. I'm not
3720 /* My guess is that the OWNSSID should always be whatever
3721 * we set to the card, whereas CURRENT_SSID is the one that
3722 * may change... - Jean II */
3727 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3728 HERMES_RID_CNFDESIREDSSID;
3730 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3737 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3738 sizeof(essidbuf), NULL, &essidbuf);
3743 len = le16_to_cpu(essidbuf.len);
3744 BUG_ON(len > IW_ESSID_MAX_SIZE);
3746 memset(buf, 0, IW_ESSID_MAX_SIZE);
3747 memcpy(buf, p, len);
3751 orinoco_unlock(priv, &flags);
3756 static long orinoco_hw_get_freq(struct orinoco_private *priv)
3759 hermes_t *hw = &priv->hw;
3763 unsigned long flags;
3765 if (orinoco_lock(priv, &flags) != 0)
3768 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3772 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3778 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3779 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3780 priv->ndev->name, channel);
3785 freq = channel_frequency[channel-1] * 100000;
3788 orinoco_unlock(priv, &flags);
3792 return err ? err : freq;
3795 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3796 int *numrates, s32 *rates, int max)
3798 hermes_t *hw = &priv->hw;
3799 struct hermes_idstring list;
3800 unsigned char *p = (unsigned char *)&list.val;
3804 unsigned long flags;
3806 if (orinoco_lock(priv, &flags) != 0)
3809 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3810 sizeof(list), NULL, &list);
3811 orinoco_unlock(priv, &flags);
3816 num = le16_to_cpu(list.len);
3818 num = min(num, max);
3820 for (i = 0; i < num; i++) {
3821 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3827 static int orinoco_ioctl_getname(struct net_device *dev,
3828 struct iw_request_info *info,
3832 struct orinoco_private *priv = netdev_priv(dev);
3836 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3838 if (!err && (numrates > 2))
3839 strcpy(name, "IEEE 802.11b");
3841 strcpy(name, "IEEE 802.11-DS");
3846 static int orinoco_ioctl_setwap(struct net_device *dev,
3847 struct iw_request_info *info,
3848 struct sockaddr *ap_addr,
3851 struct orinoco_private *priv = netdev_priv(dev);
3852 int err = -EINPROGRESS; /* Call commit handler */
3853 unsigned long flags;
3854 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3855 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3857 if (orinoco_lock(priv, &flags) != 0)
3860 /* Enable automatic roaming - no sanity checks are needed */
3861 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3862 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3863 priv->bssid_fixed = 0;
3864 memset(priv->desired_bssid, 0, ETH_ALEN);
3866 /* "off" means keep existing connection */
3867 if (ap_addr->sa_data[0] == 0) {
3868 __orinoco_hw_set_wap(priv);
3874 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3875 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3876 "support manual roaming\n",
3882 if (priv->iw_mode != IW_MODE_INFRA) {
3883 printk(KERN_WARNING "%s: Manual roaming supported only in "
3884 "managed mode\n", dev->name);
3889 /* Intersil firmware hangs without Desired ESSID */
3890 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3891 strlen(priv->desired_essid) == 0) {
3892 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3893 "manual roaming\n", dev->name);
3898 /* Finally, enable manual roaming */
3899 priv->bssid_fixed = 1;
3900 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3903 orinoco_unlock(priv, &flags);
3907 static int orinoco_ioctl_getwap(struct net_device *dev,
3908 struct iw_request_info *info,
3909 struct sockaddr *ap_addr,
3912 struct orinoco_private *priv = netdev_priv(dev);
3914 hermes_t *hw = &priv->hw;
3916 unsigned long flags;
3918 if (orinoco_lock(priv, &flags) != 0)
3921 ap_addr->sa_family = ARPHRD_ETHER;
3922 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3923 ETH_ALEN, NULL, ap_addr->sa_data);
3925 orinoco_unlock(priv, &flags);
3930 static int orinoco_ioctl_setmode(struct net_device *dev,
3931 struct iw_request_info *info,
3935 struct orinoco_private *priv = netdev_priv(dev);
3936 int err = -EINPROGRESS; /* Call commit handler */
3937 unsigned long flags;
3939 if (priv->iw_mode == *mode)
3942 if (orinoco_lock(priv, &flags) != 0)
3947 if (!priv->has_ibss && !priv->has_port3)
3954 case IW_MODE_MONITOR:
3955 if (priv->broken_monitor && !force_monitor) {
3956 printk(KERN_WARNING "%s: Monitor mode support is "
3957 "buggy in this firmware, not enabling\n",
3968 if (err == -EINPROGRESS) {
3969 priv->iw_mode = *mode;
3970 set_port_type(priv);
3973 orinoco_unlock(priv, &flags);
3978 static int orinoco_ioctl_getmode(struct net_device *dev,
3979 struct iw_request_info *info,
3983 struct orinoco_private *priv = netdev_priv(dev);
3985 *mode = priv->iw_mode;
3989 static int orinoco_ioctl_getiwrange(struct net_device *dev,
3990 struct iw_request_info *info,
3991 struct iw_point *rrq,
3994 struct orinoco_private *priv = netdev_priv(dev);
3996 struct iw_range *range = (struct iw_range *) extra;
4000 rrq->length = sizeof(struct iw_range);
4001 memset(range, 0, sizeof(struct iw_range));
4003 range->we_version_compiled = WIRELESS_EXT;
4004 range->we_version_source = 22;
4006 /* Set available channels/frequencies */
4007 range->num_channels = NUM_CHANNELS;
4009 for (i = 0; i < NUM_CHANNELS; i++) {
4010 if (priv->channel_mask & (1 << i)) {
4011 range->freq[k].i = i + 1;
4012 range->freq[k].m = channel_frequency[i] * 100000;
4013 range->freq[k].e = 1;
4017 if (k >= IW_MAX_FREQUENCIES)
4020 range->num_frequency = k;
4021 range->sensitivity = 3;
4023 if (priv->has_wep) {
4024 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
4025 range->encoding_size[0] = SMALL_KEY_SIZE;
4026 range->num_encoding_sizes = 1;
4028 if (priv->has_big_wep) {
4029 range->encoding_size[1] = LARGE_KEY_SIZE;
4030 range->num_encoding_sizes = 2;
4035 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
4037 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
4038 /* Quality stats meaningless in ad-hoc mode */
4040 range->max_qual.qual = 0x8b - 0x2f;
4041 range->max_qual.level = 0x2f - 0x95 - 1;
4042 range->max_qual.noise = 0x2f - 0x95 - 1;
4043 /* Need to get better values */
4044 range->avg_qual.qual = 0x24;
4045 range->avg_qual.level = 0xC2;
4046 range->avg_qual.noise = 0x9E;
4049 err = orinoco_hw_get_bitratelist(priv, &numrates,
4050 range->bitrate, IW_MAX_BITRATES);
4053 range->num_bitrates = numrates;
4055 /* Set an indication of the max TCP throughput in bit/s that we can
4056 * expect using this interface. May be use for QoS stuff...
4059 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
4061 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
4064 range->max_rts = 2347;
4065 range->min_frag = 256;
4066 range->max_frag = 2346;
4069 range->max_pmp = 65535000;
4071 range->max_pmt = 65535 * 1000; /* ??? */
4072 range->pmp_flags = IW_POWER_PERIOD;
4073 range->pmt_flags = IW_POWER_TIMEOUT;
4074 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
4076 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
4077 range->retry_flags = IW_RETRY_LIMIT;
4078 range->r_time_flags = IW_RETRY_LIFETIME;
4079 range->min_retry = 0;
4080 range->max_retry = 65535; /* ??? */
4081 range->min_r_time = 0;
4082 range->max_r_time = 65535 * 1000; /* ??? */
4084 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
4085 range->scan_capa = IW_SCAN_CAPA_ESSID;
4087 range->scan_capa = IW_SCAN_CAPA_NONE;
4089 /* Event capability (kernel) */
4090 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
4091 /* Event capability (driver) */
4092 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
4093 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
4094 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
4095 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
4100 static int orinoco_ioctl_setiwencode(struct net_device *dev,
4101 struct iw_request_info *info,
4102 struct iw_point *erq,
4105 struct orinoco_private *priv = netdev_priv(dev);
4106 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4107 int setindex = priv->tx_key;
4108 int encode_alg = priv->encode_alg;
4109 int restricted = priv->wep_restrict;
4111 int err = -EINPROGRESS; /* Call commit handler */
4112 unsigned long flags;
4114 if (! priv->has_wep)
4118 /* We actually have a key to set - check its length */
4119 if (erq->length > LARGE_KEY_SIZE)
4122 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
4126 if (orinoco_lock(priv, &flags) != 0)
4129 /* Clear any TKIP key we have */
4130 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
4131 (void) orinoco_clear_tkip_key(priv, setindex);
4133 if (erq->length > 0) {
4134 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4135 index = priv->tx_key;
4137 /* Adjust key length to a supported value */
4138 if (erq->length > SMALL_KEY_SIZE) {
4139 xlen = LARGE_KEY_SIZE;
4140 } else if (erq->length > 0) {
4141 xlen = SMALL_KEY_SIZE;
4145 /* Switch on WEP if off */
4146 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
4148 encode_alg = IW_ENCODE_ALG_WEP;
4151 /* Important note : if the user do "iwconfig eth0 enc off",
4152 * we will arrive there with an index of -1. This is valid
4153 * but need to be taken care off... Jean II */
4154 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
4155 if((index != -1) || (erq->flags == 0)) {
4160 /* Set the index : Check that the key is valid */
4161 if(priv->keys[index].len == 0) {
4169 if (erq->flags & IW_ENCODE_DISABLED)
4170 encode_alg = IW_ENCODE_ALG_NONE;
4171 if (erq->flags & IW_ENCODE_OPEN)
4173 if (erq->flags & IW_ENCODE_RESTRICTED)
4176 if (erq->pointer && erq->length > 0) {
4177 priv->keys[index].len = cpu_to_le16(xlen);
4178 memset(priv->keys[index].data, 0,
4179 sizeof(priv->keys[index].data));
4180 memcpy(priv->keys[index].data, keybuf, erq->length);
4182 priv->tx_key = setindex;
4184 /* Try fast key change if connected and only keys are changed */
4185 if ((priv->encode_alg == encode_alg) &&
4186 (priv->wep_restrict == restricted) &&
4187 netif_carrier_ok(dev)) {
4188 err = __orinoco_hw_setup_wepkeys(priv);
4189 /* No need to commit if successful */
4193 priv->encode_alg = encode_alg;
4194 priv->wep_restrict = restricted;
4197 orinoco_unlock(priv, &flags);
4202 static int orinoco_ioctl_getiwencode(struct net_device *dev,
4203 struct iw_request_info *info,
4204 struct iw_point *erq,
4207 struct orinoco_private *priv = netdev_priv(dev);
4208 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4210 unsigned long flags;
4212 if (! priv->has_wep)
4215 if (orinoco_lock(priv, &flags) != 0)
4218 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4219 index = priv->tx_key;
4222 if (!priv->encode_alg)
4223 erq->flags |= IW_ENCODE_DISABLED;
4224 erq->flags |= index + 1;
4226 if (priv->wep_restrict)
4227 erq->flags |= IW_ENCODE_RESTRICTED;
4229 erq->flags |= IW_ENCODE_OPEN;
4231 xlen = le16_to_cpu(priv->keys[index].len);
4235 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
4237 orinoco_unlock(priv, &flags);
4241 static int orinoco_ioctl_setessid(struct net_device *dev,
4242 struct iw_request_info *info,
4243 struct iw_point *erq,
4246 struct orinoco_private *priv = netdev_priv(dev);
4247 unsigned long flags;
4249 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4250 * anyway... - Jean II */
4252 /* Hum... Should not use Wireless Extension constant (may change),
4253 * should use our own... - Jean II */
4254 if (erq->length > IW_ESSID_MAX_SIZE)
4257 if (orinoco_lock(priv, &flags) != 0)
4260 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4261 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
4263 /* If not ANY, get the new ESSID */
4265 memcpy(priv->desired_essid, essidbuf, erq->length);
4268 orinoco_unlock(priv, &flags);
4270 return -EINPROGRESS; /* Call commit handler */
4273 static int orinoco_ioctl_getessid(struct net_device *dev,
4274 struct iw_request_info *info,
4275 struct iw_point *erq,
4278 struct orinoco_private *priv = netdev_priv(dev);
4281 unsigned long flags;
4283 if (netif_running(dev)) {
4284 err = orinoco_hw_get_essid(priv, &active, essidbuf);
4289 if (orinoco_lock(priv, &flags) != 0)
4291 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4292 erq->length = strlen(priv->desired_essid);
4293 orinoco_unlock(priv, &flags);
4301 static int orinoco_ioctl_setnick(struct net_device *dev,
4302 struct iw_request_info *info,
4303 struct iw_point *nrq,
4306 struct orinoco_private *priv = netdev_priv(dev);
4307 unsigned long flags;
4309 if (nrq->length > IW_ESSID_MAX_SIZE)
4312 if (orinoco_lock(priv, &flags) != 0)
4315 memset(priv->nick, 0, sizeof(priv->nick));
4316 memcpy(priv->nick, nickbuf, nrq->length);
4318 orinoco_unlock(priv, &flags);
4320 return -EINPROGRESS; /* Call commit handler */
4323 static int orinoco_ioctl_getnick(struct net_device *dev,
4324 struct iw_request_info *info,
4325 struct iw_point *nrq,
4328 struct orinoco_private *priv = netdev_priv(dev);
4329 unsigned long flags;
4331 if (orinoco_lock(priv, &flags) != 0)
4334 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
4335 orinoco_unlock(priv, &flags);
4337 nrq->length = strlen(priv->nick);
4342 static int orinoco_ioctl_setfreq(struct net_device *dev,
4343 struct iw_request_info *info,
4344 struct iw_freq *frq,
4347 struct orinoco_private *priv = netdev_priv(dev);
4349 unsigned long flags;
4350 int err = -EINPROGRESS; /* Call commit handler */
4352 /* In infrastructure mode the AP sets the channel */
4353 if (priv->iw_mode == IW_MODE_INFRA)
4356 if ( (frq->e == 0) && (frq->m <= 1000) ) {
4357 /* Setting by channel number */
4360 /* Setting by frequency - search the table */
4364 for (i = 0; i < (6 - frq->e); i++)
4367 for (i = 0; i < NUM_CHANNELS; i++)
4368 if (frq->m == (channel_frequency[i] * mult))
4372 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
4373 ! (priv->channel_mask & (1 << (chan-1)) ) )
4376 if (orinoco_lock(priv, &flags) != 0)
4379 priv->channel = chan;
4380 if (priv->iw_mode == IW_MODE_MONITOR) {
4381 /* Fast channel change - no commit if successful */
4382 hermes_t *hw = &priv->hw;
4383 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4384 HERMES_TEST_SET_CHANNEL,
4387 orinoco_unlock(priv, &flags);
4392 static int orinoco_ioctl_getfreq(struct net_device *dev,
4393 struct iw_request_info *info,
4394 struct iw_freq *frq,
4397 struct orinoco_private *priv = netdev_priv(dev);
4400 /* Locking done in there */
4401 tmp = orinoco_hw_get_freq(priv);
4412 static int orinoco_ioctl_getsens(struct net_device *dev,
4413 struct iw_request_info *info,
4414 struct iw_param *srq,
4417 struct orinoco_private *priv = netdev_priv(dev);
4418 hermes_t *hw = &priv->hw;
4421 unsigned long flags;
4423 if (!priv->has_sensitivity)
4426 if (orinoco_lock(priv, &flags) != 0)
4428 err = hermes_read_wordrec(hw, USER_BAP,
4429 HERMES_RID_CNFSYSTEMSCALE, &val);
4430 orinoco_unlock(priv, &flags);
4436 srq->fixed = 0; /* auto */
4441 static int orinoco_ioctl_setsens(struct net_device *dev,
4442 struct iw_request_info *info,
4443 struct iw_param *srq,
4446 struct orinoco_private *priv = netdev_priv(dev);
4447 int val = srq->value;
4448 unsigned long flags;
4450 if (!priv->has_sensitivity)
4453 if ((val < 1) || (val > 3))
4456 if (orinoco_lock(priv, &flags) != 0)
4458 priv->ap_density = val;
4459 orinoco_unlock(priv, &flags);
4461 return -EINPROGRESS; /* Call commit handler */
4464 static int orinoco_ioctl_setrts(struct net_device *dev,
4465 struct iw_request_info *info,
4466 struct iw_param *rrq,
4469 struct orinoco_private *priv = netdev_priv(dev);
4470 int val = rrq->value;
4471 unsigned long flags;
4476 if ( (val < 0) || (val > 2347) )
4479 if (orinoco_lock(priv, &flags) != 0)
4482 priv->rts_thresh = val;
4483 orinoco_unlock(priv, &flags);
4485 return -EINPROGRESS; /* Call commit handler */
4488 static int orinoco_ioctl_getrts(struct net_device *dev,
4489 struct iw_request_info *info,
4490 struct iw_param *rrq,
4493 struct orinoco_private *priv = netdev_priv(dev);
4495 rrq->value = priv->rts_thresh;
4496 rrq->disabled = (rrq->value == 2347);
4502 static int orinoco_ioctl_setfrag(struct net_device *dev,
4503 struct iw_request_info *info,
4504 struct iw_param *frq,
4507 struct orinoco_private *priv = netdev_priv(dev);
4508 int err = -EINPROGRESS; /* Call commit handler */
4509 unsigned long flags;
4511 if (orinoco_lock(priv, &flags) != 0)
4514 if (priv->has_mwo) {
4516 priv->mwo_robust = 0;
4519 printk(KERN_WARNING "%s: Fixed fragmentation is "
4520 "not supported on this firmware. "
4521 "Using MWO robust instead.\n", dev->name);
4522 priv->mwo_robust = 1;
4526 priv->frag_thresh = 2346;
4528 if ( (frq->value < 256) || (frq->value > 2346) )
4531 priv->frag_thresh = frq->value & ~0x1; /* must be even */
4535 orinoco_unlock(priv, &flags);
4540 static int orinoco_ioctl_getfrag(struct net_device *dev,
4541 struct iw_request_info *info,
4542 struct iw_param *frq,
4545 struct orinoco_private *priv = netdev_priv(dev);
4546 hermes_t *hw = &priv->hw;
4549 unsigned long flags;
4551 if (orinoco_lock(priv, &flags) != 0)
4554 if (priv->has_mwo) {
4555 err = hermes_read_wordrec(hw, USER_BAP,
4556 HERMES_RID_CNFMWOROBUST_AGERE,
4561 frq->value = val ? 2347 : 0;
4562 frq->disabled = ! val;
4565 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
4571 frq->disabled = (val >= 2346);
4575 orinoco_unlock(priv, &flags);
4580 static int orinoco_ioctl_setrate(struct net_device *dev,
4581 struct iw_request_info *info,
4582 struct iw_param *rrq,
4585 struct orinoco_private *priv = netdev_priv(dev);
4587 int bitrate; /* 100s of kilobits */
4589 unsigned long flags;
4591 /* As the user space doesn't know our highest rate, it uses -1
4592 * to ask us to set the highest rate. Test it using "iwconfig
4593 * ethX rate auto" - Jean II */
4594 if (rrq->value == -1)
4597 if (rrq->value % 100000)
4599 bitrate = rrq->value / 100000;
4602 if ( (bitrate != 10) && (bitrate != 20) &&
4603 (bitrate != 55) && (bitrate != 110) )
4606 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4607 if ( (bitrate_table[i].bitrate == bitrate) &&
4608 (bitrate_table[i].automatic == ! rrq->fixed) ) {
4616 if (orinoco_lock(priv, &flags) != 0)
4618 priv->bitratemode = ratemode;
4619 orinoco_unlock(priv, &flags);
4621 return -EINPROGRESS;
4624 static int orinoco_ioctl_getrate(struct net_device *dev,
4625 struct iw_request_info *info,
4626 struct iw_param *rrq,
4629 struct orinoco_private *priv = netdev_priv(dev);
4630 hermes_t *hw = &priv->hw;
4635 unsigned long flags;
4637 if (orinoco_lock(priv, &flags) != 0)
4640 ratemode = priv->bitratemode;
4642 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4644 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4645 rrq->fixed = ! bitrate_table[ratemode].automatic;
4648 /* If the interface is running we try to find more about the
4650 if (netif_running(dev)) {
4651 err = hermes_read_wordrec(hw, USER_BAP,
4652 HERMES_RID_CURRENTTXRATE, &val);
4656 switch (priv->firmware_type) {
4657 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4658 /* Note : in Lucent firmware, the return value of
4659 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4660 * and therefore is totally different from the
4661 * encoding of HERMES_RID_CNFTXRATECONTROL.
4662 * Don't forget that 6Mb/s is really 5.5Mb/s */
4664 rrq->value = 5500000;
4666 rrq->value = val * 1000000;
4668 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4669 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4670 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4671 if (bitrate_table[i].intersil_txratectrl == val) {
4675 if (i >= BITRATE_TABLE_SIZE)
4676 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4679 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4687 orinoco_unlock(priv, &flags);
4692 static int orinoco_ioctl_setpower(struct net_device *dev,
4693 struct iw_request_info *info,
4694 struct iw_param *prq,
4697 struct orinoco_private *priv = netdev_priv(dev);
4698 int err = -EINPROGRESS; /* Call commit handler */
4699 unsigned long flags;
4701 if (orinoco_lock(priv, &flags) != 0)
4704 if (prq->disabled) {
4707 switch (prq->flags & IW_POWER_MODE) {
4708 case IW_POWER_UNICAST_R:
4712 case IW_POWER_ALL_R:
4717 /* No flags : but we may have a value - Jean II */
4724 if (prq->flags & IW_POWER_TIMEOUT) {
4726 priv->pm_timeout = prq->value / 1000;
4728 if (prq->flags & IW_POWER_PERIOD) {
4730 priv->pm_period = prq->value / 1000;
4732 /* It's valid to not have a value if we are just toggling
4733 * the flags... Jean II */
4741 orinoco_unlock(priv, &flags);
4746 static int orinoco_ioctl_getpower(struct net_device *dev,
4747 struct iw_request_info *info,
4748 struct iw_param *prq,
4751 struct orinoco_private *priv = netdev_priv(dev);
4752 hermes_t *hw = &priv->hw;
4754 u16 enable, period, timeout, mcast;
4755 unsigned long flags;
4757 if (orinoco_lock(priv, &flags) != 0)
4760 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
4764 err = hermes_read_wordrec(hw, USER_BAP,
4765 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4769 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4773 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4777 prq->disabled = !enable;
4778 /* Note : by default, display the period */
4779 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4780 prq->flags = IW_POWER_TIMEOUT;
4781 prq->value = timeout * 1000;
4783 prq->flags = IW_POWER_PERIOD;
4784 prq->value = period * 1000;
4787 prq->flags |= IW_POWER_ALL_R;
4789 prq->flags |= IW_POWER_UNICAST_R;
4792 orinoco_unlock(priv, &flags);
4797 static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4798 struct iw_request_info *info,
4799 union iwreq_data *wrqu,
4802 struct orinoco_private *priv = netdev_priv(dev);
4803 struct iw_point *encoding = &wrqu->encoding;
4804 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4805 int idx, alg = ext->alg, set_key = 1;
4806 unsigned long flags;
4810 if (orinoco_lock(priv, &flags) != 0)
4813 /* Determine and validate the key index */
4814 idx = encoding->flags & IW_ENCODE_INDEX;
4816 if ((idx < 1) || (idx > 4))
4822 if (encoding->flags & IW_ENCODE_DISABLED)
4823 alg = IW_ENCODE_ALG_NONE;
4825 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4826 /* Clear any TKIP TX key we had */
4827 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4830 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4832 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4833 (ext->key_len > 0)) ? 1 : 0;
4837 /* Set the requested key first */
4839 case IW_ENCODE_ALG_NONE:
4840 priv->encode_alg = alg;
4841 priv->keys[idx].len = 0;
4844 case IW_ENCODE_ALG_WEP:
4845 if (ext->key_len > SMALL_KEY_SIZE)
4846 key_len = LARGE_KEY_SIZE;
4847 else if (ext->key_len > 0)
4848 key_len = SMALL_KEY_SIZE;
4852 priv->encode_alg = alg;
4853 priv->keys[idx].len = cpu_to_le16(key_len);
4855 key_len = min(ext->key_len, key_len);
4857 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4858 memcpy(priv->keys[idx].data, ext->key, key_len);
4861 case IW_ENCODE_ALG_TKIP:
4863 hermes_t *hw = &priv->hw;
4866 if (!priv->has_wpa ||
4867 (ext->key_len > sizeof(priv->tkip_key[0])))
4870 priv->encode_alg = alg;
4871 memset(&priv->tkip_key[idx], 0,
4872 sizeof(priv->tkip_key[idx]));
4873 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4875 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4876 tkip_iv = &ext->rx_seq[0];
4878 err = __orinoco_hw_set_tkip_key(hw, idx,
4879 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4880 (u8 *) &priv->tkip_key[idx],
4883 printk(KERN_ERR "%s: Error %d setting TKIP key"
4884 "\n", dev->name, err);
4894 orinoco_unlock(priv, &flags);
4899 static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4900 struct iw_request_info *info,
4901 union iwreq_data *wrqu,
4904 struct orinoco_private *priv = netdev_priv(dev);
4905 struct iw_point *encoding = &wrqu->encoding;
4906 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4907 int idx, max_key_len;
4908 unsigned long flags;
4911 if (orinoco_lock(priv, &flags) != 0)
4915 max_key_len = encoding->length - sizeof(*ext);
4916 if (max_key_len < 0)
4919 idx = encoding->flags & IW_ENCODE_INDEX;
4921 if ((idx < 1) || (idx > 4))
4927 encoding->flags = idx + 1;
4928 memset(ext, 0, sizeof(*ext));
4930 ext->alg = priv->encode_alg;
4931 switch (priv->encode_alg) {
4932 case IW_ENCODE_ALG_NONE:
4934 encoding->flags |= IW_ENCODE_DISABLED;
4936 case IW_ENCODE_ALG_WEP:
4937 ext->key_len = min_t(u16, le16_to_cpu(priv->keys[idx].len),
4939 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4940 encoding->flags |= IW_ENCODE_ENABLED;
4942 case IW_ENCODE_ALG_TKIP:
4943 ext->key_len = min_t(u16, sizeof(struct orinoco_tkip_key),
4945 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4946 encoding->flags |= IW_ENCODE_ENABLED;
4952 orinoco_unlock(priv, &flags);
4957 static int orinoco_ioctl_set_auth(struct net_device *dev,
4958 struct iw_request_info *info,
4959 union iwreq_data *wrqu, char *extra)
4961 struct orinoco_private *priv = netdev_priv(dev);
4962 hermes_t *hw = &priv->hw;
4963 struct iw_param *param = &wrqu->param;
4964 unsigned long flags;
4965 int ret = -EINPROGRESS;
4967 if (orinoco_lock(priv, &flags) != 0)
4970 switch (param->flags & IW_AUTH_INDEX) {
4971 case IW_AUTH_WPA_VERSION:
4972 case IW_AUTH_CIPHER_PAIRWISE:
4973 case IW_AUTH_CIPHER_GROUP:
4974 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4975 case IW_AUTH_PRIVACY_INVOKED:
4976 case IW_AUTH_DROP_UNENCRYPTED:
4978 * orinoco does not use these parameters
4982 case IW_AUTH_KEY_MGMT:
4983 /* wl_lkm implies value 2 == PSK for Hermes I
4984 * which ties in with WEXT
4985 * no other hints tho :(
4987 priv->key_mgmt = param->value;
4990 case IW_AUTH_TKIP_COUNTERMEASURES:
4991 /* When countermeasures are enabled, shut down the
4992 * card; when disabled, re-enable the card. This must
4993 * take effect immediately.
4995 * TODO: Make sure that the EAPOL message is getting
4996 * out before card disabled
4999 priv->tkip_cm_active = 1;
5000 ret = hermes_enable_port(hw, 0);
5002 priv->tkip_cm_active = 0;
5003 ret = hermes_disable_port(hw, 0);
5007 case IW_AUTH_80211_AUTH_ALG:
5008 if (param->value & IW_AUTH_ALG_SHARED_KEY)
5009 priv->wep_restrict = 1;
5010 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
5011 priv->wep_restrict = 0;
5016 case IW_AUTH_WPA_ENABLED:
5017 if (priv->has_wpa) {
5018 priv->wpa_enabled = param->value ? 1 : 0;
5022 /* else silently accept disable of WPA */
5023 priv->wpa_enabled = 0;
5031 orinoco_unlock(priv, &flags);
5035 static int orinoco_ioctl_get_auth(struct net_device *dev,
5036 struct iw_request_info *info,
5037 union iwreq_data *wrqu, char *extra)
5039 struct orinoco_private *priv = netdev_priv(dev);
5040 struct iw_param *param = &wrqu->param;
5041 unsigned long flags;
5044 if (orinoco_lock(priv, &flags) != 0)
5047 switch (param->flags & IW_AUTH_INDEX) {
5048 case IW_AUTH_KEY_MGMT:
5049 param->value = priv->key_mgmt;
5052 case IW_AUTH_TKIP_COUNTERMEASURES:
5053 param->value = priv->tkip_cm_active;
5056 case IW_AUTH_80211_AUTH_ALG:
5057 if (priv->wep_restrict)
5058 param->value = IW_AUTH_ALG_SHARED_KEY;
5060 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
5063 case IW_AUTH_WPA_ENABLED:
5064 param->value = priv->wpa_enabled;
5071 orinoco_unlock(priv, &flags);
5075 static int orinoco_ioctl_set_genie(struct net_device *dev,
5076 struct iw_request_info *info,
5077 union iwreq_data *wrqu, char *extra)
5079 struct orinoco_private *priv = netdev_priv(dev);
5081 unsigned long flags;
5083 /* cut off at IEEE80211_MAX_DATA_LEN */
5084 if ((wrqu->data.length > IEEE80211_MAX_DATA_LEN) ||
5085 (wrqu->data.length && (extra == NULL)))
5088 if (wrqu->data.length) {
5089 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
5093 memcpy(buf, extra, wrqu->data.length);
5097 if (orinoco_lock(priv, &flags) != 0) {
5102 kfree(priv->wpa_ie);
5104 priv->wpa_ie_len = wrqu->data.length;
5107 /* Looks like wl_lkm wants to check the auth alg, and
5108 * somehow pass it to the firmware.
5109 * Instead it just calls the key mgmt rid
5110 * - we do this in set auth.
5114 orinoco_unlock(priv, &flags);
5118 static int orinoco_ioctl_get_genie(struct net_device *dev,
5119 struct iw_request_info *info,
5120 union iwreq_data *wrqu, char *extra)
5122 struct orinoco_private *priv = netdev_priv(dev);
5123 unsigned long flags;
5126 if (orinoco_lock(priv, &flags) != 0)
5129 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
5130 wrqu->data.length = 0;
5134 if (wrqu->data.length < priv->wpa_ie_len) {
5139 wrqu->data.length = priv->wpa_ie_len;
5140 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
5143 orinoco_unlock(priv, &flags);
5147 static int orinoco_ioctl_set_mlme(struct net_device *dev,
5148 struct iw_request_info *info,
5149 union iwreq_data *wrqu, char *extra)
5151 struct orinoco_private *priv = netdev_priv(dev);
5152 hermes_t *hw = &priv->hw;
5153 struct iw_mlme *mlme = (struct iw_mlme *)extra;
5154 unsigned long flags;
5157 if (orinoco_lock(priv, &flags) != 0)
5160 switch (mlme->cmd) {
5161 case IW_MLME_DEAUTH:
5162 /* silently ignore */
5165 case IW_MLME_DISASSOC:
5170 } __attribute__ ((packed)) buf;
5172 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
5173 buf.reason_code = cpu_to_le16(mlme->reason_code);
5174 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
5175 HERMES_RID_CNFDISASSOCIATE,
5183 orinoco_unlock(priv, &flags);
5187 static int orinoco_ioctl_getretry(struct net_device *dev,
5188 struct iw_request_info *info,
5189 struct iw_param *rrq,
5192 struct orinoco_private *priv = netdev_priv(dev);
5193 hermes_t *hw = &priv->hw;
5195 u16 short_limit, long_limit, lifetime;
5196 unsigned long flags;
5198 if (orinoco_lock(priv, &flags) != 0)
5201 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
5206 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
5211 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
5216 rrq->disabled = 0; /* Can't be disabled */
5218 /* Note : by default, display the retry number */
5219 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
5220 rrq->flags = IW_RETRY_LIFETIME;
5221 rrq->value = lifetime * 1000; /* ??? */
5223 /* By default, display the min number */
5224 if ((rrq->flags & IW_RETRY_LONG)) {
5225 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
5226 rrq->value = long_limit;
5228 rrq->flags = IW_RETRY_LIMIT;
5229 rrq->value = short_limit;
5230 if(short_limit != long_limit)
5231 rrq->flags |= IW_RETRY_SHORT;
5236 orinoco_unlock(priv, &flags);
5241 static int orinoco_ioctl_reset(struct net_device *dev,
5242 struct iw_request_info *info,
5246 struct orinoco_private *priv = netdev_priv(dev);
5248 if (! capable(CAP_NET_ADMIN))
5251 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
5252 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
5254 /* Firmware reset */
5255 orinoco_reset(&priv->reset_work);
5257 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
5259 schedule_work(&priv->reset_work);
5265 static int orinoco_ioctl_setibssport(struct net_device *dev,
5266 struct iw_request_info *info,
5271 struct orinoco_private *priv = netdev_priv(dev);
5272 int val = *( (int *) extra );
5273 unsigned long flags;
5275 if (orinoco_lock(priv, &flags) != 0)
5278 priv->ibss_port = val ;
5280 /* Actually update the mode we are using */
5281 set_port_type(priv);
5283 orinoco_unlock(priv, &flags);
5284 return -EINPROGRESS; /* Call commit handler */
5287 static int orinoco_ioctl_getibssport(struct net_device *dev,
5288 struct iw_request_info *info,
5292 struct orinoco_private *priv = netdev_priv(dev);
5293 int *val = (int *) extra;
5295 *val = priv->ibss_port;
5299 static int orinoco_ioctl_setport3(struct net_device *dev,
5300 struct iw_request_info *info,
5304 struct orinoco_private *priv = netdev_priv(dev);
5305 int val = *( (int *) extra );
5307 unsigned long flags;
5309 if (orinoco_lock(priv, &flags) != 0)
5313 case 0: /* Try to do IEEE ad-hoc mode */
5314 if (! priv->has_ibss) {
5318 priv->prefer_port3 = 0;
5322 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5323 if (! priv->has_port3) {
5327 priv->prefer_port3 = 1;
5335 /* Actually update the mode we are using */
5336 set_port_type(priv);
5340 orinoco_unlock(priv, &flags);
5345 static int orinoco_ioctl_getport3(struct net_device *dev,
5346 struct iw_request_info *info,
5350 struct orinoco_private *priv = netdev_priv(dev);
5351 int *val = (int *) extra;
5353 *val = priv->prefer_port3;
5357 static int orinoco_ioctl_setpreamble(struct net_device *dev,
5358 struct iw_request_info *info,
5362 struct orinoco_private *priv = netdev_priv(dev);
5363 unsigned long flags;
5366 if (! priv->has_preamble)
5369 /* 802.11b has recently defined some short preamble.
5370 * Basically, the Phy header has been reduced in size.
5371 * This increase performance, especially at high rates
5372 * (the preamble is transmitted at 1Mb/s), unfortunately
5373 * this give compatibility troubles... - Jean II */
5374 val = *( (int *) extra );
5376 if (orinoco_lock(priv, &flags) != 0)
5384 orinoco_unlock(priv, &flags);
5386 return -EINPROGRESS; /* Call commit handler */
5389 static int orinoco_ioctl_getpreamble(struct net_device *dev,
5390 struct iw_request_info *info,
5394 struct orinoco_private *priv = netdev_priv(dev);
5395 int *val = (int *) extra;
5397 if (! priv->has_preamble)
5400 *val = priv->preamble;
5404 /* ioctl interface to hermes_read_ltv()
5405 * To use with iwpriv, pass the RID as the token argument, e.g.
5406 * iwpriv get_rid [0xfc00]
5407 * At least Wireless Tools 25 is required to use iwpriv.
5408 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5409 static int orinoco_ioctl_getrid(struct net_device *dev,
5410 struct iw_request_info *info,
5411 struct iw_point *data,
5414 struct orinoco_private *priv = netdev_priv(dev);
5415 hermes_t *hw = &priv->hw;
5416 int rid = data->flags;
5419 unsigned long flags;
5421 /* It's a "get" function, but we don't want users to access the
5422 * WEP key and other raw firmware data */
5423 if (! capable(CAP_NET_ADMIN))
5426 if (rid < 0xfc00 || rid > 0xffff)
5429 if (orinoco_lock(priv, &flags) != 0)
5432 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5437 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5441 orinoco_unlock(priv, &flags);
5445 /* Trigger a scan (look for other cells in the vicinity) */
5446 static int orinoco_ioctl_setscan(struct net_device *dev,
5447 struct iw_request_info *info,
5448 struct iw_point *srq,
5451 struct orinoco_private *priv = netdev_priv(dev);
5452 hermes_t *hw = &priv->hw;
5453 struct iw_scan_req *si = (struct iw_scan_req *) extra;
5455 unsigned long flags;
5457 /* Note : you may have realised that, as this is a SET operation,
5458 * this is privileged and therefore a normal user can't
5460 * This is not an error, while the device perform scanning,
5461 * traffic doesn't flow, so it's a perfect DoS...
5464 if (orinoco_lock(priv, &flags) != 0)
5467 /* Scanning with port 0 disabled would fail */
5468 if (!netif_running(dev)) {
5473 /* In monitor mode, the scan results are always empty.
5474 * Probe responses are passed to the driver as received
5475 * frames and could be processed in software. */
5476 if (priv->iw_mode == IW_MODE_MONITOR) {
5481 /* Note : because we don't lock out the irq handler, the way
5482 * we access scan variables in priv is critical.
5483 * o scan_inprogress : not touched by irq handler
5484 * o scan_mode : not touched by irq handler
5485 * Before modifying anything on those variables, please think hard !
5489 priv->scan_mode = srq->flags;
5491 /* Always trigger scanning, even if it's in progress.
5492 * This way, if the info frame get lost, we will recover somewhat
5493 * gracefully - Jean II */
5495 if (priv->has_hostscan) {
5496 switch (priv->firmware_type) {
5497 case FIRMWARE_TYPE_SYMBOL:
5498 err = hermes_write_wordrec(hw, USER_BAP,
5499 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5500 HERMES_HOSTSCAN_SYMBOL_ONCE |
5501 HERMES_HOSTSCAN_SYMBOL_BCAST);
5503 case FIRMWARE_TYPE_INTERSIL: {
5506 req[0] = cpu_to_le16(0x3fff); /* All channels */
5507 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5508 req[2] = 0; /* Any ESSID */
5509 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5510 HERMES_RID_CNFHOSTSCAN, &req);
5513 case FIRMWARE_TYPE_AGERE:
5514 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5515 struct hermes_idstring idbuf;
5516 size_t len = min(sizeof(idbuf.val),
5517 (size_t) si->essid_len);
5518 idbuf.len = cpu_to_le16(len);
5519 memcpy(idbuf.val, si->essid, len);
5521 err = hermes_write_ltv(hw, USER_BAP,
5522 HERMES_RID_CNFSCANSSID_AGERE,
5523 HERMES_BYTES_TO_RECLEN(len + 2),
5526 err = hermes_write_wordrec(hw, USER_BAP,
5527 HERMES_RID_CNFSCANSSID_AGERE,
5532 if (priv->has_ext_scan) {
5533 /* Clear scan results at the start of
5534 * an extended scan */
5535 orinoco_clear_scan_results(priv,
5536 msecs_to_jiffies(15000));
5538 /* TODO: Is this available on older firmware?
5539 * Can we use it to scan specific channels
5540 * for IW_SCAN_THIS_FREQ? */
5541 err = hermes_write_wordrec(hw, USER_BAP,
5542 HERMES_RID_CNFSCANCHANNELS2GHZ,
5547 err = hermes_inquire(hw,
5548 HERMES_INQ_CHANNELINFO);
5550 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5554 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5556 /* One more client */
5558 priv->scan_inprogress = 1;
5561 orinoco_unlock(priv, &flags);
5565 #define MAX_CUSTOM_LEN 64
5567 /* Translate scan data returned from the card to a card independant
5568 * format that the Wireless Tools will understand - Jean II */
5569 static inline char *orinoco_translate_scan(struct net_device *dev,
5570 struct iw_request_info *info,
5573 union hermes_scan_info *bss,
5574 unsigned long last_scanned)
5576 struct orinoco_private *priv = netdev_priv(dev);
5579 struct iw_event iwe; /* Temporary buffer */
5580 char custom[MAX_CUSTOM_LEN];
5582 memset(&iwe, 0, sizeof(iwe));
5584 /* First entry *MUST* be the AP MAC address */
5585 iwe.cmd = SIOCGIWAP;
5586 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5587 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
5588 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5589 &iwe, IW_EV_ADDR_LEN);
5591 /* Other entries will be displayed in the order we give them */
5594 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5595 if (iwe.u.data.length > 32)
5596 iwe.u.data.length = 32;
5597 iwe.cmd = SIOCGIWESSID;
5598 iwe.u.data.flags = 1;
5599 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5600 &iwe, bss->a.essid);
5603 iwe.cmd = SIOCGIWMODE;
5604 capabilities = le16_to_cpu(bss->a.capabilities);
5605 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5606 if (capabilities & WLAN_CAPABILITY_ESS)
5607 iwe.u.mode = IW_MODE_MASTER;
5609 iwe.u.mode = IW_MODE_ADHOC;
5610 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5611 &iwe, IW_EV_UINT_LEN);
5614 channel = bss->s.channel;
5615 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5616 /* Add channel and frequency */
5617 iwe.cmd = SIOCGIWFREQ;
5618 iwe.u.freq.m = channel;
5620 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5621 &iwe, IW_EV_FREQ_LEN);
5623 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5625 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5626 &iwe, IW_EV_FREQ_LEN);
5629 /* Add quality statistics. level and noise in dB. No link quality */
5631 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5632 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5633 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5634 /* Wireless tools prior to 27.pre22 will show link quality
5635 * anyway, so we provide a reasonable value. */
5636 if (iwe.u.qual.level > iwe.u.qual.noise)
5637 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5639 iwe.u.qual.qual = 0;
5640 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5641 &iwe, IW_EV_QUAL_LEN);
5643 /* Add encryption capability */
5644 iwe.cmd = SIOCGIWENCODE;
5645 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5646 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5648 iwe.u.data.flags = IW_ENCODE_DISABLED;
5649 iwe.u.data.length = 0;
5650 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5653 /* Bit rate is not available in Lucent/Agere firmwares */
5654 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
5655 char *current_val = current_ev + iwe_stream_lcp_len(info);
5659 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5664 iwe.cmd = SIOCGIWRATE;
5665 /* Those two flags are ignored... */
5666 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5668 for (i = 0; i < 10; i += step) {
5669 /* NULL terminated */
5670 if (bss->p.rates[i] == 0x0)
5672 /* Bit rate given in 500 kb/s units (+ 0x80) */
5673 iwe.u.bitrate.value =
5674 ((bss->p.rates[i] & 0x7f) * 500000);
5675 current_val = iwe_stream_add_value(info, current_ev,
5680 /* Check if we added any event */
5681 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
5682 current_ev = current_val;
5685 /* Beacon interval */
5686 iwe.cmd = IWEVCUSTOM;
5687 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5689 le16_to_cpu(bss->a.beacon_interv));
5690 if (iwe.u.data.length)
5691 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5695 iwe.cmd = IWEVCUSTOM;
5696 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5699 if (iwe.u.data.length)
5700 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5703 /* Add EXTRA: Age to display seconds since last beacon/probe response
5704 * for given network. */
5705 iwe.cmd = IWEVCUSTOM;
5706 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5707 " Last beacon: %dms ago",
5708 jiffies_to_msecs(jiffies - last_scanned));
5709 if (iwe.u.data.length)
5710 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5716 static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5717 struct iw_request_info *info,
5720 struct agere_ext_scan_info *bss,
5721 unsigned long last_scanned)
5725 struct iw_event iwe; /* Temporary buffer */
5726 char custom[MAX_CUSTOM_LEN];
5729 memset(&iwe, 0, sizeof(iwe));
5731 /* First entry *MUST* be the AP MAC address */
5732 iwe.cmd = SIOCGIWAP;
5733 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5734 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5735 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5736 &iwe, IW_EV_ADDR_LEN);
5738 /* Other entries will be displayed in the order we give them */
5742 iwe.u.data.length = ie[1];
5743 if (iwe.u.data.length) {
5744 if (iwe.u.data.length > 32)
5745 iwe.u.data.length = 32;
5746 iwe.cmd = SIOCGIWESSID;
5747 iwe.u.data.flags = 1;
5748 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5753 capabilities = le16_to_cpu(bss->capabilities);
5754 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5755 iwe.cmd = SIOCGIWMODE;
5756 if (capabilities & WLAN_CAPABILITY_ESS)
5757 iwe.u.mode = IW_MODE_MASTER;
5759 iwe.u.mode = IW_MODE_ADHOC;
5760 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5761 &iwe, IW_EV_UINT_LEN);
5764 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_DS_PARAMS);
5765 channel = ie ? ie[2] : 0;
5766 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5767 /* Add channel and frequency */
5768 iwe.cmd = SIOCGIWFREQ;
5769 iwe.u.freq.m = channel;
5771 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5772 &iwe, IW_EV_FREQ_LEN);
5774 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5776 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5777 &iwe, IW_EV_FREQ_LEN);
5780 /* Add quality statistics. level and noise in dB. No link quality */
5782 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5783 iwe.u.qual.level = bss->level - 0x95;
5784 iwe.u.qual.noise = bss->noise - 0x95;
5785 /* Wireless tools prior to 27.pre22 will show link quality
5786 * anyway, so we provide a reasonable value. */
5787 if (iwe.u.qual.level > iwe.u.qual.noise)
5788 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5790 iwe.u.qual.qual = 0;
5791 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5792 &iwe, IW_EV_QUAL_LEN);
5794 /* Add encryption capability */
5795 iwe.cmd = SIOCGIWENCODE;
5796 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5797 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5799 iwe.u.data.flags = IW_ENCODE_DISABLED;
5800 iwe.u.data.length = 0;
5801 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5805 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5807 iwe.cmd = IWEVGENIE;
5808 iwe.u.data.length = ie[1] + 2;
5809 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5814 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_RSN);
5816 iwe.cmd = IWEVGENIE;
5817 iwe.u.data.length = ie[1] + 2;
5818 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5822 ie = orinoco_get_ie(bss->data, sizeof(bss->data), WLAN_EID_SUPP_RATES);
5824 char *p = current_ev + iwe_stream_lcp_len(info);
5827 iwe.cmd = SIOCGIWRATE;
5828 /* Those two flags are ignored... */
5829 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5831 for (i = 2; i < (ie[1] + 2); i++) {
5832 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5833 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5834 &iwe, IW_EV_PARAM_LEN);
5836 /* Check if we added any event */
5837 if (p > (current_ev + iwe_stream_lcp_len(info)))
5842 iwe.cmd = IWEVCUSTOM;
5844 snprintf(custom, MAX_CUSTOM_LEN, "tsf=%016llx",
5845 (unsigned long long) le64_to_cpu(bss->timestamp));
5846 if (iwe.u.data.length)
5847 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5850 /* Beacon interval */
5851 iwe.cmd = IWEVCUSTOM;
5852 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5854 le16_to_cpu(bss->beacon_interval));
5855 if (iwe.u.data.length)
5856 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5860 iwe.cmd = IWEVCUSTOM;
5861 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5864 if (iwe.u.data.length)
5865 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5868 /* Add EXTRA: Age to display seconds since last beacon/probe response
5869 * for given network. */
5870 iwe.cmd = IWEVCUSTOM;
5871 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5872 " Last beacon: %dms ago",
5873 jiffies_to_msecs(jiffies - last_scanned));
5874 if (iwe.u.data.length)
5875 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5881 /* Return results of a scan */
5882 static int orinoco_ioctl_getscan(struct net_device *dev,
5883 struct iw_request_info *info,
5884 struct iw_point *srq,
5887 struct orinoco_private *priv = netdev_priv(dev);
5889 unsigned long flags;
5890 char *current_ev = extra;
5892 if (orinoco_lock(priv, &flags) != 0)
5895 if (priv->scan_inprogress) {
5896 /* Important note : we don't want to block the caller
5897 * until results are ready for various reasons.
5898 * First, managing wait queues is complex and racy.
5899 * Second, we grab some rtnetlink lock before comming
5900 * here (in dev_ioctl()).
5901 * Third, we generate an Wireless Event, so the
5902 * caller can wait itself on that - Jean II */
5907 if (priv->has_ext_scan) {
5908 struct xbss_element *bss;
5910 list_for_each_entry(bss, &priv->bss_list, list) {
5911 /* Translate this entry to WE format */
5913 orinoco_translate_ext_scan(dev, info,
5915 extra + srq->length,
5919 /* Check if there is space for one more entry */
5920 if ((extra + srq->length - current_ev)
5921 <= IW_EV_ADDR_LEN) {
5922 /* Ask user space to try again with a
5930 struct bss_element *bss;
5932 list_for_each_entry(bss, &priv->bss_list, list) {
5933 /* Translate this entry to WE format */
5934 current_ev = orinoco_translate_scan(dev, info,
5936 extra + srq->length,
5940 /* Check if there is space for one more entry */
5941 if ((extra + srq->length - current_ev)
5942 <= IW_EV_ADDR_LEN) {
5943 /* Ask user space to try again with a
5951 srq->length = (current_ev - extra);
5952 srq->flags = (__u16) priv->scan_mode;
5955 orinoco_unlock(priv, &flags);
5959 /* Commit handler, called after set operations */
5960 static int orinoco_ioctl_commit(struct net_device *dev,
5961 struct iw_request_info *info,
5965 struct orinoco_private *priv = netdev_priv(dev);
5966 struct hermes *hw = &priv->hw;
5967 unsigned long flags;
5973 if (priv->broken_disableport) {
5974 orinoco_reset(&priv->reset_work);
5978 if (orinoco_lock(priv, &flags) != 0)
5981 err = hermes_disable_port(hw, 0);
5983 printk(KERN_WARNING "%s: Unable to disable port "
5984 "while reconfiguring card\n", dev->name);
5985 priv->broken_disableport = 1;
5989 err = __orinoco_program_rids(dev);
5991 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5996 err = hermes_enable_port(hw, 0);
5998 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
6005 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
6006 schedule_work(&priv->reset_work);
6010 orinoco_unlock(priv, &flags);
6014 static const struct iw_priv_args orinoco_privtab[] = {
6015 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
6016 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
6017 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6019 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6021 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6022 0, "set_preamble" },
6023 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6025 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6026 0, "set_ibssport" },
6027 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
6029 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
6035 * Structures to export the Wireless Handlers
6038 #define STD_IW_HANDLER(id, func) \
6039 [IW_IOCTL_IDX(id)] = (iw_handler) func
6040 static const iw_handler orinoco_handler[] = {
6041 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
6042 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
6043 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
6044 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
6045 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
6046 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
6047 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
6048 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
6049 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
6050 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
6051 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
6052 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
6053 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
6054 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
6055 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
6056 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
6057 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
6058 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
6059 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
6060 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
6061 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
6062 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
6063 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
6064 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
6065 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
6066 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
6067 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
6068 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
6069 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
6070 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
6071 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
6072 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
6073 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
6074 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
6075 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
6076 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
6077 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
6078 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
6079 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
6084 Added typecasting since we no longer use iwreq_data -- Moustafa
6086 static const iw_handler orinoco_private_handler[] = {
6087 [0] = (iw_handler) orinoco_ioctl_reset,
6088 [1] = (iw_handler) orinoco_ioctl_reset,
6089 [2] = (iw_handler) orinoco_ioctl_setport3,
6090 [3] = (iw_handler) orinoco_ioctl_getport3,
6091 [4] = (iw_handler) orinoco_ioctl_setpreamble,
6092 [5] = (iw_handler) orinoco_ioctl_getpreamble,
6093 [6] = (iw_handler) orinoco_ioctl_setibssport,
6094 [7] = (iw_handler) orinoco_ioctl_getibssport,
6095 [9] = (iw_handler) orinoco_ioctl_getrid,
6098 static const struct iw_handler_def orinoco_handler_def = {
6099 .num_standard = ARRAY_SIZE(orinoco_handler),
6100 .num_private = ARRAY_SIZE(orinoco_private_handler),
6101 .num_private_args = ARRAY_SIZE(orinoco_privtab),
6102 .standard = orinoco_handler,
6103 .private = orinoco_private_handler,
6104 .private_args = orinoco_privtab,
6105 .get_wireless_stats = orinoco_get_wireless_stats,
6108 static void orinoco_get_drvinfo(struct net_device *dev,
6109 struct ethtool_drvinfo *info)
6111 struct orinoco_private *priv = netdev_priv(dev);
6113 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
6114 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
6115 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
6116 if (dev->dev.parent)
6117 strncpy(info->bus_info, dev_name(dev->dev.parent),
6118 sizeof(info->bus_info) - 1);
6120 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
6121 "PCMCIA %p", priv->hw.iobase);
6124 static const struct ethtool_ops orinoco_ethtool_ops = {
6125 .get_drvinfo = orinoco_get_drvinfo,
6126 .get_link = ethtool_op_get_link,
6129 /********************************************************************/
6130 /* Module initialization */
6131 /********************************************************************/
6133 EXPORT_SYMBOL(alloc_orinocodev);
6134 EXPORT_SYMBOL(free_orinocodev);
6136 EXPORT_SYMBOL(__orinoco_up);
6137 EXPORT_SYMBOL(__orinoco_down);
6138 EXPORT_SYMBOL(orinoco_reinit_firmware);
6140 EXPORT_SYMBOL(orinoco_interrupt);
6142 /* Can't be declared "const" or the whole __initdata section will
6144 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
6145 " (David Gibson <hermes@gibson.dropbear.id.au>, "
6146 "Pavel Roskin <proski@gnu.org>, et al)";
6148 static int __init init_orinoco(void)
6150 printk(KERN_DEBUG "%s\n", version);
6154 static void __exit exit_orinoco(void)
6158 module_init(init_orinoco);
6159 module_exit(exit_orinoco);